@cleocode/adapters 2026.10.27 → 2026.11.1-canary.11

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 (94) hide show
  1. package/README.md +2 -0
  2. package/dist/.source-stamp.json +4 -0
  3. package/dist/index.js +2694 -1895
  4. package/dist/index.js.map +3 -3
  5. package/dist/manifests.d.ts +25 -0
  6. package/dist/manifests.d.ts.map +1 -0
  7. package/dist/manifests.js +28 -0
  8. package/dist/manifests.js.map +6 -0
  9. package/dist/orca-execution.d.ts +90 -0
  10. package/dist/orca-execution.d.ts.map +1 -0
  11. package/dist/orca-execution.js +843 -0
  12. package/dist/orca-execution.js.map +6 -0
  13. package/dist/providers/claude-code/index.js +46728 -0
  14. package/dist/providers/claude-code/index.js.map +6 -0
  15. package/dist/providers/claude-code/lead-mcp.d.ts +99 -0
  16. package/dist/providers/claude-code/lead-mcp.d.ts.map +1 -0
  17. package/dist/providers/claude-code/lead-session.d.ts +133 -0
  18. package/dist/providers/claude-code/lead-session.d.ts.map +1 -0
  19. package/dist/providers/claude-code/spawn.d.ts +39 -0
  20. package/dist/providers/claude-code/spawn.d.ts.map +1 -1
  21. package/dist/providers/claude-sdk/index.js +44567 -0
  22. package/dist/providers/claude-sdk/index.js.map +6 -0
  23. package/dist/providers/claude-sdk/spawn.d.ts +6 -0
  24. package/dist/providers/claude-sdk/spawn.d.ts.map +1 -1
  25. package/dist/providers/codex/index.js +19333 -0
  26. package/dist/providers/codex/index.js.map +6 -0
  27. package/dist/providers/codex/spawn.d.ts +2 -0
  28. package/dist/providers/codex/spawn.d.ts.map +1 -1
  29. package/dist/providers/cursor/index.js +637 -0
  30. package/dist/providers/cursor/index.js.map +6 -0
  31. package/dist/providers/cursor/spawn.d.ts +2 -0
  32. package/dist/providers/cursor/spawn.d.ts.map +1 -1
  33. package/dist/providers/gemini-cli/index.js +18895 -0
  34. package/dist/providers/gemini-cli/index.js.map +6 -0
  35. package/dist/providers/gemini-cli/spawn.d.ts +2 -0
  36. package/dist/providers/gemini-cli/spawn.d.ts.map +1 -1
  37. package/dist/providers/kimi/index.js +18824 -0
  38. package/dist/providers/kimi/index.js.map +6 -0
  39. package/dist/providers/kimi/spawn.d.ts +2 -0
  40. package/dist/providers/kimi/spawn.d.ts.map +1 -1
  41. package/dist/providers/openai-sdk/adapter.d.ts +1 -1
  42. package/dist/providers/openai-sdk/index.d.ts +0 -1
  43. package/dist/providers/openai-sdk/index.d.ts.map +1 -1
  44. package/dist/providers/openai-sdk/index.js +44208 -0
  45. package/dist/providers/openai-sdk/index.js.map +6 -0
  46. package/dist/providers/openai-sdk/spawn.d.ts +4 -2
  47. package/dist/providers/openai-sdk/spawn.d.ts.map +1 -1
  48. package/dist/providers/openai-sdk/tracing.d.ts +8 -82
  49. package/dist/providers/openai-sdk/tracing.d.ts.map +1 -1
  50. package/dist/providers/opencode/index.js +19335 -0
  51. package/dist/providers/opencode/index.js.map +6 -0
  52. package/dist/providers/opencode/spawn.d.ts +2 -0
  53. package/dist/providers/opencode/spawn.d.ts.map +1 -1
  54. package/dist/providers/pi/index.js +18471 -0
  55. package/dist/providers/pi/index.js.map +6 -0
  56. package/dist/providers/pi/spawn.d.ts +2 -0
  57. package/dist/providers/pi/spawn.d.ts.map +1 -1
  58. package/dist/providers/shared/lead-tool-strip.d.ts +52 -0
  59. package/dist/providers/shared/lead-tool-strip.d.ts.map +1 -0
  60. package/dist/registry.d.ts +2 -55
  61. package/dist/registry.d.ts.map +1 -1
  62. package/package.json +14 -6
  63. package/src/__tests__/harness-interop.test.ts +0 -7
  64. package/src/__tests__/orca-execution-fixture.ts +422 -0
  65. package/src/__tests__/orca-execution.test.ts +1357 -0
  66. package/src/__tests__/orca-plugin-panel.test.ts +661 -0
  67. package/src/__tests__/orca-plugin.test.ts +660 -0
  68. package/src/manifests.ts +55 -0
  69. package/src/orca-execution.ts +1193 -0
  70. package/src/providers/claude-code/__tests__/lead-mcp.test.ts +348 -0
  71. package/src/providers/claude-code/__tests__/worker-exit-settings.test.ts +32 -0
  72. package/src/providers/claude-code/lead-mcp.ts +244 -0
  73. package/src/providers/claude-code/lead-session.ts +241 -0
  74. package/src/providers/claude-code/spawn.ts +180 -11
  75. package/src/providers/claude-sdk/__tests__/spawn.test.ts +63 -3
  76. package/src/providers/claude-sdk/spawn.ts +28 -1
  77. package/src/providers/codex/spawn.ts +5 -0
  78. package/src/providers/cursor/spawn.ts +3 -0
  79. package/src/providers/gemini-cli/spawn.ts +5 -0
  80. package/src/providers/kimi/spawn.ts +5 -0
  81. package/src/providers/openai-sdk/__tests__/openai-sdk-spawn.test.ts +0 -80
  82. package/src/providers/openai-sdk/adapter.ts +1 -1
  83. package/src/providers/openai-sdk/index.ts +0 -1
  84. package/src/providers/openai-sdk/manifest.json +1 -1
  85. package/src/providers/openai-sdk/spawn.ts +10 -16
  86. package/src/providers/openai-sdk/tracing.ts +8 -169
  87. package/src/providers/opencode/spawn.ts +5 -0
  88. package/src/providers/pi/spawn.ts +5 -0
  89. package/src/providers/shared/__tests__/lead-tool-strip.test.ts +126 -0
  90. package/src/providers/shared/lead-tool-strip.ts +76 -0
  91. package/src/registry.ts +2 -78
  92. package/dist/providers/shared/conduit-trace-writer.d.ts +0 -72
  93. package/dist/providers/shared/conduit-trace-writer.d.ts.map +0 -1
  94. package/src/providers/shared/conduit-trace-writer.ts +0 -101
