@ponythewhite/base-context 1.0.6 → 1.0.8

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.
Files changed (136) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/base-context-runtime/pyproject.toml +1 -1
  3. package/dist/base-context-runtime/src/rlm/__init__.py +3 -0
  4. package/dist/base-context-runtime/src/rlm/harness.py +86 -48
  5. package/dist/base-context-runtime/test/test_harness.py +215 -140
  6. package/dist/base-context-runtime/uv.lock +1 -1
  7. package/dist/build-info.json +1 -1
  8. package/dist/bundle/amazon-bedrock.js +3 -3
  9. package/dist/bundle/{anthropic-UV5GZDGU.js → anthropic-5PSCZEER.js} +2 -7
  10. package/dist/bundle/{azure-openai-responses-WSNPXLYC.js → azure-openai-responses-AYTLJR33.js} +2 -2
  11. package/dist/bundle/{bundled-modules-MEACET4U.js → bundled-modules-IGMJH2MU.js} +5 -5
  12. package/dist/bundle/{chunk-UPVDERMD.js → chunk-2IPDSTDR.js} +11 -9
  13. package/dist/bundle/chunk-D3KOF57W.js +22040 -0
  14. package/dist/bundle/{chunk-QKI6KEGP.js → chunk-EXEFSSF4.js} +1509 -577
  15. package/dist/bundle/{chunk-VSIYFWYI.js → chunk-KT2BNEPE.js} +21 -8
  16. package/dist/bundle/{chunk-KTNETTHI.js → chunk-Q3MBSBEB.js} +3 -101
  17. package/dist/bundle/{chunk-LFPWHI42.js → chunk-QKIFBA7N.js} +2 -2
  18. package/dist/bundle/{chunk-LIZVVGHR.js → chunk-RVJVXZCS.js} +13 -10
  19. package/dist/bundle/{cli-main-ANUJY7Y4.js → cli-main-BUK7QTHO.js} +4 -4
  20. package/dist/bundle/cli.js +1 -1
  21. package/dist/bundle/{google-T32FMD4G.js → google-HTMCUJ7X.js} +2 -2
  22. package/dist/bundle/{google-vertex-56KP6I3B.js → google-vertex-ZQO65AXF.js} +2 -2
  23. package/dist/bundle/{main-4GIKOHIT.js → main-2FWHT2WZ.js} +5 -5
  24. package/dist/bundle/{mistral-WGBMYIVU.js → mistral-SB7LU56G.js} +1 -1
  25. package/dist/bundle/{openai-codex-responses-PIV2RQ3G.js → openai-codex-responses-5CEW4VN3.js} +53 -27
  26. package/dist/bundle/{openai-completions-64C3JPR4.js → openai-completions-BAZJQSS2.js} +1 -1
  27. package/dist/bundle/{openai-responses-UI7RSTDV.js → openai-responses-VHOE427P.js} +48 -5
  28. package/dist/core/agent-session.d.ts +6 -1
  29. package/dist/core/agent-session.d.ts.map +1 -1
  30. package/dist/core/agent-session.js +189 -31
  31. package/dist/core/agent-session.js.map +1 -1
  32. package/dist/core/canonical-context.d.ts +8 -0
  33. package/dist/core/canonical-context.d.ts.map +1 -1
  34. package/dist/core/canonical-context.js +37 -5
  35. package/dist/core/canonical-context.js.map +1 -1
  36. package/dist/core/compaction/compaction.d.ts +2 -2
  37. package/dist/core/compaction/compaction.d.ts.map +1 -1
  38. package/dist/core/compaction/compaction.js +31 -13
  39. package/dist/core/compaction/compaction.js.map +1 -1
  40. package/dist/core/context-epoch.d.ts +1 -1
  41. package/dist/core/context-epoch.d.ts.map +1 -1
  42. package/dist/core/context-epoch.js +20 -12
  43. package/dist/core/context-epoch.js.map +1 -1
  44. package/dist/core/extensions/types.d.ts +2 -2
  45. package/dist/core/extensions/types.d.ts.map +1 -1
  46. package/dist/core/extensions/types.js.map +1 -1
  47. package/dist/core/history-index-worker.d.ts.map +1 -1
  48. package/dist/core/history-index-worker.js +29 -8
  49. package/dist/core/history-index-worker.js.map +1 -1
  50. package/dist/core/history-index.d.ts +11 -1
  51. package/dist/core/history-index.d.ts.map +1 -1
  52. package/dist/core/history-index.js +2 -1
  53. package/dist/core/history-index.js.map +1 -1
  54. package/dist/core/inference-coordinator.d.ts.map +1 -1
  55. package/dist/core/inference-coordinator.js +110 -13
  56. package/dist/core/inference-coordinator.js.map +1 -1
  57. package/dist/core/kernel/bootstrap.d.ts.map +1 -1
  58. package/dist/core/kernel/bootstrap.js +97 -107
  59. package/dist/core/kernel/bootstrap.js.map +1 -1
  60. package/dist/core/kernel/repl-manager.d.ts.map +1 -1
  61. package/dist/core/kernel/repl-manager.js +11 -0
  62. package/dist/core/kernel/repl-manager.js.map +1 -1
  63. package/dist/core/kernel/shared.d.ts +2 -0
  64. package/dist/core/kernel/shared.d.ts.map +1 -1
  65. package/dist/core/kernel/shared.js.map +1 -1
  66. package/dist/core/messages.d.ts.map +1 -1
  67. package/dist/core/messages.js +4 -1
  68. package/dist/core/messages.js.map +1 -1
  69. package/dist/core/prompts/rlm.d.ts.map +1 -1
  70. package/dist/core/prompts/rlm.js +4 -2
  71. package/dist/core/prompts/rlm.js.map +1 -1
  72. package/dist/core/public-context.d.ts.map +1 -1
  73. package/dist/core/public-context.js +16 -0
  74. package/dist/core/public-context.js.map +1 -1
  75. package/dist/core/refinement/refinement.d.ts +19 -5
  76. package/dist/core/refinement/refinement.d.ts.map +1 -1
  77. package/dist/core/refinement/refinement.js +90 -35
  78. package/dist/core/refinement/refinement.js.map +1 -1
  79. package/dist/core/request-view-selection.d.ts +12 -4
  80. package/dist/core/request-view-selection.d.ts.map +1 -1
  81. package/dist/core/request-view-selection.js +242 -100
  82. package/dist/core/request-view-selection.js.map +1 -1
  83. package/dist/core/retained-tool-output.d.ts +28 -0
  84. package/dist/core/retained-tool-output.d.ts.map +1 -0
  85. package/dist/core/retained-tool-output.js +102 -0
  86. package/dist/core/retained-tool-output.js.map +1 -0
  87. package/dist/core/sdk.d.ts.map +1 -1
  88. package/dist/core/sdk.js +1 -1
  89. package/dist/core/sdk.js.map +1 -1
  90. package/dist/core/selective-recovery.d.ts +47 -3
  91. package/dist/core/selective-recovery.d.ts.map +1 -1
  92. package/dist/core/selective-recovery.js +428 -109
  93. package/dist/core/selective-recovery.js.map +1 -1
  94. package/dist/core/session-history-index.d.ts +3 -1
  95. package/dist/core/session-history-index.d.ts.map +1 -1
  96. package/dist/core/session-history-index.js +1 -1
  97. package/dist/core/session-history-index.js.map +1 -1
  98. package/dist/core/settings-manager.d.ts +5 -0
  99. package/dist/core/settings-manager.d.ts.map +1 -1
  100. package/dist/core/settings-manager.js +3 -0
  101. package/dist/core/settings-manager.js.map +1 -1
  102. package/dist/core/system-prompt.d.ts +3 -1
  103. package/dist/core/system-prompt.d.ts.map +1 -1
  104. package/dist/core/system-prompt.js +3 -3
  105. package/dist/core/system-prompt.js.map +1 -1
  106. package/dist/core/task-frame.d.ts +1 -1
  107. package/dist/core/task-frame.d.ts.map +1 -1
  108. package/dist/core/task-frame.js +21 -1
  109. package/dist/core/task-frame.js.map +1 -1
  110. package/dist/core/task-state-reader.d.ts +10 -2
  111. package/dist/core/task-state-reader.d.ts.map +1 -1
  112. package/dist/core/task-state-reader.js +75 -9
  113. package/dist/core/task-state-reader.js.map +1 -1
  114. package/dist/core/tools/ipython.d.ts +5 -0
  115. package/dist/core/tools/ipython.d.ts.map +1 -1
  116. package/dist/core/tools/ipython.js +59 -17
  117. package/dist/core/tools/ipython.js.map +1 -1
  118. package/dist/core/tools/prime-context.d.ts.map +1 -1
  119. package/dist/core/tools/prime-context.js +1 -1
  120. package/dist/core/tools/prime-context.js.map +1 -1
  121. package/dist/core/view-units.d.ts +4 -0
  122. package/dist/core/view-units.d.ts.map +1 -1
  123. package/dist/core/view-units.js +28 -19
  124. package/dist/core/view-units.js.map +1 -1
  125. package/dist/installer.mjs +98 -77
  126. package/dist/modes/interactive/components/refinement-outcome-message.d.ts.map +1 -1
  127. package/dist/modes/interactive/components/refinement-outcome-message.js.map +1 -1
  128. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  129. package/dist/modes/interactive/interactive-mode.js +5 -5
  130. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  131. package/dist/skills/skill-creator/SKILL.md +18 -1
  132. package/docs/settings.md +45 -0
  133. package/docs/skills.md +77 -2
  134. package/package.json +4 -4
  135. package/skills/skill-creator/SKILL.md +18 -1
  136. package/dist/bundle/chunk-W46VZFI6.js +0 -21681
