@ponythewhite/base-context 1.0.11 → 1.0.12
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 +11 -0
- package/dist/base-context-runtime/pyproject.toml +1 -1
- package/dist/base-context-runtime/uv.lock +1 -1
- package/dist/build-info.json +1 -1
- package/dist/bundle/amazon-bedrock.js +3 -3
- package/dist/bundle/{anthropic-5PSCZEER.js → anthropic-BJVPUMPB.js} +2 -2
- package/dist/bundle/{azure-openai-responses-AYTLJR33.js → azure-openai-responses-ERRMAXK6.js} +4 -5
- package/dist/bundle/{bundled-modules-PEFT72QN.js → bundled-modules-WCGPZI2H.js} +5 -5
- package/dist/bundle/{chunk-D3KOF57W.js → chunk-25VYRAC6.js} +14 -1
- package/dist/bundle/{chunk-2IPDSTDR.js → chunk-AEMRBMI2.js} +9 -9
- package/dist/bundle/{chunk-Q3MBSBEB.js → chunk-FOGKLC7V.js} +1 -1
- package/dist/bundle/{chunk-JZHGOOFM.js → chunk-IAKHCQA2.js} +118 -22
- package/dist/bundle/{chunk-KT2BNEPE.js → chunk-MUFZODP5.js} +1 -1
- package/dist/bundle/{chunk-QKIFBA7N.js → chunk-Q6UAHLII.js} +2 -2
- package/dist/bundle/{chunk-TOOVREMP.js → chunk-YGV3Y4AD.js} +515 -107
- package/dist/bundle/{cli-main-BRXGYTGK.js → cli-main-CTYDQHFE.js} +4 -4
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/{google-HTMCUJ7X.js → google-4GA4YMUX.js} +2 -2
- package/dist/bundle/{google-vertex-ZQO65AXF.js → google-vertex-7AMALD7D.js} +2 -2
- package/dist/bundle/{main-POUXGEL6.js → main-GVGK354K.js} +5 -5
- package/dist/bundle/{mistral-SB7LU56G.js → mistral-74BXMNRM.js} +1 -1
- package/dist/bundle/{openai-codex-responses-5CEW4VN3.js → openai-codex-responses-COXNC4IH.js} +2 -2
- package/dist/bundle/{openai-completions-BAZJQSS2.js → openai-completions-BCSA5Q6S.js} +2 -2
- package/dist/bundle/{openai-responses-VHOE427P.js → openai-responses-ONCIZSJS.js} +3 -3
- package/dist/core/agent-session.d.ts +6 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +362 -103
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +9 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +29 -3
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/context-tree.d.ts +13 -10
- package/dist/core/context-tree.d.ts.map +1 -1
- package/dist/core/context-tree.js +49 -3
- package/dist/core/context-tree.js.map +1 -1
- package/dist/core/inference-coordinator.d.ts +1 -1
- package/dist/core/inference-coordinator.d.ts.map +1 -1
- package/dist/core/inference-coordinator.js +18 -5
- package/dist/core/inference-coordinator.js.map +1 -1
- package/dist/core/messages.d.ts +2 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +2 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/refinement/refinement.d.ts +2 -0
- package/dist/core/refinement/refinement.d.ts.map +1 -1
- package/dist/core/refinement/refinement.js +10 -1
- package/dist/core/refinement/refinement.js.map +1 -1
- package/dist/core/request-usage.d.ts +34 -0
- package/dist/core/request-usage.d.ts.map +1 -0
- package/dist/core/request-usage.js +111 -0
- package/dist/core/request-usage.js.map +1 -0
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +7 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts +2 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +4 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/modes/agent-connection/daemon-agent-connection.d.ts.map +1 -1
- package/dist/modes/agent-connection/daemon-agent-connection.js +8 -1
- package/dist/modes/agent-connection/daemon-agent-connection.js.map +1 -1
- package/dist/modes/daemon/daemon-protocol.d.ts +13 -3
- package/dist/modes/daemon/daemon-protocol.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-protocol.js +10 -2
- package/dist/modes/daemon/daemon-protocol.js.map +1 -1
- package/dist/modes/daemon/daemon-session-summarizer.d.ts +3 -0
- package/dist/modes/daemon/daemon-session-summarizer.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-session-summarizer.js +71 -32
- package/dist/modes/daemon/daemon-session-summarizer.js.map +1 -1
- package/dist/modes/interactive/components/context-tree-format.d.ts.map +1 -1
- package/dist/modes/interactive/components/context-tree-format.js +49 -0
- package/dist/modes/interactive/components/context-tree-format.js.map +1 -1
- package/docs/compaction.md +27 -3
- package/docs/context-management.md +17 -1
- package/docs/rlm.md +1 -1
- package/docs/settings.md +12 -0
- package/docs/usage.md +24 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAEN,2BAA2B,EAE3B,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAc,MAAM,aAAa,CAAC;AAE3F,oFAAoF;AACpF,MAAM,oBAAoB,GAAG;IAC5B,sEAAsE;IACtE,EAAE;IACF,8IAA8I;IAC9I,EAAE;IACF,oEAAoE;IACpE,4EAA4E;IAC5E,2EAA2E;IAC3E,kFAAkF;IAClF,sHAAsH;IACtH,uHAAuH;IACvH,EAAE;IACF,eAAe;IACf,qCAAqC;IACrC,uFAAuF;IACvF,kFAAkF;IAClF,EAAE;IACF,iBAAiB;IACjB,0GAAwG;IACxG,0JAA0J;IAC1J,kHAAkH;IAClH,6DAA6D;IAC7D,oDAAoD;IACpD,EAAE;IACF,4FAA4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C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IAExC,KAAK,MAAM,SAAS,IAAI,gBAAgB,IAAI,EAAE,EAAE,CAAC;QAChD,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACpC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7D,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC9B,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;IACF,CAAC;IAED,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACtE","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { buildChildAgentDoctrine, buildRlmPrompt, buildSubagentGuidance } from \"./prompts/index.js\";\nimport {\n\ttype ErrorFixSelectionOptions,\n\tformatHarnessStateForPrompt,\n\ttype HarnessState,\n\tREFINE_SKILL_NAME,\n} from \"./refinement/index.js\";\nimport { formatSkillsForPrompt, getPythonSkillRuntimeInfo, type Skill } from \"./skills.js\";\n\n// User-approved policy shared by every main model, including custom system prompts.\nconst ABSOLUTE_PROHIBITION = [\n\t\"## Absolute Prohibition: No Verification Theater / Proof Boilerplate\",\n\t\"\",\n\t\"You are FORBIDDEN from inventing, adding, or expanding any of the following unless the user explicitly requests them in the current message:\",\n\t\"\",\n\t'- Proofs of correctness, formal verification, or \"proof harnesses\"',\n\t'- Ledgers, audit logs, provenance tracking, or event sourcing \"for safety\"',\n\t\"- Cryptographic hashes, checksums, integrity checks, or signature schemes\",\n\t'- Review loops, multi-stage validation pipelines, or \"ensure this works\" rituals',\n\t\"- Extra test suites, property-based tests, or mutation testing that go beyond the minimal happy-path + one edge case\",\n\t\"- Over-cautious guardrails, legacy-compatibility layers, or defensive code for failure modes the user did not mention\",\n\t\"\",\n\t\"### Core Rule\",\n\t\"**Build the actual thing first.** \",\n\t\"Your job is to ship working, minimal, readable code that solves the stated problem. \",\n\t\"Do **not** turn a simple feature request into a research project on correctness.\",\n\t\"\",\n\t\"### Enforcement\",\n\t\"1. If the task is a prototype, MVP, script, or simple project → write the direct implementation. Stop.\",\n\t'2. Only add verification mechanisms when the user says words like \"prove\", \"formally verify\", \"add ledger\", \"hash everything\", or \"make it bulletproof\".',\n\t\"3. If you feel the urge to add any of the banned items, rewrite the plan to remove them before writing any code.\",\n\t\"4. Prefer deleting code over adding protective boilerplate.\",\n\t\"5. When in doubt: less is more. KISS is mandatory.\",\n\t\"\",\n\t\"Violation of this rule is considered a failure. Re-plan and ship the real feature instead.\",\n].join(\"\\n\");\n\nconst IMPLEMENTATION_CONTRACT = [\n\t\"## Implementation scope\",\n\t\"\",\n\t\"Implement the full stated input domain and required outputs, not only the cases present in the supplied data. Do not invent additional input formats or compatibility branches beyond that contract.\",\n\t\"Preserve earlier requirements unless later instructions replace them. Apply stated eligibility, priorities, and decision order literally, even when a different policy seems simpler or more sensible; reevaluate later decisions when earlier actions change their inputs.\",\n\t\"The required commands must implement the stated workflow from its stated starting state, without development-only state or extra steps.\",\n\t\"During tool-based inspection of large datasets, request schemas or small samples. Process full inputs in local code instead of printing entire datasets into the conversation.\",\n\t\"Do not repeat a successful check without a concrete reason, such as changed input, an edit, or an observed failure.\",\n\t\"Choose algorithms whose time and memory costs fit the stated input limits.\",\n\t\"For constrained search, prune known-impossible partial states before expanding them; do not postpone all feasibility checks until completed candidates.\",\n\t\"Choose numeric representations and arithmetic precision for the stated domain, not sample values or library defaults. Follow supplied formulas and operation order; use exact arithmetic for discrete decisions instead of rounded intermediates. Preserve each output field’s units, precision, rounding and required text format.\",\n].join(\"\\n\");\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces the default body; shared main-prompt policy remains). */\n\tcustomPrompt?: string;\n\t/** Active tools. Tool schemas carry tool descriptions outside the prompt body. */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. Used only for custom prompts. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the system prompt. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Conversation log path. */\n\tmessagesPath?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n\t/** Actual native recovery authorization at this owned prompt build. */\n\tnativeSkillSelection?: \"enabled\" | \"unavailable\";\n\t/** Whether to include the model-facing rlm recursion guidance. */\n\tallowRecursion?: boolean;\n\t/** Fixed recursive-agent depth for this session. */\n\trlmDepth?: number;\n\t/** Human-readable parent name or id for child communication doctrine. */\n\trlmParentAgent?: string;\n\t/** Global harness state to inject as compact persistent context. */\n\tharnessState?: HarnessState;\n\t/** Owner-captured optional advice inputs, stable with the system-prompt epoch. */\n\terrorFixSelection?: ErrorFixSelectionOptions;\n\t/** Enabled user-configured servers available through the generic kernel MCP API. */\n\tgenericMcpServers?: string[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tmessagesPath,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t\tallowRecursion,\n\t\tharnessState,\n\t} = options;\n\tconst promptCwd = cwd.replace(/\\\\/g, \"/\");\n\tconst promptMessagesPath = (messagesPath ?? \"not persisted\").replace(/\\\\/g, \"/\");\n\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 skills = options.nativeSkillSelection === \"unavailable\" ? [] : (providedSkills ?? []);\n\tconst tools = selectedTools ?? [\"ipython\"];\n\tconst hasIpython = tools.includes(\"ipython\");\n\tconst hasBash = tools.includes(\"bash\");\n\t// Admit and capture the catalog before constructing skill-derived prompt text.\n\tconst skillCatalog =\n\t\t(options.nativeSkillSelection === \"enabled\" || hasIpython || hasBash) && skills.length > 0\n\t\t\t? formatSkillsForPrompt(skills, options.nativeSkillSelection === \"enabled\")\n\t\t\t: \"\";\n\tconst visibleSkills = skills.filter((skill) => !skill.disableModelInvocation);\n\tconst visiblePythonSkillImportNames = getPythonSkillRuntimeInfo(visibleSkills).map((skill) => skill.importName);\n\tconst hasRefineSkill = visibleSkills.some((skill) => skill.name === REFINE_SKILL_NAME);\n\tconst genericMcpSection = hasIpython ? formatGenericMcpGuidance(options.genericMcpServers) : \"\";\n\n\tif (customPrompt) {\n\t\tlet prompt = `${customPrompt}\\n\\n${ABSOLUTE_PROHIBITION}\\n\\n${IMPLEMENTATION_CONTRACT}`;\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\tprompt += skillCatalog;\n\n\t\t// Add date and working directory last\n\t\tprompt += `\\nCurrent date: ${date}`;\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\tconst childDoctrine = buildChildAgentDoctrine({\n\t\t\tdepth: options.rlmDepth,\n\t\t\tparentAgent: options.rlmParentAgent,\n\t\t\tinstalledSkills: visiblePythonSkillImportNames,\n\t\t\tactiveTools: tools,\n\t\t});\n\t\tif (childDoctrine) {\n\t\t\tprompt += `\\n\\n${childDoctrine}`;\n\t\t}\n\n\t\tif (harnessState) {\n\t\t\tprompt += `\\n\\n${formatHarnessStateForPrompt(harnessState, { includeIpythonExamples: hasIpython, includeShellExamples: hasBash, includeRefineExamples: hasIpython && hasRefineSkill, errorFixSelection: options.errorFixSelection })}`;\n\t\t}\n\n\t\tif (genericMcpSection) {\n\t\t\tprompt += `\\n\\n${genericMcpSection}`;\n\t\t}\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\tlet prompt = buildRlmPrompt({\n\t\tcwd: promptCwd,\n\t\tmessagesPath: promptMessagesPath,\n\t\tinstalledSkills: visiblePythonSkillImportNames,\n\t\tactiveTools: tools.filter((name) => name === \"ipython\" || name === \"bash\" || name === \"edit\"),\n\t\tallowRecursion,\n\t\tdepth: options.rlmDepth,\n\t\tparentAgent: options.rlmParentAgent,\n\t});\n\n\tprompt += `\\n\\n${ABSOLUTE_PROHIBITION}\\n\\n${IMPLEMENTATION_CONTRACT}`;\n\n\t// Appended AFTER the trained buildRlmPrompt prefix, and before the harness-state\n\t// menu, so the model reads when/why to delegate and then sees the concrete subagent\n\t// specs it can match against — the same ordering as Claude Code's Agent tool.\n\tif ((allowRecursion ?? true) && hasIpython) {\n\t\tconst visiblePythonSkillNames = new Set(\n\t\t\tgetPythonSkillRuntimeInfo(visibleSkills).map((skill) => skill.importName),\n\t\t);\n\t\tprompt += `\\n\\n${buildSubagentGuidance({\n\t\t\tincludeRefineExamples: hasRefineSkill,\n\t\t\thasAgentMessage: visiblePythonSkillNames.has(\"agent_message\"),\n\t\t\thasAgentObserve: visiblePythonSkillNames.has(\"agent_observe\"),\n\t\t})}`;\n\t}\n\n\tif (harnessState) {\n\t\tprompt += `\\n\\n${formatHarnessStateForPrompt(harnessState, { includeIpythonExamples: hasIpython, includeShellExamples: hasBash, includeRefineExamples: hasIpython && hasRefineSkill, errorFixSelection: options.errorFixSelection })}`;\n\t}\n\n\tif (genericMcpSection) {\n\t\tprompt += `\\n\\n${genericMcpSection}`;\n\t}\n\n\tconst guidelines = formatPromptGuidelines(promptGuidelines);\n\tif (guidelines) {\n\t\tprompt += `\\n\\n# Additional Guidance\\n\\n${guidelines}`;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\tprompt += skillCatalog;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\treturn prompt;\n}\n\nfunction formatGenericMcpGuidance(servers: string[] | undefined): string {\n\tconst enabledServers = [...new Set(servers ?? [])].sort((left, right) => left.localeCompare(right));\n\tif (enabledServers.length === 0) return \"\";\n\n\treturn [\n\t\t\"# Generic MCP Connections\",\n\t\t\"\",\n\t\t\"Generic MCP connections are accessed through the pre-imported Python `mcp` object in the Python REPL, not as top-level native tool namespaces or installed Python skills.\",\n\t\t`Enabled generic MCP servers: ${enabledServers.map((server) => `\\`${server}\\``).join(\", \")}.`,\n\t\t...enabledServers.map(\n\t\t\t(server) =>\n\t\t\t\t`For \\`${server}\\`, first discover its tools with \\`await mcp.list_tools(\"${server}\")\\`, then call one with \\`await mcp.call_tool(\"${server}\", \"<tool>\", arguments)\\`.`,\n\t\t),\n\t].join(\"\\n\");\n}\n\nfunction formatPromptGuidelines(promptGuidelines: string[] | undefined): string {\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0 && !guidelinesSet.has(normalized)) {\n\t\t\tguidelinesSet.add(normalized);\n\t\t\tguidelinesList.push(normalized);\n\t\t}\n\t}\n\n\treturn guidelinesList.map((guideline) => `- ${guideline}`).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,uBAAuB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAEN,2BAA2B,EAE3B,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAc,MAAM,aAAa,CAAC;AAE3F,oFAAoF;AACpF,MAAM,oBAAoB,GAAG;IAC5B,sEAAsE;IACtE,EAAE;IACF,8IAA8I;IAC9I,EAAE;IACF,oEAAoE;IACpE,4EAA4E;IAC5E,2EAA2E;IAC3E,kFAAkF;IAClF,sHAAsH;IACtH,uHAAuH;IACvH,EAAE;IACF,eAAe;IACf,qCAAqC;IACrC,uFAAuF;IACvF,kFAAkF;IAClF,EAAE;IACF,iBAAiB;IACjB,0GAAwG;IACxG,0JAA0J;IAC1J,kHAAkH;IAClH,6DAA6D;IAC7D,oDAAoD;IACpD,EAAE;IACF,4FAA4F;CAC5F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,uBAAuB,GAAG;IAC/B,yBAAyB;IACzB,EAAE;IACF,sMAAsM;IACtM,6QAA6Q;IAC7Q,yIAAyI;IACzI,gLAAgL;IAChL,kOAAkO;IAClO,6OAA6O;IAC7O,qHAAqH;IACrH,4EAA4E;IAC5E,yJAAyJ;IACzJ,uUAAqU;CACrU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAuCb,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAiC,EAAU;IAC5E,MAAM,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,EACH,YAAY,EACZ,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,EACtB,cAAc,EACd,YAAY,GACZ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AAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACtE","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { buildChildAgentDoctrine, buildRlmPrompt, buildSubagentGuidance } from \"./prompts/index.js\";\nimport {\n\ttype ErrorFixSelectionOptions,\n\tformatHarnessStateForPrompt,\n\ttype HarnessState,\n\tREFINE_SKILL_NAME,\n} from \"./refinement/index.js\";\nimport { formatSkillsForPrompt, getPythonSkillRuntimeInfo, type Skill } from \"./skills.js\";\n\n// User-approved policy shared by every main model, including custom system prompts.\nconst ABSOLUTE_PROHIBITION = [\n\t\"## Absolute Prohibition: No Verification Theater / Proof Boilerplate\",\n\t\"\",\n\t\"You are FORBIDDEN from inventing, adding, or expanding any of the following unless the user explicitly requests them in the current message:\",\n\t\"\",\n\t'- Proofs of correctness, formal verification, or \"proof harnesses\"',\n\t'- Ledgers, audit logs, provenance tracking, or event sourcing \"for safety\"',\n\t\"- Cryptographic hashes, checksums, integrity checks, or signature schemes\",\n\t'- Review loops, multi-stage validation pipelines, or \"ensure this works\" rituals',\n\t\"- Extra test suites, property-based tests, or mutation testing that go beyond the minimal happy-path + one edge case\",\n\t\"- Over-cautious guardrails, legacy-compatibility layers, or defensive code for failure modes the user did not mention\",\n\t\"\",\n\t\"### Core Rule\",\n\t\"**Build the actual thing first.** \",\n\t\"Your job is to ship working, minimal, readable code that solves the stated problem. \",\n\t\"Do **not** turn a simple feature request into a research project on correctness.\",\n\t\"\",\n\t\"### Enforcement\",\n\t\"1. If the task is a prototype, MVP, script, or simple project → write the direct implementation. Stop.\",\n\t'2. Only add verification mechanisms when the user says words like \"prove\", \"formally verify\", \"add ledger\", \"hash everything\", or \"make it bulletproof\".',\n\t\"3. If you feel the urge to add any of the banned items, rewrite the plan to remove them before writing any code.\",\n\t\"4. Prefer deleting code over adding protective boilerplate.\",\n\t\"5. When in doubt: less is more. KISS is mandatory.\",\n\t\"\",\n\t\"Violation of this rule is considered a failure. Re-plan and ship the real feature instead.\",\n].join(\"\\n\");\n\nconst IMPLEMENTATION_CONTRACT = [\n\t\"## Implementation scope\",\n\t\"\",\n\t\"Implement the full stated input domain and required outputs, not only the cases present in the supplied data. Do not invent additional input formats or compatibility branches beyond that contract.\",\n\t\"Preserve earlier requirements unless later instructions replace them. Apply stated eligibility, priorities, and decision order literally, even when a different policy seems simpler or more sensible; reevaluate later decisions when earlier actions change their inputs.\",\n\t\"The required commands must implement the stated workflow from its stated starting state, without development-only state or extra steps.\",\n\t\"During tool-based inspection of large datasets, request schemas or small samples. Process full inputs in local code instead of printing entire datasets into the conversation.\",\n\t\"Read long text in bounded pages; use a character limit as well as a line limit when lines are long. If output is truncated, page the retained result instead of repeating the original command or printing the whole file again.\",\n\t\"Batch nonurgent child updates. Send results, blockers, or decisions that need action rather than acknowledgements and repeated status requests. Continue independent work while children run, and report meaningful milestones to the user.\",\n\t\"Do not repeat a successful check without a concrete reason, such as changed input, an edit, or an observed failure.\",\n\t\"Choose algorithms whose time and memory costs fit the stated input limits.\",\n\t\"For constrained search, prune known-impossible partial states before expanding them; do not postpone all feasibility checks until completed candidates.\",\n\t\"Choose numeric representations and arithmetic precision for the stated domain, not sample values or library defaults. Follow supplied formulas and operation order; use exact arithmetic for discrete decisions instead of rounded intermediates. Preserve each output field’s units, precision, rounding and required text format.\",\n].join(\"\\n\");\n\nexport interface BuildSystemPromptOptions {\n\t/** Custom system prompt (replaces the default body; shared main-prompt policy remains). */\n\tcustomPrompt?: string;\n\t/** Active tools. Tool schemas carry tool descriptions outside the prompt body. */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. Used only for custom prompts. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the system prompt. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. */\n\tcwd: string;\n\t/** Conversation log path. */\n\tmessagesPath?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n\t/** Actual native recovery authorization at this owned prompt build. */\n\tnativeSkillSelection?: \"enabled\" | \"unavailable\";\n\t/** Whether to include the model-facing rlm recursion guidance. */\n\tallowRecursion?: boolean;\n\t/** Fixed recursive-agent depth for this session. */\n\trlmDepth?: number;\n\t/** Human-readable parent name or id for child communication doctrine. */\n\trlmParentAgent?: string;\n\t/** Global harness state to inject as compact persistent context. */\n\tharnessState?: HarnessState;\n\t/** AgentSession moves mutable entries to owned messages; standalone builds include everything. */\n\tharnessSection?: \"all\" | \"instructions\";\n\t/** Owner-captured optional advice inputs, stable with the system-prompt epoch. */\n\terrorFixSelection?: ErrorFixSelectionOptions;\n\t/** Enabled user-configured servers available through the generic kernel MCP API. */\n\tgenericMcpServers?: string[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tmessagesPath,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t\tallowRecursion,\n\t\tharnessState,\n\t} = options;\n\tconst promptCwd = cwd.replace(/\\\\/g, \"/\");\n\tconst promptMessagesPath = (messagesPath ?? \"not persisted\").replace(/\\\\/g, \"/\");\n\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 skills = options.nativeSkillSelection === \"unavailable\" ? [] : (providedSkills ?? []);\n\tconst tools = selectedTools ?? [\"ipython\"];\n\tconst hasIpython = tools.includes(\"ipython\");\n\tconst hasBash = tools.includes(\"bash\");\n\t// Admit and capture the catalog before constructing skill-derived prompt text.\n\tconst skillCatalog =\n\t\t(options.nativeSkillSelection === \"enabled\" || hasIpython || hasBash) && skills.length > 0\n\t\t\t? formatSkillsForPrompt(skills, options.nativeSkillSelection === \"enabled\")\n\t\t\t: \"\";\n\tconst visibleSkills = skills.filter((skill) => !skill.disableModelInvocation);\n\tconst visiblePythonSkillImportNames = getPythonSkillRuntimeInfo(visibleSkills).map((skill) => skill.importName);\n\tconst hasRefineSkill = visibleSkills.some((skill) => skill.name === REFINE_SKILL_NAME);\n\tconst genericMcpSection = hasIpython ? formatGenericMcpGuidance(options.genericMcpServers) : \"\";\n\n\tif (customPrompt) {\n\t\tlet prompt = `${customPrompt}\\n\\n${ABSOLUTE_PROHIBITION}\\n\\n${IMPLEMENTATION_CONTRACT}`;\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\tprompt += skillCatalog;\n\n\t\t// Add date and working directory last\n\t\tprompt += `\\nCurrent date: ${date}`;\n\t\tprompt += `\\nCurrent working directory: ${promptCwd}`;\n\n\t\tconst childDoctrine = buildChildAgentDoctrine({\n\t\t\tdepth: options.rlmDepth,\n\t\t\tparentAgent: options.rlmParentAgent,\n\t\t\tinstalledSkills: visiblePythonSkillImportNames,\n\t\t\tactiveTools: tools,\n\t\t});\n\t\tif (childDoctrine) {\n\t\t\tprompt += `\\n\\n${childDoctrine}`;\n\t\t}\n\n\t\tif (harnessState) {\n\t\t\tprompt += `\\n\\n${formatHarnessStateForPrompt(harnessState, { includeIpythonExamples: hasIpython, includeShellExamples: hasBash, includeRefineExamples: hasIpython && hasRefineSkill, errorFixSelection: options.errorFixSelection, section: options.harnessSection })}`;\n\t\t}\n\n\t\tif (genericMcpSection) {\n\t\t\tprompt += `\\n\\n${genericMcpSection}`;\n\t\t}\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\treturn prompt;\n\t}\n\n\tlet prompt = buildRlmPrompt({\n\t\tcwd: promptCwd,\n\t\tmessagesPath: promptMessagesPath,\n\t\tinstalledSkills: visiblePythonSkillImportNames,\n\t\tactiveTools: tools.filter((name) => name === \"ipython\" || name === \"bash\" || name === \"edit\"),\n\t\tallowRecursion,\n\t\tdepth: options.rlmDepth,\n\t\tparentAgent: options.rlmParentAgent,\n\t});\n\n\tprompt += `\\n\\n${ABSOLUTE_PROHIBITION}\\n\\n${IMPLEMENTATION_CONTRACT}`;\n\n\t// Appended AFTER the trained buildRlmPrompt prefix, and before the harness-state\n\t// menu, so the model reads when/why to delegate and then sees the concrete subagent\n\t// specs it can match against — the same ordering as Claude Code's Agent tool.\n\tif ((allowRecursion ?? true) && hasIpython) {\n\t\tconst visiblePythonSkillNames = new Set(\n\t\t\tgetPythonSkillRuntimeInfo(visibleSkills).map((skill) => skill.importName),\n\t\t);\n\t\tprompt += `\\n\\n${buildSubagentGuidance({\n\t\t\tincludeRefineExamples: hasRefineSkill,\n\t\t\thasAgentMessage: visiblePythonSkillNames.has(\"agent_message\"),\n\t\t\thasAgentObserve: visiblePythonSkillNames.has(\"agent_observe\"),\n\t\t})}`;\n\t}\n\n\tif (harnessState) {\n\t\tprompt += `\\n\\n${formatHarnessStateForPrompt(harnessState, { includeIpythonExamples: hasIpython, includeShellExamples: hasBash, includeRefineExamples: hasIpython && hasRefineSkill, errorFixSelection: options.errorFixSelection, section: options.harnessSection })}`;\n\t}\n\n\tif (genericMcpSection) {\n\t\tprompt += `\\n\\n${genericMcpSection}`;\n\t}\n\n\tconst guidelines = formatPromptGuidelines(promptGuidelines);\n\tif (guidelines) {\n\t\tprompt += `\\n\\n# Additional Guidance\\n\\n${guidelines}`;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\tprompt += skillCatalog;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\treturn prompt;\n}\n\nfunction formatGenericMcpGuidance(servers: string[] | undefined): string {\n\tconst enabledServers = [...new Set(servers ?? [])].sort((left, right) => left.localeCompare(right));\n\tif (enabledServers.length === 0) return \"\";\n\n\treturn [\n\t\t\"# Generic MCP Connections\",\n\t\t\"\",\n\t\t\"Generic MCP connections are accessed through the pre-imported Python `mcp` object in the Python REPL, not as top-level native tool namespaces or installed Python skills.\",\n\t\t`Enabled generic MCP servers: ${enabledServers.map((server) => `\\`${server}\\``).join(\", \")}.`,\n\t\t...enabledServers.map(\n\t\t\t(server) =>\n\t\t\t\t`For \\`${server}\\`, first discover its tools with \\`await mcp.list_tools(\"${server}\")\\`, then call one with \\`await mcp.call_tool(\"${server}\", \"<tool>\", arguments)\\`.`,\n\t\t),\n\t].join(\"\\n\");\n}\n\nfunction formatPromptGuidelines(promptGuidelines: string[] | undefined): string {\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0 && !guidelinesSet.has(normalized)) {\n\t\t\tguidelinesSet.add(normalized);\n\t\t\tguidelinesList.push(normalized);\n\t\t}\n\t}\n\n\treturn guidelinesList.map((guideline) => `- ${guideline}`).join(\"\\n\");\n}\n"]}
|