@cleocode/core 2026.11.1-canary.9 → 2026.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/.source-stamp.json +1 -1
  2. package/dist/build-provenance.json +2 -2
  3. package/dist/config.js +2 -0
  4. package/dist/config.js.map +1 -1
  5. package/dist/doctor/db-substrate.js +14 -6
  6. package/dist/doctor/db-substrate.js.map +1 -1
  7. package/dist/doctor/migrations.d.ts +16 -0
  8. package/dist/doctor/migrations.js +85 -1
  9. package/dist/doctor/migrations.js.map +1 -1
  10. package/dist/doctor/system-health.d.ts +77 -1
  11. package/dist/doctor/system-health.js +145 -0
  12. package/dist/doctor/system-health.js.map +1 -1
  13. package/dist/errors-to-engine.d.ts +8 -4
  14. package/dist/errors-to-engine.js +9 -5
  15. package/dist/errors-to-engine.js.map +1 -1
  16. package/dist/errors.d.ts +14 -0
  17. package/dist/errors.js +10 -0
  18. package/dist/errors.js.map +1 -1
  19. package/dist/git/work-tree.js +1 -1
  20. package/dist/git/work-tree.js.map +1 -1
  21. package/dist/hygiene/census.d.ts +181 -12
  22. package/dist/hygiene/census.js +564 -86
  23. package/dist/hygiene/census.js.map +1 -1
  24. package/dist/hygiene/prune-plan-worker.d.ts +17 -0
  25. package/dist/hygiene/prune-plan-worker.js +42 -0
  26. package/dist/hygiene/prune-plan-worker.js.map +1 -0
  27. package/dist/hygiene/task-status.d.ts +20 -0
  28. package/dist/hygiene/task-status.js +71 -0
  29. package/dist/hygiene/task-status.js.map +1 -0
  30. package/dist/memory/pipeline-manifest-sqlite.d.ts +2 -1
  31. package/dist/memory/pipeline-manifest-sqlite.js +3 -2
  32. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
  33. package/dist/orchestrate/agentmbx.d.ts +5 -2
  34. package/dist/orchestrate/agentmbx.js +7 -4
  35. package/dist/orchestrate/agentmbx.js.map +1 -1
  36. package/dist/orchestrate/dispatch-workers.d.ts +10 -3
  37. package/dist/orchestrate/dispatch-workers.js +26 -14
  38. package/dist/orchestrate/dispatch-workers.js.map +1 -1
  39. package/dist/orchestrate/lead.d.ts +3 -0
  40. package/dist/orchestrate/lead.js +1 -0
  41. package/dist/orchestrate/lead.js.map +1 -1
  42. package/dist/orchestrate/orca-execution.d.ts +151 -0
  43. package/dist/orchestrate/orca-execution.js +571 -0
  44. package/dist/orchestrate/orca-execution.js.map +1 -0
  45. package/dist/orchestrate/orca-routing.d.ts +13 -0
  46. package/dist/orchestrate/orca-routing.js +142 -0
  47. package/dist/orchestrate/orca-routing.js.map +1 -0
  48. package/dist/orchestrate/spawn-ops.d.ts +50 -20
  49. package/dist/orchestrate/spawn-ops.js +332 -86
  50. package/dist/orchestrate/spawn-ops.js.map +1 -1
  51. package/dist/orchestrate/worker-records.d.ts +97 -5
  52. package/dist/orchestrate/worker-records.js +503 -11
  53. package/dist/orchestrate/worker-records.js.map +1 -1
  54. package/dist/orchestrate/worker-report.js +1 -0
  55. package/dist/orchestrate/worker-report.js.map +1 -1
  56. package/dist/orchestration/index.d.ts +8 -2
  57. package/dist/orchestration/index.js +70 -17
  58. package/dist/orchestration/index.js.map +1 -1
  59. package/dist/orchestration/spawn-prompt.d.ts +9 -2
  60. package/dist/orchestration/spawn-prompt.js +47 -18
  61. package/dist/orchestration/spawn-prompt.js.map +1 -1
  62. package/dist/orchestration/spawn.d.ts +20 -6
  63. package/dist/orchestration/spawn.js +14 -6
  64. package/dist/orchestration/spawn.js.map +1 -1
  65. package/dist/release/ci-evidence.d.ts +55 -2
  66. package/dist/release/ci-evidence.js +161 -51
  67. package/dist/release/ci-evidence.js.map +1 -1
  68. package/dist/resources/admission-ledger.d.ts +6 -0
  69. package/dist/resources/admission-ledger.js +100 -10
  70. package/dist/resources/admission-ledger.js.map +1 -1
  71. package/dist/resources/agent-lease.d.ts +7 -0
  72. package/dist/resources/agent-lease.js +37 -4
  73. package/dist/resources/agent-lease.js.map +1 -1
  74. package/dist/resources/hook-footprint.d.ts +22 -0
  75. package/dist/resources/hook-footprint.js +49 -2
  76. package/dist/resources/hook-footprint.js.map +1 -1
  77. package/dist/resources/run-class.d.ts +9 -1
  78. package/dist/resources/run-class.js +87 -6
  79. package/dist/resources/run-class.js.map +1 -1
  80. package/dist/spawn/adapter-registry.js +5 -0
  81. package/dist/spawn/adapter-registry.js.map +1 -1
  82. package/dist/spawn/branch-integration.d.ts +4 -0
  83. package/dist/spawn/branch-integration.js +10 -1
  84. package/dist/spawn/branch-integration.js.map +1 -1
  85. package/dist/store/open-cleo-db.d.ts +17 -0
  86. package/dist/store/open-cleo-db.js +39 -0
  87. package/dist/store/open-cleo-db.js.map +1 -1
  88. package/dist/store/restore-marker.js +4 -0
  89. package/dist/store/restore-marker.js.map +1 -1
  90. package/dist/store/sqlite.d.ts +21 -0
  91. package/dist/store/sqlite.js +33 -0
  92. package/dist/store/sqlite.js.map +1 -1
  93. package/dist/store/worktree-build-guard.js +3 -0
  94. package/dist/store/worktree-build-guard.js.map +1 -1
  95. package/dist/tasks/add.js +8 -0
  96. package/dist/tasks/add.js.map +1 -1
  97. package/dist/tasks/complete.d.ts +7 -3
  98. package/dist/tasks/complete.js +5 -0
  99. package/dist/tasks/complete.js.map +1 -1
  100. package/dist/tasks/engine-wrap.d.ts +3 -1
  101. package/dist/tasks/engine-wrap.js +6 -18
  102. package/dist/tasks/engine-wrap.js.map +1 -1
  103. package/dist/tasks/merge-close.d.ts +5 -3
  104. package/dist/tasks/merge-close.js +30 -10
  105. package/dist/tasks/merge-close.js.map +1 -1
  106. package/dist/tasks/pipeline-stage.d.ts +7 -1
  107. package/dist/tasks/pipeline-stage.js +44 -0
  108. package/dist/tasks/pipeline-stage.js.map +1 -1
  109. package/dist/tasks/update.js +8 -0
  110. package/dist/tasks/update.js.map +1 -1
  111. package/dist/upgrade.d.ts +4 -0
  112. package/dist/upgrade.js +32 -0
  113. package/dist/upgrade.js.map +1 -1
  114. package/dist/worktree/in-use-probe.d.ts +19 -0
  115. package/dist/worktree/in-use-probe.js +87 -0
  116. package/dist/worktree/in-use-probe.js.map +1 -1
  117. package/dist/worktree/list.d.ts +6 -6
  118. package/dist/worktree/list.js +42 -30
  119. package/dist/worktree/list.js.map +1 -1
  120. package/dist/worktree/own-project.d.ts +32 -0
  121. package/dist/worktree/own-project.js +68 -0
  122. package/dist/worktree/own-project.js.map +1 -0
  123. package/dist/worktree/prune.d.ts +11 -1
  124. package/dist/worktree/prune.js +83 -2
  125. package/dist/worktree/prune.js.map +1 -1
  126. package/package.json +12 -12
  127. package/templates/CLEO-INJECTION.md +1 -1
  128. package/templates/CLEO-REFERENCE.md +2 -2
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Project routing policy for canonically prepared Orca workers.
3
+ * @packageDocumentation
4
+ */
5
+ import { createHash } from 'node:crypto';
6
+ import { ExitCode } from '@cleocode/contracts/exit-codes.js';
7
+ import { ORCA_AGENT_HARNESSES, ORCA_AGENT_PROVIDERS, orcaAgentSchema, orcaRoutingRunSchema, orchestrateOrcaConfigSchema, } from '@cleocode/contracts/orca-execution.js';
8
+ import { getConfigValue } from '../config/registry.js';
9
+ import { CleoError } from '../errors.js';
10
+ import { getTaskAccessor } from '../store/data-accessor.js';
11
+ import { launchOrcaWorker } from './orca-execution.js';
12
+ import { listWorkerRecords, newWorkerInstanceId, retireUnconfiguredOrcaWorker, } from './worker-records.js';
13
+ /**
14
+ * Rotate across usable configured agents, retaining every sent attempt durably.
15
+ * @remarks Only a proven pre-dispatch `agent_unconfigured` refusal may advance
16
+ * to another candidate. Unknown outcomes fence the task; retries keep their harness.
17
+ * @param prepared - Canonical prompt, worker identity and worktree lock.
18
+ * @param discovery - Proven local caller and sanitized account availability.
19
+ * @param backend - Injected host execution port, never a model provider.
20
+ * @param adapterId - Optional explicit CLEO harness restriction.
21
+ * @returns The exact durable worker, including any uncertain launch outcome.
22
+ */
23
+ export async function launchRoutedOrcaWorker(prepared, discovery, backend, adapterId) {
24
+ const config = orchestrateOrcaConfigSchema.safeParse((await getConfigValue('orchestrate.orca', { projectRoot: prepared.projectRoot })) ?? {});
25
+ if (!config.success) {
26
+ // @sync-invariant none:input-shape malformed rotation policy never falls through to a native launch
27
+ throw new CleoError(ExitCode.SPAWN_VALIDATION_FAILED, 'Invalid orchestrate.orca.agents configuration.', {
28
+ fix: 'Set orchestrate.orca.agents to a nonempty unique ordered list of codex, opencode2, claude or grok.',
29
+ });
30
+ }
31
+ const agents = config.data.agents.filter((agent) => {
32
+ const provider = ORCA_AGENT_PROVIDERS[agent];
33
+ return ((adapterId === undefined || ORCA_AGENT_HARNESSES[agent] === adapterId) &&
34
+ (provider === null ||
35
+ discovery.accounts.some((account) => account.provider === provider && account.activeAccountPresent)));
36
+ });
37
+ const accessor = await getTaskAccessor(prepared.projectRoot);
38
+ const runKey = `orchestrate.orca.run:${createHash('sha256').update(JSON.stringify(discovery.context)).digest('hex')}`;
39
+ const readRun = async () => {
40
+ const state = await accessor.getMetaValue(runKey);
41
+ const saved = orcaRoutingRunSchema.safeParse(state ?? { runId: null, unconfiguredAgents: [] });
42
+ if (!saved.success) {
43
+ // @sync-invariant none:local-only an unreadable Run binding cannot authorize a replacement or reset exclusions
44
+ throw new CleoError(ExitCode.SPAWN_VALIDATION_FAILED, 'The saved Orca routing Run is invalid.', {
45
+ fix: 'Inspect the saved Orca worker bindings for this coordinator; repair the routing state without replacing unresolved attempts.',
46
+ });
47
+ }
48
+ return saved.data;
49
+ };
50
+ const currentRunId = await backend.currentRun(prepared.projectRoot, discovery.context);
51
+ if (currentRunId === null) {
52
+ const pending = (await listWorkerRecords(prepared.projectRoot, true)).find(({ execution, stoppedAt }) => stoppedAt === null &&
53
+ execution &&
54
+ execution.runId === null &&
55
+ !execution.startRefusal &&
56
+ execution.context.runtimeId === discovery.context.runtimeId &&
57
+ execution.context.coordinatorHandle === discovery.context.coordinatorHandle &&
58
+ execution.context.executionHostId === discovery.context.executionHostId);
59
+ if (pending) {
60
+ // @sync-invariant none:local-only an unresolved first launch may still create this coordinator's Run
61
+ throw new CleoError(ExitCode.SPAWN_VALIDATION_FAILED, 'The coordinator has an unresolved start with no proven Run.', {
62
+ details: { field: 'recordId', recordId: pending.recordId },
63
+ fix: `Recover the original start for ${pending.recordId} before another dispatch; preserve its claim and worktree.`,
64
+ });
65
+ }
66
+ }
67
+ await accessor.transaction(async (tx) => {
68
+ const run = await readRun();
69
+ if (run.runId !== currentRunId || currentRunId === null) {
70
+ await tx.setMetaValue(runKey, { runId: currentRunId, unconfiguredAgents: [] });
71
+ }
72
+ });
73
+ // Refusals before any Run exists belong only to this invocation.
74
+ const refused = new Set();
75
+ for (;;) {
76
+ const route = await accessor.transaction(async () => {
77
+ const run = await readRun();
78
+ const last = orcaAgentSchema
79
+ .nullable()
80
+ .safeParse(await accessor.getMetaValue('orchestrate.orca.lastAgent'));
81
+ if (!last.success) {
82
+ // @sync-invariant none:local-only corrupt rotation history refuses instead of silently resetting placement
83
+ throw new CleoError(ExitCode.SPAWN_VALIDATION_FAILED, 'The saved Orca rotation history is invalid.', {
84
+ fix: 'Inspect orchestrate.orca.agents and the saved project rotation; repair its last selected supported agent before dispatch.',
85
+ });
86
+ }
87
+ const lastIndex = last.data === null ? -1 : config.data.agents.indexOf(last.data);
88
+ const ordered = [
89
+ ...config.data.agents.slice(lastIndex + 1),
90
+ ...config.data.agents.slice(0, lastIndex + 1),
91
+ ];
92
+ const agent = ordered.find((candidate) => agents.includes(candidate) &&
93
+ !refused.has(candidate) &&
94
+ !run.unconfiguredAgents.includes(candidate));
95
+ if (!agent) {
96
+ // @sync-invariant none:local-only account or configured server-route unavailability cannot authorize another backend
97
+ throw new CleoError(ExitCode.SPAWN_VALIDATION_FAILED, 'No usable configured Orca agent is available for this Run.', {
98
+ fix: `Inspect orca account list --json and orchestrate.orca.agents; select an active account or system sign-in for a configured enabled agent${adapterId ? ` matching the explicit ${adapterId} harness` : ''}. Bound-Run exclusions clear when orca orchestration run-current reports a different Run: use orca orchestration run-create --from ${discovery.context.coordinatorHandle} --objective <new-goal> after enabling the agent. Refusals with no bound Run apply only to this dispatch.`,
99
+ });
100
+ }
101
+ return { agent, runId: run.runId };
102
+ });
103
+ const harness = ORCA_AGENT_HARNESSES[route.agent];
104
+ const record = await launchOrcaWorker({
105
+ ...prepared,
106
+ harness,
107
+ instanceId: newWorkerInstanceId(harness),
108
+ }, discovery.context, backend, route.runId);
109
+ const execution = record.execution;
110
+ // @sync-invariant none:local-only no routing progress is inferred without a persisted attempt
111
+ if (!execution)
112
+ throw new Error('The routed worker has no persisted Orca execution.');
113
+ await accessor.transaction(async (tx) => {
114
+ const run = await readRun();
115
+ if (run.runId !== null && execution.runId !== null && run.runId !== execution.runId) {
116
+ // @sync-invariant none:local-only a changed owning Run cannot authorize replacement or release of pending custody
117
+ throw new CleoError(ExitCode.SPAWN_VALIDATION_FAILED, 'The Orca coordinator Run binding changed.', {
118
+ details: { field: 'recordId', recordId: record.recordId },
119
+ fix: `Inspect the exact worker ${record.recordId} and original coordinator; retain its claim and worktree while reconciling the Run.`,
120
+ });
121
+ }
122
+ await tx.setMetaValue(runKey, {
123
+ runId: execution.runId ?? run.runId,
124
+ unconfiguredAgents: run.runId !== null && execution.startRefusal === 'agent_unconfigured'
125
+ ? [...new Set([...run.unconfiguredAgents, route.agent])]
126
+ : run.unconfiguredAgents,
127
+ });
128
+ if (['ready', 'turn_unobserved'].includes(execution.state) &&
129
+ execution.runId &&
130
+ execution.orcaTaskId &&
131
+ execution.dispatchId) {
132
+ await tx.setMetaValue('orchestrate.orca.lastAgent', route.agent);
133
+ }
134
+ });
135
+ if (execution.startRefusal !== 'agent_unconfigured')
136
+ return record;
137
+ refused.add(route.agent);
138
+ // Record the unusable route before retiring custody; a crash between them stays fenced.
139
+ await retireUnconfiguredOrcaWorker(record, prepared.projectRoot);
140
+ }
141
+ }
142
+ //# sourceMappingURL=orca-routing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orca-routing.js","sourceRoot":"","sources":["../../src/orchestrate/orca-routing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BAAoB;oBACnE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;oBACxD,CAAC,CAAC,GAAG,CAAC,kBAAkB;aAC7B,CAAC,CAAC;YACH,IACE,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC;gBACtD,SAAS,CAAC,KAAK;gBACf,SAAS,CAAC,UAAU;gBACpB,SAAS,CAAC,UAAU,EACpB,CAAC;gBACD,MAAM,EAAE,CAAC,YAAY,CAAC,4BAA4B,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACnE,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAI,SAAS,CAAC,YAAY,KAAK,oBAAoB;YAAE,OAAO,MAAM,CAAC;QACnE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,wFAAwF;QACxF,MAAM,4BAA4B,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
@@ -57,9 +57,11 @@
57
57
  * @task T1253
