Expand description
Harness construction + session-storage wiring. Mirrors the Rust-side
equivalent of the TS packages/coding-agent/src/core/sdk.ts
(createAgentSession) — build the env, tools, durable session storage, and
AgentHarnessOptions, then AgentHarness::create.
v1 scope cuts vs the TS SDK (tracked in docs/m6-cli-open-questions.md):
- Skill / prompt-template / context-file discovery IS wired
(
--no-skills/-ns,--no-prompt-templates/-np,--no-context-files/-nceach suppress one channel; project.pi/<sub>+ globalagent_dir()<sub>discovery with project-wins dedupe viacrate::resource_dirs; SYSTEM.md/APPEND_SYSTEM.md project-wins precedence). Extensionresources_discover(B5b) feeds the SAME loaders: a plugin’s discovered skill/prompt paths merge with the static dirs and re-run throughload_skills/load_prompt_templates(individual.mdfiles load too —load_skillsaccepts both dirs and files). Theme discovery is accepted but ignored (rpi has no theme system — documented divergence). Trust gating remains deferred — project resources are discovered unconditionally (a copied.pi/drops in and works). - No
--modelscycling, noModelRuntime/multi-provider. One model, one provider (Anthropic), resolved up-front bycrate::provider. - Built-in tools:
read,bash,edit,writeplus the read-onlygrep/find/ls(the TScreateCodingToolsdefault set).grep/finduse an in-processFileSystem+regex/globsetimplementation (documented divergence from the TSrg/fdshell-out; seedocs/m4-tools-open-questions.md). - Session restore (
-c/-r/--session) is partially supported: a fresh session is always created. The harness’screaterejects sessions that already have records (restore not implemented — M5f divergence #3), so-c/-r/--sessioncurrently surface a clear “not implemented” message rather than silently starting fresh. SeeSessionSelection.
Structs§
- Reload
Context - Everything
/reloadneeds to rebuild extension + resource state into a live harness. Built once inbuild(alongside the harness) and held by the TUI (cloned into the reload callback the bridge carries + the/reloadcommand handler). The harness itself is NOT held here — the TUI already owns a&AgentHarness/ a clone; passing it at the call site keeps this struct free of a harness back-reference (so it can beCloneand moved into the reload callback without borrowing the harness). - Reload
Outcome - The outcome of a reload: a human-readable status line for the transcript (counts of what reloaded), and whether any load diagnostics appeared.
Enums§
- Build
Error - A harness-build error.
- Open
Error - Errors from
open_session_by_id, split so the CLI can map them toBuildErrorwhile the TUI can surface a friendlier note. - Session
Selection - How the user asked to select a session. v1 honors
NoSession(ephemeralInMemorySessionStorage),New(a fresh JSONL file), and — new this pass —Latest/ById, which restore an existing JSONL session on launch (--continue/-c,--resume/-r,--session <id|path>). The restored transcript renders into the TUI on startup and the run continues appending to the same file.
Constants§
- BUILTIN_
TOOL_ NAMES - The built-in tool names v1 ships, in the order the TS
createCodingToolsregisters them: the mutating set (read/bash/edit/write) followed by the read-only search set (grep/find/ls).
Functions§
- build
- Build the
AgentHarnessfrom the resolved model + parsed args + cwd. - default_
session_ dir - The default session directory:
<cwd>/.pi/sessions. Mirrors the TSgetDefaultSessionDir(.pi/agent/sessionsin TS; v1 uses.pi/sessionsunder the project — a documented divergence). - default_
system_ prompt - The default coding system prompt. A condensed port of the TS
packages/coding-agent/src/core/system-prompt.tsbase prompt — the pi-internal docs/skills/context-file sections are omitted (v1 has none of that machinery), leaving the role + tools + guidelines core. - list_
session_ metadata - List the JSONL session metadata under the default session dir, newest
first. Shared by startup restore and the TUI
/sessionhot-switch. - open_
session_ by_ id - Open a session whose id matches exactly or by file-name containment
(so
--session 01a02…/ a partial id / a full file name all work). The TUI/sessionhot-switch calls this with the selector’s item value. - reload_
extension_ resources - Re-run extension + resource discovery and push the rebuilt state into the
live
harnessvia the B5d setters. The oldExtensionSession+ActionBridgeare invalidated + swapped inReloadContext’s cells. This is the single routine both/reload(TUI) and a plugin’sruntime_action(Reload)drive (the latter via the mailbox signal). - select_
session - Decide the session selection from parsed args + the resolved cwd.
Type Aliases§
- Action
Bridge Cell - The cell that holds the live
ActionBridgeacross a/reload. A plugin stores the bridge’s rawuser_datapointer duringregister; on reload the old bridge isinvalidated (in-flight calls fail fast) and the fresh onestored. The fresh session’s plugins are handed the fresh bridge pointer. - Extension
Session Cell - The cell that holds the live
ExtensionSessionacross a/reload. Cloned into every site that needs the current session (the TUI, the reload callback). On reload the old session isreplaced out (itsactiveflag flipped + its keepalive dropped, unmapping the old cdylibs) and the fresh onestored. Carried as a plainExtensionSession(notOption) — anone()placeholder fills the slot while the fresh one is being built.