@padua/cli 2.0.25 → 2.2.0
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 +12 -3
- package/dist/mcp/code-mode/executor.d.ts +32 -0
- package/dist/mcp/code-mode/executor.d.ts.map +1 -0
- package/dist/mcp/code-mode/executor.js +173 -0
- package/dist/mcp/code-mode/executor.js.map +1 -0
- package/dist/mcp/code-mode/index.d.ts +12 -0
- package/dist/mcp/code-mode/index.d.ts.map +1 -0
- package/dist/mcp/code-mode/index.js +11 -0
- package/dist/mcp/code-mode/index.js.map +1 -0
- package/dist/mcp/code-mode/interface-generator.d.ts +38 -0
- package/dist/mcp/code-mode/interface-generator.d.ts.map +1 -0
- package/dist/mcp/code-mode/interface-generator.js +159 -0
- package/dist/mcp/code-mode/interface-generator.js.map +1 -0
- package/dist/mcp/code-mode/provider.d.ts +24 -0
- package/dist/mcp/code-mode/provider.d.ts.map +1 -0
- package/dist/mcp/code-mode/provider.js +93 -0
- package/dist/mcp/code-mode/provider.js.map +1 -0
- package/dist/mcp/code-mode/search.d.ts +32 -0
- package/dist/mcp/code-mode/search.d.ts.map +1 -0
- package/dist/mcp/code-mode/search.js +47 -0
- package/dist/mcp/code-mode/search.js.map +1 -0
- package/dist/mcp/code-mode/tool-registry.d.ts +44 -0
- package/dist/mcp/code-mode/tool-registry.d.ts.map +1 -0
- package/dist/mcp/code-mode/tool-registry.js +196 -0
- package/dist/mcp/code-mode/tool-registry.js.map +1 -0
- package/dist/mcp/code-mode/types.d.ts +41 -0
- package/dist/mcp/code-mode/types.d.ts.map +1 -0
- package/dist/mcp/code-mode/types.js +8 -0
- package/dist/mcp/code-mode/types.js.map +1 -0
- package/dist/mcp/daemon/entry.js +8 -1
- package/dist/mcp/daemon/entry.js.map +1 -1
- package/dist/mcp/providers/atlassian/tools/confluence.d.ts.map +1 -1
- package/dist/mcp/providers/atlassian/tools/confluence.js +17 -9
- package/dist/mcp/providers/atlassian/tools/confluence.js.map +1 -1
- package/dist/mcp/providers/atlassian/tools/jira.d.ts.map +1 -1
- package/dist/mcp/providers/atlassian/tools/jira.js +33 -14
- package/dist/mcp/providers/atlassian/tools/jira.js.map +1 -1
- package/dist/mcp/providers/gitlab/tools/issues.d.ts.map +1 -1
- package/dist/mcp/providers/gitlab/tools/issues.js +9 -5
- package/dist/mcp/providers/gitlab/tools/issues.js.map +1 -1
- package/dist/mcp/providers/gitlab/tools/merge-requests.js +31 -14
- package/dist/mcp/providers/gitlab/tools/merge-requests.js.map +1 -1
- package/dist/mcp/providers/gitlab/tools/pipelines.d.ts.map +1 -1
- package/dist/mcp/providers/gitlab/tools/pipelines.js +9 -5
- package/dist/mcp/providers/gitlab/tools/pipelines.js.map +1 -1
- package/dist/mcp/providers/gitlab/tools/repository.d.ts.map +1 -1
- package/dist/mcp/providers/gitlab/tools/repository.js +122 -96
- package/dist/mcp/providers/gitlab/tools/repository.js.map +1 -1
- package/dist/mcp/providers/tool-helpers.d.ts +33 -8
- package/dist/mcp/providers/tool-helpers.d.ts.map +1 -1
- package/dist/mcp/providers/tool-helpers.js +58 -4
- package/dist/mcp/providers/tool-helpers.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -56,14 +56,14 @@ The `init` command will:
|
|
|
56
56
|
| **Tunnel** | RDS | Secure tunnels to RDS/Aurora databases via SSM |
|
|
57
57
|
| | LB | Port forwarding to internal ALB via SSM |
|
|
58
58
|
| **Exec** | ECS | Interactive shell in running ECS containers via SSM |
|
|
59
|
-
| **MCP** | Server | Built-in MCP server with
|
|
59
|
+
| **MCP** | Server | Built-in MCP server with 51 tools — GitLab, Atlassian, and code execution |
|
|
60
60
|
| | Daemon | Background process management via `padua login` |
|
|
61
61
|
| | Diagnostics | MCP health checks via `padua doctor` |
|
|
62
62
|
| | Migration | Token migration from legacy Go server |
|
|
63
63
|
|
|
64
64
|
## MCP Server
|
|
65
65
|
|
|
66
|
-
`@padua/cli` v2 includes a built-in [MCP](https://modelcontextprotocol.io/) (Model Context Protocol) server that exposes
|
|
66
|
+
`@padua/cli` v2 includes a built-in [MCP](https://modelcontextprotocol.io/) (Model Context Protocol) server that exposes 51 tools and 6 resource templates for GitLab, Atlassian, and code execution. Any MCP-compatible client — Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, etc. — can call these tools directly.
|
|
67
67
|
|
|
68
68
|
### Setup
|
|
69
69
|
|
|
@@ -108,6 +108,8 @@ Steps 5-7 are non-blocking — if a provider fails, the rest of Padua still work
|
|
|
108
108
|
- **Auth:** `Authorization: Bearer padua-mcp-local` (fixed token — the server only binds to localhost)
|
|
109
109
|
- **Tokens:** OAuth tokens persisted to `~/.padua/tokens.db` (AES-256-GCM encrypted), proactively refreshed before expiry and lazily refreshed on tool calls
|
|
110
110
|
- **Sessions:** Multi-session support — multiple Claude Code instances share the daemon concurrently, each with an independent session. Stale sessions are swept after 30 minutes, max 10 concurrent sessions with LRU eviction
|
|
111
|
+
- **Response format:** All tools default to TOON (Token-Oriented Object Notation) for 40-60% token savings on list/search responses. Pass `"format": "json"` on any tool call to receive raw JSON instead
|
|
112
|
+
- **Code mode:** `call_tool_chain` executes JavaScript in a secure V8 sandbox with all MCP tools available as synchronous namespaced functions (`gitlab.*`, `jira.*`, `confluence.*`). `search_tools` provides keyword search over all registered tools
|
|
111
113
|
|
|
112
114
|
### IDE Configuration
|
|
113
115
|
|
|
@@ -266,6 +268,13 @@ curl -X POST http://127.0.0.1:8919/mcp \
|
|
|
266
268
|
| `atlassian_confluence_get_space` | Get space details by key |
|
|
267
269
|
| `atlassian_confluence_search_content` | Search page content |
|
|
268
270
|
|
|
271
|
+
#### Code Mode (2 tools)
|
|
272
|
+
|
|
273
|
+
| Tool | Description |
|
|
274
|
+
|------|-------------|
|
|
275
|
+
| `call_tool_chain` | Execute JavaScript in a secure isolated-vm V8 sandbox with all MCP tools available as synchronous namespaced functions (`gitlab.*`, `jira.*`, `confluence.*`). Supports configurable timeout and memory limit. Use `__interfaces` or `__getToolInterface(name)` for tool schema introspection |
|
|
276
|
+
| `search_tools` | Search registered MCP tools by keyword — matches against name and description, returns full schema information |
|
|
277
|
+
|
|
269
278
|
### Resource Templates
|
|
270
279
|
|
|
271
280
|
Resources provide direct read access to specific entities by URI:
|
|
@@ -303,7 +312,7 @@ Returns:
|
|
|
303
312
|
"atlassian": "ready"
|
|
304
313
|
},
|
|
305
314
|
"uptime": 3600,
|
|
306
|
-
"version": "2.0
|
|
315
|
+
"version": "2.2.0"
|
|
307
316
|
}
|
|
308
317
|
```
|
|
309
318
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeExecutor — orchestrates the isolated-vm sandbox for code execution.
|
|
3
|
+
*
|
|
4
|
+
* Creates a fresh V8 isolate per execution, bridges all registered MCP tools
|
|
5
|
+
* as synchronous namespaced functions, captures console output, and disposes
|
|
6
|
+
* the isolate in a finally block.
|
|
7
|
+
*
|
|
8
|
+
* Security contract:
|
|
9
|
+
* - No filesystem access: isolated-vm provides no fs module by default
|
|
10
|
+
* - No network access: no require/import available inside the isolate
|
|
11
|
+
* - No Node.js built-ins: the sandbox only has JS builtins + bridged tools
|
|
12
|
+
*/
|
|
13
|
+
import type { ToolEntry, ExecutionResult, ExecutionOptions } from './types.js';
|
|
14
|
+
export declare class CodeExecutor {
|
|
15
|
+
private readonly tools;
|
|
16
|
+
constructor(tools: ToolEntry[]);
|
|
17
|
+
/**
|
|
18
|
+
* Execute caller-supplied JavaScript code in an isolated V8 sandbox.
|
|
19
|
+
*
|
|
20
|
+
* All registered MCP tools are available as synchronous functions inside
|
|
21
|
+
* the sandbox under their namespace (gitlab.*, jira.*, confluence.*).
|
|
22
|
+
*
|
|
23
|
+
* @param code JavaScript/TypeScript code to execute.
|
|
24
|
+
* @param options Execution options (timeout, memory limit).
|
|
25
|
+
* @returns Execution result and captured console logs.
|
|
26
|
+
*/
|
|
27
|
+
execute(code: string, options?: ExecutionOptions): Promise<ExecutionResult>;
|
|
28
|
+
private setupConsoleBridge;
|
|
29
|
+
private setupToolBridges;
|
|
30
|
+
private setupIntrospection;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/mcp/code-mode/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAM/E,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,SAAS,EAAE;IAE/C;;;;;;;;;OASG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;YAkEvE,kBAAkB;YAmClB,gBAAgB;YAqDhB,kBAAkB;CAoBjC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeExecutor — orchestrates the isolated-vm sandbox for code execution.
|
|
3
|
+
*
|
|
4
|
+
* Creates a fresh V8 isolate per execution, bridges all registered MCP tools
|
|
5
|
+
* as synchronous namespaced functions, captures console output, and disposes
|
|
6
|
+
* the isolate in a finally block.
|
|
7
|
+
*
|
|
8
|
+
* Security contract:
|
|
9
|
+
* - No filesystem access: isolated-vm provides no fs module by default
|
|
10
|
+
* - No network access: no require/import available inside the isolate
|
|
11
|
+
* - No Node.js built-ins: the sandbox only has JS builtins + bridged tools
|
|
12
|
+
*/
|
|
13
|
+
import ivm from 'isolated-vm';
|
|
14
|
+
import { InterfaceGenerator } from './interface-generator.js';
|
|
15
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
16
|
+
const DEFAULT_MEMORY_LIMIT_MB = 128;
|
|
17
|
+
export class CodeExecutor {
|
|
18
|
+
tools;
|
|
19
|
+
constructor(tools) {
|
|
20
|
+
this.tools = tools;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Execute caller-supplied JavaScript code in an isolated V8 sandbox.
|
|
24
|
+
*
|
|
25
|
+
* All registered MCP tools are available as synchronous functions inside
|
|
26
|
+
* the sandbox under their namespace (gitlab.*, jira.*, confluence.*).
|
|
27
|
+
*
|
|
28
|
+
* @param code JavaScript/TypeScript code to execute.
|
|
29
|
+
* @param options Execution options (timeout, memory limit).
|
|
30
|
+
* @returns Execution result and captured console logs.
|
|
31
|
+
*/
|
|
32
|
+
async execute(code, options = {}) {
|
|
33
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
34
|
+
const memoryLimit = options.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
|
|
35
|
+
const logs = [];
|
|
36
|
+
const isolate = new ivm.Isolate({ memoryLimit });
|
|
37
|
+
try {
|
|
38
|
+
const context = await isolate.createContext();
|
|
39
|
+
const jail = context.global;
|
|
40
|
+
// Self-reference so sandboxed code can access `global.x = ...`
|
|
41
|
+
await jail.set('global', jail.derefInto());
|
|
42
|
+
await this.setupConsoleBridge(isolate, context, jail, logs);
|
|
43
|
+
await this.setupToolBridges(isolate, context, jail);
|
|
44
|
+
await this.setupIntrospection(isolate, context, jail);
|
|
45
|
+
// Wrap user code so we can extract a return value across the isolate boundary.
|
|
46
|
+
// The result is serialised as JSON to avoid transferring non-transferable objects.
|
|
47
|
+
const wrappedCode = `
|
|
48
|
+
(function() {
|
|
49
|
+
var __result = (function() {
|
|
50
|
+
${code}
|
|
51
|
+
})();
|
|
52
|
+
return JSON.stringify({ __result: __result === undefined ? null : __result });
|
|
53
|
+
})()
|
|
54
|
+
`;
|
|
55
|
+
const script = await isolate.compileScript(wrappedCode);
|
|
56
|
+
const resultJson = await script.run(context, { timeout });
|
|
57
|
+
let result = null;
|
|
58
|
+
if (typeof resultJson === 'string') {
|
|
59
|
+
try {
|
|
60
|
+
result = JSON.parse(resultJson).__result;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
result = resultJson;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
result = resultJson;
|
|
68
|
+
}
|
|
69
|
+
return { result, logs };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
73
|
+
return {
|
|
74
|
+
result: null,
|
|
75
|
+
logs: [...logs, `[ERROR] Code execution failed: ${msg}`],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
// Isolate may already be disposed (e.g. on OOM) — guard against double-dispose
|
|
80
|
+
try {
|
|
81
|
+
if (!isolate.isDisposed) {
|
|
82
|
+
isolate.dispose();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore dispose errors — isolate is already gone
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Console bridge
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
async setupConsoleBridge(isolate, context, jail, logs) {
|
|
94
|
+
const makeHandler = (prefix) => new ivm.Reference((...args) => {
|
|
95
|
+
const parts = args.map(a => typeof a === 'object' && a !== null ? JSON.stringify(a, null, 2) : String(a));
|
|
96
|
+
const message = parts.join(' ');
|
|
97
|
+
logs.push(prefix ? `${prefix} ${message}` : message);
|
|
98
|
+
});
|
|
99
|
+
await jail.set('__logRef', makeHandler(''));
|
|
100
|
+
await jail.set('__warnRef', makeHandler('[WARN]'));
|
|
101
|
+
await jail.set('__errorRef', makeHandler('[ERROR]'));
|
|
102
|
+
const consoleScript = await isolate.compileScript(`
|
|
103
|
+
const __stringify = (a) => typeof a === 'object' && a !== null ? JSON.stringify(a, null, 2) : String(a);
|
|
104
|
+
global.console = {
|
|
105
|
+
log: (...args) => __logRef.applySync(undefined, args.map(__stringify)),
|
|
106
|
+
warn: (...args) => __warnRef.applySync(undefined, args.map(__stringify)),
|
|
107
|
+
error: (...args) => __errorRef.applySync(undefined, args.map(__stringify)),
|
|
108
|
+
info: (...args) => __logRef.applySync(undefined, args.map(__stringify)),
|
|
109
|
+
};
|
|
110
|
+
`);
|
|
111
|
+
await consoleScript.run(context);
|
|
112
|
+
}
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Tool bridges
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
async setupToolBridges(isolate, context, jail) {
|
|
117
|
+
// Single reference handles all tool calls; tool name + args passed as JSON
|
|
118
|
+
const toolCallerRef = new ivm.Reference(async (toolName, argsJson) => {
|
|
119
|
+
const tool = this.tools.find(t => t.name === toolName);
|
|
120
|
+
if (!tool) {
|
|
121
|
+
return JSON.stringify({ success: false, error: `Tool '${toolName}' not found` });
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const args = JSON.parse(argsJson);
|
|
125
|
+
const result = await tool.handler(args);
|
|
126
|
+
return JSON.stringify({ success: true, result });
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
130
|
+
return JSON.stringify({ success: false, error: msg });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
await jail.set('__callToolRef', toolCallerRef);
|
|
134
|
+
// Build namespace initialisation + per-tool wrapper code
|
|
135
|
+
const setupParts = [];
|
|
136
|
+
const seenNamespaces = new Set();
|
|
137
|
+
for (const tool of this.tools) {
|
|
138
|
+
const { namespace, functionName } = tool;
|
|
139
|
+
if (!seenNamespaces.has(namespace)) {
|
|
140
|
+
seenNamespaces.add(namespace);
|
|
141
|
+
setupParts.push(`global.${namespace} = global.${namespace} || {};`);
|
|
142
|
+
}
|
|
143
|
+
setupParts.push(`
|
|
144
|
+
global.${namespace}.${functionName} = function(args) {
|
|
145
|
+
var resultJson = __callToolRef.applySyncPromise(undefined, [${JSON.stringify(tool.name)}, JSON.stringify(args || {})]);
|
|
146
|
+
var parsed = JSON.parse(resultJson);
|
|
147
|
+
if (!parsed.success) throw new Error(parsed.error);
|
|
148
|
+
return parsed.result;
|
|
149
|
+
};
|
|
150
|
+
`);
|
|
151
|
+
}
|
|
152
|
+
const toolSetupScript = await isolate.compileScript(setupParts.join('\n'));
|
|
153
|
+
await toolSetupScript.run(context);
|
|
154
|
+
}
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// Introspection helpers
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
async setupIntrospection(isolate, context, jail) {
|
|
159
|
+
const generator = new InterfaceGenerator(this.tools);
|
|
160
|
+
const allInterfaces = generator.generateAll();
|
|
161
|
+
const interfaceMap = generator.buildInterfaceMap();
|
|
162
|
+
await jail.set('__interfaces', allInterfaces);
|
|
163
|
+
await jail.set('__interfaceMapJson', JSON.stringify(interfaceMap));
|
|
164
|
+
const utilScript = await isolate.compileScript(`
|
|
165
|
+
global.__getToolInterface = function(toolName) {
|
|
166
|
+
var map = JSON.parse(__interfaceMapJson);
|
|
167
|
+
return map[toolName] || null;
|
|
168
|
+
};
|
|
169
|
+
`);
|
|
170
|
+
await utilScript.run(context);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/mcp/code-mode/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,KAAkB;QAAlB,UAAK,GAAL,KAAK,CAAa;IAAG,CAAC;IAEnD;;;;;;;;;OASG;IACH,KAAK,CAAC,OAAO,CAAC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AA8E;IAEtE,KAAK,CAAC,kBAAkB,CAC9B,OAAoB,EACpB,OAAoB,EACpB,IAA8D;QAE9D,MAAM,SAAS,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrD,MAAM,aAAa,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAC9C,MAAM,YAAY,GAAG,SAAS,CAAC,iBAAiB,EAAE,CAAC;QAEnD,MAAM,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;QAC9C,MAAM,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QAEnE,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC;;;;;KAK9C,CAAC,CAAC;QACH,MAAM,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code-mode module barrel export.
|
|
3
|
+
*
|
|
4
|
+
* Exports the public API surface for the code-mode feature:
|
|
5
|
+
* - CodeModeProvider: MCP provider that registers call_tool_chain + search_tools
|
|
6
|
+
* - InstrumentedToolRegistrar: wraps a ToolRegistrar to capture tool registrations
|
|
7
|
+
* - Types used by callers
|
|
8
|
+
*/
|
|
9
|
+
export { CodeModeProvider } from './provider.js';
|
|
10
|
+
export { InstrumentedToolRegistrar, deriveNamespaceAndFunction } from './tool-registry.js';
|
|
11
|
+
export type { ToolEntry, ExecutionResult, ExecutionOptions } from './types.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mcp/code-mode/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAC3F,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code-mode module barrel export.
|
|
3
|
+
*
|
|
4
|
+
* Exports the public API surface for the code-mode feature:
|
|
5
|
+
* - CodeModeProvider: MCP provider that registers call_tool_chain + search_tools
|
|
6
|
+
* - InstrumentedToolRegistrar: wraps a ToolRegistrar to capture tool registrations
|
|
7
|
+
* - Types used by callers
|
|
8
|
+
*/
|
|
9
|
+
export { CodeModeProvider } from './provider.js';
|
|
10
|
+
export { InstrumentedToolRegistrar, deriveNamespaceAndFunction } from './tool-registry.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/code-mode/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InterfaceGenerator — converts tool Zod/JSON schemas to TypeScript interfaces.
|
|
3
|
+
*
|
|
4
|
+
* Produces TypeScript interface strings grouped by namespace so agents can
|
|
5
|
+
* understand tool parameter shapes before calling them.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolEntry } from './types.js';
|
|
8
|
+
export declare class InterfaceGenerator {
|
|
9
|
+
private readonly tools;
|
|
10
|
+
constructor(tools: ToolEntry[]);
|
|
11
|
+
/**
|
|
12
|
+
* Generate TypeScript interface definitions for all tools.
|
|
13
|
+
*
|
|
14
|
+
* Groups tools by namespace into ambient namespace declarations so that
|
|
15
|
+
* code running in the sandbox can reference `gitlab.list_issues({ ... })`.
|
|
16
|
+
*/
|
|
17
|
+
generateAll(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generate a TypeScript interface for a single tool by name.
|
|
20
|
+
*
|
|
21
|
+
* Returns a string containing the interface definition and JSDoc comment,
|
|
22
|
+
* or a comment indicating the tool was not found.
|
|
23
|
+
*/
|
|
24
|
+
generateForToolByName(toolName: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a TypeScript interface for a single ToolEntry.
|
|
27
|
+
*
|
|
28
|
+
* @param tool The tool to generate an interface for.
|
|
29
|
+
* @param indented When true, indent by 2 spaces (for namespace blocks).
|
|
30
|
+
*/
|
|
31
|
+
private generateForTool;
|
|
32
|
+
/**
|
|
33
|
+
* Return a map of tool name → interface string for all tools.
|
|
34
|
+
* Used to set up __getToolInterface() inside the sandbox.
|
|
35
|
+
*/
|
|
36
|
+
buildInterfaceMap(): Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=interface-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface-generator.d.ts","sourceRoot":"","sources":["../../../src/mcp/code-mode/interface-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAgE5C,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,SAAS,EAAE;IAE/C;;;;;OAKG;IACH,WAAW,IAAI,MAAM;IAyBrB;;;;;OAKG;IACH,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAM/C;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IA2CvB;;;OAGG;IACH,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAO5C"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InterfaceGenerator — converts tool Zod/JSON schemas to TypeScript interfaces.
|
|
3
|
+
*
|
|
4
|
+
* Produces TypeScript interface strings grouped by namespace so agents can
|
|
5
|
+
* understand tool parameter shapes before calling them.
|
|
6
|
+
*/
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Type helpers
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/** Convert a JSON Schema type descriptor to a TypeScript type string. */
|
|
11
|
+
function jsonSchemaTypeToTs(schema) {
|
|
12
|
+
if (!schema || typeof schema !== 'object')
|
|
13
|
+
return 'unknown';
|
|
14
|
+
const s = schema;
|
|
15
|
+
// Handle enum
|
|
16
|
+
if (s.enum && Array.isArray(s.enum)) {
|
|
17
|
+
return s.enum
|
|
18
|
+
.map(v => (typeof v === 'string' ? JSON.stringify(v) : String(v)))
|
|
19
|
+
.join(' | ');
|
|
20
|
+
}
|
|
21
|
+
// Handle oneOf / union
|
|
22
|
+
if (s.oneOf && Array.isArray(s.oneOf)) {
|
|
23
|
+
return s.oneOf.map(jsonSchemaTypeToTs).join(' | ');
|
|
24
|
+
}
|
|
25
|
+
switch (s.type) {
|
|
26
|
+
case 'string':
|
|
27
|
+
return 'string';
|
|
28
|
+
case 'number':
|
|
29
|
+
case 'integer':
|
|
30
|
+
return 'number';
|
|
31
|
+
case 'boolean':
|
|
32
|
+
return 'boolean';
|
|
33
|
+
case 'null':
|
|
34
|
+
return 'null';
|
|
35
|
+
case 'array': {
|
|
36
|
+
const itemType = s.items ? jsonSchemaTypeToTs(s.items) : 'unknown';
|
|
37
|
+
return `(${itemType})[]`;
|
|
38
|
+
}
|
|
39
|
+
case 'object': {
|
|
40
|
+
if (s.properties && typeof s.properties === 'object') {
|
|
41
|
+
const props = Object.entries(s.properties)
|
|
42
|
+
.map(([k, v]) => {
|
|
43
|
+
const required = Array.isArray(s.required) && s.required.includes(k);
|
|
44
|
+
return `${k}${required ? '' : '?'}: ${jsonSchemaTypeToTs(v)}`;
|
|
45
|
+
})
|
|
46
|
+
.join('; ');
|
|
47
|
+
return `{ ${props} }`;
|
|
48
|
+
}
|
|
49
|
+
return '{ [key: string]: unknown }';
|
|
50
|
+
}
|
|
51
|
+
case 'any':
|
|
52
|
+
default:
|
|
53
|
+
return 'unknown';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Escape a string for safe use inside a JSDoc comment. */
|
|
57
|
+
function escapeComment(text) {
|
|
58
|
+
return text.replace(/\*\//g, '*\\/').replace(/\n/g, ' ');
|
|
59
|
+
}
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// InterfaceGenerator
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
export class InterfaceGenerator {
|
|
64
|
+
tools;
|
|
65
|
+
constructor(tools) {
|
|
66
|
+
this.tools = tools;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate TypeScript interface definitions for all tools.
|
|
70
|
+
*
|
|
71
|
+
* Groups tools by namespace into ambient namespace declarations so that
|
|
72
|
+
* code running in the sandbox can reference `gitlab.list_issues({ ... })`.
|
|
73
|
+
*/
|
|
74
|
+
generateAll() {
|
|
75
|
+
const byNamespace = new Map();
|
|
76
|
+
for (const tool of this.tools) {
|
|
77
|
+
const ns = tool.namespace;
|
|
78
|
+
if (!byNamespace.has(ns))
|
|
79
|
+
byNamespace.set(ns, []);
|
|
80
|
+
byNamespace.get(ns).push(tool);
|
|
81
|
+
}
|
|
82
|
+
const parts = [
|
|
83
|
+
'// Auto-generated TypeScript interfaces for Padua MCP tools',
|
|
84
|
+
'',
|
|
85
|
+
];
|
|
86
|
+
for (const [ns, nsTools] of byNamespace) {
|
|
87
|
+
parts.push(`declare namespace ${ns} {`);
|
|
88
|
+
for (const tool of nsTools) {
|
|
89
|
+
parts.push(this.generateForTool(tool, true));
|
|
90
|
+
}
|
|
91
|
+
parts.push('}');
|
|
92
|
+
parts.push('');
|
|
93
|
+
}
|
|
94
|
+
return parts.join('\n');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Generate a TypeScript interface for a single tool by name.
|
|
98
|
+
*
|
|
99
|
+
* Returns a string containing the interface definition and JSDoc comment,
|
|
100
|
+
* or a comment indicating the tool was not found.
|
|
101
|
+
*/
|
|
102
|
+
generateForToolByName(toolName) {
|
|
103
|
+
const tool = this.tools.find(t => t.name === toolName);
|
|
104
|
+
if (!tool)
|
|
105
|
+
return `// Tool '${toolName}' not found`;
|
|
106
|
+
return this.generateForTool(tool, false);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generate a TypeScript interface for a single ToolEntry.
|
|
110
|
+
*
|
|
111
|
+
* @param tool The tool to generate an interface for.
|
|
112
|
+
* @param indented When true, indent by 2 spaces (for namespace blocks).
|
|
113
|
+
*/
|
|
114
|
+
generateForTool(tool, indented) {
|
|
115
|
+
const indent = indented ? ' ' : '';
|
|
116
|
+
const lines = [];
|
|
117
|
+
lines.push(`${indent}/**`);
|
|
118
|
+
lines.push(`${indent} * ${escapeComment(tool.description)}`);
|
|
119
|
+
lines.push(`${indent} * Access as: ${tool.namespace}.${tool.functionName}(args)`);
|
|
120
|
+
lines.push(`${indent} */`);
|
|
121
|
+
// Input interface name
|
|
122
|
+
const inputIfName = `${tool.functionName}Input`;
|
|
123
|
+
lines.push(`${indent}interface ${inputIfName} {`);
|
|
124
|
+
const schema = tool.inputSchema;
|
|
125
|
+
if (schema &&
|
|
126
|
+
schema.type === 'object' &&
|
|
127
|
+
schema.properties &&
|
|
128
|
+
typeof schema.properties === 'object') {
|
|
129
|
+
const props = schema.properties;
|
|
130
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
131
|
+
for (const [propName, propSchema] of Object.entries(props)) {
|
|
132
|
+
const isReq = required.includes(propName);
|
|
133
|
+
const desc = propSchema.description;
|
|
134
|
+
if (desc) {
|
|
135
|
+
lines.push(`${indent} /** ${escapeComment(String(desc))} */`);
|
|
136
|
+
}
|
|
137
|
+
lines.push(`${indent} ${propName}${isReq ? '' : '?'}: ${jsonSchemaTypeToTs(propSchema)};`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
lines.push(`${indent} [key: string]: unknown;`);
|
|
142
|
+
}
|
|
143
|
+
lines.push(`${indent}}`);
|
|
144
|
+
lines.push('');
|
|
145
|
+
return lines.join('\n');
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Return a map of tool name → interface string for all tools.
|
|
149
|
+
* Used to set up __getToolInterface() inside the sandbox.
|
|
150
|
+
*/
|
|
151
|
+
buildInterfaceMap() {
|
|
152
|
+
const map = {};
|
|
153
|
+
for (const tool of this.tools) {
|
|
154
|
+
map[tool.name] = this.generateForTool(tool, false);
|
|
155
|
+
}
|
|
156
|
+
return map;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=interface-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface-generator.js","sourceRoot":"","sources":["../../../src/mcp/code-mode/interface-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,yEAAyE;AACzE,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC5D,MAAM,CAAC,GAAG,MAAiC,CAAC;IAE5C,cAAc;IACd,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,CAAC,IAAI;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;aACjE,IAAI,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAED,uBAAuB;IACvB,IAA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AAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeModeProvider — MCP provider for code-mode execution tools.
|
|
3
|
+
*
|
|
4
|
+
* Registers two MCP tools:
|
|
5
|
+
* - call_tool_chain: execute JavaScript in an isolated V8 sandbox with
|
|
6
|
+
* all registered MCP tools available as synchronous functions
|
|
7
|
+
* - search_tools: keyword search over registered tools
|
|
8
|
+
*
|
|
9
|
+
* Implements the Provider interface and integrates via the existing
|
|
10
|
+
* ProviderRegistry → McpServerAdapter composition root.
|
|
11
|
+
*/
|
|
12
|
+
import type { Provider, ToolRegistrar } from '../providers/types.js';
|
|
13
|
+
import type { ToolEntry } from './types.js';
|
|
14
|
+
export declare class CodeModeProvider implements Provider {
|
|
15
|
+
readonly name = "code-mode";
|
|
16
|
+
private readonly executor;
|
|
17
|
+
private readonly searchIndex;
|
|
18
|
+
constructor(tools: ToolEntry[]);
|
|
19
|
+
registerTools(registrar: ToolRegistrar): void;
|
|
20
|
+
registerResources(_registrar: ToolRegistrar): void;
|
|
21
|
+
ready(): Promise<void>;
|
|
22
|
+
shutdown(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/mcp/code-mode/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAIrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAwC5C,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,QAAQ,CAAC,IAAI,eAAe;IAE5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkB;gBAElC,KAAK,EAAE,SAAS,EAAE;IAK9B,aAAa,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI;IAuC7C,iBAAiB,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI;IAI5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeModeProvider — MCP provider for code-mode execution tools.
|
|
3
|
+
*
|
|
4
|
+
* Registers two MCP tools:
|
|
5
|
+
* - call_tool_chain: execute JavaScript in an isolated V8 sandbox with
|
|
6
|
+
* all registered MCP tools available as synchronous functions
|
|
7
|
+
* - search_tools: keyword search over registered tools
|
|
8
|
+
*
|
|
9
|
+
* Implements the Provider interface and integrates via the existing
|
|
10
|
+
* ProviderRegistry → McpServerAdapter composition root.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { toMcpResult } from '../providers/tool-helpers.js';
|
|
14
|
+
import { CodeExecutor } from './executor.js';
|
|
15
|
+
import { ToolSearchIndex } from './search.js';
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Input schemas
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
const callToolChainSchema = z.object({
|
|
20
|
+
code: z
|
|
21
|
+
.string()
|
|
22
|
+
.min(1)
|
|
23
|
+
.describe('JavaScript code to execute in the sandbox. All MCP tools are available as ' +
|
|
24
|
+
'namespaced synchronous functions (e.g. gitlab.list_issues({...})). ' +
|
|
25
|
+
'Use return to return a value.'),
|
|
26
|
+
timeout: z
|
|
27
|
+
.number()
|
|
28
|
+
.int()
|
|
29
|
+
.positive()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Execution timeout in milliseconds (default: 30000)'),
|
|
32
|
+
memoryLimitMb: z
|
|
33
|
+
.number()
|
|
34
|
+
.int()
|
|
35
|
+
.positive()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('Memory limit for the sandbox in megabytes (default: 128)'),
|
|
38
|
+
});
|
|
39
|
+
const searchToolsSchema = z.object({
|
|
40
|
+
query: z
|
|
41
|
+
.string()
|
|
42
|
+
.min(1)
|
|
43
|
+
.describe('Keyword query to search for matching tools by name or description'),
|
|
44
|
+
});
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// CodeModeProvider
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
export class CodeModeProvider {
|
|
49
|
+
name = 'code-mode';
|
|
50
|
+
executor;
|
|
51
|
+
searchIndex;
|
|
52
|
+
constructor(tools) {
|
|
53
|
+
this.executor = new CodeExecutor(tools);
|
|
54
|
+
this.searchIndex = new ToolSearchIndex(tools);
|
|
55
|
+
}
|
|
56
|
+
registerTools(registrar) {
|
|
57
|
+
// call_tool_chain
|
|
58
|
+
registrar.registerTool('call_tool_chain', {
|
|
59
|
+
description: 'Execute JavaScript code in a secure isolated-vm V8 sandbox. All registered MCP tools ' +
|
|
60
|
+
'are available as synchronous namespaced functions (gitlab.*, jira.*, confluence.*). ' +
|
|
61
|
+
'Console output is captured and returned alongside the execution result. ' +
|
|
62
|
+
'Use __interfaces to see all tool type definitions, or __getToolInterface(name) ' +
|
|
63
|
+
'to look up a specific tool.',
|
|
64
|
+
inputSchema: callToolChainSchema,
|
|
65
|
+
}, async (args) => {
|
|
66
|
+
const { result, logs } = await this.executor.execute(args.code, {
|
|
67
|
+
timeout: args.timeout,
|
|
68
|
+
memoryLimitMb: args.memoryLimitMb,
|
|
69
|
+
});
|
|
70
|
+
return toMcpResult({ result, logs });
|
|
71
|
+
});
|
|
72
|
+
// search_tools
|
|
73
|
+
registrar.registerTool('search_tools', {
|
|
74
|
+
description: 'Search for registered MCP tools by keyword. Returns tools whose name or description ' +
|
|
75
|
+
'matches the query, each with its full schema information.',
|
|
76
|
+
inputSchema: searchToolsSchema,
|
|
77
|
+
annotations: { readOnlyHint: true },
|
|
78
|
+
}, async (args) => {
|
|
79
|
+
const results = this.searchIndex.search(args.query);
|
|
80
|
+
return toMcpResult(results);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
registerResources(_registrar) {
|
|
84
|
+
// No resources — code-mode is tools-only
|
|
85
|
+
}
|
|
86
|
+
async ready() {
|
|
87
|
+
// Always ready — no external service dependency
|
|
88
|
+
}
|
|
89
|
+
async shutdown() {
|
|
90
|
+
// No-op — no persistent state to clean up
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/mcp/code-mode/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CACP,4EAA4E;QAC5E,qEAAqE;QACrE,+BAA+B,CAChC;IACH,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,QAAQ,EAAE;SACV,QAAQ,CAAC,oDAAoD,CAAC;IACjE,aAAa,EAAE,CAAC;SACb,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,QAAQ,EAAE;SACV,QAAQ,CAAC,0DAA0D,CAAC;CACxE,C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