@cleocode/adapters 2026.10.27 → 2026.11.1-canary.10
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/README.md +2 -0
- package/dist/.source-stamp.json +4 -0
- package/dist/index.js +2676 -1895
- package/dist/index.js.map +3 -3
- package/dist/manifests.d.ts +25 -0
- package/dist/manifests.d.ts.map +1 -0
- package/dist/manifests.js +28 -0
- package/dist/manifests.js.map +6 -0
- package/dist/orca-execution.d.ts +89 -0
- package/dist/orca-execution.d.ts.map +1 -0
- package/dist/orca-execution.js +794 -0
- package/dist/orca-execution.js.map +6 -0
- package/dist/providers/claude-code/index.js +46710 -0
- package/dist/providers/claude-code/index.js.map +6 -0
- package/dist/providers/claude-code/lead-mcp.d.ts +99 -0
- package/dist/providers/claude-code/lead-mcp.d.ts.map +1 -0
- package/dist/providers/claude-code/lead-session.d.ts +133 -0
- package/dist/providers/claude-code/lead-session.d.ts.map +1 -0
- package/dist/providers/claude-code/spawn.d.ts +39 -0
- package/dist/providers/claude-code/spawn.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.js +44549 -0
- package/dist/providers/claude-sdk/index.js.map +6 -0
- package/dist/providers/claude-sdk/spawn.d.ts +6 -0
- package/dist/providers/claude-sdk/spawn.d.ts.map +1 -1
- package/dist/providers/codex/index.js +19315 -0
- package/dist/providers/codex/index.js.map +6 -0
- package/dist/providers/codex/spawn.d.ts +2 -0
- package/dist/providers/codex/spawn.d.ts.map +1 -1
- package/dist/providers/cursor/index.js +637 -0
- package/dist/providers/cursor/index.js.map +6 -0
- package/dist/providers/cursor/spawn.d.ts +2 -0
- package/dist/providers/cursor/spawn.d.ts.map +1 -1
- package/dist/providers/gemini-cli/index.js +18877 -0
- package/dist/providers/gemini-cli/index.js.map +6 -0
- package/dist/providers/gemini-cli/spawn.d.ts +2 -0
- package/dist/providers/gemini-cli/spawn.d.ts.map +1 -1
- package/dist/providers/kimi/index.js +18806 -0
- package/dist/providers/kimi/index.js.map +6 -0
- package/dist/providers/kimi/spawn.d.ts +2 -0
- package/dist/providers/kimi/spawn.d.ts.map +1 -1
- package/dist/providers/openai-sdk/adapter.d.ts +1 -1
- package/dist/providers/openai-sdk/index.d.ts +0 -1
- package/dist/providers/openai-sdk/index.d.ts.map +1 -1
- package/dist/providers/openai-sdk/index.js +44190 -0
- package/dist/providers/openai-sdk/index.js.map +6 -0
- package/dist/providers/openai-sdk/spawn.d.ts +4 -2
- package/dist/providers/openai-sdk/spawn.d.ts.map +1 -1
- package/dist/providers/openai-sdk/tracing.d.ts +8 -82
- package/dist/providers/openai-sdk/tracing.d.ts.map +1 -1
- package/dist/providers/opencode/index.js +19317 -0
- package/dist/providers/opencode/index.js.map +6 -0
- package/dist/providers/opencode/spawn.d.ts +2 -0
- package/dist/providers/opencode/spawn.d.ts.map +1 -1
- package/dist/providers/pi/index.js +18453 -0
- package/dist/providers/pi/index.js.map +6 -0
- package/dist/providers/pi/spawn.d.ts +2 -0
- package/dist/providers/pi/spawn.d.ts.map +1 -1
- package/dist/providers/shared/lead-tool-strip.d.ts +52 -0
- package/dist/providers/shared/lead-tool-strip.d.ts.map +1 -0
- package/dist/registry.d.ts +2 -55
- package/dist/registry.d.ts.map +1 -1
- package/package.json +14 -6
- package/src/__tests__/harness-interop.test.ts +0 -7
- package/src/__tests__/orca-execution-fixture.ts +380 -0
- package/src/__tests__/orca-execution.test.ts +1357 -0
- package/src/__tests__/orca-plugin-panel.test.ts +661 -0
- package/src/__tests__/orca-plugin.test.ts +660 -0
- package/src/manifests.ts +55 -0
- package/src/orca-execution.ts +1136 -0
- package/src/providers/claude-code/__tests__/lead-mcp.test.ts +348 -0
- package/src/providers/claude-code/__tests__/worker-exit-settings.test.ts +32 -0
- package/src/providers/claude-code/lead-mcp.ts +244 -0
- package/src/providers/claude-code/lead-session.ts +241 -0
- package/src/providers/claude-code/spawn.ts +180 -11
- package/src/providers/claude-sdk/__tests__/spawn.test.ts +63 -3
- package/src/providers/claude-sdk/spawn.ts +28 -1
- package/src/providers/codex/spawn.ts +5 -0
- package/src/providers/cursor/spawn.ts +3 -0
- package/src/providers/gemini-cli/spawn.ts +5 -0
- package/src/providers/kimi/spawn.ts +5 -0
- package/src/providers/openai-sdk/__tests__/openai-sdk-spawn.test.ts +0 -80
- package/src/providers/openai-sdk/adapter.ts +1 -1
- package/src/providers/openai-sdk/index.ts +0 -1
- package/src/providers/openai-sdk/manifest.json +1 -1
- package/src/providers/openai-sdk/spawn.ts +10 -16
- package/src/providers/openai-sdk/tracing.ts +8 -169
- package/src/providers/opencode/spawn.ts +5 -0
- package/src/providers/pi/spawn.ts +5 -0
- package/src/providers/shared/__tests__/lead-tool-strip.test.ts +126 -0
- package/src/providers/shared/lead-tool-strip.ts +76 -0
- package/src/registry.ts +2 -78
- package/dist/providers/shared/conduit-trace-writer.d.ts +0 -72
- package/dist/providers/shared/conduit-trace-writer.d.ts.map +0 -1
- package/src/providers/shared/conduit-trace-writer.ts +0 -101
|
@@ -26,6 +26,8 @@ import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/
|
|
|
26
26
|
* All failures are best-effort and non-blocking.
|
|
27
27
|
*/
|
|
28
28
|
export declare class PiSpawnProvider implements AdapterSpawnProvider {
|
|
29
|
+
/** Cannot remove tools from a spawned agent: a lead spawn is refused (T14357). */
|
|
30
|
+
readonly leadToolStrip: "unsupported";
|
|
29
31
|
/** Map of instance IDs to tracked process info. */
|
|
30
32
|
private processMap;
|
|
31
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../src/providers/pi/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../src/providers/pi/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAwB3F;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAgB,YAAW,oBAAoB;IAC1D,kFAAkF;IAClF,QAAQ,CAAC,aAAa,EAAG,aAAa,CAAU;IAEhD,mDAAmD;IACnD,OAAO,CAAC,UAAU,CAAqC;IAEvD;;;;;;OAMG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAOlC;;;;;;;;OAQG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IA+DxD;;;;;;;OAOG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAqB3C;;;;;;;OAOG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAWnD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lead tool strip — the spawn-time guard of the lead/worker split (epic T14351).
|
|
3
|
+
*
|
|
4
|
+
* A lead spawn carries {@link SpawnContext.leadDeniedTools}. A provider that
|
|
5
|
+
* can remove those tools from the spawned agent declares
|
|
6
|
+
* `leadToolStrip: 'enforced'` and strips them; every other provider is
|
|
7
|
+
* `'unsupported'` (also the meaning of an absent declaration), and a lead
|
|
8
|
+
* spawn there is refused with `E_LEAD_TOOLS_UNSTRIPPED` before anything runs.
|
|
9
|
+
* Worker spawns carry no denied tools and pass through unchanged.
|
|
10
|
+
*
|
|
11
|
+
* @task T14357
|
|
12
|
+
* @epic T14351
|
|
13
|
+
*/
|
|
14
|
+
import type { LeadDeniedTool, LeadToolStripSupport, SpawnContext } from '@cleocode/contracts';
|
|
15
|
+
import { ExitCode } from '@cleocode/contracts';
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when a lead spawn reaches a provider that cannot strip the lead's
|
|
18
|
+
* denied tools. Exit code aligns with {@link ExitCode.SPAWN_VALIDATION_FAILED} (63).
|
|
19
|
+
*
|
|
20
|
+
* @task T14357
|
|
21
|
+
*/
|
|
22
|
+
export declare class LeadToolsUnstrippedError extends Error {
|
|
23
|
+
readonly providerId: string;
|
|
24
|
+
readonly deniedTools: readonly LeadDeniedTool[];
|
|
25
|
+
/** Stable LAFS error code string for envelope emission. */
|
|
26
|
+
readonly code: "E_LEAD_TOOLS_UNSTRIPPED";
|
|
27
|
+
/** Numeric exit code aligned with {@link ExitCode.SPAWN_VALIDATION_FAILED} (63). */
|
|
28
|
+
readonly exitCode: ExitCode;
|
|
29
|
+
/**
|
|
30
|
+
* @param providerId - Provider that refused the lead spawn.
|
|
31
|
+
* @param deniedTools - Tools the lead had to lose.
|
|
32
|
+
*/
|
|
33
|
+
constructor(providerId: string, deniedTools: readonly LeadDeniedTool[]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Denied tools of a lead spawn, or `null` for a worker spawn.
|
|
37
|
+
*
|
|
38
|
+
* @param context - Spawn context.
|
|
39
|
+
* @returns The non-empty denied-tool list, or `null` when the spawn is not a lead spawn.
|
|
40
|
+
*/
|
|
41
|
+
export declare function leadDeniedTools(context: SpawnContext): readonly LeadDeniedTool[] | null;
|
|
42
|
+
/**
|
|
43
|
+
* Refuse a lead spawn on a provider that cannot strip its denied tools.
|
|
44
|
+
* No-op for worker spawns and for providers that enforce the strip.
|
|
45
|
+
*
|
|
46
|
+
* @param providerId - Provider performing the spawn.
|
|
47
|
+
* @param support - The provider's strip capability.
|
|
48
|
+
* @param context - Spawn context.
|
|
49
|
+
* @throws {LeadToolsUnstrippedError} When the spawn is a lead spawn and `support` is `'unsupported'`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertLeadToolsStrippable(providerId: string, support: LeadToolStripSupport, context: SpawnContext): void;
|
|
52
|
+
//# sourceMappingURL=lead-tool-strip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lead-tool-strip.d.ts","sourceRoot":"","sources":["../../../src/providers/shared/lead-tool-strip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAA2B,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAExE;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;aAW/B,UAAU,EAAE,MAAM;aAClB,WAAW,EAAE,SAAS,cAAc,EAAE;IAXxD,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,4BAA2B;IACxC,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAoC;IAE/D;;;OAGG;gBAEe,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,SAAS,cAAc,EAAE;CASzD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,cAAc,EAAE,GAAG,IAAI,CAGvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,YAAY,GACpB,IAAI,CAKN"}
|
package/dist/registry.d.ts
CHANGED
|
@@ -6,61 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @task T5240
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* Each provider adapter ships a `manifest.json` in its directory under
|
|
14
|
-
* `providers/`. The registry reads these at startup to populate the
|
|
15
|
-
* adapter discovery surface. The shape is intentionally minimal -- only
|
|
16
|
-
* the fields needed for dynamic loading and detection are required.
|
|
17
|
-
*/
|
|
18
|
-
export interface AdapterManifest {
|
|
19
|
-
/** Unique provider identifier (e.g. "claude-code", "cursor"). */
|
|
20
|
-
id: string;
|
|
21
|
-
/** Human-readable display name for the provider. */
|
|
22
|
-
name: string;
|
|
23
|
-
/** Semantic version of the adapter. */
|
|
24
|
-
version: string;
|
|
25
|
-
/** Short description of what the provider integrates with. */
|
|
26
|
-
description: string;
|
|
27
|
-
/** Provider slug used for directory lookups. */
|
|
28
|
-
provider: string;
|
|
29
|
-
/** Relative path to the adapter's entry point module. */
|
|
30
|
-
entryPoint: string;
|
|
31
|
-
/** Capability flags declared by the adapter. */
|
|
32
|
-
capabilities: Record<string, unknown>;
|
|
33
|
-
/** Patterns used to auto-detect the provider in a project. */
|
|
34
|
-
detectionPatterns: Array<{
|
|
35
|
-
/** Detection strategy type (e.g. "file", "env"). */
|
|
36
|
-
type: string;
|
|
37
|
-
/** Glob or regex pattern to match. */
|
|
38
|
-
pattern: string;
|
|
39
|
-
/** Human-readable explanation of this detection rule. */
|
|
40
|
-
description: string;
|
|
41
|
-
}>;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get the manifests for all bundled provider adapters.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* Scans the known provider directories for `manifest.json` files.
|
|
48
|
-
* Providers whose manifests cannot be loaded (missing or malformed)
|
|
49
|
-
* are silently skipped.
|
|
50
|
-
*
|
|
51
|
-
* @returns Array of adapter manifests for successfully loaded providers
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { getProviderManifests } from '@cleocode/adapters';
|
|
56
|
-
*
|
|
57
|
-
* const manifests = getProviderManifests();
|
|
58
|
-
* for (const m of manifests) {
|
|
59
|
-
* console.log(`${m.id}: ${m.name} v${m.version}`);
|
|
60
|
-
* }
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare function getProviderManifests(): AdapterManifest[];
|
|
9
|
+
export type { AdapterManifest } from '@cleocode/contracts';
|
|
10
|
+
export { getProviderManifests } from './manifests.js';
|
|
64
11
|
/**
|
|
65
12
|
* Discover all available provider adapters.
|
|
66
13
|
*
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAwBtF"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/adapters",
|
|
3
|
-
"version": "2026.10
|
|
3
|
+
"version": "2026.11.1-canary.10",
|
|
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"
|
|
12
16
|
},
|
|
17
|
+
"./manifests": {
|
|
18
|
+
"types": "./src/manifests.ts",
|
|
19
|
+
"import": "./dist/manifests.js"
|
|
20
|
+
},
|
|
13
21
|
"./heavy-command-hook": {
|
|
14
22
|
"types": "./dist/heavy-command-hook.d.ts",
|
|
15
23
|
"import": "./dist/heavy-command-hook.js"
|
|
@@ -27,9 +35,9 @@
|
|
|
27
35
|
"@ai-sdk/anthropic": "^3.0.69",
|
|
28
36
|
"@ai-sdk/openai": "^2.0.53",
|
|
29
37
|
"ai": "^6.0.168",
|
|
30
|
-
"@cleocode/caamp": "2026.10
|
|
31
|
-
"@cleocode/contracts": "2026.10
|
|
32
|
-
"@cleocode/paths": "2026.10
|
|
38
|
+
"@cleocode/caamp": "2026.11.1-canary.10",
|
|
39
|
+
"@cleocode/contracts": "2026.11.1-canary.10",
|
|
40
|
+
"@cleocode/paths": "2026.11.1-canary.10"
|
|
33
41
|
},
|
|
34
42
|
"license": "MIT",
|
|
35
43
|
"engines": {
|
|
@@ -42,8 +50,8 @@
|
|
|
42
50
|
"devDependencies": {
|
|
43
51
|
"@types/node": "^24.3.0",
|
|
44
52
|
"vitest": "^4.1.4",
|
|
45
|
-
"@cleocode/core": "2026.10
|
|
46
|
-
"@cleocode/playbooks": "2026.10
|
|
53
|
+
"@cleocode/core": "2026.11.1-canary.10",
|
|
54
|
+
"@cleocode/playbooks": "2026.11.1-canary.10"
|
|
47
55
|
},
|
|
48
56
|
"repository": {
|
|
49
57
|
"type": "git",
|
|
@@ -102,13 +102,6 @@ vi.mock('../cant-context.js', () => ({
|
|
|
102
102
|
),
|
|
103
103
|
}));
|
|
104
104
|
|
|
105
|
-
// Disable conduit trace writes so the openai-sdk provider never spawns the
|
|
106
|
-
// `cleo` CLI from inside a test run.
|
|
107
|
-
vi.mock('../providers/shared/conduit-trace-writer.js', () => ({
|
|
108
|
-
writeSpanToConduit: vi.fn(async () => ({ written: true })),
|
|
109
|
-
writeSpanBatchToConduit: vi.fn(async () => 0),
|
|
110
|
-
}));
|
|
111
|
-
|
|
112
105
|
// ---------------------------------------------------------------------------
|
|
113
106
|
// Real imports (after mocks so factories take effect)
|
|
114
107
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,380 @@
|
|
|
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 } from '@cleocode/contracts/orca-execution.js';
|
|
11
|
+
import { vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
/** Explicit fictitious caller, independent of the developer's running Orca. */
|
|
14
|
+
export const fixtureContext: OrcaContext = {
|
|
15
|
+
runtimeId: 'runtime-fixture',
|
|
16
|
+
coordinatorHandle: 'term_fixture',
|
|
17
|
+
executionHostId: 'local',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Prepared assignment containing inert shell metacharacters. */
|
|
21
|
+
export const fixtureLaunch: OrcaLaunch = {
|
|
22
|
+
projectId: 'project-fixture',
|
|
23
|
+
projectRoot: '/fixture/project',
|
|
24
|
+
taskId: 'T001',
|
|
25
|
+
instanceId: 'worker-fixture',
|
|
26
|
+
workerSessionId: 'ses_fixture',
|
|
27
|
+
agentId: 'agent-t001',
|
|
28
|
+
role: 'worker',
|
|
29
|
+
protocol: 'implementation',
|
|
30
|
+
worktreePath: '/fixture/canonical/T001',
|
|
31
|
+
worktreeBranch: 'task/T001',
|
|
32
|
+
projectHash: 'fixture-hash',
|
|
33
|
+
lockToken: 'fixture-token',
|
|
34
|
+
prompt: 'Do the task. Preserve `literal backticks` and $(literal); CLEO_SESSION_ID=ses_fixture',
|
|
35
|
+
harness: 'codex',
|
|
36
|
+
leadMailbox: 'fixture-lead',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Wrap a wire result without using its process exit as lifecycle evidence. */
|
|
40
|
+
export function fixtureReply(result: object, exitCode = 0): OrcaCommandResult {
|
|
41
|
+
return {
|
|
42
|
+
stdout: JSON.stringify({ ok: true, result, _meta: { runtimeId: fixtureContext.runtimeId } }),
|
|
43
|
+
stderr: '',
|
|
44
|
+
exitCode,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Full worker-start response fields from the installed CLI contract. */
|
|
49
|
+
export function fixtureStart(
|
|
50
|
+
state = 'ready',
|
|
51
|
+
failureCount = 0,
|
|
52
|
+
dispatchId = 'ctx_fixture',
|
|
53
|
+
): OrcaCommandResult {
|
|
54
|
+
return fixtureReply(
|
|
55
|
+
{
|
|
56
|
+
state,
|
|
57
|
+
failureCount,
|
|
58
|
+
stage: state === 'outcome_unknown' ? 'turn_start_unobserved' : 'input_accepted',
|
|
59
|
+
dispatchId,
|
|
60
|
+
runId: 'run_fixture',
|
|
61
|
+
taskId: 'task_fixture',
|
|
62
|
+
effects: [{ kind: 'worktree', action: 'reused', id: 'workspace-fixture' }],
|
|
63
|
+
residualResources: [],
|
|
64
|
+
launch: { effective: { agent: 'codex', model: null, effort: null } },
|
|
65
|
+
},
|
|
66
|
+
state === 'ready' ? 0 : 1,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Orca 1.4.255 pending workerStart refusal after accept/receipt restart.
|
|
72
|
+
* Source: installed out/main/chunks/orcad-retained-source-*.js mutation ledger
|
|
73
|
+
* and out/cli/runtime/client-error-recovery.js attachMutationRecovery.
|
|
74
|
+
*/
|
|
75
|
+
export function fixturePendingStart(
|
|
76
|
+
dispatchId = 'ctx_retry',
|
|
77
|
+
requestId = 'request-fixture',
|
|
78
|
+
): OrcaCommandResult {
|
|
79
|
+
return {
|
|
80
|
+
stdout: JSON.stringify({
|
|
81
|
+
ok: false,
|
|
82
|
+
error: {
|
|
83
|
+
code: 'operation_unknown',
|
|
84
|
+
message:
|
|
85
|
+
`Worker start ${requestId} was accepted as Dispatch ${dispatchId} before restart. ` +
|
|
86
|
+
`Inspect that Dispatch; do not start another worker. Orchestration mutation request ID: ${requestId}.`,
|
|
87
|
+
data: {
|
|
88
|
+
requestId,
|
|
89
|
+
dispatchId,
|
|
90
|
+
recoveryCommand: `orca orchestration worker-show --dispatch ${dispatchId} --json`,
|
|
91
|
+
orchestrationRequestId: requestId,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
95
|
+
}),
|
|
96
|
+
stderr: '',
|
|
97
|
+
exitCode: 1,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Full exact-dispatch observation; a status hint alone is never a worker report. */
|
|
102
|
+
export function fixtureShow(
|
|
103
|
+
dispatchId = 'ctx_fixture',
|
|
104
|
+
failureCount = 0,
|
|
105
|
+
creatorDispatchId?: string,
|
|
106
|
+
): OrcaCommandResult {
|
|
107
|
+
return fixtureReply({
|
|
108
|
+
dispatch: {
|
|
109
|
+
id: dispatchId,
|
|
110
|
+
runId: 'run_fixture',
|
|
111
|
+
taskId: 'task_fixture',
|
|
112
|
+
failureCount,
|
|
113
|
+
...(creatorDispatchId === undefined ? {} : { creatorDispatchId }),
|
|
114
|
+
},
|
|
115
|
+
worker: {
|
|
116
|
+
dispatchId,
|
|
117
|
+
runtimeEpoch: fixtureContext.runtimeId,
|
|
118
|
+
state: 'ready',
|
|
119
|
+
stage: 'input_accepted',
|
|
120
|
+
worktreeId: 'workspace-fixture',
|
|
121
|
+
},
|
|
122
|
+
observation: { status: 'live', exactWorker: true },
|
|
123
|
+
projection: { resource: { state: 'owned', terminalState: 'active' } },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Recorded resource-release proof, independent of worker launch and Task status. */
|
|
128
|
+
export function fixtureReleasedShow(
|
|
129
|
+
dispatchId = 'ctx_fixture',
|
|
130
|
+
failureCount = 0,
|
|
131
|
+
): OrcaCommandResult {
|
|
132
|
+
const original = orcaReplySchema.parse(JSON.parse(fixtureShow(dispatchId, failureCount).stdout));
|
|
133
|
+
return fixtureReply({
|
|
134
|
+
...original.result,
|
|
135
|
+
worker: { ...original.result?.worker, state: 'failed', stage: 'settled' },
|
|
136
|
+
observation: { status: 'exited', exactWorker: true },
|
|
137
|
+
projection: {
|
|
138
|
+
resource: {
|
|
139
|
+
state: 'released',
|
|
140
|
+
terminalState: 'released',
|
|
141
|
+
releaseState: 'released',
|
|
142
|
+
ownerDispatchId: dispatchId,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A helper Dispatch whose process has exited but whose terminal is still retained.
|
|
150
|
+
* @param dispatchId - Helper Dispatch to render as exited.
|
|
151
|
+
* @param creatorDispatchId - Direct creator the helper must descend from.
|
|
152
|
+
*/
|
|
153
|
+
export function fixtureHelperExited(
|
|
154
|
+
dispatchId: string,
|
|
155
|
+
creatorDispatchId = 'ctx_fixture',
|
|
156
|
+
): OrcaCommandResult {
|
|
157
|
+
const original = orcaReplySchema.parse(
|
|
158
|
+
JSON.parse(fixtureShow(dispatchId, 0, creatorDispatchId).stdout),
|
|
159
|
+
);
|
|
160
|
+
return fixtureReply({
|
|
161
|
+
...original.result,
|
|
162
|
+
worker: { ...original.result?.worker, state: 'succeeded', stage: 'settled' },
|
|
163
|
+
observation: { status: 'exited', exactWorker: true },
|
|
164
|
+
projection: { resource: { state: 'retained', terminalState: 'retained' } },
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Full inbox worker_done shape, with the canonical report carried only by a file pointer. */
|
|
169
|
+
export function fixtureReportInbox(overrides: Partial<OrcaWorkerDone> = {}): OrcaCommandResult {
|
|
170
|
+
const event: OrcaWorkerDone = {
|
|
171
|
+
messageId: 'msg_report',
|
|
172
|
+
runtimeId: fixtureContext.runtimeId,
|
|
173
|
+
runId: 'run_fixture',
|
|
174
|
+
orcaTaskId: 'task_fixture',
|
|
175
|
+
dispatchId: 'ctx_fixture',
|
|
176
|
+
senderHandle: 'term_worker',
|
|
177
|
+
outcome: 'succeeded',
|
|
178
|
+
body: 'Implemented the change. Checks passed. Review remains.',
|
|
179
|
+
reportPath: 'worker-report.txt',
|
|
180
|
+
...overrides,
|
|
181
|
+
};
|
|
182
|
+
return {
|
|
183
|
+
exitCode: 0,
|
|
184
|
+
stderr: '',
|
|
185
|
+
stdout: JSON.stringify({
|
|
186
|
+
ok: true,
|
|
187
|
+
_meta: { runtimeId: event.runtimeId },
|
|
188
|
+
result: {
|
|
189
|
+
messages: [
|
|
190
|
+
{
|
|
191
|
+
id: event.messageId,
|
|
192
|
+
run_id: event.runId,
|
|
193
|
+
delivery_contract: 'current_delivery',
|
|
194
|
+
from_handle: event.senderHandle,
|
|
195
|
+
to_handle: `run:${event.runId}`,
|
|
196
|
+
type: 'worker_done',
|
|
197
|
+
body: event.body,
|
|
198
|
+
payload: JSON.stringify({
|
|
199
|
+
taskId: event.orcaTaskId,
|
|
200
|
+
dispatchId: event.dispatchId,
|
|
201
|
+
outcome: event.outcome,
|
|
202
|
+
reportPath: event.reportPath,
|
|
203
|
+
}),
|
|
204
|
+
sender_pane_key: 'pane_worker',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
}),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** dispatch-show's raw current-task mapping; distinct from worker-show's camel-case view. */
|
|
213
|
+
export function fixtureReportDispatch(
|
|
214
|
+
dispatchId = 'ctx_fixture',
|
|
215
|
+
status = 'completed',
|
|
216
|
+
): OrcaCommandResult {
|
|
217
|
+
return fixtureReply({
|
|
218
|
+
dispatch: {
|
|
219
|
+
id: dispatchId,
|
|
220
|
+
run_id: 'run_fixture',
|
|
221
|
+
task_id: 'task_fixture',
|
|
222
|
+
assignee_handle: 'term_worker',
|
|
223
|
+
assignee_pane_key: 'pane_worker',
|
|
224
|
+
status,
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Durable attempt suitable for testing supervision independently of the store. */
|
|
230
|
+
export function fixtureAttempt(overrides: Partial<OrcaAttempt> = {}): OrcaAttempt {
|
|
231
|
+
return {
|
|
232
|
+
backend: 'orca',
|
|
233
|
+
version: 1,
|
|
234
|
+
revision: 0,
|
|
235
|
+
context: fixtureContext,
|
|
236
|
+
launch: fixtureLaunch,
|
|
237
|
+
promptDigest: 'a'.repeat(64),
|
|
238
|
+
workspaceId: 'workspace-fixture',
|
|
239
|
+
workspaceSelector: 'identity:workspace-fixture',
|
|
240
|
+
state: 'launching',
|
|
241
|
+
runId: null,
|
|
242
|
+
orcaTaskId: null,
|
|
243
|
+
dispatchId: null,
|
|
244
|
+
retryOf: null,
|
|
245
|
+
startBinding: { runId: null, orcaTaskId: null, retryOf: null },
|
|
246
|
+
startRequestId: null,
|
|
247
|
+
stopRequestId: null,
|
|
248
|
+
failureCount: 0,
|
|
249
|
+
resourceState: 'unknown',
|
|
250
|
+
lastReceipt: null,
|
|
251
|
+
lastError: null,
|
|
252
|
+
observedAt: '2026-11-11T00:00:00Z',
|
|
253
|
+
...overrides,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Mutable response selections reset by each test; requests remain argv-only. */
|
|
258
|
+
export const orcaFixture = {
|
|
259
|
+
launch: { ...fixtureLaunch },
|
|
260
|
+
start: fixtureStart(),
|
|
261
|
+
show: fixtureShow(),
|
|
262
|
+
/** Per-helper Dispatch observations; a missing key falls back to `show`. */
|
|
263
|
+
helperShows: {} as Record<string, OrcaCommandResult>,
|
|
264
|
+
capabilities: ['orchestration.contract.v1', 'orchestration.worker-stop-helpers.v1'],
|
|
265
|
+
stop: fixtureReply(
|
|
266
|
+
{
|
|
267
|
+
dispatchId: 'ctx_fixture',
|
|
268
|
+
state: 'stop_unknown',
|
|
269
|
+
processAction: 'closed_agent_terminal',
|
|
270
|
+
helpers: [],
|
|
271
|
+
},
|
|
272
|
+
1,
|
|
273
|
+
),
|
|
274
|
+
request: fixtureReply({ state: 'completed', requestId: 'request-fixture' }),
|
|
275
|
+
read: fixtureReply({ text: 'original output', nextCursor: 'source-pinned-cursor' }),
|
|
276
|
+
accounts: fixtureReply({
|
|
277
|
+
codex: { accounts: [], activeAccountId: 'system' },
|
|
278
|
+
opencode: { accounts: [], activeAccountId: 'system' },
|
|
279
|
+
claude: { accounts: [], activeAccountId: 'system' },
|
|
280
|
+
}),
|
|
281
|
+
caller: fixtureReply({
|
|
282
|
+
terminal: {
|
|
283
|
+
handle: fixtureContext.coordinatorHandle,
|
|
284
|
+
executionHostId: 'local',
|
|
285
|
+
connected: true,
|
|
286
|
+
writable: true,
|
|
287
|
+
},
|
|
288
|
+
}),
|
|
289
|
+
currentRun: fixtureReply({ run: { id: 'run_fixture' } }),
|
|
290
|
+
inbox: fixtureReportInbox(),
|
|
291
|
+
currentDispatch: fixtureReportDispatch(),
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/** Pure CLI fixture dispatcher; unexpected verbs fail instead of launching anything. */
|
|
295
|
+
export const runOrcaFixture: OrcaCommandRunner = async (_executable, args) => {
|
|
296
|
+
if (args[0] === 'account') return orcaFixture.accounts;
|
|
297
|
+
if (args[0] === 'terminal') return orcaFixture.caller;
|
|
298
|
+
if (args[1] === 'run-current') return orcaFixture.currentRun;
|
|
299
|
+
if (args[0] === 'agent-context') {
|
|
300
|
+
return {
|
|
301
|
+
exitCode: 0,
|
|
302
|
+
stderr: '',
|
|
303
|
+
stdout: JSON.stringify({
|
|
304
|
+
schemaVersion: 1,
|
|
305
|
+
commands: [
|
|
306
|
+
{
|
|
307
|
+
command: 'orchestration worker-start',
|
|
308
|
+
flags: [
|
|
309
|
+
'from',
|
|
310
|
+
'spec-file',
|
|
311
|
+
'task',
|
|
312
|
+
'run',
|
|
313
|
+
'worktree',
|
|
314
|
+
'agent',
|
|
315
|
+
'retry-of',
|
|
316
|
+
'retry-request',
|
|
317
|
+
'full',
|
|
318
|
+
'model',
|
|
319
|
+
'effort',
|
|
320
|
+
],
|
|
321
|
+
},
|
|
322
|
+
{ command: 'orchestration worker-show', flags: ['dispatch', 'full'] },
|
|
323
|
+
{
|
|
324
|
+
command: 'orchestration worker-read',
|
|
325
|
+
flags: ['dispatch', 'source', 'limit', 'cursor', 'full'],
|
|
326
|
+
},
|
|
327
|
+
{ command: 'orchestration worker-stop', flags: ['dispatch', 'retry-request', 'full'] },
|
|
328
|
+
{ command: 'orchestration request-show', flags: ['request', 'full'] },
|
|
329
|
+
{ command: 'orchestration run-current', flags: ['from', 'full'] },
|
|
330
|
+
{ command: 'worktree show', flags: ['worktree'] },
|
|
331
|
+
],
|
|
332
|
+
}),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
if (args[0] === 'status')
|
|
336
|
+
return fixtureReply({
|
|
337
|
+
runtime: {
|
|
338
|
+
runtimeId: fixtureContext.runtimeId,
|
|
339
|
+
reachable: true,
|
|
340
|
+
state: 'ready',
|
|
341
|
+
capabilities: orcaFixture.capabilities,
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
if (args[0] === 'worktree')
|
|
345
|
+
return fixtureReply({
|
|
346
|
+
worktree: {
|
|
347
|
+
id: 'workspace-fixture',
|
|
348
|
+
path: orcaFixture.launch.worktreePath,
|
|
349
|
+
branch: `refs/heads/${orcaFixture.launch.worktreeBranch}`,
|
|
350
|
+
hostId: 'local',
|
|
351
|
+
address: { worktree: 'identity:workspace-fixture' },
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
switch (args[1]) {
|
|
355
|
+
case 'worker-start':
|
|
356
|
+
return orcaFixture.start;
|
|
357
|
+
case 'worker-show': {
|
|
358
|
+
const dispatchIndex = args.indexOf('--dispatch');
|
|
359
|
+
const dispatchId = dispatchIndex === -1 ? undefined : args[dispatchIndex + 1];
|
|
360
|
+
return dispatchId
|
|
361
|
+
? (orcaFixture.helperShows[dispatchId] ?? orcaFixture.show)
|
|
362
|
+
: orcaFixture.show;
|
|
363
|
+
}
|
|
364
|
+
case 'worker-stop':
|
|
365
|
+
return orcaFixture.stop;
|
|
366
|
+
case 'request-show':
|
|
367
|
+
return orcaFixture.request;
|
|
368
|
+
case 'worker-read':
|
|
369
|
+
return orcaFixture.read;
|
|
370
|
+
case 'inbox':
|
|
371
|
+
return orcaFixture.inbox;
|
|
372
|
+
case 'dispatch-show':
|
|
373
|
+
return orcaFixture.currentDispatch;
|
|
374
|
+
default:
|
|
375
|
+
throw new Error(`Unexpected fixture command: ${args.join(' ')}`);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/** Injected process spy, never the installed Orca executable. */
|
|
380
|
+
export const fixtureRunner = vi.fn<OrcaCommandRunner>(runOrcaFixture);
|