/** * Role string namespace. Soft whitelist — the CLI does NOT hard-validate * specific role names. Empirically observed (peaks-qa SKILL.md):3 top * roles +3 sub-roles + arbitrary business subdivisions: * * - top: rd | qa | ui | txt | general-purpose * - qa sub-roles: qa-business | qa-perf | qa-security * - business细分: qa-business-regression | qa-business-api * | qa-business-frontend | ... * - promotable: prd-business | prd-technical | prd-ux | * ui-visual | ui-flow | ui-component | ... * * Any non-empty string is a valid role. CLI emits a "soft whitelist" * hint in --help but does not reject unknown values. */ export type SubAgentRole = string; /** * IDE-private tool-call descriptor. The LLM, upon receiving this in * the CLI's JSON envelope, must invoke the tool named `name` in its * own environment with the provided `args`. */ export interface SubAgentToolCall { readonly name: string; readonly args: Readonly>; /** * Slice 2026-06-23-audit-4th #C2: toolCall version. The IDE's * arg shape can change between versions (e.g. Claude Code's * `subagent_type: "general-purpose"` may become * `subagent_type: "claude-code-3.5"` in a future release). The * dispatcher stamps this on `buildToolCall`; the dispatch record * propagates it so a future reader can detect "this record is for * v2.0 Task, current IDE is v3.0" without inspecting args. * Pre-versioning records default to '2.0.0' on read. */ readonly toolCallVersion?: string; } /** * Input to `buildToolCall`. The CLI assembles this from the user's * command-line args (role, prompt) + state-machine lookups * (requestId, sessionId). */ export interface SubAgentDispatchInput { readonly role: SubAgentRole; readonly prompt: string; readonly requestId: string; readonly sessionId: string; } /** * Per-IDE sub-agent dispatcher contract. Each IdeAdapter exposes * one of these; the CLI calls `buildToolCall` after validating * `supportsRole` (and `null-dispatcher` is the fallback when an * IDE cannot dispatch sub-agents at all). */ export interface SubAgentDispatcher { /** * Short label used in envelope `ide` field and CLI help text. * e.g. "claude-code" / "trae" / "null". */ readonly label: string; /** * Whether this dispatcher supports dispatching a given role. * claude-code returns true for all non-empty strings; trae is * byte-identical (UNVERIFIED pending real Trae dogfood); * null-dispatcher always returns false. */ supportsRole(role: SubAgentRole): boolean; /** * Build the IDE-specific tool call descriptor for a dispatch. * Must be pure: no I/O, no side effects. The CLI wraps the * returned descriptor in its JSON envelope. */ buildToolCall(input: SubAgentDispatchInput): SubAgentToolCall; /** * 2.7.0 slice-dag-dispatcher MVP: join barrier for a batch of dispatched * sub-agents. Returns one BatchResult per dispatch in the batch. * * Default implementation in this MVP (1.2): claude-code holds an * in-process Promise queue (LRU-keyed by batchId); the four non-Claude * IDEs (trae / trae-cn / codex / cursor) return a * `awaitByLlm: true` marker so the calling LLM holds the await itself * — envelope shape is uniform. Real per-IDE implementations land in * 1.3. * * `nullSubAgentDispatcher` throws `SubAgentNotSupportedError` here. */ awaitBatch?(input: SubAgentAwaitBatchInput): Promise; } /** * 2.7.0 slice-dag-dispatcher MVP: input to the optional `awaitBatch` method. * MVP dispatch is one batch per top-level `peaks sub-agent dispatch --from-dag` * call; `batchId` is the same one returned in the dispatch envelope. */ export interface SubAgentAwaitBatchInput { readonly batchId: string; readonly dispatchCount: number; /** Per-dispatch record path; CLI already has this from the dispatch envelope. */ readonly recordPaths: readonly string[]; /** Optional cap on how long the join should wait. */ readonly timeoutMs?: number; } /** * 2.7.0 slice-dag-dispatcher MVP: per-dispatch result of a join barrier. * The CLI returns one of these per dispatch in the batch. */ export interface SubAgentBatchResult { readonly dispatchIndex: number; readonly recordPath: string; readonly status: 'done' | 'failed' | 'cancelled' | 'timeout'; readonly durationMs: number; readonly note: string | null; } /** * Claude Code dispatcher. Real, byte-level implementation. * * - `supportsRole`: any non-empty string (Claude Code's * `general-purpose` sub-agent accepts any prompt). * - `buildToolCall`: returns `{name: 'Task', args: {subagent_type, * description, prompt}}` — the exact shape the `Task` tool * in Claude Code expects. */ export declare const claudeCodeSubAgentDispatcher: SubAgentDispatcher; /** * Trae dispatcher. UNVERIFIED — Trae sub-agent tool name TBD on real * dogfood. Byte-level identical to claude-code by design so: * - The dispatcher's return shape is uniform across both adapters * — a single byte-equality test can verify the placeholder * contract. * - Future real Trae dogfood can replace the body of * `buildToolCall` without breaking the adapter contract. * * Slice #014: the legacy `subAgentToolMatcher: 'Task'` install entry * is gone — the field is removed from `IdeAdapter`. Slice #009+ * dispatched sub-agents directly, not via a PreToolUse hook. The Trae * dispatcher remains a placeholder so the dispatch surface is uniform * across adapters. * * When real Trae dogfood lands, replace the body of `buildToolCall` * with Trae's actual sub-agent tool name + args shape. The interface * stays the same; only the per-IDE wiring breaks (intentionally). */ export declare const traeSubAgentDispatcher: SubAgentDispatcher; /** * Trae-CN dispatcher. Mirrors Trae's shape with a separate label so * the CLI's IDE detection can distinguish a Trae install region * (Trae-CN differs in skill install path / log location only; * dispatch surface is identical per slice #011 framework rule). * * Slice 1.3: real `awaitBatch` — same polling core as Trae. */ export declare const traeCnSubAgentDispatcher: SubAgentDispatcher; /** * Codex (OpenAI CLI IDE) dispatcher. * * Slice #13 noted Codex's sub-agent tool name is TBD; per slice #009 * rationale, the dispatcher mirrors Claude Code's shape so the * adapter contract stays uniform. Slice 1.3 promotes Codex from * `awaitByLlmFallback` to a real `awaitBatch` (file-based polling, * Codex default 45s — Codex's documented heartbeat is slightly * slower per slice #13 R-3). */ export declare const codexSubAgentDispatcher: SubAgentDispatcher; /** * Cursor dispatcher. UNVERIFIED — Cursor sub-agent tool name TBD on * real dogfood. Byte-level identical to claude-code by design (slice * #012 framing). * * Slice 1.3: real `awaitBatch` — file-based polling, Cursor default * 30s. */ export declare const cursorSubAgentDispatcher: SubAgentDispatcher; /** * Null dispatcher for IDEs that cannot dispatch sub-agents at all * (e.g. a CLI-only IDE that has no LLM tool surface). Used as the * fallback by future unsupported-IDE adapters. The CLI returns * `{ok: false, code: "IDE_NOT_SUPPORTED"}` when the dispatcher's * `supportsRole` returns false. */ export declare const nullSubAgentDispatcher: SubAgentDispatcher; /** * Thrown by `nullSubAgentDispatcher.buildToolCall` and any future * dispatcher that does not support a given role. The CLI catches * this and returns the IDE_NOT_SUPPORTED error envelope. */ export declare class SubAgentNotSupportedError extends Error { readonly role: SubAgentRole; readonly code: "IDE_NOT_SUPPORTED"; constructor(role: SubAgentRole); } /** * Real awaitBatch for claude-code (MVP). In 1.2, dispatch + await are * both in the same process; we record the batch size and resolve after * `dispatchCount` heartbeats land for the given `recordPaths`, or after * `timeoutMs` elapses (per-dispatch `timeout` status). * * Implementation contract (MVP): * - We poll each `recordPaths[i]` for an `outcome: success | failed` or * `status: done | failed` field; if absent after `timeoutMs`, that * dispatch is reported as `timeout`. * - The poll interval is 50ms (fast enough for unit tests, cheap enough * for the MVP; the real cross-process version uses heartbeat polling). */ export declare function awaitClaudeCodeBatch(input: SubAgentAwaitBatchInput): Promise; /** * Slice 1.3 — shared per-IDE polling core for trae / trae-cn / codex / * cursor. Same polling loop shape as `awaitClaudeCodeBatch`, with * per-IDE default timeout + note prefix. The 4 IDEs differ only in * (a) `defaultTimeoutMs` (Trae / Trae-CN / Cursor = 30s, Codex = 45s * per slice #13 R-3) and (b) the `note` label surfaced when an IDE * times out (so 1.4 dogfood can attribute a timeout to the right * IDE). * * MVP rationale (per Karpathy §2 Simplicity First): the 4 IDEs * currently share the same file-based polling transport. The only * per-IDE distinction is the timeout + label. Future per-IDE * divergence (real IPC / shell hooks) is a 1.4 dogfood concern — * here we keep the dispatcher interface uniform while each IDE's * `awaitBatch` is now a real implementation rather than the 1.2 * `awaitByLlmFallback` marker. */ export interface PollDispatchRecordsOptions { readonly ide: 'trae' | 'trae-cn' | 'codex' | 'cursor'; readonly defaultTimeoutMs: number; readonly notePrefix: string; } export declare function pollDispatchRecords(input: SubAgentAwaitBatchInput, opts: PollDispatchRecordsOptions): Promise; /** * 1.2 fallback for trae / trae-cn / codex / cursor. Deprecated by * slice 1.3 — kept exported for legacy callers + back-compat tests * (the 1.2 marker is still a valid envelope shape; the 1.4 dogfood * tests can compare the marker note vs the 1.3 real note to verify * per-IDE attribution). */ export declare function awaitByLlmFallback(input: SubAgentAwaitBatchInput, ide: string): Promise; /** * In-process awaiter registration hook (used by `peaks sub-agent dispatch` * to attach a resolver; not part of the dispatcher public surface). * Reserved for slice 1.3 cross-process upgrade. */ export declare function registerClaudeCodeAwaiter(batchId: string, awaiter: Promise): void;