@cleocode/adapters 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 (37) hide show
  1. package/dist/.source-stamp.json +1 -1
  2. package/dist/index.js +1691 -1354
  3. package/dist/index.js.map +3 -3
  4. package/dist/orca-execution.d.ts +90 -0
  5. package/dist/orca-execution.d.ts.map +1 -0
  6. package/dist/orca-execution.js +843 -0
  7. package/dist/orca-execution.js.map +6 -0
  8. package/dist/providers/claude-code/index.js +1689 -1357
  9. package/dist/providers/claude-code/index.js.map +3 -3
  10. package/dist/providers/claude-code/lead-session.d.ts +8 -5
  11. package/dist/providers/claude-code/lead-session.d.ts.map +1 -1
  12. package/dist/providers/claude-sdk/index.js +1674 -1352
  13. package/dist/providers/claude-sdk/index.js.map +3 -3
  14. package/dist/providers/claude-sdk/spawn.d.ts.map +1 -1
  15. package/dist/providers/codex/index.js +1540 -1233
  16. package/dist/providers/codex/index.js.map +3 -3
  17. package/dist/providers/gemini-cli/index.js +1540 -1233
  18. package/dist/providers/gemini-cli/index.js.map +3 -3
  19. package/dist/providers/kimi/index.js +1540 -1233
  20. package/dist/providers/kimi/index.js.map +3 -3
  21. package/dist/providers/openai-sdk/index.js +1660 -1353
  22. package/dist/providers/openai-sdk/index.js.map +3 -3
  23. package/dist/providers/opencode/index.js +1540 -1233
  24. package/dist/providers/opencode/index.js.map +3 -3
  25. package/dist/providers/pi/index.js +1540 -1233
  26. package/dist/providers/pi/index.js.map +3 -3
  27. package/package.json +10 -6
  28. package/src/__tests__/orca-execution-fixture.ts +422 -0
  29. package/src/__tests__/orca-execution.test.ts +1357 -0
  30. package/src/__tests__/orca-plugin-panel.test.ts +661 -0
  31. package/src/__tests__/orca-plugin.test.ts +660 -0
  32. package/src/orca-execution.ts +1193 -0
  33. package/src/providers/claude-code/__tests__/lead-mcp.test.ts +27 -2
  34. package/src/providers/claude-code/lead-session.ts +21 -8
  35. package/src/providers/claude-sdk/__tests__/spawn.test.ts +19 -0
  36. package/src/providers/claude-sdk/spawn.ts +14 -0
  37. package/src/providers/shared/__tests__/lead-tool-strip.test.ts +1 -1
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@cleocode/adapters",
3
- "version": "2026.11.1-canary.9",
3
+ "version": "2026.11.1",
4
4
  "description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
+ "./orca-execution": {
10
+ "types": "./dist/orca-execution.d.ts",
11
+ "import": "./dist/orca-execution.js"
12
+ },
9
13
  ".": {
10
14
  "types": "./dist/index.d.ts",
11
15
  "import": "./dist/index.js"
@@ -31,9 +35,9 @@
31
35
  "@ai-sdk/anthropic": "^3.0.69",
32
36
  "@ai-sdk/openai": "^2.0.53",
33
37
  "ai": "^6.0.168",
34
- "@cleocode/caamp": "2026.11.1-canary.9",
35
- "@cleocode/contracts": "2026.11.1-canary.9",
36
- "@cleocode/paths": "2026.11.1-canary.9"
38
+ "@cleocode/caamp": "2026.11.1",
39
+ "@cleocode/contracts": "2026.11.1",
40
+ "@cleocode/paths": "2026.11.1"
37
41
  },
38
42
  "license": "MIT",
