Format: fix report + telegram formatting
This commit is contained in:
committed by
Peter Steinberger
parent
232c512502
commit
393d21d86c
@@ -24,8 +24,7 @@ function parseSkillBlocks(skillsPrompt: string): Array<{ name: string; blockChar
|
|||||||
);
|
);
|
||||||
return blocks
|
return blocks
|
||||||
.map((block) => {
|
.map((block) => {
|
||||||
const name =
|
const name = block.match(/<name>\s*([^<]+?)\s*<\/name>/i)?.[1]?.trim() || "(unknown)";
|
||||||
block.match(/<name>\s*([^<]+?)\s*<\/name>/i)?.[1]?.trim() || "(unknown)";
|
|
||||||
return { name, blockChars: block.length };
|
return { name, blockChars: block.length };
|
||||||
})
|
})
|
||||||
.filter((b) => b.blockChars > 0);
|
.filter((b) => b.blockChars > 0);
|
||||||
@@ -81,7 +80,8 @@ function buildToolsEntries(tools: AgentTool[]): SessionSystemPromptReport["tools
|
|||||||
|
|
||||||
function extractToolListText(systemPrompt: string): string {
|
function extractToolListText(systemPrompt: string): string {
|
||||||
const markerA = "Tool names are case-sensitive. Call tools exactly as listed.\n";
|
const markerA = "Tool names are case-sensitive. Call tools exactly as listed.\n";
|
||||||
const markerB = "\nTOOLS.md does not control tool availability; it is user guidance for how to use external tools.";
|
const markerB =
|
||||||
|
"\nTOOLS.md does not control tool availability; it is user guidance for how to use external tools.";
|
||||||
const extracted = extractBetween(systemPrompt, markerA, markerB);
|
const extracted = extractBetween(systemPrompt, markerA, markerB);
|
||||||
if (!extracted.found) return "";
|
if (!extracted.found) return "";
|
||||||
return extracted.text.replace(markerA, "").trim();
|
return extracted.text.replace(markerA, "").trim();
|
||||||
@@ -147,4 +147,3 @@ export function buildSystemPromptReport(params: {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { buildBootstrapContextFiles, resolveBootstrapMaxChars } from "../../agents/pi-embedded-helpers.js";
|
import {
|
||||||
|
buildBootstrapContextFiles,
|
||||||
|
resolveBootstrapMaxChars,
|
||||||
|
} from "../../agents/pi-embedded-helpers.js";
|
||||||
import { createClawdbotCodingTools } from "../../agents/pi-tools.js";
|
import { createClawdbotCodingTools } from "../../agents/pi-tools.js";
|
||||||
import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js";
|
import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js";
|
||||||
import { buildWorkspaceSkillSnapshot } from "../../agents/skills.js";
|
import { buildWorkspaceSkillSnapshot } from "../../agents/skills.js";
|
||||||
@@ -197,7 +200,9 @@ export async function buildContextReply(params: HandleCommandsParams): Promise<R
|
|||||||
const skillNames = Array.from(skillNameSet);
|
const skillNames = Array.from(skillNameSet);
|
||||||
const toolNames = report.tools.entries.map((t) => t.name);
|
const toolNames = report.tools.entries.map((t) => t.name);
|
||||||
const formatNameList = (names: string[], cap: number) =>
|
const formatNameList = (names: string[], cap: number) =>
|
||||||
names.length <= cap ? names.join(", ") : `${names.slice(0, cap).join(", ")}, … (+${names.length - cap} more)`;
|
names.length <= cap
|
||||||
|
? names.join(", ")
|
||||||
|
: `${names.slice(0, cap).join(", ")}, … (+${names.length - cap} more)`;
|
||||||
const skillsLine = `Skills list (system prompt text): ${formatCharsAndTokens(report.skills.promptChars)} (${skillNameSet.size} skills)`;
|
const skillsLine = `Skills list (system prompt text): ${formatCharsAndTokens(report.skills.promptChars)} (${skillNameSet.size} skills)`;
|
||||||
const skillsNamesLine = skillNameSet.size
|
const skillsNamesLine = skillNameSet.size
|
||||||
? `Skills: ${formatNameList(skillNames, 20)}`
|
? `Skills: ${formatNameList(skillNames, 20)}`
|
||||||
@@ -208,7 +213,9 @@ export async function buildContextReply(params: HandleCommandsParams): Promise<R
|
|||||||
const systemPromptLine = `System prompt (${report.source}): ${formatCharsAndTokens(report.systemPrompt.chars)} (Project Context ${formatCharsAndTokens(report.systemPrompt.projectContextChars)})`;
|
const systemPromptLine = `System prompt (${report.source}): ${formatCharsAndTokens(report.systemPrompt.chars)} (Project Context ${formatCharsAndTokens(report.systemPrompt.projectContextChars)})`;
|
||||||
const workspaceLabel = report.workspaceDir ?? params.workspaceDir;
|
const workspaceLabel = report.workspaceDir ?? params.workspaceDir;
|
||||||
const bootstrapMaxLabel =
|
const bootstrapMaxLabel =
|
||||||
typeof report.bootstrapMaxChars === "number" ? `${formatInt(report.bootstrapMaxChars)} chars` : "? chars";
|
typeof report.bootstrapMaxChars === "number"
|
||||||
|
? `${formatInt(report.bootstrapMaxChars)} chars`
|
||||||
|
: "? chars";
|
||||||
|
|
||||||
const totalsLine =
|
const totalsLine =
|
||||||
session.totalTokens != null
|
session.totalTokens != null
|
||||||
|
|||||||
@@ -91,11 +91,7 @@ export const registerTelegramHandlers = ({
|
|||||||
const newChatId = String(msg.migrate_to_chat_id);
|
const newChatId = String(msg.migrate_to_chat_id);
|
||||||
const chatTitle = (msg.chat as { title?: string }).title ?? "Unknown";
|
const chatTitle = (msg.chat as { title?: string }).title ?? "Unknown";
|
||||||
|
|
||||||
runtime.log?.(
|
runtime.log?.(warn(`[telegram] Group migrated: "${chatTitle}" ${oldChatId} → ${newChatId}`));
|
||||||
warn(
|
|
||||||
`[telegram] Group migrated: "${chatTitle}" ${oldChatId} → ${newChatId}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check if old chat ID has config and migrate it
|
// Check if old chat ID has config and migrate it
|
||||||
const currentConfig = loadConfig();
|
const currentConfig = loadConfig();
|
||||||
@@ -107,11 +103,7 @@ export const registerTelegramHandlers = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (migration.migrated) {
|
if (migration.migrated) {
|
||||||
runtime.log?.(
|
runtime.log?.(warn(`[telegram] Migrating group config from ${oldChatId} to ${newChatId}`));
|
||||||
warn(
|
|
||||||
`[telegram] Migrating group config from ${oldChatId} to ${newChatId}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
migrateTelegramGroupConfig({ cfg, accountId, oldChatId, newChatId });
|
migrateTelegramGroupConfig({ cfg, accountId, oldChatId, newChatId });
|
||||||
await writeConfigFile(currentConfig);
|
await writeConfigFile(currentConfig);
|
||||||
runtime.log?.(warn(`[telegram] Group config migrated and saved successfully`));
|
runtime.log?.(warn(`[telegram] Group config migrated and saved successfully`));
|
||||||
@@ -123,15 +115,11 @@ export const registerTelegramHandlers = ({
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
runtime.log?.(
|
runtime.log?.(
|
||||||
warn(
|
warn(`[telegram] No config found for old group ID ${oldChatId}, migration logged only`),
|
||||||
`[telegram] No config found for old group ID ${oldChatId}, migration logged only`,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
runtime.error?.(
|
runtime.error?.(danger(`[telegram] Group migration handler failed: ${String(err)}`));
|
||||||
danger(`[telegram] Group migration handler failed: ${String(err)}`),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -54,11 +54,7 @@ export function migrateTelegramGroupConfig(params: {
|
|||||||
|
|
||||||
const accountGroups = resolveAccountGroups(params.cfg, params.accountId).groups;
|
const accountGroups = resolveAccountGroups(params.cfg, params.accountId).groups;
|
||||||
if (accountGroups) {
|
if (accountGroups) {
|
||||||
const result = migrateTelegramGroupsInPlace(
|
const result = migrateTelegramGroupsInPlace(accountGroups, params.oldChatId, params.newChatId);
|
||||||
accountGroups,
|
|
||||||
params.oldChatId,
|
|
||||||
params.newChatId,
|
|
||||||
);
|
|
||||||
if (result.migrated) {
|
if (result.migrated) {
|
||||||
migrated = true;
|
migrated = true;
|
||||||
scopes.push("account");
|
scopes.push("account");
|
||||||
@@ -68,11 +64,7 @@ export function migrateTelegramGroupConfig(params: {
|
|||||||
|
|
||||||
const globalGroups = params.cfg.channels?.telegram?.groups;
|
const globalGroups = params.cfg.channels?.telegram?.groups;
|
||||||
if (globalGroups) {
|
if (globalGroups) {
|
||||||
const result = migrateTelegramGroupsInPlace(
|
const result = migrateTelegramGroupsInPlace(globalGroups, params.oldChatId, params.newChatId);
|
||||||
globalGroups,
|
|
||||||
params.oldChatId,
|
|
||||||
params.newChatId,
|
|
||||||
);
|
|
||||||
if (result.migrated) {
|
if (result.migrated) {
|
||||||
migrated = true;
|
migrated = true;
|
||||||
scopes.push("global");
|
scopes.push("global");
|
||||||
|
|||||||
Reference in New Issue
Block a user