58
58
  * @task T9545
59
59
  */
60
- import type { AgentSpawnCapability, LeadDeniedTool, LeadMode, SpawnResult } from '@cleocode/contracts';
60
+ import type { AgentSpawnCapability, LeadDeniedTool, LeadMode, SpawnResult, SpawnWorkerSession } from '@cleocode/contracts';
61
+ import type { OrcaRoutingAdapter } from '@cleocode/contracts/orca-execution.js';
61
62
  import { type EngineResult } from '../engine-result.js';
62
63
  import type { HarnessSpawnCapability } from '../harness/types.js';
64
+ import type { HarnessHint } from '../orchestration/harness-hint.js';
63
65
  import type { SpawnPayload } from '../orchestration/spawn.js';
64
66
  export type { EngineResult };
65
67
  /**
@@ -113,20 +115,30 @@ export interface TimeoutCleanupResult {
113
115
  branchDeleted: boolean;
114
116
  /** Captured error message when cleanup failed or exceeded its own budget. */
115
117
  error?: string;
118
+ /**
119
+ * Set when cleanup was skipped because the worktree or its task lock is no
120
+ * longer the one this spawn created: a newer spawn owns it (T14483).
121
+ */
122
+ notOwned?: boolean;
116
123
  /** Milliseconds the cleanup pass took. */
