@cleocode/adapters 2026.11.2 → 2026.11.3-canary.2
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/index.js +138 -35
- package/dist/index.js.map +3 -3
- package/dist/orca-execution.d.ts +14 -3
- package/dist/orca-execution.d.ts.map +1 -1
- package/dist/orca-execution.js +219 -4
- package/dist/orca-execution.js.map +1 -1
- package/dist/providers/claude-code/index.js +107 -11
- package/dist/providers/claude-code/index.js.map +3 -3
- package/dist/providers/claude-code/spawn.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.js +23 -3
- package/dist/providers/claude-sdk/index.js.map +1 -1
- package/dist/providers/codex/index.js +23 -3
- package/dist/providers/codex/index.js.map +1 -1
- package/dist/providers/gemini-cli/index.js +23 -3
- package/dist/providers/gemini-cli/index.js.map +1 -1
- package/dist/providers/kimi/index.js +23 -3
- package/dist/providers/kimi/index.js.map +1 -1
- package/dist/providers/openai-sdk/index.js +23 -3
- package/dist/providers/openai-sdk/index.js.map +1 -1
- package/dist/providers/opencode/index.js +23 -3
- package/dist/providers/opencode/index.js.map +1 -1
- package/dist/providers/pi/index.js +23 -3
- package/dist/providers/pi/index.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/orca-execution-fixture.ts +4 -0
- package/src/__tests__/orca-execution.test.ts +309 -1
- package/src/orca-execution.ts +298 -4
- package/src/providers/claude-code/__tests__/lead-mcp.test.ts +123 -0
- package/src/providers/claude-code/spawn.ts +48 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/adapters",
|
|
3
|
-
"version": "2026.11.2",
|
|
3
|
+
"version": "2026.11.3-canary.2",
|
|
4
4
|
"description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@ai-sdk/anthropic": "^3.0.69",
|
|
36
36
|
"@ai-sdk/openai": "^2.0.53",
|
|
37
37
|
"ai": "^6.0.168",
|
|
38
|
-
"@cleocode/caamp": "2026.11.2",
|
|
39
|
-
"@cleocode/contracts": "2026.11.2",
|
|
40
|
-
"@cleocode/paths": "2026.11.2"
|
|
38
|
+
"@cleocode/caamp": "2026.11.3-canary.2",
|
|
39
|
+
"@cleocode/contracts": "2026.11.3-canary.2",
|
|
40
|
+
"@cleocode/paths": "2026.11.3-canary.2"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"engines": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^24.3.0",
|
|
52
52
|
"vitest": "^4.1.4",
|
|
53
|
-
"@cleocode/core": "2026.11.2",
|
|
54
|
-
"@cleocode/playbooks": "2026.11.2"
|
|
53
|
+
"@cleocode/core": "2026.11.3-canary.2",
|
|
54
|
+
"@cleocode/playbooks": "2026.11.3-canary.2"
|
|
55
55
|
},
|
|
56
56
|
"repository": {
|
|
57
57
|
"type": "git",
|
|
@@ -363,6 +363,10 @@ export const runOrcaFixture: OrcaCommandRunner = async (_executable, args) => {
|
|
|
363
363
|
{ command: 'orchestration request-show', flags: ['request', 'full'] },
|
|
364
364
|
{ command: 'orchestration run-current', flags: ['from', 'full'] },
|
|
365
365
|
{ command: 'worktree show', flags: ['worktree'] },
|
|
366
|
+
{ command: 'terminal create', flags: ['command', 'worktree', 'title', 'environment'] },
|
|
367
|
+
{ command: 'terminal show', flags: ['terminal', 'environment'] },
|
|
368
|
+
{ command: 'terminal close', flags: ['terminal', 'environment'] },
|
|
369
|
+
{ command: 'terminal switch', flags: ['terminal', 'environment'] },
|
|
366
370
|
],
|
|
367
371
|
}),
|
|
368
372
|
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
OrcaAttempt,
|
|
3
|
+
OrcaLeadTerminal,
|
|
4
|
+
OrcaReply,
|
|
5
|
+
} from '@cleocode/contracts/orca-execution.js';
|
|
2
6
|
import { ORCA_AGENT_HARNESSES, orcaReplySchema } from '@cleocode/contracts/orca-execution.js';
|
|
3
7
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
8
|
import { OrcaExecutionBackend } from '../orca-execution.js';
|
|
@@ -345,6 +349,297 @@ describe('Orca execution process boundary', () => {
|
|
|
345
349
|
expect(fixtureRunner).not.toHaveBeenCalled();
|
|
346
350
|
});
|
|
347
351
|
|
|
352
|
+
it
|
|
353
|
+
.skipIf(process.platform === 'win32')
|
|
354
|
+
.each([
|
|
355
|
+
'ready',
|
|
356
|
+
'login-wrapper',
|
|
357
|
+
'ps-from-path',
|
|
358
|
+
'ps-fallback',
|
|
359
|
+
'ps-newer-parent',
|
|
360
|
+
'ps-invalid-start',
|
|
361
|
+
'ps-failed',
|
|
362
|
+
'disconnected',
|
|
363
|
+
'background',
|
|
364
|
+
'hidden-after-create',
|
|
365
|
+
'cleanup-unverified',
|
|
366
|
+
'not-navigated',
|
|
367
|
+
'pid-mismatch',
|
|
368
|
+
'missing-terminal-pid',
|
|
369
|
+
'recorder-failed',
|
|
370
|
+
'wrong-runtime',
|
|
371
|
+
'lost-receipt',
|
|
372
|
+
] as const)(
|
|
373
|
+
'gates the exact terminal argv before a model turn: %s (inert executable only)',
|
|
374
|
+
async (condition) => {
|
|
375
|
+
vi.stubEnv('ORCA_TERMINAL_HANDLE', fixtureContext.coordinatorHandle);
|
|
376
|
+
const root = mkdtempSync(join(tmpdir(), 'orca-lead-fixture-'));
|
|
377
|
+
const cwd = join(root, "project ' `literal` $(literal)");
|
|
378
|
+
mkdirSync(cwd);
|
|
379
|
+
const psCapture = join(root, 'ps-calls.json');
|
|
380
|
+
if (condition.startsWith('ps-')) {
|
|
381
|
+
const bin = join(root, 'bin');
|
|
382
|
+
mkdirSync(bin);
|
|
383
|
+
for (const name of ['sleep', 'rm']) symlinkSync(`/bin/${name}`, join(bin, name));
|
|
384
|
+
if (condition !== 'ps-fallback')
|
|
385
|
+
writeFileSync(
|
|
386
|
+
join(bin, 'ps'),
|
|
387
|
+
`#!${process.execPath}
|
|
388
|
+
import {execFileSync} from 'node:child_process';
|
|
389
|
+
import {writeFileSync} from 'node:fs';
|
|
390
|
+
writeFileSync(${JSON.stringify(psCapture)}, JSON.stringify({TZ:process.env.TZ, LC_ALL:process.env.LC_ALL, LANG:process.env.LANG}));
|
|
391
|
+
const condition = ${JSON.stringify(condition)};
|
|
392
|
+
if (condition === 'ps-failed') process.exit(1);
|
|
393
|
+
if (condition === 'ps-from-path') process.stdout.write(execFileSync('/bin/ps', process.argv.slice(2), {encoding:'utf8'}));
|
|
394
|
+
else {
|
|
395
|
+
const [pid, terminal] = process.argv.at(-1).split(',');
|
|
396
|
+
const start = condition === 'ps-invalid-start' ? 'unreadable' : 'Thu Jan 01 00:00:00 2026';
|
|
397
|
+
process.stdout.write(pid+' '+terminal+' '+start+'\\n'+terminal+' 1 Fri Jan 02 00:00:00 2026\\n');
|
|
398
|
+
}
|
|
399
|
+
`,
|
|
400
|
+
{ mode: 0o700 },
|
|
401
|
+
);
|
|
402
|
+
vi.stubEnv('PATH', condition === 'ps-fallback' ? bin : `${bin}:${process.env.PATH}`);
|
|
403
|
+
}
|
|
404
|
+
const capture = join(root, 'captured.json');
|
|
405
|
+
const binary = join(root, 'claude');
|
|
406
|
+
writeFileSync(
|
|
407
|
+
binary,
|
|
408
|
+
`#!${process.execPath}\nimport {writeFileSync} from 'node:fs';\nwriteFileSync(${JSON.stringify(capture)}, JSON.stringify({args:process.argv.slice(2),session:process.env.CLEO_SESSION_ID,role:process.env.CLEO_AGENT_ROLE,cwd:process.cwd()}));\n`,
|
|
409
|
+
{ mode: 0o700 },
|
|
410
|
+
);
|
|
411
|
+
const args = [
|
|
412
|
+
'--restricted',
|
|
413
|
+
'--setting-sources',
|
|
414
|
+
'',
|
|
415
|
+
"literal ' `backticks` $(touch injected)",
|
|
416
|
+
];
|
|
417
|
+
let child: ChildProcess | undefined;
|
|
418
|
+
let exit: Promise<void> | undefined;
|
|
419
|
+
const started = vi.fn<(pid: number, terminal?: OrcaLeadTerminal) => Promise<void>>(
|
|
420
|
+
async () => {
|
|
421
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
422
|
+
expect(existsSync(capture)).toBe(false);
|
|
423
|
+
if (condition === 'recorder-failed') throw new Error('Lifecycle recorder unavailable');
|
|
424
|
+
},
|
|
425
|
+
);
|
|
426
|
+
fixtureRunner.mockImplementation(async (...params) => {
|
|
427
|
+
const argv = params[1];
|
|
428
|
+
if (argv[0] === 'worktree')
|
|
429
|
+
return fixtureReply({
|
|
430
|
+
worktree: { id: 'workspace-fixture', path: cwd, branch: 'main', hostId: 'local' },
|
|
431
|
+
});
|
|
432
|
+
if (argv[0] === 'terminal' && argv[1] === 'create') {
|
|
433
|
+
const command = argv[argv.indexOf('--command') + 1];
|
|
434
|
+
child = spawn(
|
|
435
|
+
'/bin/sh',
|
|
436
|
+
[
|
|
437
|
+
'-c',
|
|
438
|
+
condition === 'login-wrapper' || condition === 'ps-newer-parent'
|
|
439
|
+
? `${command} & wait`
|
|
440
|
+
: (command ?? 'exit 99'),
|
|
441
|
+
],
|
|
442
|
+
{ stdio: 'ignore' },
|
|
443
|
+
);
|
|
444
|
+
exit = new Promise<void>((resolve) => child?.once('exit', () => resolve()));
|
|
445
|
+
if (condition === 'lost-receipt') return { stdout: '', stderr: 'lost', exitCode: null };
|
|
446
|
+
return fixtureReply({
|
|
447
|
+
terminal: {
|
|
448
|
+
handle: 'term_lead',
|
|
449
|
+
processId:
|
|
450
|
+
condition === 'missing-terminal-pid'
|
|
451
|
+
? undefined
|
|
452
|
+
: condition === 'pid-mismatch'
|
|
453
|
+
? (child.pid ?? 100) + 1
|
|
454
|
+
: child.pid,
|
|
455
|
+
// Orca 1.4.256 live reply: processId is /usr/bin/login, parent of the exec'd shell.
|
|
456
|
+
tabId: 'tab-lead',
|
|
457
|
+
paneKey: 'tab-lead:leaf-lead',
|
|
458
|
+
ptyId: 'workspace-fixture@@lead',
|
|
459
|
+
worktreeId: 'workspace-fixture',
|
|
460
|
+
title: 'CLEO no-hands lead',
|
|
461
|
+
executionHostId: 'local',
|
|
462
|
+
incarnationId: 'incarnation-lead',
|
|
463
|
+
hostPlatform: process.platform,
|
|
464
|
+
surface: condition === 'background' ? 'background' : 'visible',
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (argv[0] === 'terminal' && argv[1] === 'close') {
|
|
469
|
+
child?.kill('SIGTERM');
|
|
470
|
+
return fixtureReply({
|
|
471
|
+
close: { handle: 'term_lead', ptyKilled: condition !== 'cleanup-unverified' },
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (argv[0] === 'terminal' && argv[1] === 'switch') {
|
|
475
|
+
return fixtureReply({
|
|
476
|
+
focus: {
|
|
477
|
+
handle: 'term_lead',
|
|
478
|
+
tabId: 'tab-lead',
|
|
479
|
+
worktreeId: 'workspace-fixture',
|
|
480
|
+
navigated: condition !== 'not-navigated',
|
|
481
|
+
},
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
if (argv[0] === 'terminal' && argv.includes('term_lead')) {
|
|
485
|
+
const reply = fixtureReply({
|
|
486
|
+
terminal: {
|
|
487
|
+
handle: 'term_lead',
|
|
488
|
+
connected: true,
|
|
489
|
+
writable: condition !== 'disconnected' && condition !== 'cleanup-unverified',
|
|
490
|
+
executionHostId: 'local',
|
|
491
|
+
worktreePath: cwd,
|
|
492
|
+
tabId: 'tab-lead',
|
|
493
|
+
surface: condition === 'hidden-after-create' ? 'background' : undefined,
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
return condition === 'wrong-runtime'
|
|
497
|
+
? { ...reply, stdout: reply.stdout.replace(fixtureContext.runtimeId, 'other-runtime') }
|
|
498
|
+
: reply;
|
|
499
|
+
}
|
|
500
|
+
return runOrcaFixture(...params);
|
|
501
|
+
});
|
|
502
|
+
try {
|
|
503
|
+
const result = new OrcaExecutionBackend(fixtureRunner).startLead(
|
|
504
|
+
{
|
|
505
|
+
command: binary,
|
|
506
|
+
args,
|
|
507
|
+
cwd,
|
|
508
|
+
tempDir: root,
|
|
509
|
+
env: {
|
|
510
|
+
CLEO_SESSION_ID: 'ses_own',
|
|
511
|
+
CLEO_AGENT_ID: 'agent-own',
|
|
512
|
+
CLEO_AGENT_ROLE: 'lead',
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
started,
|
|
516
|
+
);
|
|
517
|
+
const ready = ['ready', 'login-wrapper', 'ps-from-path', 'ps-fallback'].includes(condition);
|
|
518
|
+
if (!ready) {
|
|
519
|
+
await expect(result).rejects.toThrow();
|
|
520
|
+
if (condition === 'pid-mismatch')
|
|
521
|
+
await expect(result).rejects.toMatchObject({
|
|
522
|
+
details: {
|
|
523
|
+
terminalHandle: 'term_lead',
|
|
524
|
+
expectedTerminalPid: (child?.pid ?? 100) + 1,
|
|
525
|
+
observedSupervisorPid: child?.pid,
|
|
526
|
+
observedParentPid: process.pid,
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
if (condition === 'cleanup-unverified')
|
|
530
|
+
await expect(result).rejects.toMatchObject({
|
|
531
|
+
code: 'E_LEAD_TOOLS_UNSTRIPPED',
|
|
532
|
+
message: expect.stringContaining('cleanup is unverified'),
|
|
533
|
+
fix: expect.stringContaining('term_lead'),
|
|
534
|
+
details: expect.objectContaining({
|
|
535
|
+
terminalHandle: 'term_lead',
|
|
536
|
+
observedSupervisorPid: child?.pid,
|
|
537
|
+
}),
|
|
538
|
+
});
|
|
539
|
+
expect(started).toHaveBeenCalledTimes(condition === 'recorder-failed' ? 1 : 0);
|
|
540
|
+
expect(existsSync(capture)).toBe(false);
|
|
541
|
+
} else {
|
|
542
|
+
expect(await result).toMatchObject({
|
|
543
|
+
terminalHandle: 'term_lead',
|
|
544
|
+
pid: started.mock.calls[0]?.[0],
|
|
545
|
+
runtimeId: fixtureContext.runtimeId,
|
|
546
|
+
});
|
|
547
|
+
expect(started).toHaveBeenCalledOnce();
|
|
548
|
+
expect(started.mock.calls[0]?.[1]).toMatchObject({
|
|
549
|
+
terminalHandle: 'term_lead',
|
|
550
|
+
pid: started.mock.calls[0]?.[0],
|
|
551
|
+
});
|
|
552
|
+
if (condition === 'login-wrapper')
|
|
553
|
+
expect(started.mock.calls[0]?.[0]).not.toBe(child?.pid);
|
|
554
|
+
await exit;
|
|
555
|
+
expect(JSON.parse(readFileSync(capture, 'utf8'))).toEqual({
|
|
556
|
+
args,
|
|
557
|
+
session: 'ses_own',
|
|
558
|
+
role: 'lead',
|
|
559
|
+
cwd,
|
|
560
|
+
});
|
|
561
|
+
expect(existsSync(join(cwd, 'injected'))).toBe(false);
|
|
562
|
+
}
|
|
563
|
+
if (condition.startsWith('ps-') && condition !== 'ps-fallback')
|
|
564
|
+
expect(JSON.parse(readFileSync(psCapture, 'utf8'))).toEqual({
|
|
565
|
+
TZ: 'UTC',
|
|
566
|
+
LC_ALL: 'C',
|
|
567
|
+
LANG: 'C',
|
|
568
|
+
});
|
|
569
|
+
expect(
|
|
570
|
+
fixtureRunner.mock.calls.some(
|
|
571
|
+
([, argv]) => argv[0] === 'account' || argv[1] === 'worker-start',
|
|
572
|
+
),
|
|
573
|
+
).toBe(false);
|
|
574
|
+
expect(fixtureRunner.mock.calls.filter(([, argv]) => argv[1] === 'create')).toHaveLength(1);
|
|
575
|
+
expect(fixtureRunner.mock.calls.filter(([, argv]) => argv[1] === 'close')).toHaveLength(
|
|
576
|
+
ready || condition === 'lost-receipt' ? 0 : 1,
|
|
577
|
+
);
|
|
578
|
+
if (condition === 'lost-receipt')
|
|
579
|
+
await expect.poll(() => child?.exitCode, { timeout: 1500 }).toBeTypeOf('number');
|
|
580
|
+
} finally {
|
|
581
|
+
child?.kill('SIGTERM');
|
|
582
|
+
await exit;
|
|
583
|
+
rmSync(root, { recursive: true, force: true });
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
it.each([
|
|
589
|
+
'Windows',
|
|
590
|
+
'missing-handle',
|
|
591
|
+
'remote-workspace',
|
|
592
|
+
] as const)('refuses %s before creating a terminal or admitting a lead', async (reason) => {
|
|
593
|
+
const originalPlatform = process.platform;
|
|
594
|
+
vi.stubEnv(
|
|
595
|
+
'ORCA_TERMINAL_HANDLE',
|
|
596
|
+
reason === 'missing-handle' ? undefined : fixtureContext.coordinatorHandle,
|
|
597
|
+
);
|
|
598
|
+
vi.stubEnv('ORCA_WORKTREE_ID', 'partial-context');
|
|
599
|
+
if (reason === 'Windows')
|
|
600
|
+
Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
|
|
601
|
+
if (reason === 'remote-workspace')
|
|
602
|
+
fixtureRunner.mockImplementation(async (...args) =>
|
|
603
|
+
args[1][0] === 'worktree'
|
|
604
|
+
? fixtureReply({
|
|
605
|
+
worktree: {
|
|
606
|
+
id: 'remote',
|
|
607
|
+
path: '/fixture/project',
|
|
608
|
+
branch: 'main',
|
|
609
|
+
hostId: 'ssh-host',
|
|
610
|
+
},
|
|
611
|
+
})
|
|
612
|
+
: runOrcaFixture(...args),
|
|
613
|
+
);
|
|
614
|
+
const admitted = vi.fn<(pid: number) => void>();
|
|
615
|
+
try {
|
|
616
|
+
await expect(
|
|
617
|
+
new OrcaExecutionBackend(fixtureRunner).startLead(
|
|
618
|
+
{
|
|
619
|
+
command: '/fixture/claude',
|
|
620
|
+
args: [],
|
|
621
|
+
cwd: '/fixture/project',
|
|
622
|
+
tempDir: '/fixture/spawn',
|
|
623
|
+
env: {
|
|
624
|
+
CLEO_SESSION_ID: 'ses_own',
|
|
625
|
+
CLEO_AGENT_ID: 'agent-own',
|
|
626
|
+
CLEO_AGENT_ROLE: 'lead',
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
admitted,
|
|
630
|
+
),
|
|
631
|
+
).rejects.toMatchObject({
|
|
632
|
+
code: reason === 'missing-handle' ? 'E_ORCA_CONTEXT' : 'E_LEAD_TOOLS_UNSTRIPPED',
|
|
633
|
+
exitCode: 63,
|
|
634
|
+
fix: expect.stringContaining('keep orchestrate.leadWorker.v1 enabled'),
|
|
635
|
+
});
|
|
636
|
+
expect(admitted).not.toHaveBeenCalled();
|
|
637
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'create')).toBe(false);
|
|
638
|
+
} finally {
|
|
639
|
+
Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
348
643
|
it('refuses a changed runtime and an incomplete command registry before launch', async () => {
|
|
349
644
|
fixtureRunner.mockImplementation(async (...args) =>
|
|
350
645
|
args[1][0] === 'status'
|
|
@@ -1494,3 +1789,16 @@ describe('Orca execution process boundary', () => {
|
|
|
1494
1789
|
});
|
|
1495
1790
|
});
|
|
1496
1791
|
});
|
|
1792
|
+
|
|
1793
|
+
import { type ChildProcess, spawn } from 'node:child_process';
|
|
1794
|
+
import {
|
|
1795
|
+
existsSync,
|
|
1796
|
+
mkdirSync,
|
|
1797
|
+
mkdtempSync,
|
|
1798
|
+
readFileSync,
|
|
1799
|
+
rmSync,
|
|
1800
|
+
symlinkSync,
|
|
1801
|
+
writeFileSync,
|
|
1802
|
+
} from 'node:fs';
|
|
1803
|
+
import { tmpdir } from 'node:os';
|
|
1804
|
+
import { join } from 'node:path';
|