/** * workerRun - the operator's worker primitive (plan: owner-console v6 S0-T1). * * A worker is NOT a standing agent identity and NOT a delegate/native-Task * subagent: it is a briefed, FRESH-session lane run - the same substrate the * report lane already uses (LaneManager serialization, loud failure, result * returned to the caller, gateway calls audited). * * CALLER CONTRACT (deadlock seal): * - Callers must be HOST CODE running OUTSIDE any lane (scheduler ticks, * work-order consumers, forwarder hooks). * - NEVER call workerRun from inside an active lane run (an LLM run's tool * handler, a report run, another worker): the parent holds its global lane * slot for its whole duration, so a nested awaited lane run can queue * behind its own parent forever. * * Concurrency: same-kind runs serialize on the `operator:worker:` * session lane; ALL operator work (reports + workers) serializes on the * 'operator' global lane, which is separate from chat 'main' so long worker * runs never block owner replies. */ import type { AgentLoopOptions, ContentBlock } from '../agent/types.js'; import type { BackendType } from '../agent/model-runner.js'; import { type WorkOrderKind } from './task-ledger.js'; /** Identity fields workerRun owns - never overridable by callers (plan E7/G3). */ export interface WorkerIdentityOptions { sessionKey: string; source: string; channelId: string; freshSession: boolean; } export type WorkerRunnerOptions = WorkerIdentityOptions & Pick & Record; /** Minimal surface of AgentLoop.runWithContent that workerRun needs (DI seam). * totalUsage is optional because the seam is structural: the real AgentLoopResult * always carries it, but injected test runners and older adapters may not. */ export interface WorkerRunner { runWithContent(content: ContentBlock[], options: WorkerRunnerOptions): Promise<{ response: string; totalUsage?: { input_tokens: number; output_tokens: number; }; }>; } export interface WorkerRunOutput { response: string; /** input+output tokens of the run; undefined when the runner reported no usage * (never a fabricated 0 - absence must stay distinguishable from "free"). */ tokensUsed?: number; } export interface WorkerRunInput { /** Worker kind (kebab-case, e.g. 'board', 'wiki', 'memory-curation'). */ kind: string; /** Procedural brief (skill text) injected ahead of the work order. */ brief: string; /** The work order payload the worker acts on. */ input: string; /** * Extra run options (e.g. the per-run scoped envelope). * Applied BEFORE the identity fields - identity always wins (plan E7/G3: * an override must never move a worker onto another lane or reset another * lane's fresh-session pool). */ runOptions?: Record; } /** Env override for the worker-run per-request CLI timeout, in whole seconds. */ export declare const WORKER_TIMEOUT_ENV = "MAMA_WORKER_TIMEOUT_SECONDS"; /** * Default worker request timeout: 600s. Worker gather runs (board/wiki briefs) * are long single model turns that overrun the 300s chat request bound - live * shadow evidence killed 8 of 31 orders mid-run at 300s ("CLI error: Request * timeout"). 600s is the plan's original per-kind number, un-dropped by that * evidence. */ export declare const DEFAULT_WORKER_TIMEOUT_SECONDS = 600; /** * Resolve the worker-run per-request CLI timeout in ms. Unset/empty -> the * 600s default; any other value MUST be a positive integer number of seconds. * A malformed value throws (no silent fallback: a typo must not quietly revert * workers to the 300s bound this raise exists to lift). */ export declare function resolveWorkerRequestTimeoutMs(env?: NodeJS.ProcessEnv): number; /** * Worker-specific system prompt (shadow-gate finding ยง8.2): the spawn-default * persona prompt carries code-act sandbox instructions, so worker tool calls * went through POST /api/code-act - a server-side surface the per-run * execution-context seam (envelope, capture override) cannot reach. A custom * systemPrompt REPLACES the persona layers entirely (agent-loop.ts:484-486), * so Claude workers advertise only the text-gateway syntax while Codex workers * use the injected native host tools. Both routes reach the same in-process * gateway executor where the per-run seam works. */ export declare function buildWorkerSystemPrompt(gatewayToolsPrompt: string, backend?: BackendType, kind?: WorkOrderKind): string; export declare function buildWorkerSessionKey(kind: string): string; /** Attach a claimed system-row id after all caller-provided options. */ export declare function attachWorkOrderAttemptContext(runOptions: Record, workorderAttemptId: number): Record & { workorderAttemptId: number; }; /** * Run a briefed worker on its own operator lane and return its output. * Throws loudly on invalid input, runner failure, or an empty response - * a worker never ends silently. */ export declare function workerRun(runner: WorkerRunner, { kind, brief, input, runOptions }: WorkerRunInput): Promise; //# sourceMappingURL=worker-run.d.ts.map