/**
 * host-driver-launch.ts — Phase J J4 thin host-side launcher for the
 * planning-driver.
 *
 * HOST_DRIVER_CONTRACT: this module ONLY overrides the launch path —
 * every agent logic decision delegates to `runDriver()` in
 * driver-runner.ts. Adding a new options field or behavioural branch
 * here is a code-smell; extend `DriverRunnerOptions` instead so the
 * world-side path inherits.
 *
 * Why a separate launcher: `runDriver`'s `main()` entry reads
 * `WORLD_ID` / `SESSION_ID` / `HOST_CP_URL` / `HOST_CP_BEARER` from
 * env and `await import('@anthropic-ai/claude-agent-sdk')`. That shape
 * suits the supervisor-fork-into-devbox path; on the host process
 * we already have those values in JS scope (no env injection across
 * a container boundary), so we bypass `main()` and call `runDriver()`
 * directly with the planning-agent system-prompt-append default.
 */
import { PLANNING_SYSTEM_PROMPT } from '../prompts/planning-agent.js';
import { runDriver, buildBrokerCanUseTool, } from './driver-runner.js';
/**
 * Launch a planning-driver in the host process. Delegates everything
 * substantive to `runDriver`; this function only translates the
 * host-side options shape into `DriverRunnerOptions` (defaulting
 * `systemPromptAppend` to the planning prompt) and bypasses `main()`'s
 * env-var fork.
 */
/**
 * Phase I I0 — planning-side widened tool allowlist.
 * The in-world supervisor path never sets extraAllowedTools (stays `[]` per
 * Decision D10). The planning-side driver defaults to including mcp__linear__*
 * so operators with a local Linear MCP server can ingest tickets without
 * configuring anything extra beyond the standard Linear MCP setup.
 */
export const PLANNING_DRIVER_EXTRA_ALLOWED_TOOLS = ['mcp__linear__*'];
export function launchHostDriver(opts) {
    return runDriver({
        worldId: opts.worldId,
        sessionId: opts.sessionId,
        hostCpUrl: opts.hostCpUrl,
        bearer: opts.bearer,
        sdkQuery: opts.sdkQuery,
        systemPromptAppend: opts.systemPromptAppend ?? PLANNING_SYSTEM_PROMPT,
        extraAllowedTools: opts.extraAllowedTools ?? PLANNING_DRIVER_EXTRA_ALLOWED_TOOLS,
        // Phase B (answer-anywhere): wire the AskUserQuestion broker seam from env,
        // at parity with driver-runner.main(). The host-side launcher previously
        // omitted canUseTool entirely, so the production SPA-agent path could never
        // route AskUserQuestion through the operator's inbox. Undefined when no
        // broker is configured → byte-identical default (SDK local picker).
        // Cancellation propagates: opts.abortSignal → runDriver signal → the SDK's
        // options.signal → the bridge's composite abort, so a blocked await never
        // leaks when the run is aborted.
        canUseTool: buildBrokerCanUseTool({
            worldId: opts.worldId,
            sessionId: opts.sessionId,
            logEnabled: true,
        }),
        abortSignal: opts.abortSignal,
    });
}
//# sourceMappingURL=host-driver-launch.js.map