@xioflow/kernel 0.4.0 → 0.5.1
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 +95 -3
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +94 -0
- package/dist/cli.js.map +1 -0
- package/dist/driver/node-driver.d.ts.map +1 -1
- package/dist/driver/node-driver.js +1 -30
- package/dist/driver/node-driver.js.map +1 -1
- package/dist/driver/reaper-driver.d.ts +62 -0
- package/dist/driver/reaper-driver.d.ts.map +1 -0
- package/dist/driver/reaper-driver.js +371 -0
- package/dist/driver/reaper-driver.js.map +1 -0
- package/dist/driver/spawn-support.d.ts +4 -0
- package/dist/driver/spawn-support.d.ts.map +1 -0
- package/dist/driver/spawn-support.js +31 -0
- package/dist/driver/spawn-support.js.map +1 -0
- package/dist/driver/types.d.ts +6 -2
- package/dist/driver/types.d.ts.map +1 -1
- package/dist/fault/crashpoint.d.ts +8 -0
- package/dist/fault/crashpoint.d.ts.map +1 -0
- package/dist/fault/crashpoint.js +37 -0
- package/dist/fault/crashpoint.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +49 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +233 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +32 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +255 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/native/darwin-arm64/xioflow-reaper +0 -0
- package/dist/native/darwin-x64/xioflow-reaper +0 -0
- package/dist/native/linux-arm64/xioflow-reaper +0 -0
- package/dist/native/linux-x64/xioflow-reaper +0 -0
- package/dist/otel/otlp.d.ts +37 -0
- package/dist/otel/otlp.d.ts.map +1 -0
- package/dist/otel/otlp.js +224 -0
- package/dist/otel/otlp.js.map +1 -0
- package/dist/recovery/engine.d.ts.map +1 -1
- package/dist/recovery/engine.js +2 -0
- package/dist/recovery/engine.js.map +1 -1
- package/dist/snapshot/git-shadow.d.ts +8 -0
- package/dist/snapshot/git-shadow.d.ts.map +1 -1
- package/dist/snapshot/git-shadow.js +24 -19
- package/dist/snapshot/git-shadow.js.map +1 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +5 -0
- package/dist/store/sqlite.js.map +1 -1
- package/dist/supervisor/admission.d.ts +26 -0
- package/dist/supervisor/admission.d.ts.map +1 -0
- package/dist/supervisor/admission.js +98 -0
- package/dist/supervisor/admission.js.map +1 -0
- package/dist/supervisor/finalize.d.ts +21 -0
- package/dist/supervisor/finalize.d.ts.map +1 -0
- package/dist/supervisor/finalize.js +66 -0
- package/dist/supervisor/finalize.js.map +1 -0
- package/dist/supervisor/fingerprint.d.ts +8 -0
- package/dist/supervisor/fingerprint.d.ts.map +1 -0
- package/dist/supervisor/fingerprint.js +54 -0
- package/dist/supervisor/fingerprint.js.map +1 -0
- package/dist/supervisor/process-monitor.d.ts +9 -0
- package/dist/supervisor/process-monitor.d.ts.map +1 -0
- package/dist/supervisor/process-monitor.js +230 -0
- package/dist/supervisor/process-monitor.js.map +1 -0
- package/dist/supervisor/process-output.d.ts +27 -0
- package/dist/supervisor/process-output.d.ts.map +1 -0
- package/dist/supervisor/process-output.js +102 -0
- package/dist/supervisor/process-output.js.map +1 -0
- package/dist/supervisor/process-run.d.ts +30 -0
- package/dist/supervisor/process-run.d.ts.map +1 -0
- package/dist/supervisor/process-run.js +191 -0
- package/dist/supervisor/process-run.js.map +1 -0
- package/dist/supervisor/replay.d.ts +14 -0
- package/dist/supervisor/replay.d.ts.map +1 -0
- package/dist/supervisor/replay.js +70 -0
- package/dist/supervisor/replay.js.map +1 -0
- package/dist/supervisor/rollback.d.ts +8 -0
- package/dist/supervisor/rollback.d.ts.map +1 -0
- package/dist/supervisor/rollback.js +161 -0
- package/dist/supervisor/rollback.js.map +1 -0
- package/dist/supervisor/snapshot-ops.d.ts +36 -0
- package/dist/supervisor/snapshot-ops.d.ts.map +1 -0
- package/dist/supervisor/snapshot-ops.js +243 -0
- package/dist/supervisor/snapshot-ops.js.map +1 -0
- package/dist/supervisor/supervisor.d.ts +26 -51
- package/dist/supervisor/supervisor.d.ts.map +1 -1
- package/dist/supervisor/supervisor.js +112 -1158
- package/dist/supervisor/supervisor.js.map +1 -1
- package/dist/supervisor/types.d.ts +64 -0
- package/dist/supervisor/types.d.ts.map +1 -0
- package/dist/supervisor/types.js +2 -0
- package/dist/supervisor/types.js.map +1 -0
- package/dist/testing/contract-suite.d.ts.map +1 -1
- package/dist/testing/contract-suite.js +49 -10
- package/dist/testing/contract-suite.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/workspace/read-tracking.d.ts +23 -0
- package/dist/workspace/read-tracking.d.ts.map +1 -0
- package/dist/workspace/read-tracking.js +66 -0
- package/dist/workspace/read-tracking.js.map +1 -0
- package/dist/workspace/transactions.d.ts +89 -0
- package/dist/workspace/transactions.d.ts.map +1 -0
- package/dist/workspace/transactions.js +277 -0
- package/dist/workspace/transactions.js.map +1 -0
- package/package.json +8 -2
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import readline from 'node:readline';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { ExecutionDomain } from '../domain.js';
|
|
7
|
+
import { NodePlatformDriver } from '../driver/node-driver.js';
|
|
8
|
+
import { ReaperPlatformDriver } from '../driver/reaper-driver.js';
|
|
9
|
+
import { RecoveryEngine } from '../recovery/engine.js';
|
|
10
|
+
import { exportJournalToOtlp } from '../otel/otlp.js';
|
|
11
|
+
import { ProcessSupervisor } from '../supervisor/supervisor.js';
|
|
12
|
+
import { TOOLS } from './tools.js';
|
|
13
|
+
/**
|
|
14
|
+
* MCP server(stdio,JSON-RPC 2.0,每行一条消息),零依赖。
|
|
15
|
+
*
|
|
16
|
+
* 启动顺序遵循「先恢复、再执行」(ARCHITECTURE §3.2):获取域、运行恢复引擎,然后才响应请求。
|
|
17
|
+
* stdout 只写协议消息;日志写 stderr。支持 progress 通知(请求带 progressToken 时转发输出块)
|
|
18
|
+
* 与 notifications/cancelled(取消对应的 run_command 操作,走标准停止流水线)。
|
|
19
|
+
*/
|
|
20
|
+
export const SUPPORTED_PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
21
|
+
class RpcError extends Error {
|
|
22
|
+
code;
|
|
23
|
+
constructor(code, message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.code = code;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function packageVersion() {
|
|
29
|
+
try {
|
|
30
|
+
const pkg = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../package.json');
|
|
31
|
+
return JSON.parse(fs.readFileSync(pkg, 'utf8')).version ?? 'unknown';
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return 'unknown';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function selectDriver(choice) {
|
|
38
|
+
if (choice === 'node')
|
|
39
|
+
return new NodePlatformDriver();
|
|
40
|
+
if (choice === 'reaper')
|
|
41
|
+
return new ReaperPlatformDriver();
|
|
42
|
+
return ReaperPlatformDriver.isAvailable() ? new ReaperPlatformDriver() : new NodePlatformDriver();
|
|
43
|
+
}
|
|
44
|
+
export class KernelMcpServer {
|
|
45
|
+
options;
|
|
46
|
+
log;
|
|
47
|
+
output;
|
|
48
|
+
domain;
|
|
49
|
+
supervisor;
|
|
50
|
+
driver;
|
|
51
|
+
instructions = '';
|
|
52
|
+
sessionTaskId = `mcp-session-${crypto.randomUUID()}`;
|
|
53
|
+
/** requestId → 该请求启动的操作,用于 notifications/cancelled */
|
|
54
|
+
inFlight = new Map();
|
|
55
|
+
pending = new Set();
|
|
56
|
+
constructor(options) {
|
|
57
|
+
this.options = options;
|
|
58
|
+
this.log = options.log ?? ((m) => process.stderr.write(`[xioflow-mcp] ${m}\n`));
|
|
59
|
+
this.output = options.output ?? process.stdout;
|
|
60
|
+
}
|
|
61
|
+
/** 获取域并完成恢复后开始服务;输入流结束时等待在途请求、关闭域后返回。 */
|
|
62
|
+
async serve() {
|
|
63
|
+
this.driver = selectDriver(this.options.driver);
|
|
64
|
+
this.domain = ExecutionDomain.acquire(this.options.domainPath, this.options.domainId ?? 'default');
|
|
65
|
+
try {
|
|
66
|
+
const report = await new RecoveryEngine(this.domain, this.driver).recover();
|
|
67
|
+
const isolated = report.recoveredOperations.filter((r) => r.action === 'isolated_indeterminate').length;
|
|
68
|
+
this.log(`domain ${this.options.domainPath} recovered ${report.recoveredOperations.length} operation(s), ${isolated} isolated as indeterminate`);
|
|
69
|
+
this.supervisor = new ProcessSupervisor(this.domain, this.driver);
|
|
70
|
+
this.instructions =
|
|
71
|
+
`xioflow kernel ${packageVersion()} with the ${this.driver.name} driver. ` +
|
|
72
|
+
'Use run_command instead of a plain shell when you need to know for sure what happened: reuse an opId to retry without running twice, ' +
|
|
73
|
+
'and treat "indeterminate" as "stop and ask a human", never as success or failure. ' +
|
|
74
|
+
'Use begin_transaction / commit_transaction when several agents edit the same repository.';
|
|
75
|
+
const stopExport = this.startOtlpExport();
|
|
76
|
+
const lines = readline.createInterface({ input: this.options.input ?? process.stdin, crlfDelay: Infinity });
|
|
77
|
+
for await (const line of lines) {
|
|
78
|
+
if (!line.trim())
|
|
79
|
+
continue;
|
|
80
|
+
const work = this.handleLine(line).catch((err) => this.log(`unhandled: ${err?.stack ?? err}`));
|
|
81
|
+
this.pending.add(work);
|
|
82
|
+
void work.finally(() => this.pending.delete(work));
|
|
83
|
+
}
|
|
84
|
+
await Promise.allSettled([...this.pending]);
|
|
85
|
+
await stopExport();
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
this.domain.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** 启动周期导出,返回「停止并最后导出一次」的函数;未配置时为空操作。 */
|
|
92
|
+
startOtlpExport() {
|
|
93
|
+
const otlp = this.options.otlp;
|
|
94
|
+
if (!otlp)
|
|
95
|
+
return async () => { };
|
|
96
|
+
let fromSeq = 0;
|
|
97
|
+
let running = Promise.resolve();
|
|
98
|
+
const exportOnce = () => (running = running.then(async () => {
|
|
99
|
+
try {
|
|
100
|
+
const res = await exportJournalToOtlp(this.domain, { ...otlp, fromSeq });
|
|
101
|
+
fromSeq = res.nextSeq;
|
|
102
|
+
if (res.spanCount > 0)
|
|
103
|
+
this.log(`exported ${res.spanCount} span(s) to ${otlp.endpoint}`);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
this.log(`OTLP export failed (will retry): ${err?.message ?? err}`);
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
const timer = setInterval(exportOnce, otlp.intervalMs ?? 5000);
|
|
110
|
+
timer.unref();
|
|
111
|
+
return async () => {
|
|
112
|
+
clearInterval(timer);
|
|
113
|
+
await exportOnce();
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async handleLine(line) {
|
|
117
|
+
let msg;
|
|
118
|
+
try {
|
|
119
|
+
msg = JSON.parse(line);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
this.send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof msg.method !== 'string') {
|
|
126
|
+
if (msg.id !== undefined)
|
|
127
|
+
this.log(`ignoring response to request ${String(msg.id)}`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const isNotification = msg.id === undefined || msg.id === null;
|
|
131
|
+
try {
|
|
132
|
+
const result = await this.dispatch(msg.method, msg.params ?? {}, msg.id ?? undefined);
|
|
133
|
+
if (!isNotification)
|
|
134
|
+
this.send({ jsonrpc: '2.0', id: msg.id, result });
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (isNotification) {
|
|
138
|
+
this.log(`notification ${msg.method} failed: ${err?.message ?? err}`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const code = err instanceof RpcError ? err.code : -32603;
|
|
142
|
+
this.send({ jsonrpc: '2.0', id: msg.id, error: { code, message: err?.message ?? String(err) } });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async dispatch(method, params, id) {
|
|
146
|
+
switch (method) {
|
|
147
|
+
case 'initialize': {
|
|
148
|
+
const requested = typeof params.protocolVersion === 'string' ? params.protocolVersion : '';
|
|
149
|
+
return {
|
|
150
|
+
protocolVersion: SUPPORTED_PROTOCOL_VERSIONS.includes(requested) ? requested : SUPPORTED_PROTOCOL_VERSIONS[0],
|
|
151
|
+
capabilities: { tools: { listChanged: false } },
|
|
152
|
+
serverInfo: { name: 'xioflow-kernel', title: 'xioflow supervised execution kernel', version: packageVersion() },
|
|
153
|
+
instructions: this.instructions,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
case 'notifications/initialized':
|
|
157
|
+
return undefined;
|
|
158
|
+
case 'ping':
|
|
159
|
+
return {};
|
|
160
|
+
case 'tools/list':
|
|
161
|
+
return {
|
|
162
|
+
tools: TOOLS.map(({ name, title, description, inputSchema, annotations }) => ({
|
|
163
|
+
name,
|
|
164
|
+
title,
|
|
165
|
+
description,
|
|
166
|
+
inputSchema,
|
|
167
|
+
annotations,
|
|
168
|
+
})),
|
|
169
|
+
};
|
|
170
|
+
case 'tools/call':
|
|
171
|
+
return this.callTool(params, id);
|
|
172
|
+
case 'notifications/cancelled': {
|
|
173
|
+
const opId = this.inFlight.get(String(params.requestId));
|
|
174
|
+
if (opId) {
|
|
175
|
+
this.log(`request ${params.requestId} cancelled by client (${params.reason ?? 'no reason'}), stopping ${opId}`);
|
|
176
|
+
await this.supervisor.cancelOperation(opId).catch((err) => this.log(`cancel ${opId}: ${err.message}`));
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
default:
|
|
181
|
+
throw new RpcError(-32601, `Method not found: ${method}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async callTool(params, id) {
|
|
185
|
+
const tool = TOOLS.find((t) => t.name === params?.name);
|
|
186
|
+
if (!tool)
|
|
187
|
+
throw new RpcError(-32602, `Unknown tool: ${params?.name}`);
|
|
188
|
+
const args = params.arguments ?? {};
|
|
189
|
+
const missing = (tool.inputSchema.required ?? []).filter((k) => args[k] === undefined);
|
|
190
|
+
if (missing.length > 0)
|
|
191
|
+
throw new RpcError(-32602, `${tool.name}: missing required argument(s) ${missing.join(', ')}`);
|
|
192
|
+
const progressToken = params._meta?.progressToken;
|
|
193
|
+
let progress = 0;
|
|
194
|
+
const ctx = {
|
|
195
|
+
domain: this.domain,
|
|
196
|
+
supervisor: this.supervisor,
|
|
197
|
+
driverName: this.driver.name,
|
|
198
|
+
sessionTaskId: this.sessionTaskId,
|
|
199
|
+
maxOutputChars: this.options.maxOutputChars ?? 16_000,
|
|
200
|
+
bindOperation: (opId) => {
|
|
201
|
+
if (id !== undefined)
|
|
202
|
+
this.inFlight.set(String(id), opId);
|
|
203
|
+
},
|
|
204
|
+
onChunk: progressToken === undefined
|
|
205
|
+
? undefined
|
|
206
|
+
: (stream, chunk) => {
|
|
207
|
+
progress += chunk.length;
|
|
208
|
+
this.send({
|
|
209
|
+
jsonrpc: '2.0',
|
|
210
|
+
method: 'notifications/progress',
|
|
211
|
+
params: { progressToken, progress, message: `[${stream}] ${chunk.toString('utf8').slice(0, 2000)}` },
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
try {
|
|
216
|
+
const result = await tool.call(ctx, args);
|
|
217
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result, isError: false };
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
// 工具执行失败是结果的一部分(MCP 约定),让模型看到原因而不是协议错误
|
|
221
|
+
const error = { error: err?.name ?? 'Error', message: err?.message ?? String(err) };
|
|
222
|
+
return { content: [{ type: 'text', text: JSON.stringify(error, null, 2) }], structuredContent: error, isError: true };
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
if (id !== undefined)
|
|
226
|
+
this.inFlight.delete(String(id));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
send(message) {
|
|
230
|
+
this.output.write(`${JSON.stringify(message)}\n`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,KAAK,EAAe,MAAM,YAAY,CAAC;AAEhD;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAw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,EAAE,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACpF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACxH,CAAC;gBAAS,CAAC;YACT,IAAI,EAAE,KAAK,SAAS;gBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,OAAgC;QAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ExecutionDomain } from '../domain.js';
|
|
2
|
+
import { ProcessSupervisor } from '../supervisor/supervisor.js';
|
|
3
|
+
/**
|
|
4
|
+
* MCP 工具:把内核原语暴露给任意 MCP 客户端(agent 框架、IDE、CLI agent)。
|
|
5
|
+
* 刻意不暴露 adjudicate:indeterminate 的出口是人工裁决,不交给模型。
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolContext {
|
|
8
|
+
domain: ExecutionDomain;
|
|
9
|
+
supervisor: ProcessSupervisor;
|
|
10
|
+
driverName: string;
|
|
11
|
+
sessionTaskId: string;
|
|
12
|
+
maxOutputChars: number;
|
|
13
|
+
/** 当前请求的流式输出回调(客户端带 progressToken 时才有)。 */
|
|
14
|
+
onChunk?: (stream: 'stdout' | 'stderr', chunk: Buffer) => void;
|
|
15
|
+
/** 把 opId 绑定到当前请求,使 notifications/cancelled 能取消它。 */
|
|
16
|
+
bindOperation(opId: string): void;
|
|
17
|
+
}
|
|
18
|
+
export interface ToolDefinition {
|
|
19
|
+
name: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description: string;
|
|
22
|
+
inputSchema: Record<string, unknown>;
|
|
23
|
+
annotations: {
|
|
24
|
+
readOnlyHint?: boolean;
|
|
25
|
+
destructiveHint?: boolean;
|
|
26
|
+
idempotentHint?: boolean;
|
|
27
|
+
openWorldHint?: boolean;
|
|
28
|
+
};
|
|
29
|
+
call(ctx: ToolContext, args: Record<string, any>): Promise<Record<string, unknown>>;
|
|
30
|
+
}
|
|
31
|
+
export declare const TOOLS: ToolDefinition[];
|
|
32
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/D,qDAAqD;IACrD,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAC;QAAC,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACtH,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrF;AA4ED,eAAO,MAAM,KAAK,EAAE,cAAc,EA4LjC,CAAC"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
const str = (description) => ({ type: 'string', description });
|
|
3
|
+
const strArray = (description) => ({ type: 'array', items: { type: 'string' }, description });
|
|
4
|
+
/** 每次工具调用一个 Run(Run = turn):一次 indeterminate 不会让整个会话无法继续。 */
|
|
5
|
+
function newRun(ctx, label) {
|
|
6
|
+
const store = ctx.domain.getStore();
|
|
7
|
+
if (!store.getTask(ctx.sessionTaskId)) {
|
|
8
|
+
store.saveTask({
|
|
9
|
+
id: ctx.sessionTaskId,
|
|
10
|
+
domainId: ctx.domain.domainId,
|
|
11
|
+
name: 'MCP session',
|
|
12
|
+
createdAt: new Date().toISOString(),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const runId = `${label}-${crypto.randomUUID()}`;
|
|
16
|
+
store.saveRun({
|
|
17
|
+
id: runId,
|
|
18
|
+
taskId: ctx.sessionTaskId,
|
|
19
|
+
domainId: ctx.domain.domainId,
|
|
20
|
+
owner: 'mcp',
|
|
21
|
+
status: 'running',
|
|
22
|
+
startedAt: new Date().toISOString(),
|
|
23
|
+
});
|
|
24
|
+
return runId;
|
|
25
|
+
}
|
|
26
|
+
function tail(text, max) {
|
|
27
|
+
return text.length <= max ? { text, omittedChars: 0 } : { text: text.slice(-max), omittedChars: text.length - max };
|
|
28
|
+
}
|
|
29
|
+
function summarizeProcess(ctx, opId, runId, res) {
|
|
30
|
+
const r = res;
|
|
31
|
+
const stdout = tail(r.stdout ?? '', ctx.maxOutputChars);
|
|
32
|
+
const stderr = tail(r.stderr ?? '', ctx.maxOutputChars);
|
|
33
|
+
return {
|
|
34
|
+
opId,
|
|
35
|
+
runId,
|
|
36
|
+
driver: ctx.driverName,
|
|
37
|
+
status: r.status,
|
|
38
|
+
exitCode: r.exitCode ?? null,
|
|
39
|
+
signal: r.signal ?? null,
|
|
40
|
+
replayed: r.replayed === true,
|
|
41
|
+
terminationReason: r.terminationReason,
|
|
42
|
+
reason: r.reason,
|
|
43
|
+
recoveryGuidance: r.recoveryGuidance,
|
|
44
|
+
residualProcessesReaped: r.residualProcessesReaped,
|
|
45
|
+
stdout: stdout.text,
|
|
46
|
+
stderr: stderr.text,
|
|
47
|
+
stdoutOmittedChars: stdout.omittedChars || undefined,
|
|
48
|
+
stderrOmittedChars: stderr.omittedChars || undefined,
|
|
49
|
+
stdoutRef: r.stdoutRef,
|
|
50
|
+
stderrRef: r.stderrRef,
|
|
51
|
+
durationMs: r.durationMs,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 在一个新 Run 中执行;正常返回时 Run 收尾为 succeeded(有 indeterminate 操作时内核判为 indeterminate),
|
|
56
|
+
* 抛错(准入拒绝、指纹冲突等)时收尾为 failed,不留下永远 running 的 Run。
|
|
57
|
+
*/
|
|
58
|
+
async function withRun(ctx, label, fn) {
|
|
59
|
+
const runId = newRun(ctx, label);
|
|
60
|
+
const store = ctx.domain.getStore();
|
|
61
|
+
let result;
|
|
62
|
+
try {
|
|
63
|
+
result = await fn(runId);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
store.reportRunFailed(runId);
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
store.reportRunSucceeded(runId);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
export const TOOLS = [
|
|
73
|
+
{
|
|
74
|
+
name: 'run_command',
|
|
75
|
+
title: 'Run a supervised command',
|
|
76
|
+
description: 'Run a command under the xioflow kernel: the intent is persisted before it starts, the whole process tree is stopped on timeout or cancel, and the result says "indeterminate" instead of guessing when the kernel cannot confirm what happened. Passing the same opId again returns the recorded result instead of running twice.',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
command: str('Executable to run (resolved on PATH).'),
|
|
81
|
+
args: strArray('Arguments, passed without a shell.'),
|
|
82
|
+
cwd: str('Working directory (absolute path).'),
|
|
83
|
+
opId: str('Idempotency key. Reuse it to retry safely: a recorded operation is replayed, never re-run.'),
|
|
84
|
+
timeoutMs: { type: 'integer', minimum: 1, description: 'Stop the process tree after this many milliseconds.' },
|
|
85
|
+
resources: strArray('Exclusive resources to hold while running, e.g. "workspace:write:/repo" or "port:3000".'),
|
|
86
|
+
stdin: str('Text written to stdin, which is then closed.'),
|
|
87
|
+
},
|
|
88
|
+
required: ['command', 'cwd'],
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
},
|
|
91
|
+
annotations: { destructiveHint: true, openWorldHint: true },
|
|
92
|
+
async call(ctx, args) {
|
|
93
|
+
const opId = typeof args.opId === 'string' && args.opId ? args.opId : `mcp-${crypto.randomUUID()}`;
|
|
94
|
+
ctx.bindOperation(opId);
|
|
95
|
+
return withRun(ctx, 'mcp-run', async (runId) => {
|
|
96
|
+
const res = await ctx.supervisor.executeProcess({
|
|
97
|
+
runId,
|
|
98
|
+
opId,
|
|
99
|
+
name: String(args.command),
|
|
100
|
+
command: {
|
|
101
|
+
execPath: String(args.command),
|
|
102
|
+
args: Array.isArray(args.args) ? args.args.map(String) : [],
|
|
103
|
+
cwd: String(args.cwd),
|
|
104
|
+
stdin: typeof args.stdin === 'string' ? args.stdin : undefined,
|
|
105
|
+
},
|
|
106
|
+
requiredResources: Array.isArray(args.resources) ? args.resources.map(String) : [],
|
|
107
|
+
timeoutMs: typeof args.timeoutMs === 'number' ? args.timeoutMs : undefined,
|
|
108
|
+
onStreamChunk: ctx.onChunk,
|
|
109
|
+
});
|
|
110
|
+
return summarizeProcess(ctx, opId, res.runId ?? runId, res);
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'operation_status',
|
|
116
|
+
title: 'Look up an operation',
|
|
117
|
+
description: 'Return the recorded status and result of an operation by opId, including indeterminate operations that wait for a human decision.',
|
|
118
|
+
inputSchema: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: { opId: str('Operation id returned by run_command.') },
|
|
121
|
+
required: ['opId'],
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
},
|
|
124
|
+
annotations: { readOnlyHint: true, idempotentHint: true },
|
|
125
|
+
async call(ctx, args) {
|
|
126
|
+
const op = ctx.domain.getStore().getOperation(String(args.opId));
|
|
127
|
+
if (!op)
|
|
128
|
+
return { opId: args.opId, found: false };
|
|
129
|
+
const result = op.result;
|
|
130
|
+
return {
|
|
131
|
+
opId: op.id,
|
|
132
|
+
found: true,
|
|
133
|
+
kind: op.kind,
|
|
134
|
+
status: op.status,
|
|
135
|
+
resultStatus: result?.status,
|
|
136
|
+
exitCode: result?.exitCode,
|
|
137
|
+
reason: result?.reason,
|
|
138
|
+
recoveryGuidance: result?.recoveryGuidance,
|
|
139
|
+
leasesHeld: ctx.domain
|
|
140
|
+
.getStore()
|
|
141
|
+
.getPersistedResourceLeases(ctx.domain.domainId)
|
|
142
|
+
.filter((l) => l.operationId === op.id)
|
|
143
|
+
.map((l) => l.resourceId),
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'cancel_operation',
|
|
149
|
+
title: 'Stop a running operation',
|
|
150
|
+
description: 'Stop a running operation and its whole process tree. The answer is "confirmed_stopped" only when the kernel verified nothing is left running.',
|
|
151
|
+
inputSchema: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
properties: {
|
|
154
|
+
opId: str('Operation id to stop.'),
|
|
155
|
+
graceMs: { type: 'integer', minimum: 0, description: 'Time between SIGINT and escalation (default 2000).' },
|
|
156
|
+
},
|
|
157
|
+
required: ['opId'],
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
},
|
|
160
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
161
|
+
async call(ctx, args) {
|
|
162
|
+
const res = await ctx.supervisor.cancelOperation(String(args.opId), typeof args.graceMs === 'number' ? args.graceMs : 2000);
|
|
163
|
+
return { opId: args.opId, ...res };
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'snapshot_workspace',
|
|
168
|
+
title: 'Snapshot a workspace',
|
|
169
|
+
description: 'Capture a restorable snapshot of a git working tree (tracked and untracked, ignored files excluded) without touching the index, HEAD or branches.',
|
|
170
|
+
inputSchema: {
|
|
171
|
+
type: 'object',
|
|
172
|
+
properties: { root: str('Directory inside a git working tree.') },
|
|
173
|
+
required: ['root'],
|
|
174
|
+
additionalProperties: false,
|
|
175
|
+
},
|
|
176
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
177
|
+
async call(ctx, args) {
|
|
178
|
+
const res = await withRun(ctx, 'mcp-snapshot', (runId) => ctx.supervisor.captureSnapshot({ runId, opId: `snap-${crypto.randomUUID()}`, roots: [String(args.root)] }));
|
|
179
|
+
return { status: res.status, snapshotId: res.snapshot?.id, roots: res.snapshot?.roots, error: res.errorMessage };
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'rollback_workspace',
|
|
184
|
+
title: 'Roll a workspace back to a snapshot',
|
|
185
|
+
description: 'Restore the snapshot roots and verify the result. "coverage" says how much of the change the rollback can vouch for; it is "complete" only when every operation since the snapshot ran confined.',
|
|
186
|
+
inputSchema: {
|
|
187
|
+
type: 'object',
|
|
188
|
+
properties: { snapshotId: str('Snapshot id from snapshot_workspace.') },
|
|
189
|
+
required: ['snapshotId'],
|
|
190
|
+
additionalProperties: false,
|
|
191
|
+
},
|
|
192
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
193
|
+
async call(ctx, args) {
|
|
194
|
+
const res = await withRun(ctx, 'mcp-rollback', (runId) => ctx.supervisor.rollback({ runId, opId: `rollback-${crypto.randomUUID()}`, snapshotId: String(args.snapshotId) }));
|
|
195
|
+
return { ...res };
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: 'begin_transaction',
|
|
200
|
+
title: 'Start a workspace transaction',
|
|
201
|
+
description: 'Fork a git working tree for one agent. Work inside the returned forkRoot, then commit: the change lands only if no other transaction changed what this one read or wrote.',
|
|
202
|
+
inputSchema: {
|
|
203
|
+
type: 'object',
|
|
204
|
+
properties: {
|
|
205
|
+
txId: str('Transaction id (letters, digits, ".", "_", "-").'),
|
|
206
|
+
root: str('Workspace directory inside a git working tree.'),
|
|
207
|
+
forkPath: str('Where to create the fork (must not exist).'),
|
|
208
|
+
},
|
|
209
|
+
required: ['txId', 'root', 'forkPath'],
|
|
210
|
+
additionalProperties: false,
|
|
211
|
+
},
|
|
212
|
+
annotations: { destructiveHint: false },
|
|
213
|
+
async call(ctx, args) {
|
|
214
|
+
const tx = await withRun(ctx, 'mcp-tx', (runId) => ctx.supervisor.beginWorkspaceTransaction({
|
|
215
|
+
txId: String(args.txId),
|
|
216
|
+
runId,
|
|
217
|
+
root: String(args.root),
|
|
218
|
+
forkPath: String(args.forkPath),
|
|
219
|
+
}));
|
|
220
|
+
return { ...tx };
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: 'commit_transaction',
|
|
225
|
+
title: 'Commit a workspace transaction',
|
|
226
|
+
description: 'Validate the transaction against changes committed since it began and apply it to the workspace. On conflict nothing is applied and the conflicting paths are listed.',
|
|
227
|
+
inputSchema: {
|
|
228
|
+
type: 'object',
|
|
229
|
+
properties: { txId: str('Transaction id.') },
|
|
230
|
+
required: ['txId'],
|
|
231
|
+
additionalProperties: false,
|
|
232
|
+
},
|
|
233
|
+
annotations: { destructiveHint: true },
|
|
234
|
+
async call(ctx, args) {
|
|
235
|
+
return { ...(await ctx.supervisor.commitWorkspaceTransaction(String(args.txId))) };
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: 'abort_transaction',
|
|
240
|
+
title: 'Abort a workspace transaction',
|
|
241
|
+
description: 'Discard the transaction and remove its fork. The workspace is not changed.',
|
|
242
|
+
inputSchema: {
|
|
243
|
+
type: 'object',
|
|
244
|
+
properties: { txId: str('Transaction id.'), reason: str('Why it was aborted (journaled).') },
|
|
245
|
+
required: ['txId'],
|
|
246
|
+
additionalProperties: false,
|
|
247
|
+
},
|
|
248
|
+
annotations: { destructiveHint: false, idempotentHint: false },
|
|
249
|
+
async call(ctx, args) {
|
|
250
|
+
await ctx.supervisor.abortWorkspaceTransaction(String(args.txId), typeof args.reason === 'string' ? args.reason : undefined);
|
|
251
|
+
return { txId: args.txId, aborted: true };
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
];
|
|
255
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AA+BjC,MAAM,GAAG,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;AACvE,MAAM,QAAQ,GAAG,CAAC,WAAmB,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;AAEtG,6DAA6D;AAC7D,SAAS,MAAM,CAAC,GAAgB,EAAE,KAAa;IAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IACpC,IAAI,CAAC,KAAK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,IAAI,EAAE,GAAG,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,iCAAiC,CAAC,EAAE;YAC5F,QAAQ,EAAE,CAAC,MAAM,CAAC;YAClB,oBAAoB,EAAE,KAAK;SAC5B;QACD,WAAW,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE;QAC9D,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI;YAClB,MAAM,GAAG,CAAC,UAAU,CAAC,yBAAyB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAC7H,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC5C,CAAC;KACF;CACF,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ExecutionDomain } from '../domain.js';
|
|
2
|
+
import { JournalEvent, Operation } from '../types.js';
|
|
3
|
+
export interface OtlpTraces {
|
|
4
|
+
/** ExportTraceServiceRequest 的 JSON 编码,可直接 POST 到 `<endpoint>/v1/traces`。 */
|
|
5
|
+
payload: {
|
|
6
|
+
resourceSpans: unknown[];
|
|
7
|
+
};
|
|
8
|
+
spanCount: number;
|
|
9
|
+
/** 下次增量导出的游标:传回 fromSeq 即只导出之后结束的对象。 */
|
|
10
|
+
nextSeq: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 把 journal 中在 fromSeq(含)之后结束的操作与事务转换为 OTLP traces。
|
|
14
|
+
* `lookupOperation` 通常是 `store.getOperation`。
|
|
15
|
+
*/
|
|
16
|
+
export declare function journalToOtlpTraces(options: {
|
|
17
|
+
domainId: string;
|
|
18
|
+
events: JournalEvent[];
|
|
19
|
+
lookupOperation: (opId: string) => Operation | null | undefined;
|
|
20
|
+
fromSeq?: number;
|
|
21
|
+
serviceName?: string;
|
|
22
|
+
}): OtlpTraces;
|
|
23
|
+
/**
|
|
24
|
+
* 读取域 journal 并 POST 到 OTLP/HTTP 端点(`<endpoint>/v1/traces`,JSON 编码)。
|
|
25
|
+
* 非 2xx 响应抛错,游标不前进,调用方可原样重试(span id 确定,不会产生语义重复)。
|
|
26
|
+
*/
|
|
27
|
+
export declare function exportJournalToOtlp(domain: Pick<ExecutionDomain, 'domainId' | 'getStore'>, options: {
|
|
28
|
+
endpoint: string;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
fromSeq?: number;
|
|
31
|
+
serviceName?: string;
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
spanCount: number;
|
|
35
|
+
nextSeq: number;
|
|
36
|
+
}>;
|
|
37
|
+
//# sourceMappingURL=otlp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlp.d.ts","sourceRoot":"","sources":["../../src/otel/otlp.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AA4KvE,MAAM,WAAW,UAAU;IACzB,6EAA6E;IAC7E,OAAO,EAAE;QAAE,aAAa,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;IAChE,OAAO,CAA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