@margay/ccl-core 1.3.5-rc.6
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/INTENT-GATEWAY-GUIDE.md +82 -0
- package/QUICKSTART.md +188 -0
- package/README.md +286 -0
- package/dist/cli.js +735032 -0
- package/dist/sdk/index.d.ts +13 -0
- package/dist/sdk/index.js +12 -0
- package/dist/sdk/mcpServer.d.ts +52 -0
- package/dist/sdk/mcpServer.js +134 -0
- package/dist/sdk/query.d.ts +91 -0
- package/dist/sdk/query.js +697 -0
- package/dist/sdk/queryHandle.d.ts +41 -0
- package/dist/sdk/queryHandle.js +414 -0
- package/dist/sdk/store.d.ts +16 -0
- package/dist/sdk/store.js +73 -0
- package/dist/sdk/transport.d.ts +20 -0
- package/dist/sdk/transport.js +100 -0
- package/dist/sdk/types.d.ts +423 -0
- package/dist/sdk/types.js +16 -0
- package/dist/vendor/ripgrep/VERSION +8 -0
- package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/package.json +149 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ccl-sdk public types — the embeddable SDK form of CCL (issue: CCL 改造升级,
|
|
3
|
+
* 抽出可内嵌的 SDK 形态支撑 margay 内嵌 CoS 常驻运行).
|
|
4
|
+
*
|
|
5
|
+
* The interface shape deliberately mirrors the Anthropic Claude Agent SDK
|
|
6
|
+
* (query() + canUseTool callback + session resume) so a host like margay can
|
|
7
|
+
* keep a single call seam and swap between ccl-sdk (domestic-model customers)
|
|
8
|
+
* and the Anthropic Agent SDK (Claude customers).
|
|
9
|
+
*
|
|
10
|
+
* Wire contract: these types mirror the stream-json control protocol that
|
|
11
|
+
* cli/print.ts + cli/structuredIO.ts already speak. The SDK is the HOST side
|
|
12
|
+
* of that protocol; the CLI subprocess is the agent side. Keep field names in
|
|
13
|
+
* sync with utils/permissions/PermissionPromptToolResultSchema.ts and
|
|
14
|
+
* entrypoints/sdk/controlSchemas.ts.
|
|
15
|
+
*/
|
|
16
|
+
import type { McpSdkServerConfigWithInstance } from './mcpServer.js';
|
|
17
|
+
/** Result of the host's permission callback for one tool call. */
|
|
18
|
+
export type CanUseToolResult = {
|
|
19
|
+
behavior: 'allow';
|
|
20
|
+
/**
|
|
21
|
+
* Optionally rewrite the tool input ("modify" semantics). Omit or pass
|
|
22
|
+
* an empty object to run the tool with its original input.
|
|
23
|
+
*/
|
|
24
|
+
updatedInput?: Record<string, unknown>;
|
|
25
|
+
} | {
|
|
26
|
+
behavior: 'deny';
|
|
27
|
+
message?: string;
|
|
28
|
+
/** Also interrupt the current turn instead of letting the agent continue. */
|
|
29
|
+
interrupt?: boolean;
|
|
30
|
+
} | {
|
|
31
|
+
/**
|
|
32
|
+
* Suspend the session at this tool call (issue P0-2 pending): the tool
|
|
33
|
+
* does NOT execute, the pending approval is persisted to the session
|
|
34
|
+
* store, the subprocess is terminated, and query() ends with a
|
|
35
|
+
* `suspended` event. The host process may exit. Later, from any
|
|
36
|
+
* process, resumeWithDecision(sessionId, {behavior:'allow'|'deny'})
|
|
37
|
+
* continues the session; on allow the tool executes with exactly the
|
|
38
|
+
* recorded (or host-updated) input.
|
|
39
|
+
*/
|
|
40
|
+
behavior: 'pending';
|
|
41
|
+
};
|
|
42
|
+
export type CanUseToolContext = {
|
|
43
|
+
toolUseId: string;
|
|
44
|
+
agentId?: string;
|
|
45
|
+
/** CLI-side rule that put this call on the 'ask' path, when available. */
|
|
46
|
+
decisionReason?: string;
|
|
47
|
+
blockedPath?: string;
|
|
48
|
+
/** Permission rule suggestions the CLI offered (opaque; pass to UIs). */
|
|
49
|
+
suggestions?: unknown[];
|
|
50
|
+
};
|
|
51
|
+
export type CanUseToolFn = (toolName: string, input: Record<string, unknown>, context: CanUseToolContext) => Promise<CanUseToolResult> | CanUseToolResult;
|
|
52
|
+
export type QueryOptions = {
|
|
53
|
+
/** Working directory for the agent session. */
|
|
54
|
+
cwd?: string;
|
|
55
|
+
/** Replace the system prompt entirely (sent via initialize, no ARG_MAX limit). */
|
|
56
|
+
systemPrompt?: string;
|
|
57
|
+
/** Append to the default system prompt instead of replacing it. */
|
|
58
|
+
appendSystemPrompt?: string;
|
|
59
|
+
/** Model or routing alias, forwarded to --model. */
|
|
60
|
+
model?: string;
|
|
61
|
+
/** Tool allowlist, forwarded to --allowed-tools. */
|
|
62
|
+
allowedTools?: string[];
|
|
63
|
+
/** Tool denylist, forwarded to --disallowed-tools. */
|
|
64
|
+
disallowedTools?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Permission callback. When set, the CLI runs with
|
|
67
|
+
* --permission-prompt-tool stdio and every 'ask'-path tool call is routed
|
|
68
|
+
* here before execution. Fail-closed: throw/timeout/unrecognized result ⇒
|
|
69
|
+
* deny, the tool does not execute.
|
|
70
|
+
*/
|
|
71
|
+
canUseTool?: CanUseToolFn;
|
|
72
|
+
/**
|
|
73
|
+
* Milliseconds before an unresolved canUseTool callback is treated as a
|
|
74
|
+
* deny (fail-closed). Default 300_000. Pass 0 to disable the timeout
|
|
75
|
+
* (NOT recommended for unattended hosts).
|
|
76
|
+
*/
|
|
77
|
+
canUseToolTimeoutMs?: number;
|
|
78
|
+
/** Fixed session ID (UUID) for this session, forwarded to --session-id. */
|
|
79
|
+
sessionId?: string;
|
|
80
|
+
/** Resume an existing session by ID, forwarded to --resume. */
|
|
81
|
+
resume?: string;
|
|
82
|
+
/** With resume: fork to a new session ID instead of appending. */
|
|
83
|
+
forkSession?: boolean;
|
|
84
|
+
/** Max agentic turns for this query, forwarded to --max-turns. */
|
|
85
|
+
maxTurns?: number;
|
|
86
|
+
/** Max spend for this query, forwarded to --max-budget-usd. */
|
|
87
|
+
maxBudgetUsd?: number;
|
|
88
|
+
/** Forwarded to --permission-mode. */
|
|
89
|
+
permissionMode?: string;
|
|
90
|
+
/** Plugin directories (skills/agents/hooks), repeatable --plugin-dir. */
|
|
91
|
+
pluginDirs?: string[];
|
|
92
|
+
/** Extra directories the agent may touch, forwarded to --add-dir. */
|
|
93
|
+
addDirs?: string[];
|
|
94
|
+
/** Settings file path or JSON string, forwarded to --settings. */
|
|
95
|
+
settings?: string;
|
|
96
|
+
/** Inline agent definitions JSON, forwarded to --agents. */
|
|
97
|
+
agents?: string;
|
|
98
|
+
/** Set false to disable transcript persistence (--no-session-persistence). */
|
|
99
|
+
persistSession?: boolean;
|
|
100
|
+
/** Extra environment variables for the subprocess. */
|
|
101
|
+
env?: Record<string, string>;
|
|
102
|
+
/** Abort the whole query (kills the subprocess). */
|
|
103
|
+
signal?: AbortSignal;
|
|
104
|
+
/**
|
|
105
|
+
* Path to the CCL CLI entrypoint (dist/cli.js). Defaults to resolving
|
|
106
|
+
* "ccl" from PATH; hosts embedding a pinned build should set this.
|
|
107
|
+
*/
|
|
108
|
+
cliPath?: string;
|
|
109
|
+
/** Node/bun executable used to run cliPath. Defaults to process.execPath. */
|
|
110
|
+
execPath?: string;
|
|
111
|
+
/** Escape hatch: extra argv appended verbatim. */
|
|
112
|
+
extraArgs?: string[];
|
|
113
|
+
/** Emit `raw` passthrough events for every subprocess message. */
|
|
114
|
+
includeRaw?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* slice sdk-token-streaming (G3): emit `stream_event` deltas as they arrive (token-level
|
|
117
|
+
* streaming). Passes `--include-partial-messages` to the CLI so the subprocess streams
|
|
118
|
+
* Anthropic raw message stream events (content_block_delta/text_delta, etc.). Default off →
|
|
119
|
+
* unchanged behavior; the full-block `assistant_text` events are still emitted alongside.
|
|
120
|
+
*/
|
|
121
|
+
includePartialMessages?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* slice sdk-json-schema-output (G4): a JSON Schema for structured output. When set, the CLI
|
|
124
|
+
* validates the final result against it (retrying the model) and returns `structuredOutput` on
|
|
125
|
+
* the result event. Passed over the initialize control_request (not argv). Default → unset,
|
|
126
|
+
* unchanged behavior.
|
|
127
|
+
*/
|
|
128
|
+
jsonSchema?: Record<string, unknown>;
|
|
129
|
+
/**
|
|
130
|
+
* slice sdk-input-external-mcp (G2): external MCP servers to launch for this query, keyed by name
|
|
131
|
+
* (standard MCP config, e.g. `{ myserver: { command: 'npx', args: [...] } }`). Serialized to the
|
|
132
|
+
* CLI's `--mcp-config`. Distinct from `sdkMcpServers` (in-process host tools). Default → none.
|
|
133
|
+
*/
|
|
134
|
+
mcpServers?: Record<string, unknown>;
|
|
135
|
+
/**
|
|
136
|
+
* slice sdk-input-external-mcp (G6): full content blocks for the first user message (multimodal
|
|
137
|
+
* input, e.g. text + image). When set, REPLACES the plain `prompt` text content. Vision requires a
|
|
138
|
+
* vision-capable model. Default → the string `prompt` is sent as a single text block.
|
|
139
|
+
*/
|
|
140
|
+
promptContentBlocks?: Array<{
|
|
141
|
+
type: string;
|
|
142
|
+
[key: string]: unknown;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Explicit skills directories (issue P1-5), independent of cwd. Each dir
|
|
146
|
+
* must contain `<name>/SKILL.md` entries; the SDK wraps each as an
|
|
147
|
+
* ephemeral plugin (skills symlink) loaded via --plugin-dir, the CLI's
|
|
148
|
+
* cwd-independent skill channel.
|
|
149
|
+
*/
|
|
150
|
+
skillsDirs?: string[];
|
|
151
|
+
/**
|
|
152
|
+
* Model provider (issue P0-4). 'anthropic' maps to --base-url/--api-key
|
|
153
|
+
* (any Anthropic-protocol endpoint). 'openai-compatible' maps to CCL's
|
|
154
|
+
* gateway channel (CCL_GATEWAY_URL/CCL_GATEWAY_KEY) — CCL reaches
|
|
155
|
+
* OpenAI-compatible models through its gateway, which normalizes
|
|
156
|
+
* tool-calling and rejects models without native function calling instead
|
|
157
|
+
* of silently degrading. Omit to inherit the CLI's configured provider.
|
|
158
|
+
*/
|
|
159
|
+
provider?: ProviderConfig;
|
|
160
|
+
/** Lifecycle hooks (issue P1-6). Errors are swallowed; hooks never block a decision. */
|
|
161
|
+
hooks?: LifecycleHooks;
|
|
162
|
+
/**
|
|
163
|
+
* Session store for pending approvals + usage accumulation. Defaults to
|
|
164
|
+
* the local-file store (fileSessionStore()). Pass a custom implementation
|
|
165
|
+
* to back it with Redis/DB.
|
|
166
|
+
*/
|
|
167
|
+
store?: SessionStore;
|
|
168
|
+
/**
|
|
169
|
+
* Internal to resumeWithDecision(): the approval decision to apply to the
|
|
170
|
+
* recorded pending tool call on resume. When set, query() does not send a
|
|
171
|
+
* user prompt — the CLI auto-continues the interrupted turn.
|
|
172
|
+
*/
|
|
173
|
+
pendingDecision?: PendingDecision;
|
|
174
|
+
/**
|
|
175
|
+
* slice sdk-in-process-mcp-server (G1): host-defined in-process MCP servers. Build each with
|
|
176
|
+
* `createSdkMcpServer({ name, tools: [tool(...)] })`. The agent (in the spawned CLI subprocess)
|
|
177
|
+
* can call these tools; each call is bridged back to the host's JS handler over the control
|
|
178
|
+
* protocol AND still passes through canUseTool for gating. Omit → unchanged behavior.
|
|
179
|
+
*/
|
|
180
|
+
sdkMcpServers?: McpSdkServerConfigWithInstance[];
|
|
181
|
+
};
|
|
182
|
+
export type ProviderConfig = {
|
|
183
|
+
type: 'anthropic';
|
|
184
|
+
baseUrl?: string;
|
|
185
|
+
apiKey?: string;
|
|
186
|
+
} | {
|
|
187
|
+
type: 'openai-compatible';
|
|
188
|
+
baseUrl: string;
|
|
189
|
+
apiKey?: string;
|
|
190
|
+
};
|
|
191
|
+
export type LifecycleHooks = {
|
|
192
|
+
/**
|
|
193
|
+
* slice sdk-observability-hooks-usage (G5): once, when the first session_id is observed.
|
|
194
|
+
* Observability only (never affects control flow).
|
|
195
|
+
*/
|
|
196
|
+
onSessionStart?: (event: {
|
|
197
|
+
sessionId: string;
|
|
198
|
+
}) => void | Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* slice sdk-observability-hooks-usage (G5): when the host's prompt is submitted to the agent.
|
|
201
|
+
*/
|
|
202
|
+
onUserPromptSubmit?: (event: {
|
|
203
|
+
prompt: string;
|
|
204
|
+
sessionId?: string;
|
|
205
|
+
}) => void | Promise<void>;
|
|
206
|
+
/** After each tool execution (fires on the tool_result). */
|
|
207
|
+
onToolUse?: (event: {
|
|
208
|
+
toolUseId: string;
|
|
209
|
+
toolName?: string;
|
|
210
|
+
content: unknown;
|
|
211
|
+
isError: boolean;
|
|
212
|
+
sessionId?: string;
|
|
213
|
+
}) => void | Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* After each assistant turn (one model response). `usage` (G7) carries that turn's token usage
|
|
216
|
+
* when the assistant message reported it.
|
|
217
|
+
*/
|
|
218
|
+
onTurnEnd?: (event: {
|
|
219
|
+
turn: number;
|
|
220
|
+
sessionId?: string;
|
|
221
|
+
usage?: Usage;
|
|
222
|
+
}) => void | Promise<void>;
|
|
223
|
+
/** Once per query, on the terminal result or fatal error. */
|
|
224
|
+
onSessionEnd?: (event: {
|
|
225
|
+
sessionId?: string;
|
|
226
|
+
subtype: string;
|
|
227
|
+
isError: boolean;
|
|
228
|
+
usage?: Usage;
|
|
229
|
+
}) => void | Promise<void>;
|
|
230
|
+
};
|
|
231
|
+
/** A tool call suspended for out-of-band approval, persisted by the store. */
|
|
232
|
+
export type PendingApproval = {
|
|
233
|
+
sessionId: string;
|
|
234
|
+
requestId: string;
|
|
235
|
+
toolUseId: string;
|
|
236
|
+
toolName: string;
|
|
237
|
+
input: Record<string, unknown>;
|
|
238
|
+
createdAt: string;
|
|
239
|
+
};
|
|
240
|
+
/** Host decision applied on resume for a recorded pending approval. */
|
|
241
|
+
export type PendingDecision = {
|
|
242
|
+
behavior: 'allow';
|
|
243
|
+
/** Override the approved input; defaults to the recorded pending input. */
|
|
244
|
+
updatedInput?: Record<string, unknown>;
|
|
245
|
+
} | {
|
|
246
|
+
behavior: 'deny';
|
|
247
|
+
message?: string;
|
|
248
|
+
};
|
|
249
|
+
export type AccumulatedUsage = {
|
|
250
|
+
queries: number;
|
|
251
|
+
inputTokens: number;
|
|
252
|
+
outputTokens: number;
|
|
253
|
+
cacheCreationInputTokens: number;
|
|
254
|
+
cacheReadInputTokens: number;
|
|
255
|
+
totalCostUsd: number;
|
|
256
|
+
};
|
|
257
|
+
export type SessionStore = {
|
|
258
|
+
savePendingApproval: (record: PendingApproval) => Promise<void>;
|
|
259
|
+
loadPendingApproval: (sessionId: string) => Promise<PendingApproval | null>;
|
|
260
|
+
deletePendingApproval: (sessionId: string) => Promise<void>;
|
|
261
|
+
addUsage: (sessionId: string, usage: Usage, costUsd?: number) => Promise<AccumulatedUsage>;
|
|
262
|
+
getUsage: (sessionId: string) => Promise<AccumulatedUsage | null>;
|
|
263
|
+
};
|
|
264
|
+
/** Token usage as reported by the CLI result message (provider-raw values). */
|
|
265
|
+
export type Usage = {
|
|
266
|
+
input_tokens?: number;
|
|
267
|
+
output_tokens?: number;
|
|
268
|
+
cache_creation_input_tokens?: number;
|
|
269
|
+
cache_read_input_tokens?: number;
|
|
270
|
+
[k: string]: unknown;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Events yielded by query(). All events are JSON-serializable. This is the
|
|
274
|
+
* minimal set from the issue (P0-1) plus `permission_resolved` (audit trail)
|
|
275
|
+
* and optional `raw` passthrough.
|
|
276
|
+
*/
|
|
277
|
+
export type SDKEvent = {
|
|
278
|
+
type: 'assistant_text';
|
|
279
|
+
text: string;
|
|
280
|
+
sessionId?: string;
|
|
281
|
+
} | {
|
|
282
|
+
type: 'tool_use';
|
|
283
|
+
toolName: string;
|
|
284
|
+
input: Record<string, unknown>;
|
|
285
|
+
toolUseId: string;
|
|
286
|
+
sessionId?: string;
|
|
287
|
+
} | {
|
|
288
|
+
type: 'tool_result';
|
|
289
|
+
toolUseId: string;
|
|
290
|
+
content: unknown;
|
|
291
|
+
isError: boolean;
|
|
292
|
+
sessionId?: string;
|
|
293
|
+
} | {
|
|
294
|
+
type: 'permission_request';
|
|
295
|
+
requestId: string;
|
|
296
|
+
toolName: string;
|
|
297
|
+
input: Record<string, unknown>;
|
|
298
|
+
toolUseId: string;
|
|
299
|
+
agentId?: string;
|
|
300
|
+
} | {
|
|
301
|
+
type: 'permission_resolved';
|
|
302
|
+
requestId: string;
|
|
303
|
+
toolUseId: string;
|
|
304
|
+
behavior: 'allow' | 'deny';
|
|
305
|
+
/** Why the SDK decided this way when the host callback did not decide. */
|
|
306
|
+
failClosedReason?: string;
|
|
307
|
+
/** 'pending_decision' when resolved by resumeWithDecision, not the live callback. */
|
|
308
|
+
source?: 'callback' | 'pending_decision';
|
|
309
|
+
} | {
|
|
310
|
+
/** Terminal event of a query suspended by a pending approval (P0-2). */
|
|
311
|
+
type: 'suspended';
|
|
312
|
+
sessionId: string;
|
|
313
|
+
requestId: string;
|
|
314
|
+
toolUseId: string;
|
|
315
|
+
toolName: string;
|
|
316
|
+
input: Record<string, unknown>;
|
|
317
|
+
} | {
|
|
318
|
+
type: 'result';
|
|
319
|
+
subtype: string;
|
|
320
|
+
usage?: Usage;
|
|
321
|
+
totalCostUsd?: number;
|
|
322
|
+
numTurns?: number;
|
|
323
|
+
durationMs?: number;
|
|
324
|
+
isError: boolean;
|
|
325
|
+
sessionId?: string;
|
|
326
|
+
result?: string;
|
|
327
|
+
/**
|
|
328
|
+
* slice sdk-json-schema-output (G4): the schema-validated structured output, present only
|
|
329
|
+
* when the query was run with `jsonSchema`. undefined otherwise. subtype
|
|
330
|
+
* 'error_max_structured_output_retries' means validation failed after retries.
|
|
331
|
+
*/
|
|
332
|
+
structuredOutput?: unknown;
|
|
333
|
+
} | {
|
|
334
|
+
type: 'error';
|
|
335
|
+
message: string;
|
|
336
|
+
fatal: boolean;
|
|
337
|
+
code?: string;
|
|
338
|
+
} | {
|
|
339
|
+
type: 'raw';
|
|
340
|
+
message: Record<string, unknown>;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* slice sdk-token-streaming (G3): one Anthropic raw message stream event (token-level delta),
|
|
344
|
+
* emitted only when `includePartialMessages` is set. `event.type` is one of
|
|
345
|
+
* content_block_start / content_block_delta / content_block_stop / message_delta /
|
|
346
|
+
* message_start / message_stop; e.g. a content_block_delta carries `delta.text` (text_delta).
|
|
347
|
+
*/
|
|
348
|
+
| {
|
|
349
|
+
type: 'stream_event';
|
|
350
|
+
event: {
|
|
351
|
+
type: string;
|
|
352
|
+
[key: string]: unknown;
|
|
353
|
+
};
|
|
354
|
+
sessionId?: string;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Parsed initialize control_response payload (P1). Field shapes follow
|
|
358
|
+
* SDKControlInitializeResponseSchema in entrypoints/sdk/controlSchemas.ts.
|
|
359
|
+
*/
|
|
360
|
+
export type InitializationResult = {
|
|
361
|
+
commands?: unknown[];
|
|
362
|
+
agents?: unknown[];
|
|
363
|
+
models?: unknown[];
|
|
364
|
+
account?: Record<string, unknown>;
|
|
365
|
+
output_style?: string;
|
|
366
|
+
available_output_styles?: string[];
|
|
367
|
+
[k: string]: unknown;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Query handle (P1 sdk-query-handle): the async event stream of a query plus
|
|
371
|
+
* control methods speaking the control_request/control_response wire protocol
|
|
372
|
+
* of entrypoints/sdk/controlSchemas.ts. Control methods resolve without the
|
|
373
|
+
* host iterating events; events are buffered and replayed to the iterator so
|
|
374
|
+
* the stream is identical to the bare queryWithTransport generator.
|
|
375
|
+
*/
|
|
376
|
+
export interface Query extends AsyncGenerator<SDKEvent, void, unknown> {
|
|
377
|
+
interrupt(): Promise<unknown>;
|
|
378
|
+
setPermissionMode(mode: string): Promise<unknown>;
|
|
379
|
+
setModel(model?: string): Promise<unknown>;
|
|
380
|
+
setMaxThinkingTokens(n: number | null): Promise<unknown>;
|
|
381
|
+
mcpServerStatus(): Promise<unknown>;
|
|
382
|
+
reconnectMcpServer(name: string): Promise<unknown>;
|
|
383
|
+
toggleMcpServer(name: string, enabled: boolean): Promise<unknown>;
|
|
384
|
+
setMcpServers(servers: Record<string, unknown>): Promise<unknown>;
|
|
385
|
+
stopTask(id: string): Promise<unknown>;
|
|
386
|
+
applyFlagSettings(settings: Record<string, unknown>): Promise<unknown>;
|
|
387
|
+
/**
|
|
388
|
+
* Rewind file changes made since a user message (control_request subtype
|
|
389
|
+
* "rewind_files"; wire fields user_message_id / dry_run per
|
|
390
|
+
* entrypoints/sdk/controlSchemas.ts). Pass `{ dry_run: true }` in options
|
|
391
|
+
* for a preview. Unlike other control methods it stays callable after the
|
|
392
|
+
* result event — rewinding is a post-run operation.
|
|
393
|
+
*/
|
|
394
|
+
rewindFiles(userMessageId: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
395
|
+
initializationResult(): Promise<InitializationResult>;
|
|
396
|
+
reinitialize(): Promise<InitializationResult>;
|
|
397
|
+
supportedCommands(): Promise<unknown>;
|
|
398
|
+
supportedModels(): Promise<unknown>;
|
|
399
|
+
supportedAgents(): Promise<unknown>;
|
|
400
|
+
accountInfo(): Promise<unknown>;
|
|
401
|
+
close(): Promise<void>;
|
|
402
|
+
}
|
|
403
|
+
/** One NDJSON message to/from the subprocess. */
|
|
404
|
+
export type WireMessage = Record<string, unknown> & {
|
|
405
|
+
type: string;
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Transport seam: production uses a managed subprocess (see transport.ts);
|
|
409
|
+
* tests inject a fake. read() yields parsed inbound messages until the
|
|
410
|
+
* process/stream ends.
|
|
411
|
+
*/
|
|
412
|
+
export type Transport = {
|
|
413
|
+
read: () => AsyncIterable<WireMessage>;
|
|
414
|
+
write: (message: WireMessage) => Promise<void>;
|
|
415
|
+
/** Terminate the underlying process/stream. Idempotent. */
|
|
416
|
+
close: () => Promise<void>;
|
|
417
|
+
/** Resolves with the exit code once the underlying process ends. */
|
|
418
|
+
exited: Promise<number | null>;
|
|
419
|
+
/** Child process id when the transport wraps a real subprocess (host-side
|
|
420
|
+
* monitoring/cleanup; pgrep-by-argv is unreliable once process.title is
|
|
421
|
+
* rewritten). Absent for in-memory test transports. */
|
|
422
|
+
pid?: number;
|
|
423
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ccl-sdk public types — the embeddable SDK form of CCL (issue: CCL 改造升级,
|
|
3
|
+
* 抽出可内嵌的 SDK 形态支撑 margay 内嵌 CoS 常驻运行).
|
|
4
|
+
*
|
|
5
|
+
* The interface shape deliberately mirrors the Anthropic Claude Agent SDK
|
|
6
|
+
* (query() + canUseTool callback + session resume) so a host like margay can
|
|
7
|
+
* keep a single call seam and swap between ccl-sdk (domestic-model customers)
|
|
8
|
+
* and the Anthropic Agent SDK (Claude customers).
|
|
9
|
+
*
|
|
10
|
+
* Wire contract: these types mirror the stream-json control protocol that
|
|
11
|
+
* cli/print.ts + cli/structuredIO.ts already speak. The SDK is the HOST side
|
|
12
|
+
* of that protocol; the CLI subprocess is the agent side. Keep field names in
|
|
13
|
+
* sync with utils/permissions/PermissionPromptToolResultSchema.ts and
|
|
14
|
+
* entrypoints/sdk/controlSchemas.ts.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ripgrep 14.1.1 (rev 4649aa9700)
|
|
2
|
+
source: https://github.com/BurntSushi/ripgrep/releases/tag/14.1.1
|
|
3
|
+
fetched: 2026-07-17 (official release archives, extracted rg binaries only)
|
|
4
|
+
|
|
5
|
+
0e0cb83f5195f1f51bb8feef1fff5b0b171e82bd1db6bd35deee701a3e7102f8 arm64-darwin/rg
|
|
6
|
+
923dcc25cab57d33f4e7dd0476d4b74a554401a38817e246a8d6101dcd51c50f x64-darwin/rg
|
|
7
|
+
f401154e2393f9002ac77e419f9ee5521c18f4f8cd3e32293972f493ba06fce7 x64-linux/rg
|
|
8
|
+
f162b54de2adfc72d78adb1dbada2dedda111ae0a5e2f6e9500f4f909664c5d2 x64-win32/rg.exe
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@margay/ccl-core",
|
|
3
|
+
"version": "1.3.5-rc.6",
|
|
4
|
+
"description": "Core runtime extracted from Claude Code (ccl) for Margay integration",
|
|
5
|
+
"license": "SEE LICENSE IN README.md",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"margay": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"QUICKSTART.md",
|
|
14
|
+
"INTENT-GATEWAY-GUIDE.md"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20.0.0"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"build": "bun run scripts/build.mjs && npm run build:sdk && node scripts/check-feature-gates.mjs",
|
|
22
|
+
"prepublishOnly": "bun run build",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:smoke": "vitest run -c vitest.smoke.config.ts",
|
|
25
|
+
"build:sdk": "tsc -p tsconfig.sdk.json"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@alcalzone/ansi-tokenize": "^0.3.0",
|
|
29
|
+
"@anthropic-ai/bedrock-sdk": "^0.27.0",
|
|
30
|
+
"@anthropic-ai/sdk": "^0.39.0",
|
|
31
|
+
"@anthropic-ai/vertex-sdk": "^0.14.4",
|
|
32
|
+
"@aws-sdk/client-bedrock": "^3.1024.0",
|
|
33
|
+
"@aws-sdk/client-bedrock-runtime": "^3.1024.0",
|
|
34
|
+
"@aws-sdk/client-sts": "^3.1024.0",
|
|
35
|
+
"@aws-sdk/credential-provider-node": "^3.972.29",
|
|
36
|
+
"@aws-sdk/credential-providers": "^3.1024.0",
|
|
37
|
+
"@azure/identity": "^4.13.1",
|
|
38
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
39
|
+
"@growthbook/growthbook": "^1.6.5",
|
|
40
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
41
|
+
"@opentelemetry/api": "^1.9.1",
|
|
42
|
+
"@opentelemetry/api-logs": "^0.214.0",
|
|
43
|
+
"@opentelemetry/core": "^2.6.1",
|
|
44
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "^0.214.0",
|
|
45
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.214.0",
|
|
46
|
+
"@opentelemetry/exporter-logs-otlp-proto": "^0.214.0",
|
|
47
|
+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.214.0",
|
|
48
|
+
"@opentelemetry/exporter-metrics-otlp-http": "^0.214.0",
|
|
49
|
+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.214.0",
|
|
50
|
+
"@opentelemetry/exporter-prometheus": "^0.214.0",
|
|
51
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
|
|
52
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.214.0",
|
|
53
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.214.0",
|
|
54
|
+
"@opentelemetry/resources": "^2.6.1",
|
|
55
|
+
"@opentelemetry/sdk-logs": "^0.214.0",
|
|
56
|
+
"@opentelemetry/sdk-metrics": "^2.6.1",
|
|
57
|
+
"@opentelemetry/sdk-trace-base": "^2.6.1",
|
|
58
|
+
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
59
|
+
"@smithy/core": "^3.23.13",
|
|
60
|
+
"@smithy/node-http-handler": "^4.5.1",
|
|
61
|
+
"@vitest/coverage-v8": "3",
|
|
62
|
+
"asciichart": "^1.5.25",
|
|
63
|
+
"auto-bind": "^5.0.1",
|
|
64
|
+
"axios": "^1.14.0",
|
|
65
|
+
"bidi-js": "^1.0.3",
|
|
66
|
+
"cacache": "^20.0.4",
|
|
67
|
+
"chalk": "^5.6.2",
|
|
68
|
+
"chokidar": "^5.0.0",
|
|
69
|
+
"cli-boxes": "^4.0.1",
|
|
70
|
+
"cli-highlight": "^2.1.11",
|
|
71
|
+
"code-excerpt": "^4.0.0",
|
|
72
|
+
"diff": "^8.0.4",
|
|
73
|
+
"emoji-regex": "^10.6.0",
|
|
74
|
+
"env-paths": "^4.0.0",
|
|
75
|
+
"execa": "^9.6.1",
|
|
76
|
+
"fflate": "^0.8.2",
|
|
77
|
+
"figures": "^6.1.0",
|
|
78
|
+
"fuse.js": "^7.3.0",
|
|
79
|
+
"get-east-asian-width": "^1.5.0",
|
|
80
|
+
"google-auth-library": "^10.6.2",
|
|
81
|
+
"highlight.js": "^11.11.1",
|
|
82
|
+
"https-proxy-agent": "^9.0.0",
|
|
83
|
+
"ignore": "^7.0.5",
|
|
84
|
+
"indent-string": "^5.0.0",
|
|
85
|
+
"jsonc-parser": "^3.3.1",
|
|
86
|
+
"lodash-es": "^4.17.21",
|
|
87
|
+
"lru-cache": "^11.2.7",
|
|
88
|
+
"marked": "^17.0.5",
|
|
89
|
+
"p-map": "^7.0.4",
|
|
90
|
+
"playwright": "^1.59.1",
|
|
91
|
+
"plist": "^3.1.0",
|
|
92
|
+
"proper-lockfile": "^4.1.2",
|
|
93
|
+
"qrcode": "^1.5.4",
|
|
94
|
+
"react-reconciler": "^0.33.0",
|
|
95
|
+
"semver": "^7.7.4",
|
|
96
|
+
"sharp": "^0.34.5",
|
|
97
|
+
"shell-quote": "^1.8.3",
|
|
98
|
+
"signal-exit": "^4.1.0",
|
|
99
|
+
"stack-utils": "^2.0.6",
|
|
100
|
+
"strip-ansi": "^7.1.0",
|
|
101
|
+
"supports-hyperlinks": "^4.4.0",
|
|
102
|
+
"tree-kill": "^1.2.2",
|
|
103
|
+
"turndown": "^7.2.4",
|
|
104
|
+
"type-fest": "^5.5.0",
|
|
105
|
+
"undici": "^8.0.2",
|
|
106
|
+
"usehooks-ts": "^3.1.1",
|
|
107
|
+
"vscode-jsonrpc": "^8.2.1",
|
|
108
|
+
"vscode-languageserver-protocol": "^3.17.5",
|
|
109
|
+
"vscode-languageserver-types": "^3.17.5",
|
|
110
|
+
"wrap-ansi": "^10.0.0",
|
|
111
|
+
"ws": "^8.20.0",
|
|
112
|
+
"xss": "^1.0.15",
|
|
113
|
+
"yaml": "^2.8.3",
|
|
114
|
+
"zod": "^3.25.0"
|
|
115
|
+
},
|
|
116
|
+
"devDependencies": {
|
|
117
|
+
"@types/cacache": "^20.0.1",
|
|
118
|
+
"@types/diff": "^7.0.2",
|
|
119
|
+
"@types/lodash-es": "^4.17.12",
|
|
120
|
+
"@types/node": "^22.0.0",
|
|
121
|
+
"@types/plist": "^3.0.5",
|
|
122
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
123
|
+
"@types/qrcode": "^1.5.6",
|
|
124
|
+
"@types/react": "^19.0.0",
|
|
125
|
+
"@types/semver": "^7.7.1",
|
|
126
|
+
"@types/shell-quote": "^1.7.5",
|
|
127
|
+
"@types/turndown": "^5.0.6",
|
|
128
|
+
"@types/ws": "^8.18.1",
|
|
129
|
+
"node-pty": "^1.1.0",
|
|
130
|
+
"typescript": "^5.8.0",
|
|
131
|
+
"vitest": "^3.1.0"
|
|
132
|
+
},
|
|
133
|
+
"peerDependencies": {
|
|
134
|
+
"react": ">=18.0.0"
|
|
135
|
+
},
|
|
136
|
+
"peerDependenciesMeta": {
|
|
137
|
+
"react": {
|
|
138
|
+
"optional": true
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"exports": {
|
|
142
|
+
"./sdk": {
|
|
143
|
+
"types": "./dist/sdk/index.d.ts",
|
|
144
|
+
"import": "./dist/sdk/index.js"
|
|
145
|
+
},
|
|
146
|
+
"./dist/*": "./dist/*",
|
|
147
|
+
"./package.json": "./package.json"
|
|
148
|
+
}
|
|
149
|
+
}
|