117
124
  elapsedMs: number;
118
125
  }
119
126
  /**
120
- * Best-effort, bounded cleanup of a partially-provisioned worktree after the
121
- * spawn supervisor fires. Idempotent: re-running against an absent worktree
122
- * returns `worktreeRemoved: true` without erroring. Wrapped in its own
123
- * `setTimeout` so cleanup itself can never wedge the timeout envelope.
127
+ * The worktree and per-task lock one spawn created, which
128
+ * {@link runTimeoutCleanup} may remove (T14483).
124
129
  *
125
- * @param projectRoot - Absolute path to the project root.
126
- * @param taskId - Task ID whose worktree is being cleaned up.
127
- * @returns Structured cleanup outcome (never throws).
128
- * @task T9545
130
+ * @task T14483
129
131
  */
132
+ export interface OwnedSpawnWorktree {
133
+ /** Absolute path of the worktree this spawn freshly created. */
134
+ worktreePath: string;
135
+ /** Branch this spawn created the worktree on. */
136
+ branch: string;
137
+ /** Project hash scoping the per-task lock. */
138
+ projectHash: string;
139
+ /** Token of the per-task lock acquisition this spawn holds. */
140
+ lockToken: string;
141
+ }
130
142
  /**
131
143
  * Map a {@link SpawnResult} status onto the `SubagentStop` payload vocabulary.
132
144
  *
@@ -148,18 +160,26 @@ export interface TimeoutCleanupResult {
148
160
  */
