duckhunt-runner 0.12.0 → 0.13.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 +379 -16
- package/dist/announced-capabilities.d.ts +2 -0
- package/dist/announced-capabilities.d.ts.map +1 -1
- package/dist/announced-capabilities.js +6 -0
- package/dist/announced-capabilities.js.map +1 -1
- package/dist/audit-cli.d.ts +7 -0
- package/dist/audit-cli.d.ts.map +1 -0
- package/dist/audit-cli.js +84 -0
- package/dist/audit-cli.js.map +1 -0
- package/dist/audit.d.ts +163 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +286 -0
- package/dist/audit.js.map +1 -0
- package/dist/aws.d.ts +10 -1
- package/dist/aws.d.ts.map +1 -1
- package/dist/aws.js +35 -9
- package/dist/aws.js.map +1 -1
- package/dist/browser-cli.d.ts +9 -0
- package/dist/browser-cli.d.ts.map +1 -0
- package/dist/browser-cli.js +200 -0
- package/dist/browser-cli.js.map +1 -0
- package/dist/claim.d.ts +44 -28
- package/dist/claim.d.ts.map +1 -1
- package/dist/claim.js +106 -85
- package/dist/claim.js.map +1 -1
- package/dist/claude.d.ts +1 -0
- package/dist/claude.d.ts.map +1 -1
- package/dist/claude.js +9 -3
- package/dist/claude.js.map +1 -1
- package/dist/config-legacy.d.ts +20 -0
- package/dist/config-legacy.d.ts.map +1 -0
- package/dist/config-legacy.js +253 -0
- package/dist/config-legacy.js.map +1 -0
- package/dist/config.d.ts +38 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +42 -26
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +81 -20
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +889 -417
- package/dist/daemon.js.map +1 -1
- package/dist/feed.d.ts +5 -1
- package/dist/feed.d.ts.map +1 -1
- package/dist/feed.js +78 -13
- package/dist/feed.js.map +1 -1
- package/dist/index.js +64 -4
- package/dist/index.js.map +1 -1
- package/dist/local/mcp.d.ts +93 -0
- package/dist/local/mcp.d.ts.map +1 -0
- package/dist/local/mcp.js +170 -0
- package/dist/local/mcp.js.map +1 -0
- package/dist/local/policy.d.ts +39 -0
- package/dist/local/policy.d.ts.map +1 -0
- package/dist/local/policy.js +88 -0
- package/dist/local/policy.js.map +1 -0
- package/dist/local/socket.d.ts +68 -0
- package/dist/local/socket.d.ts.map +1 -0
- package/dist/local/socket.js +140 -0
- package/dist/local/socket.js.map +1 -0
- package/dist/local/store.d.ts +75 -0
- package/dist/local/store.d.ts.map +1 -0
- package/dist/local/store.js +110 -0
- package/dist/local/store.js.map +1 -0
- package/dist/logout.d.ts +10 -11
- package/dist/logout.d.ts.map +1 -1
- package/dist/logout.js +65 -35
- package/dist/logout.js.map +1 -1
- package/dist/machine.d.ts +4 -0
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +35 -0
- package/dist/machine.js.map +1 -1
- package/dist/mcp-stdio.d.ts +19 -0
- package/dist/mcp-stdio.d.ts.map +1 -0
- package/dist/mcp-stdio.js +65 -0
- package/dist/mcp-stdio.js.map +1 -0
- package/dist/oauth.d.ts +32 -4
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +70 -35
- package/dist/oauth.js.map +1 -1
- package/dist/paths.d.ts +43 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +136 -0
- package/dist/paths.js.map +1 -0
- package/dist/platform-login.d.ts +19 -0
- package/dist/platform-login.d.ts.map +1 -0
- package/dist/platform-login.js +178 -0
- package/dist/platform-login.js.map +1 -0
- package/dist/platforms/claim-v0.d.ts +44 -0
- package/dist/platforms/claim-v0.d.ts.map +1 -0
- package/dist/platforms/claim-v0.js +243 -0
- package/dist/platforms/claim-v0.js.map +1 -0
- package/dist/platforms/credentials.d.ts +18 -0
- package/dist/platforms/credentials.d.ts.map +1 -0
- package/dist/platforms/credentials.js +64 -0
- package/dist/platforms/credentials.js.map +1 -0
- package/dist/platforms/discovery.d.ts +30 -0
- package/dist/platforms/discovery.d.ts.map +1 -0
- package/dist/platforms/discovery.js +91 -0
- package/dist/platforms/discovery.js.map +1 -0
- package/dist/platforms/duckhunt42.d.ts +33 -0
- package/dist/platforms/duckhunt42.d.ts.map +1 -0
- package/dist/platforms/duckhunt42.js +231 -0
- package/dist/platforms/duckhunt42.js.map +1 -0
- package/dist/platforms/factories.d.ts +3 -0
- package/dist/platforms/factories.d.ts.map +1 -0
- package/dist/platforms/factories.js +10 -0
- package/dist/platforms/factories.js.map +1 -0
- package/dist/platforms/http-transport.d.ts +29 -0
- package/dist/platforms/http-transport.d.ts.map +1 -0
- package/dist/platforms/http-transport.js +88 -0
- package/dist/platforms/http-transport.js.map +1 -0
- package/dist/platforms/local.d.ts +79 -0
- package/dist/platforms/local.d.ts.map +1 -0
- package/dist/platforms/local.js +302 -0
- package/dist/platforms/local.js.map +1 -0
- package/dist/platforms/origin.d.ts +12 -0
- package/dist/platforms/origin.d.ts.map +1 -0
- package/dist/platforms/origin.js +32 -0
- package/dist/platforms/origin.js.map +1 -0
- package/dist/platforms/platform.d.ts +135 -0
- package/dist/platforms/platform.d.ts.map +1 -0
- package/dist/platforms/platform.js +33 -0
- package/dist/platforms/platform.js.map +1 -0
- package/dist/platforms/scheduler.d.ts +32 -0
- package/dist/platforms/scheduler.d.ts.map +1 -0
- package/dist/platforms/scheduler.js +76 -0
- package/dist/platforms/scheduler.js.map +1 -0
- package/dist/platforms/supervisor.d.ts +45 -0
- package/dist/platforms/supervisor.d.ts.map +1 -0
- package/dist/platforms/supervisor.js +112 -0
- package/dist/platforms/supervisor.js.map +1 -0
- package/dist/platforms/types.d.ts +50 -0
- package/dist/platforms/types.d.ts.map +1 -0
- package/dist/platforms/types.js +69 -0
- package/dist/platforms/types.js.map +1 -0
- package/dist/platforms/v0.d.ts +41 -0
- package/dist/platforms/v0.d.ts.map +1 -0
- package/dist/platforms/v0.js +301 -0
- package/dist/platforms/v0.js.map +1 -0
- package/dist/platforms-cli.d.ts +5 -0
- package/dist/platforms-cli.d.ts.map +1 -0
- package/dist/platforms-cli.js +163 -0
- package/dist/platforms-cli.js.map +1 -0
- package/dist/read-shell-guard.d.ts.map +1 -1
- package/dist/read-shell-guard.js +4 -3
- package/dist/read-shell-guard.js.map +1 -1
- package/dist/repo-commands.js +2 -2
- package/dist/repo-commands.js.map +1 -1
- package/dist/repo-key.js +1 -1
- package/dist/repo-key.js.map +1 -1
- package/dist/repos.js +2 -2
- package/dist/repos.js.map +1 -1
- package/dist/resource.d.ts +2 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +91 -0
- package/dist/resource.js.map +1 -0
- package/dist/resources/aws.d.ts +36 -0
- package/dist/resources/aws.d.ts.map +1 -0
- package/dist/resources/aws.js +160 -0
- package/dist/resources/aws.js.map +1 -0
- package/dist/resources/browser/config.d.ts +33 -0
- package/dist/resources/browser/config.d.ts.map +1 -0
- package/dist/resources/browser/config.js +86 -0
- package/dist/resources/browser/config.js.map +1 -0
- package/dist/resources/browser/health.d.ts +48 -0
- package/dist/resources/browser/health.d.ts.map +1 -0
- package/dist/resources/browser/health.js +100 -0
- package/dist/resources/browser/health.js.map +1 -0
- package/dist/resources/browser/odysea-cli.d.ts +41 -0
- package/dist/resources/browser/odysea-cli.d.ts.map +1 -0
- package/dist/resources/browser/odysea-cli.js +122 -0
- package/dist/resources/browser/odysea-cli.js.map +1 -0
- package/dist/resources/browser/origins.d.ts +17 -0
- package/dist/resources/browser/origins.d.ts.map +1 -0
- package/dist/resources/browser/origins.js +72 -0
- package/dist/resources/browser/origins.js.map +1 -0
- package/dist/resources/browser/provider.d.ts +49 -0
- package/dist/resources/browser/provider.d.ts.map +1 -0
- package/dist/resources/browser/provider.js +166 -0
- package/dist/resources/browser/provider.js.map +1 -0
- package/dist/resources/browser/state-filter.d.ts +28 -0
- package/dist/resources/browser/state-filter.d.ts.map +1 -0
- package/dist/resources/browser/state-filter.js +61 -0
- package/dist/resources/browser/state-filter.js.map +1 -0
- package/dist/resources/legacy.d.ts +13 -0
- package/dist/resources/legacy.d.ts.map +1 -0
- package/dist/resources/legacy.js +46 -0
- package/dist/resources/legacy.js.map +1 -0
- package/dist/resources/lifecycle.d.ts +48 -0
- package/dist/resources/lifecycle.d.ts.map +1 -0
- package/dist/resources/lifecycle.js +137 -0
- package/dist/resources/lifecycle.js.map +1 -0
- package/dist/resources/registry.d.ts +20 -0
- package/dist/resources/registry.d.ts.map +1 -0
- package/dist/resources/registry.js +37 -0
- package/dist/resources/registry.js.map +1 -0
- package/dist/{conversation-gc.d.ts → resources/repo/gc.d.ts} +6 -6
- package/dist/resources/repo/gc.d.ts.map +1 -0
- package/dist/{conversation-gc.js → resources/repo/gc.js} +16 -13
- package/dist/resources/repo/gc.js.map +1 -0
- package/dist/{repo-health.d.ts → resources/repo/health.d.ts} +4 -2
- package/dist/resources/repo/health.d.ts.map +1 -0
- package/dist/{repo-health.js → resources/repo/health.js} +14 -9
- package/dist/resources/repo/health.js.map +1 -0
- package/dist/resources/repo/provider.d.ts +14 -0
- package/dist/resources/repo/provider.d.ts.map +1 -0
- package/dist/resources/repo/provider.js +75 -0
- package/dist/resources/repo/provider.js.map +1 -0
- package/dist/{worktree.d.ts → resources/repo/worktree.d.ts} +3 -5
- package/dist/resources/repo/worktree.d.ts.map +1 -0
- package/dist/{worktree.js → resources/repo/worktree.js} +24 -27
- package/dist/resources/repo/worktree.js.map +1 -0
- package/dist/resources/s3-read.d.ts +29 -0
- package/dist/resources/s3-read.d.ts.map +1 -0
- package/dist/resources/s3-read.js +68 -0
- package/dist/resources/s3-read.js.map +1 -0
- package/dist/resources/types.d.ts +106 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +73 -0
- package/dist/resources/types.js.map +1 -0
- package/dist/run-cli.d.ts +25 -0
- package/dist/run-cli.d.ts.map +1 -0
- package/dist/run-cli.js +432 -0
- package/dist/run-cli.js.map +1 -0
- package/dist/run-id.d.ts +10 -0
- package/dist/run-id.d.ts.map +1 -0
- package/dist/run-id.js +36 -0
- package/dist/run-id.js.map +1 -0
- package/dist/run-lease.d.ts +2 -2
- package/dist/run-mcp-config.d.ts +7 -4
- package/dist/run-mcp-config.d.ts.map +1 -1
- package/dist/run-mcp-config.js +14 -8
- package/dist/run-mcp-config.js.map +1 -1
- package/dist/s3-read-server.d.ts +22 -0
- package/dist/s3-read-server.d.ts.map +1 -0
- package/dist/s3-read-server.js +173 -0
- package/dist/s3-read-server.js.map +1 -0
- package/dist/secret-paths.d.ts +12 -0
- package/dist/secret-paths.d.ts.map +1 -1
- package/dist/secret-paths.js +82 -10
- package/dist/secret-paths.js.map +1 -1
- package/dist/server-state.d.ts +7 -9
- package/dist/server-state.d.ts.map +1 -1
- package/dist/server-state.js +14 -17
- package/dist/server-state.js.map +1 -1
- package/dist/status-report.d.ts +2 -0
- package/dist/status-report.d.ts.map +1 -1
- package/dist/status-report.js.map +1 -1
- package/dist/status.d.ts +5 -1
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +100 -6
- package/dist/status.js.map +1 -1
- package/dist/toolset/intersect.d.ts +10 -0
- package/dist/toolset/intersect.d.ts.map +1 -0
- package/dist/toolset/intersect.js +36 -0
- package/dist/toolset/intersect.js.map +1 -0
- package/dist/toolset/legacy-render.d.ts +12 -0
- package/dist/toolset/legacy-render.d.ts.map +1 -0
- package/dist/toolset/legacy-render.js +69 -0
- package/dist/toolset/legacy-render.js.map +1 -0
- package/dist/toolset/parse.d.ts +4 -0
- package/dist/toolset/parse.d.ts.map +1 -0
- package/dist/toolset/parse.js +74 -0
- package/dist/toolset/parse.js.map +1 -0
- package/dist/toolset/render.d.ts +28 -0
- package/dist/toolset/render.d.ts.map +1 -0
- package/dist/toolset/render.js +78 -0
- package/dist/toolset/render.js.map +1 -0
- package/dist/toolset/shadow.d.ts +16 -0
- package/dist/toolset/shadow.d.ts.map +1 -0
- package/dist/toolset/shadow.js +61 -0
- package/dist/toolset/shadow.js.map +1 -0
- package/dist/vendor/runner-protocol/aws.d.ts +6 -0
- package/dist/vendor/runner-protocol/aws.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/aws.js +69 -0
- package/dist/vendor/runner-protocol/aws.js.map +1 -0
- package/dist/vendor/runner-protocol/capabilities.d.ts +20 -0
- package/dist/vendor/runner-protocol/capabilities.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/capabilities.js +58 -0
- package/dist/vendor/runner-protocol/capabilities.js.map +1 -0
- package/dist/vendor/runner-protocol/claim.d.ts +112 -0
- package/dist/vendor/runner-protocol/claim.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/claim.js +54 -0
- package/dist/vendor/runner-protocol/claim.js.map +1 -0
- package/dist/vendor/runner-protocol/errors.d.ts +17 -0
- package/dist/vendor/runner-protocol/errors.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/errors.js +19 -0
- package/dist/vendor/runner-protocol/errors.js.map +1 -0
- package/dist/vendor/runner-protocol/events.d.ts +14 -0
- package/dist/vendor/runner-protocol/events.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/events.js +22 -0
- package/dist/vendor/runner-protocol/events.js.map +1 -0
- package/dist/vendor/runner-protocol/index.d.ts +10 -0
- package/dist/vendor/runner-protocol/index.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/index.js +24 -0
- package/dist/vendor/runner-protocol/index.js.map +1 -0
- package/dist/vendor/runner-protocol/limits.d.ts +31 -0
- package/dist/vendor/runner-protocol/limits.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/limits.js +60 -0
- package/dist/vendor/runner-protocol/limits.js.map +1 -0
- package/dist/vendor/runner-protocol/resources.d.ts +35 -0
- package/dist/vendor/runner-protocol/resources.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/resources.js +39 -0
- package/dist/vendor/runner-protocol/resources.js.map +1 -0
- package/dist/vendor/runner-protocol/toolset.d.ts +59 -0
- package/dist/vendor/runner-protocol/toolset.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/toolset.js +50 -0
- package/dist/vendor/runner-protocol/toolset.js.map +1 -0
- package/dist/vendor/runner-protocol/v0.d.ts +277 -0
- package/dist/vendor/runner-protocol/v0.d.ts.map +1 -0
- package/dist/vendor/runner-protocol/v0.js +121 -0
- package/dist/vendor/runner-protocol/v0.js.map +1 -0
- package/package.json +3 -2
- package/dist/aws-env.d.ts +0 -21
- package/dist/aws-env.d.ts.map +0 -1
- package/dist/aws-env.js +0 -80
- package/dist/aws-env.js.map +0 -1
- package/dist/conversation-gc.d.ts.map +0 -1
- package/dist/conversation-gc.js.map +0 -1
- package/dist/repo-health.d.ts.map +0 -1
- package/dist/repo-health.js.map +0 -1
- package/dist/worktree.d.ts.map +0 -1
- package/dist/worktree.js.map +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export declare const JSONRPC_VERSION = "2.0";
|
|
2
|
+
export declare const MCP_PROTOCOL_FALLBACK = "2025-06-18";
|
|
3
|
+
export declare const RPC_ERROR: {
|
|
4
|
+
readonly parse: -32700;
|
|
5
|
+
readonly invalidRequest: -32600;
|
|
6
|
+
readonly methodNotFound: -32601;
|
|
7
|
+
readonly invalidParams: -32602;
|
|
8
|
+
};
|
|
9
|
+
/** de quién es un token: la conversación y el segmento que lo recibieron al reclamar. */
|
|
10
|
+
export interface TokenSubject {
|
|
11
|
+
conversation: string;
|
|
12
|
+
segment: number;
|
|
13
|
+
}
|
|
14
|
+
/** atiende una tool: devuelve el texto para el agente o lanza con el motivo (argumentos que no valen). */
|
|
15
|
+
export type ToolHandler = (subject: TokenSubject, tool: string, args: Record<string, unknown>) => string;
|
|
16
|
+
/** las tools que lista el servidor (su esquema es lo que valida quien las atiende). */
|
|
17
|
+
export declare const LOCAL_TOOLS: readonly [{
|
|
18
|
+
readonly name: "ask_user";
|
|
19
|
+
readonly description: "pregunta al usuario y termina tu turno: la respuesta llega como el siguiente mensaje. kind yes_no (sí o no), text (texto libre) o form (varias preguntas en `questions`, cada una con sus `options` si son de elegir).";
|
|
20
|
+
readonly inputSchema: {
|
|
21
|
+
readonly type: "object";
|
|
22
|
+
readonly properties: {
|
|
23
|
+
readonly kind: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly enum: readonly string[];
|
|
26
|
+
};
|
|
27
|
+
readonly question: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
30
|
+
readonly questions: {
|
|
31
|
+
readonly type: "array";
|
|
32
|
+
readonly items: {
|
|
33
|
+
readonly type: "object";
|
|
34
|
+
readonly properties: {
|
|
35
|
+
readonly question: {
|
|
36
|
+
readonly type: "string";
|
|
37
|
+
};
|
|
38
|
+
readonly options: {
|
|
39
|
+
readonly type: "array";
|
|
40
|
+
readonly items: {
|
|
41
|
+
readonly type: "string";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
readonly required: readonly ["question"];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readonly required: readonly ["kind", "question"];
|
|
50
|
+
};
|
|
51
|
+
}, {
|
|
52
|
+
readonly name: "reply";
|
|
53
|
+
readonly description: "tu respuesta final al usuario: kind result (el trabajo hecho) o blocker (no puedes seguir y por qué). body es lo que el usuario lee.";
|
|
54
|
+
readonly inputSchema: {
|
|
55
|
+
readonly type: "object";
|
|
56
|
+
readonly properties: {
|
|
57
|
+
readonly kind: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
readonly enum: readonly string[];
|
|
60
|
+
};
|
|
61
|
+
readonly body: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
};
|
|
64
|
+
readonly summary: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
readonly required: readonly ["kind", "body"];
|
|
69
|
+
};
|
|
70
|
+
}];
|
|
71
|
+
type Obj = Record<string, unknown>;
|
|
72
|
+
export declare const rpcResult: (id: unknown, result: unknown) => Obj;
|
|
73
|
+
export declare const rpcError: (id: unknown, code: number, message: string) => Obj;
|
|
74
|
+
export declare class LocalMcpServer {
|
|
75
|
+
private readonly handle;
|
|
76
|
+
private server;
|
|
77
|
+
private readonly tokens;
|
|
78
|
+
constructor(handle: ToolHandler);
|
|
79
|
+
/** arranca en un puerto libre de loopback. */
|
|
80
|
+
start(): Promise<void>;
|
|
81
|
+
/** origen del servidor (la base de la plataforma local: el mcp vive en su mismo origen, claim-v0.ts). */
|
|
82
|
+
get origin(): string;
|
|
83
|
+
get url(): string;
|
|
84
|
+
/** un token para el segmento. */
|
|
85
|
+
issue(subject: TokenSubject): string;
|
|
86
|
+
/** revoca los tokens del segmento. */
|
|
87
|
+
revoke(subject: TokenSubject): void;
|
|
88
|
+
close(): Promise<void>;
|
|
89
|
+
private serve;
|
|
90
|
+
private answer;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/local/mcp.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAKlD,eAAO,MAAM,SAAS;;;;;CAAoG,CAAC;AAM3H,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,0GAA0G;AAC1G,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;AAKzG,uFAAuF;AACvF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBd,CAAC;AAEX,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAGnC,eAAO,MAAM,SAAS,GAAI,IAAI,OAAO,EAAE,QAAQ,OAAO,KAAG,GAAiD,CAAC;AAC3G,eAAO,MAAM,QAAQ,GAAI,IAAI,OAAO,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM,KAAG,GAA+E,CAAC;AAEtJ,qBAAa,cAAc;IAIb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;gBAE7B,MAAM,EAAE,WAAW;IAEhD,8CAA8C;IACxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B,yGAAyG;IACzG,IAAI,MAAM,IAAI,MAAM,CAGnB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,iCAAiC;IACjC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;IAMpC,sCAAsC;IACtC,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAQd,KAAK;IAuBnB,OAAO,CAAC,MAAM;CAoBf"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// servidor mcp de la plataforma local (t#495, M7): sus dos tools (ask_user, reply) para el claude de un `runner run`,
|
|
2
|
+
// en 127.0.0.1 con un puerto al azar. un subconjunto de json-rpc escrito a mano (initialize, ping, tools/list,
|
|
3
|
+
// tools/call; respuestas json, sin sse) para seguir sin dependencias: el cli lo carga como cualquier servidor http
|
|
4
|
+
// del mcp-config del run (run-mcp-config.ts).
|
|
5
|
+
// decisiones:
|
|
6
|
+
// - un token bearer por segmento: se da al reclamar y se revoca con su result; sin token vivo, 401.
|
|
7
|
+
// - la tool solo anota (quien aloja la plataforma, `handle`) y contesta un texto: el turno lo cierra el agente.
|
|
8
|
+
// - un argumento que no vale vuelve como resultado de tool con isError (la convención del mcp), no como error de
|
|
9
|
+
// json-rpc: el agente lo lee y puede corregirse.
|
|
10
|
+
import crypto from 'node:crypto';
|
|
11
|
+
import http from 'node:http';
|
|
12
|
+
import { runnerVersion } from '../version.js';
|
|
13
|
+
import { LOCAL_TOOL } from './policy.js';
|
|
14
|
+
import { QUESTION_KIND, REPLY_KIND } from './store.js';
|
|
15
|
+
const LOOPBACK_HOST = '127.0.0.1';
|
|
16
|
+
const MCP_PATH = '/mcp';
|
|
17
|
+
export const JSONRPC_VERSION = '2.0';
|
|
18
|
+
// versión del protocolo mcp si el cliente no pide ninguna (la que dice el cliente se devuelve tal cual).
|
|
19
|
+
export const MCP_PROTOCOL_FALLBACK = '2025-06-18';
|
|
20
|
+
const SERVER_NAME = 'duckhunt-runner-local';
|
|
21
|
+
const TOKEN_BYTES = 24;
|
|
22
|
+
const BODY_MAX_BYTES = 1 << 20;
|
|
23
|
+
const HTTP = { ok: 200, accepted: 202, unauthorized: 401, notFound: 404, notAllowed: 405, tooLarge: 413 };
|
|
24
|
+
export const RPC_ERROR = { parse: -32700, invalidRequest: -32600, methodNotFound: -32601, invalidParams: -32602 };
|
|
25
|
+
const BEARER_RE = /^Bearer\s+(\S+)$/i;
|
|
26
|
+
const JSON_TYPE = { 'Content-Type': 'application/json' };
|
|
27
|
+
// marca del error de un cuerpo que pasa de BODY_MAX_BYTES.
|
|
28
|
+
const TOO_LARGE = 'too_large';
|
|
29
|
+
const QUESTION_KINDS = Object.values(QUESTION_KIND);
|
|
30
|
+
const REPLY_KINDS = Object.values(REPLY_KIND);
|
|
31
|
+
/** las tools que lista el servidor (su esquema es lo que valida quien las atiende). */
|
|
32
|
+
export const LOCAL_TOOLS = [
|
|
33
|
+
{
|
|
34
|
+
name: LOCAL_TOOL.askUser,
|
|
35
|
+
description: 'pregunta al usuario y termina tu turno: la respuesta llega como el siguiente mensaje. kind yes_no (sí o no), text (texto libre) o form (varias preguntas en `questions`, cada una con sus `options` si son de elegir).',
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
kind: { type: 'string', enum: QUESTION_KINDS },
|
|
40
|
+
question: { type: 'string' },
|
|
41
|
+
questions: { type: 'array', items: { type: 'object', properties: { question: { type: 'string' }, options: { type: 'array', items: { type: 'string' } } }, required: ['question'] } },
|
|
42
|
+
},
|
|
43
|
+
required: ['kind', 'question'],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: LOCAL_TOOL.reply,
|
|
48
|
+
description: 'tu respuesta final al usuario: kind result (el trabajo hecho) o blocker (no puedes seguir y por qué). body es lo que el usuario lee.',
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: { kind: { type: 'string', enum: REPLY_KINDS }, body: { type: 'string' }, summary: { type: 'string' } },
|
|
52
|
+
required: ['kind', 'body'],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
57
|
+
export const rpcResult = (id, result) => ({ jsonrpc: JSONRPC_VERSION, id, result });
|
|
58
|
+
export const rpcError = (id, code, message) => ({ jsonrpc: JSONRPC_VERSION, id: id ?? null, error: { code, message } });
|
|
59
|
+
export class LocalMcpServer {
|
|
60
|
+
handle;
|
|
61
|
+
server = null;
|
|
62
|
+
tokens = new Map();
|
|
63
|
+
constructor(handle) {
|
|
64
|
+
this.handle = handle;
|
|
65
|
+
}
|
|
66
|
+
/** arranca en un puerto libre de loopback. */
|
|
67
|
+
async start() {
|
|
68
|
+
const server = http.createServer((req, res) => void this.serve(req, res));
|
|
69
|
+
await new Promise((resolve, reject) => {
|
|
70
|
+
server.once('error', reject);
|
|
71
|
+
server.listen(0, LOOPBACK_HOST, () => resolve());
|
|
72
|
+
});
|
|
73
|
+
// un cli que deja la conexión abierta no debe alargar la parada.
|
|
74
|
+
server.unref();
|
|
75
|
+
this.server = server;
|
|
76
|
+
}
|
|
77
|
+
/** origen del servidor (la base de la plataforma local: el mcp vive en su mismo origen, claim-v0.ts). */
|
|
78
|
+
get origin() {
|
|
79
|
+
const { port } = this.server.address();
|
|
80
|
+
return `http://${LOOPBACK_HOST}:${port}`;
|
|
81
|
+
}
|
|
82
|
+
get url() {
|
|
83
|
+
return `${this.origin}${MCP_PATH}`;
|
|
84
|
+
}
|
|
85
|
+
/** un token para el segmento. */
|
|
86
|
+
issue(subject) {
|
|
87
|
+
const token = crypto.randomBytes(TOKEN_BYTES).toString('base64url');
|
|
88
|
+
this.tokens.set(token, subject);
|
|
89
|
+
return token;
|
|
90
|
+
}
|
|
91
|
+
/** revoca los tokens del segmento. */
|
|
92
|
+
revoke(subject) {
|
|
93
|
+
[...this.tokens].filter(([, s]) => s.conversation === subject.conversation && s.segment === subject.segment).forEach(([token]) => this.tokens.delete(token));
|
|
94
|
+
}
|
|
95
|
+
async close() {
|
|
96
|
+
const server = this.server;
|
|
97
|
+
this.server = null;
|
|
98
|
+
if (!server)
|
|
99
|
+
return;
|
|
100
|
+
server.closeAllConnections();
|
|
101
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
102
|
+
}
|
|
103
|
+
async serve(req, res) {
|
|
104
|
+
const send = (status, body) => {
|
|
105
|
+
res.writeHead(status, body === undefined ? {} : JSON_TYPE);
|
|
106
|
+
res.end(body === undefined ? undefined : JSON.stringify(body));
|
|
107
|
+
};
|
|
108
|
+
if (new URL(req.url ?? '/', this.origin).pathname !== MCP_PATH)
|
|
109
|
+
return send(HTTP.notFound, { error: 'no encontrado' });
|
|
110
|
+
if (req.method !== 'POST')
|
|
111
|
+
return send(HTTP.notAllowed, { error: 'solo POST (sin sse)' });
|
|
112
|
+
const token = BEARER_RE.exec(req.headers.authorization ?? '')?.[1];
|
|
113
|
+
const subject = token === undefined ? undefined : this.tokens.get(token);
|
|
114
|
+
if (!subject)
|
|
115
|
+
return send(HTTP.unauthorized, { error: 'token inválido o revocado' });
|
|
116
|
+
let body;
|
|
117
|
+
try {
|
|
118
|
+
body = JSON.parse(await readBody(req));
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
if (err.message === TOO_LARGE)
|
|
122
|
+
return send(HTTP.tooLarge, { error: 'cuerpo demasiado grande' });
|
|
123
|
+
return send(HTTP.ok, rpcError(null, RPC_ERROR.parse, 'json ilegible'));
|
|
124
|
+
}
|
|
125
|
+
if (!isObj(body) || body.jsonrpc !== JSONRPC_VERSION || typeof body.method !== 'string')
|
|
126
|
+
return send(HTTP.ok, rpcError(isObj(body) ? body.id : null, RPC_ERROR.invalidRequest, 'petición json-rpc inválida'));
|
|
127
|
+
// una notificación (sin id) no lleva respuesta.
|
|
128
|
+
if (body.id === undefined)
|
|
129
|
+
return send(HTTP.accepted);
|
|
130
|
+
send(HTTP.ok, this.answer(subject, body.id, body.method, isObj(body.params) ? body.params : {}));
|
|
131
|
+
}
|
|
132
|
+
answer(subject, id, method, params) {
|
|
133
|
+
if (method === 'initialize') {
|
|
134
|
+
return rpcResult(id, {
|
|
135
|
+
protocolVersion: typeof params.protocolVersion === 'string' ? params.protocolVersion : MCP_PROTOCOL_FALLBACK,
|
|
136
|
+
capabilities: { tools: { listChanged: false } },
|
|
137
|
+
serverInfo: { name: SERVER_NAME, version: runnerVersion() ?? '0' },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (method === 'ping')
|
|
141
|
+
return rpcResult(id, {});
|
|
142
|
+
if (method === 'tools/list')
|
|
143
|
+
return rpcResult(id, { tools: LOCAL_TOOLS });
|
|
144
|
+
if (method !== 'tools/call')
|
|
145
|
+
return rpcError(id, RPC_ERROR.methodNotFound, `método desconocido: ${method}`);
|
|
146
|
+
const name = params.name;
|
|
147
|
+
if (typeof name !== 'string' || !LOCAL_TOOLS.some((t) => t.name === name))
|
|
148
|
+
return rpcError(id, RPC_ERROR.invalidParams, `tool desconocida: ${String(name)}`);
|
|
149
|
+
try {
|
|
150
|
+
const text = this.handle(subject, name, isObj(params.arguments) ? params.arguments : {});
|
|
151
|
+
return rpcResult(id, { content: [{ type: 'text', text }] });
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
return rpcResult(id, { content: [{ type: 'text', text: err.message }], isError: true });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// el cuerpo entero, acotado.
|
|
159
|
+
async function readBody(req) {
|
|
160
|
+
const chunks = [];
|
|
161
|
+
let size = 0;
|
|
162
|
+
for await (const chunk of req) {
|
|
163
|
+
size += chunk.length;
|
|
164
|
+
if (size > BODY_MAX_BYTES)
|
|
165
|
+
throw new Error(TOO_LARGE);
|
|
166
|
+
chunks.push(chunk);
|
|
167
|
+
}
|
|
168
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/local/mcp.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,+GAA+G;AAC/G,mHAAmH;AACnH,8CAA8C;AAC9C,cAAc;AACd,oGAAoG;AACpG,gHAAgH;AAChH,iHAAiH;AACjH,mDAAmD;AAEnD,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AACrC,yGAAyG;AACzG,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAClD,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAC5C,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,CAAC;AAC/B,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,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BAAqB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7J,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACzF,OAAO,SAAS,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,SAAS,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACrG,CAAC;IACH,CAAC;CACF;AAED,6BAA6B;AAC7B,KAAK,UAAU,QAAQ,CAAC,GAAyB;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;QAC9B,IAAI,IAAK,KAAgB,CAAC,MAAM,CAAC;QACjC,IAAI,IAAI,GAAG,cAAc;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type PromptProfile } from '../claim.js';
|
|
2
|
+
import type { PlatformConfig } from '../platforms/types.js';
|
|
3
|
+
import { type ToolsetGrant, type ToolsetV1 } from '../vendor/runner-protocol/index.js';
|
|
4
|
+
/** nombre del servidor mcp de la plataforma local: prefijo de sus tools (`mcp__local__ask_user`). */
|
|
5
|
+
export declare const LOCAL_MCP_SERVER = "local";
|
|
6
|
+
export declare const LOCAL_TOOL: {
|
|
7
|
+
readonly askUser: "ask_user";
|
|
8
|
+
readonly reply: "reply";
|
|
9
|
+
};
|
|
10
|
+
export declare const LOCAL_PLATFORM_TOOLS: readonly string[];
|
|
11
|
+
/** lo que pide un `runner run`: el prompt y sus flags de política. */
|
|
12
|
+
export interface LocalRequest {
|
|
13
|
+
prompt: string;
|
|
14
|
+
profile: PromptProfile;
|
|
15
|
+
repo: string | null;
|
|
16
|
+
branch: string | null;
|
|
17
|
+
push: boolean;
|
|
18
|
+
grants: ToolsetGrant[];
|
|
19
|
+
model: string | null;
|
|
20
|
+
}
|
|
21
|
+
/** una petición que no se lanza: el techo, la exposición o el consentimiento la niegan (exit 77). */
|
|
22
|
+
export declare class RequestRefusedError extends Error {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
/** `tipo:clave[:acceso]` como grant, o null si no tiene esa forma. */
|
|
26
|
+
export declare function parseGrant(raw: string): ToolsetGrant | null;
|
|
27
|
+
/** el toolset_v1 de una petición (ver cabecera). */
|
|
28
|
+
export declare function toolsetOfRequest(req: LocalRequest): ToolsetV1;
|
|
29
|
+
/** lo que el toolset pide por encima de lectura, como líneas para enseñar (vacío = no hay escalada). */
|
|
30
|
+
export declare function escalationOf(t: ToolsetV1): string[];
|
|
31
|
+
/**
|
|
32
|
+
* la petición contra la plataforma local de AHORA: lanza RequestRefusedError si el techo la recortaría o un grant no
|
|
33
|
+
* se puede cumplir (un tipo que el daemon no sirve, una clave no expuesta); si no, el toolset y su escalada.
|
|
34
|
+
*/
|
|
35
|
+
export declare function evaluateRequest(req: LocalRequest, platform: PlatformConfig, resourceTypes: readonly string[]): {
|
|
36
|
+
toolset: ToolsetV1;
|
|
37
|
+
escalation: string[];
|
|
38
|
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E,GAAG;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAa3J"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// la política de un `runner run` (t#495, M7): el usuario ES la plataforma local, así que sus flags son la petición
|
|
2
|
+
// (toolset_v1) y su techo el de `platforms.local` (por defecto el entero: platforms/types.ts::LOCAL_PLATFORM_DEFAULTS).
|
|
3
|
+
// el daemon aplica el claim igual que el de cualquier plataforma v0 (platforms/claim-v0.ts); esto mira lo mismo ANTES
|
|
4
|
+
// de lanzar, para negarse con su exit code y decir qué falta en vez de recortar en silencio.
|
|
5
|
+
// decisiones:
|
|
6
|
+
// - perfil read por defecto: shell de lectura, sin escribir, memoria y web; edit da shell entera y escritura; --push el
|
|
7
|
+
// push; --repo un grant del repo (full en edit, read si no); --grant tipo:clave[:acceso] añade grants.
|
|
8
|
+
// - las tools de la plataforma local son ask_user y reply (local/mcp.ts), siempre.
|
|
9
|
+
// - pedir más que el techo no se recorta: se rechaza diciendo qué campos (lo que intersect anotaría en narrowed).
|
|
10
|
+
// - escalada = lo que pasa de lectura: shell entera, escritura, push y grants de interact o full. en una tty se enseña
|
|
11
|
+
// y se pregunta; sin tty, solo con --yes Y `unattendedEscalation` en la plataforma local.
|
|
12
|
+
import { PROMPT_PROFILE } from '../claim.js';
|
|
13
|
+
import { checkGrants, CLAIM_REJECT, ClaimRejectedError } from '../platforms/claim-v0.js';
|
|
14
|
+
import { RESOURCE_TYPE } from '../resources/types.js';
|
|
15
|
+
import { intersectToolset } from '../toolset/intersect.js';
|
|
16
|
+
import { GRANT_ACCESS, TOOLSET_SHELL, TOOLSET_V1 } from '../vendor/runner-protocol/index.js';
|
|
17
|
+
/** nombre del servidor mcp de la plataforma local: prefijo de sus tools (`mcp__local__ask_user`). */
|
|
18
|
+
export const LOCAL_MCP_SERVER = 'local';
|
|
19
|
+
export const LOCAL_TOOL = { askUser: 'ask_user', reply: 'reply' };
|
|
20
|
+
export const LOCAL_PLATFORM_TOOLS = Object.values(LOCAL_TOOL);
|
|
21
|
+
// separador de `--grant tipo:clave[:acceso]`.
|
|
22
|
+
const GRANT_SEPARATOR = ':';
|
|
23
|
+
const GRANT_PARTS_MIN = 2;
|
|
24
|
+
const GRANT_PARTS_MAX = 3;
|
|
25
|
+
const ACCESS_LEVELS = Object.values(GRANT_ACCESS);
|
|
26
|
+
/** una petición que no se lanza: el techo, la exposición o el consentimiento la niegan (exit 77). */
|
|
27
|
+
export class RequestRefusedError extends Error {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = 'RequestRefusedError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** `tipo:clave[:acceso]` como grant, o null si no tiene esa forma. */
|
|
34
|
+
export function parseGrant(raw) {
|
|
35
|
+
const parts = raw.split(GRANT_SEPARATOR);
|
|
36
|
+
if (parts.length < GRANT_PARTS_MIN || parts.length > GRANT_PARTS_MAX || parts.some((p) => !p))
|
|
37
|
+
return null;
|
|
38
|
+
const [type, key, access] = parts;
|
|
39
|
+
if (access !== undefined && !ACCESS_LEVELS.includes(access))
|
|
40
|
+
return null;
|
|
41
|
+
return { type, key, access: access ?? GRANT_ACCESS.read };
|
|
42
|
+
}
|
|
43
|
+
/** el toolset_v1 de una petición (ver cabecera). */
|
|
44
|
+
export function toolsetOfRequest(req) {
|
|
45
|
+
const edit = req.profile === PROMPT_PROFILE.edit;
|
|
46
|
+
const repo = req.repo ? [{ type: RESOURCE_TYPE.repo, key: req.repo, access: edit ? GRANT_ACCESS.full : GRANT_ACCESS.read }] : [];
|
|
47
|
+
return {
|
|
48
|
+
v: TOOLSET_V1,
|
|
49
|
+
shell: edit ? TOOLSET_SHELL.full : TOOLSET_SHELL.read,
|
|
50
|
+
fsWrite: edit,
|
|
51
|
+
memory: true,
|
|
52
|
+
web: true,
|
|
53
|
+
vcsPush: req.push,
|
|
54
|
+
grants: [...repo, ...req.grants],
|
|
55
|
+
platformTools: [...LOCAL_PLATFORM_TOOLS],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** lo que el toolset pide por encima de lectura, como líneas para enseñar (vacío = no hay escalada). */
|
|
59
|
+
export function escalationOf(t) {
|
|
60
|
+
return [
|
|
61
|
+
...(t.shell === TOOLSET_SHELL.full ? ['shell entera'] : []),
|
|
62
|
+
...(t.fsWrite ? ['escribir ficheros'] : []),
|
|
63
|
+
...(t.vcsPush ? ['push'] : []),
|
|
64
|
+
...t.grants.filter((g) => (g.access ?? GRANT_ACCESS.read) !== GRANT_ACCESS.read).map((g) => `${g.type} ${g.key}: ${g.access}`),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* la petición contra la plataforma local de AHORA: lanza RequestRefusedError si el techo la recortaría o un grant no
|
|
69
|
+
* se puede cumplir (un tipo que el daemon no sirve, una clave no expuesta); si no, el toolset y su escalada.
|
|
70
|
+
*/
|
|
71
|
+
export function evaluateRequest(req, platform, resourceTypes) {
|
|
72
|
+
const toolset = toolsetOfRequest(req);
|
|
73
|
+
try {
|
|
74
|
+
checkGrants(toolset, { ceiling: platform.ceiling, expose: platform.expose, resourceTypes });
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (!(err instanceof ClaimRejectedError))
|
|
78
|
+
throw err;
|
|
79
|
+
// una clave sin exponer: el comando que la expone.
|
|
80
|
+
const hint = err.code === CLAIM_REJECT.notExposed ? toolset.grants.find((g) => err.message.includes(`${g.type} ${g.key}`)) : undefined;
|
|
81
|
+
throw new RequestRefusedError(`${err.message}${hint ? ` (\`duckhunt-runner platforms expose local ${hint.type} ${hint.key}\`)` : ''}`);
|
|
82
|
+
}
|
|
83
|
+
const { narrowed } = intersectToolset(toolset, platform.ceiling);
|
|
84
|
+
if (narrowed.length > 0)
|
|
85
|
+
throw new RequestRefusedError(`el techo de la plataforma local no lo permite: ${narrowed.join(', ')}`);
|
|
86
|
+
return { toolset, escalation: escalationOf(toolset) };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/local/policy.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,wHAAwH;AACxH,sHAAsH;AACtH,6FAA6F;AAC7F,cAAc;AACd,wHAAwH;AACxH,yGAAyG;AACzG,mFAAmF;AACnF,kHAAkH;AAClH,uHAAuH;AACvH,4FAA4F;AAE5F,OAAO,EAAE,cAAc,EAAsB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEzF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAuD,MAAM,oCAAoC,CAAC;AAElJ,qGAAqG;AACrG,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACxC,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAW,CAAC;AAC3E,MAAM,CAAC,MAAM,oBAAoB,GAAsB,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAEjF,8CAA8C;AAC9C,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,aAAa,GAAsB,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAarE,qGAAqG;AACrG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC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C;YAAE,MAAM,GAAG,CAAC;QACpD,mDAAmD;QACnD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvI,MAAM,IAAI,mBAAmB,CAAC,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,8CAA8C,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACzI,CAAC;IACD,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,mBAAmB,CAAC,kDAAkD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChI,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { LocalMessage, LocalPlatform } from '../platforms/local.js';
|
|
2
|
+
import type { ToolsetV1 } from '../vendor/runner-protocol/index.js';
|
|
3
|
+
import { type LocalRequest } from './policy.js';
|
|
4
|
+
export declare const SOCKET_OP: {
|
|
5
|
+
readonly evaluate: "evaluate";
|
|
6
|
+
readonly submit: "submit";
|
|
7
|
+
readonly answer: "answer";
|
|
8
|
+
readonly cancel: "cancel";
|
|
9
|
+
readonly subscribe: "subscribe";
|
|
10
|
+
};
|
|
11
|
+
/** lo que manda el cliente. */
|
|
12
|
+
export type ClientMessage = {
|
|
13
|
+
op: typeof SOCKET_OP.evaluate;
|
|
14
|
+
request: LocalRequest;
|
|
15
|
+
} | {
|
|
16
|
+
op: typeof SOCKET_OP.submit;
|
|
17
|
+
request: LocalRequest;
|
|
18
|
+
} | {
|
|
19
|
+
op: typeof SOCKET_OP.answer;
|
|
20
|
+
conversation: string;
|
|
21
|
+
text: string;
|
|
22
|
+
} | {
|
|
23
|
+
op: typeof SOCKET_OP.cancel;
|
|
24
|
+
conversation: string;
|
|
25
|
+
} | {
|
|
26
|
+
op: typeof SOCKET_OP.subscribe;
|
|
27
|
+
conversation: string;
|
|
28
|
+
};
|
|
29
|
+
/** lo que contesta el daemon, además de lo que oye de la conversación. */
|
|
30
|
+
export type ServerMessage = LocalMessage | {
|
|
31
|
+
type: 'evaluated';
|
|
32
|
+
evaluation: LocalEvaluation;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'accepted';
|
|
35
|
+
conversation: string;
|
|
36
|
+
segment: number;
|
|
37
|
+
toolset?: ToolsetV1;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'refused';
|
|
40
|
+
message: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'error';
|
|
43
|
+
message: string;
|
|
44
|
+
};
|
|
45
|
+
/** lo que diría el daemon de una petición sin lanzarla: su toolset y si la local acepta escaladas sin tty. */
|
|
46
|
+
export interface LocalEvaluation {
|
|
47
|
+
toolset: ToolsetV1;
|
|
48
|
+
unattendedEscalation: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** lo que el daemon pone para servir el socket: la plataforma y cómo aceptar una petición con la config de AHORA. */
|
|
51
|
+
export interface LocalHost {
|
|
52
|
+
platform: LocalPlatform;
|
|
53
|
+
evaluate(request: LocalRequest): LocalEvaluation;
|
|
54
|
+
}
|
|
55
|
+
/** ruta del socket (sin crearlo). */
|
|
56
|
+
export declare function localSocketPath(): string;
|
|
57
|
+
/** escucha en local.sock (ver cabecera). devuelve con qué cerrarlo. */
|
|
58
|
+
export declare function serveLocal(host: LocalHost, file?: string): Promise<() => Promise<void>>;
|
|
59
|
+
/** una conexión a local.sock desde el cli. */
|
|
60
|
+
export interface LocalConnection {
|
|
61
|
+
send(m: ClientMessage): void;
|
|
62
|
+
onMessage(handler: (m: ServerMessage) => void): void;
|
|
63
|
+
readonly closed: Promise<void>;
|
|
64
|
+
close(): void;
|
|
65
|
+
}
|
|
66
|
+
/** conecta con el daemon; null si no hay ninguno escuchando. */
|
|
67
|
+
export declare function connectLocal(file?: string): Promise<LocalConnection | null>;
|
|
68
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/local/socket.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAUrE,eAAO,MAAM,SAAS;;;;;;CAAkH,CAAC;AAEzI,+BAA+B;AAC/B,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,OAAO,SAAS,CAAC,QAAQ,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GACxD;IAAE,EAAE,EAAE,OAAO,SAAS,CAAC,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GACtD;IAAE,EAAE,EAAE,OAAO,SAAS,CAAC,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnE;IAAE,EAAE,EAAE,OAAO,SAAS,CAAC,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,EAAE,EAAE,OAAO,SAAS,CAAC,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,0EA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
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// local.sock (t#495, M7): con el daemon en marcha, `runner run` es un cliente fino de la plataforma local que vive en
|
|
2
|
+
// él, así comparte sus slots, sus cuotas y su lock de git. ndjson en un socket unix: el cliente manda `submit`,
|
|
3
|
+
// `answer`, `cancel` o `subscribe` y el daemon contesta `accepted` (o `refused`) y le pasa lo que oye de esa
|
|
4
|
+
// conversación (local/platform.ts::LocalMessage) hasta su result.
|
|
5
|
+
// decisiones:
|
|
6
|
+
// - <runnerHome>/sockets/local.sock, 0600 dentro de un directorio 0700: solo el usuario dueño habla con él. quien
|
|
7
|
+
// llega aquí es ese usuario: el techo y la exposición se aplican igual (al aceptar y en el claim), el
|
|
8
|
+
// consentimiento de una escalada es cosa del cli.
|
|
9
|
+
// - el daemon tiene su lock al escuchar: un socket que ya estaba es de un daemon muerto y se borra.
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import net from 'node:net';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { runnerHome } from '../config.js';
|
|
14
|
+
import { RequestRefusedError } from './policy.js';
|
|
15
|
+
const SOCKETS_SUBDIR = 'sockets';
|
|
16
|
+
const SOCKET_FILE = 'local.sock';
|
|
17
|
+
const DIR_MODE = 0o700;
|
|
18
|
+
const SOCKET_MODE = 0o600;
|
|
19
|
+
const NEWLINE = '\n';
|
|
20
|
+
// tope de una línea del cliente (un prompt largo cabe de sobra).
|
|
21
|
+
const LINE_MAX_BYTES = 1 << 20;
|
|
22
|
+
export const SOCKET_OP = { evaluate: 'evaluate', submit: 'submit', answer: 'answer', cancel: 'cancel', subscribe: 'subscribe' };
|
|
23
|
+
/** ruta del socket (sin crearlo). */
|
|
24
|
+
export function localSocketPath() {
|
|
25
|
+
return path.join(runnerHome(), SOCKETS_SUBDIR, SOCKET_FILE);
|
|
26
|
+
}
|
|
27
|
+
// las líneas ndjson de un stream, acotadas.
|
|
28
|
+
function onLines(stream, handle) {
|
|
29
|
+
let buffer = '';
|
|
30
|
+
stream.setEncoding('utf8');
|
|
31
|
+
stream.on('data', (chunk) => {
|
|
32
|
+
buffer += chunk;
|
|
33
|
+
if (buffer.length > LINE_MAX_BYTES) {
|
|
34
|
+
stream.destroy();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const lines = buffer.split(NEWLINE);
|
|
38
|
+
buffer = lines.pop() ?? '';
|
|
39
|
+
lines.filter((l) => l.trim()).forEach(handle);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const write = (socket, m) => {
|
|
43
|
+
if (!socket.destroyed)
|
|
44
|
+
socket.write(`${JSON.stringify(m)}${NEWLINE}`);
|
|
45
|
+
};
|
|
46
|
+
// sigue la conversación hasta su result (o hasta que el cliente se vaya).
|
|
47
|
+
function follow(socket, platform, conversation) {
|
|
48
|
+
const stop = platform.subscribe(conversation, (m) => {
|
|
49
|
+
write(socket, m);
|
|
50
|
+
if (m.type === 'result')
|
|
51
|
+
stop();
|
|
52
|
+
});
|
|
53
|
+
socket.once('close', stop);
|
|
54
|
+
}
|
|
55
|
+
function handle(socket, host, raw) {
|
|
56
|
+
let m;
|
|
57
|
+
try {
|
|
58
|
+
m = JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return write(socket, { type: 'error', message: 'línea ilegible' });
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
if (m.op === SOCKET_OP.evaluate)
|
|
65
|
+
return write(socket, { type: 'evaluated', evaluation: host.evaluate(m.request) });
|
|
66
|
+
if (m.op === SOCKET_OP.submit) {
|
|
67
|
+
const { toolset } = host.evaluate(m.request);
|
|
68
|
+
const conversation = host.platform.submit(m.request, toolset);
|
|
69
|
+
follow(socket, host.platform, conversation);
|
|
70
|
+
return write(socket, { type: 'accepted', conversation, segment: 1, toolset });
|
|
71
|
+
}
|
|
72
|
+
if (m.op === SOCKET_OP.answer) {
|
|
73
|
+
follow(socket, host.platform, m.conversation);
|
|
74
|
+
const segment = host.platform.answer(m.conversation, m.text);
|
|
75
|
+
return write(socket, { type: 'accepted', conversation: m.conversation, segment });
|
|
76
|
+
}
|
|
77
|
+
if (m.op === SOCKET_OP.cancel)
|
|
78
|
+
return host.platform.cancel(m.conversation);
|
|
79
|
+
if (m.op === SOCKET_OP.subscribe)
|
|
80
|
+
return follow(socket, host.platform, m.conversation);
|
|
81
|
+
write(socket, { type: 'error', message: `op desconocida: ${String(m.op)}` });
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
write(socket, err instanceof RequestRefusedError ? { type: 'refused', message: err.message } : { type: 'error', message: err.message });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** escucha en local.sock (ver cabecera). devuelve con qué cerrarlo. */
|
|
88
|
+
export async function serveLocal(host, file = localSocketPath()) {
|
|
89
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: DIR_MODE });
|
|
90
|
+
fs.chmodSync(path.dirname(file), DIR_MODE);
|
|
91
|
+
fs.rmSync(file, { force: true });
|
|
92
|
+
const sockets = new Set();
|
|
93
|
+
const server = net.createServer((socket) => {
|
|
94
|
+
sockets.add(socket);
|
|
95
|
+
socket.once('close', () => sockets.delete(socket));
|
|
96
|
+
socket.on('error', () => socket.destroy());
|
|
97
|
+
onLines(socket, (line) => handle(socket, host, line));
|
|
98
|
+
});
|
|
99
|
+
await new Promise((resolve, reject) => {
|
|
100
|
+
server.once('error', reject);
|
|
101
|
+
server.listen(file, () => resolve());
|
|
102
|
+
});
|
|
103
|
+
fs.chmodSync(file, SOCKET_MODE);
|
|
104
|
+
server.unref();
|
|
105
|
+
return async () => {
|
|
106
|
+
sockets.forEach((s) => s.destroy());
|
|
107
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
108
|
+
fs.rmSync(file, { force: true });
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** conecta con el daemon; null si no hay ninguno escuchando. */
|
|
112
|
+
export async function connectLocal(file = localSocketPath()) {
|
|
113
|
+
const socket = await new Promise((resolve) => {
|
|
114
|
+
const s = net.createConnection(file);
|
|
115
|
+
s.once('connect', () => resolve(s));
|
|
116
|
+
s.once('error', () => resolve(null));
|
|
117
|
+
});
|
|
118
|
+
if (!socket)
|
|
119
|
+
return null;
|
|
120
|
+
const handlers = [];
|
|
121
|
+
const closed = new Promise((resolve) => socket.once('close', () => resolve()));
|
|
122
|
+
socket.on('error', () => socket.destroy());
|
|
123
|
+
onLines(socket, (line) => {
|
|
124
|
+
let m;
|
|
125
|
+
try {
|
|
126
|
+
m = JSON.parse(line);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
handlers.forEach((h) => h(m));
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
send: (m) => void socket.write(`${JSON.stringify(m)}${NEWLINE}`),
|
|
135
|
+
onMessage: (h) => void handlers.push(h),
|
|
136
|
+
closed,
|
|
137
|
+
close: () => socket.end(),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=socket.js.map
|