Add files using upload-large-folder tool
Browse files
src/agents/pi-embedded-runner/run/attempt.ts
CHANGED
|
@@ -1399,6 +1399,7 @@ export async function runEmbeddedAttempt(
|
|
| 1399 |
let restoreSkillEnv: (() => void) | undefined;
|
| 1400 |
process.chdir(effectiveWorkspace);
|
| 1401 |
try {
|
|
|
|
| 1402 |
const { shouldLoadSkillEntries, skillEntries } = resolveEmbeddedRunSkillEntries({
|
| 1403 |
workspaceDir: effectiveWorkspace,
|
| 1404 |
config: params.config,
|
|
@@ -1414,14 +1415,17 @@ export async function runEmbeddedAttempt(
|
|
| 1414 |
config: params.config,
|
| 1415 |
});
|
| 1416 |
|
|
|
|
| 1417 |
const skillsPrompt = resolveSkillsPromptForRun({
|
| 1418 |
skillsSnapshot: params.skillsSnapshot,
|
| 1419 |
entries: shouldLoadSkillEntries ? skillEntries : undefined,
|
| 1420 |
config: params.config,
|
| 1421 |
workspaceDir: effectiveWorkspace,
|
| 1422 |
});
|
|
|
|
| 1423 |
|
| 1424 |
const sessionLabel = params.sessionKey ?? params.sessionId;
|
|
|
|
| 1425 |
const { bootstrapFiles: hookAdjustedBootstrapFiles, contextFiles } =
|
| 1426 |
await resolveBootstrapContextForRun({
|
| 1427 |
workspaceDir: effectiveWorkspace,
|
|
@@ -1454,6 +1458,7 @@ export async function runEmbeddedAttempt(
|
|
| 1454 |
)
|
| 1455 |
? ["Reminder: commit your changes in this workspace after edits."]
|
| 1456 |
: undefined;
|
|
|
|
| 1457 |
|
| 1458 |
const agentDir = params.agentDir ?? resolveOpenClawAgentDir();
|
| 1459 |
|
|
@@ -1475,6 +1480,7 @@ export async function runEmbeddedAttempt(
|
|
| 1475 |
let yieldAbortSettled: Promise<void> | null = null;
|
| 1476 |
// Check if the model supports native image input
|
| 1477 |
const modelHasVision = params.model.input?.includes("image") ?? false;
|
|
|
|
| 1478 |
const toolsRaw = params.disableTools
|
| 1479 |
? []
|
| 1480 |
: createOpenClawCodingTools({
|
|
@@ -1534,6 +1540,7 @@ export async function runEmbeddedAttempt(
|
|
| 1534 |
tools: toolsEnabled ? toolsRaw : [],
|
| 1535 |
provider: params.provider,
|
| 1536 |
});
|
|
|
|
| 1537 |
const clientTools = toolsEnabled ? params.clientTools : undefined;
|
| 1538 |
const allowedToolNames = collectAllowedToolNames({
|
| 1539 |
tools,
|
|
@@ -1610,6 +1617,7 @@ export async function runEmbeddedAttempt(
|
|
| 1610 |
agentId: sessionAgentId,
|
| 1611 |
});
|
| 1612 |
const defaultModelLabel = `${defaultModelRef.provider}/${defaultModelRef.model}`;
|
|
|
|
| 1613 |
const { runtimeInfo, userTimezone, userTime, userTimeFormat } = buildSystemPromptParams({
|
| 1614 |
config: params.config,
|
| 1615 |
agentId: sessionAgentId,
|
|
@@ -1628,17 +1636,21 @@ export async function runEmbeddedAttempt(
|
|
| 1628 |
channelActions,
|
| 1629 |
},
|
| 1630 |
});
|
|
|
|
| 1631 |
const isDefaultAgent = sessionAgentId === defaultAgentId;
|
| 1632 |
const promptMode = resolvePromptModeForSession(params.sessionKey);
|
|
|
|
| 1633 |
const docsPath = await resolveOpenClawDocsPath({
|
| 1634 |
workspaceDir: effectiveWorkspace,
|
| 1635 |
argv1: process.argv[1],
|
| 1636 |
cwd: process.cwd(),
|
| 1637 |
moduleUrl: import.meta.url,
|
| 1638 |
});
|
|
|
|
| 1639 |
const ttsHint = params.config ? buildTtsSystemPromptHint(params.config) : undefined;
|
| 1640 |
const ownerDisplay = resolveOwnerDisplaySetting(params.config);
|
| 1641 |
|
|
|
|
| 1642 |
const appendPrompt = buildEmbeddedSystemPrompt({
|
| 1643 |
workspaceDir: effectiveWorkspace,
|
| 1644 |
defaultThinkLevel: params.thinkLevel,
|
|
@@ -1670,6 +1682,7 @@ export async function runEmbeddedAttempt(
|
|
| 1670 |
bootstrapTruncationWarningLines: bootstrapPromptWarning.lines,
|
| 1671 |
memoryCitationsMode: params.config?.memory?.citations,
|
| 1672 |
});
|
|
|
|
| 1673 |
const systemPromptReport = buildSystemPromptReport({
|
| 1674 |
source: "run",
|
| 1675 |
generatedAt: Date.now(),
|
|
@@ -1692,6 +1705,15 @@ export async function runEmbeddedAttempt(
|
|
| 1692 |
});
|
| 1693 |
return { mode: runtime.mode, sandboxed: runtime.sandboxed };
|
| 1694 |
})(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1695 |
systemPrompt: appendPrompt,
|
| 1696 |
bootstrapFiles: hookAdjustedBootstrapFiles,
|
| 1697 |
injectedFiles: contextFiles,
|
|
|
|
| 1399 |
let restoreSkillEnv: (() => void) | undefined;
|
| 1400 |
process.chdir(effectiveWorkspace);
|
| 1401 |
try {
|
| 1402 |
+
const promptPreparationStartedAt = Date.now();
|
| 1403 |
const { shouldLoadSkillEntries, skillEntries } = resolveEmbeddedRunSkillEntries({
|
| 1404 |
workspaceDir: effectiveWorkspace,
|
| 1405 |
config: params.config,
|
|
|
|
| 1415 |
config: params.config,
|
| 1416 |
});
|
| 1417 |
|
| 1418 |
+
const skillsStartedAt = Date.now();
|
| 1419 |
const skillsPrompt = resolveSkillsPromptForRun({
|
| 1420 |
skillsSnapshot: params.skillsSnapshot,
|
| 1421 |
entries: shouldLoadSkillEntries ? skillEntries : undefined,
|
| 1422 |
config: params.config,
|
| 1423 |
workspaceDir: effectiveWorkspace,
|
| 1424 |
});
|
| 1425 |
+
const skillsMs = Date.now() - skillsStartedAt;
|
| 1426 |
|
| 1427 |
const sessionLabel = params.sessionKey ?? params.sessionId;
|
| 1428 |
+
const bootstrapStartedAt = Date.now();
|
| 1429 |
const { bootstrapFiles: hookAdjustedBootstrapFiles, contextFiles } =
|
| 1430 |
await resolveBootstrapContextForRun({
|
| 1431 |
workspaceDir: effectiveWorkspace,
|
|
|
|
| 1458 |
)
|
| 1459 |
? ["Reminder: commit your changes in this workspace after edits."]
|
| 1460 |
: undefined;
|
| 1461 |
+
const bootstrapMs = Date.now() - bootstrapStartedAt;
|
| 1462 |
|
| 1463 |
const agentDir = params.agentDir ?? resolveOpenClawAgentDir();
|
| 1464 |
|
|
|
|
| 1480 |
let yieldAbortSettled: Promise<void> | null = null;
|
| 1481 |
// Check if the model supports native image input
|
| 1482 |
const modelHasVision = params.model.input?.includes("image") ?? false;
|
| 1483 |
+
const toolsStartedAt = Date.now();
|
| 1484 |
const toolsRaw = params.disableTools
|
| 1485 |
? []
|
| 1486 |
: createOpenClawCodingTools({
|
|
|
|
| 1540 |
tools: toolsEnabled ? toolsRaw : [],
|
| 1541 |
provider: params.provider,
|
| 1542 |
});
|
| 1543 |
+
const toolsMs = Date.now() - toolsStartedAt;
|
| 1544 |
const clientTools = toolsEnabled ? params.clientTools : undefined;
|
| 1545 |
const allowedToolNames = collectAllowedToolNames({
|
| 1546 |
tools,
|
|
|
|
| 1617 |
agentId: sessionAgentId,
|
| 1618 |
});
|
| 1619 |
const defaultModelLabel = `${defaultModelRef.provider}/${defaultModelRef.model}`;
|
| 1620 |
+
const runtimeInfoStartedAt = Date.now();
|
| 1621 |
const { runtimeInfo, userTimezone, userTime, userTimeFormat } = buildSystemPromptParams({
|
| 1622 |
config: params.config,
|
| 1623 |
agentId: sessionAgentId,
|
|
|
|
| 1636 |
channelActions,
|
| 1637 |
},
|
| 1638 |
});
|
| 1639 |
+
const runtimeInfoMs = Date.now() - runtimeInfoStartedAt;
|
| 1640 |
const isDefaultAgent = sessionAgentId === defaultAgentId;
|
| 1641 |
const promptMode = resolvePromptModeForSession(params.sessionKey);
|
| 1642 |
+
const docsPathStartedAt = Date.now();
|
| 1643 |
const docsPath = await resolveOpenClawDocsPath({
|
| 1644 |
workspaceDir: effectiveWorkspace,
|
| 1645 |
argv1: process.argv[1],
|
| 1646 |
cwd: process.cwd(),
|
| 1647 |
moduleUrl: import.meta.url,
|
| 1648 |
});
|
| 1649 |
+
const docsPathMs = Date.now() - docsPathStartedAt;
|
| 1650 |
const ttsHint = params.config ? buildTtsSystemPromptHint(params.config) : undefined;
|
| 1651 |
const ownerDisplay = resolveOwnerDisplaySetting(params.config);
|
| 1652 |
|
| 1653 |
+
const systemPromptBuildStartedAt = Date.now();
|
| 1654 |
const appendPrompt = buildEmbeddedSystemPrompt({
|
| 1655 |
workspaceDir: effectiveWorkspace,
|
| 1656 |
defaultThinkLevel: params.thinkLevel,
|
|
|
|
| 1682 |
bootstrapTruncationWarningLines: bootstrapPromptWarning.lines,
|
| 1683 |
memoryCitationsMode: params.config?.memory?.citations,
|
| 1684 |
});
|
| 1685 |
+
const systemPromptBuildMs = Date.now() - systemPromptBuildStartedAt;
|
| 1686 |
const systemPromptReport = buildSystemPromptReport({
|
| 1687 |
source: "run",
|
| 1688 |
generatedAt: Date.now(),
|
|
|
|
| 1705 |
});
|
| 1706 |
return { mode: runtime.mode, sandboxed: runtime.sandboxed };
|
| 1707 |
})(),
|
| 1708 |
+
preparation: {
|
| 1709 |
+
totalMs: Date.now() - promptPreparationStartedAt,
|
| 1710 |
+
skillsMs,
|
| 1711 |
+
bootstrapMs,
|
| 1712 |
+
toolsMs,
|
| 1713 |
+
runtimeInfoMs,
|
| 1714 |
+
docsPathMs,
|
| 1715 |
+
systemPromptBuildMs,
|
| 1716 |
+
},
|
| 1717 |
systemPrompt: appendPrompt,
|
| 1718 |
bootstrapFiles: hookAdjustedBootstrapFiles,
|
| 1719 |
injectedFiles: contextFiles,
|
src/agents/system-prompt-report.test.ts
CHANGED
|
@@ -82,6 +82,39 @@ describe("buildSystemPromptReport", () => {
|
|
| 82 |
expect(report.bootstrapTotalMaxChars).toBe(22_222);
|
| 83 |
});
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
it("reports injectedChars=0 when injected file does not match by path or basename", () => {
|
| 86 |
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
| 87 |
const report = makeReport({
|
|
|
|
| 82 |
expect(report.bootstrapTotalMaxChars).toBe(22_222);
|
| 83 |
});
|
| 84 |
|
| 85 |
+
it("includes prompt preparation timings when provided", () => {
|
| 86 |
+
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
| 87 |
+
const report = buildSystemPromptReport({
|
| 88 |
+
source: "run",
|
| 89 |
+
generatedAt: 0,
|
| 90 |
+
bootstrapMaxChars: 20_000,
|
| 91 |
+
systemPrompt: "system",
|
| 92 |
+
bootstrapFiles: [file],
|
| 93 |
+
injectedFiles: [{ path: "AGENTS.md", content: "trimmed" }],
|
| 94 |
+
skillsPrompt: "",
|
| 95 |
+
tools: [],
|
| 96 |
+
preparation: {
|
| 97 |
+
totalMs: 321,
|
| 98 |
+
skillsMs: 12,
|
| 99 |
+
bootstrapMs: 34,
|
| 100 |
+
toolsMs: 56,
|
| 101 |
+
runtimeInfoMs: 7,
|
| 102 |
+
docsPathMs: 8,
|
| 103 |
+
systemPromptBuildMs: 9,
|
| 104 |
+
},
|
| 105 |
+
});
|
| 106 |
+
|
| 107 |
+
expect(report.preparation).toEqual({
|
| 108 |
+
totalMs: 321,
|
| 109 |
+
skillsMs: 12,
|
| 110 |
+
bootstrapMs: 34,
|
| 111 |
+
toolsMs: 56,
|
| 112 |
+
runtimeInfoMs: 7,
|
| 113 |
+
docsPathMs: 8,
|
| 114 |
+
systemPromptBuildMs: 9,
|
| 115 |
+
});
|
| 116 |
+
});
|
| 117 |
+
|
| 118 |
it("reports injectedChars=0 when injected file does not match by path or basename", () => {
|
| 119 |
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
| 120 |
const report = makeReport({
|
src/agents/system-prompt-report.ts
CHANGED
|
@@ -89,6 +89,7 @@ export function buildSystemPromptReport(params: {
|
|
| 89 |
bootstrapTotalMaxChars?: number;
|
| 90 |
bootstrapTruncation?: SessionSystemPromptReport["bootstrapTruncation"];
|
| 91 |
sandbox?: SessionSystemPromptReport["sandbox"];
|
|
|
|
| 92 |
systemPrompt: string;
|
| 93 |
bootstrapFiles: WorkspaceBootstrapFile[];
|
| 94 |
injectedFiles: EmbeddedContextFile[];
|
|
@@ -120,6 +121,7 @@ export function buildSystemPromptReport(params: {
|
|
| 120 |
bootstrapTotalMaxChars: params.bootstrapTotalMaxChars,
|
| 121 |
...(params.bootstrapTruncation ? { bootstrapTruncation: params.bootstrapTruncation } : {}),
|
| 122 |
sandbox: params.sandbox,
|
|
|
|
| 123 |
systemPrompt: {
|
| 124 |
chars: systemPrompt.length,
|
| 125 |
projectContextChars,
|
|
|
|
| 89 |
bootstrapTotalMaxChars?: number;
|
| 90 |
bootstrapTruncation?: SessionSystemPromptReport["bootstrapTruncation"];
|
| 91 |
sandbox?: SessionSystemPromptReport["sandbox"];
|
| 92 |
+
preparation?: SessionSystemPromptReport["preparation"];
|
| 93 |
systemPrompt: string;
|
| 94 |
bootstrapFiles: WorkspaceBootstrapFile[];
|
| 95 |
injectedFiles: EmbeddedContextFile[];
|
|
|
|
| 121 |
bootstrapTotalMaxChars: params.bootstrapTotalMaxChars,
|
| 122 |
...(params.bootstrapTruncation ? { bootstrapTruncation: params.bootstrapTruncation } : {}),
|
| 123 |
sandbox: params.sandbox,
|
| 124 |
+
...(params.preparation ? { preparation: params.preparation } : {}),
|
| 125 |
systemPrompt: {
|
| 126 |
chars: systemPrompt.length,
|
| 127 |
projectContextChars,
|