Skip to main content

Module session

Module session 

Source
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):

  • No extension / skill / prompt-template / theme / context-file discovery. The harness resources stay empty; the system prompt is either the caller’s --system-prompt or the built-in default (default_system_prompt).
  • No --models cycling, no ModelRuntime/multi-provider. One model, one provider (Anthropic), resolved up-front by crate::provider.
  • Built-in tools: read, bash, edit, write plus the read-only grep/find/ls (the TS createCodingTools default set). grep/find use an in-process FileSystem+regex/globset implementation (documented divergence from the TS rg/fd shell-out; see docs/m4-tools-open-questions.md).
  • Session restore (-c/-r/--session) is partially supported: a fresh session is always created. The harness’s create rejects sessions that already have records (restore not implemented — M5f divergence #3), so -c/-r/--session currently surface a clear “not implemented” message rather than silently starting fresh. See SessionSelection.

Enums§

BuildError
A harness-build error.
SessionSelection
How the user asked to select a session. v1 only honors NoSession (ephemeral InMemorySessionStorage) and New (a fresh JSONL file). The continue/resume/specific-session paths are recognized but not wired (the harness rejects restore — see module docs).

Constants§

BUILTIN_TOOL_NAMES
The built-in tool names v1 ships, in the order the TS createCodingTools registers them: the mutating set (read/bash/edit/write) followed by the read-only search set (grep/find/ls).

Functions§

build
Build the AgentHarness from the resolved model + parsed args + cwd.
default_session_dir
The default session directory: <cwd>/.pi/sessions. Mirrors the TS getDefaultSessionDir (.pi/agent/sessions in TS; v1 uses .pi/sessions under 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.ts base prompt — the pi-internal docs/skills/context-file sections are omitted (v1 has none of that machinery), leaving the role + tools + guidelines core.
select_session
Decide the session selection from parsed args + the resolved cwd.