@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.
Files changed (94) hide show
  1. package/README.md +2 -0
  2. package/dist/.source-stamp.json +4 -0
  3. package/dist/index.js +2676 -1895
  4. package/dist/index.js.map +3 -3
  5. package/dist/manifests.d.ts +25 -0
  6. package/dist/manifests.d.ts.map +1 -0
  7. package/dist/manifests.js +28 -0
  8. package/dist/manifests.js.map +6 -0
  9. package/dist/orca-execution.d.ts +89 -0
  10. package/dist/orca-execution.d.ts.map +1 -0
  11. package/dist/orca-execution.js +794 -0
  12. package/dist/orca-execution.js.map +6 -0
  13. package/dist/providers/claude-code/index.js +46710 -0
  14. package/dist/providers/claude-code/index.js.map +6 -0
  15. package/dist/providers/claude-code/lead-mcp.d.ts +99 -0
  16. package/dist/providers/claude-code/lead-mcp.d.ts.map +1 -0
  17. package/dist/providers/claude-code/lead-session.d.ts +133 -0
  18. package/dist/providers/claude-code/lead-session.d.ts.map +1 -0
  19. package/dist/providers/claude-code/spawn.d.ts +39 -0
  20. package/dist/providers/claude-code/spawn.d.ts.map +1 -1
  21. package/dist/providers/claude-sdk/index.js +44549 -0
  22. package/dist/providers/claude-sdk/index.js.map +6 -0
  23. package/dist/providers/claude-sdk/spawn.d.ts +6 -0
  24. package/dist/providers/claude-sdk/spawn.d.ts.map +1 -1
  25. package/dist/providers/codex/index.js +19315 -0
  26. package/dist/providers/codex/index.js.map +6 -0
  27. package/dist/providers/codex/spawn.d.ts +2 -0
  28. package/dist/providers/codex/spawn.d.ts.map +1 -1
  29. package/dist/providers/cursor/index.js +637 -0
  30. package/dist/providers/cursor/index.js.map +6 -0
  31. package/dist/providers/cursor/spawn.d.ts +2 -0
  32. package/dist/providers/cursor/spawn.d.ts.map +1 -1
  33. package/dist/providers/gemini-cli/index.js +18877 -0
  34. package/dist/providers/gemini-cli/index.js.map +6 -0
  35. package/dist/providers/gemini-cli/spawn.d.ts +2 -0
  36. package/dist/providers/gemini-cli/spawn.d.ts.map +1 -1
  37. package/dist/providers/kimi/index.js +18806 -0
  38. package/dist/providers/kimi/index.js.map +6 -0
  39. package/dist/providers/kimi/spawn.d.ts +2 -0
  40. package/dist/providers/kimi/spawn.d.ts.map +1 -1
  41. package/dist/providers/openai-sdk/adapter.d.ts +1 -1
  42. package/dist/providers/openai-sdk/index.d.ts +0 -1
  43. package/dist/providers/openai-sdk/index.d.ts.map +1 -1
  44. package/dist/providers/openai-sdk/index.js +44190 -0
  45. package/dist/providers/openai-sdk/index.js.map +6 -0
  46. package/dist/providers/openai-sdk/spawn.d.ts +4 -2
  47. package/dist/providers/openai-sdk/spawn.d.ts.map +1 -1
  48. package/dist/providers/openai-sdk/tracing.d.ts +8 -82
  49. package/dist/providers/openai-sdk/tracing.d.ts.map +1 -1
  50. package/dist/providers/opencode/index.js +19317 -0
  51. package/dist/providers/opencode/index.js.map +6 -0
  52. package/dist/providers/opencode/spawn.d.ts +2 -0
  53. package/dist/providers/opencode/spawn.d.ts.map +1 -1
  54. package/dist/providers/pi/index.js +18453 -0
  55. package/dist/providers/pi/index.js.map +6 -0
  56. package/dist/providers/pi/spawn.d.ts +2 -0
  57. package/dist/providers/pi/spawn.d.ts.map +1 -1
  58. package/dist/providers/shared/lead-tool-strip.d.ts +52 -0
  59. package/dist/providers/shared/lead-tool-strip.d.ts.map +1 -0
  60. package/dist/registry.d.ts +2 -55
  61. package/dist/registry.d.ts.map +1 -1
  62. package/package.json +14 -6
  63. package/src/__tests__/harness-interop.test.ts +0 -7
  64. package/src/__tests__/orca-execution-fixture.ts +380 -0
  65. package/src/__tests__/orca-execution.test.ts +1357 -0
  66. package/src/__tests__/orca-plugin-panel.test.ts +661 -0
  67. package/src/__tests__/orca-plugin.test.ts +660 -0
  68. package/src/manifests.ts +55 -0
  69. package/src/orca-execution.ts +1136 -0
  70. package/src/providers/claude-code/__tests__/lead-mcp.test.ts +348 -0
  71. package/src/providers/claude-code/__tests__/worker-exit-settings.test.ts +32 -0
  72. package/src/providers/claude-code/lead-mcp.ts +244 -0
  73. package/src/providers/claude-code/lead-session.ts +241 -0
  74. package/src/providers/claude-code/spawn.ts +180 -11
  75. package/src/providers/claude-sdk/__tests__/spawn.test.ts +63 -3
  76. package/src/providers/claude-sdk/spawn.ts +28 -1
  77. package/src/providers/codex/spawn.ts +5 -0
  78. package/src/providers/cursor/spawn.ts +3 -0
  79. package/src/providers/gemini-cli/spawn.ts +5 -0
  80. package/src/providers/kimi/spawn.ts +5 -0
  81. package/src/providers/openai-sdk/__tests__/openai-sdk-spawn.test.ts +0 -80
  82. package/src/providers/openai-sdk/adapter.ts +1 -1
  83. package/src/providers/openai-sdk/index.ts +0 -1
  84. package/src/providers/openai-sdk/manifest.json +1 -1
  85. package/src/providers/openai-sdk/spawn.ts +10 -16
  86. package/src/providers/openai-sdk/tracing.ts +8 -169
  87. package/src/providers/opencode/spawn.ts +5 -0
  88. package/src/providers/pi/spawn.ts +5 -0
  89. package/src/providers/shared/__tests__/lead-tool-strip.test.ts +126 -0
  90. package/src/providers/shared/lead-tool-strip.ts +76 -0
  91. package/src/registry.ts +2 -78
  92. package/dist/providers/shared/conduit-trace-writer.d.ts +0 -72
  93. package/dist/providers/shared/conduit-trace-writer.d.ts.map +0 -1
  94. package/src/providers/shared/conduit-trace-writer.ts +0 -101
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Lead tool strip — the spawn-time guard of the lead/worker split (epic T14351).
3
+ *
4
+ * A lead spawn carries {@link SpawnContext.leadDeniedTools}. A provider that
5
+ * can remove those tools from the spawned agent declares
6
+ * `leadToolStrip: 'enforced'` and strips them; every other provider is
7
+ * `'unsupported'` (also the meaning of an absent declaration), and a lead
8
+ * spawn there is refused with `E_LEAD_TOOLS_UNSTRIPPED` before anything runs.
9
+ * Worker spawns carry no denied tools and pass through unchanged.
10
+ *
11
+ * @task T14357
12
+ * @epic T14351
13
+ */
14
+
15
+ import type { LeadDeniedTool, LeadToolStripSupport, SpawnContext } from '@cleocode/contracts';
16
+ import { E_LEAD_TOOLS_UNSTRIPPED, ExitCode } from '@cleocode/contracts';
17
+
18
+ /**
19
+ * Thrown when a lead spawn reaches a provider that cannot strip the lead's
20
+ * denied tools. Exit code aligns with {@link ExitCode.SPAWN_VALIDATION_FAILED} (63).
21
+ *
22
+ * @task T14357
23
+ */
24
+ export class LeadToolsUnstrippedError extends Error {
25
+ /** Stable LAFS error code string for envelope emission. */
26
+ readonly code = E_LEAD_TOOLS_UNSTRIPPED;
27
+ /** Numeric exit code aligned with {@link ExitCode.SPAWN_VALIDATION_FAILED} (63). */
28
+ readonly exitCode: ExitCode = ExitCode.SPAWN_VALIDATION_FAILED;
29
+
30
+ /**
31
+ * @param providerId - Provider that refused the lead spawn.
32
+ * @param deniedTools - Tools the lead had to lose.
33
+ */
34
+ constructor(
35
+ public readonly providerId: string,
36
+ public readonly deniedTools: readonly LeadDeniedTool[],
37
+ ) {
38
+ super(
39
+ `${E_LEAD_TOOLS_UNSTRIPPED}: provider '${providerId}' cannot strip the lead's denied ` +
40
+ `tools [${deniedTools.join(', ')}]. Spawn the lead on a provider that enforces the ` +
41
+ `strip (claude-code, claude-sdk) or turn off orchestrate.leadWorker.v1.`,
42
+ );
43
+ this.name = 'LeadToolsUnstrippedError';
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Denied tools of a lead spawn, or `null` for a worker spawn.
49
+ *
50
+ * @param context - Spawn context.
51
+ * @returns The non-empty denied-tool list, or `null` when the spawn is not a lead spawn.
52
+ */
53
+ export function leadDeniedTools(context: SpawnContext): readonly LeadDeniedTool[] | null {
54
+ const denied = context.leadDeniedTools;
55
+ return denied !== undefined && denied.length > 0 ? denied : null;
56
+ }
57
+
58
+ /**
59
+ * Refuse a lead spawn on a provider that cannot strip its denied tools.
60
+ * No-op for worker spawns and for providers that enforce the strip.
61
+ *
62
+ * @param providerId - Provider performing the spawn.
63
+ * @param support - The provider's strip capability.
64
+ * @param context - Spawn context.
65
+ * @throws {LeadToolsUnstrippedError} When the spawn is a lead spawn and `support` is `'unsupported'`.
66
+ */
67
+ export function assertLeadToolsStrippable(
68
+ providerId: string,
69
+ support: LeadToolStripSupport,
70
+ context: SpawnContext,
71
+ ): void {
72
+ const denied = leadDeniedTools(context);
73
+ if (denied !== null && support !== 'enforced') {
74
+ throw new LeadToolsUnstrippedError(providerId, denied);
75
+ }
76
+ }
package/src/registry.ts CHANGED
@@ -7,84 +7,8 @@
7
7
  * @task T5240
8
8
  */
9
9
 
10
- import { readFileSync } from 'node:fs';
11
- import { dirname, join, resolve } from 'node:path';
12
- import { fileURLToPath } from 'node:url';
13
-
14
- /**
15
- * Minimal manifest shape for provider discovery.
16
- *
17
- * @remarks
18
- * Each provider adapter ships a `manifest.json` in its directory under
19
- * `providers/`. The registry reads these at startup to populate the
20
- * adapter discovery surface. The shape is intentionally minimal -- only
21
- * the fields needed for dynamic loading and detection are required.
22
- */
23
- export interface AdapterManifest {
24
- /** Unique provider identifier (e.g. "claude-code", "cursor"). */
25
- id: string;
26
- /** Human-readable display name for the provider. */
27
- name: string;
28
- /** Semantic version of the adapter. */
29
- version: string;
30
- /** Short description of what the provider integrates with. */
31
- description: string;
32
- /** Provider slug used for directory lookups. */
33
- provider: string;
34
- /** Relative path to the adapter's entry point module. */
35
- entryPoint: string;
36
- /** Capability flags declared by the adapter. */
37
- capabilities: Record<string, unknown>;
38
- /** Patterns used to auto-detect the provider in a project. */
39
- detectionPatterns: Array<{
40
- /** Detection strategy type (e.g. "file", "env"). */
41
- type: string;
42
- /** Glob or regex pattern to match. */
43
- pattern: string;
44
- /** Human-readable explanation of this detection rule. */
45
- description: string;
46
- }>;
47
- }
48
-
49
- /** Known provider IDs bundled with @cleocode/adapters. */
50
- const PROVIDER_IDS = ['claude-code', 'opencode', 'cursor', 'pi'] as const;
51
-
52
- /**
53
- * Get the manifests for all bundled provider adapters.
54
- *
55
- * @remarks
56
- * Scans the known provider directories for `manifest.json` files.
57
- * Providers whose manifests cannot be loaded (missing or malformed)
58
- * are silently skipped.
59
- *
60
- * @returns Array of adapter manifests for successfully loaded providers
61
- *
62
- * @example
63
- * ```typescript
64
- * import { getProviderManifests } from '@cleocode/adapters';
65
- *
66
- * const manifests = getProviderManifests();
67
- * for (const m of manifests) {
68
- * console.log(`${m.id}: ${m.name} v${m.version}`);
69
- * }
70
- * ```
71
- */
72
- export function getProviderManifests(): AdapterManifest[] {
73
- const manifests: AdapterManifest[] = [];
74
- const baseDir = resolve(dirname(fileURLToPath(import.meta.url)), 'providers');
75
-
76
- for (const providerId of PROVIDER_IDS) {
77
- try {
78
- const manifestPath = join(baseDir, providerId, 'manifest.json');
79
- const raw = readFileSync(manifestPath, 'utf-8');
80
- manifests.push(JSON.parse(raw) as AdapterManifest);
81
- } catch {
82
- // Skip providers whose manifests cannot be loaded
83
- }
84
- }
85
-
86
- return manifests;
87
- }
10
+ export type { AdapterManifest } from '@cleocode/contracts';
11
+ export { getProviderManifests } from './manifests.js';
88
12
 
89
13
  /**
90
14
  * Discover all available provider adapters.
@@ -1,72 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,101 +0,0 @@
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
- /**
15
- * A single normalised span event written to conduit.
16
- *
17
- * @remarks
18
- * This shape is intentionally minimal — only fields that both SDK providers
19
- * can populate consistently are required. Provider-specific fields go into
20
- * the `metadata` bag.
21
- */
22
- export interface ConduitSpanEvent {
23
- /** Unique identifier for this span (from the SDK). */
24
- spanId: string;
25
- /** The task ID this span belongs to. */
26
- taskId: string;
27
- /** The name of the agent that produced this span. */
28
- agentName: string;
29
- /** Type of span: `'agent'`, `'function'`, `'handoff'`, `'generation'`, etc. */
30
- spanType: string;
31
- /** ISO timestamp when the span started. */
32
- startTime: string;
33
- /** ISO timestamp when the span ended. */
34
- endTime: string;
35
- /** Optional tool name for function/tool spans. */
36
- toolName?: string;
37
- /** Optional handoff target agent name. */
38
- handoffTarget?: string;
39
- /** Extra provider-specific metadata. */
40
- metadata?: Record<string, unknown>;
41
- }
42
-
43
- /** Conduit write result — only used internally for error handling. */
44
- interface WriteResult {
45
- written: boolean;
46
- error?: string;
47
- }
48
-
49
- /**
50
- * Write a single span event to conduit via `cleo` CLI transport.
51
- *
52
- * Falls back gracefully when conduit is unavailable. All errors are caught
53
- * and returned in the result rather than thrown.
54
- *
55
- * @param event - The span event to persist.
56
- * @returns Result indicating whether the write succeeded.
57
- *
58
- * @remarks
59
- * The current implementation writes to conduit using the `cleo conduit send`
60
- * CLI command. This keeps the trace writer free of direct DB dependencies and
61
- * consistent with the no-direct-SQLite rule (ADR).
62
- *
63
- * When conduit grows a native TS API this writer can be updated without
64
- * changing caller code.
65
- */
66
- export async function writeSpanToConduit(event: ConduitSpanEvent): Promise<WriteResult> {
67
- try {
68
- const { exec } = await import('node:child_process');
69
- const { promisify } = await import('node:util');
70
- const execAsync = promisify(exec);
71
-
72
- const payload = JSON.stringify({
73
- type: 'agent_span',
74
- version: '1',
75
- ...event,
76
- });
77
-
78
- // Use the CLEO conduit send command which handles DB access via the
79
- // business logic layer (no direct SQLite per ADR-013 §9).
80
- await execAsync(`cleo conduit send --type agent_span --payload ${JSON.stringify(payload)}`);
81
- return { written: true };
82
- } catch (err: unknown) {
83
- const message = err instanceof Error ? err.message : String(err);
84
- return { written: false, error: message };
85
- }
86
- }
87
-
88
- /**
89
- * Write multiple span events to conduit, swallowing individual write failures.
90
- *
91
- * @param events - Array of span events to persist.
92
- * @returns Number of events successfully written.
93
- */
94
- export async function writeSpanBatchToConduit(events: ConduitSpanEvent[]): Promise<number> {
95
- let written = 0;
96
- for (const event of events) {
97
- const result = await writeSpanToConduit(event);
98
- if (result.written) written++;
99
- }
100
- return written;
101
- }