@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
|
@@ -30,6 +30,7 @@ import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/
|
|
|
30
30
|
import { getErrorMessage } from '@cleocode/contracts';
|
|
31
31
|
import { findOnPath } from '@cleocode/paths';
|
|
32
32
|
import { spawnCli } from '../shared/cli-spawn.js';
|
|
33
|
+
import { assertLeadToolsStrippable } from '../shared/lead-tool-strip.js';
|
|
33
34
|
|
|
34
35
|
/** Default Gemini model for subagent spawns. */
|
|
35
36
|
const DEFAULT_MODEL = 'gemini-2.5-pro';
|
|
@@ -59,6 +60,9 @@ interface TrackedProcess {
|
|
|
59
60
|
* @task T648
|
|
60
61
|
*/
|
|
61
62
|
export class GeminiCliSpawnProvider implements AdapterSpawnProvider {
|
|
63
|
+
/** Cannot remove tools from a spawned agent: a lead spawn is refused (T14357). */
|
|
64
|
+
readonly leadToolStrip = 'unsupported' as const;
|
|
65
|
+
|
|
62
66
|
/** Map of instance IDs to tracked process info. */
|
|
63
67
|
private processMap = new Map<string, TrackedProcess>();
|
|
64
68
|
|
|
@@ -87,6 +91,7 @@ export class GeminiCliSpawnProvider implements AdapterSpawnProvider {
|
|
|
87
91
|
* @returns Spawn result with instance ID and status
|
|
88
92
|
*/
|
|
89
93
|
async spawn(context: SpawnContext): Promise<SpawnResult> {
|
|
94
|
+
assertLeadToolsStrippable('gemini-cli', this.leadToolStrip, context);
|
|
90
95
|
const instanceId = `gemini-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
91
96
|
const startTime = new Date().toISOString();
|
|
92
97
|
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/contracts';
|
|
31
31
|
import { getErrorMessage } from '@cleocode/contracts';
|
|
32
32
|
import { findOnPath } from '@cleocode/paths';
|
|
33
|
+
import { assertLeadToolsStrippable } from '../shared/lead-tool-strip.js';
|
|
33
34
|
|
|
34
35
|
/** Moonshot AI API base URL. */
|
|
35
36
|
const MOONSHOT_API_BASE = 'https://api.moonshot.cn/v1';
|
|
@@ -102,6 +103,9 @@ async function kimiCliBinaryAvailable(): Promise<boolean> {
|
|
|
102
103
|
* @task T648
|
|
103
104
|
*/
|
|
104
105
|
export class KimiSpawnProvider implements AdapterSpawnProvider {
|
|
106
|
+
/** Cannot remove tools from a spawned agent: a lead spawn is refused (T14357). */
|
|
107
|
+
readonly leadToolStrip = 'unsupported' as const;
|
|
108
|
+
|
|
105
109
|
/** In-flight run tracking set. */
|
|
106
110
|
private readonly runningInstances = new Map<string, TrackedRun>();
|
|
107
111
|
|
|
@@ -136,6 +140,7 @@ export class KimiSpawnProvider implements AdapterSpawnProvider {
|
|
|
136
140
|
* @returns Resolved spawn result with `status: 'completed'` or `'failed'`
|
|
137
141
|
*/
|
|
138
142
|
async spawn(context: SpawnContext): Promise<SpawnResult> {
|
|
143
|
+
assertLeadToolsStrippable('kimi', this.leadToolStrip, context);
|
|
139
144
|
const instanceId = `kimi-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
140
145
|
const startTime = new Date().toISOString();
|
|
141
146
|
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
* - SpawnProviderTests: spawn(), listRunning(), terminate(), canSpawn()
|
|
11
11
|
* - AdapterTests: identity, capabilities, initialize, dispose, healthCheck
|
|
12
12
|
* - InstallProviderTests: isInstalled, install, uninstall
|
|
13
|
-
* - TraceProcessorTests: onSpanEnd event capture
|
|
14
13
|
* - HandoffIntegrationTest: lead + worker topology with mocked generateText
|
|
15
14
|
*
|
|
16
15
|
* @task T582 (original)
|
|
@@ -100,15 +99,6 @@ vi.mock('../../cant-context.js', () => ({
|
|
|
100
99
|
),
|
|
101
100
|
}));
|
|
102
101
|
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
// Mock conduit-trace-writer to avoid CLI calls in unit tests
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
|
|
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
102
|
// ---------------------------------------------------------------------------
|
|
113
103
|
// Imports (after mocks)
|
|
114
104
|
// ---------------------------------------------------------------------------
|
|
@@ -131,21 +121,6 @@ import {
|
|
|
131
121
|
} from '../handoff.js';
|
|
132
122
|
import { OpenAiSdkInstallProvider } from '../install.js';
|
|
133
123
|
import { OpenAiSdkSpawnProvider } from '../spawn.js';
|
|
134
|
-
import { CleoConduitTraceProcessor, type CleoSpan } from '../tracing.js';
|
|
135
|
-
|
|
136
|
-
// ---------------------------------------------------------------------------
|
|
137
|
-
// Helpers
|
|
138
|
-
// ---------------------------------------------------------------------------
|
|
139
|
-
|
|
140
|
-
function makeSpanLike(overrides: Partial<CleoSpan> = {}): CleoSpan {
|
|
141
|
-
return {
|
|
142
|
-
spanId: 'span-001',
|
|
143
|
-
startedAt: new Date().toISOString(),
|
|
144
|
-
endedAt: new Date().toISOString(),
|
|
145
|
-
spanData: { type: 'agent', name: 'test-agent' },
|
|
146
|
-
...overrides,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
124
|
|
|
150
125
|
// ---------------------------------------------------------------------------
|
|
151
126
|
// Path ACL helpers
|
|
@@ -626,61 +601,6 @@ describe('OpenAiSdkInstallProvider', () => {
|
|
|
626
601
|
});
|
|
627
602
|
});
|
|
628
603
|
|
|
629
|
-
// ---------------------------------------------------------------------------
|
|
630
|
-
// Trace processor
|
|
631
|
-
// ---------------------------------------------------------------------------
|
|
632
|
-
|
|
633
|
-
describe('CleoConduitTraceProcessor', () => {
|
|
634
|
-
let processor: CleoConduitTraceProcessor;
|
|
635
|
-
|
|
636
|
-
beforeEach(() => {
|
|
637
|
-
processor = new CleoConduitTraceProcessor('T582-test');
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
afterEach(() => vi.clearAllMocks());
|
|
641
|
-
|
|
642
|
-
describe('onTraceStart', () => {
|
|
643
|
-
it('resolves without error', async () => {
|
|
644
|
-
await expect(processor.onTraceStart({})).resolves.toBeUndefined();
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
describe('onTraceEnd', () => {
|
|
649
|
-
it('resolves without error', async () => {
|
|
650
|
-
await expect(processor.onTraceEnd({})).resolves.toBeUndefined();
|
|
651
|
-
});
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
describe('onSpanStart', () => {
|
|
655
|
-
it('resolves without error', async () => {
|
|
656
|
-
await expect(processor.onSpanStart(makeSpanLike())).resolves.toBeUndefined();
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
describe('onSpanEnd', () => {
|
|
661
|
-
it('does not throw for a well-formed span', async () => {
|
|
662
|
-
const span = makeSpanLike();
|
|
663
|
-
await expect(processor.onSpanEnd(span)).resolves.toBeUndefined();
|
|
664
|
-
});
|
|
665
|
-
|
|
666
|
-
it('does not throw for a span with missing fields', async () => {
|
|
667
|
-
await expect(processor.onSpanEnd({ spanId: 'x' })).resolves.toBeUndefined();
|
|
668
|
-
});
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
describe('shutdown', () => {
|
|
672
|
-
it('resolves without error', async () => {
|
|
673
|
-
await expect(processor.shutdown(1000)).resolves.toBeUndefined();
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
describe('forceFlush', () => {
|
|
678
|
-
it('resolves without error', async () => {
|
|
679
|
-
await expect(processor.forceFlush()).resolves.toBeUndefined();
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
});
|
|
683
|
-
|
|
684
604
|
// ---------------------------------------------------------------------------
|
|
685
605
|
// Handoff integration: lead + workers with mocked generateText
|
|
686
606
|
// ---------------------------------------------------------------------------
|
|
@@ -25,7 +25,7 @@ import { OpenAiSdkSpawnProvider } from './spawn.js';
|
|
|
25
25
|
* Bridges CLEO's adapter system with the Vercel AI SDK:
|
|
26
26
|
* - Spawn: Launches agents via the SDK with CLEO-native handoff topology
|
|
27
27
|
* - Install: Manages AGENTS.md @-references and .openai/ config directory
|
|
28
|
-
* - Tracing:
|
|
28
|
+
* - Tracing: span dispatch to processors registered via `registerTraceProcessor`
|
|
29
29
|
*
|
|
30
30
|
* @remarks
|
|
31
31
|
* Handoff topology is CLEO-owned (see `handoff.ts`): lead agents delegate to
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"provider.openai.tracingEnabled": {
|
|
36
36
|
"type": "boolean",
|
|
37
37
|
"default": true,
|
|
38
|
-
"description": "Whether to
|
|
38
|
+
"description": "Whether to dispatch adapter span events to registered trace processors"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"detectionPatterns": [
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* - Tier-based model selection (lead → gpt-4.1, worker → gpt-4.1-mini)
|
|
15
15
|
* - Handoff topology built from `SpawnContext.options.handoffs` (CLEO-native)
|
|
16
16
|
* - CLEO path ACL guardrails evaluated before the model call
|
|
17
|
-
* -
|
|
17
|
+
* - Span dispatch to processors registered via `registerTraceProcessor`
|
|
18
18
|
* - CANT prompt enrichment (best-effort, same as Claude Code provider)
|
|
19
19
|
*
|
|
20
20
|
* @task T582 (original)
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
|
|
25
25
|
import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/contracts';
|
|
26
26
|
import { getErrorMessage } from '@cleocode/contracts';
|
|
27
|
+
import { assertLeadToolsStrippable } from '../shared/lead-tool-strip.js';
|
|
27
28
|
import { mapSdkRunOutcome } from '../shared/sdk-result-mapper.js';
|
|
28
29
|
import { buildDefaultGuardrails, evaluateGuardrails } from './guardrails.js';
|
|
29
30
|
import { buildAgentTopology, type CleoAgent } from './handoff.js';
|
|
30
31
|
import type { CleoSpan, CleoTraceProcessor } from './tracing.js';
|
|
31
|
-
import { CleoConduitTraceProcessor } from './tracing.js';
|
|
32
32
|
|
|
33
33
|
// ---------------------------------------------------------------------------
|
|
34
34
|
// Types
|
|
@@ -81,7 +81,7 @@ export interface OpenAiSdkSpawnOptions {
|
|
|
81
81
|
allowedTools?: string[];
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
* Disable
|
|
84
|
+
* Disable span dispatch to registered trace processors for this run.
|
|
85
85
|
*
|
|
86
86
|
* @defaultValue `false`
|
|
87
87
|
*/
|
|
@@ -195,6 +195,9 @@ async function emitSpan(span: CleoSpan): Promise<void> {
|
|
|
195
195
|
* ```
|
|
196
196
|
*/
|
|
197
197
|
export class OpenAiSdkSpawnProvider implements AdapterSpawnProvider {
|
|
198
|
+
/** Cannot remove tools from a spawned agent: a lead spawn is refused (T14357). */
|
|
199
|
+
readonly leadToolStrip = 'unsupported' as const;
|
|
200
|
+
|
|
198
201
|
/** Currently running instance IDs (completed runs are removed). */
|
|
199
202
|
private readonly runningInstances = new Set<string>();
|
|
200
203
|
|
|
@@ -218,6 +221,7 @@ export class OpenAiSdkSpawnProvider implements AdapterSpawnProvider {
|
|
|
218
221
|
* @returns Resolved spawn result with `status: 'completed'` or `'failed'`.
|
|
219
222
|
*/
|
|
220
223
|
async spawn(context: SpawnContext): Promise<SpawnResult> {
|
|
224
|
+
assertLeadToolsStrippable('openai-sdk', this.leadToolStrip, context);
|
|
221
225
|
const instanceId = `openai-sdk-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
222
226
|
const startTime = new Date().toISOString();
|
|
223
227
|
|
|
@@ -254,16 +258,9 @@ export class OpenAiSdkSpawnProvider implements AdapterSpawnProvider {
|
|
|
254
258
|
guardrails,
|
|
255
259
|
});
|
|
256
260
|
|
|
257
|
-
//
|
|
258
|
-
let traceProcessor: CleoConduitTraceProcessor | undefined;
|
|
261
|
+
// Span dispatch is on unless this run opts out.
|
|
259
262
|
const previousTracingDisabled = tracingGlobalDisabled;
|
|
260
|
-
|
|
261
|
-
traceProcessor = new CleoConduitTraceProcessor(context.taskId);
|
|
262
|
-
registerTraceProcessor(traceProcessor);
|
|
263
|
-
setTracingDisabled(false);
|
|
264
|
-
} else {
|
|
265
|
-
setTracingDisabled(true);
|
|
266
|
-
}
|
|
263
|
+
setTracingDisabled(opts.tracingDisabled === true);
|
|
267
264
|
|
|
268
265
|
try {
|
|
269
266
|
// Evaluate guardrails before any model call. A tripped guardrail
|
|
@@ -288,10 +285,7 @@ export class OpenAiSdkSpawnProvider implements AdapterSpawnProvider {
|
|
|
288
285
|
succeeded: true,
|
|
289
286
|
});
|
|
290
287
|
} finally {
|
|
291
|
-
// Restore previous tracing state
|
|
292
|
-
if (traceProcessor) {
|
|
293
|
-
unregisterTraceProcessor(traceProcessor);
|
|
294
|
-
}
|
|
288
|
+
// Restore the previous tracing state.
|
|
295
289
|
setTracingDisabled(previousTracingDisabled);
|
|
296
290
|
}
|
|
297
291
|
} catch (error: unknown) {
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CLEO
|
|
2
|
+
* CLEO-native tracing contract for the OpenAI SDK adapter.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
* (
|
|
7
|
-
*
|
|
8
|
-
* produced by `OpenAiSdkSpawnProvider` during a run.
|
|
4
|
+
* `OpenAiSdkSpawnProvider` emits `CleoSpan` events during a run and dispatches
|
|
5
|
+
* them to every processor registered through `registerTraceProcessor`
|
|
6
|
+
* (`spawn.ts`). No processor is registered by default: the former conduit
|
|
7
|
+
* writer shelled out to `cleo conduit send`, which no longer exists (T14376).
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* conduit is unavailable.
|
|
9
|
+
* Set `options.tracingDisabled = true` in `SpawnContext.options` to suppress
|
|
10
|
+
* dispatch for a run.
|
|
13
11
|
*
|
|
14
12
|
* @task T582 (original)
|
|
15
13
|
* @task T933 (SDK consolidation — provider-neutral rewrite)
|
|
14
|
+
* @task T14376 (dead conduit writer removed)
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
|
-
import type { ConduitSpanEvent } from '../shared/conduit-trace-writer.js';
|
|
19
|
-
import { writeSpanBatchToConduit } from '../shared/conduit-trace-writer.js';
|
|
20
|
-
|
|
21
17
|
// ---------------------------------------------------------------------------
|
|
22
18
|
// CLEO-native span shape
|
|
23
19
|
// ---------------------------------------------------------------------------
|
|
@@ -99,160 +95,3 @@ export interface CleoTraceProcessor {
|
|
|
99
95
|
shutdown(timeout?: number): Promise<void>;
|
|
100
96
|
forceFlush(): Promise<void>;
|
|
101
97
|
}
|
|
102
|
-
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
// Processor
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* CLEO trace processor that persists OpenAI SDK adapter spans to conduit.db.
|
|
109
|
-
*
|
|
110
|
-
* Each `onSpanEnd` call extracts span metadata and enqueues a write to conduit
|
|
111
|
-
* via the shared `conduit-trace-writer` module. Writes are fire-and-forget —
|
|
112
|
-
* failures are logged but never propagated to the caller.
|
|
113
|
-
*
|
|
114
|
-
* @remarks
|
|
115
|
-
* `onTraceEnd` performs a batch flush of any buffered spans. Individual
|
|
116
|
-
* `onSpanEnd` calls also write immediately so spans are not lost if the run
|
|
117
|
-
* is interrupted.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* import { registerTraceProcessor } from './spawn.js';
|
|
122
|
-
* import { CleoConduitTraceProcessor } from './tracing.js';
|
|
123
|
-
*
|
|
124
|
-
* const processor = new CleoConduitTraceProcessor('T582');
|
|
125
|
-
* registerTraceProcessor(processor);
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
export class CleoConduitTraceProcessor implements CleoTraceProcessor {
|
|
129
|
-
/** CLEO task ID included in every span event for correlation. */
|
|
130
|
-
private readonly taskId: string;
|
|
131
|
-
|
|
132
|
-
/** Pending span events buffered within the current trace. */
|
|
133
|
-
private pendingEvents: ConduitSpanEvent[] = [];
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @param taskId - CLEO task ID to attach to every written span.
|
|
137
|
-
*/
|
|
138
|
-
constructor(taskId: string) {
|
|
139
|
-
this.taskId = taskId;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Called when a new trace starts. Resets the pending event buffer.
|
|
144
|
-
*
|
|
145
|
-
* @param _trace - The trace that just started (unused).
|
|
146
|
-
*/
|
|
147
|
-
async onTraceStart(_trace: CleoTrace): Promise<void> {
|
|
148
|
-
this.pendingEvents = [];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Called when a trace ends. Flushes all pending span events to conduit.
|
|
153
|
-
*
|
|
154
|
-
* @param _trace - The trace that just ended (unused — spans were captured via `onSpanEnd`).
|
|
155
|
-
*/
|
|
156
|
-
async onTraceEnd(_trace: CleoTrace): Promise<void> {
|
|
157
|
-
if (this.pendingEvents.length > 0) {
|
|
158
|
-
await writeSpanBatchToConduit(this.pendingEvents);
|
|
159
|
-
this.pendingEvents = [];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Called when a new span starts. No-op — we capture on end to have full timing.
|
|
165
|
-
*
|
|
166
|
-
* @param _span - The span that just started (unused).
|
|
167
|
-
*/
|
|
168
|
-
async onSpanStart(_span: CleoSpan): Promise<void> {
|
|
169
|
-
// Capture on end so startedAt / endedAt are both populated.
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Called when a span ends. Serialises and writes the span to conduit.
|
|
174
|
-
*
|
|
175
|
-
* @param span - The completed span from the adapter.
|
|
176
|
-
*/
|
|
177
|
-
async onSpanEnd(span: CleoSpan): Promise<void> {
|
|
178
|
-
const event = this.extractSpanEvent(span);
|
|
179
|
-
if (event) {
|
|
180
|
-
this.pendingEvents.push(event);
|
|
181
|
-
// Also write immediately to survive partial run interruptions.
|
|
182
|
-
await writeSpanBatchToConduit([event]);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Called during graceful shutdown. Flushes any remaining pending events.
|
|
188
|
-
*
|
|
189
|
-
* @param _timeout - Shutdown timeout in milliseconds (unused).
|
|
190
|
-
*/
|
|
191
|
-
async shutdown(_timeout?: number): Promise<void> {
|
|
192
|
-
if (this.pendingEvents.length > 0) {
|
|
193
|
-
await writeSpanBatchToConduit(this.pendingEvents);
|
|
194
|
-
this.pendingEvents = [];
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Force-flush all pending span events to conduit immediately.
|
|
200
|
-
*/
|
|
201
|
-
async forceFlush(): Promise<void> {
|
|
202
|
-
if (this.pendingEvents.length > 0) {
|
|
203
|
-
await writeSpanBatchToConduit(this.pendingEvents);
|
|
204
|
-
this.pendingEvents = [];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ---------------------------------------------------------------------------
|
|
209
|
-
// Private helpers
|
|
210
|
-
// ---------------------------------------------------------------------------
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Extract a {@link ConduitSpanEvent} from an adapter span, or `null` if the
|
|
214
|
-
* span cannot be meaningfully serialised.
|
|
215
|
-
*
|
|
216
|
-
* @param span - The adapter span to serialise.
|
|
217
|
-
* @returns A conduit span event or `null`.
|
|
218
|
-
*/
|
|
219
|
-
private extractSpanEvent(span: CleoSpan): ConduitSpanEvent | null {
|
|
220
|
-
const spanId =
|
|
221
|
-
span.spanId ?? `span-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`;
|
|
222
|
-
|
|
223
|
-
// Guard against malformed/empty spans (e.g. in unit tests with minimal mocks).
|
|
224
|
-
if (!span.spanData) return null;
|
|
225
|
-
|
|
226
|
-
const data = span.spanData;
|
|
227
|
-
const spanType = data.type;
|
|
228
|
-
|
|
229
|
-
// Extract agent name from span data shape based on type.
|
|
230
|
-
let agentName = 'unknown';
|
|
231
|
-
let handoffTarget: string | undefined;
|
|
232
|
-
|
|
233
|
-
if (data.type === 'agent') {
|
|
234
|
-
agentName = data.name;
|
|
235
|
-
} else if (data.type === 'handoff') {
|
|
236
|
-
agentName = data.from_agent ?? 'unknown';
|
|
237
|
-
handoffTarget = data.to_agent ?? undefined;
|
|
238
|
-
} else if (data.type === 'function') {
|
|
239
|
-
agentName = data.name;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const startTime = span.startedAt ?? new Date().toISOString();
|
|
243
|
-
const endTime = span.endedAt ?? new Date().toISOString();
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
spanId,
|
|
247
|
-
taskId: this.taskId,
|
|
248
|
-
agentName,
|
|
249
|
-
spanType,
|
|
250
|
-
startTime,
|
|
251
|
-
endTime,
|
|
252
|
-
handoffTarget,
|
|
253
|
-
metadata: {
|
|
254
|
-
rawSpanData: data,
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
}
|
|
@@ -16,6 +16,7 @@ import { join } from 'node:path';
|
|
|
16
16
|
import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/contracts';
|
|
17
17
|
import { findOnPath } from '@cleocode/paths';
|
|
18
18
|
import { spawnCli } from '../shared/cli-spawn.js';
|
|
19
|
+
import { assertLeadToolsStrippable } from '../shared/lead-tool-strip.js';
|
|
19
20
|
import { getCleoTemplatesTildePath } from '../shared/paths.js';
|
|
20
21
|
|
|
21
22
|
/** Name used for the CLEO subagent definition in OpenCode's agent directory. */
|
|
@@ -132,6 +133,9 @@ async function ensureSubagentDefinition(
|
|
|
132
133
|
* checks.
|
|
133
134
|
*/
|
|
134
135
|
export class OpenCodeSpawnProvider implements AdapterSpawnProvider {
|
|
136
|
+
/** Cannot remove tools from a spawned agent: a lead spawn is refused (T14357). */
|
|
137
|
+
readonly leadToolStrip = 'unsupported' as const;
|
|
138
|
+
|
|
135
139
|
/** Map of instance IDs to tracked process info. */
|
|
136
140
|
private processMap = new Map<string, TrackedProcess>();
|
|
137
141
|
|
|
@@ -155,6 +159,7 @@ export class OpenCodeSpawnProvider implements AdapterSpawnProvider {
|
|
|
155
159
|
* @returns Spawn result with instance ID and status
|
|
156
160
|
*/
|
|
157
161
|
async spawn(context: SpawnContext): Promise<SpawnResult> {
|
|
162
|
+
assertLeadToolsStrippable('opencode', this.leadToolStrip, context);
|
|
158
163
|
const instanceId = `opencode-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
159
164
|
const startTime = new Date().toISOString();
|
|
160
165
|
const workingDirectory = context.workingDirectory ?? process.cwd();
|
|
@@ -17,6 +17,7 @@ import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/
|
|
|
17
17
|
import { getErrorMessage } from '@cleocode/contracts';
|
|
18
18
|
import { findOnPath } from '@cleocode/paths';
|
|
19
19
|
import { spawnCli } from '../shared/cli-spawn.js';
|
|
20
|
+
import { assertLeadToolsStrippable } from '../shared/lead-tool-strip.js';
|
|
20
21
|
import { removeSpawnPromptFile, writeSpawnPromptFile } from '../shared/prompt-file.js';
|
|
21
22
|
|
|
22
23
|
/** Internal tracking entry for a spawned process. */
|
|
@@ -50,6 +51,9 @@ function getPiCliPath(): string {
|
|
|
50
51
|
* All failures are best-effort and non-blocking.
|
|
51
52
|
*/
|
|
52
53
|
export class PiSpawnProvider implements AdapterSpawnProvider {
|
|
54
|
+
/** Cannot remove tools from a spawned agent: a lead spawn is refused (T14357). */
|
|
55
|
+
readonly leadToolStrip = 'unsupported' as const;
|
|
56
|
+
|
|
53
57
|
/** Map of instance IDs to tracked process info. */
|
|
54
58
|
private processMap = new Map<string, TrackedProcess>();
|
|
55
59
|
|
|
@@ -77,6 +81,7 @@ export class PiSpawnProvider implements AdapterSpawnProvider {
|
|
|
77
81
|
* @returns Spawn result with instance ID and status
|
|
78
82
|
*/
|
|
79
83
|
async spawn(context: SpawnContext): Promise<SpawnResult> {
|
|
84
|
+
assertLeadToolsStrippable('pi', this.leadToolStrip, context);
|
|
80
85
|
const instanceId = `pi-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
81
86
|
const startTime = new Date().toISOString();
|
|
82
87
|
let tmpFile: string | undefined;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lead tool strip (T14357): claude-code strips the lead's denied tools with
|
|
3
|
+
* `--disallowedTools`, providers that cannot strip refuse a lead spawn with
|
|
4
|
+
* `E_LEAD_TOOLS_UNSTRIPPED`, and worker spawns keep their tool set. A lead
|
|
5
|
+
* gets the command runner as its one command tool (T14363).
|
|
6
|
+
*
|
|
7
|
+
* @task T14357
|
|
8
|
+
* @epic T14351
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { AdapterSpawnProvider, SpawnContext } from '@cleocode/contracts';
|
|
12
|
+
import {
|
|
13
|
+
E_LEAD_TOOLS_UNSTRIPPED,
|
|
14
|
+
LEAD_DENIED_TOOLS,
|
|
15
|
+
LEAD_RUNNER_MCP_SERVER,
|
|
16
|
+
LEAD_RUNNER_TOOL,
|
|
17
|
+
} from '@cleocode/contracts';
|
|
18
|
+
import { describe, expect, it } from 'vitest';
|
|
19
|
+
import { buildClaudeArgs, ClaudeCodeSpawnProvider } from '../../claude-code/spawn.js';
|
|
20
|
+
import { CodexSpawnProvider } from '../../codex/spawn.js';
|
|
21
|
+
import { GeminiCliSpawnProvider } from '../../gemini-cli/spawn.js';
|
|
22
|
+
import { KimiSpawnProvider } from '../../kimi/spawn.js';
|
|
23
|
+
import { OpenAiSdkSpawnProvider } from '../../openai-sdk/spawn.js';
|
|
24
|
+
import { OpenCodeSpawnProvider } from '../../opencode/spawn.js';
|
|
25
|
+
import { PiSpawnProvider } from '../../pi/spawn.js';
|
|
26
|
+
import { assertLeadToolsStrippable, LeadToolsUnstrippedError } from '../lead-tool-strip.js';
|
|
27
|
+
|
|
28
|
+
const LEAD: SpawnContext = { taskId: 'T1', prompt: 'plan', leadDeniedTools: LEAD_DENIED_TOOLS };
|
|
29
|
+
const WORKER: SpawnContext = { taskId: 'T1', prompt: 'work' };
|
|
30
|
+
|
|
31
|
+
describe('claude-code lead tool strip', () => {
|
|
32
|
+
it('declares the strip as enforced', () => {
|
|
33
|
+
expect(new ClaudeCodeSpawnProvider().leadToolStrip).toBe('enforced');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('lead argv carries --disallowedTools with Bash, Edit and Write and no --dangerously-skip-permissions', () => {
|
|
37
|
+
const args = buildClaudeArgs(LEAD, '/tmp/prompt.md');
|
|
38
|
+
expect(args).not.toContain('--dangerously-skip-permissions');
|
|
39
|
+
// T14363: --allowedTools only pre-approves the runner; it never strips.
|
|
40
|
+
// (Interactive, the default, also allows AskUserQuestion.)
|
|
41
|
+
expect(args[args.indexOf('--allowedTools') + 1]?.split(',')).toEqual([
|
|
42
|
+
LEAD_RUNNER_TOOL,
|
|
43
|
+
'AskUserQuestion',
|
|
44
|
+
]);
|
|
45
|
+
const flag = args.indexOf('--disallowedTools');
|
|
46
|
+
expect(flag).toBeGreaterThanOrEqual(0);
|
|
47
|
+
const denied = (args[flag + 1] ?? '').split(',');
|
|
48
|
+
expect(denied).toEqual(expect.arrayContaining(['Bash', 'Edit', 'Write']));
|
|
49
|
+
expect(denied).toEqual(['Bash', 'Edit', 'Write', 'NotebookEdit', 'WebFetch', 'WebSearch']);
|
|
50
|
+
// The prompt file is the appended system prompt; the lead cannot Read files.
|
|
51
|
+
expect(args[args.indexOf('--append-system-prompt-file') + 1]).toBe('/tmp/prompt.md');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('lead argv serves the command runner as its only command tool (T14363)', () => {
|
|
55
|
+
const args = buildClaudeArgs(LEAD, '/tmp/prompt.md');
|
|
56
|
+
const config = JSON.parse(args[args.indexOf('--mcp-config') + 1] ?? '{}');
|
|
57
|
+
expect(Object.keys(config.mcpServers)).toEqual([LEAD_RUNNER_MCP_SERVER]);
|
|
58
|
+
expect(args).toContain('--strict-mcp-config');
|
|
59
|
+
expect(config.mcpServers[LEAD_RUNNER_MCP_SERVER]).toEqual({
|
|
60
|
+
type: 'stdio',
|
|
61
|
+
command: 'cleo',
|
|
62
|
+
args: ['orchestrate', 'lead-runner'],
|
|
63
|
+
});
|
|
64
|
+
// Each variadic flag is followed by another flag, never the kickoff prompt.
|
|
65
|
+
for (const flag of ['--tools', '--disallowedTools', '--allowedTools', '--mcp-config']) {
|
|
66
|
+
expect(args[args.indexOf(flag) + 2]?.startsWith('--')).toBe(true);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('lead argv pins a pre-assigned session id, and ignores a malformed one (T14363)', () => {
|
|
71
|
+
const sessionId = '0b9a1c2d-3e4f-4a5b-8c6d-7e8f9a0b1c2d';
|
|
72
|
+
const pinned = buildClaudeArgs({ ...LEAD, options: { leadSessionId: sessionId } }, '/tmp/p.md');
|
|
73
|
+
expect(pinned[pinned.indexOf('--session-id') + 1]).toBe(sessionId);
|
|
74
|
+
const bad = buildClaudeArgs(
|
|
75
|
+
{ ...LEAD, options: { leadSessionId: 'x; rm -rf /' } },
|
|
76
|
+
'/tmp/p.md',
|
|
77
|
+
);
|
|
78
|
+
expect(bad).not.toContain('--session-id');
|
|
79
|
+
expect(buildClaudeArgs(LEAD, '/tmp/p.md')).not.toContain('--session-id');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('worker argv is unchanged', () => {
|
|
83
|
+
expect(buildClaudeArgs(WORKER, '/tmp/prompt.md')).toEqual([
|
|
84
|
+
'--print',
|
|
85
|
+
'--dangerously-skip-permissions',
|
|
86
|
+
'--output-format',
|
|
87
|
+
'json',
|
|
88
|
+
'/tmp/prompt.md',
|
|
89
|
+
]);
|
|
90
|
+
expect(buildClaudeArgs({ ...WORKER, leadDeniedTools: [] }, '/tmp/p.md')).toContain(
|
|
91
|
+
'--dangerously-skip-permissions',
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('providers without strip support', () => {
|
|
97
|
+
const unsupported: ReadonlyArray<[string, AdapterSpawnProvider]> = [
|
|
98
|
+
['codex', new CodexSpawnProvider()],
|
|
99
|
+
['gemini-cli', new GeminiCliSpawnProvider()],
|
|
100
|
+
['kimi', new KimiSpawnProvider()],
|
|
101
|
+
['openai-sdk', new OpenAiSdkSpawnProvider()],
|
|
102
|
+
['opencode', new OpenCodeSpawnProvider()],
|
|
103
|
+
['pi', new PiSpawnProvider()],
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
it.each(unsupported)('%s: a lead spawn throws E_LEAD_TOOLS_UNSTRIPPED', async (_id, provider) => {
|
|
107
|
+
expect(provider.leadToolStrip).toBe('unsupported');
|
|
108
|
+
await expect(provider.spawn(LEAD)).rejects.toMatchObject({ code: E_LEAD_TOOLS_UNSTRIPPED });
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('assertLeadToolsStrippable', () => {
|
|
113
|
+
it('refuses a lead spawn when unsupported', () => {
|
|
114
|
+
expect(() => assertLeadToolsStrippable('x', 'unsupported', LEAD)).toThrow(
|
|
115
|
+
LeadToolsUnstrippedError,
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('passes a lead spawn when enforced, and every worker spawn', () => {
|
|
120
|
+
expect(() => assertLeadToolsStrippable('x', 'enforced', LEAD)).not.toThrow();
|
|
121
|
+
expect(() => assertLeadToolsStrippable('x', 'unsupported', WORKER)).not.toThrow();
|
|
122
|
+
expect(() =>
|
|
123
|
+
assertLeadToolsStrippable('x', 'unsupported', { ...WORKER, leadDeniedTools: [] }),
|
|
124
|
+
).not.toThrow();
|
|
125
|
+
});
|
|
126
|
+
});
|