@cleocode/adapters 2026.4.47 → 2026.4.48
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19562 -372
- package/dist/index.js.map +4 -4
- package/dist/providers/claude-code/adapter.d.ts +12 -6
- package/dist/providers/claude-code/adapter.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.d.ts +18 -0
- package/dist/providers/claude-sdk/index.d.ts.map +1 -0
- package/dist/providers/claude-sdk/mcp-registry.d.ts +40 -0
- package/dist/providers/claude-sdk/mcp-registry.d.ts.map +1 -0
- package/dist/providers/claude-sdk/session-store.d.ts +78 -0
- package/dist/providers/claude-sdk/session-store.d.ts.map +1 -0
- package/dist/providers/claude-sdk/spawn.d.ts +79 -0
- package/dist/providers/claude-sdk/spawn.d.ts.map +1 -0
- package/dist/providers/claude-sdk/tool-bridge.d.ts +38 -0
- package/dist/providers/claude-sdk/tool-bridge.d.ts.map +1 -0
- package/dist/providers/openai-sdk/adapter.d.ts +77 -0
- package/dist/providers/openai-sdk/adapter.d.ts.map +1 -0
- package/dist/providers/openai-sdk/guardrails.d.ts +67 -0
- package/dist/providers/openai-sdk/guardrails.d.ts.map +1 -0
- package/dist/providers/openai-sdk/handoff.d.ts +94 -0
- package/dist/providers/openai-sdk/handoff.d.ts.map +1 -0
- package/dist/providers/openai-sdk/index.d.ts +39 -0
- package/dist/providers/openai-sdk/index.d.ts.map +1 -0
- package/dist/providers/openai-sdk/install.d.ts +61 -0
- package/dist/providers/openai-sdk/install.d.ts.map +1 -0
- package/dist/providers/openai-sdk/spawn.d.ts +146 -0
- package/dist/providers/openai-sdk/spawn.d.ts.map +1 -0
- package/dist/providers/openai-sdk/tracing.d.ts +89 -0
- package/dist/providers/openai-sdk/tracing.d.ts.map +1 -0
- package/dist/providers/shared/conduit-trace-writer.d.ts +72 -0
- package/dist/providers/shared/conduit-trace-writer.d.ts.map +1 -0
- package/dist/providers/shared/sdk-result-mapper.d.ts +51 -0
- package/dist/providers/shared/sdk-result-mapper.d.ts.map +1 -0
- package/package.json +5 -3
- package/src/index.ts +8 -0
- package/src/providers/claude-code/adapter.ts +41 -4
- package/src/providers/claude-sdk/__tests__/spawn.test.ts +448 -0
- package/src/providers/claude-sdk/index.ts +18 -0
- package/src/providers/claude-sdk/mcp-registry.ts +96 -0
- package/src/providers/claude-sdk/session-store.ts +103 -0
- package/src/providers/claude-sdk/spawn.ts +242 -0
- package/src/providers/claude-sdk/tool-bridge.ts +51 -0
- package/src/providers/openai-sdk/__tests__/openai-sdk-spawn.test.ts +716 -0
- package/src/providers/openai-sdk/adapter.ts +138 -0
- package/src/providers/openai-sdk/guardrails.ts +158 -0
- package/src/providers/openai-sdk/handoff.ts +187 -0
- package/src/providers/openai-sdk/index.ts +55 -0
- package/src/providers/openai-sdk/install.ts +135 -0
- package/src/providers/openai-sdk/manifest.json +45 -0
- package/src/providers/openai-sdk/spawn.ts +300 -0
- package/src/providers/openai-sdk/tracing.ts +175 -0
- package/src/providers/shared/conduit-trace-writer.ts +101 -0
- package/src/providers/shared/sdk-result-mapper.ts +83 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI SDK Install Provider.
|
|
3
|
+
*
|
|
4
|
+
* Handles CLEO installation into OpenAI SDK environments:
|
|
5
|
+
* - Writes an AGENTS.md file with CLEO @-references
|
|
6
|
+
* - Creates a `.openai/` config stub if it does not exist
|
|
7
|
+
*
|
|
8
|
+
* @task T582
|
|
9
|
+
*/
|
|
10
|
+
import type { AdapterInstallProvider, InstallOptions, InstallResult } from '@cleocode/contracts';
|
|
11
|
+
/**
|
|
12
|
+
* Install provider for the OpenAI Agents SDK.
|
|
13
|
+
*
|
|
14
|
+
* Manages CLEO's integration with OpenAI SDK projects by:
|
|
15
|
+
* 1. Ensuring AGENTS.md contains @-references to CLEO instruction files
|
|
16
|
+
* 2. Creating the `.openai/` config directory stub if absent
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Installation is idempotent — running install multiple times on the same
|
|
20
|
+
* project produces the same result.
|
|
21
|
+
*/
|
|
22
|
+
export declare class OpenAiSdkInstallProvider implements AdapterInstallProvider {
|
|
23
|
+
/**
|
|
24
|
+
* Install CLEO into an OpenAI SDK project.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Installation options including project directory.
|
|
27
|
+
* @returns Result describing what was installed.
|
|
28
|
+
*/
|
|
29
|
+
install(options: InstallOptions): Promise<InstallResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Uninstall CLEO from the current OpenAI SDK project.
|
|
32
|
+
*
|
|
33
|
+
* Does not remove AGENTS.md references (they are harmless if CLEO is absent).
|
|
34
|
+
*/
|
|
35
|
+
uninstall(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Check whether CLEO is installed in the current OpenAI SDK environment.
|
|
38
|
+
*
|
|
39
|
+
* Checks for `@~/.cleo/templates/CLEO-INJECTION.md` in AGENTS.md.
|
|
40
|
+
*/
|
|
41
|
+
isInstalled(): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Ensure AGENTS.md contains @-references to CLEO instruction files.
|
|
44
|
+
*
|
|
45
|
+
* @param projectDir - Project root directory.
|
|
46
|
+
*/
|
|
47
|
+
ensureInstructionReferences(projectDir: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Update AGENTS.md with CLEO @-references.
|
|
50
|
+
*
|
|
51
|
+
* @returns `true` if the file was created or modified.
|
|
52
|
+
*/
|
|
53
|
+
private updateInstructionFile;
|
|
54
|
+
/**
|
|
55
|
+
* Create the `.openai/` config directory if it does not exist.
|
|
56
|
+
*
|
|
57
|
+
* @returns `true` if the directory was created.
|
|
58
|
+
*/
|
|
59
|
+
private ensureConfigDir;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-sdk/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKjG;;;;;;;;;;GAUG;AACH,qBAAa,wBAAyB,YAAW,sBAAsB;IACrE;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAyB9D;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAEhC;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAMrC;;;;OAIG;IACG,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpE;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IA0B7B;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAOxB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Agents SDK spawn provider.
|
|
3
|
+
*
|
|
4
|
+
* Implements `AdapterSpawnProvider` using the `@openai/agents` SDK runner.
|
|
5
|
+
* Unlike the Claude Code provider (detached fire-and-forget), this provider
|
|
6
|
+
* awaits the run and returns `status: 'completed'` or `status: 'failed'`
|
|
7
|
+
* so the orchestrator receives rich output immediately.
|
|
8
|
+
*
|
|
9
|
+
* Key features:
|
|
10
|
+
* - Tier-based model selection (lead → gpt-4.1, worker → gpt-4.1-mini)
|
|
11
|
+
* - Handoff topology built from `SpawnContext.options.handoffs`
|
|
12
|
+
* - CLEO path ACL guardrails applied at input stage
|
|
13
|
+
* - Default-on tracing via `CleoConduitTraceProcessor`
|
|
14
|
+
* - CANT prompt enrichment (best-effort, same as Claude Code provider)
|
|
15
|
+
*
|
|
16
|
+
* @task T582
|
|
17
|
+
*/
|
|
18
|
+
import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/contracts';
|
|
19
|
+
/**
|
|
20
|
+
* OpenAI SDK-specific spawn options carried in `SpawnContext.options`.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* All fields are optional. Unknown fields are ignored.
|
|
24
|
+
*/
|
|
25
|
+
export interface OpenAiSdkSpawnOptions {
|
|
26
|
+
/**
|
|
27
|
+
* OpenAI model to use.
|
|
28
|
+
*
|
|
29
|
+
* @defaultValue Derived from `tier`:
|
|
30
|
+
* - `'lead'` / `'orchestrator'` → `'gpt-4.1'`
|
|
31
|
+
* - `'worker'` → `'gpt-4.1-mini'`
|
|
32
|
+
*/
|
|
33
|
+
model?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Agent archetype tier. Controls model selection and topology shape.
|
|
36
|
+
*
|
|
37
|
+
* @defaultValue `'worker'`
|
|
38
|
+
*/
|
|
39
|
+
tier?: 'lead' | 'worker' | 'orchestrator';
|
|
40
|
+
/**
|
|
41
|
+
* Worker archetype names this agent may hand off to.
|
|
42
|
+
* References keys in `WORKER_ARCHETYPES` from `handoff.ts`.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue `[]`
|
|
45
|
+
*/
|
|
46
|
+
handoffs?: string[];
|
|
47
|
+
/**
|
|
48
|
+
* File-path glob ACL allowlist. Paths outside this list trip the path guardrail.
|
|
49
|
+
*
|
|
50
|
+
* @defaultValue `[]` (all paths allowed)
|
|
51
|
+
*/
|
|
52
|
+
allowedGlobs?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Tool name allowlist. Tools not in this list are documented but not enforced
|
|
55
|
+
* (enforcement is structural via the `tools` array on the Agent).
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue `[]` (all tools allowed)
|
|
58
|
+
*/
|
|
59
|
+
allowedTools?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Disable tracing to conduit.db.
|
|
62
|
+
*
|
|
63
|
+
* @defaultValue `false`
|
|
64
|
+
*/
|
|
65
|
+
tracingDisabled?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Agent display name used as the CANT persona.
|
|
68
|
+
*/
|
|
69
|
+
agentName?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Spawn provider for the OpenAI Agents SDK.
|
|
73
|
+
*
|
|
74
|
+
* Spawns SDK-backed agent runs for a given `SpawnContext`. The run is
|
|
75
|
+
* awaited synchronously and the result mapped to a `SpawnResult` with
|
|
76
|
+
* `status: 'completed'` or `status: 'failed'`. In-flight runs are tracked
|
|
77
|
+
* by instance ID so `listRunning()` and `terminate()` work correctly.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The provider creates a fresh `Runner` per spawn so that `RunConfig`
|
|
81
|
+
* settings do not bleed across parallel spawns. Trace processors are
|
|
82
|
+
* registered globally via `addTraceProcessor` and removed by disabling
|
|
83
|
+
* tracing when the option is set.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const provider = new OpenAiSdkSpawnProvider();
|
|
88
|
+
* const result = await provider.spawn({
|
|
89
|
+
* taskId: 'T582',
|
|
90
|
+
* prompt: 'Implement feature X',
|
|
91
|
+
* options: { tier: 'lead', handoffs: ['worker-read', 'worker-write'] },
|
|
92
|
+
* });
|
|
93
|
+
* console.log(result.status); // 'completed'
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare class OpenAiSdkSpawnProvider implements AdapterSpawnProvider {
|
|
97
|
+
/** Currently running instance IDs (completed runs are removed). */
|
|
98
|
+
private readonly runningInstances;
|
|
99
|
+
/**
|
|
100
|
+
* Check whether the OpenAI SDK can spawn in the current environment.
|
|
101
|
+
*
|
|
102
|
+
* Requires `OPENAI_API_KEY` to be set. Does not make a network call.
|
|
103
|
+
*
|
|
104
|
+
* @returns `true` when `OPENAI_API_KEY` is present in the environment.
|
|
105
|
+
*/
|
|
106
|
+
canSpawn(): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* Spawn a subagent via the OpenAI Agents SDK runner.
|
|
109
|
+
*
|
|
110
|
+
* Awaits the run to completion and returns a fully-resolved `SpawnResult`.
|
|
111
|
+
*
|
|
112
|
+
* @param context - Spawn context with task ID, prompt, and options.
|
|
113
|
+
* @returns Resolved spawn result with `status: 'completed'` or `'failed'`.
|
|
114
|
+
*/
|
|
115
|
+
spawn(context: SpawnContext): Promise<SpawnResult>;
|
|
116
|
+
/**
|
|
117
|
+
* List currently running OpenAI SDK agent instances.
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of in-progress spawn results.
|
|
120
|
+
*/
|
|
121
|
+
listRunning(): Promise<SpawnResult[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Terminate a running spawn by instance ID.
|
|
124
|
+
*
|
|
125
|
+
* The OpenAI SDK runner does not support external termination of in-flight
|
|
126
|
+
* runs; this method removes the instance from the tracking set so it will
|
|
127
|
+
* no longer appear in `listRunning()`.
|
|
128
|
+
*
|
|
129
|
+
* @param instanceId - ID of the spawn instance to terminate.
|
|
130
|
+
*/
|
|
131
|
+
terminate(instanceId: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Parse and validate `SpawnContext.options` into typed `OpenAiSdkSpawnOptions`.
|
|
134
|
+
*
|
|
135
|
+
* Unknown fields are silently ignored.
|
|
136
|
+
*/
|
|
137
|
+
private parseOptions;
|
|
138
|
+
/**
|
|
139
|
+
* Derive the default model for a given tier.
|
|
140
|
+
*
|
|
141
|
+
* @param tier - Agent tier.
|
|
142
|
+
* @returns Model identifier string.
|
|
143
|
+
*/
|
|
144
|
+
private modelForTier;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-sdk/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAY3F;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,cAAc,CAAC;IAE1C;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,sBAAuB,YAAW,oBAAoB;IACjE,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;IAEtD;;;;;;OAMG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAIlC;;;;;;;OAOG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAiFxD;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAU3C;;;;;;;;OAQG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlD;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAwBpB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAGrB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Agents SDK trace processor that writes spans to conduit.db.
|
|
3
|
+
*
|
|
4
|
+
* `CleoConduitTraceProcessor` implements the SDK `TracingProcessor` interface.
|
|
5
|
+
* On every span end it serialises the span and writes a structured event to
|
|
6
|
+
* conduit.db via the shared `conduit-trace-writer` transport layer.
|
|
7
|
+
*
|
|
8
|
+
* Tracing is on by default for all OpenAI SDK spawns. Set
|
|
9
|
+
* `options.tracingDisabled = true` in `SpawnContext.options` to opt out when
|
|
10
|
+
* conduit is unavailable.
|
|
11
|
+
*
|
|
12
|
+
* @task T582
|
|
13
|
+
*/
|
|
14
|
+
import type { Span, SpanData, Trace, TracingProcessor } from '@openai/agents';
|
|
15
|
+
/**
|
|
16
|
+
* CLEO trace processor that persists OpenAI Agents SDK spans to conduit.db.
|
|
17
|
+
*
|
|
18
|
+
* Implements the `TracingProcessor` interface from `@openai/agents-core`.
|
|
19
|
+
* Each `onSpanEnd` call extracts span metadata and enqueues a write to
|
|
20
|
+
* conduit via the shared `conduit-trace-writer` module. Writes are
|
|
21
|
+
* fire-and-forget — failures are logged but never propagated to the caller.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* `onTraceEnd` performs a batch flush of any buffered spans. Individual
|
|
25
|
+
* `onSpanEnd` calls also write immediately so spans are not lost if the run
|
|
26
|
+
* is interrupted.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { addTraceProcessor } from '@openai/agents';
|
|
31
|
+
* import { CleoConduitTraceProcessor } from './tracing.js';
|
|
32
|
+
*
|
|
33
|
+
* const processor = new CleoConduitTraceProcessor('T582');
|
|
34
|
+
* addTraceProcessor(processor);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class CleoConduitTraceProcessor implements TracingProcessor {
|
|
38
|
+
/** CLEO task ID included in every span event for correlation. */
|
|
39
|
+
private readonly taskId;
|
|
40
|
+
/** Pending span events buffered within the current trace. */
|
|
41
|
+
private pendingEvents;
|
|
42
|
+
/**
|
|
43
|
+
* @param taskId - CLEO task ID to attach to every written span.
|
|
44
|
+
*/
|
|
45
|
+
constructor(taskId: string);
|
|
46
|
+
/**
|
|
47
|
+
* Called when a new trace starts. Resets the pending event buffer.
|
|
48
|
+
*
|
|
49
|
+
* @param _trace - The trace that just started (unused).
|
|
50
|
+
*/
|
|
51
|
+
onTraceStart(_trace: Trace): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Called when a trace ends. Flushes all pending span events to conduit.
|
|
54
|
+
*
|
|
55
|
+
* @param _trace - The trace that just ended (unused — spans were captured via `onSpanEnd`).
|
|
56
|
+
*/
|
|
57
|
+
onTraceEnd(_trace: Trace): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Called when a new span starts. No-op — we capture on end to have full timing.
|
|
60
|
+
*
|
|
61
|
+
* @param _span - The span that just started (unused).
|
|
62
|
+
*/
|
|
63
|
+
onSpanStart(_span: Span<SpanData>): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Called when a span ends. Serialises and writes the span to conduit.
|
|
66
|
+
*
|
|
67
|
+
* @param span - The completed span from the SDK.
|
|
68
|
+
*/
|
|
69
|
+
onSpanEnd(span: Span<SpanData>): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Called during graceful shutdown. Flushes any remaining pending events.
|
|
72
|
+
*
|
|
73
|
+
* @param _timeout - Shutdown timeout in milliseconds (unused).
|
|
74
|
+
*/
|
|
75
|
+
shutdown(_timeout?: number): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Force-flush all pending span events to conduit immediately.
|
|
78
|
+
*/
|
|
79
|
+
forceFlush(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Extract a {@link ConduitSpanEvent} from an SDK span, or `null` if the
|
|
82
|
+
* span cannot be meaningfully serialised.
|
|
83
|
+
*
|
|
84
|
+
* @param span - The SDK span to serialise.
|
|
85
|
+
* @returns A conduit span event or `null`.
|
|
86
|
+
*/
|
|
87
|
+
private extractSpanEvent;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-sdk/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAQ9E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,yBAA0B,YAAW,gBAAgB;IAChE,iEAAiE;IACjE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,6DAA6D;IAC7D,OAAO,CAAC,aAAa,CAA0B;IAE/C;;OAEG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;OAIG;IACG,YAAY,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9C;;;;OAIG;IACG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD;;;;OAIG;IACG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IASpD;;;;OAIG;IACG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOhD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAWjC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;CAuCzB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared conduit trace writer for SDK-backed providers.
|
|
3
|
+
*
|
|
4
|
+
* Writes structured span events to conduit.db via the CLEO transport layer.
|
|
5
|
+
* Both T581 (Claude SDK) and T582 (OpenAI SDK) use this module so the
|
|
6
|
+
* conduit write path stays DRY.
|
|
7
|
+
*
|
|
8
|
+
* The writer is fire-and-forget: if conduit is unavailable, write failures are
|
|
9
|
+
* silently swallowed so that missing tracing never breaks agent execution.
|
|
10
|
+
*
|
|
11
|
+
* @task T582
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* A single normalised span event written to conduit.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This shape is intentionally minimal — only fields that both SDK providers
|
|
18
|
+
* can populate consistently are required. Provider-specific fields go into
|
|
19
|
+
* the `metadata` bag.
|
|
20
|
+
*/
|
|
21
|
+
export interface ConduitSpanEvent {
|
|
22
|
+
/** Unique identifier for this span (from the SDK). */
|
|
23
|
+
spanId: string;
|
|
24
|
+
/** The task ID this span belongs to. */
|
|
25
|
+
taskId: string;
|
|
26
|
+
/** The name of the agent that produced this span. */
|
|
27
|
+
agentName: string;
|
|
28
|
+
/** Type of span: `'agent'`, `'function'`, `'handoff'`, `'generation'`, etc. */
|
|
29
|
+
spanType: string;
|
|
30
|
+
/** ISO timestamp when the span started. */
|
|
31
|
+
startTime: string;
|
|
32
|
+
/** ISO timestamp when the span ended. */
|
|
33
|
+
endTime: string;
|
|
34
|
+
/** Optional tool name for function/tool spans. */
|
|
35
|
+
toolName?: string;
|
|
36
|
+
/** Optional handoff target agent name. */
|
|
37
|
+
handoffTarget?: string;
|
|
38
|
+
/** Extra provider-specific metadata. */
|
|
39
|
+
metadata?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
/** Conduit write result — only used internally for error handling. */
|
|
42
|
+
interface WriteResult {
|
|
43
|
+
written: boolean;
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Write a single span event to conduit via `cleo` CLI transport.
|
|
48
|
+
*
|
|
49
|
+
* Falls back gracefully when conduit is unavailable. All errors are caught
|
|
50
|
+
* and returned in the result rather than thrown.
|
|
51
|
+
*
|
|
52
|
+
* @param event - The span event to persist.
|
|
53
|
+
* @returns Result indicating whether the write succeeded.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* The current implementation writes to conduit using the `cleo conduit send`
|
|
57
|
+
* CLI command. This keeps the trace writer free of direct DB dependencies and
|
|
58
|
+
* consistent with the no-direct-SQLite rule (ADR).
|
|
59
|
+
*
|
|
60
|
+
* When conduit grows a native TS API this writer can be updated without
|
|
61
|
+
* changing caller code.
|
|
62
|
+
*/
|
|
63
|
+
export declare function writeSpanToConduit(event: ConduitSpanEvent): Promise<WriteResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Write multiple span events to conduit, swallowing individual write failures.
|
|
66
|
+
*
|
|
67
|
+
* @param events - Array of span events to persist.
|
|
68
|
+
* @returns Number of events successfully written.
|
|
69
|
+
*/
|
|
70
|
+
export declare function writeSpanBatchToConduit(events: ConduitSpanEvent[]): Promise<number>;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=conduit-trace-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conduit-trace-writer.d.ts","sourceRoot":"","sources":["../../../src/providers/shared/conduit-trace-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,sEAAsE;AACtE,UAAU,WAAW;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CAoBtF;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAOzF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared SDK result mapper for CLEO spawn providers.
|
|
3
|
+
*
|
|
4
|
+
* Normalises provider-specific run results (OpenAI Agents SDK, Claude Agent SDK)
|
|
5
|
+
* into the canonical {@link SpawnResult} contract used by CLEO orchestration.
|
|
6
|
+
*
|
|
7
|
+
* Both T581 (Claude SDK) and T582 (OpenAI SDK) import from this module so the
|
|
8
|
+
* mapping logic stays DRY.
|
|
9
|
+
*
|
|
10
|
+
* @task T582
|
|
11
|
+
*/
|
|
12
|
+
import type { SpawnResult } from '@cleocode/contracts';
|
|
13
|
+
/**
|
|
14
|
+
* Raw run outcome from any SDK provider, normalised before mapping.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Both `@anthropic-ai/claude-agent-sdk` and `@openai/agents` surface a
|
|
18
|
+
* `finalOutput` string plus an optional error. This interface captures the
|
|
19
|
+
* minimal shared shape so the mapper stays provider-agnostic.
|
|
20
|
+
*/
|
|
21
|
+
export interface RawSdkRunOutcome {
|
|
22
|
+
/** Final text produced by the agent run. Empty string when the run failed. */
|
|
23
|
+
finalOutput: string;
|
|
24
|
+
/** True when the run completed without error. */
|
|
25
|
+
succeeded: boolean;
|
|
26
|
+
/** Human-readable error message when `succeeded` is false. */
|
|
27
|
+
errorMessage?: string;
|
|
28
|
+
/** Exit / stop reason surfaced by the SDK (optional). */
|
|
29
|
+
stopReason?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Map a raw SDK run outcome to the canonical CLEO {@link SpawnResult}.
|
|
33
|
+
*
|
|
34
|
+
* @param instanceId - Unique identifier for this spawn instance.
|
|
35
|
+
* @param taskId - CLEO task ID associated with the run.
|
|
36
|
+
* @param providerId - Identifier of the provider that performed the run (e.g. `'openai-sdk'`).
|
|
37
|
+
* @param startTime - ISO timestamp captured just before the run was started.
|
|
38
|
+
* @param outcome - Normalised run outcome from the SDK provider.
|
|
39
|
+
* @returns A fully-populated {@link SpawnResult} ready for return from `spawn()`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const result = mapSdkRunOutcome('openai-sdk-123', 'T582', 'openai-sdk', start, {
|
|
44
|
+
* finalOutput: 'Done',
|
|
45
|
+
* succeeded: true,
|
|
46
|
+
* });
|
|
47
|
+
* // result.status === 'completed'
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function mapSdkRunOutcome(instanceId: string, taskId: string, providerId: string, startTime: string, outcome: RawSdkRunOutcome): SpawnResult;
|
|
51
|
+
//# sourceMappingURL=sdk-result-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-result-mapper.d.ts","sourceRoot":"","sources":["../../../src/providers/shared/sdk-result-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,SAAS,EAAE,OAAO,CAAC;IACnB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,gBAAgB,GACxB,WAAW,CAwBb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/adapters",
|
|
3
|
-
"version": "2026.4.
|
|
3
|
+
"version": "2026.4.48",
|
|
4
4
|
"description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"@
|
|
15
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.108",
|
|
16
|
+
"@openai/agents": "0.8.3",
|
|
17
|
+
"@cleocode/caamp": "2026.4.48",
|
|
18
|
+
"@cleocode/contracts": "2026.4.48"
|
|
17
19
|
},
|
|
18
20
|
"license": "MIT",
|
|
19
21
|
"engines": {
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,14 @@ export {
|
|
|
31
31
|
getSetupInstructions,
|
|
32
32
|
getStatuslineConfig,
|
|
33
33
|
} from './providers/claude-code/index.js';
|
|
34
|
+
export type { McpServerMap, McpStdioConfig, SessionEntry } from './providers/claude-sdk/index.js';
|
|
35
|
+
export {
|
|
36
|
+
ClaudeSDKSpawnProvider,
|
|
37
|
+
DEFAULT_TOOLS,
|
|
38
|
+
getServers,
|
|
39
|
+
resolveTools,
|
|
40
|
+
SessionStore,
|
|
41
|
+
} from './providers/claude-sdk/index.js';
|
|
34
42
|
export {
|
|
35
43
|
CodexAdapter,
|
|
36
44
|
CodexHookProvider,
|
|
@@ -15,8 +15,10 @@ import { promisify } from 'node:util';
|
|
|
15
15
|
import type {
|
|
16
16
|
AdapterCapabilities,
|
|
17
17
|
AdapterHealthStatus,
|
|
18
|
+
AdapterSpawnProvider,
|
|
18
19
|
CLEOProviderAdapter,
|
|
19
20
|
} from '@cleocode/contracts';
|
|
21
|
+
import { ClaudeSDKSpawnProvider } from '../claude-sdk/spawn.js';
|
|
20
22
|
import { ClaudeCodeContextMonitorProvider } from './context-monitor.js';
|
|
21
23
|
import { ClaudeCodeHookProvider } from './hooks.js';
|
|
22
24
|
import { ClaudeCodeInstallProvider } from './install.js';
|
|
@@ -84,8 +86,14 @@ export class ClaudeCodeAdapter implements CLEOProviderAdapter {
|
|
|
84
86
|
|
|
85
87
|
/** Hook provider for CAAMP event mapping and registration. */
|
|
86
88
|
hooks: ClaudeCodeHookProvider;
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Spawn provider for launching subagent processes.
|
|
91
|
+
*
|
|
92
|
+
* Defaults to `ClaudeCodeSpawnProvider` (CLI mode). When
|
|
93
|
+
* `provider.claude.mode === 'sdk'` is set in CLEO config, the adapter
|
|
94
|
+
* swaps this for `ClaudeSDKSpawnProvider` at initialization time.
|
|
95
|
+
*/
|
|
96
|
+
spawn: AdapterSpawnProvider;
|
|
89
97
|
/** Install provider for managing instruction files and plugin registration. */
|
|
90
98
|
install: ClaudeCodeInstallProvider;
|
|
91
99
|
/** Path provider for resolving Claude Code directory locations. */
|
|
@@ -115,8 +123,9 @@ export class ClaudeCodeAdapter implements CLEOProviderAdapter {
|
|
|
115
123
|
/**
|
|
116
124
|
* Initialize the adapter for a given project directory.
|
|
117
125
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
126
|
+
* Reads the CLEO config to determine the spawn mode and swaps the spawn
|
|
127
|
+
* provider to `ClaudeSDKSpawnProvider` when `provider.claude.mode === 'sdk'`.
|
|
128
|
+
* Defaults to `ClaudeCodeSpawnProvider` (CLI) for backwards compatibility.
|
|
120
129
|
*
|
|
121
130
|
* @param projectDir - Root directory of the project
|
|
122
131
|
*/
|
|
@@ -124,6 +133,34 @@ export class ClaudeCodeAdapter implements CLEOProviderAdapter {
|
|
|
124
133
|
this.projectDir = projectDir;
|
|
125
134
|
this.initialized = true;
|
|
126
135
|
|
|
136
|
+
// Determine spawn mode from CLEO config. Best-effort: any error falls
|
|
137
|
+
// back to the default CLI provider.
|
|
138
|
+
try {
|
|
139
|
+
const { execFile } = await import('node:child_process');
|
|
140
|
+
const { promisify: pfy } = await import('node:util');
|
|
141
|
+
const execFileAsync = pfy(execFile);
|
|
142
|
+
const { stdout } = await execFileAsync('cleo', [
|
|
143
|
+
'config',
|
|
144
|
+
'get',
|
|
145
|
+
'provider.claude.mode',
|
|
146
|
+
'--output',
|
|
147
|
+
'json',
|
|
148
|
+
]);
|
|
149
|
+
const parsed: unknown = JSON.parse(stdout.trim());
|
|
150
|
+
const mode =
|
|
151
|
+
parsed !== null &&
|
|
152
|
+
typeof parsed === 'object' &&
|
|
153
|
+
'data' in parsed &&
|
|
154
|
+
typeof (parsed as Record<string, unknown>).data === 'string'
|
|
155
|
+
? (parsed as Record<string, string>).data
|
|
156
|
+
: undefined;
|
|
157
|
+
if (mode === 'sdk') {
|
|
158
|
+
this.spawn = new ClaudeSDKSpawnProvider();
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
// Config unavailable or mode is default 'cli' — keep CLI provider
|
|
162
|
+
}
|
|
163
|
+
|
|
127
164
|
// Activate CLEO hook bridge for this project — connects Claude Code
|
|
128
165
|
// native events to CLEO's internal hook dispatch (T555).
|
|
129
166
|
await this.hooks.registerNativeHooks(projectDir);
|