@@ -14,6 +14,8 @@ const SIMPLIFIED_TECHNICAL_ENGLISH_PROMPT = [
14
14
  const REPL_CONTROL_PROMPT = [
15
15
  "The `ipython` tool is a persistent Python REPL — the agent's long-lived control environment for reasoning, context management, state, tool orchestration, and recursive subcalls. Top-level `await` works directly. Use it to keep intermediate variables, inspect and transform outputs, and write small helper functions. Compaction removes individual variables whose serialized form exceeds 16 MiB; keep large source data on disk and reload it when needed.",
16
16
  "",
17
+ "Reuse a named Python function for repeated multi-step work; keep one-off operations inline. Pass changing inputs explicitly and read current data each call. Save cross-task helpers as editable .py files with short project-skill instructions, without packaging them. After editing loaded code, execute its updated definition or invoke the saved file afresh.",
18
+ "",
17
19
  "Python is the orchestration language: use Python for loops, conditionals, parsing, and state. Use `bash()` to invoke programs, not to write shell programs — no shell loops or heredocs; do those in Python.",
18
20
  "",
19
21
  "Do not assume the REPL is the native runtime of the external thing being investigated. A repository, package, service, dataset, paper, website, benchmark, or API may have its own environment and normal interface. Evaluate external systems through their own interface, then use the REPL to coordinate the process and analyze what comes back.",
@@ -68,8 +70,6 @@ export function buildRlmPrompt(options) {
68
70
  ...(depth === 0 ? [USER_PROGRESS_PROMPT, ""] : []),
69
71
  SIMPLIFIED_TECHNICAL_ENGLISH_PROMPT,
70
72
  "",
71
- `Working directory: ${cwd}`,
72
- `Conversation log: ${messagesPath}`,
73
73
  `Recursive agent depth: ${depth}`,
74
74
  `Pre-installed Python packages: ${DEFAULT_RLM_EXTRA_IMPORT_LABELS.join(", ")}.`,
75
75
  "Install additional packages with `uv pip install <pkg>` (this is a uv-managed venv with no pip module).",
@@ -129,6 +129,8 @@ export function buildRlmPrompt(options) {
129
129
  parts.push("", "Treat continual harness refinement as a small, evidence-backed update after observing a repeated failure or reusable tactic: diagnose the issue, update the smallest relevant continual harness component, validate on the next action, then record the outcome. Use `await refine.run()` to turn repeated delegation patterns into reusable subagent specs, repeated procedures into skills, durable facts/preferences into memories, and narrow behavioral policies into prompt addendums. It returns immediately and runs when the current turn ends, so continue working normally after calling it. Do not rewrite the whole continual harness when a focused memory, skill, prompt note, or subagent spec is enough.");
130
130
  }
131
131
  }
132
+ // Runtime coordinates follow the fixed harness guidance without moving user/project instructions.
133
+ parts.push("", `Working directory: ${cwd}`, `Conversation log: ${messagesPath}`);
132
134
  return parts.join("\n");
133
135
  }
134
136
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rlm.js","sourceRoot":"","sources":["../../../src/core/prompts/rlm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAazE,MAAM,wBAAwB,GAAG;IAChC,+MAA+M;IAC/M,uMAAuM;IACvM,gQAAgQ;CAChQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,oBAAoB,GACzB,kmBAAkmB,CAAC;AAEpmB,MAAM,mCAAmC,GAAG;IAC3C,oEAAoE;IACpE,yJAAyJ;IACzJ,4HAA4H;IAC5H,4JAA4J;CAC5J,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,mBAAmB,GAAG;IAC3B,ucAAqc;IACrc,EAAE;IACF,gNAA8M;IAC9M,EAAE;IACF,sVAAsV;IACtV,EAAE;IACF,uvBAAuvB;IACvvB,EAAE;IACF,4dAA4d;IAC5d,EAAE;IACF,oOAAkO;IAClO,EAAE;IACF,qPAAmP;IACnP,EAAE;IACF,qWAAqW;IACrW,EAAE;IACF,swBAAswB;IACtwB,EAAE;IACF,0LAA0L;IAC1L,EAAE;IACF,kpBAAkpB;CAClpB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AASb,MAAM,UAAU,uBAAuB,CAAC,OAAkC,EAAsB;IAC/F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,KAAK,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChG,MAAM,eAAe,GAAG,OAAO,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F,EAAE,EAC9F;IACT,MAAM,KAAK,GAAG;QACb,4BAA4B;QAC5B,EAAE;QACF,yLAAyL;KACzL,CAAC;IACF,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CACT,sOAAsO,CACtO,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;IACnF,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;IACtE,CAAC;IACD,KAAK,CAAC,IAAI,CACT,4DAA4D,EAC5D,4HAA4H,CAC5H,CAAC;IACF,IAAI,OAAO,CAAC,qBAAqB,IAAI,IAAI,EAAE,CAAC;QAC3C,KAAK,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACxB","sourcesContent":["import { DEFAULT_RLM_EXTRA_IMPORT_LABELS } from \"../kernel/bootstrap.js\";\n\nexport interface RlmPromptOptions {\n\tcwd: string;\n\tskillsDir?: string;\n\tinstalledSkills?: string[];\n\tmessagesPath: string;\n\tallowRecursion?: boolean;\n\tdepth?: number;\n\tparentAgent?: string;\n\tactiveTools?: string[];\n}\n\nconst LONG_RUNNING_WORK_PROMPT = [\n\t\"For slow or independently completing work, use a nonblocking control loop: start the work, record its handle or output location, then end your turn. Read the result on a later turn or when a reply arrives.\",\n\t\"When delegation is available and useful, assign independent substantive tasks to separate workers. Start independent workers without waiting for each one sequentially, and let them run in parallel.\",\n\t\"Do not keep the turn open by polling with `time.sleep()` or shell `sleep`, and do not replace polling with a long blocking `await`. Await only the short operation needed to start work or inspect a result that is already available; otherwise end the turn.\",\n].join(\"\\n\");\n\nconst USER_PROGRESS_PROMPT =\n\t\"As the user-facing root agent, when work follows a plan, uses many subagents, or spans multiple turns, proactively give regular concise progress updates so the user does not have to ask. State the current plan, what has completed, any blockers, the proposed fixes, and the next actions. Lead with user-visible outcomes rather than internal process or gate names. Mention internal details only when they explain a blocker or decision. Send an update at meaningful milestones and before ending a turn while work is still running. Do not repeat unchanged status or interrupt short work with unnecessary updates.\";\n\nconst SIMPLIFIED_TECHNICAL_ENGLISH_PROMPT = [\n\t\"Use simplified technical English by default for user-facing prose.\",\n\t\"Prefer short sentences, common words, and concrete verbs. State one main action or fact per sentence when practical. Use lists for steps or conditions.\",\n\t\"Keep necessary technical terms, names, commands, code, paths, and exact quoted text unchanged. State uncertainty directly.\",\n\t\"Treat this as clarity guidance, not a claim of formal ASD-STE100 compliance. Preserve a user-requested format, tone, terminology, and necessary precision.\",\n].join(\"\\n\");\n\nconst REPL_CONTROL_PROMPT = [\n\t\"The `ipython` tool is a persistent Python REPL — the agent's long-lived control environment for reasoning, context management, state, tool orchestration, and recursive subcalls. Top-level `await` works directly. Use it to keep intermediate variables, inspect and transform outputs, and write small helper functions. Compaction removes individual variables whose serialized form exceeds 16 MiB; keep large source data on disk and reload it when needed.\",\n\t\"\",\n\t\"Python is the orchestration language: use Python for loops, conditionals, parsing, and state. Use `bash()` to invoke programs, not to write shell programs — no shell loops or heredocs; do those in Python.\",\n\t\"\",\n\t\"Do not assume the REPL is the native runtime of the external thing being investigated. A repository, package, service, dataset, paper, website, benchmark, or API may have its own environment and normal interface. Evaluate external systems through their own interface, then use the REPL to coordinate the process and analyze what comes back.\",\n\t\"\",\n\t\"`bash(command)` starts a shell command in the background and returns a handle immediately: `h = bash('npm test')`. Use `h.pid` / `h.running` for liveness, `h.tail(n)` / `h.output()` for combined stdout+stderr so far, `h.poll()` for a non-blocking result, `h.kill()` to terminate (SIGTERM, escalating to SIGKILL; on Windows kill() uses taskkill /T and detached or reparented descendants may survive), and `await h` (or `await bash('cmd')`) for the completed result with exit_code, output, and duration. Prefer bash() for long-running commands so the turn keeps working. Run shell commands with `bash()`, not `subprocess`/`os.system`: subprocess calls block the kernel, show the user nothing while they run, and spawn processes the harness cannot see or stop.\",\n\t\"\",\n\t\"Important: do not install dependencies into the kernel just to make an external project import or run there. If a project import, test, script, CLI, or dependency check is needed, run it through that project's own environment and normal command interface. For example, in a Python repo use its documented commands, `uv run ...`, `.venv/bin/python ...`, or the active project interpreter from the repo root. Treat failures from that native environment as the relevant result.\",\n\t\"\",\n\t\"Use Python for reading, searching, and editing files — it gives you reusable variables you can slice, filter, and act on without re-reading. Always assign read/search results to named variables so you can revisit them later.\",\n\t\"\",\n\t\"Each `bash()` call is its own process, so shell state does not persist between calls; use `os.chdir(...)` for the working directory and `os.environ[...]` for environment variables — both persist in the REPL and apply to later `bash()` calls.\",\n\t\"\",\n\t\"Python state in the kernel persists across cells: named variables, helper functions, classes, imports, notes, parsed outputs, and helper data structures all remain available in every later turn. Tool calls are themselves Python `await` expressions, so their return values can be bound to variables and composed into program logic just like any other call.\",\n\t\"\",\n\t\"Continual harness state is available as `rlm.harness` and `rlm.get_harness_state()`. CRUD calls are local to this Base Context session by default: `rlm.harness.create_memory(...)`, `rlm.harness.update_memory(...)`, `rlm.harness.delete_memory(...)`, `rlm.harness.create_skill(...)`, `rlm.harness.update_skill(...)`, `rlm.harness.delete_skill(...)`, `rlm.harness.create_subagent(...)`, `rlm.harness.update_subagent(...)`, `rlm.harness.delete_subagent(...)`, `rlm.harness.create_prompt_note(...)`, `rlm.harness.update_prompt_note(...)`, `rlm.harness.delete_prompt_note(...)`, plus `rlm.harness.record_refinement(...)` and `rlm.harness.overview()`. Use `global_=True` only for stable cross-session lessons; Python reserves `global`, so literal `global=True` is invalid syntax.\",\n\t\"\",\n\t\"Terminology: continual harness names the persisted prompt, memory, skill, and subagent layer; RLM names the runtime, Python REPL kernel, and native call interface exposed to the model.\",\n\t\"\",\n\t\"RLM-native call contract: installed Python skills are pre-imported modules. Read the matching SKILL.md and call its documented function, such as `await <skill_import>.<function>(...)`; when a CLI exists, use `<skill_import> ...` from shell. Continual harness skill entries are Python REPL skills with an explicit Python `reference` and `arguments` contract. Spawn a reusable delegation spec with `await rlm('sub-task')`; admission returns a child handle immediately. Results arrive only through an available messaging capability or files, never as an `rlm()` return value. Do not invent non-native wrappers such as `call_skill(...)` or `run_subagent(...)`.\",\n].join(\"\\n\");\n\nexport interface ChildAgentDoctrineOptions {\n\tdepth?: number;\n\tparentAgent?: string;\n\tinstalledSkills?: string[];\n\tactiveTools?: string[];\n}\n\nexport function buildChildAgentDoctrine(options: ChildAgentDoctrineOptions): string | undefined {\n\tconst depth = options.depth ?? 0;\n\tconst hasIpython = options.activeTools === undefined || options.activeTools.includes(\"ipython\");\n\tconst hasAgentMessage = options.installedSkills?.includes(\"agent_message\") ?? false;\n\tif (depth <= 0) return undefined;\n\n\tconst lines = [\n\t\t`You are a child agent spawned by ${options.parentAgent ?? \"your parent agent\"}. Task prompts are labeled \\`[task from parent]\\`.`,\n\t];\n\tif (hasAgentMessage && hasIpython) {\n\t\tlines.push(\n\t\t\t'When a task calls for an answer, reply explicitly with `await agent_message.send(message, receiver_role=\"parent\")`. Not every message or task needs a reply; continue cleanup after sending and go idle normally.',\n\t\t);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function buildRlmPrompt(options: RlmPromptOptions): string {\n\tconst { cwd, skillsDir, messagesPath } = options;\n\tconst installedSkills = options.installedSkills ?? [];\n\tconst hasAgentMessage = installedSkills.includes(\"agent_message\");\n\tconst hasAgentObserve = installedSkills.includes(\"agent_observe\");\n\tconst allowRecursion = options.allowRecursion ?? true;\n\tconst depth = options.depth ?? 0;\n\tconst activeTools = options.activeTools ?? [];\n\tconst hasIpython = options.activeTools === undefined ? true : activeTools.includes(\"ipython\");\n\tconst canRunShellSkills = hasIpython || activeTools.includes(\"bash\");\n\tconst parts = [\n\t\t\"You are a general purpose agent that uses code to solve tasks.\",\n\t\t\"You solve tasks by breaking down problems into sub-tasks, writing and executing code, observing results, and iterating one step at a time.\",\n\t\t\"When you are done, stop calling tools and state your final answer.\",\n\t\t\"\",\n\t\tLONG_RUNNING_WORK_PROMPT,\n\t\t\"\",\n\t\t...(depth === 0 ? [USER_PROGRESS_PROMPT, \"\"] : []),\n\t\tSIMPLIFIED_TECHNICAL_ENGLISH_PROMPT,\n\t\t\"\",\n\t\t`Working directory: ${cwd}`,\n\t\t`Conversation log: ${messagesPath}`,\n\t\t`Recursive agent depth: ${depth}`,\n\t\t`Pre-installed Python packages: ${DEFAULT_RLM_EXTRA_IMPORT_LABELS.join(\", \")}.`,\n\t\t\"Install additional packages with `uv pip install <pkg>` (this is a uv-managed venv with no pip module).\",\n\t];\n\n\tconst childDoctrine = buildChildAgentDoctrine(options);\n\tif (childDoctrine) {\n\t\tparts.push(\"\", childDoctrine);\n\t}\n\n\tconst skillLines: string[] = [];\n\tif (skillsDir) {\n\t\tskillLines.push(`Local skills live under ${skillsDir}. Read their SKILL.md files when helpful.`);\n\t}\n\tif (installedSkills.length > 0) {\n\t\tconst installed = installedSkills.map((skill) => `\\`${skill}\\``).join(\", \");\n\t\tif (hasIpython) {\n\t\t\tskillLines.push(`Installed Python skill modules (pre-imported): ${installed}.`);\n\t\t\tskillLines.push(\n\t\t\t\t\"Read each skill's SKILL.md for its API. Inspect a module with `help(<skill>)` or `dir(<skill>)`, then inspect a documented callable with `inspect.signature(<skill>.<function>)`.\",\n\t\t\t);\n\t\t} else if (canRunShellSkills) {\n\t\t\tskillLines.push(`Installed skills available as shell commands: ${installed}.`);\n\t\t}\n\t\tif (canRunShellSkills) {\n\t\t\tskillLines.push(\n\t\t\t\t\"Each skill is also available as a shell command by the same name: `<skill> ...`. Discover its CLI usage with `<skill> --help`.\",\n\t\t\t);\n\t\t}\n\t\tif (hasIpython && installedSkills.includes(\"edit\")) {\n\t\t\tskillLines.push(\n\t\t\t\t\"For targeted existing-file edits, prefer the pre-imported async `edit` skill from the REPL: `old = '''...'''; new = '''...'''; await edit(path=\\\"pkg/file.py\\\", old_str=old, new_str=new)`. Use exact old/new strings; if the text contains triple double quotes, use triple single-quoted variables or build `old`/`new` from inspected file slices.\",\n\t\t\t);\n\t\t}\n\t}\n\tif (skillLines.length > 0) {\n\t\tparts.push(\"\", ...skillLines);\n\t}\n\tif (hasAgentMessage) {\n\t\tparts.push(\n\t\t\t\"Agent messaging is restricted to your parent, siblings, and direct children; roots are siblings, and deeper communication relays through the intermediate child.\",\n\t\t);\n\t}\n\tif (hasAgentObserve) {\n\t\tparts.push(\n\t\t\t\"Agent observation is restricted to your parent, siblings, and direct children; roots are siblings, and deeper inspection relays through the intermediate child.\",\n\t\t);\n\t}\n\n\tif (allowRecursion && hasIpython) {\n\t\tparts.push(\n\t\t\t\"\",\n\t\t\t\"A callable `rlm` is already in your global namespace. `await rlm('sub-task')` spawns a child and returns immediately after task admission with `rlm_child_id`, `name`, `session_dir`, and `model`; it never waits for or returns the child's answer.\",\n\t\t\t\"Choose a stable child name with `await rlm('sub-task', name='api-reviewer')`; names must be unique among siblings. If omitted, the host generates a readable unique name.\",\n\t\t\t\"A child inherits your model. If a different model is explicitly requested, use `await rlm.find_models(...)` and an exact returned selector. An unavailable requested model fails spawn; decide whether to retry or omit `model`. Children also inherit your thinking level; the `thinking` option overrides it with any level the resolved child model supports, and an unsupported level fails spawn.\",\n\t\t);\n\t\tif (hasAgentMessage) {\n\t\t\tparts.push(\n\t\t\t\t\"Children reply explicitly with `await agent_message.send(message, receiver_role='parent')` when an answer is needed. Replies and follow-ups arrive as ordinary agent messages; not every task requires a reply.\",\n\t\t\t\t\"Use `await agent_message.list_agents()` to discover family and `await rlm.list_subagents()` to recover direct child handles. Use `agent_message.send(..., receiver_role='child', receiver_name=child.name)` for follow-ups.\",\n\t\t\t);\n\t\t} else {\n\t\t\tparts.push(\"Use `await rlm.list_subagents()` to recover direct child handles after admission.\");\n\t\t}\n\t\tif (hasAgentObserve) {\n\t\t\tparts.push(\n\t\t\t\t\"Use `agent_observe` to inspect a child's rollout. Observation is restricted to your parent, siblings, and direct children; relay through the intermediate child for deeper descendants.\",\n\t\t\t);\n\t\t} else {\n\t\t\tparts.push(\"Inspect files a child wrote when you need to collect its work without an observation capability.\");\n\t\t}\n\t\tparts.push(\n\t\t\t\"Spawn independent children in separate calls and end your turn instead of awaiting completion. Multiple replies may arrive over multiple turns. Delete a direct child explicitly with `await rlm.delete_subagent(child)` when it is no longer needed.\",\n\t\t);\n\t}\n\n\tif (hasIpython) {\n\t\tparts.push(\"\", REPL_CONTROL_PROMPT);\n\t\tif (installedSkills.includes(\"refine\")) {\n\t\t\tparts.push(\n\t\t\t\t\"\",\n\t\t\t\t\"Treat continual harness refinement as a small, evidence-backed update after observing a repeated failure or reusable tactic: diagnose the issue, update the smallest relevant continual harness component, validate on the next action, then record the outcome. Use `await refine.run()` to turn repeated delegation patterns into reusable subagent specs, repeated procedures into skills, durable facts/preferences into memories, and narrow behavioral policies into prompt addendums. It returns immediately and runs when the current turn ends, so continue working normally after calling it. Do not rewrite the whole continual harness when a focused memory, skill, prompt note, or subagent spec is enough.\",\n\t\t\t);\n\t\t}\n\t}\n\n\treturn parts.join(\"\\n\");\n}\n\n/**\n * Supplemental sub-agent delegation guidance, appended after the base RLM\n * prompt (see system-prompt.ts). The recursion block covers the mechanics\n * (`rlm(...)` admission and handle management); this block adds the\n * when and why in the same When -> Why -> menu order Claude Code's Agent tool\n * uses. The subagent-spec menu itself renders just after this, inside the\n * harness-state block.\n */\nexport function buildSubagentGuidance(\n\toptions: { includeRefineExamples?: boolean; hasAgentMessage?: boolean; hasAgentObserve?: boolean } = {},\n): string {\n\tconst lines = [\n\t\t\"# Delegating to sub-agents\",\n\t\t\"\",\n\t\t\"Spawn independent, self-contained work with `handle = await rlm('task', name='worker')`. This returns at admission, not completion; keep the handle to stop or inspect the child later.\",\n\t];\n\tif (options.hasAgentMessage) {\n\t\tlines.push(\n\t\t\t\"Ask for an explicit reply when needed. A child replies with `await agent_message.send(message, receiver_role='parent')`; parent follow-ups use `receiver_role='child'` plus the child's name or id. Not every message needs a reply.\",\n\t\t);\n\t}\n\tlines.push(\"Use `await rlm.list_subagents()` after kernel restart or compaction.\");\n\tif (options.hasAgentObserve) {\n\t\tlines.push(\"Use `agent_observe` for bounded transcript inspection.\");\n\t}\n\tlines.push(\n\t\t\"Have children write files and read those files for fan-in.\",\n\t\t\"Delegate parallel context-heavy research or independent implementation; do a single known lookup, edit, or command inline.\",\n\t);\n\tif (options.includeRefineExamples ?? true) {\n\t\tlines.push(\"Persist genuinely reusable delegation patterns with `await refine.run()`.\");\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"rlm.js","sourceRoot":"","sources":["../../../src/core/prompts/rlm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAazE,MAAM,wBAAwB,GAAG;IAChC,+MAA+M;IAC/M,uMAAuM;IACvM,gQAAgQ;CAChQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,oBAAoB,GACzB,kmBAAkmB,CAAC;AAEpmB,MAAM,mCAAmC,GAAG;IAC3C,oEAAoE;IACpE,yJAAyJ;IACzJ,4HAA4H;IAC5H,4JAA4J;CAC5J,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,mBAAmB,GAAG;IAC3B,ucAAqc;IACrc,EAAE;IACF,sWAAsW;IACtW,EAAE;IACF,gNAA8M;IAC9M,EAAE;IACF,sVAAsV;IACtV,EAAE;IACF,uvBAAuvB;IACvvB,EAAE;IACF,4dAA4d;IAC5d,EAAE;IACF,oOAAkO;IAClO,EAAE;IACF,qPAAmP;IACnP,EAAE;IACF,qWAAqW;IACrW,EAAE;IACF,swBAAswB;IACtwB,EAAE;IACF,0LAA0L;IAC1L,EAAE;IACF,kpBAAkpB;CAClpB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AASb,MAAM,UAAU,uBAAuB,CAAC,OAAkC,EAAsB;IAC/F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,KA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AE,qBAAqB,YAAY,EAAE,CAAC,CAAC;IACjF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACxB;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACpC,OAAO,GAA8F,EAAE,EAC9F;IACT,MAAM,KAAK,GAAG;QACb,4BAA4B;QAC5B,EAAE;QACF,yLAAyL;KACzL,CAAC;IACF,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CACT,sOAAsO,CACtO,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;IACnF,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;IACtE,CAAC;IACD,KAAK,CAAC,IAAI,CACT,4DAA4D,EAC5D,4HAA4H,CAC5H,CAAC;IACF,IAAI,OAAO,CAAC,qBAAqB,IAAI,IAAI,EAAE,CAAC;QAC3C,KAAK,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACxB","sourcesContent":["import { DEFAULT_RLM_EXTRA_IMPORT_LABELS } from \"../kernel/bootstrap.js\";\n\nexport interface RlmPromptOptions {\n\tcwd: string;\n\tskillsDir?: string;\n\tinstalledSkills?: string[];\n\tmessagesPath: string;\n\tallowRecursion?: boolean;\n\tdepth?: number;\n\tparentAgent?: string;\n\tactiveTools?: string[];\n}\n\nconst LONG_RUNNING_WORK_PROMPT = [\n\t\"For slow or independently completing work, use a nonblocking control loop: start the work, record its handle or output location, then end your turn. Read the result on a later turn or when a reply arrives.\",\n\t\"When delegation is available and useful, assign independent substantive tasks to separate workers. Start independent workers without waiting for each one sequentially, and let them run in parallel.\",\n\t\"Do not keep the turn open by polling with `time.sleep()` or shell `sleep`, and do not replace polling with a long blocking `await`. Await only the short operation needed to start work or inspect a result that is already available; otherwise end the turn.\",\n].join(\"\\n\");\n\nconst USER_PROGRESS_PROMPT =\n\t\"As the user-facing root agent, when work follows a plan, uses many subagents, or spans multiple turns, proactively give regular concise progress updates so the user does not have to ask. State the current plan, what has completed, any blockers, the proposed fixes, and the next actions. Lead with user-visible outcomes rather than internal process or gate names. Mention internal details only when they explain a blocker or decision. Send an update at meaningful milestones and before ending a turn while work is still running. Do not repeat unchanged status or interrupt short work with unnecessary updates.\";\n\nconst SIMPLIFIED_TECHNICAL_ENGLISH_PROMPT = [\n\t\"Use simplified technical English by default for user-facing prose.\",\n\t\"Prefer short sentences, common words, and concrete verbs. State one main action or fact per sentence when practical. Use lists for steps or conditions.\",\n\t\"Keep necessary technical terms, names, commands, code, paths, and exact quoted text unchanged. State uncertainty directly.\",\n\t\"Treat this as clarity guidance, not a claim of formal ASD-STE100 compliance. Preserve a user-requested format, tone, terminology, and necessary precision.\",\n].join(\"\\n\");\n\nconst REPL_CONTROL_PROMPT = [\n\t\"The `ipython` tool is a persistent Python REPL — the agent's long-lived control environment for reasoning, context management, state, tool orchestration, and recursive subcalls. Top-level `await` works directly. Use it to keep intermediate variables, inspect and transform outputs, and write small helper functions. Compaction removes individual variables whose serialized form exceeds 16 MiB; keep large source data on disk and reload it when needed.\",\n\t\"\",\n\t\"Reuse a named Python function for repeated multi-step work; keep one-off operations inline. Pass changing inputs explicitly and read current data each call. Save cross-task helpers as editable .py files with short project-skill instructions, without packaging them. After editing loaded code, execute its updated definition or invoke the saved file afresh.\",\n\t\"\",\n\t\"Python is the orchestration language: use Python for loops, conditionals, parsing, and state. Use `bash()` to invoke programs, not to write shell programs — no shell loops or heredocs; do those in Python.\",\n\t\"\",\n\t\"Do not assume the REPL is the native runtime of the external thing being investigated. A repository, package, service, dataset, paper, website, benchmark, or API may have its own environment and normal interface. Evaluate external systems through their own interface, then use the REPL to coordinate the process and analyze what comes back.\",\n\t\"\",\n\t\"`bash(command)` starts a shell command in the background and returns a handle immediately: `h = bash('npm test')`. Use `h.pid` / `h.running` for liveness, `h.tail(n)` / `h.output()` for combined stdout+stderr so far, `h.poll()` for a non-blocking result, `h.kill()` to terminate (SIGTERM, escalating to SIGKILL; on Windows kill() uses taskkill /T and detached or reparented descendants may survive), and `await h` (or `await bash('cmd')`) for the completed result with exit_code, output, and duration. Prefer bash() for long-running commands so the turn keeps working. Run shell commands with `bash()`, not `subprocess`/`os.system`: subprocess calls block the kernel, show the user nothing while they run, and spawn processes the harness cannot see or stop.\",\n\t\"\",\n\t\"Important: do not install dependencies into the kernel just to make an external project import or run there. If a project import, test, script, CLI, or dependency check is needed, run it through that project's own environment and normal command interface. For example, in a Python repo use its documented commands, `uv run ...`, `.venv/bin/python ...`, or the active project interpreter from the repo root. Treat failures from that native environment as the relevant result.\",\n\t\"\",\n\t\"Use Python for reading, searching, and editing files — it gives you reusable variables you can slice, filter, and act on without re-reading. Always assign read/search results to named variables so you can revisit them later.\",\n\t\"\",\n\t\"Each `bash()` call is its own process, so shell state does not persist between calls; use `os.chdir(...)` for the working directory and `os.environ[...]` for environment variables — both persist in the REPL and apply to later `bash()` calls.\",\n\t\"\",\n\t\"Python state in the kernel persists across cells: named variables, helper functions, classes, imports, notes, parsed outputs, and helper data structures all remain available in every later turn. Tool calls are themselves Python `await` expressions, so their return values can be bound to variables and composed into program logic just like any other call.\",\n\t\"\",\n\t\"Continual harness state is available as `rlm.harness` and `rlm.get_harness_state()`. CRUD calls are local to this Base Context session by default: `rlm.harness.create_memory(...)`, `rlm.harness.update_memory(...)`, `rlm.harness.delete_memory(...)`, `rlm.harness.create_skill(...)`, `rlm.harness.update_skill(...)`, `rlm.harness.delete_skill(...)`, `rlm.harness.create_subagent(...)`, `rlm.harness.update_subagent(...)`, `rlm.harness.delete_subagent(...)`, `rlm.harness.create_prompt_note(...)`, `rlm.harness.update_prompt_note(...)`, `rlm.harness.delete_prompt_note(...)`, plus `rlm.harness.record_refinement(...)` and `rlm.harness.overview()`. Use `global_=True` only for stable cross-session lessons; Python reserves `global`, so literal `global=True` is invalid syntax.\",\n\t\"\",\n\t\"Terminology: continual harness names the persisted prompt, memory, skill, and subagent layer; RLM names the runtime, Python REPL kernel, and native call interface exposed to the model.\",\n\t\"\",\n\t\"RLM-native call contract: installed Python skills are pre-imported modules. Read the matching SKILL.md and call its documented function, such as `await <skill_import>.<function>(...)`; when a CLI exists, use `<skill_import> ...` from shell. Continual harness skill entries are Python REPL skills with an explicit Python `reference` and `arguments` contract. Spawn a reusable delegation spec with `await rlm('sub-task')`; admission returns a child handle immediately. Results arrive only through an available messaging capability or files, never as an `rlm()` return value. Do not invent non-native wrappers such as `call_skill(...)` or `run_subagent(...)`.\",\n].join(\"\\n\");\n\nexport interface ChildAgentDoctrineOptions {\n\tdepth?: number;\n\tparentAgent?: string;\n\tinstalledSkills?: string[];\n\tactiveTools?: string[];\n}\n\nexport function buildChildAgentDoctrine(options: ChildAgentDoctrineOptions): string | undefined {\n\tconst depth = options.depth ?? 0;\n\tconst hasIpython = options.activeTools === undefined || options.activeTools.includes(\"ipython\");\n\tconst hasAgentMessage = options.installedSkills?.includes(\"agent_message\") ?? false;\n\tif (depth <= 0) return undefined;\n\n\tconst lines = [\n\t\t`You are a child agent spawned by ${options.parentAgent ?? \"your parent agent\"}. Task prompts are labeled \\`[task from parent]\\`.`,\n\t];\n\tif (hasAgentMessage && hasIpython) {\n\t\tlines.push(\n\t\t\t'When a task calls for an answer, reply explicitly with `await agent_message.send(message, receiver_role=\"parent\")`. Not every message or task needs a reply; continue cleanup after sending and go idle normally.',\n\t\t);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function buildRlmPrompt(options: RlmPromptOptions): string {\n\tconst { cwd, skillsDir, messagesPath } = options;\n\tconst installedSkills = options.installedSkills ?? [];\n\tconst hasAgentMessage = installedSkills.includes(\"agent_message\");\n\tconst hasAgentObserve = installedSkills.includes(\"agent_observe\");\n\tconst allowRecursion = options.allowRecursion ?? true;\n\tconst depth = options.depth ?? 0;\n\tconst activeTools = options.activeTools ?? [];\n\tconst hasIpython = options.activeTools === undefined ? true : activeTools.includes(\"ipython\");\n\tconst canRunShellSkills = hasIpython || activeTools.includes(\"bash\");\n\tconst parts = [\n\t\t\"You are a general purpose agent that uses code to solve tasks.\",\n\t\t\"You solve tasks by breaking down problems into sub-tasks, writing and executing code, observing results, and iterating one step at a time.\",\n\t\t\"When you are done, stop calling tools and state your final answer.\",\n\t\t\"\",\n\t\tLONG_RUNNING_WORK_PROMPT,\n\t\t\"\",\n\t\t...(depth === 0 ? [USER_PROGRESS_PROMPT, \"\"] : []),\n\t\tSIMPLIFIED_TECHNICAL_ENGLISH_PROMPT,\n\t\t\"\",\n\t\t`Recursive agent depth: ${depth}`,\n\t\t`Pre-installed Python packages: ${DEFAULT_RLM_EXTRA_IMPORT_LABELS.join(\", \")}.`,\n\t\t\"Install additional packages with `uv pip install <pkg>` (this is a uv-managed venv with no pip module).\",\n\t];\n\n\tconst childDoctrine = buildChildAgentDoctrine(options);\n\tif (childDoctrine) {\n\t\tparts.push(\"\", childDoctrine);\n\t}\n\n\tconst skillLines: string[] = [];\n\tif (skillsDir) {\n\t\tskillLines.push(`Local skills live under ${skillsDir}. Read their SKILL.md files when helpful.`);\n\t}\n\tif (installedSkills.length > 0) {\n\t\tconst installed = installedSkills.map((skill) => `\\`${skill}\\``).join(\", \");\n\t\tif (hasIpython) {\n\t\t\tskillLines.push(`Installed Python skill modules (pre-imported): ${installed}.`);\n\t\t\tskillLines.push(\n\t\t\t\t\"Read each skill's SKILL.md for its API. Inspect a module with `help(<skill>)` or `dir(<skill>)`, then inspect a documented callable with `inspect.signature(<skill>.<function>)`.\",\n\t\t\t);\n\t\t} else if (canRunShellSkills) {\n\t\t\tskillLines.push(`Installed skills available as shell commands: ${installed}.`);\n\t\t}\n\t\tif (canRunShellSkills) {\n\t\t\tskillLines.push(\n\t\t\t\t\"Each skill is also available as a shell command by the same name: `<skill> ...`. Discover its CLI usage with `<skill> --help`.\",\n\t\t\t);\n\t\t}\n\t\tif (hasIpython && installedSkills.includes(\"edit\")) {\n\t\t\tskillLines.push(\n\t\t\t\t\"For targeted existing-file edits, prefer the pre-imported async `edit` skill from the REPL: `old = '''...'''; new = '''...'''; await edit(path=\\\"pkg/file.py\\\", old_str=old, new_str=new)`. Use exact old/new strings; if the text contains triple double quotes, use triple single-quoted variables or build `old`/`new` from inspected file slices.\",\n\t\t\t);\n\t\t}\n\t}\n\tif (skillLines.length > 0) {\n\t\tparts.push(\"\", ...skillLines);\n\t}\n\tif (hasAgentMessage) {\n\t\tparts.push(\n\t\t\t\"Agent messaging is restricted to your parent, siblings, and direct children; roots are siblings, and deeper communication relays through the intermediate child.\",\n\t\t);\n\t}\n\tif (hasAgentObserve) {\n\t\tparts.push(\n\t\t\t\"Agent observation is restricted to your parent, siblings, and direct children; roots are siblings, and deeper inspection relays through the intermediate child.\",\n\t\t);\n\t}\n\n\tif (allowRecursion && hasIpython) {\n\t\tparts.push(\n\t\t\t\"\",\n\t\t\t\"A callable `rlm` is already in your global namespace. `await rlm('sub-task')` spawns a child and returns immediately after task admission with `rlm_child_id`, `name`, `session_dir`, and `model`; it never waits for or returns the child's answer.\",\n\t\t\t\"Choose a stable child name with `await rlm('sub-task', name='api-reviewer')`; names must be unique among siblings. If omitted, the host generates a readable unique name.\",\n\t\t\t\"A child inherits your model. If a different model is explicitly requested, use `await rlm.find_models(...)` and an exact returned selector. An unavailable requested model fails spawn; decide whether to retry or omit `model`. Children also inherit your thinking level; the `thinking` option overrides it with any level the resolved child model supports, and an unsupported level fails spawn.\",\n\t\t);\n\t\tif (hasAgentMessage) {\n\t\t\tparts.push(\n\t\t\t\t\"Children reply explicitly with `await agent_message.send(message, receiver_role='parent')` when an answer is needed. Replies and follow-ups arrive as ordinary agent messages; not every task requires a reply.\",\n\t\t\t\t\"Use `await agent_message.list_agents()` to discover family and `await rlm.list_subagents()` to recover direct child handles. Use `agent_message.send(..., receiver_role='child', receiver_name=child.name)` for follow-ups.\",\n\t\t\t);\n\t\t} else {\n\t\t\tparts.push(\"Use `await rlm.list_subagents()` to recover direct child handles after admission.\");\n\t\t}\n\t\tif (hasAgentObserve) {\n\t\t\tparts.push(\n\t\t\t\t\"Use `agent_observe` to inspect a child's rollout. Observation is restricted to your parent, siblings, and direct children; relay through the intermediate child for deeper descendants.\",\n\t\t\t);\n\t\t} else {\n\t\t\tparts.push(\"Inspect files a child wrote when you need to collect its work without an observation capability.\");\n\t\t}\n\t\tparts.push(\n\t\t\t\"Spawn independent children in separate calls and end your turn instead of awaiting completion. Multiple replies may arrive over multiple turns. Delete a direct child explicitly with `await rlm.delete_subagent(child)` when it is no longer needed.\",\n\t\t);\n\t}\n\n\tif (hasIpython) {\n\t\tparts.push(\"\", REPL_CONTROL_PROMPT);\n\t\tif (installedSkills.includes(\"refine\")) {\n\t\t\tparts.push(\n\t\t\t\t\"\",\n\t\t\t\t\"Treat continual harness refinement as a small, evidence-backed update after observing a repeated failure or reusable tactic: diagnose the issue, update the smallest relevant continual harness component, validate on the next action, then record the outcome. Use `await refine.run()` to turn repeated delegation patterns into reusable subagent specs, repeated procedures into skills, durable facts/preferences into memories, and narrow behavioral policies into prompt addendums. It returns immediately and runs when the current turn ends, so continue working normally after calling it. Do not rewrite the whole continual harness when a focused memory, skill, prompt note, or subagent spec is enough.\",\n\t\t\t);\n\t\t}\n\t}\n\n\t// Runtime coordinates follow the fixed harness guidance without moving user/project instructions.\n\tparts.push(\"\", `Working directory: ${cwd}`, `Conversation log: ${messagesPath}`);\n\treturn parts.join(\"\\n\");\n}\n\n/**\n * Supplemental sub-agent delegation guidance, appended after the base RLM\n * prompt (see system-prompt.ts). The recursion block covers the mechanics\n * (`rlm(...)` admission and handle management); this block adds the\n * when and why in the same When -> Why -> menu order Claude Code's Agent tool\n * uses. The subagent-spec menu itself renders just after this, inside the\n * harness-state block.\n */\nexport function buildSubagentGuidance(\n\toptions: { includeRefineExamples?: boolean; hasAgentMessage?: boolean; hasAgentObserve?: boolean } = {},\n): string {\n\tconst lines = [\n\t\t\"# Delegating to sub-agents\",\n\t\t\"\",\n\t\t\"Spawn independent, self-contained work with `handle = await rlm('task', name='worker')`. This returns at admission, not completion; keep the handle to stop or inspect the child later.\",\n\t];\n\tif (options.hasAgentMessage) {\n\t\tlines.push(\n\t\t\t\"Ask for an explicit reply when needed. A child replies with `await agent_message.send(message, receiver_role='parent')`; parent follow-ups use `receiver_role='child'` plus the child's name or id. Not every message needs a reply.\",\n\t\t);\n\t}\n\tlines.push(\"Use `await rlm.list_subagents()` after kernel restart or compaction.\");\n\tif (options.hasAgentObserve) {\n\t\tlines.push(\"Use `agent_observe` for bounded transcript inspection.\");\n\t}\n\tlines.push(\n\t\t\"Have children write files and read those files for fan-in.\",\n\t\t\"Delegate parallel context-heavy research or independent implementation; do a single known lookup, edit, or command inline.\",\n\t);\n\tif (options.includeRefineExamples ?? true) {\n\t\tlines.push(\"Persist genuinely reusable delegation patterns with `await refine.run()`.\");\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"public-context.d.ts","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,iCAAiC,+BAA+B,CAAC;AAE9E,uGAAuG;AACvG,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,MAAM,GACd,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAuCrC;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAsC1G","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call) => ({\n\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
1
+ {"version":3,"file":"public-context.d.ts","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,iCAAiC,+BAA+B,CAAC;AAE9E,uGAAuG;AACvG,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,MAAM,GACd,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAwCrC;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAuC1G","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { retainedToolOutput } from \"./retained-tool-output.js\";\n\nfunction retainedRecovery(message: AgentMessage, entryId: string) {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst retained = retainedToolOutput((message.details as { retainedOutput?: unknown } | undefined)?.retainedOutput);\n\treturn retained\n\t\t? {\n\t\t\t\tref: entryId,\n\t\t\t\tfield: retained.field,\n\t\t\t\tbyteLength: retained.byteLength,\n\t\t\t\tcaptureComplete: retained.captureComplete,\n\t\t\t}\n\t\t: undefined;\n}\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call) => ({\n\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
@@ -1,4 +1,18 @@
1
1
  import { stringifyBoundedJson } from "./bounded-json.js";
2
+ import { retainedToolOutput } from "./retained-tool-output.js";
3
+ function retainedRecovery(message, entryId) {
4
+ if (message.role !== "toolResult")
5
+ return undefined;
6
+ const retained = retainedToolOutput(message.details?.retainedOutput);
7
+ return retained
8
+ ? {
9
+ ref: entryId,
10
+ field: retained.field,
11
+ byteLength: retained.byteLength,
12
+ captureComplete: retained.captureComplete,
13
+ }
14
+ : undefined;
15
+ }
2
16
  export const PUBLIC_CONTEXT_RENDERER = "public-history/1";
3
17
  export const PUBLIC_TOOL_CONTINUATION_RENDERER = "public-tool-continuation/1";
4
18
  /** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */
@@ -15,6 +29,7 @@ export function renderToolContinuation(message, entryId, source, group, maxBytes
15
29
  const data = stringifyBoundedJson({
16
30
  source: { sessionId: source.sessionId },
17
31
  entryId,
32
+ ...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),
18
33
  role: message.role,
19
34
  content,
20
35
  ...(message.role === "assistant"
@@ -62,6 +77,7 @@ export function renderPublicHistory(message, entryId, maxBytes) {
62
77
  }
63
78
  const data = stringifyBoundedJson({
64
79
  entryId,
80
+ ...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),
65
81
  role: message.role,
66
82
  ...(message.role === "toolResult"
67
83
  ? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }
@@ -1 +1 @@
1
- {"version":3,"file":"public-context.js","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAKzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAC1D,MAAM,CAAC,MAAM,iCAAiC,GAAG,4BAA4B,CAAC;AAE9E,uGAAuG;AACvG,MAAM,UAAU,sBAAsB,CACrC,OAAqB,EACrB,OAAe,EACf,MAAyB,EACzB,KAA4B,EAC5B,QAAgB,EACsB;IACtC,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,CAAC,IAAI,KAA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OAAO,EAAE;YAC1F,CAAC,CAAC,EAAE,CAAC;QACN,OAAO;KACP,EACD,QAAQ,CACR,CAAC;IACF,MAAM,QAAQ,GAAkB;QAC/B,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,uBAAuB;QACnC,OAAO,EAAE,sLAAsL,IAAI,EAAE;QACrM,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;IACF,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call) => ({\n\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
1
+ {"version":3,"file":"public-context.js","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,SAAS,gBAAgB,CAAC,OAAqB,EAAE,OAAe,EAAE;IACjE,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,QAAQ,GAAG,kBAAkB,CAAE,OAAO,CAAC,OAAoD,EAAE,cAAc,CAAC,CAAC;IACnH,OAAO,QAAQ;QACd,CAAC,CAAC;YACA,GAAG,EAAE,OAAO;YACZ,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,eAAe,EAAE,QAAQ,CAAC,eAAe;SACzC;QACF,CAAC,CAAC,SAAS,CAAC;AAAA,CACb;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAC1D,MAAM,CAAC,MAAM,iCAAiC,GAAG,4BAA4B,CAAC;AAE9E,uGAAuG;AACvG,MAAM,UAAU,sBAAsB,CACrC,OAAqB,EACrB,OAAe,EACf,MAAyB,EACzB,KAA4B,EAC5B,QAAgB,EACsB;IACtC,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY;QAChE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IACzE,MAAM,OAAO,GAAqC,EAAE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CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY;YAChC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;YAC1F,CAAC,CAAC,EAAE,CAAC;QACN,OAAO;KACP,EACD,QAAQ,CACR,CAAC;IACF,MAAM,QAAQ,GAAkB;QAC/B,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,uBAAuB;QACnC,OAAO,EAAE,sLAAsL,IAAI,EAAE;QACrM,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;IACF,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { retainedToolOutput } from \"./retained-tool-output.js\";\n\nfunction retainedRecovery(message: AgentMessage, entryId: string) {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst retained = retainedToolOutput((message.details as { retainedOutput?: unknown } | undefined)?.retainedOutput);\n\treturn retained\n\t\t? {\n\t\t\t\tref: entryId,\n\t\t\t\tfield: retained.field,\n\t\t\t\tbyteLength: retained.byteLength,\n\t\t\t\tcaptureComplete: retained.captureComplete,\n\t\t\t}\n\t\t: undefined;\n}\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call) => ({\n\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
@@ -7,7 +7,7 @@ export declare const REFINEMENT_CUSTOM_TYPE = "prime-agent.refinement";
7
7
  export declare const REFINE_SKILL_NAME = "refine";
8
8
  export type RefinementKind = "prompt" | "memory" | "skill" | "subagent";
9
9
  export type RefinementAction = "create" | "update" | "delete";
10
- export type HarnessScope = "local" | "global";
10
+ export type HarnessScope = "local" | "global" | "workspace";
11
11
  export interface HarnessEntry {
12
12
  id: string;
13
13
  kind: RefinementKind;
@@ -89,10 +89,11 @@ export interface AutoRefineReview {
89
89
  export declare function inferRefinementResultScope(result: RefinementResult): HarnessScope | undefined;
90
90
  export declare function getGlobalHarnessStateDir(agentDir?: string): string;
91
91
  export declare function getLocalHarnessStateDir(sessionArtifactDir: string | undefined): string | undefined;
92
- export declare function getHarnessStatePath(harnessStateDir?: string): string;
92
+ export declare function getWorkspaceHarnessStateDir(projectRoot: string): string;
93
+ export declare function getHarnessStatePath(harnessStateDir?: string, scope?: HarnessScope): string;
93
94
  export declare function loadHarnessState(harnessStateDir?: string, scope?: HarnessScope, limits?: SessionHistoryReadLimits): HarnessState;
94
- export declare function mergeHarnessStates(globalState: HarnessState, localState?: HarnessState): HarnessState;
95
- export declare function saveHarnessState(harnessStateDir: string, state: HarnessState, limits?: SessionHistoryReadLimits): string;
95
+ export declare function mergeHarnessStates(globalState: HarnessState, localState?: HarnessState, workspaceState?: HarnessState): HarnessState;
96
+ export declare function saveHarnessState(harnessStateDir: string, state: HarnessState, limits?: SessionHistoryReadLimits, scope?: HarnessScope): string;
96
97
  export declare function getRefinementHistoryPath(harnessStateDir?: string): string;
97
98
  /**
98
99
  * Append a global-scope refinement to the cross-session history log so it can be
@@ -106,13 +107,26 @@ export declare function loadGlobalRefinementHistory(harnessStateDir?: string, li
106
107
  * win on conflict so a session that is mid-flight still resolves its own latest result.
107
108
  */
108
109
  export declare function mergeRefinementHistory(global: readonly RefinementResult[], session: readonly RefinementResult[]): RefinementResult[];
110
+ export interface ErrorFixSelectionOptions {
111
+ enabled: boolean;
112
+ /** Captured available tool names; this does not predict the next tool call. */
113
+ tools: readonly string[];
114
+ operation?: string;
115
+ goal?: string;
116
+ /** Only values already known to the owner; retrieval never probes the environment. */
117
+ environment?: Readonly<Record<string, string>>;
118
+ /** Local request-meter text cost, including the complete rendered advice wrapper. */
119
+ countTokens: (text: string) => number;
120
+ }
121
+ /** Optional contextual advice, never a replacement for current task evidence or policy. */
122
+ export declare function selectErrorFixAdvice(state: HarnessState, options: ErrorFixSelectionOptions): string;
109
123
  export declare function formatHarnessStateForPrompt(state: HarnessState, options?: {
110
124
  maxEntriesPerKind?: number;
111
- maxRefinements?: number;
112
125
  maxContentLength?: number;
113
126
  includeIpythonExamples?: boolean;
114
127
  includeShellExamples?: boolean;
115
128
  includeRefineExamples?: boolean;
129
+ errorFixSelection?: ErrorFixSelectionOptions;
116
130
  }): string;
117
131
  /**
118
132
  * Normalizes an untrusted refinement proposal while preserving invalid edit