@ponythewhite/base-context 1.0.15 → 1.0.16

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 (74) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/base-context-runtime/pyproject.toml +1 -1
  3. package/dist/base-context-runtime/src/rlm/bash.py +19 -0
  4. package/dist/base-context-runtime/src/rlm/job_watch.py +156 -0
  5. package/dist/base-context-runtime/src/rlm/repl.md +28 -6
  6. package/dist/base-context-runtime/src/rlm/repl.py +6 -1
  7. package/dist/base-context-runtime/test/test_bash.py +4 -4
  8. package/dist/base-context-runtime/test/test_job_watch.py +67 -0
  9. package/dist/base-context-runtime/uv.lock +1 -1
  10. package/dist/build-info.json +1 -1
  11. package/dist/bundle/{bundled-modules-O67MEO74.js → bundled-modules-2DMTK7VK.js} +2 -2
  12. package/dist/bundle/{chunk-RQFC34FM.js → chunk-MSH6QRP5.js} +1601 -820
  13. package/dist/bundle/{chunk-DGO66I3L.js → chunk-T2OK7SRV.js} +3 -2
  14. package/dist/bundle/{cli-main-2RER6PBE.js → cli-main-WL2L5IEQ.js} +2 -2
  15. package/dist/bundle/cli.js +1 -1
  16. package/dist/bundle/{main-YERLD3T4.js → main-XPIEIEQJ.js} +2 -2
  17. package/dist/core/agent-session.d.ts +2 -0
  18. package/dist/core/agent-session.d.ts.map +1 -1
  19. package/dist/core/agent-session.js +155 -9
  20. package/dist/core/agent-session.js.map +1 -1
  21. package/dist/core/history-index-worker.d.ts.map +1 -1
  22. package/dist/core/history-index-worker.js +22 -1
  23. package/dist/core/history-index-worker.js.map +1 -1
  24. package/dist/core/history-index.d.ts +2 -0
  25. package/dist/core/history-index.d.ts.map +1 -1
  26. package/dist/core/history-index.js.map +1 -1
  27. package/dist/core/job-watch.d.ts +120 -0
  28. package/dist/core/job-watch.d.ts.map +1 -0
  29. package/dist/core/job-watch.js +648 -0
  30. package/dist/core/job-watch.js.map +1 -0
  31. package/dist/core/kernel/repl-manager.d.ts +5 -1
  32. package/dist/core/kernel/repl-manager.d.ts.map +1 -1
  33. package/dist/core/kernel/repl-manager.js +52 -0
  34. package/dist/core/kernel/repl-manager.js.map +1 -1
  35. package/dist/core/kernel/shared.d.ts +12 -0
  36. package/dist/core/kernel/shared.d.ts.map +1 -1
  37. package/dist/core/kernel/shared.js.map +1 -1
  38. package/dist/core/prompts/rlm.d.ts.map +1 -1
  39. package/dist/core/prompts/rlm.js +49 -39
  40. package/dist/core/prompts/rlm.js.map +1 -1
  41. package/dist/core/session-manager.d.ts +2 -0
  42. package/dist/core/session-manager.d.ts.map +1 -1
  43. package/dist/core/session-manager.js +9 -1
  44. package/dist/core/session-manager.js.map +1 -1
  45. package/dist/core/tools/prime-context.d.ts.map +1 -1
  46. package/dist/core/tools/prime-context.js +1 -1
  47. package/dist/core/tools/prime-context.js.map +1 -1
  48. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  49. package/dist/modes/interactive/interactive-mode.js +2 -1
  50. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  51. package/dist/skills/agent-message/SKILL.md +8 -2
  52. package/dist/skills/bounded-inspect/SKILL.md +78 -0
  53. package/dist/skills/bounded-inspect/pyproject.toml +16 -0
  54. package/dist/skills/bounded-inspect/src/bounded_inspect/__init__.py +313 -0
  55. package/dist/skills/bounded-inspect/src/bounded_inspect/__main__.py +3 -0
  56. package/dist/skills/job-watch/SKILL.md +43 -0
  57. package/dist/skills/job-watch/pyproject.toml +13 -0
  58. package/dist/skills/job-watch/src/job_watch/__init__.py +61 -0
  59. package/dist/skills/rlm-heartbeat/SKILL.md +10 -6
  60. package/dist/utils/file-lines.d.ts.map +1 -1
  61. package/dist/utils/file-lines.js +6 -2
  62. package/dist/utils/file-lines.js.map +1 -1
  63. package/docs/rlm-runtime.md +4 -1
  64. package/docs/skills.md +18 -26
  65. package/package.json +4 -4
  66. package/skills/agent-message/SKILL.md +8 -2
  67. package/skills/bounded-inspect/SKILL.md +78 -0
  68. package/skills/bounded-inspect/pyproject.toml +16 -0
  69. package/skills/bounded-inspect/src/bounded_inspect/__init__.py +313 -0
  70. package/skills/bounded-inspect/src/bounded_inspect/__main__.py +3 -0
  71. package/skills/job-watch/SKILL.md +43 -0
  72. package/skills/job-watch/pyproject.toml +13 -0
  73. package/skills/job-watch/src/job_watch/__init__.py +61 -0
  74. package/skills/rlm-heartbeat/SKILL.md +10 -6