149
161
  export declare function toSubagentStopStatus(status: SpawnResult['status'] | undefined): 'complete' | 'partial' | 'blocked' | 'failed';
150
162
  /**
151
- * Decide whether a failed `spawnWorktree` may be answered with
152
- * {@link runTimeoutCleanup} (T12506). Only a worktree the failing call itself
153
- * created (`freshWorktreeCreated === true`, set by `createWorktree`) is ours
154
- * to destroy; every other failure — including every lock error — is a
155
- * refusal that leaves the existing worktree untouched.
156
- *
157
- * @param err - The error thrown by `spawnWorktree` / `createWorktree`.
158
- * @returns True only when cleanup is safe.
159
- * @task T12506
163
+ * Best-effort, bounded cleanup of a partially-provisioned worktree after the
164
+ * spawn supervisor fires. Idempotent: re-running against an absent worktree
165
+ * returns `worktreeRemoved: true` without erroring. Wrapped in its own
166
+ * `setTimeout` so cleanup itself can never wedge the timeout envelope.
167
+ *
168
+ * With `owned`, removal goes through `disposeOwnedWorktree`: nothing is
169
+ * removed unless, under the task lock's mutex, the lock still carries the
170
+ * token this spawn acquired and the task's checkout is the exact path and
171
+ * branch this spawn created (T14483). After a supervisor timeout or a session
172
+ * abandonment a newer spawn of the same task may have reclaimed the lock and
173
+ * now owns that checkout. The branch is kept.
174
+ *
175
+ * @param projectRoot - Absolute path to the project root.
176
+ * @param taskId - Task ID whose worktree is being cleaned up.
177
+ * @param owned - The exact worktree path and lock token this spawn created.
178
+ * @returns Structured cleanup outcome (never throws).
179
+ * @task T9545
180
+ * @task T14483
160
181
  */
