{"version":3,"sources":["../src/model.ts","../src/continuation/strategies/none.ts","../src/continuation/types.ts","../src/continuation/strategies/pinned-session.ts","../src/continuation/strategies/transcript.ts","../src/continuation/strategies/native-resume.ts","../src/continuation/registry.ts","../src/index.ts"],"names":[],"mappings":";;;;;;;;AA0CO,SAAS,gBAAgB,UAAA,EAA4B;AAC1D,EAAA,OACE,2DAA2D,UAAU,CAAA,yNAAA,CAAA;AAKzE;AAGO,SAAS,aAAA,CACd,MAAA,EACA,MAAA,EACA,UAAA,EACQ;AACR,EAAA,MAAM,IAAA,GAAO,UAAA,GAAa,CAAA,EAAG,eAAA,CAAgB,UAAU,CAAC;;AAAA,CAAA,GAAS,EAAA;AACjE,EAAA,OAAO,MAAA,GAAS,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM;;AAAA,EAAO,MAAM,CAAA,CAAA,GAAK,CAAA,EAAG,IAAI,GAAG,MAAM,CAAA,CAAA;AACpE;AAGO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,oBAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF;AAoBO,SAAS,cACd,IAAA,EACwB;AACxB,EAAA,IAAI,IAAA,CAAK,GAAA,EAAK,OAAO,IAAA,CAAK,GAAA;AAC1B,EAAA,MAAM,MAA8B,EAAC;AACrC,EAAA,KAAA,MAAW,KAAK,gBAAA,EAAkB;AAChC,IAAA,MAAM,CAAA,GAAI,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA;AACvB,IAAA,IAAI,CAAA,EAAG,GAAA,CAAI,CAAC,CAAA,GAAI,CAAA;AAAA,EAClB;AACA,EAAA,OAAO,GAAA;AACT;AAGA,eAAe,SAAA,CACb,OAAA,EACA,MAAA,EACA,IAAA,EACiB;AACjB,EAAA,MAAM,UAAA,GAAa,IAAI,eAAA,EAAgB;AACvC,EAAA,MAAM,KAAA,GAAQ,UAAA;AAAA,IACZ,MAAM,WAAW,KAAA,EAAM;AAAA,IACvB,IAAA,CAAK,SAAA,IAAa,CAAA,GAAI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A,EAEA,MAAM,QAAQ,GAAA,EAAK;AAIjB,IAAA,MAAM,GAAA,CAAI,QAAQ,KAAA,EAAM;AAAA,EAC1B;AACF,CAAA;;;AC5HA,IAAM,QAAA,uBAAe,GAAA,EAAkD;AAQhE,SAAS,6BACd,QAAA,EACM;AACN,EAAA,QAAA,CAAS,GAAA,CAAI,QAAA,CAAS,EAAA,EAAI,QAAQ,CAAA;AACpC;AAEO,SAAS,wBACd,EAAA,EACsB;AACtB,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,GAAA,CAAI,EAAE,CAAA;AACzB,EAAA,IAAI,CAAC,CAAA,EAAG;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,wDAAA,EAA2D,EAAE,CAAA,cAAA,EAAiB,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,IAAA,EAAM,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA;AAAA,KACtH;AAAA,EACF;AACA,EAAA,OAAO,CAAA;AACT;AAEO,SAAS,0BAAA,GAAuD;AACrE,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,IAAA,EAAM,CAAA;AACnC;AAIA,4BAAA,CAA6B,YAAY,CAAA;AACzC,4BAAA,CAA6B,qBAAqB,CAAA;AAClD,4BAAA,CAA6B,kBAAkB,CAAA;AAC/C,4BAAA,CAA6B,oBAAoB,CAAA;;;ACrC1C,IAAM,SAAA,GAAY;AAClB,IAAM,YAAA,GAAe","file":"index.mjs","sourcesContent":["/**\n * Agent CLI as a model port — turn ANY AIP-45 agent CLI runtime into a generic\n * `complete({system?, prompt}) → {result}` executor. This is the one bridge that\n * lets the SAME registry (hermes, claude-code, opencode, codex, openclaw, …)\n * back any prompt→completion seam: a report's chapter writer, a corpus\n * distiller, a Mastra tool's judgment step. The executor swaps, the prompts\n * (built by each seam's engine) don't.\n *\n * It drives the CLI over **ACP**: per `complete()` it spawns a fresh session,\n * sends one user turn, concatenates the `text-delta` stream until `turn-end`,\n * then closes. Lives here (not in a product) so seams BELOW the products —\n * `@agentproto/corpus` distill, the CLI — can consume it without importing\n * upward. The runner is injectable so assembly is unit-tested without a binary.\n */\n\nimport type { AgentCliRuntime } from \"./types.js\"\n\n/**\n * The minimal structural model port every seam consumes. Anything with this\n * `complete` shape satisfies the corpus `ReportModelPort` / `DistillPort`-backing\n * model / an AIP `ModelPort` — duck-typed, no nominal coupling.\n */\nexport interface ModelLike {\n  complete(req: {\n    system?: string\n    prompt: string\n    [k: string]: unknown\n  }): Promise<{ result: string }>\n}\n\n/**\n * The \"file-reading sub-agent\" tier — opt-in across every file-IO-capable\n * executor. When `datasetDir` is set the executor is rooted there and granted\n * its own read tools, so instead of being limited to the excerpts a seam quotes\n * in the prompt it can open the primary sources directly and ground first-hand.\n */\nexport interface FileReadingOptions {\n  /** Absolute path to the dataset/source root the executor may read from. */\n  datasetDir?: string\n}\n\n/** The instruction prepended to a completion when {@link FileReadingOptions.datasetDir} is set. */\nexport function datasetPreamble(datasetDir: string): string {\n  return (\n    `You have direct read access to the source files under \\`${datasetDir}\\` ` +\n    `(e.g. \\`sources/\\` raw captures, \\`entries/\\` refined notes). Use your ` +\n    `file-reading tools to consult the primary sources directly when grounding ` +\n    `claims — do not rely only on the excerpts quoted in this prompt.`\n  )\n}\n\n/** Compose system + prompt with an optional source-access preamble (shared by every executor). */\nexport function composePrompt(\n  system: string | undefined,\n  prompt: string,\n  datasetDir?: string\n): string {\n  const head = datasetDir ? `${datasetPreamble(datasetDir)}\\n\\n` : \"\"\n  return system ? `${head}${system}\\n\\n${prompt}` : `${head}${prompt}`\n}\n\n/** Provider keys an agent CLI may route through, forwarded from the parent env by default. */\nexport const PROVIDER_KEY_ENV = [\n  \"OPENROUTER_API_KEY\",\n  \"ANTHROPIC_API_KEY\",\n  \"OPENAI_API_KEY\",\n] as const\n\nexport interface AgentCliModelOptions extends FileReadingOptions {\n  /**\n   * Env handed to the spawned CLI process — the provider key it routes through.\n   * Defaults to forwarding {@link PROVIDER_KEY_ENV} from the parent process env.\n   */\n  env?: Record<string, string>\n  /** Working directory for the CLI process. Defaults to `datasetDir` when set. */\n  cwd?: string\n  /** Timeout per completion (ms). Default 5 min. */\n  timeoutMs?: number\n  /**\n   * Injectable runner (composed prompt → completion text). Defaults to driving\n   * the runtime over ACP. Override in tests to avoid the CLI.\n   */\n  run?: (prompt: string) => Promise<string>\n}\n\n/** Build the env for the spawned CLI: explicit override, else forwarded provider keys. */\nexport function resolveCliEnv(\n  opts: Pick<AgentCliModelOptions, \"env\">\n): Record<string, string> {\n  if (opts.env) return opts.env\n  const env: Record<string, string> = {}\n  for (const k of PROVIDER_KEY_ENV) {\n    const v = process.env[k]\n    if (v) env[k] = v\n  }\n  return env\n}\n\n/** Drive one ACP turn on `runtime`, concatenating the text deltas. */\nasync function driveTurn(\n  runtime: AgentCliRuntime,\n  prompt: string,\n  opts: AgentCliModelOptions\n): Promise<string> {\n  const controller = new AbortController()\n  const timer = setTimeout(\n    () => controller.abort(),\n    opts.timeoutMs ?? 5 * 60 * 1000\n  )\n\n  const cwd = opts.cwd ?? opts.datasetDir\n  const session = await runtime.start({\n    env: resolveCliEnv(opts),\n    signal: controller.signal,\n    ...(cwd ? { cwd } : {}),\n  })\n\n  try {\n    let text = \"\"\n    for await (const evt of session.send({ role: \"user\", content: prompt })) {\n      if (evt.kind === \"text-delta\") {\n        text += evt.text\n      } else if (evt.kind === \"error\") {\n        throw new Error(`${runtime.definition.id} model: ${evt.error.message}`)\n      } else if (evt.kind === \"turn-end\") {\n        if (evt.reason !== \"completed\")\n          throw new Error(`${runtime.definition.id} model: turn ${evt.reason}`)\n        break\n      }\n    }\n    if (controller.signal.aborted)\n      throw new Error(`${runtime.definition.id} model: timed out`)\n    return text.trim()\n  } finally {\n    clearTimeout(timer)\n    await session.close()\n  }\n}\n\n/**\n * Build a {@link ModelLike} backed by an AIP-45 agent-CLI runtime. Hand it any\n * `*Runtime()` from the registry (Hermes, claude-code, opencode, …); per-CLI\n * presets are one-liners over this.\n */\nexport function makeAgentCliModel(\n  runtime: AgentCliRuntime,\n  opts: AgentCliModelOptions = {}\n): ModelLike {\n  const run = opts.run ?? ((prompt: string) => driveTurn(runtime, prompt, opts))\n  return {\n    async complete({ system, prompt }) {\n      return {\n        result: await run(composePrompt(system, prompt, opts.datasetDir)),\n      }\n    },\n  }\n}\n","/**\n * `none` strategy — pre-AIP-45-extension behaviour.\n *\n * Spawn a fresh session per acquire; close it on release. No state,\n * no reuse. The default when a manifest declares no `continuation`\n * block (back-compat for adapters that haven't been updated).\n */\n\nimport type { ContinuationStrategy } from \"../types.js\"\n\nexport const noneStrategy: ContinuationStrategy = {\n  id: \"none\",\n  async acquire(ctx) {\n    return ctx.runtime.start(ctx.startOptions)\n  },\n  async release(ctx) {\n    await ctx.session.close()\n  },\n}\n","/**\n * AIP-45 ContinuationStrategy interface.\n *\n * A continuation strategy decides HOW prior conversation turns reach a\n * spawned CLI on subsequent invocations. Built-ins handle:\n *\n *   - `none`           — fresh session per call (current pre-AIP-45 behaviour)\n *   - `pinned-session` — keep the spawned child alive, reuse across turns\n *   - `transcript`     — caller-supplied preamble prepended to each turn\n *   - `native-resume`  — pass a session id to the CLI's own `--resume` flag\n *\n * Adapter packages MAY register custom strategies via the registry —\n * for example, a Goose-specific strategy that uses MCP-side session\n * load semantics. Custom strategy ids require a follow-up AIP that\n * opens the `ContinuationStrategyId` enum (so the manifest schema can\n * validate them).\n *\n * The strategy owns the SESSION LIFECYCLE: `acquire` returns a session\n * the caller can `send()` against, and `release` decides whether the\n * session lives on (pinned-session) or closes immediately (none). The\n * runner / generation strategy MUST go through `acquire`/`release` —\n * it MUST NOT call `runtime.start()` / `session.close()` directly when\n * a strategy is active.\n */\n\nimport type {\n  AgentCliRuntime,\n  AgentCliRuntimeSession,\n  AgentCliStartOptions,\n  ContinuationKeyScope,\n  ContinuationStrategyId,\n  RuntimeConfig,\n  TurnContext,\n} from \"../types.js\"\n\n/**\n * Per-acquire context the strategy gets. The runner builds this from\n * the manifest, the operator config, and the current turn's identity.\n */\nexport interface AcquireContext {\n  runtime: AgentCliRuntime\n  /** Already-composed start options (cwd / env / signal / config /\n   *  turnCtx). Strategies MAY override individual fields when they\n   *  call `runtime.start(...)` themselves. */\n  startOptions: AgentCliStartOptions\n  /** Per-call config (already validated against the manifest). */\n  config: RuntimeConfig\n  /** Identity context for key derivation. */\n  turnCtx: TurnContext\n}\n\n/**\n * Strategies can hint to the runner about how the turn played out so\n * the strategy can decide whether to keep the session alive (normal\n * end), reset its TTL but keep it (transient error), or evict it\n * (dead-process error).\n */\nexport type ReleaseOutcome =\n  | { kind: \"completed\" }\n  | { kind: \"cancelled\" }\n  | { kind: \"error\"; reason: \"transient\" | \"fatal\"; message: string }\n\nexport interface ReleaseContext {\n  session: AgentCliRuntimeSession\n  outcome: ReleaseOutcome\n  turnCtx: TurnContext\n}\n\n/**\n * The strategy contract. `acquire` returns a session ready for the\n * caller to `send()` against — fresh OR reused. `release` decides\n * the session's fate. Strategies MAY hold internal state (e.g.\n * the pinned-session map) keyed by `turnCtx`.\n */\nexport interface ContinuationStrategy {\n  readonly id: ContinuationStrategyId\n  acquire(ctx: AcquireContext): Promise<AgentCliRuntimeSession>\n  release(ctx: ReleaseContext): Promise<void>\n}\n\n/**\n * Derive a stable pin key from `turnCtx` according to the manifest's\n * `pinned_session.key_scope`. Missing scope fields downgrade to a\n * less-specific key with a warning — pinning still works, it just\n * collides more.\n *\n * Returns `null` when EVERY scope field the manifest asked for is\n * missing (no key derivable; strategy falls back to per-spawn).\n */\nexport function deriveKeyFromScope(\n  scope: ContinuationKeyScope[],\n  turnCtx: TurnContext\n): string | null {\n  const parts: string[] = []\n  for (const s of scope) {\n    const v = turnCtx[s]\n    if (v) parts.push(`${s}=${v}`)\n  }\n  return parts.length === 0 ? null : parts.join(\"|\")\n}\n","/**\n * `pinned-session` strategy — keep the spawned child alive across\n * turns so the CLI's in-memory model context carries over.\n *\n * Suitable for manifests that declare `session.mode: persistent` AND\n * `context_carryover: true` (Claude Code, OpenCode, ...). Acquires\n * either reuse a live pinned session or spawn fresh and pin; releases\n * keep the session alive and reset its idle TTL. The strategy\n * auto-evicts after the manifest's `pinned_session.idle_timeout_ms`.\n *\n * The pin key is derived from `turnCtx` according to the manifest's\n * `pinned_session.key_scope` (default: `[conversation, operator]` —\n * different conversations and different operators each get their own\n * child process).\n *\n * Lost on process restart. DB-backed pin persistence is a follow-up\n * (track sessionId in `cli_sessions` table, then optionally fall back\n * to native-resume / transcript on restart).\n */\n\nimport type {\n  AgentCliRuntimeSession,\n  AgentCliRuntime,\n  AgentCliStartOptions,\n} from \"../../types.js\"\nimport type { ContinuationStrategy } from \"../types.js\"\nimport { deriveKeyFromScope } from \"../types.js\"\n\ninterface PinnedEntry {\n  session: AgentCliRuntimeSession\n  /** Cached so retry-after-eviction can recreate without re-resolving\n   *  the runtime entry from outside. */\n  runtime: AgentCliRuntime\n  /** Cached so eviction-and-retry uses the same start options. */\n  startOptions: AgentCliStartOptions\n  idleTimer: ReturnType<typeof setTimeout> | null\n}\n\nconst DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000\n\nconst pins = new Map<string, PinnedEntry>()\n\nfunction clearIdleTimer(entry: PinnedEntry): void {\n  if (entry.idleTimer) {\n    clearTimeout(entry.idleTimer)\n    entry.idleTimer = null\n  }\n}\n\nfunction scheduleIdleEviction(\n  key: string,\n  entry: PinnedEntry,\n  idleTimeoutMs: number\n): void {\n  clearIdleTimer(entry)\n  entry.idleTimer = setTimeout(() => {\n    pins.delete(key)\n    entry.session.close().catch(err => {\n      console.warn(\n        `[pinned-session] idle close failed for ${key}:`,\n        err instanceof Error ? err.message : err\n      )\n    })\n    console.log(\n      `[pinned-session] ${key} idle ${idleTimeoutMs / 60_000}m → closed`\n    )\n  }, idleTimeoutMs)\n  // Don't keep the event loop alive just for the idle close — the\n  // child will be reaped on process exit anyway. Without `unref`\n  // a stale pin would block graceful shutdown.\n  entry.idleTimer.unref?.()\n}\n\nfunction evictPin(key: string): void {\n  const entry = pins.get(key)\n  if (!entry) return\n  clearIdleTimer(entry)\n  pins.delete(key)\n  entry.session.close().catch(err => {\n    console.warn(\n      `[pinned-session] evict close failed for ${key}:`,\n      err instanceof Error ? err.message : err\n    )\n  })\n}\n\nexport const pinnedSessionStrategy: ContinuationStrategy = {\n  id: \"pinned-session\",\n\n  async acquire(ctx) {\n    const tuning = ctx.runtime.definition.continuation?.pinned_session\n    const scope = tuning?.key_scope ?? [\"conversation\", \"operator\"]\n    const key = deriveKeyFromScope(scope, ctx.turnCtx)\n    const idleTimeoutMs = tuning?.idle_timeout_ms ?? DEFAULT_IDLE_TIMEOUT_MS\n\n    if (key === null) {\n      // No identity to pin against — fall back to per-spawn behaviour.\n      // Warn so the host learns to populate turnCtx.\n      console.warn(\n        `[pinned-session] turnCtx has no fields matching key_scope ${JSON.stringify(scope)}; falling back to per-spawn (no pin).`\n      )\n      return ctx.runtime.start(ctx.startOptions)\n    }\n\n    const existing = pins.get(key)\n    if (existing) {\n      // Cancel the idle timer — this turn is reusing the pin.\n      clearIdleTimer(existing)\n      return existing.session\n    }\n\n    const session = await ctx.runtime.start(ctx.startOptions)\n    const entry: PinnedEntry = {\n      session,\n      runtime: ctx.runtime,\n      startOptions: ctx.startOptions,\n      idleTimer: null,\n    }\n    pins.set(key, entry)\n    scheduleIdleEviction(key, entry, idleTimeoutMs)\n    return session\n  },\n\n  async release(ctx) {\n    // Find the entry by identity — ReleaseContext doesn't carry `runtime`,\n    // so we match by session reference. Acceptable since the pin map is small.\n    let foundKey: string | null = null\n    for (const [k, e] of pins) {\n      if (e.session === ctx.session) {\n        foundKey = k\n        break\n      }\n    }\n\n    if (!foundKey) {\n      // Session wasn't pinned (per-spawn fallback path) — close it\n      // like the `none` strategy would.\n      await ctx.session.close()\n      return\n    }\n\n    const entry = pins.get(foundKey)!\n    const tuning = entry.runtime.definition.continuation?.pinned_session\n    const idleTimeoutMs = tuning?.idle_timeout_ms ?? DEFAULT_IDLE_TIMEOUT_MS\n\n    // Fatal errors → evict so the next turn re-spawns. Transient\n    // errors and normal completion → reset the idle TTL and keep.\n    // Cancelled (user aborted) is treated like normal completion —\n    // the user wanted to stop this turn, not the whole session.\n    if (ctx.outcome.kind === \"error\" && ctx.outcome.reason === \"fatal\") {\n      evictPin(foundKey)\n      return\n    }\n\n    scheduleIdleEviction(foundKey, entry, idleTimeoutMs)\n  },\n}\n\n/**\n * Test helper — drop all pinned entries and clear timers. Not part\n * of the public API; exposed under `__test__` so tests can reset the\n * module's singleton state between runs.\n */\nexport const __test__ = {\n  resetPins(): void {\n    for (const [k] of pins) evictPin(k)\n  },\n  pinCount(): number {\n    return pins.size\n  },\n}\n","/**\n * `transcript` strategy — works for any CLI, including those with\n * `resumable: false` and ephemeral sessions.\n *\n * The driver doesn't know about Mastra memory or the host's\n * conversation log — that's the host's domain. The host supplies the\n * preamble at acquire-time via `startOptions.config.options` (the\n * convention is option id `__transcript`, see below) and the strategy\n * is otherwise identical to `none` — fresh session per acquire,\n * close on release.\n *\n * In practice the host does the prepending itself before calling\n * `runtime.start` (it controls the `message` text). This strategy\n * exists mostly as a NAMED policy choice in the manifest — declaring\n * it tells the host \"use the transcript-replay path for this CLI\"\n * without the host needing to inspect capabilities.\n *\n * Token-costly but stateless and survives API restarts.\n */\n\nimport type { ContinuationStrategy } from \"../types.js\"\n\nexport const transcriptStrategy: ContinuationStrategy = {\n  id: \"transcript\",\n  async acquire(ctx) {\n    return ctx.runtime.start(ctx.startOptions)\n  },\n  async release(ctx) {\n    await ctx.session.close()\n  },\n}\n","/**\n * `native-resume` strategy — reattach to the agent's own session by id\n * (ACP `loadSession`, MCP equivalent, or argv-style `--resume`).\n *\n * Two-step lifecycle:\n *   1. **acquire**: look up a persisted sessionId for `turnCtx` via\n *      `loadHook`. If found, pass it to `runtime.start` as\n *      `resumeSessionId` so the protocol arm reattaches. If not, spawn\n *      fresh — and after the session is up, capture the new id from\n *      `session.sessionId` and persist it via `saveHook`.\n *   2. **release**: close the spawned process. The session lives in\n *      the agent's storage layer (e.g. Claude Code's JSONL files);\n *      cold-start resume on the next acquire reads from that store.\n *\n * Hooks are registered once per host process via\n * `configureNativeResume({ load, save })`. Without hooks the strategy\n * degrades to per-spawn behaviour with a one-line warning — it's not\n * fatal because the spawn still works, just without continuity.\n *\n * Requires the manifest to declare `capabilities.resumable: true`\n * AND the agent to advertise the matching protocol capability (e.g.\n * ACP `loadSession: true`). The schema enforces the manifest side at\n * validation; runtime capability mismatch surfaces from the protocol\n * arm as the agent's own error.\n */\n\nimport type { ContinuationStrategy, AcquireContext } from \"../types.js\"\nimport { deriveKeyFromScope } from \"../types.js\"\nimport type { TurnContext } from \"../../types.js\"\n\nexport interface NativeResumeHooks {\n  /** Look up a persisted sessionId for the given identity scope. Return\n   *  undefined when no prior session exists — strategy spawns fresh. */\n  load: (turnCtx: TurnContext) => Promise<string | undefined>\n  /** Persist a freshly-established sessionId so the next cold start\n   *  can resume. Called once per \"fresh spawn\" acquire (not per turn).\n   *  Idempotent / upsert semantics expected on the host side. */\n  save: (turnCtx: TurnContext, sessionId: string) => Promise<void>\n  /** Optional: drop the persisted entry when a session is detected as\n   *  unresumable (agent rejected loadSession with a hard error). */\n  forget?: (turnCtx: TurnContext) => Promise<void>\n}\n\nlet _hooks: NativeResumeHooks | null = null\n\n/**\n * Register the host's session-id load/save callbacks. Call once at\n * boot. Subsequent calls overwrite — useful in tests; in prod treat\n * the registration as exclusive.\n */\nexport function configureNativeResume(hooks: NativeResumeHooks): void {\n  _hooks = hooks\n}\n\n/** Reset to no-hooks. Test helper; not part of public API. */\nexport function __resetNativeResumeForTests(): void {\n  _hooks = null\n}\n\nexport const nativeResumeStrategy: ContinuationStrategy = {\n  id: \"native-resume\",\n  async acquire(ctx: AcquireContext) {\n    if (!_hooks) {\n      console.warn(\n        \"[native-resume] no hooks registered (call configureNativeResume at boot); falling back to per-spawn — no continuity.\"\n      )\n      return ctx.runtime.start(ctx.startOptions)\n    }\n    // Use the same key-derivation as pinned-session so a host can\n    // declare its scope ONCE in the manifest (`continuation.pinned_session.key_scope`)\n    // and have both strategies key off the same identity. Native-resume\n    // doesn't have its own key_scope today; it inherits.\n    const scope =\n      ctx.runtime.definition.continuation?.pinned_session?.key_scope ?? [\n        \"conversation\",\n        \"operator\",\n      ]\n    const key = deriveKeyFromScope(scope, ctx.turnCtx)\n    if (key === null) {\n      console.warn(\n        `[native-resume] turnCtx has no fields matching key_scope ${JSON.stringify(scope)}; falling back to per-spawn (no resume).`\n      )\n      return ctx.runtime.start(ctx.startOptions)\n    }\n\n    const existingId = await _hooks.load(ctx.turnCtx).catch(err => {\n      console.warn(\n        `[native-resume] load hook failed for ${key}:`,\n        err instanceof Error ? err.message : err\n      )\n      return undefined\n    })\n\n    let session\n    let resumed = false\n    if (existingId) {\n      try {\n        session = await ctx.runtime.start({\n          ...ctx.startOptions,\n          resumeSessionId: existingId,\n        })\n        resumed = true\n      } catch (err) {\n        // Most likely the agent rejected the id (session expired,\n        // wiped, mismatched cwd). Drop the stale pin and spawn fresh\n        // so the user gets continuity going forward instead of being\n        // stuck on a dead reference.\n        console.warn(\n          `[native-resume] resume failed for ${key} (id=${existingId.slice(0, 12)}…), starting fresh:`,\n          err instanceof Error ? err.message : err\n        )\n        if (_hooks.forget) {\n          await _hooks.forget(ctx.turnCtx).catch(() => undefined)\n        }\n        session = await ctx.runtime.start(ctx.startOptions)\n      }\n    } else {\n      session = await ctx.runtime.start(ctx.startOptions)\n    }\n\n    // Persist the established id when this is a NEW session (resume\n    // path keeps the same id we already have, no need to re-save).\n    // The runtime guarantees session.sessionId reflects the protocol\n    // session id when the arm exposes it.\n    if (!resumed && session.sessionId) {\n      await _hooks.save(ctx.turnCtx, session.sessionId).catch(err => {\n        console.warn(\n          `[native-resume] save hook failed for ${key}:`,\n          err instanceof Error ? err.message : err\n        )\n      })\n    }\n    return session\n  },\n\n  async release(ctx) {\n    // The protocol session lives in the agent's own storage; closing\n    // the spawned subprocess is fine — `loadSession` on the next\n    // acquire reattaches via the persisted id.\n    await ctx.session.close()\n  },\n}\n","/**\n * Continuation strategy registry.\n *\n * Module-scoped singleton — all built-ins are registered at import\n * time, custom strategies (from adapter packages) register via\n * `registerContinuationStrategy`. The runner looks up by id;\n * unregistered ids throw at acquire-time so the caller fails fast\n * with a clear \"this strategy id isn't registered\" message.\n */\n\nimport type { ContinuationStrategyId } from \"../types.js\"\nimport type { ContinuationStrategy } from \"./types.js\"\nimport { noneStrategy } from \"./strategies/none.js\"\nimport { pinnedSessionStrategy } from \"./strategies/pinned-session.js\"\nimport { transcriptStrategy } from \"./strategies/transcript.js\"\nimport { nativeResumeStrategy } from \"./strategies/native-resume.js\"\n\nconst registry = new Map<ContinuationStrategyId, ContinuationStrategy>()\n\n/**\n * Register (or replace) a continuation strategy. Adapter packages\n * MAY register custom strategies on import — but they MUST first\n * land an AIP that opens the `ContinuationStrategyId` enum so the\n * manifest schema accepts the new id.\n */\nexport function registerContinuationStrategy(\n  strategy: ContinuationStrategy\n): void {\n  registry.set(strategy.id, strategy)\n}\n\nexport function getContinuationStrategy(\n  id: ContinuationStrategyId\n): ContinuationStrategy {\n  const s = registry.get(id)\n  if (!s) {\n    throw new Error(\n      `[agent-cli] No continuation strategy registered for id '${id}'. Built-ins: ${Array.from(registry.keys()).join(\", \")}.`\n    )\n  }\n  return s\n}\n\nexport function listContinuationStrategies(): ContinuationStrategyId[] {\n  return Array.from(registry.keys())\n}\n\n// Register built-ins eagerly at module load so any importer of the\n// registry sees them. Custom strategies layer on top.\nregisterContinuationStrategy(noneStrategy)\nregisterContinuationStrategy(pinnedSessionStrategy)\nregisterContinuationStrategy(transcriptStrategy)\nregisterContinuationStrategy(nativeResumeStrategy)\n","/**\n * @agentproto/driver-agent-cli — AIP-45 AGENT-CLI.md `defineAgentCli`\n * reference impl.\n *\n * Spec: https://agentproto.sh/docs/aip-45\n *\n * Authoring paths:\n *   - TS:  `defineAgentCli({...})` → `AgentCliHandle`\n *   - MD:  `parseAgentCliManifest(src) → agentCliFromManifest({...})` → `AgentCliHandle`\n *\n * Runtime: `createAgentCliRuntime(handle)` → spawn binary, dispatch\n * turns through the protocol arm (acp / mcp / proprietary), normalise\n * events to {@link StreamEvent}.\n */\n\nexport const SPEC_NAME = \"agentcli-interactive/v1\" as const\nexport const SPEC_VERSION = \"0.1.0-alpha\" as const\n\nexport {\n  defineAgentCli,\n  createAgentCliRuntime,\n  // Same bin resolution the driver spawns with (`bin: \"node\"` → this\n  // process's execPath, `npx`/`npm` → execPath sibling when present) —\n  // exported so a host that spawns a harness outside the runtime (the CLI's\n  // ACP smoke probe) resolves argv identically instead of PATH-guessing.\n  resolveSpawnBin,\n  // Which canonical postures an adapter enforces through its isolated spawn\n  // config (claude-code / opencode) — also stamped on each started session.\n  spawnEnforcedPostures,\n} from \"./define-agent-cli.js\"\n// The live-session control surface (setModel/setSessionMode/setEffort +\n// the availableConfigOptions/availableModes/currentModeId read-surface),\n// factored out of `createAgentCliRuntime` so a host that builds its OWN\n// `AgentCliRuntimeSession` over another transport (sandbox-resident,\n// tunnel-resident) delegates to the same implementation instead of\n// hand-copying it and drifting on the next interface change.\nexport {\n  createArmSessionControls,\n  applyModelCommand,\n  promptTurn,\n  isModelSwitchAcknowledgement,\n  parseModelSwitchCommand,\n  type ArmSessionControls,\n} from \"./session-controls.js\"\n// Agent CLI → generic model port: one executor backing every prompt→completion\n// seam (report writer, corpus distiller, Mastra judgment step) over any AIP-45 CLI.\nexport {\n  makeAgentCliModel,\n  resolveCliEnv,\n  composePrompt,\n  datasetPreamble,\n  PROVIDER_KEY_ENV,\n} from \"./model.js\"\nexport type {\n  ModelLike,\n  FileReadingOptions,\n  AgentCliModelOptions,\n} from \"./model.js\"\n// Exposed so callers can build a sandbox-resident `AgentCliRuntime`\n// against the same protocol layer the host-spawn factory uses, by\n// passing a `ChildProcess`-shaped duck whose stdio is bridged to a\n// remote subprocess (e2b sandbox, ssh, etc.). See guilde's\n// `cli-session-spawn/sandbox-runtime.ts` for a worked example.\nexport {\n  createAcpProtocolArm,\n  autoAllowPermissionHandler,\n  planModePermissionHandler,\n  type AcpPermissionHandler,\n  type AcpPermissionOutcome,\n  type AcpPermissionRequestParams,\n} from \"./protocol/acp-client.js\"\nexport {\n  createPrintSession,\n  mapMastraEvent,\n  createMastraMapperState,\n  mapJcodeEvent,\n  createJcodeMapperState,\n  type PrintArmOptions,\n  type MastraMapperState,\n  type JcodeMapperState,\n} from \"./protocol/print-arm.js\"\n// Generic proprietary-protocol arm loader — dynamically imports the\n// manifest's `adapter` package. Exported so proprietary adapter packages\n// (and their tests) can drive the same loader `createAgentCliRuntime`\n// uses, without duplicating the load-and-validate logic.\nexport {\n  createProprietaryProtocolArm,\n  type ProprietaryProtocolOptions,\n} from \"./protocol/proprietary.js\"\nexport {\n  agentCliSupportsHostContextIsolation,\n  hostContextExcludes,\n} from \"./host-context.js\"\nexport { CREDENTIAL_DATA_SUBDIR } from \"./state-home.js\"\n// Whole-tree teardown for a spawned adapter process — exported so hosts that\n// spawn a harness themselves (the CLI's ACP smoke probe) tear it down the\n// same way `createAgentCliRuntime` does, instead of SIGKILLing only the\n// npx/npm wrapper and leaking its descendants.\nexport {\n  terminateChildTree,\n  descendantsOf,\n  type ProcessRow,\n  type TerminateTreeOptions,\n  type TerminateTreeResult,\n} from \"./process-tree.js\"\nexport {\n  applySessionSkills,\n  readSessionSkillsMetadata,\n  SESSION_SKILLS_ABS_DIR,\n  type SessionSkillsMetadata,\n  type ApplySessionSkillsArgs,\n  type ApplySessionSkillsResult,\n} from \"./session-skills.js\"\nexport {\n  agentCliFrontmatterSchema,\n  runtimeConfigSchema,\n  type AgentCliFrontmatter,\n  type RuntimeConfigInput,\n} from \"./schema.js\"\nexport {\n  toFileBasedMcpServers,\n  type MastracodeMcpServerConfig,\n} from \"./mcp-servers.js\"\nexport {\n  composeSpawn,\n  resolveContinuationStrategy,\n  RuntimeConfigError,\n  type ComposedSpawn,\n} from \"./manifest/compose.js\"\n// Legacy AIP-45 mode-id classification (SPEC §3.4a) — the single source the\n// daemon's `decomposeMode` shim reuses so the route/posture id set never drifts.\nexport {\n  LEGACY_GATEWAY_MODE_IDS,\n  LEGACY_POSTURE_MODE_IDS,\n  inferLegacyModeKind,\n  isLegacyExtractedModeId,\n} from \"./legacy-modes.js\"\nexport {\n  registerContinuationStrategy,\n  getContinuationStrategy,\n  listContinuationStrategies,\n} from \"./continuation/registry.js\"\nexport {\n  configureNativeResume,\n  type NativeResumeHooks,\n} from \"./continuation/strategies/native-resume.js\"\nexport {\n  deriveKeyFromScope,\n  type ContinuationStrategy,\n  type AcquireContext,\n  type ReleaseContext,\n  type ReleaseOutcome,\n} from \"./continuation/types.js\"\nexport type {\n  SteerOutcome,\n  AgentCliDefinition,\n  AgentCliHandle,\n  AgentCliProtocol,\n  AgentCliSessionMode,\n  AgentCliClient,\n  AgentCliConnectOptions,\n  AgentCliRuntime,\n  AgentCliRuntimeSession,\n  AgentCliStartOptions,\n  AgentCliSessionSkill,\n  AgentCliFsZones,\n  AgentCliStateHome,\n  AgentCliSmallModel,\n  AgentCliCapabilities,\n  AgentCliInstallMethod,\n  AgentCliVersionCheck,\n  AgentCliUpgrade,\n  AgentCliAuth,\n  AgentCliSetupStep,\n  AgentCliSetupSkipIf,\n  AgentCliSetupPersist,\n  AgentCliSession,\n  AgentCliModels,\n  AgentCliModelEntry,\n  AgentCliMcpBlock,\n  AgentCliMode,\n  AgentCliRouteSelection,\n  AgentCliOption,\n  AgentCliOptionType,\n  AgentCliPresetDeclaration,\n  AgentCliContinuation,\n  AgentCliPinnedSessionTuning,\n  AgentCliPrintConfig,\n  ContinuationStrategyId,\n  ContinuationKeyScope,\n  RuntimeConfig,\n  TurnContext,\n  StreamEvent,\n  // Result vocabularies for the three mid-session switches, and the two\n  // read-surface element types. Exported so a host can name what\n  // `AgentCliRuntimeSession`'s members hand back.\n  SetModelResult,\n  SetSessionModeResult,\n  SetEffortResult,\n  SessionConfigOption,\n  SessionMode,\n} from \"./types.js\"\n"]}