@agentvault/agentvault 0.23.71 → 0.23.72

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.
Files changed (71) hide show
  1. package/README.md +3 -1
  2. package/dist/atomic-file.d.ts +11 -0
  3. package/dist/atomic-file.d.ts.map +1 -0
  4. package/dist/channel.d.ts +675 -44
  5. package/dist/channel.d.ts.map +1 -1
  6. package/dist/cli.js +8162 -2403
  7. package/dist/cli.js.map +4 -4
  8. package/dist/dm-group-pins.d.ts +190 -0
  9. package/dist/dm-group-pins.d.ts.map +1 -0
  10. package/dist/dr-refusal.d.ts +54 -0
  11. package/dist/dr-refusal.d.ts.map +1 -0
  12. package/dist/file-send-failure.d.ts +115 -0
  13. package/dist/file-send-failure.d.ts.map +1 -0
  14. package/dist/file-send-policy.d.ts +251 -0
  15. package/dist/file-send-policy.d.ts.map +1 -0
  16. package/dist/full-permissions.d.ts +479 -0
  17. package/dist/full-permissions.d.ts.map +1 -0
  18. package/dist/gateway-send.d.ts +8 -0
  19. package/dist/gateway-send.d.ts.map +1 -1
  20. package/dist/harness-compat.d.ts +12 -0
  21. package/dist/harness-compat.d.ts.map +1 -1
  22. package/dist/http-handlers.d.ts +5 -1
  23. package/dist/http-handlers.d.ts.map +1 -1
  24. package/dist/index.d.ts +13 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +8653 -2417
  27. package/dist/index.js.map +4 -4
  28. package/dist/local-api-server.d.ts +71 -0
  29. package/dist/local-api-server.d.ts.map +1 -0
  30. package/dist/local-api.d.ts +107 -0
  31. package/dist/local-api.d.ts.map +1 -0
  32. package/dist/mcp-handlers.d.ts +15 -1
  33. package/dist/mcp-handlers.d.ts.map +1 -1
  34. package/dist/mcp-server.d.ts +4 -1
  35. package/dist/mcp-server.d.ts.map +1 -1
  36. package/dist/off-sequence-report.d.ts +74 -0
  37. package/dist/off-sequence-report.d.ts.map +1 -0
  38. package/dist/onturn-stop.d.ts +253 -0
  39. package/dist/onturn-stop.d.ts.map +1 -0
  40. package/dist/openclaw-entry.d.ts +32 -2
  41. package/dist/openclaw-entry.d.ts.map +1 -1
  42. package/dist/openclaw-entry.js +1377 -171
  43. package/dist/openclaw-entry.js.map +4 -4
  44. package/dist/openclaw-file-send.d.ts +308 -0
  45. package/dist/openclaw-file-send.d.ts.map +1 -0
  46. package/dist/openclaw-plugin.d.ts +7 -2
  47. package/dist/openclaw-plugin.d.ts.map +1 -1
  48. package/dist/openclaw-room-taint.d.ts +43 -0
  49. package/dist/openclaw-room-taint.d.ts.map +1 -0
  50. package/dist/openclaw-sender.d.ts +47 -0
  51. package/dist/openclaw-sender.d.ts.map +1 -0
  52. package/dist/openclaw-types.d.ts +7 -1
  53. package/dist/openclaw-types.d.ts.map +1 -1
  54. package/dist/owner-devices.d.ts +71 -0
  55. package/dist/owner-devices.d.ts.map +1 -0
  56. package/dist/owner-epoch.d.ts +36 -0
  57. package/dist/owner-epoch.d.ts.map +1 -0
  58. package/dist/room-send-error.d.ts +17 -0
  59. package/dist/room-send-error.d.ts.map +1 -0
  60. package/dist/sender-binding.d.ts +130 -0
  61. package/dist/sender-binding.d.ts.map +1 -0
  62. package/dist/tool-telemetry.d.ts +1 -1
  63. package/dist/tool-telemetry.d.ts.map +1 -1
  64. package/dist/turn-token.d.ts +168 -0
  65. package/dist/turn-token.d.ts.map +1 -0
  66. package/dist/types.d.ts +160 -6
  67. package/dist/types.d.ts.map +1 -1
  68. package/openclaw.plugin.json +1 -1
  69. package/package.json +1 -1
  70. package/dist/workspace-handlers.d.ts +0 -62
  71. package/dist/workspace-handlers.d.ts.map +0 -1