161
- export declare function shouldCleanUpFailedProvision(err: unknown): boolean;
162
- export declare function runTimeoutCleanup(projectRoot: string, taskId: string): Promise<TimeoutCleanupResult>;
182
+ export declare function runTimeoutCleanup(projectRoot: string, taskId: string, owned?: OwnedSpawnWorktree): Promise<TimeoutCleanupResult>;
163
183
  /**
164
184
  * Run the lint-changesets hygiene gate.
165
185
  *
@@ -193,8 +213,12 @@ export declare function runLintChangesets(projectRoot: string): {
193
213
  export declare function composeSpawnForTask(taskId: string, root: string, options?: {
194
214
  tier?: 0 | 1 | 2;
195
215
  sessionId?: string | null;
216
+ workerSession?: SpawnWorkerSession;
217
+ coordinatorSessionId?: string | null;
196
218
  role?: AgentSpawnCapability;
197
219
  protocol?: string;
220
+ /** Portable prompt composition when execution may rotate harnesses. */
221
+ harnessHint?: HarnessHint;
198
222
  skipAtomicityCheck?: boolean;
199
223
  /** Pre-provisioned worktree path — emits Worktree Setup section (T1140). */
200
224
  worktreePath?: string;
@@ -239,6 +263,10 @@ export declare function orchestrateSpawnSelectProvider(capabilities: HarnessSpaw
239
263
  * @task T9548
240
264
  */
241
265
  export interface OrchestrateSpawnExecuteOpts {
266
+ /** Host execution port supplied by product dispatch; absence preserves native SDK behavior. */
267
+ orca?: OrcaRoutingAdapter;
268
+ /** Exact account constraints refuse on Orca; its public launch API cannot enforce them. */
269
+ accountId?: string;
242
270
  /**
243
271
  * When `true` (default), auto-invoke {@link completeWorktreeForTask} after
244
272
  * a successful worker spawn returns. Idempotent — re-running on an already
@@ -308,6 +336,8 @@ export interface LeadSpawnOptions {
308
336
  * (`git merge --no-ff` per ADR-062) back into the project default branch
309
337
  * and pruned. The behaviour is idempotent and can be disabled by passing
310
338
  * `autoComplete: false` in {@link OrchestrateSpawnExecuteOpts}.
339
+ * A supplied Orca port selects supervised execution only after local context
340
+ * verification; those launches retain custody and never integrate at spawn.
311
341
  *
312
342
  * @param taskId - Task to spawn.
313
343
  * @param adapterId - Optional adapter id to use. Auto-selects if not provided.