sigild 0.0.1 → 0.0.2
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 +107 -34
- package/THREAT_MODEL.md +32 -15
- package/dist/src/bin/sigil-hook-post.d.ts +3 -0
- package/dist/src/bin/sigil-hook-post.d.ts.map +1 -0
- package/dist/src/bin/sigil-hook-post.js +15 -0
- package/dist/src/bin/sigil-hook-post.js.map +1 -0
- package/dist/src/bin/sigil-hook-pre.d.ts +3 -0
- package/dist/src/bin/sigil-hook-pre.d.ts.map +1 -0
- package/dist/src/bin/sigil-hook-pre.js +18 -0
- package/dist/src/bin/sigil-hook-pre.js.map +1 -0
- package/dist/src/bin/sigil-mcp.d.ts +3 -0
- package/dist/src/bin/sigil-mcp.d.ts.map +1 -0
- package/dist/src/bin/sigil-mcp.js +87 -0
- package/dist/src/bin/sigil-mcp.js.map +1 -0
- package/dist/src/bin/sigil.d.ts +3 -0
- package/dist/src/bin/sigil.d.ts.map +1 -0
- package/dist/src/bin/sigil.js +9 -0
- package/dist/src/bin/sigil.js.map +1 -0
- package/dist/src/cli/args.d.ts +26 -0
- package/dist/src/cli/args.d.ts.map +1 -0
- package/dist/src/cli/args.js +36 -0
- package/dist/src/cli/args.js.map +1 -0
- package/dist/src/cli/index.d.ts +7 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +7 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/main.d.ts +26 -0
- package/dist/src/cli/main.d.ts.map +1 -0
- package/dist/src/cli/main.js +152 -0
- package/dist/src/cli/main.js.map +1 -0
- package/dist/src/cli/paths.d.ts +17 -0
- package/dist/src/cli/paths.d.ts.map +1 -0
- package/dist/src/cli/paths.js +12 -0
- package/dist/src/cli/paths.js.map +1 -0
- package/dist/src/cli/portal.d.ts +50 -0
- package/dist/src/cli/portal.d.ts.map +1 -0
- package/dist/src/cli/portal.js +93 -0
- package/dist/src/cli/portal.js.map +1 -0
- package/dist/src/cli/status.d.ts +28 -0
- package/dist/src/cli/status.d.ts.map +1 -0
- package/dist/src/cli/status.js +59 -0
- package/dist/src/cli/status.js.map +1 -0
- package/dist/src/cli/unlock.d.ts +36 -0
- package/dist/src/cli/unlock.d.ts.map +1 -0
- package/dist/src/cli/unlock.js +77 -0
- package/dist/src/cli/unlock.js.map +1 -0
- package/dist/src/control/client.d.ts +26 -0
- package/dist/src/control/client.d.ts.map +1 -0
- package/dist/src/control/client.js +76 -0
- package/dist/src/control/client.js.map +1 -0
- package/dist/src/control/index.d.ts +4 -0
- package/dist/src/control/index.d.ts.map +1 -0
- package/dist/src/control/index.js +4 -0
- package/dist/src/control/index.js.map +1 -0
- package/dist/src/control/protocol.d.ts +54 -0
- package/dist/src/control/protocol.d.ts.map +1 -0
- package/dist/src/control/protocol.js +60 -0
- package/dist/src/control/protocol.js.map +1 -0
- package/dist/src/control/server.d.ts +52 -0
- package/dist/src/control/server.d.ts.map +1 -0
- package/dist/src/control/server.js +199 -0
- package/dist/src/control/server.js.map +1 -0
- package/dist/src/daemon/handles.d.ts +35 -6
- package/dist/src/daemon/handles.d.ts.map +1 -1
- package/dist/src/daemon/handles.js +83 -28
- package/dist/src/daemon/handles.js.map +1 -1
- package/dist/src/daemon/index.d.ts +2 -3
- package/dist/src/daemon/index.d.ts.map +1 -1
- package/dist/src/daemon/index.js +2 -3
- package/dist/src/daemon/index.js.map +1 -1
- package/dist/src/daemon/methods.d.ts +6 -0
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +13 -1
- package/dist/src/daemon/methods.js.map +1 -1
- package/dist/src/hooks/command-scanner.d.ts +5 -0
- package/dist/src/hooks/command-scanner.d.ts.map +1 -0
- package/dist/src/hooks/command-scanner.js +117 -0
- package/dist/src/hooks/command-scanner.js.map +1 -0
- package/dist/src/hooks/glob.d.ts +8 -0
- package/dist/src/hooks/glob.d.ts.map +1 -0
- package/dist/src/hooks/glob.js +98 -0
- package/dist/src/hooks/glob.js.map +1 -0
- package/dist/src/hooks/index.d.ts +9 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +9 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/install.d.ts +29 -0
- package/dist/src/hooks/install.d.ts.map +1 -0
- package/dist/src/hooks/install.js +86 -0
- package/dist/src/hooks/install.js.map +1 -0
- package/dist/src/hooks/path-blocker.d.ts +29 -0
- package/dist/src/hooks/path-blocker.d.ts.map +1 -0
- package/dist/src/hooks/path-blocker.js +59 -0
- package/dist/src/hooks/path-blocker.js.map +1 -0
- package/dist/src/hooks/post-tool-use.d.ts +13 -0
- package/dist/src/hooks/post-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/post-tool-use.js +45 -0
- package/dist/src/hooks/post-tool-use.js.map +1 -0
- package/dist/src/hooks/pre-tool-use.d.ts +8 -0
- package/dist/src/hooks/pre-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/pre-tool-use.js +38 -0
- package/dist/src/hooks/pre-tool-use.js.map +1 -0
- package/dist/src/hooks/protocol.d.ts +41 -0
- package/dist/src/hooks/protocol.d.ts.map +1 -0
- package/dist/src/hooks/protocol.js +27 -0
- package/dist/src/hooks/protocol.js.map +1 -0
- package/dist/src/hooks/redactor.d.ts +19 -0
- package/dist/src/hooks/redactor.d.ts.map +1 -0
- package/dist/src/hooks/redactor.js +71 -0
- package/dist/src/hooks/redactor.js.map +1 -0
- package/dist/src/mcp/index.d.ts +4 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/mcp/index.js +4 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/protocol.d.ts +98 -0
- package/dist/src/mcp/protocol.d.ts.map +1 -0
- package/dist/src/mcp/protocol.js +79 -0
- package/dist/src/mcp/protocol.js.map +1 -0
- package/dist/src/mcp/server.d.ts +46 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +108 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/mcp/tools.d.ts +16 -0
- package/dist/src/mcp/tools.d.ts.map +1 -0
- package/dist/src/mcp/tools.js +117 -0
- package/dist/src/mcp/tools.js.map +1 -0
- package/package.json +8 -3
- package/dist/src/bin/sigild.d.ts +0 -3
- package/dist/src/bin/sigild.d.ts.map +0 -1
- package/dist/src/bin/sigild.js +0 -30
- package/dist/src/bin/sigild.js.map +0 -1
- package/dist/src/daemon/rpc.d.ts +0 -61
- package/dist/src/daemon/rpc.d.ts.map +0 -1
- package/dist/src/daemon/rpc.js +0 -76
- package/dist/src/daemon/rpc.js.map +0 -1
- package/dist/src/daemon/runtime.d.ts +0 -40
- package/dist/src/daemon/runtime.d.ts.map +0 -1
- package/dist/src/daemon/runtime.js +0 -61
- package/dist/src/daemon/runtime.js.map +0 -1
- package/dist/src/daemon/server.d.ts +0 -53
- package/dist/src/daemon/server.d.ts.map +0 -1
- package/dist/src/daemon/server.js +0 -103
- package/dist/src/daemon/server.js.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal subset of the Model Context Protocol (MCP) wire format that sigil
|
|
3
|
+
* needs to act as a stdio tool server for Claude Code (and any other MCP
|
|
4
|
+
* client). MCP rides on JSON-RPC 2.0; this module defines the request,
|
|
5
|
+
* response, and notification shapes plus helpers for encoding.
|
|
6
|
+
*
|
|
7
|
+
* Spec reference: https://modelcontextprotocol.io/specification
|
|
8
|
+
*
|
|
9
|
+
* We implement: initialize, notifications/initialized, tools/list, tools/call.
|
|
10
|
+
* Everything else (resources, prompts, sampling, completions, logging,
|
|
11
|
+
* pagination cursors) is intentionally omitted.
|
|
12
|
+
*/
|
|
13
|
+
export const PROTOCOL_VERSION = '2025-06-18';
|
|
14
|
+
export const SERVER_INFO = {
|
|
15
|
+
name: 'sigil-mcp',
|
|
16
|
+
version: '0.0.1',
|
|
17
|
+
};
|
|
18
|
+
// Standard JSON-RPC 2.0 error codes (re-stated to keep this module self-contained).
|
|
19
|
+
export const MCP_PARSE_ERROR = -32700;
|
|
20
|
+
export const MCP_INVALID_REQUEST = -32600;
|
|
21
|
+
export const MCP_METHOD_NOT_FOUND = -32601;
|
|
22
|
+
export const MCP_INVALID_PARAMS = -32602;
|
|
23
|
+
export const MCP_INTERNAL_ERROR = -32603;
|
|
24
|
+
export function parseMessage(line) {
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(line);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { kind: 'parse_error' };
|
|
31
|
+
}
|
|
32
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
33
|
+
return { kind: 'invalid', id: null, reason: 'message must be a JSON object' };
|
|
34
|
+
}
|
|
35
|
+
const obj = parsed;
|
|
36
|
+
if (obj['jsonrpc'] !== '2.0') {
|
|
37
|
+
return { kind: 'invalid', id: extractId(obj['id']), reason: 'jsonrpc must be "2.0"' };
|
|
38
|
+
}
|
|
39
|
+
if (typeof obj['method'] !== 'string' || obj['method'].length === 0) {
|
|
40
|
+
return { kind: 'invalid', id: extractId(obj['id']), reason: 'method must be a non-empty string' };
|
|
41
|
+
}
|
|
42
|
+
// Distinguish request vs notification by presence of id.
|
|
43
|
+
if (!('id' in obj)) {
|
|
44
|
+
return {
|
|
45
|
+
kind: 'notification',
|
|
46
|
+
notification: {
|
|
47
|
+
jsonrpc: '2.0',
|
|
48
|
+
method: obj['method'],
|
|
49
|
+
...(obj['params'] !== undefined ? { params: obj['params'] } : {}),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const rawId = obj['id'];
|
|
54
|
+
if (typeof rawId !== 'string' && typeof rawId !== 'number' && rawId !== null) {
|
|
55
|
+
return { kind: 'invalid', id: null, reason: 'id must be string, number, or null' };
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
kind: 'request',
|
|
59
|
+
request: {
|
|
60
|
+
jsonrpc: '2.0',
|
|
61
|
+
id: rawId,
|
|
62
|
+
method: obj['method'],
|
|
63
|
+
...(obj['params'] !== undefined ? { params: obj['params'] } : {}),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function extractId(raw) {
|
|
68
|
+
return typeof raw === 'string' || typeof raw === 'number' || raw === null ? raw : null;
|
|
69
|
+
}
|
|
70
|
+
export function encodeSuccess(id, result) {
|
|
71
|
+
const r = { jsonrpc: '2.0', id, result };
|
|
72
|
+
return JSON.stringify(r);
|
|
73
|
+
}
|
|
74
|
+
export function encodeError(id, code, message, data) {
|
|
75
|
+
const error = data === undefined ? { code, message } : { code, message, data };
|
|
76
|
+
const r = { jsonrpc: '2.0', id, error };
|
|
77
|
+
return JSON.stringify(r);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/mcp/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;CACR,CAAC;AAqCX,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AAyCzC,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IA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AO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IAClD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MethodContext } from '../daemon/methods.js';
|
|
2
|
+
import { type McpId } from './protocol.js';
|
|
3
|
+
export interface McpServerOpts {
|
|
4
|
+
/**
|
|
5
|
+
* In-process method context: handles + audit. The MCP server invokes
|
|
6
|
+
* sign methods directly against this — no cross-process IPC.
|
|
7
|
+
*/
|
|
8
|
+
context: MethodContext;
|
|
9
|
+
/**
|
|
10
|
+
* Optional log sink for protocol-level events. Defaults to a no-op.
|
|
11
|
+
* The default binary entrypoint writes log events to stderr so they don't
|
|
12
|
+
* collide with stdio MCP traffic on stdout.
|
|
13
|
+
*/
|
|
14
|
+
onLog?: (event: McpLogEvent) => void;
|
|
15
|
+
}
|
|
16
|
+
export type McpLogEvent = {
|
|
17
|
+
kind: 'recv';
|
|
18
|
+
method: string;
|
|
19
|
+
id: McpId | null;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'send_ok';
|
|
22
|
+
id: McpId;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'send_error';
|
|
25
|
+
id: McpId;
|
|
26
|
+
code: number;
|
|
27
|
+
message: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'initialized';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Handle a single received line by dispatching it through the MCP protocol.
|
|
33
|
+
* Returns either a response string to send back, or `null` if the line was a
|
|
34
|
+
* notification (no response expected).
|
|
35
|
+
*/
|
|
36
|
+
export declare function handleLine(line: string, opts: McpServerOpts): string | null;
|
|
37
|
+
export interface McpStdioOpts extends McpServerOpts {
|
|
38
|
+
stdin: NodeJS.ReadableStream;
|
|
39
|
+
stdout: NodeJS.WritableStream;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Run the MCP server over arbitrary streams (stdin/stdout in production,
|
|
43
|
+
* mock streams in tests). Resolves when stdin closes.
|
|
44
|
+
*/
|
|
45
|
+
export declare function runMcpStdio(opts: McpStdioOpts): Promise<void>;
|
|
46
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/mcp/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAWL,KAAK,KAAK,EAEX,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC;IACvB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CACtC;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,GAAG,IAAI,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,KAAK,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAE5B;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAkC3E;AA0CD,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB7D"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { findTool, ToolError, TOOLS } from './tools.js';
|
|
2
|
+
import { encodeError, encodeSuccess, MCP_INTERNAL_ERROR, MCP_INVALID_PARAMS, MCP_INVALID_REQUEST, MCP_METHOD_NOT_FOUND, MCP_PARSE_ERROR, parseMessage, PROTOCOL_VERSION, SERVER_INFO, } from './protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handle a single received line by dispatching it through the MCP protocol.
|
|
5
|
+
* Returns either a response string to send back, or `null` if the line was a
|
|
6
|
+
* notification (no response expected).
|
|
7
|
+
*/
|
|
8
|
+
export function handleLine(line, opts) {
|
|
9
|
+
const parsed = parseMessage(line);
|
|
10
|
+
const log = (e) => opts.onLog?.(e);
|
|
11
|
+
if (parsed.kind === 'parse_error') {
|
|
12
|
+
log({ kind: 'send_error', id: null, code: MCP_PARSE_ERROR, message: 'parse error' });
|
|
13
|
+
return encodeError(null, MCP_PARSE_ERROR, 'parse error');
|
|
14
|
+
}
|
|
15
|
+
if (parsed.kind === 'invalid') {
|
|
16
|
+
log({ kind: 'send_error', id: parsed.id, code: MCP_INVALID_REQUEST, message: parsed.reason });
|
|
17
|
+
return encodeError(parsed.id, MCP_INVALID_REQUEST, parsed.reason);
|
|
18
|
+
}
|
|
19
|
+
if (parsed.kind === 'notification') {
|
|
20
|
+
log({ kind: 'recv', method: parsed.notification.method, id: null });
|
|
21
|
+
if (parsed.notification.method === 'notifications/initialized') {
|
|
22
|
+
log({ kind: 'initialized' });
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const req = parsed.request;
|
|
27
|
+
log({ kind: 'recv', method: req.method, id: req.id });
|
|
28
|
+
try {
|
|
29
|
+
const result = dispatch(req, opts);
|
|
30
|
+
log({ kind: 'send_ok', id: req.id });
|
|
31
|
+
return encodeSuccess(req.id, result);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err instanceof ToolError) {
|
|
35
|
+
log({ kind: 'send_error', id: req.id, code: err.code, message: err.message });
|
|
36
|
+
return encodeError(req.id, err.code, err.message, err.data);
|
|
37
|
+
}
|
|
38
|
+
const message = `internal error: ${err.message}`;
|
|
39
|
+
log({ kind: 'send_error', id: req.id, code: MCP_INTERNAL_ERROR, message });
|
|
40
|
+
return encodeError(req.id, MCP_INTERNAL_ERROR, message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function dispatch(req, opts) {
|
|
44
|
+
switch (req.method) {
|
|
45
|
+
case 'initialize':
|
|
46
|
+
return {
|
|
47
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
48
|
+
capabilities: { tools: { listChanged: false } },
|
|
49
|
+
serverInfo: SERVER_INFO,
|
|
50
|
+
};
|
|
51
|
+
case 'tools/list':
|
|
52
|
+
return { tools: TOOLS.map((t) => t.definition) };
|
|
53
|
+
case 'tools/call':
|
|
54
|
+
return invokeTool(req.params, opts);
|
|
55
|
+
case 'ping':
|
|
56
|
+
return {};
|
|
57
|
+
default:
|
|
58
|
+
throw new ToolError(MCP_METHOD_NOT_FOUND, `method not found: ${req.method}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function invokeTool(params, opts) {
|
|
62
|
+
if (typeof params !== 'object' || params === null || Array.isArray(params)) {
|
|
63
|
+
throw new ToolError(MCP_INVALID_PARAMS, 'tools/call: params must be an object');
|
|
64
|
+
}
|
|
65
|
+
const obj = params;
|
|
66
|
+
const name = obj['name'];
|
|
67
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
68
|
+
throw new ToolError(MCP_INVALID_PARAMS, 'tools/call: name must be a non-empty string');
|
|
69
|
+
}
|
|
70
|
+
const tool = findTool(name);
|
|
71
|
+
if (!tool) {
|
|
72
|
+
throw new ToolError(MCP_METHOD_NOT_FOUND, `unknown tool: ${name}`);
|
|
73
|
+
}
|
|
74
|
+
const args = obj['arguments'] ?? {};
|
|
75
|
+
return tool.handler(args, opts.context);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Run the MCP server over arbitrary streams (stdin/stdout in production,
|
|
79
|
+
* mock streams in tests). Resolves when stdin closes.
|
|
80
|
+
*/
|
|
81
|
+
export function runMcpStdio(opts) {
|
|
82
|
+
const { stdin, stdout } = opts;
|
|
83
|
+
stdin.setEncoding?.('utf8');
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
let buf = '';
|
|
86
|
+
let stdinEnded = false;
|
|
87
|
+
stdin.on('data', (chunk) => {
|
|
88
|
+
buf += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
89
|
+
let nl;
|
|
90
|
+
while ((nl = buf.indexOf('\n')) !== -1) {
|
|
91
|
+
const line = buf.slice(0, nl);
|
|
92
|
+
buf = buf.slice(nl + 1);
|
|
93
|
+
if (line.length === 0)
|
|
94
|
+
continue;
|
|
95
|
+
const resp = handleLine(line, opts);
|
|
96
|
+
if (resp !== null)
|
|
97
|
+
stdout.write(resp + '\n');
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
stdin.on('end', () => {
|
|
101
|
+
stdinEnded = true;
|
|
102
|
+
if (stdinEnded)
|
|
103
|
+
resolve();
|
|
104
|
+
});
|
|
105
|
+
stdin.on('error', reject);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,EACL,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,WAAW,GAGZ,MAAM,eAAe,CAAC;AAsBvB;;;;GAIG;AACH,MAAM,UAAU,UAAU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AAO,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MethodContext } from '../daemon/methods.js';
|
|
2
|
+
import { type ToolDefinition, type ToolResult } from './protocol.js';
|
|
3
|
+
export type ToolHandlerCtx = MethodContext;
|
|
4
|
+
export type ToolHandler = (args: unknown, ctx: ToolHandlerCtx) => ToolResult;
|
|
5
|
+
export interface Tool {
|
|
6
|
+
definition: ToolDefinition;
|
|
7
|
+
handler: ToolHandler;
|
|
8
|
+
}
|
|
9
|
+
export declare const TOOLS: readonly Tool[];
|
|
10
|
+
export declare function findTool(name: string): Tool | undefined;
|
|
11
|
+
export declare class ToolError extends Error {
|
|
12
|
+
readonly code: number;
|
|
13
|
+
readonly data: unknown;
|
|
14
|
+
constructor(code: number, message: string, data?: unknown);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAkB,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,KAAK,UAAU,CAAC;AAE7E,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,EAAE,WAAW,CAAC;CACtB;AA6ED,eAAO,MAAM,KAAK,EAAE,SAAS,IAAI,EAK/B,CAAC;AAEH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAEvD;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBACX,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAM1D"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { dispatch, RpcMethodError } from '../daemon/methods.js';
|
|
2
|
+
import { MCP_INTERNAL_ERROR } from './protocol.js';
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Tool definitions
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
const listPortals = {
|
|
7
|
+
definition: {
|
|
8
|
+
name: 'sigil_list_portals',
|
|
9
|
+
description: 'List the signing portals currently loaded in sigil. Returns each portal handle (e.g. "eth:executor"), its kind, and the public address it controls.',
|
|
10
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
11
|
+
},
|
|
12
|
+
handler: (args, ctx) => callMethod('sigil_list_portals', args, ctx),
|
|
13
|
+
};
|
|
14
|
+
const ethSignMessage = {
|
|
15
|
+
definition: {
|
|
16
|
+
name: 'sigil_eth_sign_message',
|
|
17
|
+
description: 'Sign an EIP-191 personal_sign message with the named portal. The message is supplied as 0x-prefixed hex bytes (encode strings to UTF-8 first). Returns the 65-byte r||s||v signature as 0x-prefixed hex.',
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
portal: { type: 'string', description: 'Portal handle, e.g. "eth:executor".' },
|
|
22
|
+
message: { type: 'string', description: '0x-prefixed hex of the bytes to sign.' },
|
|
23
|
+
},
|
|
24
|
+
required: ['portal', 'message'],
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
handler: (args, ctx) => callMethod('sigil_eth_sign_message', args, ctx),
|
|
29
|
+
};
|
|
30
|
+
const ethSignTransaction = {
|
|
31
|
+
definition: {
|
|
32
|
+
name: 'sigil_eth_sign_transaction',
|
|
33
|
+
description: 'Sign an Ethereum transaction (legacy or EIP-1559) with the named portal. Returns the signed transaction as 0x-prefixed hex, ready for eth_sendRawTransaction.',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
portal: { type: 'string', description: 'Portal handle.' },
|
|
38
|
+
tx: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
description: 'Transaction fields. type="legacy" requires {chainId, nonce, gasPrice, gasLimit, to, value, data}. type="eip1559" requires {chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList?}. Numbers may be supplied as JSON numbers or decimal strings.',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ['portal', 'tx'],
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
handler: (args, ctx) => callMethod('sigil_eth_sign_transaction', args, ctx),
|
|
48
|
+
};
|
|
49
|
+
const ethSignTypedData = {
|
|
50
|
+
definition: {
|
|
51
|
+
name: 'sigil_eth_sign_typed_data',
|
|
52
|
+
description: 'Sign an EIP-712 typed data structure with the named portal. Returns the 65-byte signature as 0x-prefixed hex.',
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
portal: { type: 'string', description: 'Portal handle.' },
|
|
57
|
+
typedData: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
description: 'EIP-712 typed data: {types, primaryType, domain, message}.',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
required: ['portal', 'typedData'],
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
handler: (args, ctx) => callMethod('sigil_eth_sign_typed_data', args, ctx),
|
|
67
|
+
};
|
|
68
|
+
export const TOOLS = Object.freeze([
|
|
69
|
+
listPortals,
|
|
70
|
+
ethSignMessage,
|
|
71
|
+
ethSignTransaction,
|
|
72
|
+
ethSignTypedData,
|
|
73
|
+
]);
|
|
74
|
+
export function findTool(name) {
|
|
75
|
+
return TOOLS.find((t) => t.definition.name === name);
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Helpers
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
export class ToolError extends Error {
|
|
81
|
+
code;
|
|
82
|
+
data;
|
|
83
|
+
constructor(code, message, data) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = 'ToolError';
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.data = data;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Call into the in-process method dispatcher and wrap the result for MCP.
|
|
92
|
+
* Maps `RpcMethodError` (raised by the dispatcher on user errors or
|
|
93
|
+
* not-found method) into `ToolError` with the same code, so the original
|
|
94
|
+
* error semantics flow through to the MCP client unchanged.
|
|
95
|
+
*/
|
|
96
|
+
function callMethod(methodName, args, ctx) {
|
|
97
|
+
try {
|
|
98
|
+
const result = dispatch(methodName, args, ctx);
|
|
99
|
+
return textResult(result);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (err instanceof RpcMethodError) {
|
|
103
|
+
throw new ToolError(err.code, err.message, err.data);
|
|
104
|
+
}
|
|
105
|
+
throw new ToolError(MCP_INTERNAL_ERROR, `internal: ${err.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function textResult(payload) {
|
|
109
|
+
// JSON-serialize the response into the MCP text content slot.
|
|
110
|
+
// We also include structuredContent so MCP clients that support it can
|
|
111
|
+
// access the typed payload directly without re-parsing.
|
|
112
|
+
return {
|
|
113
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
114
|
+
structuredContent: payload,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","s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igil",
|
|
5
|
+
"description": "Claude can sign, but never see. MCP server + CLI that keeps private keys out of the LLM's context window.",
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
7
|
"author": "Chris Doran",
|
|
7
8
|
"homepage": "https://github.com/cdrn/sigil#readme",
|
|
@@ -30,7 +31,11 @@
|
|
|
30
31
|
],
|
|
31
32
|
"type": "module",
|
|
32
33
|
"bin": {
|
|
33
|
-
"
|
|
34
|
+
"sigil": "dist/src/bin/sigil.js",
|
|
35
|
+
"sigil-mcp": "dist/src/bin/sigil-mcp.js",
|
|
36
|
+
"sigild": "dist/src/bin/sigil-mcp.js",
|
|
37
|
+
"sigil-hook-pre": "dist/src/bin/sigil-hook-pre.js",
|
|
38
|
+
"sigil-hook-post": "dist/src/bin/sigil-hook-post.js"
|
|
34
39
|
},
|
|
35
40
|
"files": [
|
|
36
41
|
"dist/src/**/*",
|
package/dist/src/bin/sigild.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sigild.d.ts","sourceRoot":"","sources":["../../../src/bin/sigild.ts"],"names":[],"mappings":""}
|
package/dist/src/bin/sigild.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { readPassphrase } from '../daemon/passphrase.js';
|
|
5
|
-
import { runDaemon } from '../daemon/runtime.js';
|
|
6
|
-
const sigilHome = process.env['SIGIL_HOME'] ?? join(homedir(), '.sigil');
|
|
7
|
-
let shutting = false;
|
|
8
|
-
async function main() {
|
|
9
|
-
const handle = await runDaemon({
|
|
10
|
-
sigilHome,
|
|
11
|
-
passphrase: () => readPassphrase('sigil passphrase: '),
|
|
12
|
-
onLog: (e) => process.stderr.write(JSON.stringify(e) + '\n'),
|
|
13
|
-
});
|
|
14
|
-
process.stderr.write(`sigild ready: ${handle.portals} portal(s) loaded, listening on ${handle.socketPath}\n`);
|
|
15
|
-
const shutdown = async (signal) => {
|
|
16
|
-
if (shutting)
|
|
17
|
-
return;
|
|
18
|
-
shutting = true;
|
|
19
|
-
process.stderr.write(`sigild: ${signal} received, shutting down\n`);
|
|
20
|
-
await handle.shutdown();
|
|
21
|
-
process.exit(0);
|
|
22
|
-
};
|
|
23
|
-
process.on('SIGINT', () => { void shutdown('SIGINT'); });
|
|
24
|
-
process.on('SIGTERM', () => { void shutdown('SIGTERM'); });
|
|
25
|
-
}
|
|
26
|
-
main().catch((err) => {
|
|
27
|
-
process.stderr.write(`sigild: ${err.message}\n`);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
});
|
|
30
|
-
//# sourceMappingURL=sigild.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sigild.js","sourceRoot":"","sources":["../../../src/bin/sigild.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AAEzE,IAAI,QAAQ,GAAG,KAAK,CAAC;AAErB,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC;QAC7B,SAAS;QACT,UAAU,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,oBAAoB,CAAC;QACtD,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;KAC7D,CAAC,CAAC;IAEH,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,iBAAiB,MAAM,CAAC,OAAO,mCAAmC,MAAM,CAAC,UAAU,IAAI,CACxF,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;QACvD,IAAI,QAAQ;YAAE,OAAO;QACrB,QAAQ,GAAG,IAAI,CAAC;QAChB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,MAAM,4BAA4B,CAAC,CAAC;QACpE,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/src/daemon/rpc.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON-RPC 2.0 over newline-delimited JSON (NDJSON).
|
|
3
|
-
* Pure functions only — no IO. The server in server.ts wires this onto sockets.
|
|
4
|
-
*
|
|
5
|
-
* We use the strict JSON-RPC 2.0 envelope: every request has `jsonrpc: "2.0"`,
|
|
6
|
-
* a method, and either an id (for requests expecting a response) or no id (for
|
|
7
|
-
* notifications, which sigil currently rejects since every sign decision needs
|
|
8
|
-
* to round-trip through the audit log).
|
|
9
|
-
*/
|
|
10
|
-
export declare const RPC_VERSION = "2.0";
|
|
11
|
-
export type RpcId = string | number | null;
|
|
12
|
-
export interface RpcRequest {
|
|
13
|
-
jsonrpc: '2.0';
|
|
14
|
-
id: RpcId;
|
|
15
|
-
method: string;
|
|
16
|
-
params: unknown;
|
|
17
|
-
}
|
|
18
|
-
export interface RpcSuccess {
|
|
19
|
-
jsonrpc: '2.0';
|
|
20
|
-
id: RpcId;
|
|
21
|
-
result: unknown;
|
|
22
|
-
}
|
|
23
|
-
export interface RpcErrorObject {
|
|
24
|
-
code: number;
|
|
25
|
-
message: string;
|
|
26
|
-
data?: unknown;
|
|
27
|
-
}
|
|
28
|
-
export interface RpcError {
|
|
29
|
-
jsonrpc: '2.0';
|
|
30
|
-
id: RpcId;
|
|
31
|
-
error: RpcErrorObject;
|
|
32
|
-
}
|
|
33
|
-
export type RpcResponse = RpcSuccess | RpcError;
|
|
34
|
-
export declare const RPC_PARSE_ERROR = -32700;
|
|
35
|
-
export declare const RPC_INVALID_REQUEST = -32600;
|
|
36
|
-
export declare const RPC_METHOD_NOT_FOUND = -32601;
|
|
37
|
-
export declare const RPC_INVALID_PARAMS = -32602;
|
|
38
|
-
export declare const RPC_INTERNAL_ERROR = -32603;
|
|
39
|
-
export declare const RPC_PORTAL_NOT_FOUND = -32000;
|
|
40
|
-
export declare const RPC_POLICY_DENIED = -32001;
|
|
41
|
-
export declare const RPC_INVALID_PAYLOAD = -32002;
|
|
42
|
-
export type ParseResult = {
|
|
43
|
-
kind: 'request';
|
|
44
|
-
request: RpcRequest;
|
|
45
|
-
} | {
|
|
46
|
-
kind: 'parse_error';
|
|
47
|
-
} | {
|
|
48
|
-
kind: 'invalid';
|
|
49
|
-
id: RpcId;
|
|
50
|
-
reason: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Parse a single NDJSON line into a JSON-RPC request.
|
|
54
|
-
* Returns either a valid request, a parse_error (if the line is not JSON), or
|
|
55
|
-
* an invalid envelope along with the id that should be echoed in the error
|
|
56
|
-
* response (which is null if the id couldn't be extracted).
|
|
57
|
-
*/
|
|
58
|
-
export declare function parseRequest(line: string): ParseResult;
|
|
59
|
-
export declare function encodeResponse(id: RpcId, result: unknown): string;
|
|
60
|
-
export declare function encodeError(id: RpcId, code: number, message: string, data?: unknown): string;
|
|
61
|
-
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/daemon/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,WAAW,QAAQ,CAAC;AAEjC,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC;AAGhD,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,oBAAoB,SAAS,CAAC;AAC3C,eAAO,MAAM,kBAAkB,SAAS,CAAC;AACzC,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAGzC,eAAO,MAAM,oBAAoB,SAAS,CAAC;AAC3C,eAAO,MAAM,iBAAiB,SAAS,CAAC;AACxC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAuCtD;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAGjE;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAI5F"}
|
package/dist/src/daemon/rpc.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON-RPC 2.0 over newline-delimited JSON (NDJSON).
|
|
3
|
-
* Pure functions only — no IO. The server in server.ts wires this onto sockets.
|
|
4
|
-
*
|
|
5
|
-
* We use the strict JSON-RPC 2.0 envelope: every request has `jsonrpc: "2.0"`,
|
|
6
|
-
* a method, and either an id (for requests expecting a response) or no id (for
|
|
7
|
-
* notifications, which sigil currently rejects since every sign decision needs
|
|
8
|
-
* to round-trip through the audit log).
|
|
9
|
-
*/
|
|
10
|
-
export const RPC_VERSION = '2.0';
|
|
11
|
-
// Standard JSON-RPC 2.0 error codes.
|
|
12
|
-
export const RPC_PARSE_ERROR = -32700;
|
|
13
|
-
export const RPC_INVALID_REQUEST = -32600;
|
|
14
|
-
export const RPC_METHOD_NOT_FOUND = -32601;
|
|
15
|
-
export const RPC_INVALID_PARAMS = -32602;
|
|
16
|
-
export const RPC_INTERNAL_ERROR = -32603;
|
|
17
|
-
// Reserved range for sigil-specific errors: -32000 .. -32099.
|
|
18
|
-
export const RPC_PORTAL_NOT_FOUND = -32000;
|
|
19
|
-
export const RPC_POLICY_DENIED = -32001;
|
|
20
|
-
export const RPC_INVALID_PAYLOAD = -32002;
|
|
21
|
-
/**
|
|
22
|
-
* Parse a single NDJSON line into a JSON-RPC request.
|
|
23
|
-
* Returns either a valid request, a parse_error (if the line is not JSON), or
|
|
24
|
-
* an invalid envelope along with the id that should be echoed in the error
|
|
25
|
-
* response (which is null if the id couldn't be extracted).
|
|
26
|
-
*/
|
|
27
|
-
export function parseRequest(line) {
|
|
28
|
-
let parsed;
|
|
29
|
-
try {
|
|
30
|
-
parsed = JSON.parse(line);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return { kind: 'parse_error' };
|
|
34
|
-
}
|
|
35
|
-
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
36
|
-
return { kind: 'invalid', id: null, reason: 'request must be a JSON object' };
|
|
37
|
-
}
|
|
38
|
-
const obj = parsed;
|
|
39
|
-
// Try to extract an id even if the rest is malformed, so the error
|
|
40
|
-
// response can be correlated.
|
|
41
|
-
const rawId = obj['id'];
|
|
42
|
-
const id = typeof rawId === 'string' || typeof rawId === 'number' || rawId === null ? rawId : null;
|
|
43
|
-
if (obj['jsonrpc'] !== RPC_VERSION) {
|
|
44
|
-
return { kind: 'invalid', id, reason: 'jsonrpc must be "2.0"' };
|
|
45
|
-
}
|
|
46
|
-
if (typeof obj['method'] !== 'string' || obj['method'].length === 0) {
|
|
47
|
-
return { kind: 'invalid', id, reason: 'method must be a non-empty string' };
|
|
48
|
-
}
|
|
49
|
-
// Notifications (no id) are not supported — every call must be acknowledged
|
|
50
|
-
// because every sign call needs an audit-log roundtrip.
|
|
51
|
-
if (!('id' in obj)) {
|
|
52
|
-
return { kind: 'invalid', id: null, reason: 'notifications are not supported' };
|
|
53
|
-
}
|
|
54
|
-
if (typeof rawId !== 'string' && typeof rawId !== 'number' && rawId !== null) {
|
|
55
|
-
return { kind: 'invalid', id: null, reason: 'id must be string, number, or null' };
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
kind: 'request',
|
|
59
|
-
request: {
|
|
60
|
-
jsonrpc: '2.0',
|
|
61
|
-
id,
|
|
62
|
-
method: obj['method'],
|
|
63
|
-
params: obj['params'],
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export function encodeResponse(id, result) {
|
|
68
|
-
const r = { jsonrpc: RPC_VERSION, id, result };
|
|
69
|
-
return JSON.stringify(r);
|
|
70
|
-
}
|
|
71
|
-
export function encodeError(id, code, message, data) {
|
|
72
|
-
const error = data === undefined ? { code, message } : { code, message, data };
|
|
73
|
-
const r = { jsonrpc: RPC_VERSION, id, error };
|
|
74
|
-
return JSON.stringify(r);
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=rpc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/daemon/rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AA+BjC,qCAAqC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AAEzC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC;AACxC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