@@ -0,0 +1,71 @@
1
+ /**
2
+ * #1791 — the one request pipeline for the plugin's local HTTP API, shared by
3
+ * the self-managed loopback server (`SecureChannel.startHttpServer`) and the
4
+ * OpenClaw managed routes (`/agentvault/*`). Both run the same checks
5
+ * (`local-api.ts`) before any body is read or any handler runs, so neither
6
+ * surface can drift from the other.
7
+ */
8
+ import type { IncomingMessage, ServerResponse } from "node:http";
9
+ import type { SecureChannel } from "./channel.js";
10
+ import { type LocalApiRefusal } from "./local-api.js";
11
+ /** What the pipeline needs from a channel. */
12
+ export interface LocalApiChannel {
13
+ config?: {
14
+ agentName?: string;
15
+ };
16
+ mcpServer?: {
17
+ skillCount?: number;
18
+ handleRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
19
+ } | null;
20
+ reportLocalApiRefusal(route: string, reason: LocalApiRefusal): void;
21
+ }
22
+ export interface LocalApiContext {
23
+ token: string;
24
+ /** Exact port for the self-managed server; null for the managed routes (gateway port). */
25
+ port: number | null;
26
+ /** The loopback port advertised by `/mcp-config`. */
27
+ advertisedPort: number;
28
+ /** The dispatch key when the URL is not it (managed: `/agentvault/send` → `/send`). */
29
+ route?: string;
30
+ }
31
+ export interface LocalApiReply {
32
+ status: number;
33
+ body: unknown;
34
+ close?: boolean;
35
+ }
36
+ /**
37
+ * Serve one request on a Node `IncomingMessage`/`ServerResponse` pair: the
38
+ * self-managed server, and the managed routes on OpenClaw ≥ 2026.10 (which
39
+ * call a route handler as `(req, res)`).
40
+ */
41
+ export declare function serveLocalApi(req: IncomingMessage, res: ServerResponse, channel: SecureChannel, ctx: LocalApiContext): Promise<void>;
42
+ /**
43
+ * The handler for one OpenClaw managed route (`/agentvault/<route>`). The
44
+ * gateway's own auth (`auth: "gateway"`) is not enough on its own: in gateway
45
+ * auth modes `none` and `tailscale` it lets a browser through, so the same
46
+ * Origin, Host and token checks apply here (design §13.2, L1).
47
+ *
48
+ * Order (review L2): remote address, Origin and Host first — none of them
49
+ * needs a channel or reads a token file, so a page looping requests cannot
50
+ * make the plugin touch the disk or log.
51
+ *
52
+ * Which agent (review L5): the presented token selects the channel. With
53
+ * several accounts in one gateway, whichever agent's token arrives, that agent
54
+ * serves the request — so it no longer matters which channel registered first
55
+ * or which server started first.
56
+ *
57
+ * OpenClaw 2026.10 calls `handler(req, res)` with Node objects and ignores the
58
+ * return value's shape (anything but `false` means "handled"). The older
59
+ * simplified shape is still answered with `{status, body}`.
60
+ */
61
+ export declare function managedLocalApiHandler(route: string, getChannels: () => Iterable<SecureChannel>): (req: unknown, res?: unknown) => Promise<unknown>;
62
+ /**
63
+ * Start the local API from an OpenClaw entry and log what ACTUALLY happened
64
+ * (#1791 review 2). `startHttpServer` returning true only means the binds
65
+ * began: the [::1] bind can still fail and shut everything down. So the
66
+ * "listening" line waits for `http-ready`, and `http-failed` logs "NOT
67
+ * started". Called on every channel "ready" (reconnects too): while a server
68
+ * is already up or starting it says nothing and leaves no listeners behind.
69
+ */
70
+ export declare function startLocalApiWithLog(channel: SecureChannel, port: number, log: (m: string) => void): void;
71
+ //# sourceMappingURL=local-api-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-api-server.d.ts","sourceRoot":"","sources":["../src/local-api-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAaL,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,8CAA8C;AAC9C,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,SAAS,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1I,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;CACrE;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA6ED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,aAAa,EACtB,GAAG,EAAE,eAAe,GACnB,OAAO,CAAC,IAAI,CAAC,CAyDf;AA8BD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,QAAQ,CAAC,aAAa,CAAC,GACzC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAiDnD;AASD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CA0BzG"}
@@ -0,0 +1,107 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ export declare const LOCAL_API_TOKEN_FILE = "local-api.token";
3
+ /** Lower-case: Node lower-cases incoming header names. */
4
+ export declare const LOCAL_API_TOKEN_HEADER = "x-agentvault-local-token";
5
+ export declare const LOCAL_API_BODY_LIMIT: number;
6
+ /**
7
+ * Review L7: a local caller sends its headers at once, so an unauthenticated
8
+ * connection gets 5 s to finish them (Node's default is 60 s) and the whole
9
+ * request 15 s. At most 32 connections at a time, inside the gateway process.
10
+ */
11
+ export declare const LOCAL_API_HEADERS_TIMEOUT_MS = 5000;
12
+ export declare const LOCAL_API_REQUEST_TIMEOUT_MS = 15000;
13
+ export declare const LOCAL_API_MAX_CONNECTIONS = 32;
14
+ /** The one thing a 401 says: fixed text, no path, no token. */
15
+ export declare const LOCAL_API_TOKEN_HINT: string;
16
+ /**
17
+ * Hosts a client may send the local token to: loopback LITERALS only. Not
18
+ * `localhost` (it may resolve to an address someone else holds), and never a
19
+ * remote gateway URL (review L6).
20
+ */
21
+ export declare function isLoopbackLiteral(hostname: string): boolean;
22
+ export type LocalTokenProblem = "symlink" | "not_file" | "owner" | "mode" | "malformed" | "unreadable";
23
+ export declare class LocalApiTokenError extends Error {
24
+ readonly problem: LocalTokenProblem;
25
+ readonly path: string;
26
+ constructor(problem: LocalTokenProblem, path: string);
27
+ }
28
+ export declare function localApiTokenPath(dataDir: string): string;
29
+ /**
30
+ * Return this agent's local API token, creating it if it does not exist.
31
+ *
32
+ * Creation is `O_CREAT|O_EXCL|O_NOFOLLOW` with mode 0600 (and an explicit
33
+ * `fchmod`, because the create mode is masked by umask and never widens).
34
+ * An existing file is opened with `O_NOFOLLOW` and checked through its own
35
+ * descriptor (no lstat-then-open race): a regular file, owned by this user,
36
+ * with no group or other bits. Anything else throws, and the caller must not
37
+ * serve — a token other users can read protects nothing, and silently
38
+ * "fixing" the mode would hide that it was exposed.
39
+ *
40
+ * `expectedUid` exists for tests (a wrong owner cannot be made without root).
41
+ */
42
+ export declare function ensureLocalApiToken(dataDir: string, opts?: {
43
+ expectedUid?: number;
44
+ }): string;
45
+ /**
46
+ * Read a token for a CLIENT (the CLI, `gateway-send`). Never creates one and
47
+ * never throws: a missing file means "send no token", and the server answers
48
+ * 401, which the caller turns into a readable error.
49
+ */
50
+ export declare function readLocalApiToken(dataDir: string | undefined): string | undefined;
51
+ /**
52
+ * Constant-time and length-safe: both sides are hashed to 32 bytes first, so
53
+ * `timingSafeEqual` never sees unequal lengths and the comparison leaks
54
+ * neither the content nor the length of the expected token.
55
+ */
56
+ export declare function tokenMatches(presented: string | string[] | undefined, expected: string): boolean;
57
+ export type LocalApiRefusal = "remote" | "origin" | "host" | "token" | "too_large";
58
+ /**
59
+ * `port` given: Host must be exactly a loopback name and that port. `port`
60
+ * null (the gateway's managed routes, whose port the plugin is not told): Host
61
+ * must still be a loopback name, with any numeric port. Rebinding is defeated
62
+ * either way — the attacker's page sends its own hostname, never a literal.
63
+ */
64
+ export declare function hostAllowed(host: string | undefined, port: number | null): boolean;
65
+ export declare function headerValue(headers: Record<string, string | string[] | undefined>, name: string): string | string[] | undefined;
66
+ /**
67
+ * The header checks, in order. `null` = allowed. Run before any body is read
68
+ * and before any handler runs.
69
+ */
70
+ export declare function checkLocalRequest(req: {
71
+ headers: Record<string, string | string[] | undefined>;
72
+ socket?: {
73
+ remoteAddress?: string;
74
+ };
75
+ }, opts: {
76
+ port: number | null;
77
+ token: string;
78
+ checkRemote?: boolean;
79
+ }): LocalApiRefusal | null;
80
+ export declare class BodyTooLargeError extends Error {
81
+ constructor();
82
+ }
83
+ /**
84
+ * Read a request body, refusing it as soon as it passes `limit` bytes. A
85
+ * declared `Content-Length` over the limit is refused before a byte is read;
86
+ * otherwise every streamed chunk is counted and the read stops at the cap —
87
+ * the rest is never held in memory.
88
+ */
89
+ export declare function readLimitedBody(req: IncomingMessage, limit?: number): Promise<Buffer>;
90
+ /** Generic bodies only: a refusal never says why (the span does). */
91
+ export declare const REFUSAL_RESPONSE: Record<LocalApiRefusal, {
92
+ status: number;
93
+ error: string;
94
+ }>;
95
+ export declare function sendJson(res: ServerResponse, status: number, body: unknown, close?: boolean): void;
96
+ /** The JSON body of a refusal. Only a 401 adds the fixed hint. */
97
+ export declare function refusalBody(reason: LocalApiRefusal): {
98
+ ok: false;
99
+ error: string;
100
+ hint?: string;
101
+ };
102
+ export declare function refuse(res: ServerResponse, reason: LocalApiRefusal): void;
103
+ export declare function localRouteLabel(url: string | undefined): string;
104
+ export declare function registerLocalApiToken(port: number, token: string): void;
105
+ export declare function unregisterLocalApiToken(port: number, token: string): void;
106
+ export declare function registeredLocalApiToken(port: number | undefined): string | undefined;
107
+ //# sourceMappingURL=local-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-api.d.ts","sourceRoot":"","sources":["../src/local-api.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,0DAA0D;AAC1D,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AACjE,eAAO,MAAM,oBAAoB,QAAY,CAAC;AAC9C;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,OAAQ,CAAC;AAClD,eAAO,MAAM,4BAA4B,QAAS,CAAC;AACnD,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,QAEwC,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAG3D;AAKD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,WAAW,GAAG,YAAY,CAAC;AAEvG,qBAAa,kBAAmB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,OAAO,EAAE,iBAAiB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAjD,OAAO,EAAE,iBAAiB,EAAW,IAAI,EAAE,MAAM;CAIvE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAgChG;AAoCD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAQjF;AAED;;;;GAIG;AACH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,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,UAAQ,GAAG,IAAI,CAWhG;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAGhG;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAEzE;AAID,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAI/D;AASD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAEvE;AACD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAEzE;AACD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGpF"}
@@ -5,6 +5,13 @@
5
5
  */
