@cleocode/adapters 2026.11.11 → 2026.11.12-rc.ci.729
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 +73 -458
- package/dist/.source-stamp.json +1 -1
- package/package.json +6 -6
- package/src/providers/README.md +31 -29
package/README.md
CHANGED
|
@@ -2,510 +2,125 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [CLEO](https://github.com/kryptobaseddev/cleo#readme). Start with the root README; run `cleo <command> --help` for any command.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Provider adapters for CLEO: the install, hook and instruction-injection code for each AI coding harness, plus the spawn providers behind `cleo orchestrate spawn-execute`.
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
CLEO is a harness-agnostic core (ADR-098): the harness (Claude Code, Codex, OpenCode, Cursor, Gemini CLI, Kimi) launches the agent, and CLEO installs its instructions and hooks into that harness. Each provider directory under `src/providers/` exports an adapter class implementing `CLEOProviderAdapter` from `@cleocode/contracts`, plus the hook, install and (where present) spawn providers it is built from.
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Providers
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|----------|--------|----------|
|
|
15
|
-
| **Claude Code** | ✅ Production | Full integration with statusline sync, context monitoring, PreCompact hook |
|
|
16
|
-
| **OpenCode** | ✅ Production | Spawn hooks, task synchronization, PreCompact plugin |
|
|
17
|
-
| **Cursor** | ✅ Production | Basic adapter with install hooks, PreCompact hook |
|
|
18
|
-
| **Codex** | Adapter | `AGENTS.md` instruction references; heavy-command `PreToolUse` hook in `.codex/hooks.json` |
|
|
19
|
-
| **Gemini CLI** | Adapter | `GEMINI.md` instruction references; a PreCompact shim ships but is not wired yet |
|
|
20
|
-
| **Kimi** | Adapter | `AGENTS.md` instruction references |
|
|
21
|
-
| **claude-sdk**, **openai-sdk** | SDK spawn | Programmatic subagent execution behind `cleo orchestrate spawn-execute` (Vercel AI SDK); whether to keep them is an open owner call in ADR-098 |
|
|
22
|
-
| **Pi** | Deprecated | Retiring with the Pi/CleoOS harness (ADR-098); removed after a release ships the freeze |
|
|
13
|
+
Capabilities below are the flags each adapter class declares in its `adapter.ts`.
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
| Provider | Install writes | Hooks | Spawn |
|
|
16
|
+
|----------|----------------|-------|-------|
|
|
17
|
+
| **claude-code** | `CLAUDE.md` references; PreCompact shim and heavy-command `PreToolUse` hook in the project's `.claude/` | Yes; also context monitor, statusline, provider paths, TodoWrite task sync | Starts the `claude` CLI as a child process. Lead spawns are supported (`leadToolStrip: 'enforced'`) |
|
|
18
|
+
| **opencode** | `AGENTS.md` references; PreCompact shim + `.opencode/plugins/cleo-precompact.js`; heavy-command plugin `.opencode/plugins/cleo-heavy-command.js` | Yes | Starts the `opencode` CLI as a child process |
|
|
19
|
+
| **cursor** | `AGENTS.md`, `.cursor/rules/cleo.mdc` and legacy `.cursorrules`; PreCompact shim wired into `.cursor/hooks.json` | Declared `true` in `adapter.ts`, `false` in `manifest.json` | None: `spawn()` throws |
|
|
20
|
+
| **codex** | `AGENTS.md` references; heavy-command `PreToolUse` hook in `.codex/hooks.json` | Yes (`SessionStart`, `UserPromptSubmit`, `Stop`) | Declared unsupported (see note) |
|
|
21
|
+
| **gemini-cli** | `GEMINI.md` references. A PreCompact shim ships, but the install path does not wire it yet | Yes | Declared unsupported (see note) |
|
|
22
|
+
| **kimi** | `AGENTS.md` references | No | Declared unsupported (see note) |
|
|
23
|
+
| **claude-sdk** | Nothing (no-op install) | No | Programmatic Claude run through the Vercel AI SDK; lead spawns supported (`leadToolStrip: 'enforced'`). The claude-code adapter switches to it when `provider.claude.mode` is `sdk` |
|
|
24
|
+
| **openai-sdk** | `AGENTS.md` references and a `.openai/` stub | No | Programmatic run through the Vercel AI SDK; needs `OPENAI_API_KEY` |
|
|
25
|
+
| **pi** | Frozen | Frozen | Frozen. ADR-098 retires the Pi/CleoOS harness: the `pi/` directory is still in the source and still registered, and is deleted after a release ships the freeze |
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
ADR-098 leaves one open owner call: whether to keep, freeze or delete the two SDK spawn adapters (`claude-sdk`, `openai-sdk`).
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
npm install @cleocode/adapters
|
|
30
|
-
```
|
|
29
|
+
**Spawn note.** `cleo orchestrate spawn-execute` registers a provider's spawn provider only when its `manifest.json` sets `supportsSpawn: true` (`packages/core/src/spawn/adapter-registry.ts`, `initializeSpawnAdapters`). Codex, Gemini CLI and Kimi ship a `spawn.ts` (`codex` and `gemini` start their CLIs; Kimi calls the Moonshot API), but their manifests declare `supportsSpawn: false`, so that path does not use them. A lead spawn on a provider whose spawn provider does not declare `leadToolStrip: 'enforced'` is refused with `E_LEAD_TOOLS_UNSTRIPPED` before anything runs (`src/providers/shared/lead-tool-strip.ts`).
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
Per-provider hook detail: [`src/providers/README.md`](src/providers/README.md).
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
35
34
|
|
|
36
35
|
```bash
|
|
37
|
-
|
|
36
|
+
pnpm add @cleocode/adapters
|
|
38
37
|
```
|
|
39
38
|
|
|
40
|
-
##
|
|
39
|
+
## Exports
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
| Subpath | Contents |
|
|
42
|
+
|---------|----------|
|
|
43
|
+
| `@cleocode/adapters` | Adapter classes and providers for claude-code, claude-sdk, codex, cursor, gemini-cli, kimi and opencode; `createClaudeCodeAdapter`, `createCodexAdapter`, `createCursorAdapter`, `createGeminiCliAdapter`, `createKimiAdapter`, `createOpenCodeAdapter`, `createClaudeSDKAdapter`; the CANT/NEXUS prompt-context builders; the PreCompact template installer; the heavy-command hook delivery API; `discoverProviders`, `getProviderManifests` |
|
|
44
|
+
| `@cleocode/adapters/manifests` | `getProviderManifests()` without loading provider code |
|
|
45
|
+
| `@cleocode/adapters/heavy-command-hook` | Project-level heavy-command hook delivery (T13124) |
|
|
46
|
+
| `@cleocode/adapters/project-hook-delivery`, `/project-hook-native` | Project-local delivery of shared checks and the provider payload adapters for them (T13344) |
|
|
47
|
+
| `@cleocode/adapters/orca-execution` | Local Orca execution |
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#### Claude Code Adapter
|
|
49
|
+
The SDK factories take no arguments. An adapter is bound to a project with `initialize(projectDir)`:
|
|
47
50
|
|
|
48
51
|
```typescript
|
|
49
|
-
import {
|
|
50
|
-
ClaudeCodeAdapter,
|
|
51
|
-
createClaudeCodeAdapter,
|
|
52
|
-
ClaudeCodeContextMonitorProvider,
|
|
53
|
-
ClaudeCodeHookProvider,
|
|
54
|
-
ClaudeCodeInstallProvider,
|
|
55
|
-
ClaudeCodePathProvider,
|
|
56
|
-
ClaudeCodeSpawnProvider,
|
|
57
|
-
ClaudeCodeTransportProvider,
|
|
58
|
-
checkStatuslineIntegration,
|
|
59
|
-
getSetupInstructions,
|
|
60
|
-
getStatuslineConfig
|
|
61
|
-
} from '@cleocode/adapters';
|
|
62
|
-
|
|
63
|
-
// Create adapter
|
|
64
|
-
const adapter = createClaudeCodeAdapter({
|
|
65
|
-
projectPath: './my-project'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Check statusline integration
|
|
69
|
-
const status = await checkStatuslineIntegration('./my-project');
|
|
70
|
-
|
|
71
|
-
// Get setup instructions
|
|
72
|
-
const instructions = getSetupInstructions();
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
#### OpenCode Adapter
|
|
52
|
+
import { createClaudeCodeAdapter, checkStatuslineIntegration } from '@cleocode/adapters';
|
|
76
53
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
createOpenCodeAdapter,
|
|
81
|
-
OpenCodeHookProvider,
|
|
82
|
-
OpenCodeInstallProvider,
|
|
83
|
-
OpenCodeSpawnProvider
|
|
84
|
-
} from '@cleocode/adapters';
|
|
85
|
-
|
|
86
|
-
// Create adapter
|
|
87
|
-
const adapter = createOpenCodeAdapter({
|
|
88
|
-
projectPath: './my-project'
|
|
89
|
-
});
|
|
90
|
-
```
|
|
54
|
+
const adapter = createClaudeCodeAdapter();
|
|
55
|
+
await adapter.initialize('/path/to/project'); // registers the project's native hooks
|
|
56
|
+
const health = await adapter.healthCheck(); // { healthy, provider, details? }
|
|
91
57
|
|
|
92
|
-
|
|
58
|
+
// 'configured' | 'not_configured' | 'custom_no_cleo' | 'no_settings'
|
|
59
|
+
const statusline = checkStatuslineIntegration();
|
|
93
60
|
|
|
94
|
-
|
|
95
|
-
import {
|
|
96
|
-
CursorAdapter,
|
|
97
|
-
createCursorAdapter,
|
|
98
|
-
CursorHookProvider,
|
|
99
|
-
CursorInstallProvider
|
|
100
|
-
} from '@cleocode/adapters';
|
|
101
|
-
|
|
102
|
-
// Create adapter
|
|
103
|
-
const adapter = createCursorAdapter({
|
|
104
|
-
projectPath: './my-project'
|
|
105
|
-
});
|
|
61
|
+
await adapter.dispose();
|
|
106
62
|
```
|
|
107
63
|
|
|
108
64
|
### Registry
|
|
109
65
|
|
|
110
|
-
Discover and manage provider manifests:
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import {
|
|
114
|
-
discoverProviders,
|
|
115
|
-
getProviderManifests,
|
|
116
|
-
type AdapterManifest
|
|
117
|
-
} from '@cleocode/adapters';
|
|
118
|
-
|
|
119
|
-
// Discover available providers
|
|
120
|
-
const providers = await discoverProviders('./my-project');
|
|
121
|
-
|
|
122
|
-
// Get all manifests
|
|
123
|
-
const manifests = getProviderManifests();
|
|
124
|
-
|
|
125
|
-
// Check specific provider
|
|
126
|
-
const claudeManifest = manifests.find(m => m.name === 'claude-code');
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Adapter Capabilities
|
|
130
|
-
|
|
131
|
-
Each provider adapter implements specific capability interfaces:
|
|
132
|
-
|
|
133
|
-
### Install Provider
|
|
134
|
-
|
|
135
|
-
Handles installation and setup:
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
import type { AdapterInstallProvider, InstallOptions, InstallResult } from '@cleocode/contracts';
|
|
139
|
-
|
|
140
|
-
const installProvider: AdapterInstallProvider = {
|
|
141
|
-
async install(options: InstallOptions): Promise<InstallResult> {
|
|
142
|
-
// Install provider-specific files
|
|
143
|
-
return { success: true, installed: ['file1', 'file2'] };
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
async detect(projectPath: string): Promise<boolean> {
|
|
147
|
-
// Check if provider is installed
|
|
148
|
-
return fs.existsSync(path.join(projectPath, '.claude'));
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Hook Provider
|
|
154
|
-
|
|
155
|
-
Provides lifecycle hooks:
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
import type { AdapterHookProvider } from '@cleocode/contracts';
|
|
159
|
-
|
|
160
|
-
const hookProvider: AdapterHookProvider = {
|
|
161
|
-
async onTaskCreate(context) {
|
|
162
|
-
// Called when a task is created
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
async onTaskComplete(context) {
|
|
166
|
-
// Called when a task is completed
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
async onSessionStart(context) {
|
|
170
|
-
// Called when a session starts
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
async onSessionEnd(context) {
|
|
174
|
-
// Called when a session ends
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### Spawn Provider
|
|
180
|
-
|
|
181
|
-
Handles subagent spawning:
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
import type { AdapterSpawnProvider, SpawnContext, SpawnResult } from '@cleocode/contracts';
|
|
185
|
-
|
|
186
|
-
const spawnProvider: AdapterSpawnProvider = {
|
|
187
|
-
async spawn(context: SpawnContext): Promise<SpawnResult> {
|
|
188
|
-
// Spawn a subagent
|
|
189
|
-
return {
|
|
190
|
-
pid: 12345,
|
|
191
|
-
stdout: process.stdout,
|
|
192
|
-
stderr: process.stderr,
|
|
193
|
-
exitCode: 0
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Context Monitor Provider
|
|
200
|
-
|
|
201
|
-
Monitors provider context:
|
|
202
|
-
|
|
203
|
-
```typescript
|
|
204
|
-
import type { AdapterContextMonitorProvider } from '@cleocode/contracts';
|
|
205
|
-
|
|
206
|
-
const contextProvider: AdapterContextMonitorProvider = {
|
|
207
|
-
async getContext(projectPath: string) {
|
|
208
|
-
return {
|
|
209
|
-
activeTask: 'T1234',
|
|
210
|
-
sessionId: 'session-abc',
|
|
211
|
-
memoryUsage: 1024000
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Transport Provider
|
|
218
|
-
|
|
219
|
-
Handles communication:
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
import type { AdapterTransportProvider } from '@cleocode/contracts';
|
|
223
|
-
|
|
224
|
-
const transportProvider: AdapterTransportProvider = {
|
|
225
|
-
async send(message) {
|
|
226
|
-
// Send message to provider
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
async receive() {
|
|
230
|
-
// Receive message from provider
|
|
231
|
-
return { type: 'response', data: {} };
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Path Provider
|
|
237
|
-
|
|
238
|
-
Provides provider-specific paths:
|
|
239
|
-
|
|
240
|
-
```typescript
|
|
241
|
-
import type { AdapterPathProvider } from '@cleocode/contracts';
|
|
242
|
-
|
|
243
|
-
const pathProvider: AdapterPathProvider = {
|
|
244
|
-
getConfigPath(projectPath: string) {
|
|
245
|
-
return path.join(projectPath, '.claude', 'settings.json');
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
getDataPath(projectPath: string) {
|
|
249
|
-
return path.join(projectPath, '.claude', 'data');
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
### Task Sync Provider
|
|
255
|
-
|
|
256
|
-
Synchronizes tasks with provider:
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
import type { AdapterTaskSyncProvider, ReconcileOptions, ReconcileResult } from '@cleocode/contracts';
|
|
260
|
-
|
|
261
|
-
const syncProvider: AdapterTaskSyncProvider = {
|
|
262
|
-
async getExternalTasks(projectPath: string) {
|
|
263
|
-
// Get tasks from provider
|
|
264
|
-
return [];
|
|
265
|
-
},
|
|
266
|
-
|
|
267
|
-
async reconcile(options: ReconcileOptions): Promise<ReconcileResult> {
|
|
268
|
-
// Reconcile tasks
|
|
269
|
-
return {
|
|
270
|
-
actions: [],
|
|
271
|
-
conflicts: []
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
## Usage Examples
|
|
278
|
-
|
|
279
|
-
### Detecting Available Providers
|
|
280
|
-
|
|
281
66
|
```typescript
|
|
282
67
|
import { discoverProviders, getProviderManifests } from '@cleocode/adapters';
|
|
283
68
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
// Auto-detect installed providers
|
|
288
|
-
const available = await discoverProviders(projectPath);
|
|
289
|
-
|
|
290
|
-
console.log('Available providers:');
|
|
291
|
-
for (const provider of available) {
|
|
292
|
-
console.log(` - ${provider.name}: ${provider.version}`);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Get detailed manifests
|
|
296
|
-
const manifests = getProviderManifests();
|
|
297
|
-
for (const manifest of manifests) {
|
|
298
|
-
console.log(`\n${manifest.name}:`);
|
|
299
|
-
console.log(` Capabilities: ${manifest.capabilities.join(', ')}`);
|
|
300
|
-
console.log(` Patterns: ${manifest.patterns.join(', ')}`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
### Setting Up Claude Code Integration
|
|
306
|
-
|
|
307
|
-
```typescript
|
|
308
|
-
import {
|
|
309
|
-
createClaudeCodeAdapter,
|
|
310
|
-
checkStatuslineIntegration,
|
|
311
|
-
getSetupInstructions
|
|
312
|
-
} from '@cleocode/adapters';
|
|
313
|
-
|
|
314
|
-
async function setupClaudeCode() {
|
|
315
|
-
const projectPath = './my-project';
|
|
316
|
-
|
|
317
|
-
// Check if already integrated
|
|
318
|
-
const status = await checkStatuslineIntegration(projectPath);
|
|
319
|
-
|
|
320
|
-
if (!status.integrated) {
|
|
321
|
-
console.log('Claude Code not yet integrated');
|
|
322
|
-
console.log(getSetupInstructions());
|
|
323
|
-
|
|
324
|
-
// Create adapter and install
|
|
325
|
-
const adapter = createClaudeCodeAdapter({ projectPath });
|
|
326
|
-
const result = await adapter.install({ force: false });
|
|
327
|
-
|
|
328
|
-
if (result.success) {
|
|
329
|
-
console.log('Claude Code integration installed');
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
console.log('Claude Code is already integrated ✓');
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
### Working with Hooks
|
|
338
|
-
|
|
339
|
-
```typescript
|
|
340
|
-
import { createClaudeCodeAdapter } from '@cleocode/adapters';
|
|
341
|
-
|
|
342
|
-
async function setupHooks() {
|
|
343
|
-
const adapter = createClaudeCodeAdapter({
|
|
344
|
-
projectPath: './my-project'
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
// Register task creation hook
|
|
348
|
-
adapter.hooks.register('onTaskCreate', async (context) => {
|
|
349
|
-
console.log(`Task ${context.taskId} created in Claude Code`);
|
|
350
|
-
// Update Claude Code statusline
|
|
351
|
-
await adapter.updateStatusline({ activeTask: context.taskId });
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
// Register task completion hook
|
|
355
|
-
adapter.hooks.register('onTaskComplete', async (context) => {
|
|
356
|
-
console.log(`Task ${context.taskId} completed`);
|
|
357
|
-
// Clear statusline
|
|
358
|
-
await adapter.updateStatusline({ activeTask: null });
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### Spawning Subagents
|
|
69
|
+
// Bundled manifests: every src/providers/<id>/manifest.json that parses.
|
|
70
|
+
const manifests = getProviderManifests();
|
|
364
71
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
async function spawnSubagent() {
|
|
369
|
-
const adapter = createClaudeCodeAdapter({
|
|
370
|
-
projectPath: './my-project'
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
// Spawn a Claude Code subagent
|
|
374
|
-
const result = await adapter.spawn({
|
|
375
|
-
taskId: 'T1234',
|
|
376
|
-
context: {
|
|
377
|
-
instructions: 'Implement the authentication endpoint',
|
|
378
|
-
files: ['src/auth.ts', 'src/routes.ts']
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
if (result.pid) {
|
|
383
|
-
console.log(`Spawned subagent with PID ${result.pid}`);
|
|
384
|
-
|
|
385
|
-
// Wait for completion
|
|
386
|
-
result.stdout?.on('data', (data) => {
|
|
387
|
-
console.log(`Output: ${data}`);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
72
|
+
// Lazy factories for claude-code, opencode, cursor and pi.
|
|
73
|
+
const factories = await discoverProviders();
|
|
74
|
+
const adapter = await factories.get('claude-code')?.();
|
|
391
75
|
```
|
|
392
76
|
|
|
393
|
-
|
|
77
|
+
`claude-sdk` has no `manifest.json`, so `getProviderManifests()` does not list it.
|
|
394
78
|
|
|
395
|
-
|
|
396
|
-
import { createClaudeCodeAdapter } from '@cleocode/adapters';
|
|
397
|
-
|
|
398
|
-
async function syncTasks() {
|
|
399
|
-
const adapter = createClaudeCodeAdapter({
|
|
400
|
-
projectPath: './my-project'
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
// Get external tasks from Claude Code
|
|
404
|
-
const externalTasks = await adapter.getExternalTasks();
|
|
405
|
-
|
|
406
|
-
// Reconcile with CLEO tasks
|
|
407
|
-
const result = await adapter.reconcile({
|
|
408
|
-
conflictPolicy: 'prefer-external',
|
|
409
|
-
dryRun: false
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
console.log(`Reconciliation complete:`);
|
|
413
|
-
console.log(` Created: ${result.created.length}`);
|
|
414
|
-
console.log(` Updated: ${result.updated.length}`);
|
|
415
|
-
console.log(` Conflicts: ${result.conflicts.length}`);
|
|
416
|
-
}
|
|
417
|
-
```
|
|
79
|
+
## Adapter contract
|
|
418
80
|
|
|
419
|
-
|
|
81
|
+
The contracts live in `@cleocode/contracts`. `CLEOProviderAdapter` (`adapter.ts`) has `id`, `name`, `version`, `capabilities`, a required `install` provider, the optional `hooks`, `spawn`, `paths`, `contextMonitor`, `transport` and `taskSync` providers, and the lifecycle methods `initialize(projectDir)`, `dispose()` and `healthCheck()`.
|
|
420
82
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
version = '1.0.0';
|
|
431
|
-
|
|
432
|
-
getCapabilities(): AdapterCapabilities {
|
|
433
|
-
return {
|
|
434
|
-
spawn: true,
|
|
435
|
-
hooks: true,
|
|
436
|
-
install: true,
|
|
437
|
-
contextMonitor: false,
|
|
438
|
-
transport: true,
|
|
439
|
-
paths: true,
|
|
440
|
-
taskSync: false
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
async healthCheck(projectPath: string): Promise<AdapterHealthStatus> {
|
|
445
|
-
const isInstalled = await this.detect(projectPath);
|
|
446
|
-
return {
|
|
447
|
-
healthy: isInstalled,
|
|
448
|
-
message: isInstalled ? 'Ready' : 'Not installed'
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
async detect(projectPath: string): Promise<boolean> {
|
|
453
|
-
// Check for provider-specific files
|
|
454
|
-
return fs.existsSync(path.join(projectPath, '.my-provider'));
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// Implement other provider methods...
|
|
458
|
-
}
|
|
83
|
+
| Provider interface | Methods |
|
|
84
|
+
|--------------------|---------|
|
|
85
|
+
| `AdapterInstallProvider` (`install.ts`) | `install(options)`, `uninstall()`, `isInstalled()`, `ensureInstructionReferences(projectDir)` |
|
|
86
|
+
| `AdapterHookProvider` (`hooks.ts`) | `mapProviderEvent(event)`, `registerNativeHooks(projectDir)`, `unregisterNativeHooks()`, optional `getEventMap()`, `getTranscript()` |
|
|
87
|
+
| `AdapterSpawnProvider` (`spawn.ts`) | `canSpawn()`, `spawn(context)`, `listRunning()`, `terminate(instanceId)` |
|
|
88
|
+
| `AdapterPathProvider` (`provider-paths.ts`) | `getProviderDir()`, `getSettingsPath()`, `getAgentInstallDir()`, `getMemoryDbPath()` |
|
|
89
|
+
| `AdapterContextMonitorProvider` (`context-monitor.ts`) | `processContextInput()`, `checkStatuslineIntegration()`, `getStatuslineConfig()`, `getSetupInstructions()` |
|
|
90
|
+
| `AdapterTransportProvider` (`transport.ts`) | `createTransport()`, `transportName`. The claude-code transport is a stub that returns `null` |
|
|
91
|
+
| `ExternalTaskProvider` (`task-sync.ts`) | `getExternalTasks(projectDir)`, optional outbound push |
|
|
459
92
|
|
|
460
|
-
|
|
461
|
-
import { discoverProviders } from '@cleocode/adapters';
|
|
462
|
-
discoverProviders.register(new MyCustomAdapter());
|
|
463
|
-
```
|
|
93
|
+
`AdapterCapabilities` (`capabilities.ts`) is a set of flags: `supportsHooks`, `supportedHookEvents`, `supportsSpawn`, `supportsInstall`, `supportsInstructionFiles`, `instructionFilePattern`, `supportsContextMonitor`, `supportsStatusline`, `supportsProviderPaths`, `supportsTransport`, `supportsTaskSync`.
|
|
464
94
|
|
|
465
|
-
##
|
|
95
|
+
## Manifest format
|
|
466
96
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
```typescript
|
|
470
|
-
interface AdapterManifest {
|
|
471
|
-
name: string;
|
|
472
|
-
version: string;
|
|
473
|
-
description: string;
|
|
474
|
-
capabilities: Array<'spawn' | 'hooks' | 'install' | 'contextMonitor' | 'transport' | 'paths' | 'taskSync'>;
|
|
475
|
-
patterns: DetectionPattern[];
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
interface DetectionPattern {
|
|
479
|
-
type: 'file' | 'directory' | 'config';
|
|
480
|
-
path: string;
|
|
481
|
-
content?: string; // Optional: check file content
|
|
482
|
-
}
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
Example manifest:
|
|
97
|
+
Each provider directory may ship a `manifest.json` matching `AdapterManifest` (`@cleocode/contracts`, `discovery.ts`). `packagePath` and `entryPoint` are filled in at discovery time.
|
|
486
98
|
|
|
487
99
|
```json
|
|
488
100
|
{
|
|
489
|
-
"
|
|
101
|
+
"id": "claude-code",
|
|
102
|
+
"name": "Claude Code Adapter",
|
|
490
103
|
"version": "1.0.0",
|
|
491
|
-
"description": "Claude Code
|
|
492
|
-
"
|
|
493
|
-
"
|
|
494
|
-
|
|
495
|
-
|
|
104
|
+
"description": "CLEO adapter for Anthropic Claude Code CLI",
|
|
105
|
+
"provider": "claude-code",
|
|
106
|
+
"entryPoint": "src/index.ts",
|
|
107
|
+
"capabilities": { "supportsHooks": true, "supportsSpawn": true, "...": "..." },
|
|
108
|
+
"detectionPatterns": [
|
|
109
|
+
{ "type": "env", "pattern": "CLAUDE_CODE_ENTRYPOINT", "description": "Claude Code sets this env var" },
|
|
110
|
+
{ "type": "file", "pattern": ".claude/settings.json", "description": "Claude Code config directory" },
|
|
111
|
+
{ "type": "cli", "pattern": "claude", "description": "Claude CLI available in PATH" }
|
|
496
112
|
]
|
|
497
113
|
}
|
|
498
114
|
```
|
|
499
115
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
### Production Dependencies
|
|
116
|
+
Detection pattern types are `env`, `file`, `process` and `cli`.
|
|
503
117
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
### Development Dependencies
|
|
118
|
+
## Dependencies
|
|
507
119
|
|
|
508
|
-
- `@
|
|
120
|
+
- `@cleocode/contracts`: adapter, spawn, hook and install contracts
|
|
121
|
+
- `@cleocode/caamp`: provider registry and hook event mappings
|
|
122
|
+
- `@cleocode/paths`: path resolution
|
|
123
|
+
- `ai`, `@ai-sdk/anthropic`, `@ai-sdk/openai`: the SDK spawn adapters
|
|
509
124
|
|
|
510
125
|
## License
|
|
511
126
|
|
package/dist/.source-stamp.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleocode/adapters",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.12-rc.ci.729",
|
|
4
4
|
"description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"@ai-sdk/anthropic": "^3.0.69",
|
|
36
36
|
"@ai-sdk/openai": "^2.0.53",
|
|
37
37
|
"ai": "^6.0.168",
|
|
38
|
-
"@cleocode/caamp": "2026.11.
|
|
39
|
-
"@cleocode/contracts": "2026.11.
|
|
40
|
-
"@cleocode/paths": "2026.11.
|
|
38
|
+
"@cleocode/caamp": "2026.11.12-rc.ci.729",
|
|
39
|
+
"@cleocode/contracts": "2026.11.12-rc.ci.729",
|
|
40
|
+
"@cleocode/paths": "2026.11.12-rc.ci.729"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"engines": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^24.3.0",
|
|
52
52
|
"vitest": "^4.1.4",
|
|
53
|
-
"@cleocode/core": "2026.11.
|
|
54
|
-
"@cleocode/playbooks": "2026.11.
|
|
53
|
+
"@cleocode/core": "2026.11.12-rc.ci.729",
|
|
54
|
+
"@cleocode/playbooks": "2026.11.12-rc.ci.729"
|
|
55
55
|
},
|
|
56
56
|
"repository": {
|
|
57
57
|
"type": "git",
|
package/src/providers/README.md
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This directory contains the per-provider adapters that integrate CLEO with
|
|
4
4
|
individual AI coding harnesses: Claude Code, Codex, Cursor, Gemini CLI, Kimi
|
|
5
|
-
and OpenCode, plus the two SDK spawn adapters (`claude-sdk`, `openai-sdk`)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
and OpenCode, plus the two SDK spawn adapters (`claude-sdk`, `openai-sdk`).
|
|
6
|
+
Each adapter implements the contracts defined in `@cleocode/contracts` and
|
|
7
|
+
delegates universal behaviour to CLEO core through the `cleo` CLI. Adapters
|
|
8
|
+
never reach into `@cleocode/core` internals at runtime.
|
|
9
|
+
|
|
10
|
+
The `pi/` directory is frozen: ADR-098 retires the Pi/CleoOS harness, and the
|
|
11
|
+
directory is deleted after a release has shipped the freeze. Until then it is
|
|
12
|
+
still in the source and still registered.
|
|
12
13
|
|
|
13
14
|
## Directory layout
|
|
14
15
|
|
|
@@ -31,11 +32,11 @@ providers/
|
|
|
31
32
|
│ ├── ...
|
|
32
33
|
│ └── templates/hooks/
|
|
33
34
|
├── codex/, kimi/ # instruction files (+ Codex PreToolUse hook), no PreCompact shim
|
|
34
|
-
├── claude-sdk/, openai-sdk/ # SDK spawn adapters (no harness
|
|
35
|
-
├── pi/ #
|
|
36
|
-
│ └── templates/hooks/ # README only
|
|
35
|
+
├── claude-sdk/, openai-sdk/ # SDK spawn adapters (no harness hooks)
|
|
36
|
+
├── pi/ # frozen, deleted under ADR-098
|
|
37
37
|
└── shared/
|
|
38
38
|
├── hook-template-installer.ts # DRY installer for all providers
|
|
39
|
+
├── lead-tool-strip.ts # E_LEAD_TOOLS_UNSTRIPPED guard for lead spawns
|
|
39
40
|
├── paths.ts
|
|
40
41
|
├── transcript-reader.ts
|
|
41
42
|
└── templates/hooks/
|
|
@@ -47,17 +48,17 @@ providers/
|
|
|
47
48
|
The provider adapters own all harness-specific hook templates. The core
|
|
48
49
|
package (`@cleocode/core`) ships only the universal business logic
|
|
49
50
|
(`src/memory/precompact-flush.ts`, `src/hooks/handlers/*`) and the `cleo`
|
|
50
|
-
CLI
|
|
51
|
+
CLI, never bash.
|
|
51
52
|
|
|
52
53
|
### Layered design
|
|
53
54
|
|
|
54
|
-
1. **Universal layer
|
|
55
|
+
1. **Universal layer**: `shared/templates/hooks/cleo-precompact-core.sh`
|
|
55
56
|
contains the one-and-only implementation of the pre-compact flush +
|
|
56
57
|
safestop sequence. It invokes the CLEO CLI (`cleo memory precompact-flush`
|
|
57
58
|
and `cleo safestop …`). No provider knows any CLEO internals; every
|
|
58
59
|
provider ends up at the same CLI surface.
|
|
59
60
|
|
|
60
|
-
2. **Provider shim layer
|
|
61
|
+
2. **Provider shim layer**: each harness-specific directory ships a tiny
|
|
61
62
|
wrapper that sources the universal helper and adds only provider-flavoured
|
|
62
63
|
banners / env handling. Per-provider filenames match the harness's native
|
|
63
64
|
event vocabulary:
|
|
@@ -68,14 +69,14 @@ CLI — never bash.
|
|
|
68
69
|
| cursor | `precompact.sh` | `PreCompact` | `preCompact` |
|
|
69
70
|
| opencode | `precompact.sh` + `cleo-precompact.js` | `PreCompact` | `experimental.session.compacting` |
|
|
70
71
|
| gemini-cli | `precompact.sh` | `PreCompact` | `PreCompress` |
|
|
71
|
-
| pi | *README-only* (deprecated, ADR-098) | `PreCompact` | `context` |
|
|
72
72
|
|
|
73
73
|
The event mappings are sourced from `packages/caamp/providers/hook-mappings.json`
|
|
74
|
-
(the CAAMP SSoT).
|
|
75
|
-
`@cleocode/caamp`'s `toNative()` / `getProviderHookProfile()
|
|
76
|
-
|
|
74
|
+
(the CAAMP SSoT). The Claude Code, Cursor and OpenCode hook providers use
|
|
75
|
+
`@cleocode/caamp`'s `toNative()` / `getProviderHookProfile()`; the Codex and
|
|
76
|
+
Gemini CLI hook providers read `PROVIDER_NATIVE_EVENT_MAPS` from
|
|
77
|
+
`@cleocode/caamp/hooks`.
|
|
77
78
|
|
|
78
|
-
3. **Installer layer
|
|
79
|
+
3. **Installer layer**: `shared/hook-template-installer.ts` exposes a single
|
|
79
80
|
`installProviderHookTemplates({ provider, targetDir })` function that:
|
|
80
81
|
1. Resolves the provider's shim + the shared helper from this package.
|
|
81
82
|
2. Copies both into the provided target directory (idempotent).
|
|
@@ -83,15 +84,16 @@ CLI — never bash.
|
|
|
83
84
|
|
|
84
85
|
Each provider's `AdapterInstallProvider.install(...)` method calls this
|
|
85
86
|
installer and then wires the shim into the harness's configuration
|
|
86
|
-
surface
|
|
87
|
+
surface. Every target is project-local; the user-global `~/.claude` is
|
|
88
|
+
never written (T13227):
|
|
87
89
|
|
|
88
|
-
- Claude Code:
|
|
90
|
+
- Claude Code: copy the shim into the project's `.claude/hooks/` and
|
|
91
|
+
append a `PreCompact` entry to the project's `.claude/settings.local.json`.
|
|
89
92
|
- Cursor: append a `preCompact` entry to `.cursor/hooks.json`.
|
|
90
|
-
- OpenCode:
|
|
91
|
-
`.opencode/plugins/cleo-precompact.js` that `spawn()`s
|
|
93
|
+
- OpenCode: copy the shim into `.opencode/plugins/hooks/` and generate a
|
|
94
|
+
JS plugin at `.opencode/plugins/cleo-precompact.js` that `spawn()`s it.
|
|
92
95
|
- Gemini CLI: a `precompact.sh` shim ships, but the Gemini install path
|
|
93
96
|
does not call the installer yet, so nothing is wired.
|
|
94
|
-
- Pi: nothing; the provider is deprecated and retiring (ADR-098).
|
|
95
97
|
|
|
96
98
|
Codex and Kimi install no PreCompact shim: their install providers write
|
|
97
99
|
the CLEO instruction references into `AGENTS.md`, and Codex also adds the
|
|
@@ -100,20 +102,20 @@ CLI — never bash.
|
|
|
100
102
|
### Why this split?
|
|
101
103
|
|
|
102
104
|
Before T1013 the pre-compact hook lived in
|
|
103
|
-
`packages/core/templates/hooks/precompact-safestop.sh
|
|
105
|
+
`packages/core/templates/hooks/precompact-safestop.sh`: Claude-Code-specific
|
|
104
106
|
bash buried inside the provider-neutral core package. Moving the file into
|
|
105
107
|
`packages/adapters/src/providers/claude-code/templates/hooks/` and adding
|
|
106
108
|
equivalent templates under the other provider directories restores the
|
|
107
109
|
architectural boundary:
|
|
108
110
|
|
|
109
|
-
- **Core** owns universal CLEO logic (`precompact-flush.ts`,
|
|
110
|
-
|
|
111
|
+
- **Core** owns universal CLEO logic (`precompact-flush.ts`, the hook
|
|
112
|
+
handlers, session handling).
|
|
111
113
|
- **Adapters** own harness-specific wiring (shell shims, config fragments,
|
|
112
114
|
plugin generators).
|
|
113
115
|
- **CAAMP** owns the event-name translation SSoT (`hook-mappings.json`).
|
|
114
116
|
|
|
115
117
|
Provider adapters are the only place that knows whether a harness uses
|
|
116
|
-
`.claude/settings.json` versus `.cursor/hooks.json` versus a JS plugin
|
|
118
|
+
`.claude/settings.local.json` versus `.cursor/hooks.json` versus a JS plugin,
|
|
117
119
|
and they all funnel execution back through the same `cleo` CLI.
|
|
118
120
|
|
|
119
121
|
### Adding a new harness
|
|
@@ -122,7 +124,7 @@ and they all funnel execution back through the same `cleo` CLI.
|
|
|
122
124
|
(the SSoT). At minimum populate `hookSystem`, `hookConfigPath`,
|
|
123
125
|
`handlerTypes`, and the `PreCompact` entry under `mappings`.
|
|
124
126
|
2. Create `<provider>/templates/hooks/<shim>.sh` that sources the shared
|
|
125
|
-
helper. Keep the shim small
|
|
127
|
+
helper. Keep the shim small: only provider-flavoured echo / exit handling
|
|
126
128
|
goes here.
|
|
127
129
|
3. Teach `shared/hook-template-installer.ts` about the new provider id by
|
|
128
130
|
adding it to `HookTemplateProviderId` and `PROVIDER_SHIM`.
|
|
@@ -138,7 +140,7 @@ and they all funnel execution back through the same `cleo` CLI.
|
|
|
138
140
|
- **Shims MUST be idempotent on install and uninstall.** Re-running the
|
|
139
141
|
installer must not duplicate config entries.
|
|
140
142
|
- **The shared helper is the one-and-only contract.** Duplicating its logic
|
|
141
|
-
into provider shims is a DRY violation
|
|
143
|
+
into provider shims is a DRY violation; add provider-specific behaviour
|
|
142
144
|
only to the shim wrapper.
|
|
143
145
|
- **Hook failures MUST NOT block the harness.** All CLEO invocations in the
|
|
144
146
|
shim tolerate non-zero exits via `|| true` so the host compaction path is
|