@caupulican/pi-adaptative 0.93.7 → 0.93.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +3 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +2 -4
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +7 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +2 -6
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +3 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +10 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +2 -8
- package/dist/core/tools/write.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-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AC,EAAE,CAAC;SAC3G,CAAC,CACF,CAAC;QACF,KAAK,EAAE,CAAC;IACT,CAAC;IAED,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { dirname } from \"node:path\";\nimport { getReadmePath } from \"../config.ts\";\nimport { getExtensionDescription, getExtensionDisplayName } from \"./extension-metadata.ts\";\nimport type { Extension } from \"./extensions/types.ts\";\nimport { enforceModelCapabilitySystemPromptBudget, type ModelCapabilityProfile } from \"./model-capability.ts\";\nimport { SKILL_VAULT_SYSTEM_RULE } from \"./provider-prompt-contracts.ts\";\nimport type { Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Capability profile that selects the stable prompt shape. Missing means full/legacy behavior. */\n\tmodelCapability?: Pick<ModelCapabilityProfile, \"class\" | \"contextWindow\" | \"reasonCode\" | \"systemPromptMaxChars\">;\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in the prompt. Defaults come from the shared active-tool surface. */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Global instruction files (with content) plus on-demand project paths (path only). */\n\tcontextFiles?: Array<{ path: string; content?: string }>;\n\t/** Discovered skills remain host-side; retained for extension/API construction compatibility. */\n\tskills?: Skill[];\n\t/** Discovered extensions currently active. */\n\textensions?: Extension[];\n}\n\nconst MODEL_BLIND_CREDENTIAL_AUTHORITY =\n\t\"Active secret_store: host gate authorizes model-blind activation/migration from named accessible sources; no duplicate confirmation.\";\n\nconst ULTRA_TERSE_OUTPUT_POLICY = `\n\nULTRA-TERSE OUTPUT\n\n- Drop articles/filler/pleasantries/hedging; fragments valid. Strip conjunctions only when clear; each fact once.\n- Never drop not/never/no/only/except; never invent abbreviations or use causal arrows. Preserve numbers, units, code symbols, function/API names, commands, errors.\n- No self-reference/tool narration/tables/emoji/log dumps. Keep user language. Full grammar: security, irreversible actions, ambiguous order. Replies terse; artifacts normal prose.\n- Answer shape: status/ops turns terse; analysis/review/evaluation asks get complete structured answers; never restate harness protocol text or failure-record JSON to the user as an answer.`;\n\nconst PI_ADAPTATIVE_CORE_SECTION = `\n\nOPERATING CONTRACT\n\n- Clear conversational outcome is goal; persist progress/evidence through compaction; finish or report blocker.\n- Hold scope; verify unknowns from primary sources; simplest proven design, one owner/path per invariant.\n- User outcome governs, method does not. Outcome risk: show evidence, test when practical, offer safest effective path, execute.\n- Work over 15 seconds: managed background run, event terminal, bounded handoff, owner notice; never poll.\n- Delegate independent work within host bounds; root integrates/verifies. Facts: memory, specialization: skills, behavior: source; discard noise.\n- Implementation/verification work loads skill evidence-gated-tdd; architecture/performance design loads skill n-plus-2-architecture; their gates bind only while that work is active.\n- Explicit user instruction in current message overrides standing style (length/format/tone); security, untrusted-content, and authorization rules are never overridable.\n- Ask before broader scope, credential or authentication change/disclosure, destructive action, publication. Bound, source-label output; show paths.\n- ${MODEL_BLIND_CREDENTIAL_AUTHORITY}`;\n\nconst PI_ADAPTATIVE_LEAN_CORE_SECTION = `\n\nOPERATING CONTRACT\n\n- Complete current goal within scope, granted authority; keep progress, evidence concise.\n- Inspect relevant files and instructions before editing; make minimal coherent change, run focused checks.\n- Use active tools, exact schemas. On failure, read error, expected shape, correct call; never repeat unchanged failure.\n- Batch independent reads, order mutations; report real output, unresolved failures.\n- Ask before destructive actions, credential disclosure or provider authentication changes, publication, push/tag/release, scope expansion.\n- ${MODEL_BLIND_CREDENTIAL_AUTHORITY}`;\n\nconst PI_ADAPTATIVE_MINIMAL_CORE_SECTION = `\n\nEXECUTION RULES\n\n- Work one scoped task. Inspect before editing, make small coherent change, run narrowest useful check.\n- Use listed tools, exact schemas. On failure, read error, expected shape, correct call; never repeat unchanged failure.\n- Batch independent reads, order mutations. Report actual results; never claim incomplete action.\n- Ask before destructive actions, credential disclosure or provider authentication changes, publication, push/tag/release, material scope change.\n- ${MODEL_BLIND_CREDENTIAL_AUTHORITY}`;\n\nconst PI_ADAPTATIVE_CHAT_CORE_SECTION = `\n\nCHAT RULES\n\n- Answer concisely from conversation; state uncertainty.\n- No execution tools are active. Do not claim to read files, run commands, or make changes.\n- Say when the request requires a tool-capable model or additional user-provided context.`;\n\nconst DEFERRED_CONTEXT_PATH_BUDGET_CHARS = 512;\nconst EXTENSION_DESCRIPTION_BUDGET_CHARS = 180;\n\nfunction compactPromptText(value: string, maxChars: number): string {\n\tconst normalized = value.replace(/\\s+/g, \" \").trim();\n\tif (normalized.length <= maxChars) return normalized;\n\tlet end = maxChars - 1;\n\tconst code = normalized.charCodeAt(end - 1);\n\tif (code >= 0xd800 && code <= 0xdbff) end--;\n\treturn `${normalized.slice(0, end)}…`;\n}\n\nfunction formatContextFilesForPrompt(\n\tcontextFiles: Array<{ path: string; content?: string }>,\n\toptions: { deferContents: boolean; canRead: boolean },\n): string {\n\tif (contextFiles.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst injected = options.deferContents ? [] : contextFiles.filter((file) => file.content !== undefined);\n\tconst deferred = options.deferContents ? contextFiles : contextFiles.filter((file) => file.content === undefined);\n\tconst parts: string[] = [];\n\n\tif (injected.length > 0) {\n\t\tconst lines = [\"\\n\\nPROJECT-SPECIFIC INSTRUCTIONS (apply in listed order)\"];\n\t\tconst seen = new Set<string>();\n\t\tfor (const { path, content } of injected) {\n\t\t\tconst identity = `${path}\\0${content ?? \"\"}`;\n\t\t\tif (seen.has(identity)) continue;\n\t\t\tseen.add(identity);\n\t\t\tlines.push(`FILE ${JSON.stringify(path)} (${(content ?? \"\").length} chars)`);\n\t\t\tlines.push(content ?? \"\");\n\t\t\tlines.push(\"END FILE\");\n\t\t}\n\t\tparts.push(lines.join(\"\\n\"));\n\t}\n\n\tif (deferred.length > 0) {\n\t\tconst lines = [\n\t\t\t\"\\n\\nPROJECT RULE PATHS — contents not preloaded.\",\n\t\t\toptions.deferContents\n\t\t\t\t? options.canRead\n\t\t\t\t\t? \"Before editing, writing, or running a mutating command, read each relevant listed file completely before any mutation. Follow its instructions; if a file cannot fit, ask for a scoped instruction digest.\"\n\t\t\t\t\t: \"No read tool is active. Ask the user for the relevant project instructions before giving project-specific guidance.\"\n\t\t\t\t: options.canRead\n\t\t\t\t\t? \"Read a listed file completely before following it. Do not assume its contents.\"\n\t\t\t\t\t: \"No read tool is active. Ask the user for the relevant project instructions before giving project-specific guidance.\",\n\t\t];\n\t\tlet pathChars = 0;\n\t\tlet included = 0;\n\t\tfor (const { path } of deferred) {\n\t\t\tconst line = `- ${JSON.stringify(path)}`;\n\t\t\tif (pathChars + line.length > DEFERRED_CONTEXT_PATH_BUDGET_CHARS) break;\n\t\t\tlines.push(line);\n\t\t\tpathChars += line.length + 1;\n\t\t\tincluded++;\n\t\t}\n\t\tconst omitted = deferred.length - included;\n\t\tif (omitted > 0) {\n\t\t\tlines.push(`- omitted=${omitted}`);\n\t\t\tlines.push(\n\t\t\t\t\"Do not mutate until the omitted instruction paths are supplied or a more capable profile is used.\",\n\t\t\t);\n\t\t}\n\t\tparts.push(lines.join(\"\\n\"));\n\t}\n\n\treturn parts.join(\"\");\n}\n\nfunction appendPromptResources(\n\tprompt: string,\n\toptions: {\n\t\tappendSection: string;\n\t\tcontextFiles: Array<{ path: string; content?: string }>;\n\t\textensions: Extension[];\n\t\tvisibleTools: string[];\n\t\tfullPrompt: boolean;\n\t\thasRead: boolean;\n\t\tdate: string;\n\t\tpromptCwd: string;\n\t\tmodelCapability: BuildSystemPromptOptions[\"modelCapability\"];\n\t},\n): string {\n\tlet result = prompt;\n\tif (options.appendSection) result += options.appendSection;\n\tresult += formatContextFilesForPrompt(options.contextFiles, {\n\t\tdeferContents: !options.fullPrompt,\n\t\tcanRead: options.hasRead,\n\t});\n\t// Extension metadata is redundant with the active tool snippets on constrained profiles.\n\tif (options.fullPrompt && options.extensions.length > 0) {\n\t\tresult += formatExtensionsForPrompt(options.extensions, options.visibleTools);\n\t}\n\t// Day-granularity only; keep this tail stable across every call on the same calendar day.\n\tresult += `\\nCurrent date: ${options.date}`;\n\tresult += `\\nCurrent working directory: ${options.promptCwd}`;\n\t// Prompt resources can come from CRLF checkouts or user files. Canonicalize once at the final\n\t// assembly boundary so capability budgets and provider cache keys are host-independent.\n\tconst normalizedResult = result.replace(/\\r\\n?/g, \"\\n\");\n\treturn options.modelCapability\n\t\t? enforceModelCapabilitySystemPromptBudget(normalizedResult, options.modelCapability)\n\t\t: normalizedResult;\n}\n\n/**\n * Build the system prompt with tools, guidelines, and context.\n *\n * CACHE-STABILITY INVARIANT: providers treat the returned string as ONE prompt-cache block (a\n * single cache breakpoint covering the whole system prompt). The caller (SystemPromptBuilder /\n * AgentSession, see `_rebuildSystemPrompt` in agent-session.ts) rebuilds it only when the TOOL\n * SURFACE changes — never per turn. For a fixed `options` (fixed tool surface, cwd, context\n * files, extensions), two calls on the SAME CALENDAR DAY must return byte-identical\n * output, because `date` below is deliberately truncated to Y-M-D granularity. Do NOT widen it\n * to a timestamp (HH:MM:SS) or otherwise fold in any per-turn-volatile field (turn counters,\n * elapsed time, random ids, etc.) — that would cache-bust this entire block on EVERY turn instead\n * of once per calendar day, defeating provider prompt caching (cost + latency regression on every\n * request). Pinned by test/system-prompt-stability.test.ts.\n */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t} = options;\n\tconst resolvedCwd = cwd;\n\tconst promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n\t// Day-granularity only (see cache-stability invariant on buildSystemPrompt above): this must\n\t// stay stable across every call within a calendar day, not just within a single turn.\n\tconst now = new Date();\n\tconst year = now.getFullYear();\n\tconst month = String(now.getMonth() + 1).padStart(2, \"0\");\n\tconst day = String(now.getDate()).padStart(2, \"0\");\n\tconst date = `${year}-${month}-${day}`;\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst capabilityClass = options.modelCapability?.class ?? \"full\";\n\tconst fullPrompt = capabilityClass === \"full\";\n\tconst leanPrompt = capabilityClass === \"lean\";\n\n\tconst activeTools = selectedTools || [\"read\", \"bash\", \"python\", \"edit\", \"write\"];\n\tconst visibleTools = activeTools.filter((name) => !!toolSnippets?.[name]);\n\tconst hasRead = activeTools.includes(\"read\");\n\tconst coreSection = fullPrompt\n\t\t? PI_ADAPTATIVE_CORE_SECTION\n\t\t: leanPrompt\n\t\t\t? PI_ADAPTATIVE_LEAN_CORE_SECTION\n\t\t\t: capabilityClass === \"minimal\"\n\t\t\t\t? PI_ADAPTATIVE_MINIMAL_CORE_SECTION\n\t\t\t\t: PI_ADAPTATIVE_CHAT_CORE_SECTION;\n\tconst skillVaultContract = activeTools.includes(\"skill\") ? `\\n\\n${SKILL_VAULT_SYSTEM_RULE}` : \"\";\n\tconst operatingContract = `${coreSection}${skillVaultContract}${ULTRA_TERSE_OUTPUT_POLICY}`;\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tprompt += operatingContract;\n\t\treturn appendPromptResources(prompt, {\n\t\t\tappendSection,\n\t\t\tcontextFiles,\n\t\t\textensions: options.extensions ?? [],\n\t\t\tvisibleTools,\n\t\t\tfullPrompt,\n\t\t\thasRead,\n\t\t\tdate,\n\t\t\tpromptCwd,\n\t\t\tmodelCapability: options.modelCapability,\n\t\t});\n\t}\n\n\tconst packageRoot = dirname(getReadmePath());\n\n\t// Build tools list based on selected tools.\n\t// A tool appears in Available tools only when the caller provides a one-line snippet.\n\tconst toolsList =\n\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join(\"\\n\") : \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = activeTools.includes(\"bash\");\n\tconst hasPython = activeTools.includes(\"python\");\n\tconst hasGrep = activeTools.includes(\"grep\");\n\tconst hasFind = activeTools.includes(\"find\");\n\tconst hasLs = activeTools.includes(\"ls\");\n\tconst hasReadOnlyTools = hasRead || hasGrep || hasFind || hasLs;\n\n\t// File exploration guidelines\n\tif (!fullPrompt && !leanPrompt) {\n\t\tif (hasBash) addGuideline(\"Use bash for bounded shell commands\");\n\t\tif (hasReadOnlyTools) addGuideline(\"Batch independent reads; keep mutations and dependent calls ordered\");\n\t} else if (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Bash: ls, rg, find\");\n\t}\n\tif (fullPrompt || leanPrompt) {\n\t\tif (hasBash || hasGrep || hasFind) {\n\t\t\taddGuideline(\"rg/jq: scoped roots/filters, exhaustive output to file\");\n\t\t}\n\t\tif (hasPython) {\n\t\t\taddGuideline(\"Python: bounded scripts/data, source edits via read/edit/write\");\n\t\t}\n\t\tif (hasReadOnlyTools) {\n\t\t\taddGuideline(\"Batch independent reads; order dependent/mutating/stateful calls\");\n\t\t}\n\t}\n\n\tif (fullPrompt || leanPrompt) {\n\t\tfor (const guideline of promptGuidelines ?? []) {\n\t\t\tconst normalized = guideline.trim();\n\t\t\tif (normalized.length > 0) {\n\t\t\t\taddGuideline(normalized);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\tconst toolGuidelinesSection = guidelines.length > 0 ? `\\n\\nTOOL GUIDELINES\\n\\n${guidelines}` : \"\";\n\n\tconst introduction = fullPrompt\n\t\t? \"Pi-Adaptative: self-evolving assistant. Deliver goals within authority; preserve continuity, own integration.\"\n\t\t: leanPrompt\n\t\t\t? \"Pi-Adaptative bounded coding agent. Complete current goal with active surface; preserve handoff evidence.\"\n\t\t\t: capabilityClass === \"minimal\"\n\t\t\t\t? \"Pi-Adaptative focused coding executor. Complete one scoped task with active tools; report verified results.\"\n\t\t\t\t: \"Pi-Adaptative concise chat assistant. No execution tools active.\";\n\tconst toolSurfaceRule =\n\t\tfullPrompt || leanPrompt\n\t\t\t? \"Use active tool surface only; unlisted capabilities may exist.\"\n\t\t\t: \"Use only the active tool surface.\";\n\tlet prompt = `${introduction}\n\nAvailable tools:\n${toolsList}\n\n${toolSurfaceRule}${operatingContract}${toolGuidelinesSection}`;\n\n\tif (fullPrompt) {\n\t\tprompt += `\n\nPI DOCS: root=${packageRoot}. Relevant work only; read needed README.md, \\`docs/...\\`, \\`examples/...\\` fully, follow links.`;\n\t}\n\n\treturn appendPromptResources(prompt, {\n\t\tappendSection,\n\t\tcontextFiles,\n\t\textensions: options.extensions ?? [],\n\t\tvisibleTools,\n\t\tfullPrompt,\n\t\thasRead,\n\t\tdate,\n\t\tpromptCwd,\n\t\tmodelCapability: options.modelCapability,\n\t});\n}\n\nfunction formatExtensionsForPrompt(extensions: Extension[], visibleTools: string[]): string {\n\tif (extensions.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst lines = [\"\\n\\nEXTENSIONS: name, path, tools, commands, description\"];\n\tlet added = 0;\n\n\tfor (const ext of extensions) {\n\t\tconst name = getExtensionDisplayName(ext.path);\n\t\tconst description = getExtensionDescription(ext.path);\n\n\t\tconst tools = Array.from(ext.tools.keys()).filter((t) => visibleTools.includes(t));\n\t\tconst commands = Array.from(ext.commands.keys());\n\n\t\t// Skip extension listing if it has no visible tools, commands, or description\n\t\tif (tools.length === 0 && commands.length === 0 && !description) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlines.push(\n\t\t\tJSON.stringify({\n\t\t\t\tname,\n\t\t\t\tpath: ext.path,\n\t\t\t\t...(tools.length > 0 ? { tools } : {}),\n\t\t\t\t...(commands.length > 0 ? { commands } : {}),\n\t\t\t\t...(description ? { description: compactPromptText(description, EXTENSION_DESCRIPTION_BUDGET_CHARS) } : {}),\n\t\t\t}),\n\t\t);\n\t\tadded++;\n\t}\n\n\tif (added === 0) {\n\t\treturn \"\";\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAE3F,OAAO,EAAE,wCAAwC,EAA+B,MAAM,uBAAuB,CAAC;AAC9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AA0BzE,MAAM,gCAAgC,GACrC,sIAAsI,CAAC;AAExI,MAAM,yBAAyB,GAAG;;;;;;;8LAO4J,CAAC;AAE/L,MAAM,0BAA0B,GAAG;;;;;;;;;;;;IAY/B,gCAAgC,EAAE,CAAC;AAEvC,MAAM,+BAA+B,GAAG;;;;;;iEAMyB,6BAA6B;;;IAG1F,gCAAgC,EAAE,CAAC;AAEvC,MAAM,kCAAkC,GAAG;;;;;iEAKsB,6BAA6B;;;IAG1F,gCAAgC,EAAE,CAAC;AAEvC,MAAM,+BAA+B,GAAG;;;;;;0FAMkD,CAAC;AAE3F,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAC/C,MAAM,kCAAkC,GAAG,G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,SAAS;QACV,CAAC;QAED,KAAK,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC;YACd,IAAI;YACJ,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5C,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,iBAAiB,CAAC,WAAW,EAAE,kCAAkC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3G,CAAC,CACF,CAAC;QACF,KAAK,EAAE,CAAC;IACT,CAAC;IAED,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { dirname } from \"node:path\";\nimport { TOOL_FAILURE_RETRY_MODEL_RULE } from \"@caupulican/pi-agent-core\";\nimport { getReadmePath } from \"../config.ts\";\nimport { getExtensionDescription, getExtensionDisplayName } from \"./extension-metadata.ts\";\nimport type { Extension } from \"./extensions/types.ts\";\nimport { enforceModelCapabilitySystemPromptBudget, type ModelCapabilityProfile } from \"./model-capability.ts\";\nimport { SKILL_VAULT_SYSTEM_RULE } from \"./provider-prompt-contracts.ts\";\nimport type { Skill } from \"./skills.ts\";\n\nexport interface BuildSystemPromptOptions {\n\t/** Capability profile that selects the stable prompt shape. Missing means full/legacy behavior. */\n\tmodelCapability?: Pick<ModelCapabilityProfile, \"class\" | \"contextWindow\" | \"reasonCode\" | \"systemPromptMaxChars\">;\n\t/** Custom system prompt (replaces default). */\n\tcustomPrompt?: string;\n\t/** Tools to include in the prompt. Defaults come from the shared active-tool surface. */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Global instruction files (with content) plus on-demand project paths (path only). */\n\tcontextFiles?: Array<{ path: string; content?: string }>;\n\t/** Discovered skills remain host-side; retained for extension/API construction compatibility. */\n\tskills?: Skill[];\n\t/** Discovered extensions currently active. */\n\textensions?: Extension[];\n}\n\nconst MODEL_BLIND_CREDENTIAL_AUTHORITY =\n\t\"Active secret_store: host gate authorizes model-blind activation/migration from named accessible sources; no duplicate confirmation.\";\n\nconst ULTRA_TERSE_OUTPUT_POLICY = `\n\nULTRA-TERSE OUTPUT\n\n- Drop articles/filler/pleasantries/hedging; fragments valid. Strip conjunctions only when clear; each fact once.\n- Never drop not/never/no/only/except; never invent abbreviations or use causal arrows. Preserve numbers, units, code symbols, function/API names, commands, errors.\n- No self-reference/tool narration/tables/emoji/log dumps. Keep user language. Full grammar: security, irreversible actions, ambiguous order. Replies terse; artifacts normal prose.\n- Answer shape: status/ops turns terse; analysis/review/evaluation asks get complete structured answers; never restate harness protocol text or failure-record JSON to the user as an answer.`;\n\nconst PI_ADAPTATIVE_CORE_SECTION = `\n\nOPERATING CONTRACT\n\n- Clear conversational outcome is goal; persist progress/evidence through compaction; finish or report blocker.\n- Hold scope; verify unknowns from primary sources; simplest proven design, one owner/path per invariant.\n- User outcome governs, method does not. Outcome risk: show evidence, test when practical, offer safest effective path, execute.\n- Work over 15 seconds: managed background run, event terminal, bounded handoff, owner notice; never poll.\n- Delegate independent work within host bounds; root integrates/verifies. Facts: memory, specialization: skills, behavior: source; discard noise.\n- Implementation/verification work loads skill evidence-gated-tdd; architecture/performance design loads skill n-plus-2-architecture; their gates bind only while that work is active.\n- Explicit user instruction in current message overrides standing style (length/format/tone); security, untrusted-content, and authorization rules are never overridable.\n- Ask before broader scope, credential or authentication change/disclosure, destructive action, publication. Bound, source-label output; show paths.\n- ${MODEL_BLIND_CREDENTIAL_AUTHORITY}`;\n\nconst PI_ADAPTATIVE_LEAN_CORE_SECTION = `\n\nOPERATING CONTRACT\n\n- Complete current goal within scope, granted authority; keep progress, evidence concise.\n- Inspect relevant files and instructions before editing; make minimal coherent change, run focused checks.\n- Use active tools/schemas. On failure, follow error guidance. ${TOOL_FAILURE_RETRY_MODEL_RULE}\n- Batch independent reads, order mutations; report real output, unresolved failures.\n- Ask before destructive actions, credential disclosure or provider authentication changes, publication, push/tag/release, scope expansion.\n- ${MODEL_BLIND_CREDENTIAL_AUTHORITY}`;\n\nconst PI_ADAPTATIVE_MINIMAL_CORE_SECTION = `\n\nEXECUTION RULES\n\n- Work one scoped task. Inspect before editing, make small coherent change, run narrowest useful check.\n- Use listed tools/schemas. On failure, follow error guidance. ${TOOL_FAILURE_RETRY_MODEL_RULE}\n- Batch independent reads, order mutations. Report actual results; never claim incomplete action.\n- Ask before destructive actions, credential disclosure or provider authentication changes, publication, push/tag/release, material scope change.\n- ${MODEL_BLIND_CREDENTIAL_AUTHORITY}`;\n\nconst PI_ADAPTATIVE_CHAT_CORE_SECTION = `\n\nCHAT RULES\n\n- Answer concisely from conversation; state uncertainty.\n- No execution tools are active. Do not claim to read files, run commands, or make changes.\n- Say when the request requires a tool-capable model or additional user-provided context.`;\n\nconst DEFERRED_CONTEXT_PATH_BUDGET_CHARS = 512;\nconst EXTENSION_DESCRIPTION_BUDGET_CHARS = 180;\n\nfunction compactPromptText(value: string, maxChars: number): string {\n\tconst normalized = value.replace(/\\s+/g, \" \").trim();\n\tif (normalized.length <= maxChars) return normalized;\n\tlet end = maxChars - 1;\n\tconst code = normalized.charCodeAt(end - 1);\n\tif (code >= 0xd800 && code <= 0xdbff) end--;\n\treturn `${normalized.slice(0, end)}…`;\n}\n\nfunction formatContextFilesForPrompt(\n\tcontextFiles: Array<{ path: string; content?: string }>,\n\toptions: { deferContents: boolean; canRead: boolean },\n): string {\n\tif (contextFiles.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst injected = options.deferContents ? [] : contextFiles.filter((file) => file.content !== undefined);\n\tconst deferred = options.deferContents ? contextFiles : contextFiles.filter((file) => file.content === undefined);\n\tconst parts: string[] = [];\n\n\tif (injected.length > 0) {\n\t\tconst lines = [\"\\n\\nPROJECT-SPECIFIC INSTRUCTIONS (apply in listed order)\"];\n\t\tconst seen = new Set<string>();\n\t\tfor (const { path, content } of injected) {\n\t\t\tconst identity = `${path}\\0${content ?? \"\"}`;\n\t\t\tif (seen.has(identity)) continue;\n\t\t\tseen.add(identity);\n\t\t\tlines.push(`FILE ${JSON.stringify(path)} (${(content ?? \"\").length} chars)`);\n\t\t\tlines.push(content ?? \"\");\n\t\t\tlines.push(\"END FILE\");\n\t\t}\n\t\tparts.push(lines.join(\"\\n\"));\n\t}\n\n\tif (deferred.length > 0) {\n\t\tconst lines = [\n\t\t\t\"\\n\\nPROJECT RULE PATHS — contents not preloaded.\",\n\t\t\toptions.deferContents\n\t\t\t\t? options.canRead\n\t\t\t\t\t? \"Before editing, writing, or running a mutating command, read each relevant listed file completely before any mutation. Follow its instructions; if a file cannot fit, ask for a scoped instruction digest.\"\n\t\t\t\t\t: \"No read tool is active. Ask the user for the relevant project instructions before giving project-specific guidance.\"\n\t\t\t\t: options.canRead\n\t\t\t\t\t? \"Read a listed file completely before following it. Do not assume its contents.\"\n\t\t\t\t\t: \"No read tool is active. Ask the user for the relevant project instructions before giving project-specific guidance.\",\n\t\t];\n\t\tlet pathChars = 0;\n\t\tlet included = 0;\n\t\tfor (const { path } of deferred) {\n\t\t\tconst line = `- ${JSON.stringify(path)}`;\n\t\t\tif (pathChars + line.length > DEFERRED_CONTEXT_PATH_BUDGET_CHARS) break;\n\t\t\tlines.push(line);\n\t\t\tpathChars += line.length + 1;\n\t\t\tincluded++;\n\t\t}\n\t\tconst omitted = deferred.length - included;\n\t\tif (omitted > 0) {\n\t\t\tlines.push(`- omitted=${omitted}`);\n\t\t\tlines.push(\n\t\t\t\t\"Do not mutate until the omitted instruction paths are supplied or a more capable profile is used.\",\n\t\t\t);\n\t\t}\n\t\tparts.push(lines.join(\"\\n\"));\n\t}\n\n\treturn parts.join(\"\");\n}\n\nfunction appendPromptResources(\n\tprompt: string,\n\toptions: {\n\t\tappendSection: string;\n\t\tcontextFiles: Array<{ path: string; content?: string }>;\n\t\textensions: Extension[];\n\t\tvisibleTools: string[];\n\t\tfullPrompt: boolean;\n\t\thasRead: boolean;\n\t\tdate: string;\n\t\tpromptCwd: string;\n\t\tmodelCapability: BuildSystemPromptOptions[\"modelCapability\"];\n\t},\n): string {\n\tlet result = prompt;\n\tif (options.appendSection) result += options.appendSection;\n\tresult += formatContextFilesForPrompt(options.contextFiles, {\n\t\tdeferContents: !options.fullPrompt,\n\t\tcanRead: options.hasRead,\n\t});\n\t// Extension metadata is redundant with the active tool snippets on constrained profiles.\n\tif (options.fullPrompt && options.extensions.length > 0) {\n\t\tresult += formatExtensionsForPrompt(options.extensions, options.visibleTools);\n\t}\n\t// Day-granularity only; keep this tail stable across every call on the same calendar day.\n\tresult += `\\nCurrent date: ${options.date}`;\n\tresult += `\\nCurrent working directory: ${options.promptCwd}`;\n\t// Prompt resources can come from CRLF checkouts or user files. Canonicalize once at the final\n\t// assembly boundary so capability budgets and provider cache keys are host-independent.\n\tconst normalizedResult = result.replace(/\\r\\n?/g, \"\\n\");\n\treturn options.modelCapability\n\t\t? enforceModelCapabilitySystemPromptBudget(normalizedResult, options.modelCapability)\n\t\t: normalizedResult;\n}\n\n/**\n * Build the system prompt with tools, guidelines, and context.\n *\n * CACHE-STABILITY INVARIANT: providers treat the returned string as ONE prompt-cache block (a\n * single cache breakpoint covering the whole system prompt). The caller (SystemPromptBuilder /\n * AgentSession, see `_rebuildSystemPrompt` in agent-session.ts) rebuilds it only when the TOOL\n * SURFACE changes — never per turn. For a fixed `options` (fixed tool surface, cwd, context\n * files, extensions), two calls on the SAME CALENDAR DAY must return byte-identical\n * output, because `date` below is deliberately truncated to Y-M-D granularity. Do NOT widen it\n * to a timestamp (HH:MM:SS) or otherwise fold in any per-turn-volatile field (turn counters,\n * elapsed time, random ids, etc.) — that would cache-bust this entire block on EVERY turn instead\n * of once per calendar day, defeating provider prompt caching (cost + latency regression on every\n * request). Pinned by test/system-prompt-stability.test.ts.\n */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t} = options;\n\tconst resolvedCwd = cwd;\n\tconst promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n\t// Day-granularity only (see cache-stability invariant on buildSystemPrompt above): this must\n\t// stay stable across every call within a calendar day, not just within a single turn.\n\tconst now = new Date();\n\tconst year = now.getFullYear();\n\tconst month = String(now.getMonth() + 1).padStart(2, \"0\");\n\tconst day = String(now.getDate()).padStart(2, \"0\");\n\tconst date = `${year}-${month}-${day}`;\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst capabilityClass = options.modelCapability?.class ?? \"full\";\n\tconst fullPrompt = capabilityClass === \"full\";\n\tconst leanPrompt = capabilityClass === \"lean\";\n\n\tconst activeTools = selectedTools || [\"read\", \"bash\", \"python\", \"edit\", \"write\"];\n\tconst visibleTools = activeTools.filter((name) => !!toolSnippets?.[name]);\n\tconst hasRead = activeTools.includes(\"read\");\n\tconst coreSection = fullPrompt\n\t\t? PI_ADAPTATIVE_CORE_SECTION\n\t\t: leanPrompt\n\t\t\t? PI_ADAPTATIVE_LEAN_CORE_SECTION\n\t\t\t: capabilityClass === \"minimal\"\n\t\t\t\t? PI_ADAPTATIVE_MINIMAL_CORE_SECTION\n\t\t\t\t: PI_ADAPTATIVE_CHAT_CORE_SECTION;\n\tconst skillVaultContract = activeTools.includes(\"skill\") ? `\\n\\n${SKILL_VAULT_SYSTEM_RULE}` : \"\";\n\tconst operatingContract = `${coreSection}${skillVaultContract}${ULTRA_TERSE_OUTPUT_POLICY}`;\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tprompt += operatingContract;\n\t\treturn appendPromptResources(prompt, {\n\t\t\tappendSection,\n\t\t\tcontextFiles,\n\t\t\textensions: options.extensions ?? [],\n\t\t\tvisibleTools,\n\t\t\tfullPrompt,\n\t\t\thasRead,\n\t\t\tdate,\n\t\t\tpromptCwd,\n\t\t\tmodelCapability: options.modelCapability,\n\t\t});\n\t}\n\n\tconst packageRoot = dirname(getReadmePath());\n\n\t// Build tools list based on selected tools.\n\t// A tool appears in Available tools only when the caller provides a one-line snippet.\n\tconst toolsList =\n\t\tvisibleTools.length > 0 ? visibleTools.map((name) => `- ${name}: ${toolSnippets![name]}`).join(\"\\n\") : \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasBash = activeTools.includes(\"bash\");\n\tconst hasPython = activeTools.includes(\"python\");\n\tconst hasGrep = activeTools.includes(\"grep\");\n\tconst hasFind = activeTools.includes(\"find\");\n\tconst hasLs = activeTools.includes(\"ls\");\n\tconst hasReadOnlyTools = hasRead || hasGrep || hasFind || hasLs;\n\n\t// File exploration guidelines\n\tif (!fullPrompt && !leanPrompt) {\n\t\tif (hasBash) addGuideline(\"Use bash for bounded shell commands\");\n\t\tif (hasReadOnlyTools) addGuideline(\"Batch independent reads; keep mutations and dependent calls ordered\");\n\t} else if (hasBash && !hasGrep && !hasFind && !hasLs) {\n\t\taddGuideline(\"Bash: ls, rg, find\");\n\t}\n\tif (fullPrompt || leanPrompt) {\n\t\tif (hasBash || hasGrep || hasFind) {\n\t\t\taddGuideline(\"rg/jq: scoped roots/filters, exhaustive output to file\");\n\t\t}\n\t\tif (hasPython) {\n\t\t\taddGuideline(\"Python: bounded scripts/data, source edits via read/edit/write\");\n\t\t}\n\t\tif (hasReadOnlyTools) {\n\t\t\taddGuideline(\"Batch independent reads; order dependent/mutating/stateful calls\");\n\t\t}\n\t}\n\n\tif (fullPrompt || leanPrompt) {\n\t\tfor (const guideline of promptGuidelines ?? []) {\n\t\t\tconst normalized = guideline.trim();\n\t\t\tif (normalized.length > 0) {\n\t\t\t\taddGuideline(normalized);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\tconst toolGuidelinesSection = guidelines.length > 0 ? `\\n\\nTOOL GUIDELINES\\n\\n${guidelines}` : \"\";\n\n\tconst introduction = fullPrompt\n\t\t? \"Pi-Adaptative: self-evolving assistant. Deliver goals within authority; preserve continuity, own integration.\"\n\t\t: leanPrompt\n\t\t\t? \"Pi-Adaptative bounded coding agent. Complete current goal with active surface; preserve handoff evidence.\"\n\t\t\t: capabilityClass === \"minimal\"\n\t\t\t\t? \"Pi-Adaptative focused coding executor. Complete one scoped task with active tools; report verified results.\"\n\t\t\t\t: \"Pi-Adaptative concise chat assistant. No execution tools active.\";\n\tconst toolSurfaceRule =\n\t\tfullPrompt || leanPrompt\n\t\t\t? \"Use active tool surface only; unlisted capabilities may exist.\"\n\t\t\t: \"Use only the active tool surface.\";\n\tlet prompt = `${introduction}\n\nAvailable tools:\n${toolsList}\n\n${toolSurfaceRule}${operatingContract}${toolGuidelinesSection}`;\n\n\tif (fullPrompt) {\n\t\tprompt += `\n\nPI DOCS: root=${packageRoot}. Relevant work only; read needed README.md, \\`docs/...\\`, \\`examples/...\\` fully, follow links.`;\n\t}\n\n\treturn appendPromptResources(prompt, {\n\t\tappendSection,\n\t\tcontextFiles,\n\t\textensions: options.extensions ?? [],\n\t\tvisibleTools,\n\t\tfullPrompt,\n\t\thasRead,\n\t\tdate,\n\t\tpromptCwd,\n\t\tmodelCapability: options.modelCapability,\n\t});\n}\n\nfunction formatExtensionsForPrompt(extensions: Extension[], visibleTools: string[]): string {\n\tif (extensions.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst lines = [\"\\n\\nEXTENSIONS: name, path, tools, commands, description\"];\n\tlet added = 0;\n\n\tfor (const ext of extensions) {\n\t\tconst name = getExtensionDisplayName(ext.path);\n\t\tconst description = getExtensionDescription(ext.path);\n\n\t\tconst tools = Array.from(ext.tools.keys()).filter((t) => visibleTools.includes(t));\n\t\tconst commands = Array.from(ext.commands.keys());\n\n\t\t// Skip extension listing if it has no visible tools, commands, or description\n\t\tif (tools.length === 0 && commands.length === 0 && !description) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlines.push(\n\t\t\tJSON.stringify({\n\t\t\t\tname,\n\t\t\t\tpath: ext.path,\n\t\t\t\t...(tools.length > 0 ? { tools } : {}),\n\t\t\t\t...(commands.length > 0 ? { commands } : {}),\n\t\t\t\t...(description ? { description: compactPromptText(description, EXTENSION_DESCRIPTION_BUDGET_CHARS) } : {}),\n\t\t\t}),\n\t\t);\n\t\tadded++;\n\t}\n\n\tif (added === 0) {\n\t\treturn \"\";\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
@@ -87,7 +87,7 @@ export declare function formatTaskSteps(state: TaskStepsState, options?: {
|
|
|
87
87
|
includeTerminal?: boolean;
|
|
88
88
|
maxItems?: number;
|
|
89
89
|
}): string;
|
|
90
|
-
export declare function formatTaskStepsContext(state: TaskStepsState, maxItems?: number
|
|
90
|
+
export declare function formatTaskStepsContext(state: TaskStepsState, maxItems?: number): string | undefined;
|
|
91
91
|
export declare function serializeTaskStepsState(state: TaskStepsState): string;
|
|
92
92
|
export declare function parseTaskStepsState(text: string): TaskStepsState | undefined;
|
|
93
93
|
//# sourceMappingURL=task-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-state.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/task-state.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,YAAI,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,CAAU,CAAC;AAC3G,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,eAAO,MAAM,oBAAoB,YAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AACvE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,4BAA4B,OAAQ,CAAC;AAOlD,eAAO,MAAM,oCAAoC,MAAM,CAAC;AAExD,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,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AQ,EAAE,MAAM,GAAG,QAAQ,CA0B9F;AAED,wBAAgB,cAAc,CAC7B,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,MAAM,GACT,cAAc,CAqDhB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,CAKjF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,CAYnF;AAED,wBAAgB,eAAe,CAC9B,KAAK,EAAE,cAAc,EACrB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5D,MAAM,CAqCR;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,SAAK,GAAG,MAAM,GAAG,SAAS,CA+B/F;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAErE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAO5E"}
|
|
@@ -416,7 +416,7 @@ export function formatTaskSteps(state, options = {}) {
|
|
|
416
416
|
}
|
|
417
417
|
return lines.join("\n");
|
|
418
418
|
}
|
|
419
|
-
export function formatTaskStepsContext(state, maxItems = 12
|
|
419
|
+
export function formatTaskStepsContext(state, maxItems = 12) {
|
|
420
420
|
const open = state.steps.filter((step) => step.status !== "completed" && step.status !== "cancelled");
|
|
421
421
|
if (open.length === 0)
|
|
422
422
|
return undefined;
|
|
@@ -435,9 +435,7 @@ export function formatTaskStepsContext(state, maxItems = 12, exhaustedRecovery =
|
|
|
435
435
|
lines.push(`- omitted=${open.length - limit}`);
|
|
436
436
|
const active = open.find((step) => step.status === "in_progress");
|
|
437
437
|
lines.push(active
|
|
438
|
-
?
|
|
439
|
-
? `FIRST: recovery exhausted for the last unchanged operation on in_progress step: ${active.activeForm || active.content}. Do not repeat that call. Change arguments/approach or set the step blocked/cancelled.`
|
|
440
|
-
: `FIRST: continue in_progress step: ${active.activeForm || active.content}. Evidence known: set completed/blocked/cancelled.`
|
|
438
|
+
? `FIRST: continue in_progress step: ${active.activeForm || active.content}. Evidence known: set completed/blocked/cancelled.`
|
|
441
439
|
: `No in_progress step. Start first: ${open[0].activeForm || open[0].content}.`, "Keep task_steps current; no stale in_progress before final.");
|
|
442
440
|
if (hasUnverifiedCompletedStep(state)) {
|
|
443
441
|
lines.push("Completed step lacks evidence; attach via task_steps before verified.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-state.js","sourceRoot":"","sources":["../../../src/core/tasks/task-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,CAAU,CAAC;AAG3G,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAGvE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAClC,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAClD,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AACvC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAC5C,MAAM,0BAA0B,GAAG,EAAE,CAAC;AACtC,MAAM,mCAAmC,GAAG,GAAG,CAAC;AAChD,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,CAAC;AAgExD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACxC,Y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;IACF,IAAI,0BAA0B,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,uEAAuE,CAAC,CAAC;IACrF,CAAC;IACD,+EAA+E;IAC/E,8FAA8F;IAC9F,gGAAgG;IAChG,wFAAwF;IACxF,OAAO,gCAAgC,KAAK,CAAC,QAAQ,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC;AACtG,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAqB;IAC5D,OAAO,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC/C,IAAI,CAAC;QACJ,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["import { MAX_PIPELINE_STAGE_ID_LENGTH } from \"../pipelines/types.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport const TASK_STEP_STATUSES = [\"pending\", \"in_progress\", \"completed\", \"blocked\", \"cancelled\"] as const;\nexport type TaskStepStatus = (typeof TASK_STEP_STATUSES)[number];\n\nexport const TASK_STEP_PRIORITIES = [\"low\", \"normal\", \"high\"] as const;\nexport type TaskStepPriority = (typeof TASK_STEP_PRIORITIES)[number];\n\nexport const MAX_TASK_STEPS = 100;\nexport const MAX_TASK_STEP_CONTENT_LENGTH = 2_000;\nconst MAX_TASK_STEP_NOTE_LENGTH = 4_000;\nconst MAX_TASK_STEP_OWNER_LENGTH = 200;\nconst MAX_TASK_STEP_EVIDENCE = 32;\nconst MAX_TASK_STEP_EVIDENCE_LENGTH = 2_000;\nconst MAX_TASK_STEP_REQUIREMENTS = 32;\nconst MAX_TASK_STEP_REQUIREMENT_ID_LENGTH = 200;\nexport const MAX_TASK_STEP_PIPELINE_RUN_ID_LENGTH = 128;\n\nexport interface TaskStepInput {\n\tcontent: string;\n\tactiveForm?: string;\n\tstatus?: TaskStepStatus;\n\tpriority?: TaskStepPriority;\n\towner?: string;\n\trequirementIds?: readonly string[];\n\tpipelineRunId?: string;\n\tpipelineStageId?: string;\n\tclearPipelineLink?: boolean;\n\tnote?: string;\n\tnotes?: readonly string[];\n\tevidence?: readonly string[];\n}\n\nexport interface TaskStep {\n\tid: string;\n\tcontent: string;\n\tactiveForm?: string;\n\tstatus: TaskStepStatus;\n\tpriority?: TaskStepPriority;\n\towner?: string;\n\t/** Goal requirements this foreground step advances. Optional only for snapshots from older sessions. */\n\trequirementIds?: readonly string[];\n\tpipelineRunId?: string;\n\tpipelineStageId?: string;\n\tnotes: readonly string[];\n\tevidence: readonly string[];\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface TaskStepsArchive {\n\tcompleted: number;\n\tcancelled: number;\n\tcompactedAt?: string;\n}\n\nexport interface TaskStepsState {\n\tversion: 1;\n\trevision: number;\n\tnextStepNumber: number;\n\tsteps: readonly TaskStep[];\n\tarchive: TaskStepsArchive;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface TaskStepUpdate {\n\tcontent?: string;\n\tactiveForm?: string;\n\tstatus?: TaskStepStatus;\n\tpriority?: TaskStepPriority;\n\towner?: string;\n\trequirementIds?: readonly string[];\n\tpipelineRunId?: string;\n\tpipelineStageId?: string;\n\tclearPipelineLink?: boolean;\n\tnote?: string;\n\tevidence?: readonly string[];\n}\n\nexport class TaskStepsError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TaskStepsError\";\n\t}\n}\n\nfunction isTaskStepStatus(value: unknown): value is TaskStepStatus {\n\treturn TASK_STEP_STATUSES.some((status) => status === value);\n}\n\nfunction isTaskStepPriority(value: unknown): value is TaskStepPriority {\n\treturn TASK_STEP_PRIORITIES.some((priority) => priority === value);\n}\n\nfunction hasOptionalString(record: Record<string, unknown>, key: string, maxLength: number): boolean {\n\tconst value = record[key];\n\treturn value === undefined || (typeof value === \"string\" && value.length <= maxLength);\n}\n\nfunction hasOptionalNormalizedString(record: Record<string, unknown>, key: string, maxLength: number): boolean {\n\tconst value = record[key];\n\treturn (\n\t\tvalue === undefined ||\n\t\t(typeof value === \"string\" && value.length > 0 && value.length <= maxLength && value.trim() === value)\n\t);\n}\n\nfunction isBoundedStringArray(value: unknown, maxItems: number, maxLength: number): value is readonly string[] {\n\treturn (\n\t\tArray.isArray(value) &&\n\t\tvalue.length <= maxItems &&\n\t\tvalue.every((item) => typeof item === \"string\" && item.length > 0 && item.length <= maxLength)\n\t);\n}\n\nfunction isTaskStep(value: unknown): value is TaskStep {\n\tif (!isPlainRecord(value)) return false;\n\treturn (\n\t\ttypeof value.id === \"string\" &&\n\t\t/^step-[1-9]\\d*$/.test(value.id) &&\n\t\ttypeof value.content === \"string\" &&\n\t\tvalue.content.length > 0 &&\n\t\tvalue.content.length <= MAX_TASK_STEP_CONTENT_LENGTH &&\n\t\thasOptionalString(value, \"activeForm\", MAX_TASK_STEP_CONTENT_LENGTH) &&\n\t\tisTaskStepStatus(value.status) &&\n\t\t(value.priority === undefined || isTaskStepPriority(value.priority)) &&\n\t\thasOptionalString(value, \"owner\", MAX_TASK_STEP_OWNER_LENGTH) &&\n\t\t(value.requirementIds === undefined ||\n\t\t\tisBoundedStringArray(value.requirementIds, MAX_TASK_STEP_REQUIREMENTS, MAX_TASK_STEP_REQUIREMENT_ID_LENGTH)) &&\n\t\thasOptionalNormalizedString(value, \"pipelineRunId\", MAX_TASK_STEP_PIPELINE_RUN_ID_LENGTH) &&\n\t\thasOptionalNormalizedString(value, \"pipelineStageId\", MAX_PIPELINE_STAGE_ID_LENGTH) &&\n\t\t(value.pipelineRunId === undefined) === (value.pipelineStageId === undefined) &&\n\t\tisBoundedStringArray(value.notes, MAX_TASK_STEP_EVIDENCE, MAX_TASK_STEP_NOTE_LENGTH) &&\n\t\tisBoundedStringArray(value.evidence, MAX_TASK_STEP_EVIDENCE, MAX_TASK_STEP_EVIDENCE_LENGTH) &&\n\t\ttypeof value.createdAt === \"string\" &&\n\t\ttypeof value.updatedAt === \"string\"\n\t);\n}\n\nfunction isTaskStepsArchive(value: unknown): value is TaskStepsArchive {\n\tif (!isPlainRecord(value)) return false;\n\treturn (\n\t\tNumber.isInteger(value.completed) &&\n\t\tNumber(value.completed) >= 0 &&\n\t\tNumber.isInteger(value.cancelled) &&\n\t\tNumber(value.cancelled) >= 0 &&\n\t\thasOptionalString(value, \"compactedAt\", 100)\n\t);\n}\n\nexport function isTaskStepsState(value: unknown): value is TaskStepsState {\n\tif (!isPlainRecord(value)) return false;\n\tif (\n\t\tvalue.version !== 1 ||\n\t\t!Number.isInteger(value.revision) ||\n\t\tNumber(value.revision) < 0 ||\n\t\t!Number.isInteger(value.nextStepNumber) ||\n\t\tNumber(value.nextStepNumber) < 1 ||\n\t\t!Array.isArray(value.steps) ||\n\t\tvalue.steps.length > MAX_TASK_STEPS ||\n\t\t!value.steps.every(isTaskStep) ||\n\t\t!isTaskStepsArchive(value.archive) ||\n\t\ttypeof value.createdAt !== \"string\" ||\n\t\ttypeof value.updatedAt !== \"string\"\n\t) {\n\t\treturn false;\n\t}\n\tconst ids = new Set(value.steps.map((step) => step.id));\n\treturn ids.size === value.steps.length && value.steps.filter((step) => step.status === \"in_progress\").length <= 1;\n}\n\nfunction cloneTaskStep(step: TaskStep): TaskStep {\n\treturn {\n\t\t...step,\n\t\trequirementIds: [...(step.requirementIds ?? [])],\n\t\tnotes: [...step.notes],\n\t\tevidence: [...step.evidence],\n\t};\n}\n\nexport function cloneTaskStepsState(state: TaskStepsState): TaskStepsState {\n\treturn {\n\t\t...state,\n\t\tsteps: state.steps.map(cloneTaskStep),\n\t\tarchive: { ...state.archive },\n\t};\n}\n\nexport function createTaskStepsState(now: string): TaskStepsState {\n\treturn {\n\t\tversion: 1,\n\t\trevision: 0,\n\t\tnextStepNumber: 1,\n\t\tsteps: [],\n\t\tarchive: { completed: 0, cancelled: 0 },\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n}\n\nfunction requireBoundedText(value: string, label: string, maxLength: number): string {\n\tconst normalized = value.trim();\n\tif (!normalized) throw new TaskStepsError(`${label} is required.`);\n\tif (normalized.length > maxLength) throw new TaskStepsError(`${label} must be at most ${maxLength} characters.`);\n\treturn normalized;\n}\n\nfunction optionalBoundedText(value: string | undefined, label: string, maxLength: number): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst normalized = value.trim();\n\tif (!normalized) return undefined;\n\tif (normalized.length > maxLength) throw new TaskStepsError(`${label} must be at most ${maxLength} characters.`);\n\treturn normalized;\n}\n\nfunction normalizeStrings(values: readonly string[] | undefined, label: string, maxLength: number): string[] {\n\tif (!values) return [];\n\tconst normalized: string[] = [];\n\tfor (const value of values) {\n\t\tconst item = requireBoundedText(value, label, maxLength);\n\t\tif (!normalized.includes(item)) normalized.push(item);\n\t}\n\tif (normalized.length > MAX_TASK_STEP_EVIDENCE) {\n\t\tthrow new TaskStepsError(`${label} supports at most ${MAX_TASK_STEP_EVIDENCE} entries.`);\n\t}\n\treturn normalized;\n}\n\nfunction appendUniqueStrings(\n\tcurrent: readonly string[],\n\tvalues: readonly string[] | undefined,\n\tlabel: string,\n\tmaxLength: number,\n): string[] {\n\tconst appended = [...current];\n\tfor (const value of normalizeStrings(values, label, maxLength)) {\n\t\tif (!appended.includes(value)) appended.push(value);\n\t}\n\tif (appended.length > MAX_TASK_STEP_EVIDENCE) {\n\t\tthrow new TaskStepsError(`${label} supports at most ${MAX_TASK_STEP_EVIDENCE} entries.`);\n\t}\n\treturn appended;\n}\n\nfunction normalizeInputNotes(input: TaskStepInput): string[] {\n\tconst notes = normalizeStrings(input.notes, \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH);\n\tconst note = optionalBoundedText(input.note, \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH);\n\tif (note && !notes.includes(note)) notes.push(note);\n\treturn notes;\n}\n\nexport function normalizeTaskStepPipelineLink(\n\tpipelineRunId: string | undefined,\n\tpipelineStageId: string | undefined,\n\tclearPipelineLink = false,\n): Pick<TaskStep, \"pipelineRunId\" | \"pipelineStageId\"> {\n\tif (clearPipelineLink) {\n\t\tif (pipelineRunId !== undefined || pipelineStageId !== undefined) {\n\t\t\tthrow new TaskStepsError(\"Task step cannot supply pipeline ids while clearPipelineLink is true.\");\n\t\t}\n\t\treturn {};\n\t}\n\tconst runId = optionalBoundedText(pipelineRunId, \"Task step pipeline run id\", MAX_TASK_STEP_PIPELINE_RUN_ID_LENGTH);\n\tconst stageId = optionalBoundedText(pipelineStageId, \"Task step pipeline stage id\", MAX_PIPELINE_STAGE_ID_LENGTH);\n\tif ((runId === undefined) !== (stageId === undefined)) {\n\t\tthrow new TaskStepsError(\"Task step pipelineRunId and pipelineStageId must be supplied together.\");\n\t}\n\treturn runId && stageId ? { pipelineRunId: runId, pipelineStageId: stageId } : {};\n}\n\n/**\n * Find an OPEN (non-terminal) step whose content matches `content` case-insensitively.\n * Terminal steps (completed/cancelled) are deliberately excluded so a legitimate re-add of\n * previously finished work still creates a new step.\n */\nexport function findOpenDuplicateStep(steps: readonly TaskStep[], content: string): TaskStep | undefined {\n\tconst normalized = content.trim().toLocaleLowerCase();\n\tif (!normalized) return undefined;\n\treturn steps.find(\n\t\t(step) =>\n\t\t\tstep.status !== \"completed\" && step.status !== \"cancelled\" && step.content.toLocaleLowerCase() === normalized,\n\t);\n}\n\n/** True when a completed step has no evidence attached (a verification nudge candidate). */\nexport function hasUnverifiedCompletedStep(state: TaskStepsState): boolean {\n\treturn state.steps.some((step) => step.status === \"completed\" && step.evidence.length === 0);\n}\n\nfunction demoteOtherActiveSteps(steps: TaskStep[], activeIndex: number): void {\n\tfor (let index = 0; index < steps.length; index++) {\n\t\tif (index !== activeIndex && steps[index].status === \"in_progress\") {\n\t\t\tsteps[index] = { ...steps[index], status: \"pending\" };\n\t\t}\n\t}\n}\n\nfunction nextState(state: TaskStepsState, steps: readonly TaskStep[], now: string): TaskStepsState {\n\treturn {\n\t\t...state,\n\t\trevision: state.revision + 1,\n\t\tsteps: steps.map(cloneTaskStep),\n\t\tarchive: { ...state.archive },\n\t\tupdatedAt: now,\n\t};\n}\n\nfunction createStep(args: {\n\tinput: TaskStepInput;\n\tid: string;\n\tcreatedAt: string;\n\tupdatedAt: string;\n\texisting?: TaskStep;\n}): TaskStep {\n\tconst existing = args.existing;\n\tconst notes =\n\t\targs.input.note === undefined && args.input.notes === undefined\n\t\t\t? [...(existing?.notes ?? [])]\n\t\t\t: normalizeInputNotes(args.input);\n\tconst evidence =\n\t\targs.input.evidence === undefined\n\t\t\t? [...(existing?.evidence ?? [])]\n\t\t\t: normalizeStrings(args.input.evidence, \"Task step evidence\", MAX_TASK_STEP_EVIDENCE_LENGTH);\n\tconst requirementIds =\n\t\targs.input.requirementIds === undefined\n\t\t\t? [...(existing?.requirementIds ?? [])]\n\t\t\t: normalizeStrings(args.input.requirementIds, \"Task step requirement id\", MAX_TASK_STEP_REQUIREMENT_ID_LENGTH);\n\tconst pipelineLink = args.input.clearPipelineLink\n\t\t? normalizeTaskStepPipelineLink(args.input.pipelineRunId, args.input.pipelineStageId, true)\n\t\t: normalizeTaskStepPipelineLink(\n\t\t\t\targs.input.pipelineRunId === undefined ? existing?.pipelineRunId : args.input.pipelineRunId,\n\t\t\t\targs.input.pipelineStageId === undefined ? existing?.pipelineStageId : args.input.pipelineStageId,\n\t\t\t);\n\treturn {\n\t\tid: args.id,\n\t\tcontent: requireBoundedText(args.input.content, \"Task step content\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tactiveForm:\n\t\t\targs.input.activeForm === undefined\n\t\t\t\t? existing?.activeForm\n\t\t\t\t: optionalBoundedText(args.input.activeForm, \"Task step active form\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tstatus: args.input.status ?? existing?.status ?? \"pending\",\n\t\tpriority: args.input.priority ?? existing?.priority,\n\t\towner:\n\t\t\targs.input.owner === undefined\n\t\t\t\t? existing?.owner\n\t\t\t\t: optionalBoundedText(args.input.owner, \"Task step owner\", MAX_TASK_STEP_OWNER_LENGTH),\n\t\trequirementIds,\n\t\t...pipelineLink,\n\t\tnotes,\n\t\tevidence,\n\t\tcreatedAt: args.createdAt,\n\t\tupdatedAt: args.updatedAt,\n\t};\n}\n\nexport function setTaskSteps(state: TaskStepsState, inputs: readonly TaskStepInput[], now: string): TaskStepsState {\n\tif (inputs.length > MAX_TASK_STEPS) {\n\t\tthrow new TaskStepsError(`Task steps supports at most ${MAX_TASK_STEPS} steps.`);\n\t}\n\tconst existingByContent = new Map<string, TaskStep[]>();\n\tfor (const step of state.steps) {\n\t\tconst key = step.content.toLocaleLowerCase();\n\t\tconst matches = existingByContent.get(key) ?? [];\n\t\tmatches.push(step);\n\t\texistingByContent.set(key, matches);\n\t}\n\n\tlet nextStepNumber = state.nextStepNumber;\n\tconst steps = inputs.map((input) => {\n\t\tconst content = requireBoundedText(input.content, \"Task step content\", MAX_TASK_STEP_CONTENT_LENGTH);\n\t\tconst matches = existingByContent.get(content.toLocaleLowerCase());\n\t\tconst existing = matches?.shift();\n\t\tconst id = existing?.id ?? `step-${nextStepNumber++}`;\n\t\treturn createStep({\n\t\t\tinput: { ...input, content },\n\t\t\tid,\n\t\t\tcreatedAt: existing?.createdAt ?? now,\n\t\t\tupdatedAt: now,\n\t\t\texisting,\n\t\t});\n\t});\n\tconst activeIndex = steps.findLastIndex((step) => step.status === \"in_progress\");\n\tif (activeIndex >= 0) demoteOtherActiveSteps(steps, activeIndex);\n\treturn { ...nextState(state, steps, now), nextStepNumber };\n}\n\nexport function addTaskStep(state: TaskStepsState, input: TaskStepInput, now: string): TaskStepsState {\n\t// Dedupe against OPEN steps only, before the capacity check: a duplicate re-add of an\n\t// already-open step is a no-op regardless of whether the list happens to be full. Terminal\n\t// (completed/cancelled) matches are excluded so a legitimate re-add still creates a step.\n\tif (findOpenDuplicateStep(state.steps, input.content)) return state;\n\tif (state.steps.length >= MAX_TASK_STEPS) {\n\t\tthrow new TaskStepsError(`Task steps already has the maximum ${MAX_TASK_STEPS} steps.`);\n\t}\n\tconst step = createStep({ input, id: `step-${state.nextStepNumber}`, createdAt: now, updatedAt: now });\n\tconst steps = [...state.steps.map(cloneTaskStep), step];\n\tif (step.status === \"in_progress\") demoteOtherActiveSteps(steps, steps.length - 1);\n\treturn { ...nextState(state, steps, now), nextStepNumber: state.nextStepNumber + 1 };\n}\n\nexport function resolveTaskStepSelector(steps: readonly TaskStep[], selector: string): TaskStep {\n\tconst normalized = selector.trim().toLocaleLowerCase();\n\tif (!normalized) throw new TaskStepsError(\"Task step selector is required.\");\n\tif (normalized === \"current\" || normalized === \"active\") {\n\t\tconst active = steps.find((step) => step.status === \"in_progress\");\n\t\tif (!active) throw new TaskStepsError(\"No in_progress task step was found.\");\n\t\treturn active;\n\t}\n\n\tconst exactId = steps.find((step) => step.id.toLocaleLowerCase() === normalized);\n\tif (exactId) return exactId;\n\tconst idPrefix = steps.filter((step) => step.id.toLocaleLowerCase().startsWith(normalized));\n\tif (idPrefix.length === 1) return idPrefix[0];\n\tif (idPrefix.length > 1) {\n\t\tthrow new TaskStepsError(`Task step selector is ambiguous: ${idPrefix.map((step) => step.id).join(\", \")}.`);\n\t}\n\n\tconst exactContent = steps.filter((step) => step.content.toLocaleLowerCase() === normalized);\n\tif (exactContent.length === 1) return exactContent[0];\n\tconst contentMatches = steps.filter((step) => step.content.toLocaleLowerCase().includes(normalized));\n\tif (contentMatches.length === 1) return contentMatches[0];\n\tif (exactContent.length > 1 || contentMatches.length > 1) {\n\t\tconst matches = exactContent.length > 1 ? exactContent : contentMatches;\n\t\tthrow new TaskStepsError(`Task step selector is ambiguous: ${matches.map((step) => step.id).join(\", \")}.`);\n\t}\n\tthrow new TaskStepsError(`Task step not found for selector: ${selector}.`);\n}\n\nexport function updateTaskStep(\n\tstate: TaskStepsState,\n\tselector: string,\n\tupdate: TaskStepUpdate,\n\tnow: string,\n): TaskStepsState {\n\tconst selected = resolveTaskStepSelector(state.steps, selector);\n\tconst selectedIndex = state.steps.findIndex((step) => step.id === selected.id);\n\tconst steps = state.steps.map(cloneTaskStep);\n\tconst current = steps[selectedIndex];\n\tconst note = optionalBoundedText(update.note, \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH);\n\tconst notes = note\n\t\t? appendUniqueStrings(current.notes, [note], \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH)\n\t\t: [...current.notes];\n\tconst evidence = appendUniqueStrings(\n\t\tcurrent.evidence,\n\t\tupdate.evidence,\n\t\t\"Task step evidence\",\n\t\tMAX_TASK_STEP_EVIDENCE_LENGTH,\n\t);\n\tconst pipelineLink = update.clearPipelineLink\n\t\t? normalizeTaskStepPipelineLink(update.pipelineRunId, update.pipelineStageId, true)\n\t\t: normalizeTaskStepPipelineLink(\n\t\t\t\tupdate.pipelineRunId === undefined ? current.pipelineRunId : update.pipelineRunId,\n\t\t\t\tupdate.pipelineStageId === undefined ? current.pipelineStageId : update.pipelineStageId,\n\t\t\t);\n\tconst nextStep: TaskStep = {\n\t\t...current,\n\t\tcontent:\n\t\t\tupdate.content === undefined\n\t\t\t\t? current.content\n\t\t\t\t: requireBoundedText(update.content, \"Task step content\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tactiveForm:\n\t\t\tupdate.activeForm === undefined\n\t\t\t\t? current.activeForm\n\t\t\t\t: optionalBoundedText(update.activeForm, \"Task step active form\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tstatus: update.status ?? current.status,\n\t\tpriority: update.priority ?? current.priority,\n\t\towner:\n\t\t\tupdate.owner === undefined\n\t\t\t\t? current.owner\n\t\t\t\t: optionalBoundedText(update.owner, \"Task step owner\", MAX_TASK_STEP_OWNER_LENGTH),\n\t\trequirementIds:\n\t\t\tupdate.requirementIds === undefined\n\t\t\t\t? [...(current.requirementIds ?? [])]\n\t\t\t\t: normalizeStrings(update.requirementIds, \"Task step requirement id\", MAX_TASK_STEP_REQUIREMENT_ID_LENGTH),\n\t\t...pipelineLink,\n\t\tnotes,\n\t\tevidence,\n\t\tupdatedAt: now,\n\t};\n\tif (!pipelineLink.pipelineRunId) {\n\t\tdelete nextStep.pipelineRunId;\n\t\tdelete nextStep.pipelineStageId;\n\t}\n\tsteps[selectedIndex] = nextStep;\n\tif (steps[selectedIndex].status === \"in_progress\") demoteOtherActiveSteps(steps, selectedIndex);\n\treturn nextState(state, steps, now);\n}\n\nexport function clearTaskSteps(state: TaskStepsState, now: string): TaskStepsState {\n\treturn {\n\t\t...nextState(state, [], now),\n\t\tarchive: { completed: 0, cancelled: 0 },\n\t};\n}\n\nexport function compactTaskSteps(state: TaskStepsState, now: string): TaskStepsState {\n\tconst completed = state.steps.filter((step) => step.status === \"completed\").length;\n\tconst cancelled = state.steps.filter((step) => step.status === \"cancelled\").length;\n\tconst open = state.steps.filter((step) => step.status !== \"completed\" && step.status !== \"cancelled\");\n\treturn {\n\t\t...nextState(state, open, now),\n\t\tarchive: {\n\t\t\tcompleted: state.archive.completed + completed,\n\t\t\tcancelled: state.archive.cancelled + cancelled,\n\t\t\tcompactedAt: now,\n\t\t},\n\t};\n}\n\nexport function formatTaskSteps(\n\tstate: TaskStepsState,\n\toptions: { includeTerminal?: boolean; maxItems?: number } = {},\n): string {\n\tconst visible = options.includeTerminal\n\t\t? state.steps\n\t\t: state.steps.filter((step) => step.status !== \"completed\" && step.status !== \"cancelled\");\n\tconst maxItems = Math.max(1, Math.min(MAX_TASK_STEPS, Math.floor(options.maxItems ?? 20)));\n\tconst statusMarker: Record<TaskStepStatus, string> = {\n\t\tpending: \" \",\n\t\tin_progress: \">\",\n\t\tcompleted: \"x\",\n\t\tblocked: \"!\",\n\t\tcancelled: \"-\",\n\t};\n\tconst lines = [`Task steps (${visible.length} visible, ${state.steps.length} tracked):`];\n\tfor (const step of visible.slice(0, maxItems)) {\n\t\tconst details = [\n\t\t\tstep.priority,\n\t\t\tstep.owner,\n\t\t\tstep.requirementIds?.length ? `requirements: ${step.requirementIds.join(\", \")}` : undefined,\n\t\t\tstep.pipelineRunId && step.pipelineStageId\n\t\t\t\t? `pipeline: ${step.pipelineRunId}/${step.pipelineStageId}`\n\t\t\t\t: undefined,\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\", \");\n\t\tlines.push(\n\t\t\t`- [${statusMarker[step.status]}] ${step.id} ${step.activeForm || step.content}${details ? ` (${details})` : \"\"}`,\n\t\t);\n\t\tfor (const note of step.notes.slice(-2)) lines.push(` note: ${note}`);\n\t\tfor (const evidence of step.evidence.slice(-2)) lines.push(` evidence: ${evidence}`);\n\t}\n\tif (visible.length > maxItems) lines.push(`- … ${visible.length - maxItems} more`);\n\tif (state.archive.completed || state.archive.cancelled) {\n\t\tlines.push(\n\t\t\t`Archived terminal steps: ${state.archive.completed} completed, ${state.archive.cancelled} cancelled.`,\n\t\t);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatTaskStepsContext(\n\tstate: TaskStepsState,\n\tmaxItems = 12,\n\texhaustedRecovery = false,\n): string | undefined {\n\tconst open = state.steps.filter((step) => step.status !== \"completed\" && step.status !== \"cancelled\");\n\tif (open.length === 0) return undefined;\n\tconst limit = Math.max(1, Math.min(MAX_TASK_STEPS, Math.floor(maxItems)));\n\tconst lines = [\n\t\t\"TASK STEPS\",\n\t\t...open.slice(0, limit).map((step) => {\n\t\t\tconst label = step.activeForm || step.content;\n\t\t\tconst requirementIds = step.requirementIds?.length ? ` requirements=${step.requirementIds.join(\",\")}` : \"\";\n\t\t\tconst pipeline =\n\t\t\t\tstep.pipelineRunId && step.pipelineStageId ? ` pipeline=${step.pipelineRunId}/${step.pipelineStageId}` : \"\";\n\t\t\tconst evidence = step.evidence?.length ? ` evidence=${step.evidence.join(\",\")}` : \"\";\n\t\t\treturn `- [${step.status}] ${label}${requirementIds}${pipeline}${evidence}`;\n\t\t}),\n\t];\n\tif (open.length > limit) lines.push(`- omitted=${open.length - limit}`);\n\tconst active = open.find((step) => step.status === \"in_progress\");\n\tlines.push(\n\t\tactive\n\t\t\t? exhaustedRecovery\n\t\t\t\t? `FIRST: recovery exhausted for the last unchanged operation on in_progress step: ${active.activeForm || active.content}. Do not repeat that call. Change arguments/approach or set the step blocked/cancelled.`\n\t\t\t\t: `FIRST: continue in_progress step: ${active.activeForm || active.content}. Evidence known: set completed/blocked/cancelled.`\n\t\t\t: `No in_progress step. Start first: ${open[0].activeForm || open[0].content}.`,\n\t\t\"Keep task_steps current; no stale in_progress before final.\",\n\t);\n\tif (hasUnverifiedCompletedStep(state)) {\n\t\tlines.push(\"Completed step lacks evidence; attach via task_steps before verified.\");\n\t}\n\t// Wrapped in a marker (mirrors the <memory_context> precedent) so context-gc's\n\t// semantic-memory packer can recognize this as a deterministic, re-derivable context page and\n\t// pack stale copies down to the most recent one instead of letting a full page accumulate every\n\t// turn. The revision (monotonic per mutation) lets a reader tell which page is current.\n\treturn `<task_steps_context revision=${state.revision}>\\n${lines.join(\"\\n\")}\\n</task_steps_context>`;\n}\n\nexport function serializeTaskStepsState(state: TaskStepsState): string {\n\treturn JSON.stringify(cloneTaskStepsState(state), null, 2);\n}\n\nexport function parseTaskStepsState(text: string): TaskStepsState | undefined {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(text);\n\t\treturn isTaskStepsState(parsed) ? cloneTaskStepsState(parsed) : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"task-state.js","sourceRoot":"","sources":["../../../src/core/tasks/task-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,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ent":["import { MAX_PIPELINE_STAGE_ID_LENGTH } from \"../pipelines/types.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport const TASK_STEP_STATUSES = [\"pending\", \"in_progress\", \"completed\", \"blocked\", \"cancelled\"] as const;\nexport type TaskStepStatus = (typeof TASK_STEP_STATUSES)[number];\n\nexport const TASK_STEP_PRIORITIES = [\"low\", \"normal\", \"high\"] as const;\nexport type TaskStepPriority = (typeof TASK_STEP_PRIORITIES)[number];\n\nexport const MAX_TASK_STEPS = 100;\nexport const MAX_TASK_STEP_CONTENT_LENGTH = 2_000;\nconst MAX_TASK_STEP_NOTE_LENGTH = 4_000;\nconst MAX_TASK_STEP_OWNER_LENGTH = 200;\nconst MAX_TASK_STEP_EVIDENCE = 32;\nconst MAX_TASK_STEP_EVIDENCE_LENGTH = 2_000;\nconst MAX_TASK_STEP_REQUIREMENTS = 32;\nconst MAX_TASK_STEP_REQUIREMENT_ID_LENGTH = 200;\nexport const MAX_TASK_STEP_PIPELINE_RUN_ID_LENGTH = 128;\n\nexport interface TaskStepInput {\n\tcontent: string;\n\tactiveForm?: string;\n\tstatus?: TaskStepStatus;\n\tpriority?: TaskStepPriority;\n\towner?: string;\n\trequirementIds?: readonly string[];\n\tpipelineRunId?: string;\n\tpipelineStageId?: string;\n\tclearPipelineLink?: boolean;\n\tnote?: string;\n\tnotes?: readonly string[];\n\tevidence?: readonly string[];\n}\n\nexport interface TaskStep {\n\tid: string;\n\tcontent: string;\n\tactiveForm?: string;\n\tstatus: TaskStepStatus;\n\tpriority?: TaskStepPriority;\n\towner?: string;\n\t/** Goal requirements this foreground step advances. Optional only for snapshots from older sessions. */\n\trequirementIds?: readonly string[];\n\tpipelineRunId?: string;\n\tpipelineStageId?: string;\n\tnotes: readonly string[];\n\tevidence: readonly string[];\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface TaskStepsArchive {\n\tcompleted: number;\n\tcancelled: number;\n\tcompactedAt?: string;\n}\n\nexport interface TaskStepsState {\n\tversion: 1;\n\trevision: number;\n\tnextStepNumber: number;\n\tsteps: readonly TaskStep[];\n\tarchive: TaskStepsArchive;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface TaskStepUpdate {\n\tcontent?: string;\n\tactiveForm?: string;\n\tstatus?: TaskStepStatus;\n\tpriority?: TaskStepPriority;\n\towner?: string;\n\trequirementIds?: readonly string[];\n\tpipelineRunId?: string;\n\tpipelineStageId?: string;\n\tclearPipelineLink?: boolean;\n\tnote?: string;\n\tevidence?: readonly string[];\n}\n\nexport class TaskStepsError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TaskStepsError\";\n\t}\n}\n\nfunction isTaskStepStatus(value: unknown): value is TaskStepStatus {\n\treturn TASK_STEP_STATUSES.some((status) => status === value);\n}\n\nfunction isTaskStepPriority(value: unknown): value is TaskStepPriority {\n\treturn TASK_STEP_PRIORITIES.some((priority) => priority === value);\n}\n\nfunction hasOptionalString(record: Record<string, unknown>, key: string, maxLength: number): boolean {\n\tconst value = record[key];\n\treturn value === undefined || (typeof value === \"string\" && value.length <= maxLength);\n}\n\nfunction hasOptionalNormalizedString(record: Record<string, unknown>, key: string, maxLength: number): boolean {\n\tconst value = record[key];\n\treturn (\n\t\tvalue === undefined ||\n\t\t(typeof value === \"string\" && value.length > 0 && value.length <= maxLength && value.trim() === value)\n\t);\n}\n\nfunction isBoundedStringArray(value: unknown, maxItems: number, maxLength: number): value is readonly string[] {\n\treturn (\n\t\tArray.isArray(value) &&\n\t\tvalue.length <= maxItems &&\n\t\tvalue.every((item) => typeof item === \"string\" && item.length > 0 && item.length <= maxLength)\n\t);\n}\n\nfunction isTaskStep(value: unknown): value is TaskStep {\n\tif (!isPlainRecord(value)) return false;\n\treturn (\n\t\ttypeof value.id === \"string\" &&\n\t\t/^step-[1-9]\\d*$/.test(value.id) &&\n\t\ttypeof value.content === \"string\" &&\n\t\tvalue.content.length > 0 &&\n\t\tvalue.content.length <= MAX_TASK_STEP_CONTENT_LENGTH &&\n\t\thasOptionalString(value, \"activeForm\", MAX_TASK_STEP_CONTENT_LENGTH) &&\n\t\tisTaskStepStatus(value.status) &&\n\t\t(value.priority === undefined || isTaskStepPriority(value.priority)) &&\n\t\thasOptionalString(value, \"owner\", MAX_TASK_STEP_OWNER_LENGTH) &&\n\t\t(value.requirementIds === undefined ||\n\t\t\tisBoundedStringArray(value.requirementIds, MAX_TASK_STEP_REQUIREMENTS, MAX_TASK_STEP_REQUIREMENT_ID_LENGTH)) &&\n\t\thasOptionalNormalizedString(value, \"pipelineRunId\", MAX_TASK_STEP_PIPELINE_RUN_ID_LENGTH) &&\n\t\thasOptionalNormalizedString(value, \"pipelineStageId\", MAX_PIPELINE_STAGE_ID_LENGTH) &&\n\t\t(value.pipelineRunId === undefined) === (value.pipelineStageId === undefined) &&\n\t\tisBoundedStringArray(value.notes, MAX_TASK_STEP_EVIDENCE, MAX_TASK_STEP_NOTE_LENGTH) &&\n\t\tisBoundedStringArray(value.evidence, MAX_TASK_STEP_EVIDENCE, MAX_TASK_STEP_EVIDENCE_LENGTH) &&\n\t\ttypeof value.createdAt === \"string\" &&\n\t\ttypeof value.updatedAt === \"string\"\n\t);\n}\n\nfunction isTaskStepsArchive(value: unknown): value is TaskStepsArchive {\n\tif (!isPlainRecord(value)) return false;\n\treturn (\n\t\tNumber.isInteger(value.completed) &&\n\t\tNumber(value.completed) >= 0 &&\n\t\tNumber.isInteger(value.cancelled) &&\n\t\tNumber(value.cancelled) >= 0 &&\n\t\thasOptionalString(value, \"compactedAt\", 100)\n\t);\n}\n\nexport function isTaskStepsState(value: unknown): value is TaskStepsState {\n\tif (!isPlainRecord(value)) return false;\n\tif (\n\t\tvalue.version !== 1 ||\n\t\t!Number.isInteger(value.revision) ||\n\t\tNumber(value.revision) < 0 ||\n\t\t!Number.isInteger(value.nextStepNumber) ||\n\t\tNumber(value.nextStepNumber) < 1 ||\n\t\t!Array.isArray(value.steps) ||\n\t\tvalue.steps.length > MAX_TASK_STEPS ||\n\t\t!value.steps.every(isTaskStep) ||\n\t\t!isTaskStepsArchive(value.archive) ||\n\t\ttypeof value.createdAt !== \"string\" ||\n\t\ttypeof value.updatedAt !== \"string\"\n\t) {\n\t\treturn false;\n\t}\n\tconst ids = new Set(value.steps.map((step) => step.id));\n\treturn ids.size === value.steps.length && value.steps.filter((step) => step.status === \"in_progress\").length <= 1;\n}\n\nfunction cloneTaskStep(step: TaskStep): TaskStep {\n\treturn {\n\t\t...step,\n\t\trequirementIds: [...(step.requirementIds ?? [])],\n\t\tnotes: [...step.notes],\n\t\tevidence: [...step.evidence],\n\t};\n}\n\nexport function cloneTaskStepsState(state: TaskStepsState): TaskStepsState {\n\treturn {\n\t\t...state,\n\t\tsteps: state.steps.map(cloneTaskStep),\n\t\tarchive: { ...state.archive },\n\t};\n}\n\nexport function createTaskStepsState(now: string): TaskStepsState {\n\treturn {\n\t\tversion: 1,\n\t\trevision: 0,\n\t\tnextStepNumber: 1,\n\t\tsteps: [],\n\t\tarchive: { completed: 0, cancelled: 0 },\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n}\n\nfunction requireBoundedText(value: string, label: string, maxLength: number): string {\n\tconst normalized = value.trim();\n\tif (!normalized) throw new TaskStepsError(`${label} is required.`);\n\tif (normalized.length > maxLength) throw new TaskStepsError(`${label} must be at most ${maxLength} characters.`);\n\treturn normalized;\n}\n\nfunction optionalBoundedText(value: string | undefined, label: string, maxLength: number): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst normalized = value.trim();\n\tif (!normalized) return undefined;\n\tif (normalized.length > maxLength) throw new TaskStepsError(`${label} must be at most ${maxLength} characters.`);\n\treturn normalized;\n}\n\nfunction normalizeStrings(values: readonly string[] | undefined, label: string, maxLength: number): string[] {\n\tif (!values) return [];\n\tconst normalized: string[] = [];\n\tfor (const value of values) {\n\t\tconst item = requireBoundedText(value, label, maxLength);\n\t\tif (!normalized.includes(item)) normalized.push(item);\n\t}\n\tif (normalized.length > MAX_TASK_STEP_EVIDENCE) {\n\t\tthrow new TaskStepsError(`${label} supports at most ${MAX_TASK_STEP_EVIDENCE} entries.`);\n\t}\n\treturn normalized;\n}\n\nfunction appendUniqueStrings(\n\tcurrent: readonly string[],\n\tvalues: readonly string[] | undefined,\n\tlabel: string,\n\tmaxLength: number,\n): string[] {\n\tconst appended = [...current];\n\tfor (const value of normalizeStrings(values, label, maxLength)) {\n\t\tif (!appended.includes(value)) appended.push(value);\n\t}\n\tif (appended.length > MAX_TASK_STEP_EVIDENCE) {\n\t\tthrow new TaskStepsError(`${label} supports at most ${MAX_TASK_STEP_EVIDENCE} entries.`);\n\t}\n\treturn appended;\n}\n\nfunction normalizeInputNotes(input: TaskStepInput): string[] {\n\tconst notes = normalizeStrings(input.notes, \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH);\n\tconst note = optionalBoundedText(input.note, \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH);\n\tif (note && !notes.includes(note)) notes.push(note);\n\treturn notes;\n}\n\nexport function normalizeTaskStepPipelineLink(\n\tpipelineRunId: string | undefined,\n\tpipelineStageId: string | undefined,\n\tclearPipelineLink = false,\n): Pick<TaskStep, \"pipelineRunId\" | \"pipelineStageId\"> {\n\tif (clearPipelineLink) {\n\t\tif (pipelineRunId !== undefined || pipelineStageId !== undefined) {\n\t\t\tthrow new TaskStepsError(\"Task step cannot supply pipeline ids while clearPipelineLink is true.\");\n\t\t}\n\t\treturn {};\n\t}\n\tconst runId = optionalBoundedText(pipelineRunId, \"Task step pipeline run id\", MAX_TASK_STEP_PIPELINE_RUN_ID_LENGTH);\n\tconst stageId = optionalBoundedText(pipelineStageId, \"Task step pipeline stage id\", MAX_PIPELINE_STAGE_ID_LENGTH);\n\tif ((runId === undefined) !== (stageId === undefined)) {\n\t\tthrow new TaskStepsError(\"Task step pipelineRunId and pipelineStageId must be supplied together.\");\n\t}\n\treturn runId && stageId ? { pipelineRunId: runId, pipelineStageId: stageId } : {};\n}\n\n/**\n * Find an OPEN (non-terminal) step whose content matches `content` case-insensitively.\n * Terminal steps (completed/cancelled) are deliberately excluded so a legitimate re-add of\n * previously finished work still creates a new step.\n */\nexport function findOpenDuplicateStep(steps: readonly TaskStep[], content: string): TaskStep | undefined {\n\tconst normalized = content.trim().toLocaleLowerCase();\n\tif (!normalized) return undefined;\n\treturn steps.find(\n\t\t(step) =>\n\t\t\tstep.status !== \"completed\" && step.status !== \"cancelled\" && step.content.toLocaleLowerCase() === normalized,\n\t);\n}\n\n/** True when a completed step has no evidence attached (a verification nudge candidate). */\nexport function hasUnverifiedCompletedStep(state: TaskStepsState): boolean {\n\treturn state.steps.some((step) => step.status === \"completed\" && step.evidence.length === 0);\n}\n\nfunction demoteOtherActiveSteps(steps: TaskStep[], activeIndex: number): void {\n\tfor (let index = 0; index < steps.length; index++) {\n\t\tif (index !== activeIndex && steps[index].status === \"in_progress\") {\n\t\t\tsteps[index] = { ...steps[index], status: \"pending\" };\n\t\t}\n\t}\n}\n\nfunction nextState(state: TaskStepsState, steps: readonly TaskStep[], now: string): TaskStepsState {\n\treturn {\n\t\t...state,\n\t\trevision: state.revision + 1,\n\t\tsteps: steps.map(cloneTaskStep),\n\t\tarchive: { ...state.archive },\n\t\tupdatedAt: now,\n\t};\n}\n\nfunction createStep(args: {\n\tinput: TaskStepInput;\n\tid: string;\n\tcreatedAt: string;\n\tupdatedAt: string;\n\texisting?: TaskStep;\n}): TaskStep {\n\tconst existing = args.existing;\n\tconst notes =\n\t\targs.input.note === undefined && args.input.notes === undefined\n\t\t\t? [...(existing?.notes ?? [])]\n\t\t\t: normalizeInputNotes(args.input);\n\tconst evidence =\n\t\targs.input.evidence === undefined\n\t\t\t? [...(existing?.evidence ?? [])]\n\t\t\t: normalizeStrings(args.input.evidence, \"Task step evidence\", MAX_TASK_STEP_EVIDENCE_LENGTH);\n\tconst requirementIds =\n\t\targs.input.requirementIds === undefined\n\t\t\t? [...(existing?.requirementIds ?? [])]\n\t\t\t: normalizeStrings(args.input.requirementIds, \"Task step requirement id\", MAX_TASK_STEP_REQUIREMENT_ID_LENGTH);\n\tconst pipelineLink = args.input.clearPipelineLink\n\t\t? normalizeTaskStepPipelineLink(args.input.pipelineRunId, args.input.pipelineStageId, true)\n\t\t: normalizeTaskStepPipelineLink(\n\t\t\t\targs.input.pipelineRunId === undefined ? existing?.pipelineRunId : args.input.pipelineRunId,\n\t\t\t\targs.input.pipelineStageId === undefined ? existing?.pipelineStageId : args.input.pipelineStageId,\n\t\t\t);\n\treturn {\n\t\tid: args.id,\n\t\tcontent: requireBoundedText(args.input.content, \"Task step content\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tactiveForm:\n\t\t\targs.input.activeForm === undefined\n\t\t\t\t? existing?.activeForm\n\t\t\t\t: optionalBoundedText(args.input.activeForm, \"Task step active form\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tstatus: args.input.status ?? existing?.status ?? \"pending\",\n\t\tpriority: args.input.priority ?? existing?.priority,\n\t\towner:\n\t\t\targs.input.owner === undefined\n\t\t\t\t? existing?.owner\n\t\t\t\t: optionalBoundedText(args.input.owner, \"Task step owner\", MAX_TASK_STEP_OWNER_LENGTH),\n\t\trequirementIds,\n\t\t...pipelineLink,\n\t\tnotes,\n\t\tevidence,\n\t\tcreatedAt: args.createdAt,\n\t\tupdatedAt: args.updatedAt,\n\t};\n}\n\nexport function setTaskSteps(state: TaskStepsState, inputs: readonly TaskStepInput[], now: string): TaskStepsState {\n\tif (inputs.length > MAX_TASK_STEPS) {\n\t\tthrow new TaskStepsError(`Task steps supports at most ${MAX_TASK_STEPS} steps.`);\n\t}\n\tconst existingByContent = new Map<string, TaskStep[]>();\n\tfor (const step of state.steps) {\n\t\tconst key = step.content.toLocaleLowerCase();\n\t\tconst matches = existingByContent.get(key) ?? [];\n\t\tmatches.push(step);\n\t\texistingByContent.set(key, matches);\n\t}\n\n\tlet nextStepNumber = state.nextStepNumber;\n\tconst steps = inputs.map((input) => {\n\t\tconst content = requireBoundedText(input.content, \"Task step content\", MAX_TASK_STEP_CONTENT_LENGTH);\n\t\tconst matches = existingByContent.get(content.toLocaleLowerCase());\n\t\tconst existing = matches?.shift();\n\t\tconst id = existing?.id ?? `step-${nextStepNumber++}`;\n\t\treturn createStep({\n\t\t\tinput: { ...input, content },\n\t\t\tid,\n\t\t\tcreatedAt: existing?.createdAt ?? now,\n\t\t\tupdatedAt: now,\n\t\t\texisting,\n\t\t});\n\t});\n\tconst activeIndex = steps.findLastIndex((step) => step.status === \"in_progress\");\n\tif (activeIndex >= 0) demoteOtherActiveSteps(steps, activeIndex);\n\treturn { ...nextState(state, steps, now), nextStepNumber };\n}\n\nexport function addTaskStep(state: TaskStepsState, input: TaskStepInput, now: string): TaskStepsState {\n\t// Dedupe against OPEN steps only, before the capacity check: a duplicate re-add of an\n\t// already-open step is a no-op regardless of whether the list happens to be full. Terminal\n\t// (completed/cancelled) matches are excluded so a legitimate re-add still creates a step.\n\tif (findOpenDuplicateStep(state.steps, input.content)) return state;\n\tif (state.steps.length >= MAX_TASK_STEPS) {\n\t\tthrow new TaskStepsError(`Task steps already has the maximum ${MAX_TASK_STEPS} steps.`);\n\t}\n\tconst step = createStep({ input, id: `step-${state.nextStepNumber}`, createdAt: now, updatedAt: now });\n\tconst steps = [...state.steps.map(cloneTaskStep), step];\n\tif (step.status === \"in_progress\") demoteOtherActiveSteps(steps, steps.length - 1);\n\treturn { ...nextState(state, steps, now), nextStepNumber: state.nextStepNumber + 1 };\n}\n\nexport function resolveTaskStepSelector(steps: readonly TaskStep[], selector: string): TaskStep {\n\tconst normalized = selector.trim().toLocaleLowerCase();\n\tif (!normalized) throw new TaskStepsError(\"Task step selector is required.\");\n\tif (normalized === \"current\" || normalized === \"active\") {\n\t\tconst active = steps.find((step) => step.status === \"in_progress\");\n\t\tif (!active) throw new TaskStepsError(\"No in_progress task step was found.\");\n\t\treturn active;\n\t}\n\n\tconst exactId = steps.find((step) => step.id.toLocaleLowerCase() === normalized);\n\tif (exactId) return exactId;\n\tconst idPrefix = steps.filter((step) => step.id.toLocaleLowerCase().startsWith(normalized));\n\tif (idPrefix.length === 1) return idPrefix[0];\n\tif (idPrefix.length > 1) {\n\t\tthrow new TaskStepsError(`Task step selector is ambiguous: ${idPrefix.map((step) => step.id).join(\", \")}.`);\n\t}\n\n\tconst exactContent = steps.filter((step) => step.content.toLocaleLowerCase() === normalized);\n\tif (exactContent.length === 1) return exactContent[0];\n\tconst contentMatches = steps.filter((step) => step.content.toLocaleLowerCase().includes(normalized));\n\tif (contentMatches.length === 1) return contentMatches[0];\n\tif (exactContent.length > 1 || contentMatches.length > 1) {\n\t\tconst matches = exactContent.length > 1 ? exactContent : contentMatches;\n\t\tthrow new TaskStepsError(`Task step selector is ambiguous: ${matches.map((step) => step.id).join(\", \")}.`);\n\t}\n\tthrow new TaskStepsError(`Task step not found for selector: ${selector}.`);\n}\n\nexport function updateTaskStep(\n\tstate: TaskStepsState,\n\tselector: string,\n\tupdate: TaskStepUpdate,\n\tnow: string,\n): TaskStepsState {\n\tconst selected = resolveTaskStepSelector(state.steps, selector);\n\tconst selectedIndex = state.steps.findIndex((step) => step.id === selected.id);\n\tconst steps = state.steps.map(cloneTaskStep);\n\tconst current = steps[selectedIndex];\n\tconst note = optionalBoundedText(update.note, \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH);\n\tconst notes = note\n\t\t? appendUniqueStrings(current.notes, [note], \"Task step note\", MAX_TASK_STEP_NOTE_LENGTH)\n\t\t: [...current.notes];\n\tconst evidence = appendUniqueStrings(\n\t\tcurrent.evidence,\n\t\tupdate.evidence,\n\t\t\"Task step evidence\",\n\t\tMAX_TASK_STEP_EVIDENCE_LENGTH,\n\t);\n\tconst pipelineLink = update.clearPipelineLink\n\t\t? normalizeTaskStepPipelineLink(update.pipelineRunId, update.pipelineStageId, true)\n\t\t: normalizeTaskStepPipelineLink(\n\t\t\t\tupdate.pipelineRunId === undefined ? current.pipelineRunId : update.pipelineRunId,\n\t\t\t\tupdate.pipelineStageId === undefined ? current.pipelineStageId : update.pipelineStageId,\n\t\t\t);\n\tconst nextStep: TaskStep = {\n\t\t...current,\n\t\tcontent:\n\t\t\tupdate.content === undefined\n\t\t\t\t? current.content\n\t\t\t\t: requireBoundedText(update.content, \"Task step content\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tactiveForm:\n\t\t\tupdate.activeForm === undefined\n\t\t\t\t? current.activeForm\n\t\t\t\t: optionalBoundedText(update.activeForm, \"Task step active form\", MAX_TASK_STEP_CONTENT_LENGTH),\n\t\tstatus: update.status ?? current.status,\n\t\tpriority: update.priority ?? current.priority,\n\t\towner:\n\t\t\tupdate.owner === undefined\n\t\t\t\t? current.owner\n\t\t\t\t: optionalBoundedText(update.owner, \"Task step owner\", MAX_TASK_STEP_OWNER_LENGTH),\n\t\trequirementIds:\n\t\t\tupdate.requirementIds === undefined\n\t\t\t\t? [...(current.requirementIds ?? [])]\n\t\t\t\t: normalizeStrings(update.requirementIds, \"Task step requirement id\", MAX_TASK_STEP_REQUIREMENT_ID_LENGTH),\n\t\t...pipelineLink,\n\t\tnotes,\n\t\tevidence,\n\t\tupdatedAt: now,\n\t};\n\tif (!pipelineLink.pipelineRunId) {\n\t\tdelete nextStep.pipelineRunId;\n\t\tdelete nextStep.pipelineStageId;\n\t}\n\tsteps[selectedIndex] = nextStep;\n\tif (steps[selectedIndex].status === \"in_progress\") demoteOtherActiveSteps(steps, selectedIndex);\n\treturn nextState(state, steps, now);\n}\n\nexport function clearTaskSteps(state: TaskStepsState, now: string): TaskStepsState {\n\treturn {\n\t\t...nextState(state, [], now),\n\t\tarchive: { completed: 0, cancelled: 0 },\n\t};\n}\n\nexport function compactTaskSteps(state: TaskStepsState, now: string): TaskStepsState {\n\tconst completed = state.steps.filter((step) => step.status === \"completed\").length;\n\tconst cancelled = state.steps.filter((step) => step.status === \"cancelled\").length;\n\tconst open = state.steps.filter((step) => step.status !== \"completed\" && step.status !== \"cancelled\");\n\treturn {\n\t\t...nextState(state, open, now),\n\t\tarchive: {\n\t\t\tcompleted: state.archive.completed + completed,\n\t\t\tcancelled: state.archive.cancelled + cancelled,\n\t\t\tcompactedAt: now,\n\t\t},\n\t};\n}\n\nexport function formatTaskSteps(\n\tstate: TaskStepsState,\n\toptions: { includeTerminal?: boolean; maxItems?: number } = {},\n): string {\n\tconst visible = options.includeTerminal\n\t\t? state.steps\n\t\t: state.steps.filter((step) => step.status !== \"completed\" && step.status !== \"cancelled\");\n\tconst maxItems = Math.max(1, Math.min(MAX_TASK_STEPS, Math.floor(options.maxItems ?? 20)));\n\tconst statusMarker: Record<TaskStepStatus, string> = {\n\t\tpending: \" \",\n\t\tin_progress: \">\",\n\t\tcompleted: \"x\",\n\t\tblocked: \"!\",\n\t\tcancelled: \"-\",\n\t};\n\tconst lines = [`Task steps (${visible.length} visible, ${state.steps.length} tracked):`];\n\tfor (const step of visible.slice(0, maxItems)) {\n\t\tconst details = [\n\t\t\tstep.priority,\n\t\t\tstep.owner,\n\t\t\tstep.requirementIds?.length ? `requirements: ${step.requirementIds.join(\", \")}` : undefined,\n\t\t\tstep.pipelineRunId && step.pipelineStageId\n\t\t\t\t? `pipeline: ${step.pipelineRunId}/${step.pipelineStageId}`\n\t\t\t\t: undefined,\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\", \");\n\t\tlines.push(\n\t\t\t`- [${statusMarker[step.status]}] ${step.id} ${step.activeForm || step.content}${details ? ` (${details})` : \"\"}`,\n\t\t);\n\t\tfor (const note of step.notes.slice(-2)) lines.push(` note: ${note}`);\n\t\tfor (const evidence of step.evidence.slice(-2)) lines.push(` evidence: ${evidence}`);\n\t}\n\tif (visible.length > maxItems) lines.push(`- … ${visible.length - maxItems} more`);\n\tif (state.archive.completed || state.archive.cancelled) {\n\t\tlines.push(\n\t\t\t`Archived terminal steps: ${state.archive.completed} completed, ${state.archive.cancelled} cancelled.`,\n\t\t);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatTaskStepsContext(state: TaskStepsState, maxItems = 12): string | undefined {\n\tconst open = state.steps.filter((step) => step.status !== \"completed\" && step.status !== \"cancelled\");\n\tif (open.length === 0) return undefined;\n\tconst limit = Math.max(1, Math.min(MAX_TASK_STEPS, Math.floor(maxItems)));\n\tconst lines = [\n\t\t\"TASK STEPS\",\n\t\t...open.slice(0, limit).map((step) => {\n\t\t\tconst label = step.activeForm || step.content;\n\t\t\tconst requirementIds = step.requirementIds?.length ? ` requirements=${step.requirementIds.join(\",\")}` : \"\";\n\t\t\tconst pipeline =\n\t\t\t\tstep.pipelineRunId && step.pipelineStageId ? ` pipeline=${step.pipelineRunId}/${step.pipelineStageId}` : \"\";\n\t\t\tconst evidence = step.evidence?.length ? ` evidence=${step.evidence.join(\",\")}` : \"\";\n\t\t\treturn `- [${step.status}] ${label}${requirementIds}${pipeline}${evidence}`;\n\t\t}),\n\t];\n\tif (open.length > limit) lines.push(`- omitted=${open.length - limit}`);\n\tconst active = open.find((step) => step.status === \"in_progress\");\n\tlines.push(\n\t\tactive\n\t\t\t? `FIRST: continue in_progress step: ${active.activeForm || active.content}. Evidence known: set completed/blocked/cancelled.`\n\t\t\t: `No in_progress step. Start first: ${open[0].activeForm || open[0].content}.`,\n\t\t\"Keep task_steps current; no stale in_progress before final.\",\n\t);\n\tif (hasUnverifiedCompletedStep(state)) {\n\t\tlines.push(\"Completed step lacks evidence; attach via task_steps before verified.\");\n\t}\n\t// Wrapped in a marker (mirrors the <memory_context> precedent) so context-gc's\n\t// semantic-memory packer can recognize this as a deterministic, re-derivable context page and\n\t// pack stale copies down to the most recent one instead of letting a full page accumulate every\n\t// turn. The revision (monotonic per mutation) lets a reader tell which page is current.\n\treturn `<task_steps_context revision=${state.revision}>\\n${lines.join(\"\\n\")}\\n</task_steps_context>`;\n}\n\nexport function serializeTaskStepsState(state: TaskStepsState): string {\n\treturn JSON.stringify(cloneTaskStepsState(state), null, 2);\n}\n\nexport function parseTaskStepsState(text: string): TaskStepsState | undefined {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(text);\n\t\treturn isTaskStepsState(parsed) ? cloneTaskStepsState(parsed) : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TruncationResult } from "@caupulican/pi-agent-core/truncate";
|
|
2
|
-
import type
|
|
2
|
+
import { type AgentTool } from "@caupulican/pi-agent-core/types";
|
|
3
3
|
import { type Static, Type } from "typebox";
|
|
4
4
|
import type { ToolDefinition } from "../extensions/types.ts";
|
|
5
5
|
import { type FileFailureRecoveryAuthority } from "./file-failure-recovery.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAIA,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAIA,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,iCAAiC,CAAC;AAI1F,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAc5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AACtF,OAAO,EACN,KAAK,4BAA4B,EAIjC,MAAM,4BAA4B,CAAC;AAYpC,OAAO,EAGN,KAAK,4BAA4B,EACjC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAsC,KAAK,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAK/G,qGAAqG;AACrG,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAKhD,kGAAkG;AAClG,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,MAAM,GAAG,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vF,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD,iGAAiG;IACjG,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,4FAA4F;IAC5F,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAkpBD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAGhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
|
package/dist/core/tools/bash.js
CHANGED
|
@@ -3,6 +3,7 @@ import { constants } from "node:fs";
|
|
|
3
3
|
import { access as fsAccess } from "node:fs/promises";
|
|
4
4
|
import { createSilenceWatchdog } from "@caupulican/pi-agent-core/reliability";
|
|
5
5
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, } from "@caupulican/pi-agent-core/truncate";
|
|
6
|
+
import { AgentToolExecutionError } from "@caupulican/pi-agent-core/types";
|
|
6
7
|
import { TOOL_OPERATION_REJECTED_MARKER } from "@caupulican/pi-ai/tool-repair-registry";
|
|
7
8
|
import { Container, Text, truncateToWidth } from "@caupulican/pi-tui";
|
|
8
9
|
import { spawn } from "child_process";
|
|
@@ -661,6 +662,10 @@ function createShellToolDefinition(cwd, backendShell, contractPlatform, options)
|
|
|
661
662
|
return { text, details };
|
|
662
663
|
};
|
|
663
664
|
const appendStatus = (text, status) => `${text ? `${text}\n\n` : ""}${status}`;
|
|
665
|
+
// The shell ran the command to completion and is reporting the process's own status. That is
|
|
666
|
+
// the observation the caller asked for — a red test run, a search that matched nothing, a
|
|
667
|
+
// false predicate — so it is an operation outcome, never a failure of this tool.
|
|
668
|
+
const createExitError = (text, exitCode, effectiveCwd) => new AgentToolExecutionError(appendStatus(text, `Command exited with code ${exitCode}\ncwd: ${effectiveCwd}`), `exit_${exitCode}`, output.getOutputSignature(), "operation_outcome");
|
|
664
669
|
const effectiveTimeoutSeconds = typeof timeout === "number" && Number.isFinite(timeout) && timeout > 0
|
|
665
670
|
? resolveCommandTimeoutSeconds(timeout)
|
|
666
671
|
: (commandTimeoutMsOverride ?? DEFAULT_COMMAND_TIMEOUT_SECONDS * 1000) / 1000;
|
|
@@ -675,7 +680,7 @@ function createShellToolDefinition(cwd, backendShell, contractPlatform, options)
|
|
|
675
680
|
if (res.exitCode !== 0) {
|
|
676
681
|
const { text: rawOutputText } = formatOutput(snapshot);
|
|
677
682
|
// executeFilteredGit runs at the host cwd by construction.
|
|
678
|
-
throw
|
|
683
|
+
throw createExitError(rawOutputText, res.exitCode, cwd);
|
|
679
684
|
}
|
|
680
685
|
const details = snapshot.truncation.truncated
|
|
681
686
|
? {
|
|
@@ -773,7 +778,7 @@ function createShellToolDefinition(cwd, backendShell, contractPlatform, options)
|
|
|
773
778
|
const reportedCwd = routesWindowsContract
|
|
774
779
|
? resolveEffectiveCwd(getOrCreateWindowsShellState(sessionKey), cwd)
|
|
775
780
|
: (sessionCwd ?? spawnContext.cwd);
|
|
776
|
-
throw
|
|
781
|
+
throw createExitError(outputText, exitCode, reportedCwd);
|
|
777
782
|
}
|
|
778
783
|
return { content: [{ type: "text", text: outputText }], details };
|
|
779
784
|
}
|