6
6
  import type { IncomingMessage, ServerResponse } from "node:http";
7
7
  import type { AgentVaultMcpServer } from "./mcp-server.js";
8
+ /** #1791 review L4: what the handler authenticates against. */
9
+ export interface McpHandlerAuth {
10
+ /** The agent's local API token (`SecureChannel.localApiToken()`). */
11
+ token: string;
12
+ /** The loopback port this handler is served on (the `Host` must name it). */
13
+ port: number;
14
+ }
8
15
  /**
9
16
  * Create an HTTP request handler for MCP routes.
10
17
  *
@@ -14,8 +21,15 @@ import type { AgentVaultMcpServer } from "./mcp-server.js";
14
21
  * DELETE /mcp — Close MCP session
15
22
  *
16
23
  * All other paths are passed through to the next handler.
24
+ *
25
+ * #1791 review L4: this is exported for SDK users who mount /mcp on their own
26
+ * server, and it used to serve anyone (any web page included). It now runs
27
+ * the plugin's loopback checks — no Origin, exact loopback Host, the agent's
28
+ * local token, a 64 KB body cap — and WITHOUT `auth` it refuses every MCP
29
+ * request (401), so an old call site fails closed and loudly instead of
30
+ * staying open.
17
31
  */
18
- export declare function createMcpHandler(mcpServer: AgentVaultMcpServer | null, basePath?: string): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
32
+ export declare function createMcpHandler(mcpServer: AgentVaultMcpServer | null, basePath?: string, auth?: McpHandlerAuth): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
19
33
  /**
20
34
  * Build a status object with MCP info for the /status endpoint.
21
35
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-handlers.d.ts","sourceRoot":"","sources":["../src/mcp-handlers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,mBAAmB,GAAG,IAAI,EACrC,QAAQ,GAAE,MAAe,GACxB,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CA0BxE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,mBAAmB,GAAG,IAAI,GACpC;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAQpD"}
1
+ {"version":3,"file":"mcp-handlers.d.ts","sourceRoot":"","sources":["../src/mcp-handlers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D,+DAA+D;AAC/D,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;CACd;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,mBAAmB,GAAG,IAAI,EACrC,QAAQ,GAAE,MAAe,EACzB,IAAI,CAAC,EAAE,cAAc,GACpB,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CA8DxE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,mBAAmB,GAAG,IAAI,GACpC;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CAQpD"}
@@ -70,8 +70,11 @@ export declare class AgentVaultMcpServer {
70
70
  * so the single McpServer instance is ready for the next caller.
71
71
  *
72
72
  * Local requests from 127.0.0.1/::1 bypass SPT validation (owner access).
73
+ * #1791: the loopback server authenticates them first (Origin, Host, local
74
+ * token) and reads the POST body itself under its 64 KB cap; it hands the
75
+ * parsed body in as `parsedBody`, so the transport never reads the stream.
73
76
  */
