@cleocode/contracts 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.
- package/dist/.source-stamp.json +1 -1
- package/dist/config/manifest.d.ts.map +1 -1
- package/dist/config/manifest.js +5 -1
- package/dist/config/manifest.js.map +1 -1
- package/dist/config/types.d.ts +3 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nexus-cloud.d.ts +1 -1
- package/dist/operations/orchestrate.d.ts +9 -6
- package/dist/operations/orchestrate.d.ts.map +1 -1
- package/dist/operations/orchestrate.js.map +1 -1
- package/dist/operations/worktree.d.ts +20 -0
- package/dist/operations/worktree.d.ts.map +1 -1
- package/dist/orca-execution.d.ts +533 -0
- package/dist/orca-execution.d.ts.map +1 -0
- package/dist/orca-execution.js +385 -0
- package/dist/orca-execution.js.map +1 -0
- package/dist/project-hooks.d.ts +12 -12
- package/dist/spawn-types.d.ts +30 -0
- package/dist/spawn-types.d.ts.map +1 -1
- package/dist/spawn.d.ts +7 -0
- package/dist/spawn.d.ts.map +1 -1
- package/dist/spawn.js.map +1 -1
- package/dist/task.d.ts +13 -0
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js.map +1 -1
- package/dist/workgraph.d.ts +8 -8
- package/package.json +2 -2
- package/src/config/manifest.ts +5 -1
- package/src/config/types.ts +3 -0
- package/src/index.ts +5 -0
- package/src/operations/orchestrate.ts +9 -6
- package/src/operations/worktree.ts +21 -0
- package/src/orca-execution.ts +528 -0
- package/src/spawn-types.ts +43 -0
- package/src/spawn.ts +7 -0
- package/src/task.ts +14 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Orca execution contracts, independent of model/provider registration.
|
|
3
|
+
*
|
|
4
|
+
* @task T14455
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
9
|
+
/** Current public Orca launch APIs cannot carry the native lead's enforced guards. */
|
|
10
|
+
export const ORCA_LEAD_LAUNCH_REFUSAL = {
|
|
11
|
+
code: 'E_LEAD_TOOLS_UNSTRIPPED',
|
|
12
|
+
message:
|
|
13
|
+
'Orca cannot enforce lead tool/permission restrictions (--restricted, --tools, --allowedTools, --disallowedTools, --permission-mode, --setting-sources), strict MCP isolation (--mcp-config, --strict-mcp-config), or the owner channel and own session (--session-id, --settings, inherited owner terminal or validated user-only mbx) before launch.',
|
|
14
|
+
fix: 'Run cleo orchestrate lead <epicId> --adapter claude-code for the enforced native lead route, including inside Orca, with validated user-scope mbx for --detached; keep orchestrate.leadWorker.v1 enabled. The Orca backend needs a constrained launch API carrying these argv/settings before it can start a lead.',
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
const identifier = z.string().min(1);
|
|
18
|
+
|
|
19
|
+
/** Orca server agent ids supported by the local routing contract. */
|
|
20
|
+
export const orcaAgentSchema = z.enum(['codex', 'opencode2', 'claude', 'grok']);
|
|
21
|
+
|
|
22
|
+
/** Server agent identity, separate from CLEO harness and model identity. */
|
|
23
|
+
export type OrcaAgent = z.infer<typeof orcaAgentSchema>;
|
|
24
|
+
|
|
25
|
+
/** Ordered rotation defaults; availability is verified on the execution host. */
|
|
26
|
+
export const DEFAULT_ORCA_AGENTS: OrcaAgent[] = ['codex', 'opencode2', 'claude'];
|
|
27
|
+
|
|
28
|
+
/** Harness identity for each supported Orca server agent. */
|
|
29
|
+
export const ORCA_AGENT_HARNESSES = {
|
|
30
|
+
codex: 'codex',
|
|
31
|
+
opencode2: 'opencode',
|
|
32
|
+
claude: 'claude-code',
|
|
33
|
+
grok: 'grok',
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
/** Account inventory provider; Grok uses its server-side sign-in. */
|
|
37
|
+
export const ORCA_AGENT_PROVIDERS = {
|
|
38
|
+
codex: 'codex',
|
|
39
|
+
opencode2: 'opencode',
|
|
40
|
+
claude: 'claude',
|
|
41
|
+
grok: null,
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
/** Project rotation configuration; duplicates and unsupported ids refuse. */
|
|
45
|
+
export const orchestrateOrcaConfigSchema = z.object({
|
|
46
|
+
agents: z
|
|
47
|
+
.array(orcaAgentSchema)
|
|
48
|
+
.min(1)
|
|
49
|
+
.refine((agents) => new Set(agents).size === agents.length, 'Agent ids must be unique.')
|
|
50
|
+
.default(DEFAULT_ORCA_AGENTS),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** Configuration for `orchestrate.orca`, independent of native provider discovery. */
|
|
54
|
+
export type OrchestrateOrcaConfig = z.input<typeof orchestrateOrcaConfigSchema>;
|
|
55
|
+
|
|
56
|
+
/** Explicit execution endpoint and caller; never inferred from the newest Run. */
|
|
57
|
+
export const orcaContextSchema = z.object({
|
|
58
|
+
runtimeId: identifier,
|
|
59
|
+
coordinatorHandle: identifier,
|
|
60
|
+
executionHostId: z.literal('local'),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** Verified local endpoint used for every operation, including recovery. */
|
|
64
|
+
export type OrcaContext = z.infer<typeof orcaContextSchema>;
|
|
65
|
+
|
|
66
|
+
/** Nonsecret account availability; private account rows never leave the adapter. */
|
|
67
|
+
export interface OrcaAccountAvailability {
|
|
68
|
+
/** Provider understood by `orca account list`. */
|
|
69
|
+
provider: 'codex' | 'opencode' | 'claude';
|
|
70
|
+
/** Number of configured accounts, excluding their private fields. */
|
|
71
|
+
accountCount: number;
|
|
72
|
+
/** An active account or the provider's `system` sign-in is selected. */
|
|
73
|
+
activeAccountPresent: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Verified caller and the sanitized local account inventory. */
|
|
77
|
+
export interface OrcaDiscovery {
|
|
78
|
+
/** Runtime and coordinator proven through read-only host calls. */
|
|
79
|
+
context: OrcaContext;
|
|
80
|
+
/** Availability only; no emails, homes, credentials or exact account placement. */
|
|
81
|
+
accounts: OrcaAccountAvailability[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Durable routing state for one exact runtime/coordinator Run. */
|
|
85
|
+
export const orcaRoutingRunSchema = z.object({
|
|
86
|
+
runId: identifier.nullable(),
|
|
87
|
+
unconfiguredAgents: z.array(orcaAgentSchema),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** Persisted execution Run and its confirmed prelaunch refusals. */
|
|
91
|
+
export type OrcaRoutingRun = z.infer<typeof orcaRoutingRunSchema>;
|
|
92
|
+
|
|
93
|
+
/** Canonically prepared CLEO assignment consumed without allocating another session. */
|
|
94
|
+
export const orcaLaunchSchema = z.object({
|
|
95
|
+
projectId: identifier,
|
|
96
|
+
projectRoot: identifier,
|
|
97
|
+
taskId: identifier,
|
|
98
|
+
instanceId: identifier,
|
|
99
|
+
workerSessionId: identifier,
|
|
100
|
+
agentId: identifier,
|
|
101
|
+
role: z.enum(['worker', 'lead']),
|
|
102
|
+
protocol: identifier,
|
|
103
|
+
worktreePath: identifier,
|
|
104
|
+
worktreeBranch: identifier,
|
|
105
|
+
projectHash: identifier,
|
|
106
|
+
lockToken: identifier,
|
|
107
|
+
prompt: identifier,
|
|
108
|
+
harness: z.enum(['claude-code', 'codex', 'opencode', 'grok', 'kimi']),
|
|
109
|
+
leadMailbox: identifier.nullable(),
|
|
110
|
+
model: identifier.optional(),
|
|
111
|
+
effort: identifier.optional(),
|
|
112
|
+
accountId: identifier.optional(),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/** Input from canonical CLEO spawn preparation; Orca does not create its checkout. */
|
|
116
|
+
export type OrcaLaunch = z.infer<typeof orcaLaunchSchema>;
|
|
117
|
+
|
|
118
|
+
/** Original launch addressing, retained even when a partial receipt supplies ids. */
|
|
119
|
+
export const orcaStartBindingSchema = z.object({
|
|
120
|
+
runId: identifier.nullable(),
|
|
121
|
+
orcaTaskId: identifier.nullable(),
|
|
122
|
+
retryOf: identifier.nullable(),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/** Durable attempt, stored in the existing local worker record before launch. */
|
|
126
|
+
export const orcaAttemptSchema = z.object({
|
|
127
|
+
backend: z.literal('orca'),
|
|
128
|
+
version: z.literal(1),
|
|
129
|
+
/** Monotonic local CAS revision; repeated identical observations still serialize. */
|
|
130
|
+
revision: z.number().int().nonnegative(),
|
|
131
|
+
context: orcaContextSchema,
|
|
132
|
+
launch: orcaLaunchSchema,
|
|
133
|
+
promptDigest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
134
|
+
workspaceId: identifier,
|
|
135
|
+
workspaceSelector: identifier,
|
|
136
|
+
state: z.enum([
|
|
137
|
+
'prepared',
|
|
138
|
+
'launching',
|
|
139
|
+
'ready',
|
|
140
|
+
'turn_unobserved',
|
|
141
|
+
'outcome_unknown',
|
|
142
|
+
'stop_pending',
|
|
143
|
+
'stop_unknown',
|
|
144
|
+
'stopped',
|
|
145
|
+
'failed',
|
|
146
|
+
'circuit_broken',
|
|
147
|
+
]),
|
|
148
|
+
runId: identifier.nullable(),
|
|
149
|
+
orcaTaskId: identifier.nullable(),
|
|
150
|
+
dispatchId: identifier.nullable(),
|
|
151
|
+
retryOf: identifier.nullable(),
|
|
152
|
+
/** Absent on legacy records, whose original argv cannot safely be reconstructed. */
|
|
153
|
+
startBinding: orcaStartBindingSchema.optional(),
|
|
154
|
+
/** UUID reserved before committing a retry; its first send and every replay use this key. */
|
|
155
|
+
startRequestKey: z.string().uuid().optional(),
|
|
156
|
+
startRequestId: identifier.nullable(),
|
|
157
|
+
/** UUID reserved before committing a stop; its first send and every replay use this key. */
|
|
158
|
+
stopRequestKey: z.string().uuid().optional(),
|
|
159
|
+
/** Orca-issued stop request id, retained only when the stop receipt was received. */
|
|
160
|
+
stopRequestId: identifier.nullable(),
|
|
161
|
+
/**
|
|
162
|
+
* Set when the worker-stop reply came from a runtime that proved it enumerates
|
|
163
|
+
* every helper it stopped, so an omitted helper list means the worker had none.
|
|
164
|
+
*/
|
|
165
|
+
stopHelperEvidence: z.literal('enumerated').optional(),
|
|
166
|
+
failureCount: z.number().int().nonnegative(),
|
|
167
|
+
resourceState: z.string(),
|
|
168
|
+
/** Full receipts retain effects, residual resources and recovery advice. */
|
|
169
|
+
lastReceipt: z.string().nullable(),
|
|
170
|
+
lastError: z.string().nullable(),
|
|
171
|
+
/** Confirmed pre-dispatch refusal; never inferred from a process exit. */
|
|
172
|
+
startRefusal: z.literal('agent_unconfigured').optional(),
|
|
173
|
+
observedAt: z.string(),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/** An exact execution attempt; uncertain states always retain worker custody. */
|
|
177
|
+
export type OrcaAttempt = z.infer<typeof orcaAttemptSchema>;
|
|
178
|
+
|
|
179
|
+
/** Selected worker_done transport, independent of the canonical CLEO report bytes. */
|
|
180
|
+
export const orcaWorkerDoneSchema = z.object({
|
|
181
|
+
messageId: identifier,
|
|
182
|
+
runtimeId: identifier,
|
|
183
|
+
runId: identifier,
|
|
184
|
+
orcaTaskId: identifier,
|
|
185
|
+
dispatchId: identifier,
|
|
186
|
+
senderHandle: identifier,
|
|
187
|
+
outcome: z.enum(['succeeded', 'failed']),
|
|
188
|
+
body: z.string(),
|
|
189
|
+
reportPath: identifier,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/** Provenance returned by the read-only Orca report transport. */
|
|
193
|
+
export type OrcaWorkerDone = z.infer<typeof orcaWorkerDoneSchema>;
|
|
194
|
+
|
|
195
|
+
/** Durable report settlement; no task acceptance or process-release state is implied. */
|
|
196
|
+
export const orcaWorkerReportSchema = z.object({
|
|
197
|
+
event: orcaWorkerDoneSchema,
|
|
198
|
+
manifestId: identifier,
|
|
199
|
+
manifestDigest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
200
|
+
reportText: z.string().min(1).max(65_536),
|
|
201
|
+
reportDigest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
202
|
+
ingestedAt: z.string().datetime(),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/** Validated original report and manifest link, stored on the local worker record. */
|
|
206
|
+
export type OrcaWorkerReport = z.infer<typeof orcaWorkerReportSchema>;
|
|
207
|
+
|
|
208
|
+
/** Durable AgentMBX outbox state for the first validated report of one Dispatch. */
|
|
209
|
+
export const orcaReportDeliverySchema = z.object({
|
|
210
|
+
key: identifier,
|
|
211
|
+
mailbox: identifier.nullable(),
|
|
212
|
+
state: z.enum(['pending', 'delivered']),
|
|
213
|
+
messageId: identifier.nullable(),
|
|
214
|
+
deliveredAt: z.string().datetime().nullable(),
|
|
215
|
+
lastError: z.string().nullable(),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
/** Independent report transport acknowledgement; never CLEO acceptance evidence. */
|
|
219
|
+
export type OrcaReportDelivery = z.infer<typeof orcaReportDeliverySchema>;
|
|
220
|
+
|
|
221
|
+
/** Separate physical exit, execution retirement and logical report delivery receipts. */
|
|
222
|
+
export const orcaWorkerSettlementSchema = z.object({
|
|
223
|
+
resourceRelease: z
|
|
224
|
+
.object({
|
|
225
|
+
dispatchId: identifier,
|
|
226
|
+
releasedAt: z.string().datetime(),
|
|
227
|
+
receiptDigest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
228
|
+
receipt: identifier,
|
|
229
|
+
})
|
|
230
|
+
.optional(),
|
|
231
|
+
retiredAt: z.string().datetime().optional(),
|
|
232
|
+
reportDelivery: orcaReportDeliverySchema.optional(),
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
/** Local-only settlement fields carried by the existing CLEO worker record. */
|
|
236
|
+
export type OrcaWorkerSettlement = z.infer<typeof orcaWorkerSettlementSchema>;
|
|
237
|
+
|
|
238
|
+
/** Full transport fields validated only for the requested inbox message id. */
|
|
239
|
+
export const orcaReportMessageSchema = z.object({
|
|
240
|
+
id: identifier,
|
|
241
|
+
run_id: z.string().nullable(),
|
|
242
|
+
delivery_contract: z.string(),
|
|
243
|
+
from_handle: z.string(),
|
|
244
|
+
to_handle: z.string(),
|
|
245
|
+
type: z.string(),
|
|
246
|
+
body: z.string(),
|
|
247
|
+
payload: z.string().nullable(),
|
|
248
|
+
sender_pane_key: z.string().nullable(),
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/** Full report source envelope; unrelated inbox rows remain unvalidated JSON. */
|
|
252
|
+
export const orcaReportSourceSchema = z.object({
|
|
253
|
+
ok: z.literal(true),
|
|
254
|
+
_meta: z.object({ runtimeId: identifier }),
|
|
255
|
+
result: z.object({
|
|
256
|
+
messages: z.array(z.json()).optional(),
|
|
257
|
+
dispatch: z
|
|
258
|
+
.object({
|
|
259
|
+
id: identifier,
|
|
260
|
+
run_id: identifier,
|
|
261
|
+
task_id: identifier,
|
|
262
|
+
assignee_handle: identifier,
|
|
263
|
+
assignee_pane_key: z.string().nullable(),
|
|
264
|
+
status: z.string(),
|
|
265
|
+
})
|
|
266
|
+
.optional(),
|
|
267
|
+
}),
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
/** Parsed report source with subprocess diagnostics retained for target validation. */
|
|
271
|
+
export type OrcaReportSource = z.infer<typeof orcaReportSourceSchema> & {
|
|
272
|
+
command: OrcaCommandResult;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/** Fields Orca records from worker_done flags; prose never supplies a report or proof. */
|
|
276
|
+
export const orcaWorkerDonePayloadSchema = z.object({
|
|
277
|
+
taskId: identifier,
|
|
278
|
+
dispatchId: identifier,
|
|
279
|
+
outcome: z.enum(['succeeded', 'failed']),
|
|
280
|
+
reportPath: identifier,
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
/** Exact-record supervision request; recovery never chooses a task's newest attempt. */
|
|
284
|
+
export const orcaWorkerRequestSchema = z
|
|
285
|
+
.object({
|
|
286
|
+
action: z.enum([
|
|
287
|
+
'show',
|
|
288
|
+
'read',
|
|
289
|
+
'recover-start',
|
|
290
|
+
'recover-stop',
|
|
291
|
+
'retry',
|
|
292
|
+
'stop',
|
|
293
|
+
'ingest-report',
|
|
294
|
+
'relay-report',
|
|
295
|
+
]),
|
|
296
|
+
recordId: identifier,
|
|
297
|
+
cursor: identifier.optional(),
|
|
298
|
+
messageId: identifier.optional(),
|
|
299
|
+
})
|
|
300
|
+
.refine(({ action, cursor }) => cursor === undefined || action === 'read', {
|
|
301
|
+
message: 'A source-pinned cursor is accepted only for read.',
|
|
302
|
+
path: ['cursor'],
|
|
303
|
+
})
|
|
304
|
+
.refine(({ action, messageId }) => (action === 'ingest-report') === (messageId !== undefined), {
|
|
305
|
+
message: 'ingest-report requires an exact message id; other actions do not accept one.',
|
|
306
|
+
path: ['messageId'],
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
/** CLI and SDK input for inspecting or recovering one durable Orca attempt. */
|
|
310
|
+
export type OrcaWorkerRequest = z.infer<typeof orcaWorkerRequestSchema>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Process-side execution port. Core owns persistence and receives this port from
|
|
314
|
+
* its caller, so it never imports an adapter that builds after core.
|
|
315
|
+
*/
|
|
316
|
+
export interface OrcaExecutionAdapter {
|
|
317
|
+
/** Verify installed commands, runtime and existing workspace before admission. */
|
|
318
|
+
preflight(
|
|
319
|
+
launch: OrcaLaunch,
|
|
320
|
+
context: OrcaContext,
|
|
321
|
+
): Promise<Pick<OrcaAttempt, 'workspaceId' | 'workspaceSelector'>>;
|
|
322
|
+
/** Start a durably reserved attempt, preserving uncertain outcomes. */
|
|
323
|
+
start(attempt: OrcaAttempt): Promise<OrcaAttempt>;
|
|
324
|
+
/** Replay only the original mutation identity, including a pre-reserved retry. */
|
|
325
|
+
replayStart(attempt: OrcaAttempt): Promise<OrcaAttempt>;
|
|
326
|
+
/** Read the exact stored Dispatch identity. */
|
|
327
|
+
show(attempt: OrcaAttempt): Promise<OrcaAttempt>;
|
|
328
|
+
/** Read a bounded output page without consuming coordinator mail. */
|
|
329
|
+
read(attempt: OrcaAttempt, cursor?: string): Promise<string>;
|
|
330
|
+
/** Fetch one current-dispatch worker_done without consuming coordinator mail. */
|
|
331
|
+
readReport(attempt: OrcaAttempt, messageId: string): Promise<OrcaWorkerDone>;
|
|
332
|
+
/** Request guarded cancellation after core reserves it durably. */
|
|
333
|
+
stop(attempt: OrcaAttempt): Promise<OrcaAttempt>;
|
|
334
|
+
/** Replay only the issued stop request on its original exact Dispatch. */
|
|
335
|
+
replayStop(attempt: OrcaAttempt): Promise<OrcaAttempt>;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Host discovery port injected by product dispatch, outside the model registry. */
|
|
339
|
+
export interface OrcaRoutingAdapter extends OrcaExecutionAdapter {
|
|
340
|
+
/** Process-free admission hint; backend selection still requires verified discovery. */
|
|
341
|
+
hasContextHints(): boolean;
|
|
342
|
+
/** Null outside Orca; partial, unavailable or ambiguous contexts throw a refusal. */
|
|
343
|
+
discover(projectRoot: string): Promise<OrcaDiscovery | null>;
|
|
344
|
+
/** Inspect the exact coordinator's current Run; explicit null proves no binding. */
|
|
345
|
+
currentRun(projectRoot: string, context: OrcaContext): Promise<string | null>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Result from one bounded subprocess invocation, including nonzero JSON receipts. */
|
|
349
|
+
export interface OrcaCommandResult {
|
|
350
|
+
/** Entire stdout, with no shell or human-output parsing. */
|
|
351
|
+
stdout: string;
|
|
352
|
+
/** Diagnostic stderr. */
|
|
353
|
+
stderr: string;
|
|
354
|
+
/** Null for a transport failure or timeout; never proof of worker exit. */
|
|
355
|
+
exitCode: number | null;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Process boundary; fixtures inject this instead of launching real workers. */
|
|
359
|
+
export type OrcaCommandRunner = (
|
|
360
|
+
executable: string,
|
|
361
|
+
args: readonly string[],
|
|
362
|
+
cwd: string,
|
|
363
|
+
input?: string,
|
|
364
|
+
) => Promise<OrcaCommandResult>;
|
|
365
|
+
|
|
366
|
+
const effectSchema = z.object({
|
|
367
|
+
kind: z.string(),
|
|
368
|
+
role: z.string().optional(),
|
|
369
|
+
action: z.string().optional(),
|
|
370
|
+
id: z.string().optional(),
|
|
371
|
+
});
|
|
372
|
+
const selectionSchema = z.object({
|
|
373
|
+
agent: z.string().nullable().optional(),
|
|
374
|
+
model: z.string().nullable().optional(),
|
|
375
|
+
effort: z.string().nullable().optional(),
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Validates the wire fields used for admission and fencing. Unknown fields are
|
|
380
|
+
* ignored here and preserved in the original receipt, never treated as evidence.
|
|
381
|
+
* Audited against the installed Orca 1.4.255 full CLI views.
|
|
382
|
+
*/
|
|
383
|
+
export const orcaReplySchema = z.object({
|
|
384
|
+
ok: z.boolean(),
|
|
385
|
+
_meta: z.object({ runtimeId: z.string().nullable() }).optional(),
|
|
386
|
+
error: z
|
|
387
|
+
.object({
|
|
388
|
+
code: z.string(),
|
|
389
|
+
message: z.string(),
|
|
390
|
+
data: z
|
|
391
|
+
.object({
|
|
392
|
+
requestId: identifier.optional(),
|
|
393
|
+
orchestrationRequestId: identifier.optional(),
|
|
394
|
+
dispatchId: identifier.optional(),
|
|
395
|
+
})
|
|
396
|
+
.optional(),
|
|
397
|
+
})
|
|
398
|
+
.optional(),
|
|
399
|
+
result: z
|
|
400
|
+
.object({
|
|
401
|
+
state: z.string().optional(),
|
|
402
|
+
requestId: identifier.optional(),
|
|
403
|
+
/**
|
|
404
|
+
* Mutation ledger identity Orca stamps on every successful mutation result.
|
|
405
|
+
* @remarks Installed Orca 1.4.255 attaches `{ requestId, replayed }` to the
|
|
406
|
+
* result it records (`Jy` in the retained source), so a successful stop can
|
|
407
|
+
* be bound to the request key this attempt issued.
|
|
408
|
+
*/
|
|
409
|
+
mutation: z
|
|
410
|
+
.object({
|
|
411
|
+
requestId: identifier.optional(),
|
|
412
|
+
replayed: z.boolean().optional(),
|
|
413
|
+
})
|
|
414
|
+
.optional(),
|
|
415
|
+
stage: z.string().optional(),
|
|
416
|
+
turnStart: z.string().optional(),
|
|
417
|
+
runId: identifier.optional(),
|
|
418
|
+
run: z.object({ id: identifier }).nullable().optional(),
|
|
419
|
+
taskId: identifier.optional(),
|
|
420
|
+
dispatchId: identifier.optional(),
|
|
421
|
+
failureCount: z.number().int().nonnegative().optional(),
|
|
422
|
+
effects: z.array(effectSchema).optional(),
|
|
423
|
+
residualResources: z.array(effectSchema).optional(),
|
|
424
|
+
launch: z.object({ effective: selectionSchema.optional() }).optional(),
|
|
425
|
+
lastError: z.string().nullable().optional(),
|
|
426
|
+
processAction: z.string().optional(),
|
|
427
|
+
helpers: z
|
|
428
|
+
.array(
|
|
429
|
+
z.object({
|
|
430
|
+
dispatchId: identifier.optional(),
|
|
431
|
+
creatorDispatchId: identifier.optional(),
|
|
432
|
+
outcome: z.string(),
|
|
433
|
+
keptOpenBy: identifier.optional(),
|
|
434
|
+
state: z.string().optional(),
|
|
435
|
+
lastError: z.string().nullable().optional(),
|
|
436
|
+
}),
|
|
437
|
+
)
|
|
438
|
+
.optional(),
|
|
439
|
+
helperStopError: z.string().nullable().optional(),
|
|
440
|
+
status: z.string().optional(),
|
|
441
|
+
terminal: z
|
|
442
|
+
.object({
|
|
443
|
+
handle: identifier,
|
|
444
|
+
connected: z.boolean(),
|
|
445
|
+
writable: z.boolean(),
|
|
446
|
+
executionHostId: identifier,
|
|
447
|
+
})
|
|
448
|
+
.optional(),
|
|
449
|
+
runtime: z
|
|
450
|
+
.object({
|
|
451
|
+
runtimeId: identifier,
|
|
452
|
+
reachable: z.boolean(),
|
|
453
|
+
state: z.string(),
|
|
454
|
+
capabilities: z.array(z.string()),
|
|
455
|
+
})
|
|
456
|
+
.optional(),
|
|
457
|
+
worktree: z
|
|
458
|
+
.object({
|
|
459
|
+
id: identifier,
|
|
460
|
+
path: identifier,
|
|
461
|
+
branch: identifier,
|
|
462
|
+
hostId: identifier,
|
|
463
|
+
address: z.object({ worktree: identifier }).optional(),
|
|
464
|
+
})
|
|
465
|
+
.optional(),
|
|
466
|
+
dispatch: z
|
|
467
|
+
.object({
|
|
468
|
+
id: identifier,
|
|
469
|
+
runId: identifier,
|
|
470
|
+
taskId: identifier,
|
|
471
|
+
/** Direct creator Dispatch that started this one; null for a Run root. */
|
|
472
|
+
creatorDispatchId: identifier.nullable().optional(),
|
|
473
|
+
failureCount: z.number().int().nonnegative(),
|
|
474
|
+
})
|
|
475
|
+
.optional(),
|
|
476
|
+
worker: z
|
|
477
|
+
.object({
|
|
478
|
+
dispatchId: identifier,
|
|
479
|
+
runtimeEpoch: identifier,
|
|
480
|
+
state: z.string(),
|
|
481
|
+
stage: z.string(),
|
|
482
|
+
worktreeId: identifier.nullable(),
|
|
483
|
+
})
|
|
484
|
+
.optional(),
|
|
485
|
+
observation: z.object({ status: z.string(), exactWorker: z.boolean().optional() }).optional(),
|
|
486
|
+
projection: z
|
|
487
|
+
.object({
|
|
488
|
+
resource: z
|
|
489
|
+
.object({
|
|
490
|
+
state: z.string(),
|
|
491
|
+
terminalState: z.string(),
|
|
492
|
+
ownerDispatchId: identifier.optional(),
|
|
493
|
+
releaseState: z.string().optional(),
|
|
494
|
+
})
|
|
495
|
+
.optional(),
|
|
496
|
+
})
|
|
497
|
+
.optional(),
|
|
498
|
+
})
|
|
499
|
+
.optional(),
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
/** Validated subset of a full Orca response. */
|
|
503
|
+
export type OrcaReply = z.infer<typeof orcaReplySchema>;
|
|
504
|
+
|
|
505
|
+
/** Parsed fields alongside the original receipt, kept per call during parallel fanout. */
|
|
506
|
+
export type OrcaCommandReply = OrcaReply & { rawReceipt: string };
|
|
507
|
+
|
|
508
|
+
/** Installed command declarations; PATH presence alone never authorizes a launch. */
|
|
509
|
+
export const orcaCommandRegistrySchema = z.object({
|
|
510
|
+
schemaVersion: z.number().int().positive(),
|
|
511
|
+
commands: z.array(z.object({ command: identifier, flags: z.array(z.string()) })),
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
const accountProviderSchema = z.object({
|
|
515
|
+
accounts: z.array(z.object({})),
|
|
516
|
+
activeAccountId: identifier.nullable(),
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
/** Private account wire fields: account attributes are discarded during parsing. */
|
|
520
|
+
export const orcaAccountReplySchema = z.object({
|
|
521
|
+
ok: z.literal(true),
|
|
522
|
+
_meta: z.object({ runtimeId: identifier }),
|
|
523
|
+
result: z.object({
|
|
524
|
+
codex: accountProviderSchema,
|
|
525
|
+
opencode: accountProviderSchema,
|
|
526
|
+
claude: accountProviderSchema,
|
|
527
|
+
}),
|
|
528
|
+
});
|
package/src/spawn-types.ts
CHANGED
|
@@ -9,14 +9,48 @@
|
|
|
9
9
|
* @phase 1B
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { AgentSpawnCapability } from './agent-registry-v3.js';
|
|
12
13
|
import type { LeadDeniedTool, LeadMcpReport } from './operations/orchestrate.js';
|
|
13
14
|
import type { AgentSuiteOwnership } from './spawn.js';
|
|
15
|
+
import type { TaskPipelineStageSource } from './task.js';
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Provider identifier for spawn operations.
|
|
17
19
|
*/
|
|
18
20
|
export type Provider = string;
|
|
19
21
|
|
|
22
|
+
/** Allocated worker identity carried unchanged from the task claim to launch. */
|
|
23
|
+
export interface SpawnWorkerSession {
|
|
24
|
+
/** The worker's allocated CLEO_SESSION_ID, never the coordinator's. */
|
|
25
|
+
readonly sessionId: string;
|
|
26
|
+
/** The worker's claim identity, exported as CLEO_AGENT_ID. */
|
|
27
|
+
readonly agentId: string;
|
|
28
|
+
/** Actual execution role assigned by dispatch, never a classifier's persona. */
|
|
29
|
+
readonly role?: AgentSpawnCapability;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Protocol selection source; task-stage priority requires explicit provenance. */
|
|
33
|
+
export type SpawnProtocolSource =
|
|
34
|
+
| 'explicit'
|
|
35
|
+
| 'pipelineStage'
|
|
36
|
+
| 'kind'
|
|
37
|
+
| 'label'
|
|
38
|
+
| 'type'
|
|
39
|
+
| 'keyword'
|
|
40
|
+
| 'fallback';
|
|
41
|
+
|
|
42
|
+
/** Selected protocol and disclosed disagreements; no model grants authority. */
|
|
43
|
+
export interface SpawnProtocolResolution {
|
|
44
|
+
/** Protocol rendered into the assignment. */
|
|
45
|
+
readonly protocol: string;
|
|
46
|
+
/** Highest-precedence source that selected the protocol. */
|
|
47
|
+
readonly source: SpawnProtocolSource;
|
|
48
|
+
/** Origin of the stored stage; an inherited/default/unknown stage is not explicit intent. */
|
|
49
|
+
readonly pipelineStageSource?: TaskPipelineStageSource;
|
|
50
|
+
/** Lower-precedence signals that disagree with the selection. */
|
|
51
|
+
readonly conflicts: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
20
54
|
/**
|
|
21
55
|
* CAAMP-compatible spawn options (inlined for zero-dep contracts).
|
|
22
56
|
*/
|
|
@@ -54,6 +88,15 @@ export interface CLEOSpawnContext {
|
|
|
54
88
|
/** Protocol to use for the spawned task */
|
|
55
89
|
protocol: string;
|
|
56
90
|
|
|
91
|
+
/** Authority and conflicting task signals for the selected protocol. */
|
|
92
|
+
protocolResolution?: SpawnProtocolResolution;
|
|
93
|
+
|
|
94
|
+
/** Allocated worker session and claim identity for the execution backend. */
|
|
95
|
+
workerSession?: SpawnWorkerSession;
|
|
96
|
+
|
|
97
|
+
/** Coordinator session for correlation only; never a worker binding. */
|
|
98
|
+
coordinatorSessionId?: string | null;
|
|
99
|
+
|
|
57
100
|
/** Fully-resolved prompt to send to subagent */
|
|
58
101
|
prompt: string;
|
|
59
102
|
|
package/src/spawn.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
LeadMcpReport,
|
|
14
14
|
LeadToolStripSupport,
|
|
15
15
|
} from './operations/orchestrate.js';
|
|
16
|
+
import type { SpawnProtocolResolution, SpawnWorkerSession } from './spawn-types.js';
|
|
16
17
|
|
|
17
18
|
// =============================================================================
|
|
18
19
|
// Agent suite ownership handle (T11998 — suite containment)
|
|
@@ -102,6 +103,12 @@ export interface AdapterSpawnProvider {
|
|
|
102
103
|
export interface SpawnContext {
|
|
103
104
|
taskId: string;
|
|
104
105
|
prompt: string;
|
|
106
|
+
/** Allocated worker identity; execution backends must preserve both values. */
|
|
107
|
+
workerSession?: SpawnWorkerSession;
|
|
108
|
+
/** Coordinator session for correlation only. */
|
|
109
|
+
coordinatorSessionId?: string | null;
|
|
110
|
+
/** Protocol authority and disagreements, independent of persona classification. */
|
|
111
|
+
protocolResolution?: SpawnProtocolResolution;
|
|
105
112
|
workingDirectory?: string;
|
|
106
113
|
options?: Record<string, unknown>;
|
|
107
114
|
/**
|
package/src/task.ts
CHANGED
|
@@ -74,6 +74,9 @@ export type TaskType = 'saga' | 'epic' | 'task' | 'subtask';
|
|
|
74
74
|
*/
|
|
75
75
|
export type TaskKind = 'work' | 'research' | 'experiment' | 'bug' | 'spike' | 'release';
|
|
76
76
|
|
|
77
|
+
/** Provenance of a stored pipeline stage; legacy rows without evidence are unknown. */
|
|
78
|
+
export type TaskPipelineStageSource = 'explicit' | 'inherited' | 'default' | 'unknown';
|
|
79
|
+
|
|
77
80
|
/**
|
|
78
81
|
* Task scope axis — granularity of work. Orthogonal to {@link TaskType} and
|
|
79
82
|
* {@link TaskKind}. Defaults to `'feature'`.
|
|
@@ -757,6 +760,17 @@ export type EvidenceAtom =
|
|
|
757
760
|
* runs are re-checked.
|
|
758
761
|
*/
|
|
759
762
|
workspaceWide?: string;
|
|
763
|
+
/**
|
|
764
|
+
* `descendantSha` is the default branch's head at verify time standing
|
|
765
|
+
* in for a SCOPED change (T14434, owner decision D11241): the merge
|
|
766
|
+
* commit's red or cancelled run was not the PR's, every required check
|
|
767
|
+
* was green on the PR head (`descendantPrHeadSha`), and every hunk the
|
|
768
|
+
* PR added was still there at `descendantSha` and at the head it was
|
|
769
|
+
* read from. Unlike the T12742 stand-in,
|
|
770
|
+
* `descendantRange` may hold commits that touched the PR's files or a
|
|
771
|
+
* CI definition.
|
|
772
|
+
*/
|
|
773
|
+
currentHead?: boolean;
|
|
760
774
|
/** Task the PR was verified to be linked to (T12634). */
|
|
761
775
|
taskId?: string;
|
|
762
776
|
/** Component PR the task is linked through; its CI ran as this integration PR's (T12671). */
|