@@ -0,0 +1,660 @@
1
+ /**
2
+ * T14462 — the CLEO Orca plugin's worker side, run in CI.
3
+ *
4
+ * Orca loads the plugin folder (`packages/adapters/orca-plugin`) as written,
5
+ * and its own test kit ships only inside the Orca app, which CI does not have.
6
+ * So everything that decides what a local `cleo` subprocess may run, and how
7
+ * its envelope is read, has no Orca import and is proven here: the runner
8
+ * against real subprocesses (`process.execPath` stands in for `cleo`), then
9
+ * the argv builders, the workspace policy, the view mapping and the worker's
10
+ * request handlers. The panel's state is covered in `orca-plugin-panel.test.ts`.
11
+ */
12
+
13
+ import { mkdtempSync, readFileSync, realpathSync, rmSync } from 'node:fs';
14
+ import { tmpdir } from 'node:os';
15
+ import { join } from 'node:path';
16
+ import { fileURLToPath } from 'node:url';
17
+ import { afterAll, describe, expect, it } from 'vitest';
18
+ import {
19
+ type CleoRunOptions,
20
+ type CleoRunResult,
21
+ listArgv,
22
+ parseEnvelope,
23
+ readEnvironment,
24
+ runCleo,
25
+ showArgv,
26
+ TASK_PAGE_SIZE,
27
+ } from '../../orca-plugin/src/cleo-cli.ts';
28
+ import { createHandlers } from '../../orca-plugin/src/handlers.ts';
29
+ import { toTaskDetail, toTaskPage } from '../../orca-plugin/src/views.ts';
30
+ import {
31
+ buildWorkspaceOptions,
32
+ type HostWorkspace,
33
+ isLocalHost,
34
+ resolveSelection,
35
+ } from '../../orca-plugin/src/workspaces.ts';
36
+
37
+ const cwd = mkdtempSync(join(tmpdir(), 'cleo-orca-plugin-'));
38
+ afterAll(() => rmSync(cwd, { recursive: true, force: true }));
39
+
40
+ /** Runs a Node one-liner in place of `cleo`, under the runner's real bounds. */
41
+ function runScript(script: string, options: Partial<Parameters<typeof runCleo>[1]> = {}) {
42
+ return runCleo(['-e', script], { cwd, bin: process.execPath, ...options });
43
+ }
44
+
45
+ const print = (value: unknown, exitCode = 0) =>
46
+ `process.stdout.write(${JSON.stringify(JSON.stringify(value))} + "\\n"); process.exitCode = ${exitCode};`;
47
+
48
+ describe('runCleo', () => {
49
+ it('returns the data of a successful envelope', async () => {
50
+ const result = await runScript(print({ success: true, data: { tasks: [] } }));
51
+ expect(result).toEqual({ ok: true, data: { tasks: [] } });
52
+ });
53
+
54
+ it('trusts the envelope over the exit code (an empty list exits 100)', async () => {
55
+ const result = await runScript(print({ success: true, data: { tasks: [] } }, 100));
56
+ expect(result).toEqual({ ok: true, data: { tasks: [] } });
57
+ });
58
+
59
+ it('reports a missing CLEO executable', async () => {
60
+ const result = await runCleo(['list'], { cwd, bin: join(cwd, 'no-such-cleo') });
61
+ expect(result).toMatchObject({ ok: false, code: 'cleo-missing' });
62
+ });
63
+
64
+ it('reports a workspace folder that is not on this machine, without starting anything', async () => {
65
+ const result = await runScript(print({ success: true, data: {} }), {
66
+ cwd: join(cwd, 'not-here'),
67
+ });
68
+ expect(result).toMatchObject({ ok: false, code: 'workspace-unavailable' });
69
+ });
70
+
71
+ it('stops a read that outlives its deadline', async () => {
72
+ const result = await runScript('setTimeout(() => {}, 60_000);', { timeoutMs: 300 });
73
+ expect(result).toMatchObject({ ok: false, code: 'timeout' });
74
+ });
75
+
76
+ it('stops a read that prints more than the output cap', async () => {
77
+ const result = await runScript('process.stdout.write("x".repeat(200_000));', {
78
+ maxOutputBytes: 1024,
79
+ });
80
+ expect(result).toMatchObject({ ok: false, code: 'output-too-large' });
81
+ });
82
+
83
+ it('stops a read when the caller cancels', async () => {
84
+ const controller = new AbortController();
85
+ const pending = runScript('setTimeout(() => {}, 60_000);', { signal: controller.signal });
86
+ setTimeout(() => controller.abort(), 100);
87
+ expect(await pending).toMatchObject({ ok: false, code: 'cancelled' });
88
+ });
89
+
90
+ it('reports output that is not one JSON envelope', async () => {
91
+ const result = await runScript('process.stdout.write("Loading...\\n{\\"success\\":true}");');
92
+ expect(result).toMatchObject({ ok: false, code: 'malformed-envelope' });
93
+ });
94
+
95
+ it('reads a folder that is not a CLEO project from the error envelope', async () => {
96
+ const result = await runScript(
97
+ print(
98
+ {
99
+ success: false,
100
+ error: { code: 4, codeName: 'E_CLEO_NOT_FOUND', message: 'Not inside a CLEO project.' },
101
+ },
102
+ 4,
103
+ ),
104
+ );
105
+ expect(result).toEqual({
106
+ ok: false,
107
+ code: 'not-a-project',
108
+ message: 'Not inside a CLEO project.',
109
+ });
110
+ });
111
+
112
+ it('runs in the chosen folder with no inherited CLEO project, directory or identity', async () => {
113
+ // CLEO_ROOT, CLEO_PROJECT_ROOT and CLEO_DIR override the working directory as the project
114
+ // a cleo command reads (packages/core/src/project-scope.ts), so one inherited from whatever
115
+ // started Orca would show another project under the chosen workspace's name.
116
+ const leaked = [
117
+ 'CLEO_ROOT',
118
+ 'CLEO_PROJECT_ROOT',
119
+ 'CLEO_DIR',
120
+ 'CLEO_WORKTREE_ROOT',
121
+ 'CLEO_PROJECT_HASH',
122
+ 'CLEO_SESSION_ID',
123
+ 'CLEO_AGENT_ID',
124
+ 'CLEO_AGENT_ROLE',
125
+ 'CLEO_HOME',
126
+ ] as const;
127
+ const before = leaked.map((name) => process.env[name]);
128
+ for (const name of leaked) process.env[name] = '/somewhere/else';
129
+ try {
130
+ const result = await runScript(
131
+ 'const names = Object.keys(process.env).filter((name) => name.startsWith("CLEO_")).sort();' +
132
+ 'process.stdout.write(JSON.stringify({ success: true, data: { names, cwd: process.cwd() } }));',
133
+ );
134
+ expect(result).toEqual({
135
+ ok: true,
136
+ data: { names: ['CLEO_HOME'], cwd: realpathSync(cwd) },
137
+ });
138
+ } finally {
139
+ leaked.forEach((name, index) => {
140
+ if (before[index] === undefined) delete process.env[name];
141
+ else process.env[name] = before[index];
142
+ });
143
+ }
144
+ });
145
+ });
146
+
147
+ describe('readEnvironment', () => {
148
+ it('keeps the machine environment and CLEO_HOME, and drops every other CLEO_ setting', () => {
149
+ const env = readEnvironment({
150
+ PATH: '/usr/bin',
151
+ HOME: '/home/me',
152
+ CLEO_HOME: '/data/cleo',
153
+ CLEO_ROOT: '/other/project',
154
+ CLEO_DIR: '/other/project/.cleo',
155
+ CLEO_SESSION_ID: 'ses_1',
156
+ CLEO_SOMETHING_ADDED_LATER: '1',
157
+ });
158
+ expect(env).toEqual({
159
+ PATH: '/usr/bin',
160
+ HOME: '/home/me',
161
+ CLEO_HOME: '/data/cleo',
162
+ NO_COLOR: '1',
163
+ });
164
+ });
165
+ });
166
+
167
+ describe('parseEnvelope', () => {
168
+ it.each([
169
+ ['', 'no output'],
170
+ ['[]', 'an array'],
171
+ ['{"data":{}}', 'no success flag'],
172
+ ['{"success":true}', 'success without data'],
173
+ ['{"success":true,"data":[]}', 'data that is not an object'],
174
+ ['{"success":false}', 'failure without an error'],
175
+ ])('rejects %j (%s) as malformed', (stdout) => {
176
+ expect(parseEnvelope(stdout)).toMatchObject({ ok: false, code: 'malformed-envelope' });
177
+ });
178
+
179
+ it('keeps CLEO’s own error code and message', () => {
180
+ const stdout = '{"success":false,"error":{"codeName":"E_NOT_FOUND","message":"No such task"}}';
181
+ expect(parseEnvelope(stdout)).toEqual({
182
+ ok: false,
183
+ code: 'cli-error',
184
+ message: 'E_NOT_FOUND: No such task',
185
+ });
186
+ });
187
+ });
188
+
189
+ describe('argv builders', () => {
190
+ it('builds only bounded read commands', () => {
191
+ const page = ['--limit', String(TASK_PAGE_SIZE), '--offset'];
192
+ expect(listArgv({})).toEqual(['list', '--type', 'epic', '--status', 'active', ...page, '0']);
193
+ expect(listArgv({ status: 'all', offset: 50 })).toEqual([
194
+ 'list',
195
+ '--type',
196
+ 'epic',
197
+ ...page,
198
+ '50',
199
+ ]);
200
+ expect(listArgv({ parentId: 'T14451' })).toEqual(['list', '--parent', 'T14451', ...page, '0']);
201
+ expect(showArgv('T932EP')).toEqual(['show', 'T932EP', '--full']);
202
+ });
203
+
204
+ it.each([
205
+ [{ parentId: '--all' }],
206
+ [{ parentId: 'T1; rm -rf /' }],
207
+ [{ parentId: 14451 }],
208
+ [{ status: 'active,pending' }],
209
+ [{ offset: -1 }],
210
+ [{ offset: 1.5 }],
211
+ [{ offset: '0' }],
212
+ ])('refuses the list request %j', (request) => {
213
+ expect(listArgv(request)).toBeNull();
214
+ });
215
+
216
+ it.each([
217
+ '--force',
218
+ 'complete',
219
+ 'T',
220
+ 't100',
221
+ 'T100 --full',
222
+ '',
223
+ null,
224
+ 100,
225
+ ])('refuses %j as a task id', (taskId) => {
226
+ expect(showArgv(taskId)).toBeNull();
227
+ });
228
+ });
229
+
230
+ describe('workspace selection', () => {
231
+ const local: HostWorkspace = {
232
+ id: 'ws-app',
233
+ kind: 'worktree',
234
+ name: 'app',
235
+ path: '/work/app',
236
+ branch: 'main',
237
+ hostId: 'local',
238
+ };
239
+ const twin: HostWorkspace = { ...local, id: 'ws-twin', path: '/work/app-2' };
240
+ const remote: HostWorkspace = { ...local, id: 'ws-ssh', name: 'server', hostId: 'ssh:build' };
241
+ const folder: HostWorkspace = {
242
+ ...local,
243
+ id: 'ws-dir',
244
+ kind: 'folder',
245
+ branch: null,
246
+ hostId: null,
247
+ };
248
+
249
+ it('treats only Orca’s own machine as local', () => {
250
+ expect([
251
+ isLocalHost('local'),
252
+ isLocalHost(null),
253
+ isLocalHost('ssh:build'),
254
+ isLocalHost(''),
255
+ ]).toEqual([true, true, false, false]);
256
+ });
257
+
258
+ it('tells workspaces that share a name apart by path and blocks remote ones', () => {
259
+ const { workspaces } = buildWorkspaceOptions([local, twin, remote], null);
260
+ expect(workspaces.map(({ label, blocked }) => [label, blocked])).toEqual([
261
+ ['app — /work/app', null],
262
+ ['app — /work/app-2', null],
263
+ ['server (remote: ssh:build)', 'remote'],
264
+ ]);
265
+ });
266
+
267
+ it('marks the focused workspace only when exactly one matches', () => {
268
+ const focus = { displayName: 'app', branch: 'main' };
269
+ const ambiguous = buildWorkspaceOptions([local, twin], focus);
270
+ expect(ambiguous.focus).toEqual({ name: 'app', matches: 2 });
271
+ expect(ambiguous.workspaces.map((workspace) => workspace.focused)).toEqual([false, false]);
272
+ const unique = buildWorkspaceOptions([local, remote], focus);
273
+ expect(unique.workspaces.map((workspace) => workspace.focused)).toEqual([true, false]);
274
+ });
275
+
276
+ it('collapses an id that names two workspaces into one blocked row', () => {
277
+ const { workspaces } = buildWorkspaceOptions([local, { ...twin, id: 'ws-app' }], null);
278
+ expect(workspaces.map((workspace) => workspace.blocked)).toEqual(['duplicate-id']);
279
+ });
280
+
281
+ it('resolves a selection only while id, host and path all still agree', () => {
282
+ const listed = [local, twin, remote, folder];
283
+ const pick = (selection: unknown) => {
284
+ const resolved = resolveSelection(listed, selection);
285
+ return resolved.ok ? resolved.path : resolved.code;
286
+ };
287
+ expect(pick({ id: 'ws-app', hostId: 'local', path: '/work/app' })).toBe('/work/app');
288
+ expect(pick({ id: 'ws-dir', hostId: null, path: '/work/app' })).toBe('/work/app');
289
+ expect(pick({ id: 'ws-app', hostId: 'local', path: '/work/app-2' })).toBe('workspace-changed');
290
+ expect(pick({ id: 'ws-ssh', hostId: 'local', path: '/work/app' })).toBe('workspace-changed');
291
+ expect(pick({ id: 'ws-ssh', hostId: 'ssh:build', path: '/work/app' })).toBe('workspace-remote');
292
+ expect(pick({ id: 'ws-gone', hostId: 'local', path: '/work/app' })).toBe(
293
+ 'workspace-unavailable',
294
+ );
295
+ expect(pick({ id: 'ws-app', path: '/work/app' })).toBe('invalid-request');
296
+ expect(pick('ws-app')).toBe('invalid-request');
297
+ expect(resolveSelection([local, { ...twin, id: 'ws-app' }], { ...local })).toMatchObject({
298
+ code: 'workspace-changed',
299
+ });
300
+ expect(
301
+ resolveSelection([{ ...local, path: 'relative/app' }], { ...local, path: 'relative/app' }),
302
+ ).toMatchObject({ code: 'workspace-unavailable' });
303
+ });
304
+ });
305
+
306
+ describe('view mapping', () => {
307
+ // The population block is what `cleo list` prints (packages/core/src/tasks/population.ts):
308
+ // `truncated` there is `returned < matched`, which is still true on the last page.
309
+ const listData = (ids: string[], population: Record<string, unknown>) => ({
310
+ tasks: ids.map((id) => ({ id, title: id, status: 'pending', type: 'epic' })),
311
+ population: { archive: 'excluded', limit: 50, ...population },
312
+ });
313
+
314
+ it('reports more rows while the cursor is short of the match', () => {
315
+ const data = listData(['T1', 'T2'], { matched: 3, returned: 2, truncated: true, offset: 0 });
316
+ expect(toTaskPage(data, 0)).toMatchObject({ ok: true, matched: 3, truncated: true });
317
+ });
318
+
319
+ it('stops on the last page, where CLEO still says truncated', () => {
320
+ const data = listData(['T3'], { matched: 3, returned: 1, truncated: true, offset: 2 });
321
+ expect(toTaskPage(data, 2)).toMatchObject({ ok: true, matched: 3, truncated: false });
322
+ });
323
+
324
+ it('stops when a page adds nothing, whatever the match count says', () => {
325
+ const data = listData([], { matched: 9, returned: 0, truncated: true, offset: 3 });
326
+ expect(toTaskPage(data, 3)).toMatchObject({ ok: true, tasks: [], truncated: false });
327
+ });
328
+
329
+ it.each([
330
+ [{ tasks: 'none' }],
331
+ [{ tasks: [{ title: 'no id' }] }],
332
+ [{}],
333
+ ])('rejects the list data %j as malformed', (data) => {
334
+ expect(toTaskPage(data, 0)).toMatchObject({ ok: false, code: 'malformed-envelope' });
335
+ });
336
+
337
+ it('clips long text and ignores evidence aimed at another task', () => {
338
+ const detail = toTaskDetail({
339
+ task: {
340
+ id: 'T2',
341
+ title: 'x'.repeat(1000),
342
+ description: 'y'.repeat(10_000),
343
+ acceptance: ['First', 'Second'],
344
+ verification: {
345
+ gates: { implemented: true },
346
+ evidence: {
347
+ implemented: {
348
+ atoms: [{ kind: 'satisfies', targetTaskId: 'T9', targetAcAlias: 'AC1' }],
349
+ },
350
+ },
351
+ },
352
+ },
353
+ });
354
+ if (!detail.ok) throw new Error(detail.message);
355
+ expect(detail.task.title.length).toBeLessThan(400);
356
+ expect(detail.task.description.length).toBeLessThan(4100);
357
+ expect(detail.acceptance).toEqual([
358
+ { alias: 'AC1', text: 'First', gates: [] },
359
+ { alias: 'AC2', text: 'Second', gates: [] },
360
+ ]);
361
+ expect(detail.claim).toBeNull();
362
+ expect(toTaskDetail({ task: { title: 'no id' } })).toMatchObject({
363
+ code: 'malformed-envelope',
364
+ });
365
+ });
366
+
367
+ it('shows evidence against the criterion its atom names by id or by alias', () => {
368
+ const first = '11111111-1111-4111-8111-111111111111';
369
+ const second = '22222222-2222-4222-8222-222222222222';
370
+ const atoms = (...list: Record<string, unknown>[]) => ({
371
+ atoms: list.map((atom) => ({ kind: 'satisfies', targetTaskId: 'T5', ...atom })),
372
+ });
373
+ const detail = toTaskDetail({
374
+ task: {
375
+ id: 'T5',
376
+ title: 'Evidence',
377
+ verification: {
378
+ gates: { implemented: true, testsPassed: true, qaPassed: true, documented: true },
379
+ evidence: {
380
+ // The canonical form: the criterion's id.
381
+ implemented: atoms({ targetAcId: second }),
382
+ // The alias form, with the id CLEO resolved it to.
383
+ testsPassed: atoms({ targetAcAlias: 'AC1', resolvedAcUuid: first }),
384
+ // An alias whose resolved id is no criterion of this task any more.
385
+ qaPassed: atoms({
386
+ targetAcAlias: 'AC2',
387
+ resolvedAcUuid: '33333333-3333-4333-8333-333333333333',
388
+ }),
389
+ // An id that is no criterion of this task.
390
+ documented: atoms({ targetAcId: '44444444-4444-4444-8444-444444444444' }),
391
+ },
392
+ },
393
+ },
394
+ acRows: [
395
+ { id: first, alias: 'AC1', text: 'First' },
396
+ { id: second, alias: 'AC2', text: 'Second' },
397
+ ],
398
+ });
399
+ if (!detail.ok) throw new Error(detail.message);
400
+ expect(detail.acceptance).toEqual([
401
+ { alias: 'AC1', text: 'First', gates: ['testsPassed'] },
402
+ { alias: 'AC2', text: 'Second', gates: ['implemented'] },
403
+ ]);
404
+ });
405
+
406
+ it('falls back to the alias when the task read carries no criterion ids', () => {
407
+ const detail = toTaskDetail({
408
+ task: {
409
+ id: 'T6',
410
+ title: 'Plain acceptance',
411
+ acceptance: ['First', 'Second'],
412
+ verification: {
413
+ gates: { implemented: true },
414
+ evidence: {
415
+ implemented: {
416
+ atoms: [{ kind: 'satisfies', targetTaskId: 'T6', targetAcAlias: 'AC2' }],
417
+ },
418
+ },
419
+ },
420
+ },
421
+ });
422
+ if (!detail.ok) throw new Error(detail.message);
423
+ expect(detail.acceptance.map((criterion) => criterion.gates)).toEqual([[], ['implemented']]);
424
+ });
425
+ });
426
+
427
+ describe('plugin manifest', () => {
428
+ const manifest = JSON.parse(
429
+ readFileSync(
430
+ fileURLToPath(new URL('../../orca-plugin/orca-plugin.json', import.meta.url)),
431
+ 'utf8',
432
+ ),
433
+ );
434
+
435
+ it('asks Orca for workspace:read only and contributes one panel and one command', () => {
436
+ expect(manifest.manifestVersion).toBe(2);
437
+ expect(manifest.execution).toBe('trusted-worker');
438
+ expect(manifest.engines.orca).toBe('>=1.4.255');
439
+ expect(manifest.capabilities).toEqual([{ kind: 'workspace:read' }]);
440
+ expect(Object.keys(manifest.contributes).sort()).toEqual(['commands', 'panels']);
441
+ expect(manifest.contributes.panels).toHaveLength(1);
442
+ expect(manifest.contributes.panels[0].ui).toBe('components');
443
+ expect(manifest.contributes.commands).toEqual([
444
+ { id: 'cleo.refresh', title: 'CLEO: Refresh Tasks' },
445
+ ]);
446
+ });
447
+ });
448
+
449
+ describe('worker handlers', () => {
450
+ const local: HostWorkspace = {
451
+ id: 'ws-app',
452
+ kind: 'worktree',
453
+ name: 'app',
454
+ path: '/work/app',
455
+ branch: 'main',
456
+ hostId: 'local',
457
+ };
458
+ const twin: HostWorkspace = { ...local, id: 'ws-twin', path: '/work/app-2' };
459
+ const remote: HostWorkspace = { ...local, id: 'ws-ssh', name: 'server', hostId: 'ssh:build' };
460
+ const chosen = { id: 'ws-app', hostId: 'local', path: '/work/app' };
461
+ const { signal } = new AbortController();
462
+
463
+ /** Handlers over listed workspaces and a runner that records each read. */
464
+ function handlersFor(
465
+ workspaces: HostWorkspace[],
466
+ answer: CleoRunResult = { ok: true, data: { tasks: [] } },
467
+ focus: { displayName: string; branch: string } | null = null,
468
+ ) {
469
+ const runs: { argv: readonly string[]; options: CleoRunOptions }[] = [];
470
+ const handlers = createHandlers(
471
+ {
472
+ list: async () => ({ workspaces, truncated: false }),
473
+ focus: async () => focus,
474
+ },
475
+ async (argv, options) => {
476
+ runs.push({ argv, options });
477
+ return answer;
478
+ },
479
+ );
480
+ return { handlers, runs };
481
+ }
482
+
483
+ it('lists workspaces with remote hosts blocked and the unique focus marked', async () => {
484
+ const { handlers } = handlersFor([local, twin, remote], undefined, {
485
+ displayName: 'server',
486
+ branch: 'main',
487
+ });
488
+ const answer = await handlers.workspaces(signal);
489
+ if (!answer.ok) throw new Error(answer.message);
490
+ expect(
491
+ answer.workspaces.map(({ label, blocked, focused }) => [label, blocked, focused]),
492
+ ).toEqual([
493
+ ['app — /work/app', null, false],
494
+ ['app — /work/app-2', null, false],
495
+ ['server (remote: ssh:build)', 'remote', true],
496
+ ]);
497
+ expect(answer.focus).toEqual({ name: 'server', matches: 1 });
498
+ });
499
+
500
+ it('still lists workspaces when Orca cannot say which one is focused', async () => {
501
+ const handlers = createHandlers(
502
+ {
503
+ list: async () => ({ workspaces: [local], truncated: true }),
504
+ focus: async () => {
505
+ throw new Error('no focus');
506
+ },
507
+ },
508
+ async () => ({ ok: true, data: {} }),
509
+ );
510
+ expect(await handlers.workspaces(signal)).toMatchObject({
511
+ ok: true,
512
+ truncated: true,
513
+ focus: { name: null, matches: 0 },
514
+ });
515
+ });
516
+
517
+ it('reports a workspace list Orca could not give', async () => {
518
+ const handlers = createHandlers(
519
+ {
520
+ list: async () => {
521
+ throw new Error('capability_denied');
522
+ },
523
+ focus: async () => null,
524
+ },
525
+ async () => ({ ok: true, data: {} }),
526
+ );
527
+ expect(await handlers.workspaces(signal)).toMatchObject({ ok: false, code: 'host-error' });
528
+ expect(await handlers.tasks({ selection: chosen }, signal)).toMatchObject({
529
+ ok: false,
530
+ code: 'host-error',
531
+ });
532
+ });
533
+
534
+ it('reads epics with one bounded list call in the chosen local folder', async () => {
535
+ const { handlers, runs } = handlersFor([local, remote], {
536
+ ok: true,
537
+ data: {
538
+ tasks: [{ id: 'T100', title: 'Ship it', status: 'active', type: 'epic' }],
539
+ population: { matched: 120, returned: 1, truncated: true, limit: 50, offset: 0 },
540
+ },
541
+ });
542
+ const page = await handlers.tasks({ selection: chosen, status: 'active' }, signal);
543
+ expect(runs).toHaveLength(1);
544
+ expect(runs[0]?.argv).toEqual([
545
+ 'list',
546
+ '--type',
547
+ 'epic',
548
+ '--status',
549
+ 'active',
550
+ '--limit',
551
+ '50',
552
+ '--offset',
553
+ '0',
554
+ ]);
555
+ expect(runs[0]?.options).toEqual({ cwd: '/work/app', signal });
556
+ expect(page).toMatchObject({ ok: true, matched: 120, truncated: true });
557
+ });
558
+
559
+ it('never runs cleo for a remote, moved, unknown or malformed request', async () => {
560
+ const { handlers, runs } = handlersFor([local, remote]);
561
+ const answers = await Promise.all([
562
+ handlers.tasks(
563
+ { selection: { id: 'ws-ssh', hostId: 'ssh:build', path: '/work/app' } },
564
+ signal,
565
+ ),
566
+ handlers.tasks({ selection: { id: 'ws-app', hostId: 'local', path: '/elsewhere' } }, signal),
567
+ handlers.task({ selection: { ...chosen, id: 'ws-gone' }, taskId: 'T1' }, signal),
568
+ handlers.task({ selection: chosen, taskId: '--force' }, signal),
569
+ handlers.tasks({ selection: chosen, parentId: '--all' }, signal),
570
+ handlers.tasks('not a request', signal),
571
+ ]);
572
+ expect(answers.map((answer) => (answer.ok ? 'ok' : answer.code))).toEqual([
573
+ 'workspace-remote',
574
+ 'workspace-changed',
575
+ 'workspace-unavailable',
576
+ 'invalid-request',
577
+ 'invalid-request',
578
+ 'invalid-request',
579
+ ]);
580
+ expect(runs).toEqual([]);
581
+ });
582
+
583
+ it('refuses a workspace id that names two workspaces', async () => {
584
+ const { handlers, runs } = handlersFor([local, { ...twin, id: 'ws-app' }]);
585
+ expect(await handlers.tasks({ selection: chosen }, signal)).toMatchObject({
586
+ ok: false,
587
+ code: 'workspace-changed',
588
+ });
589
+ expect(runs).toEqual([]);
590
+ });
591
+
592
+ it.each([
593
+ 'cleo-missing',
594
+ 'timeout',
595
+ 'malformed-envelope',
596
+ 'not-a-project',
597
+ ] as const)('hands the panel a %s failure as a value', async (code) => {
598
+ const failed = { ok: false as const, code, message: `fixture ${code}` };
599
+ const { handlers } = handlersFor([local], failed);
600
+ expect(await handlers.tasks({ selection: chosen }, signal)).toEqual(failed);
601
+ expect(await handlers.task({ selection: chosen, taskId: 'T1' }, signal)).toEqual(failed);
602
+ });
603
+
604
+ it('treats a successful envelope without a task list as malformed', async () => {
605
+ const { handlers } = handlersFor([local], { ok: true, data: { rows: [] } });
606
+ expect(await handlers.tasks({ selection: chosen, parentId: 'T100' }, signal)).toMatchObject({
607
+ ok: false,
608
+ code: 'malformed-envelope',
609
+ });
610
+ });
611
+
612
+ it('reads one task with acceptance, evidence and the worker claim', async () => {
613
+ const { handlers, runs } = handlersFor([local], {
614
+ ok: true,
615
+ data: {
616
+ task: {
617
+ id: 'T101',
618
+ title: 'Build the panel',
619
+ status: 'active',
620
+ type: 'task',
621
+ verification: {
622
+ gates: { implemented: true, testsPassed: false },
623
+ evidence: {
624
+ implemented: {
625
+ capturedAt: '2026-11-10T19:00:00.000Z',
626
+ atoms: [
627
+ { kind: 'commit' },
628
+ { kind: 'satisfies', targetTaskId: 'T101', targetAcAlias: 'AC1' },
629
+ ],
630
+ },
631
+ },
632
+ },
633
+ claim: { agentId: 'agent-t101', sessionId: 'ses_1' },
634
+ relationCounts: { children: 2 },
635
+ },
636
+ acRows: [
637
+ { alias: 'AC1', text: 'The panel renders.' },
638
+ { alias: 'AC2', text: 'The worker is bounded.' },
639
+ ],
640
+ view: { nextAction: 'verify' },
641
+ },
642
+ });
643
+ const detail = await handlers.task({ selection: chosen, taskId: 'T101' }, signal);
644
+ expect(runs[0]?.argv).toEqual(['show', 'T101', '--full']);
645
+ expect(detail).toMatchObject({
646
+ ok: true,
647
+ acceptance: [
648
+ { alias: 'AC1', gates: ['implemented'] },
649
+ { alias: 'AC2', gates: [] },
650
+ ],
651
+ gates: [
652
+ { gate: 'implemented', passed: true, atoms: 'commit, satisfies' },
653
+ { gate: 'testsPassed', passed: false, atoms: '' },
654
+ ],
655
+ claim: { agentId: 'agent-t101', sessionId: 'ses_1', claimedAt: null },
656
+ task: { children: 2 },
657
+ nextAction: 'verify',
658
+ });
659
+ });
660
+ });