@@ -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,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,KAAK,SAAS,IAAI,O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,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
+ {"version":3,"file":"rlm.js","sourceRoot":"","sources":["../../../src/core/prompts/rlm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAazE,SAAS,0BAA0B,CAAC,WAAoB,EAAU;IACjE,OAAO;QACN,WAAW;YACV,CAAC,CAAC,uSAAuS;YACzS,CAAC,CAAC,+MAA+M;QAClN,uMAAuM;QACvM,gQAAgQ;KAChQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACb;AAED,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,SAAS,sBAAsB,CAAC,iBAA0B,EAAU;IACnE,OAAO;QACN,ucAAqc;QACrc,EAAE;QACF,yfAAyf;QACzf,EAAE;QACF,g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EAC/D,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\nfunction buildLongRunningWorkPrompt(hasJobWatch: boolean): string {\n\treturn [\n\t\thasJobWatch\n\t\t\t? \"Use `job_watch` for repeated job checks after an authorized launch. Consume prepared evidence; call `park` and end the turn only when no independent work remains. Parking holds goal and autonomous continuation, not user input. Preserve every required report. Tiny one-off commands stay inline.\"\n\t\t\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\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\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\t].join(\"\\n\");\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\nfunction buildReplControlPrompt(hasBoundedInspect: boolean): string {\n\treturn [\n\t\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\t\"\",\n\t\t\"Reuse a named Python function for repeated multi-step work; keep one-off operations inline. Once a stable operation has been useful twice, save a small editable project .py helper without packaging it. Pass current commit, configuration, paths, resource identity, and limits explicitly instead of capturing stale globals; read current data each call. After editing loaded code, execute its updated definition or invoke the saved file afresh. Repetition never authorizes another deployment or experiment.\",\n\t\t\"\",\n\t\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\t\"\",\n\t\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\t\"\",\n\t\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\t\"\",\n\t\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\t\"\",\n\t\thasBoundedInspect\n\t\t\t? \"Use Python for reading, searching, and editing files; prefer `bounded_inspect` for potentially large file evidence. Select fields/windows and emit once under one aggregate byte budget. Keep small one-off reads inline. Always assign read/search results to named variables so you can revisit them later.\"\n\t\t\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\t\"\",\n\t\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\t\"\",\n\t\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\t\"\",\n\t\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\t\"\",\n\t\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\t\"\",\n\t\t\"RLM-native call contract: installed Python skills are pre-imported modules. Use 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\t].join(\"\\n\");\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, use `await agent_message.send(message, receiver_role=\"parent\")` for short coordination and `await agent_message.send_result(summary, findings, receiver_role=\"parent\")` for substantial findings or final reports. Include the outcome and important caveats. Not every message needs a reply; finish cleanup 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\tbuildLongRunningWorkPrompt(hasIpython && installedSkills.includes(\"job_watch\")),\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\"A complete selected SKILL.md body already in context needs no duplicate read; recover it later if needed. 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 Python skill packages: ${installed}.`);\n\t\t}\n\t\tif (canRunShellSkills) {\n\t\t\tskillLines.push(\n\t\t\t\t\"Only use a shell command when the skill documents a CLI: `<skill> ...`. Discover its usage with `<skill> --help`; not every Python skill has a CLI.\",\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\"Replies and follow-ups arrive as ordinary agent messages or result capsules; request an explicit answer only when needed.\",\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(\"\", buildReplControlPrompt(installedSkills.includes(\"bounded_inspect\")));\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\"Use `agent_message.send` for short steering, blockers, and decisions. For substantial findings or final reports, a child replies with `await agent_message.send_result(summary, findings, receiver_role='parent')`; parent follow-ups use `receiver_role='child'` plus the child's name or id. Keep the outcome, important caveats, and evidence references in the summary. Avoid routine acknowledgements: messaging an idle child can start another turn.\",\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\toptions.hasAgentMessage\n\t\t\t? \"Skim result capsules first and recover details only when needed. Child results are evidence, not verified truth; newer reports do not silently supersede earlier evidence.\"\n\t\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"]}
@@ -389,6 +389,8 @@ export declare class SessionManager {
389
389
  bindRequestSink(): BoundSessionRequestSink;
390
390
  /** Capture ownership, not a history frontier: ordinary appends may finish before the checkpoint capture. */
391
391
  captureCompactionSourceOwner(): () => boolean;
392
+ /** Capture content ownership, ignoring bookkeeping and allowing the caller's known ACKed content appends. */
393
+ captureCompactionContentOwner(): (ownAppends?: number) => boolean;
392
394
  bindCompactionSink(limits?: SessionHistoryReadLimits): BoundCompactionSink;
393
395
  private _bindHistorySource;
394
396
  appendToolInvocation(invocation: ToolInvocation): Promise<string>;