74
- handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
77
+ handleRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
75
78
  /**
76
79
  * Register a single skill as an MCP tool.
77
80
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAMjE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO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 "Surface a failed run").
4
+ *
5
+ * Every run and every bound stop is a span (`av.gates.off_sequence`,
6
+ * `av.gates.unknown_kill`). A FAILED one — a family callback that threw or
7
+ * timed out, or processes still running after the descendant-tree stop — is
8
+ * never left to a log line or `lastOffSequence()` alone:
9
+ *
10
+ * - a `ai.agent.tool.invoke` span with `tool.error_kind = off_sequence_failed`
11
+ * (the existing agent-error path: the owner's "Recent problems" on the
12
+ * agent's Health page, and the agent-reported evidence Admin reads);
13
+ * - an `off_sequence_failed` channel event, for the family and the host;
14
+ * - one plain notice in the owner's 1:1 chat per on period (#1560: failures
15
+ * are shown, never swallowed), saying what to do.
16
+ *
17
+ * Nothing here carries message text, paths, pids or exception messages.
18
+ * THIS FILE MUST NOT import the plugin core's reader module (the permission
19
+ * field guard checks it on its raw text); it takes results structurally.
20
+ */
21
+ import { type ToolSpanSink } from "./tool-telemetry.js";
22
+ export declare const OFF_SEQUENCE_FAILED_CODE = "off_sequence_failed";
23
+ /** The `tool.name` of the failure span. Not a send tool: it delivers nothing. */
24
+ export declare const OFF_SEQUENCE_TOOL_NAME = "off_sequence";
25
+ export declare const OFF_SEQUENCE_SPAN = "av.gates.off_sequence";
26
+ export declare const BOUND_STOP_SPAN = "av.gates.unknown_kill";
27
+ export interface OffSequenceRunLike {
28
+ sequenceId: number;
29
+ trigger: string;
30
+ ran: number;
31
+ failed: number;
32
+ timedOut: number;
33
+ killed: number;
34
+ unverified?: boolean;
35
+ onPeriod: number;
36
+ }
37
+ export interface BoundStopLike {
38
+ killed: number;
39
+ state: string;
40
+ failed: boolean;
41
+ unverified?: boolean;
42
+ attempt: number;
43
+ onPeriod: number;
44
+ }
45
+ /** The sink `SecureChannel.telemetry` provides (a `TelemetryReporter`). */
46
+ export interface GatesSpanSink extends ToolSpanSink {
47
+ }
48
+ /**
49
+ * A short family label for spans, from the client build string the channel
50
+ * reports (`@agentvault/claude-bridge@0.8.42` → `claude-bridge`; the plugin's
51
+ * own default `@agentvault/agentvault@…` → `agentvault`, the OpenClaw family).
52
+ * Diagnostic only.
53
+ */
54
+ export declare function familyLabel(clientVersion: unknown): string;
55
+ /**
56
+ * What the owner reads when stopping the agent's work did not finish. One
57
+ * line, no '@' (it can never address anyone), no path or process detail.
58
+ *
59
+ * It never implies containment (review M2): restarting the AGENT does not stop
60
+ * work that left its process group (launchd reaps only the job's own group),
61
+ * so only restarting the computer stops running work — and even that does not
62
+ * remove anything set to start again on its own (cron, LaunchAgents).
63
+ */
64
+ export declare function offSequenceFailedNotice(agentName: unknown): string;
65
+ /** So a family never treats this notice as a reply it owes. */
66
+ export declare function isOffSequenceNotice(text: unknown): boolean;
67
+ /** `av.gates.off_sequence` for every run; plus the failure span when it failed. */
68
+ export declare function reportOffSequenceRun(sink: GatesSpanSink | null | undefined, family: string, r: OffSequenceRunLike, durationMs: number): void;
69
+ /** `av.gates.unknown_kill` for every bound stop; plus the failure span when it failed. */
70
+ export declare function reportBoundStop(sink: GatesSpanSink | null | undefined, family: string, r: BoundStopLike): void;
71
+ export declare const ROOT_EVICTED_SPAN = "av.gates.onturn_root_evicted";
72
+ /** The on-turn registry dropped its oldest root past the cap (review r3): never silent. */
73
+ export declare function reportRootEvicted(sink: GatesSpanSink | null | undefined, family: string): void;
74
+ //# sourceMappingURL=off-sequence-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"off-sequence-report.d.ts","sourceRoot":"","sources":["../src/off-sequence-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,wBAAwB,wBAAwB,CAAC;AAC9D,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,iBAAiB,CAAC;AACrD,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AACzD,eAAO,MAAM,eAAe,0BAA0B,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAA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F"}
@@ -0,0 +1,253 @@
1
+ /** The environment variable every on-turn spawn carries (§13.13, C2). */
2
+ export declare const ONTURN_ENV = "AV_ONTURN";
3
+ /** The persisted records, in the agent's data dir. */
4
+ export declare const ONTURN_RECORDS_FILE = "onturn-records.json";
5
+ /**
6
+ * Fallback only, where no boot-session id exists: two wall-clock boot-time
7
+ * readings within this many seconds are the same boot. Wide on purpose
8
+ * (review r2): a wall-clock step moves the derived boot time, and calling a
9
+ * step a "reboot" DROPS records (a stop may then miss work), while calling a
10
+ * real reboot "the same boot" keeps records that can match nothing — every
11
+ * member and root is checked by pid AND start time, and a wall-clock start
12
+ * time from an earlier boot cannot recur. So erring wide is the safe side.
13
+ */
14
+ export declare const BOOT_TOLERANCE_S = 3600;
15
+ export interface ProcInfo {
16
+ pid: number;
17
+ ppid: number;
18
+ pgid: number;
19
+ /** Session id. `null` where it cannot be read (macOS `ps` has no `sid`). */
20
+ sid: number | null;
21
+ uid: number;
22
+ /** Start time, as an opaque string compared for equality (pid-reuse guard). */
23
+ start: string;
24
+ zombie: boolean;
25
+ /** Values of `AV_ONTURN` in its ENVIRONMENT, or `null` when not read. */
26
+ onturn: readonly string[] | null;
27
+ }
28
+ export interface ProcessTable {
29
+ /** False on a platform with no reader: a stop there does nothing. */
30
+ readonly supported: boolean;
31
+ /** `env: true` also reads each same-user process's `AV_ONTURN` (costs more). */
32
+ list(opts?: {
33
+ env?: boolean;
34
+ }): Promise<ProcInfo[]>;
35
+ }
36
+ export type SignalFn = (pid: number, sig: "SIGTERM" | "SIGKILL") => void;
37
+ /** A recorded group (or Linux session): its leader's start time and the members seen in it. */
38
+ export interface RecordedGroup {
39
+ /** Start time of the process whose pid equals this id, when recorded; null if it had already exited. */
40
+ leaderStart: string | null;
41
+ /** Members seen in it: pid → start time. */
42
+ members: ReadonlyMap<number, string>;
43
+ }
44
+ export interface StopTargetsInput {
45
+ selfPid: number;
46
+ selfUid: number;
47
+ roots: ReadonlyArray<{
48
+ pid: number;
49
+ start: string;
50
+ }>;
51
+ recordedGroups?: ReadonlyMap<number, RecordedGroup>;
52
+ recordedSessions?: ReadonlyMap<number, RecordedGroup>;
53
+ nonces?: ReadonlySet<string>;
54
+ }
55
+ /**
56
+ * Is the recorded group/session `id` provably the SAME one in `table`?
57
+ * - its leader (pid == id) is alive with the recorded start time; or
58
+ * - its leader is gone and a RECORDED member (same pid, same start time) is
59
+ * still in it. An id cannot be reused while any member holds it.
60
+ * A leader alive with another start time, or a group whose recorded members
61
+ * have all gone, is NOT the same group (review M3).
62
+ */
63
+ export declare function recordedGroupHolds(table: ReadonlyMap<number, ProcInfo>, id: number, rec: RecordedGroup, kind: "pgid" | "sid"): boolean;
64
+ /**
65
+ * Which processes a stop takes in, from ONE snapshot. Pure: no I/O. See the
66
+ * header for the three ways in and what is never touched.
67
+ */
68
+ export declare function computeStopTargets(table: readonly ProcInfo[], input: StopTargetsInput): ProcInfo[];
69
+ /** Parse `ps -axww -o pid=,ppid=,pgid=,uid=,stat=,lstart=` (macOS). Exported for tests. */
70
+ export declare function parseDarwinPs(out: string): ProcInfo[];
71
+ /**
72
+ * The `AV_ONTURN` values in each process's ENVIRONMENT, from `ps -axwwE -o
73
+ * pid=,command=` (argv + environment) and `ps -axww -o pid=,command=` (argv
74
+ * only): the environment is what `-E` adds after the argv. A line whose `-E`
75
+ * form does not start with its argv form (the process exec'd between the two
76
+ * reads) yields nothing — never a match on argv. Exported for tests.
77
+ */
78
+ export declare function parseDarwinEnvNonces(withEnv: string, argvOnly: string): Map<number, string[]>;
79
+ /** Parse one `/proc/<pid>/stat` line (Linux). Exported for tests. */
80
+ export declare function parseLinuxStat(line: string): {
81
+ state: string;
82
+ ppid: number;
83
+ pgid: number;
84
+ sid: number;
85
+ start: string;
86
+ } | null;
87
+ /** The real process table for this platform; unsupported (empty) elsewhere. */
88
+ export declare function defaultProcessTable(): ProcessTable;
89
+ /** The system boot time, in unix seconds (`kern.boottime` / `btime` through libuv's uptime). */
90
+ export declare function bootTimeS(): number;
91
+ /**
92
+ * A boot-session id that changes at every boot and never with the wall clock
93
+ * (review r2): macOS `kern.bootsessionuuid`, Linux `/proc/sys/kernel/random/boot_id`.
94
+ * `null` where neither is available (the wall-clock boot time is then the fallback).
95
+ */
96
+ export declare function bootSessionId(): string | null;
97
+ /**
98
+ * The agent process may itself carry `AV_ONTURN` (it was restarted from an
99
+ * on-turn's shell). Its own non-on-turn children must not inherit it, or a
100
+ * later stop would take them in (Linux; macOS for third-party binaries). Called
101
+ * once at SecureChannel construction. Returns whether anything was removed.
102
+ */
103
+ export declare function scrubInheritedOnTurnEnv(env?: NodeJS.ProcessEnv): boolean;
104
+ export interface StopOutcome {
105
+ /** Distinct processes signalled (pid + start time). */
106
+ killed: number;
107
+ /** Still present when the budget ran out (0 = clean). */
108
+ remaining: number;
109
+ /** False on a platform with no process reader (nothing was done). */
110
+ supported: boolean;
111
+ }
112
+ export declare class OnTurnStopIncomplete extends Error {
113
+ readonly outcome: StopOutcome;
114
+ constructor(outcome: StopOutcome);
115
+ }
116
+ /** What a stop may touch: roots and groups registered up to `seq`, and these nonces. Opaque to callers. */
117
+ export interface FreezeToken {
118
+ readonly seq: number;
119
+ readonly nonces: ReadonlySet<string>;
120
+ }
121
+ export interface OnTurnRegistryOptions {
122
+ table?: ProcessTable;
123
+ signal?: SignalFn;
124
+ /** How often groups/sessions under live roots are recorded. Default 1 s. */
125
+ recordIntervalMs?: number;
126
+ selfPid?: number;
127
+ selfUid?: number;
128
+ /** Where the records persist. Without it they live in memory only. */
129
+ dataDir?: string;
130
+ /** For tests: the boot time to compare persisted records against (fallback). */
131
+ bootTime?: () => number;
132
+ /** For tests: the boot-session id (null = none on this platform). */
133
+ bootId?: () => string | null;
134
+ /** For tests: the most bytes a records file may be written with. */
135
+ maxWriteBytes?: number;
136
+ }
137
+ export interface StopOptions {
138
+ signal?: AbortSignal;
139
+ /** Total budget. Default 10 s (§13.13). */
140
+ budgetMs?: number;
141
+ /** SIGTERM → SIGKILL grace. Default 3 s (§13.13). */
142
+ graceMs?: number;
143
+ /** Poll interval while waiting for the grace. Default 200 ms. */
144
+ pollMs?: number;
145
+ /** The set frozen at the off edge (default: frozen now). */
146
+ frozen?: FreezeToken;
147
+ }
148
+ /** How the persisted records were found at construction. */
149
+ export type RecordsLoad = "none" | "ok" | "absent" | "corrupt" | "reboot";
150
+ /**
151
+ * On-turn processes of ONE agent: the registered roots, the groups/sessions
152
+ * recorded under them, and the agent's `AV_ONTURN` nonces. Families register
153
+ * a root for every process an on-turn spawns and give it `env()`; the plugin
154
+ * core calls `stopAll()` at an explicit off and at the bound, and
155
+ * `stopOnTurnsNow()` runs it on a terminal exit.
156
+ */
157
+ export declare class OnTurnRegistry {
158
+ /**
159
+ * One registry per data dir, shared by every channel object in the process:
160
+ * an OpenClaw config reload builds a new SecureChannel on the same data dir,
161
+ * and the on-turns started under the old one must still be found.
162
+ */
163
+ static forDataDir(dataDir: string | undefined): OnTurnRegistry;
164
+ private _table;
165
+ private _signal;
166
+ private readonly _selfPid;
167
+ private readonly _selfUid;
168
+ private readonly _recordIntervalMs;
169
+ private readonly _path;
170
+ private readonly _bootTime;
171
+ private readonly _bootIdFn;
172
+ private _bootIdCache;
173
+ private readonly _maxWriteBytes;
174
+ private _maxRoots;
175
+ private _evictionReporter;
176
+ private _seq;
177
+ private readonly _roots;
178
+ private readonly _groups;
179
+ private readonly _sessions;
180
+ private _primary;
181
+ private readonly _nonces;
182
+ private _recorder;
183
+ private _load;
184
+ constructor(opts?: OnTurnRegistryOptions);
185
+ /** The environment every on-turn spawn must carry (this on period's nonce). */
186
+ env(): Record<string, string>;
187
+ primaryNonce(): string;
188
+ /** How the persisted records were found at construction (`absent`/`corrupt` = lost). */
189
+ recordsLoad(): RecordsLoad;
190
+ /**
191
+ * True when a records file was expected but missing or unreadable at
192
+ * construction (not after a reboot, which frees every process): a stop then
193
+ * cannot prove it found what the previous process started (review M2).
194
+ */
195
+ recordsLost(): boolean;
196
+ rootCount(): number;
197
+ /** A new on period: a new nonce, so a stop frozen at the last off never matches it. Persisted. */
198
+ beginPeriod(): void;
199
+ /** The set a stop started now may touch (see `FreezeToken`). */
200
+ freeze(): FreezeToken;
201
+ /**
202
+ * Register a process an on-turn spawned. Resolves once its start time is
203
+ * read (the identity a stop checks) and its group is recorded, with an
204
+ * unregister function that records one last time. A process already gone
205
+ * registers nothing. Never throws.
206
+ */
207
+ register(pid: number): Promise<() => void>;
208
+ /** Record the groups/sessions under every live root, refresh or drop the old ones. Never throws. */
209
+ record(): Promise<void>;
210
+ private _recordFrom;
211
+ private _refresh;
212
+ /**
213
+ * After a cleanly completed off sequence: forget what the frozen stop
214
+ * covered — the roots, groups and nonces up to its token — and nothing a
215
+ * newer on period recorded (review M4). Without a token: everything.
216
+ */
217
+ clearRecorded(frozen?: FreezeToken): void;
218
+ /** The current targets, from one snapshot (diagnostics and tests). */
219
+ targets(frozen?: FreezeToken): Promise<ProcInfo[]>;
220
+ private _input;
221
+ /**
222
+ * Stop every on-turn process inside `frozen` (see the header). Resolves
223
+ * with what was done; REJECTS with `OnTurnStopIncomplete` when processes are
224
+ * still there after the budget, so the caller records the run as failed.
225
+ */
226
+ stopAll(opts?: StopOptions): Promise<StopOutcome>;
227
+ /** This boot's session id (see `bootSessionId`), cached. */
228
+ bootSessionId(): string | null;
229
+ /** Called with the pid of a root dropped past the cap (the channel logs it and sends a span). */
230
+ setRootEvictionReporter(fn: ((pid: number) => void) | null): void;
231
+ /** The wall-clock boot time (unix s), for the fallback rule. */
232
+ bootTimeS(): number;
233
+ /**
234
+ * Cached only when the read SUCCEEDS (review r4): a failed read (the
235
+ * `sysctl` timeout on a loaded Mac) is retried on the next call, never
236
+ * remembered as "this platform has none".
237
+ */
238
+ private _bootId;
239
+ /**
240
+ * Write the records now (atomic, 0600). THROWS on failure (the caller stays
241
+ * restricted). Never writes a file the loader would reject for its size
242
+ * (review r2): if the records ever exceed the write bound, a small "broken"
243
+ * file is written instead — it reads back as unreadable, so a later stop of
244
+ * this period reports UNVERIFIED rather than clean on partial records — and
245
+ * the write throws.
246
+ */
247
+ persistNow(): void;
248
+ private _persistQuiet;
249
+ private _loadRecords;
250
+ private _ensureRecorder;
251
+ private _stopRecorder;
252
+ }
253
+ //# sourceMappingURL=onturn-stop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onturn-stop.d.ts","sourceRoot":"","sources":["../src/onturn-stop.ts"],"names":[],"mappings":"AAyEA,yEAAyE;AACzE,eAAO,MAAM,UAAU,cAAc,CAAC;AACtC,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAgBzD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AAEtC,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,gFAAgF;IAChF,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;CACrD;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;AAEzE,+FAA+F;AAC/F,MAAM,WAAW,aAAa;IAC5B,wGAAwG;IACxG,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,4CAA4C;I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