39
43
  "engines": {
@@ -46,8 +50,8 @@
46
50
  "devDependencies": {
47
51
  "@types/node": "^24.3.0",
48
52
  "vitest": "^4.1.4",
49
- "@cleocode/core": "2026.11.1-canary.9",
50
- "@cleocode/playbooks": "2026.11.1-canary.9"
53
+ "@cleocode/core": "2026.11.1",
54
+ "@cleocode/playbooks": "2026.11.1"
51
55
  },
52
56
  "repository": {
53
57
  "type": "git",
@@ -0,0 +1,422 @@
1
+ /** Recorded-shape fixtures; no command in this module reaches an Orca runtime. */
2
+ import type {
3
+ OrcaAttempt,
4
+ OrcaCommandResult,
5
+ OrcaCommandRunner,
6
+ OrcaContext,
7
+ OrcaLaunch,
8
+ OrcaWorkerDone,
9
+ } from '@cleocode/contracts/orca-execution.js';
10
+ import { orcaReplySchema, orcaReportSourceSchema } from '@cleocode/contracts/orca-execution.js';
11
+ import type { MbxRunner } from '@cleocode/core/orchestrate/agentmbx';
12
+ import { vi } from 'vitest';
13
+
14
+ /** Fake durable provider mailbox; retained while a fresh client simulates CLI restart. */
15
+ export const fixtureMail = { bodies: new Map<string, string>(), failBefore: false, loseAck: false };
16
+
17
+ /** AgentMBX's existing idempotent send contract, with no network or real mailbox access. */
18
+ export const runMbxFixture: MbxRunner = async (args) => {
19
+ if (args[0] !== 'send') throw new Error(`Unexpected mailbox fixture command: ${args[0]}`);
20
+ const key = args[args.indexOf('--idempotency-key') + 1];
21
+ const body = args[args.indexOf('-m') + 1];
22
+ if (!args.includes('--idempotency-key') || !key || !body)
23
+ throw new Error('Missing logical mailbox key or canonical report');
24
+ if (fixtureMail.failBefore)
25
+ return { missing: false, exitCode: 1, stdout: '', stderr: 'mailbox unavailable' };
26
+ if (fixtureMail.bodies.has(key) && fixtureMail.bodies.get(key) !== body)
27
+ throw new Error('A logical mailbox key changed its report');
28
+ fixtureMail.bodies.set(key, body);
29
+ if (fixtureMail.loseAck)
30
+ return {
31
+ missing: false,
32
+ exitCode: null,
33
+ stdout: '',
34
+ stderr: 'acknowledgement lost after durable send',
35
+ };
36
+ return {
37
+ missing: false,
38
+ exitCode: 0,
39
+ stdout: JSON.stringify({ id: `mbx-${[...fixtureMail.bodies.keys()].indexOf(key) + 1}` }),
40
+ stderr: '',
41
+ };
42
+ };
43
+
44
+ /** Injected mailbox process boundary; never invokes the installed AgentMBX CLI. */
45
+ export const fixtureMbxRunner = vi.fn<MbxRunner>(runMbxFixture);
46
+
47
+ /** Explicit fictitious caller, independent of the developer's running Orca. */
48
+ export const fixtureContext: OrcaContext = {
49
+ runtimeId: 'runtime-fixture',
50
+ coordinatorHandle: 'term_fixture',
51
+ executionHostId: 'local',
52
+ };
53
+
54
+ /** Prepared assignment containing inert shell metacharacters. */
55
+ export const fixtureLaunch: OrcaLaunch = {
56
+ projectId: 'project-fixture',
57
+ projectRoot: '/fixture/project',
58
+ taskId: 'T001',
59
+ instanceId: 'worker-fixture',
60
+ workerSessionId: 'ses_fixture',
61
+ agentId: 'agent-t001',
62
+ role: 'worker',
63
+ protocol: 'implementation',
64
+ worktreePath: '/fixture/canonical/T001',
65
+ worktreeBranch: 'task/T001',
66
+ projectHash: 'fixture-hash',
67
+ lockToken: 'fixture-token',
68
+ prompt: 'Do the task. Preserve `literal backticks` and $(literal); CLEO_SESSION_ID=ses_fixture',
69
+ harness: 'codex',
70
+ leadMailbox: 'fixture-lead',
71
+ };
72
+
73
+ /** Wrap a wire result without using its process exit as lifecycle evidence. */
74
+ export function fixtureReply(result: object, exitCode = 0): OrcaCommandResult {
75
+ return {
76
+ stdout: JSON.stringify({ ok: true, result, _meta: { runtimeId: fixtureContext.runtimeId } }),
77
+ stderr: '',
78
+ exitCode,
79
+ };
80
+ }
81
+
82
+ /** Full worker-start response fields from the installed CLI contract. */
83
+ export function fixtureStart(
84
+ state = 'ready',
85
+ failureCount = 0,
86
+ dispatchId = 'ctx_fixture',
87
+ ): OrcaCommandResult {
88
+ return fixtureReply(
89
+ {
90
+ state,
91
+ failureCount,
92
+ stage: state === 'outcome_unknown' ? 'turn_start_unobserved' : 'input_accepted',
93
+ dispatchId,
94
+ runId: 'run_fixture',
95
+ taskId: 'task_fixture',
96
+ effects: [{ kind: 'worktree', action: 'reused', id: 'workspace-fixture' }],
97
+ residualResources: [],
98
+ launch: { effective: { agent: 'codex', model: null, effort: null } },
99
+ },
100
+ state === 'ready' ? 0 : 1,
101
+ );
102
+ }
103
+
104
+ /**
105
+ * Orca 1.4.255 pending workerStart refusal after accept/receipt restart.
106
+ * Source: installed out/main/chunks/orcad-retained-source-*.js mutation ledger
107
+ * and out/cli/runtime/client-error-recovery.js attachMutationRecovery.
108
+ */
109
+ export function fixturePendingStart(
110
+ dispatchId = 'ctx_retry',
111
+ requestId = 'request-fixture',
112
+ ): OrcaCommandResult {
113
+ return {
114
+ stdout: JSON.stringify({
115
+ ok: false,
116
+ error: {
117
+ code: 'operation_unknown',
118
+ message:
119
+ `Worker start ${requestId} was accepted as Dispatch ${dispatchId} before restart. ` +
120
+ `Inspect that Dispatch; do not start another worker. Orchestration mutation request ID: ${requestId}.`,
121
+ data: {
122
+ requestId,
123
+ dispatchId,
124
+ recoveryCommand: `orca orchestration worker-show --dispatch ${dispatchId} --json`,
125
+ orchestrationRequestId: requestId,
126
+ },
127
+ },
128
+ _meta: { runtimeId: fixtureContext.runtimeId },
129
+ }),
130
+ stderr: '',
131
+ exitCode: 1,
132
+ };
133
+ }
134
+
135
+ /** Full exact-dispatch observation; a status hint alone is never a worker report. */
136
+ export function fixtureShow(
137
+ dispatchId = 'ctx_fixture',
138
+ failureCount = 0,
139
+ creatorDispatchId?: string,
140
+ ): OrcaCommandResult {
141
+ return fixtureReply({
142
+ dispatch: {
143
+ id: dispatchId,
144
+ runId: 'run_fixture',
145
+ taskId: 'task_fixture',
146
+ failureCount,
147
+ ...(creatorDispatchId === undefined ? {} : { creatorDispatchId }),
148
+ },
149
+ worker: {
150
+ dispatchId,
151
+ runtimeEpoch: fixtureContext.runtimeId,
152
+ state: 'ready',
153
+ stage: 'input_accepted',
154
+ worktreeId: 'workspace-fixture',
155
+ },
156
+ observation: { status: 'live', exactWorker: true },
157
+ projection: { resource: { state: 'owned', terminalState: 'active' } },
158
+ });
159
+ }
160
+
161
+ /** Recorded resource-release proof, independent of worker launch and Task status. */
162
+ export function fixtureReleasedShow(
163
+ dispatchId = 'ctx_fixture',
164
+ failureCount = 0,
165
+ ): OrcaCommandResult {
166
+ const original = orcaReplySchema.parse(JSON.parse(fixtureShow(dispatchId, failureCount).stdout));
167
+ return fixtureReply({
168
+ ...original.result,
169
+ worker: { ...original.result?.worker, state: 'failed', stage: 'settled' },
170
+ observation: { status: 'exited', exactWorker: true },
171
+ projection: {
172
+ resource: {
173
+ state: 'released',
174
+ terminalState: 'released',
175
+ releaseState: 'released',
176
+ ownerDispatchId: dispatchId,
177
+ },
178
+ },
179
+ });
180
+ }
181
+
182
+ /**
183
+ * A helper Dispatch whose process has exited but whose terminal is still retained.
184
+ * @param dispatchId - Helper Dispatch to render as exited.
185
+ * @param creatorDispatchId - Direct creator the helper must descend from.
186
+ */
187
+ export function fixtureHelperExited(
188
+ dispatchId: string,
189
+ creatorDispatchId = 'ctx_fixture',
190
+ ): OrcaCommandResult {
191
+ const original = orcaReplySchema.parse(
192
+ JSON.parse(fixtureShow(dispatchId, 0, creatorDispatchId).stdout),
193
+ );
194
+ return fixtureReply({
195
+ ...original.result,
196
+ worker: { ...original.result?.worker, state: 'succeeded', stage: 'settled' },
197
+ observation: { status: 'exited', exactWorker: true },
198
+ projection: { resource: { state: 'retained', terminalState: 'retained' } },
199
+ });
200
+ }
201
+
202
+ /** Full inbox worker_done shape, with the canonical report carried only by a file pointer. */
203
+ export function fixtureReportInbox(
204
+ overrides: Partial<OrcaWorkerDone> = {},
205
+ newerMessages = 0,
206
+ ): OrcaCommandResult {
207
+ const event: OrcaWorkerDone = {
208
+ messageId: 'msg_report',
209
+ runtimeId: fixtureContext.runtimeId,
210
+ runId: 'run_fixture',
211
+ orcaTaskId: 'task_fixture',
212
+ dispatchId: 'ctx_fixture',
213
+ senderHandle: 'term_worker',
214
+ outcome: 'succeeded',
215
+ body: 'Implemented the change. Checks passed. Review remains.',
216
+ reportPath: 'worker-report.txt',
217
+ ...overrides,
218
+ };
219
+ return {
220
+ exitCode: 0,
221
+ stderr: '',
222
+ stdout: JSON.stringify({
223
+ ok: true,
224
+ _meta: { runtimeId: event.runtimeId },
225
+ result: {
226
+ messages: Array.from({ length: newerMessages + 1 }, (_, index) => ({
227
+ id: index === newerMessages ? event.messageId : `msg_newer_${index}`,
228
+ run_id: event.runId,
229
+ delivery_contract: 'current_delivery',
230
+ from_handle: event.senderHandle,
231
+ to_handle: `run:${event.runId}`,
232
+ type: 'worker_done',
233
+ body: event.body,
234
+ payload: JSON.stringify({
235
+ taskId: event.orcaTaskId,
236
+ dispatchId: event.dispatchId,
237
+ outcome: event.outcome,
238
+ reportPath: event.reportPath,
239
+ }),
240
+ sender_pane_key: 'pane_worker',
241
+ })),
242
+ },
243
+ }),
244
+ };
245
+ }
246
+
247
+ /** dispatch-show's raw current-task mapping; distinct from worker-show's camel-case view. */
248
+ export function fixtureReportDispatch(
249
+ dispatchId = 'ctx_fixture',
250
+ status = 'completed',
251
+ ): OrcaCommandResult {
252
+ return fixtureReply({
253
+ dispatch: {
254
+ id: dispatchId,
255
+ run_id: 'run_fixture',
256
+ task_id: 'task_fixture',
257
+ assignee_handle: 'term_worker',
258
+ assignee_pane_key: 'pane_worker',
259
+ status,
260
+ },
261
+ });
262
+ }
263
+
264
+ /** Durable attempt suitable for testing supervision independently of the store. */
265
+ export function fixtureAttempt(overrides: Partial<OrcaAttempt> = {}): OrcaAttempt {
266
+ return {
267
+ backend: 'orca',
268
+ version: 1,
269
+ revision: 0,
270
+ context: fixtureContext,
271
+ launch: fixtureLaunch,
272
+ promptDigest: 'a'.repeat(64),
273
+ workspaceId: 'workspace-fixture',
274
+ workspaceSelector: 'identity:workspace-fixture',
275
+ state: 'launching',
276
+ runId: null,
277
+ orcaTaskId: null,
278
+ dispatchId: null,
279
+ retryOf: null,
280
+ startBinding: { runId: null, orcaTaskId: null, retryOf: null },
281
+ startRequestId: null,
282
+ stopRequestId: null,
283
+ failureCount: 0,
284
+ resourceState: 'unknown',
285
+ lastReceipt: null,
286
+ lastError: null,
287
+ observedAt: '2026-11-11T00:00:00Z',
288
+ ...overrides,
289
+ };
290
+ }
291
+
292
+ /** Mutable response selections reset by each test; requests remain argv-only. */
293
+ export const orcaFixture = {
294
+ launch: { ...fixtureLaunch },
295
+ start: fixtureStart(),
296
+ show: fixtureShow(),
297
+ /** Per-helper Dispatch observations; a missing key falls back to `show`. */
298
+ helperShows: {} as Record<string, OrcaCommandResult>,
299
+ capabilities: ['orchestration.contract.v1', 'orchestration.worker-stop-helpers.v1'],
300
+ stop: fixtureReply(
301
+ {
302
+ dispatchId: 'ctx_fixture',
303
+ state: 'stop_unknown',
304
+ processAction: 'closed_agent_terminal',
305
+ helpers: [],
306
+ },
307
+ 1,
308
+ ),
309
+ request: fixtureReply({ state: 'completed', requestId: 'request-fixture' }),
310
+ read: fixtureReply({ text: 'original output', nextCursor: 'source-pinned-cursor' }),
311
+ accounts: fixtureReply({
312
+ codex: { accounts: [], activeAccountId: 'system' },
313
+ opencode: { accounts: [], activeAccountId: 'system' },
314
+ claude: { accounts: [], activeAccountId: 'system' },
315
+ }),
316
+ caller: fixtureReply({
317
+ terminal: {
318
+ handle: fixtureContext.coordinatorHandle,
319
+ executionHostId: 'local',
320
+ connected: true,
321
+ writable: true,
322
+ },
323
+ }),
324
+ currentRun: fixtureReply({ run: { id: 'run_fixture' } }),
325
+ inbox: fixtureReportInbox(),
326
+ currentDispatch: fixtureReportDispatch(),
327
+ };
328
+
329
+ /** Pure CLI fixture dispatcher; unexpected verbs fail instead of launching anything. */
330
+ export const runOrcaFixture: OrcaCommandRunner = async (_executable, args) => {
331
+ if (args[0] === 'account') return orcaFixture.accounts;
332
+ if (args[0] === 'terminal') return orcaFixture.caller;
333
+ if (args[1] === 'run-current') return orcaFixture.currentRun;
334
+ if (args[0] === 'agent-context') {
335
+ return {
336
+ exitCode: 0,
337
+ stderr: '',
338
+ stdout: JSON.stringify({
339
+ schemaVersion: 1,
340
+ commands: [
341
+ {
342
+ command: 'orchestration worker-start',
343
+ flags: [
344
+ 'from',
345
+ 'spec-file',
346
+ 'task',
347
+ 'run',
348
+ 'worktree',
349
+ 'agent',
350
+ 'retry-of',
351
+ 'retry-request',
352
+ 'full',
353
+ 'model',
354
+ 'effort',
355
+ ],
356
+ },
357
+ { command: 'orchestration worker-show', flags: ['dispatch', 'full'] },
358
+ {
359
+ command: 'orchestration worker-read',
360
+ flags: ['dispatch', 'source', 'limit', 'cursor', 'full'],
361
+ },
362
+ { command: 'orchestration worker-stop', flags: ['dispatch', 'retry-request', 'full'] },
363
+ { command: 'orchestration request-show', flags: ['request', 'full'] },
364
+ { command: 'orchestration run-current', flags: ['from', 'full'] },
365
+ { command: 'worktree show', flags: ['worktree'] },
366
+ ],
367
+ }),
368
+ };
369
+ }
370
+ if (args[0] === 'status')
371
+ return fixtureReply({
372
+ runtime: {
373
+ runtimeId: fixtureContext.runtimeId,
374
+ reachable: true,
375
+ state: 'ready',
376
+ capabilities: orcaFixture.capabilities,
377
+ },
378
+ });
379
+ if (args[0] === 'worktree')
380
+ return fixtureReply({
381
+ worktree: {
382
+ id: 'workspace-fixture',
383
+ path: orcaFixture.launch.worktreePath,
384
+ branch: `refs/heads/${orcaFixture.launch.worktreeBranch}`,
385
+ hostId: 'local',
386
+ address: { worktree: 'identity:workspace-fixture' },
387
+ },
388
+ });
389
+ switch (args[1]) {
390
+ case 'worker-start':
391
+ return orcaFixture.start;
392
+ case 'worker-show': {
393
+ const dispatchIndex = args.indexOf('--dispatch');
394
+ const dispatchId = dispatchIndex === -1 ? undefined : args[dispatchIndex + 1];
395
+ return dispatchId
396
+ ? (orcaFixture.helperShows[dispatchId] ?? orcaFixture.show)
397
+ : orcaFixture.show;
398
+ }
399
+ case 'worker-stop':
400
+ return orcaFixture.stop;
401
+ case 'request-show':
402
+ return orcaFixture.request;
403
+ case 'worker-read':
404
+ return orcaFixture.read;
405
+ case 'inbox':
406
+ try {
407
+ const source = orcaReportSourceSchema.parse(JSON.parse(orcaFixture.inbox.stdout));
408
+ const limit = Number(args[args.indexOf('--limit') + 1]);
409
+ if (source.result.messages) source.result.messages = source.result.messages.slice(0, limit);
410
+ return { ...orcaFixture.inbox, stdout: JSON.stringify(source) };
411
+ } catch {
412
+ return orcaFixture.inbox;
413
+ }
414
+ case 'dispatch-show':
415
+ return orcaFixture.currentDispatch;
416
+ default:
417
+ throw new Error(`Unexpected fixture command: ${args.join(' ')}`);
418
+ }
419
+ };
420
+
421
+ /** Injected process spy, never the installed Orca executable. */
422
+ export const fixtureRunner = vi.fn<OrcaCommandRunner>(runOrcaFixture);