@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,190 @@
1
+ /** The subset of PersistedState these rules read. */
2
+ export interface PinState {
3
+ dmGroupPins?: Record<string, unknown>;
4
+ mlsGroups?: Record<string, {
5
+ mlsGroupId?: unknown;
6
+ } | undefined>;
7
+ mlsConversations?: Record<string, {
8
+ mlsGroupId?: unknown;
9
+ } | undefined>;
10
+ rooms?: Record<string, {
11
+ mlsGroupId?: unknown;
12
+ } | undefined>;
13
+ a2aChannels?: Record<string, {
14
+ mlsGroupId?: unknown;
15
+ } | undefined>;
16
+ }
17
+ /** A 1:1 routing key: `cg:<conversationGroupId>` or `conv:<conversationId>`. */
18
+ export type DmRouteKey = string;
19
+ /** The Welcome fields that decide where a joined group is registered and saved. */
20
+ export declare const WELCOME_ROUTING_FIELDS: readonly ["group_id", "conversation_group_id", "conversation_id", "room_id", "a2a_channel_id"];
21
+ /**
22
+ * The first routing field of a Welcome frame that is malformed, or `null`.
23
+ * `group_id` is required; the others may be absent (`null`/`undefined`). A
24
+ * PRESENT field must be a canonical lowercase UUID string: the backend builds
25
+ * every one of them with `str(uuid)` (mls_delivery_service), so an array, a
26
+ * number, an object, an empty string or an uppercase/odd-case id is never
27
+ * honest. Without this, a non-string that is truthy took the handler's 1:1
28
+ * branch (template strings and property access coerce `[id]` back to `id`)
29
+ * while every Tier 1 check, which reads strings, saw nothing.
30
+ */
31
+ export declare function malformedWelcomeField(data: Record<string, unknown>): string | null;
32
+ /**
33
+ * The 1:1 routing key a Welcome frame is registered under, or `null` when it is
34
+ * not a 1:1 Welcome. `_handleMlsWelcome` BRANCHES ON THIS RESULT (the shared
35
+ * branch when it starts `cg:`, the legacy branch when it starts `conv:`), so the
36
+ * key and the branch cannot diverge. Call it only on a frame
37
+ * `malformedWelcomeField` accepted; the truthiness test and `String()` are
38
+ * deliberately the handler's old predicate, so even an unvalidated non-string
39
+ * still yields the key it would have been registered under.
40
+ */
41
+ export declare function dmRouteKey(data: {
42
+ conversation_group_id?: unknown;
43
+ conversation_id?: unknown;
44
+ room_id?: unknown;
45
+ }): DmRouteKey | null;
46
+ /**
47
+ * The 1:1 key (pin or mapping) that holds `groupId`, or `null`. The reverse of
48
+ * T1-b: a room or A2A Welcome naming a 1:1's group would `saveMlsState` over
49
+ * that 1:1's state file. Server group ids are unique rows, so a room never
50
+ * honestly shares one with a 1:1.
51
+ */
52
+ export declare function dmKeyHolding(state: PinState, groupId: string): DmRouteKey | null;
53
+ /** Does ANY routing key of ours (room, A2A, 1:1 pin or mapping) hold `groupId`? */
54
+ export declare function anyKeyHolds(state: PinState, groupId: string): boolean;
55
+ /** The MLS group id the persisted 1:1 mapping holds for `key`, if any. */
56
+ export declare function mappedGroupId(state: PinState, key: DmRouteKey): string | undefined;
57
+ /**
58
+ * Eager backfill (§3.2 "Populate eagerly"): pin every 1:1 key the agent
59
+ * already maps, so the first delivery pull after an upgrade is already guarded.
60
+ * Only fills MISSING pins — an existing pin (valid, malformed or tombstone) is
61
+ * never overwritten from a mapping. Returns how many pins were added.
62
+ */
63
+ export declare function backfillDmGroupPins(state: PinState): number;
64
+ export type PinRefusal = "remap" | "malformed_pin" | "held_by_other";
65
+ export type PinDecision = {
66
+ action: "accept";
67
+ /** Write `pins[key] = groupId` before registering (first sight, or a malformed pin repaired). */
68
+ writePin: boolean;
69
+ } | {
70
+ action: "refuse";
71
+ reason: PinRefusal;
72
+ /** The group the key is pinned to (where the notice goes), when there is a valid one. */
73
+ pinnedGroupId?: string;
74
+ /** For `held_by_other`: which routing key holds the group (for the log only). */
75
+ heldBy?: string;
76
+ };
77
+ /**
78
+ * The routing key OTHER than `key` that holds `groupId` — a room, an A2A
79
+ * channel, or a different 1:1 key's pin or mapping — or `null`. T1-b.
80
+ */
81
+ export declare function otherHolder(state: PinState, key: DmRouteKey, groupId: string, groupOfConversation: (conversationId: string) => string | undefined): string | null;
82
+ /**
83
+ * The pre-join decision (§3.2 table). Runs BEFORE any KeyPackage is tried, so
84
+ * a refusal consumes nothing and touches no state.
85
+ *
86
+ * - group held by another routing key → refuse, whatever the pin says (T1-b)
87
+ * - pin == groupId → accept (a same-group repair is never blocked)
88
+ * - no pin → accept, write the pin (first sight — R1)
89
+ * - pin ≠ groupId → refuse (remap)
90
+ * - pin malformed → accept ONLY when the 1:1 mapping itself
91
+ * names groupId; a state file is NOT
92
+ * evidence (T1-a)
93
+ *
94
+ * A key with a mapping but no pin (a mapping written after load by a path that
95
+ * did not pin) is treated as pinned to its mapping — it fails closed, never open.
96
+ */
97
+ export declare function decideDmWelcome(state: PinState, key: DmRouteKey, groupId: string, groupOfConversation: (conversationId: string) => string | undefined): PinDecision;
98
+ /**
99
+ * T1-c: the joined group's AUTHENTICATED id (GroupContext.groupId, which every
100
+ * AgentVault client encodes as the UTF-8 of the server's MLS group id) must be
101
+ * the id the frame claims. The claim decides which state file is written.
102
+ */
103
+ export declare function joinedGroupIdMatches(groupIdBytes: unknown, claimed: unknown): boolean;
104
+ /**
105
+ * Fulfilment guard (§3.2): does this KeyPackage's leaf credential name
106
+ * `deviceId`? #1800 PR B (obligation 4): exactly crypto's rule,
107
+ * `keyPackageDeviceId(kp) === canonicalDeviceId(deviceId)`, both non-null —
108
+ * the SAME rule the sender-binding predicate applies to a leaf, so a
109
+ * KeyPackage this admits yields a leaf that can bind. The identity must
110
+ * already be the canonical lowercase UUID, byte for byte (an uppercase
111
+ * identity could never bind, so it is not admitted either); the claim may be
112
+ * any ASCII case. Never throws.
113
+ */
114
+ export declare function keyPackageNamesDevice(keyPackage: unknown, deviceId: unknown): boolean;
115
+ /** Log-safe 8-character id: `[0-9a-f-]` only, then truncated (§3.4 Logs). */
116
+ export declare function logId(id: unknown): string;
117
+ /** Label used when the claimed device's name cannot be resolved. */
118
+ export declare const UNKNOWN_DEVICE_LABEL = "an unrecognized device";
119
+ /**
120
+ * §3.4 remap variant — sent on a Tier 1 refused remap (PR C). A refused remap
121
+ * ran nothing, so the main text ("…ran without owner permissions") does not fit.
122
+ */
123
+ export declare const REMAP_REFUSED_NOTICE = "This chat's encryption was asked to switch to a different group; I refused. If you didn't reset this chat, tell your administrator.";
124
+ /**
125
+ * Chris's copy (11-22), the MAIN text: for PR B's mismatch / duplicate
126
+ * triggers. `label` is a device name, or UNKNOWN_DEVICE_LABEL.
127
+ */
128
+ export declare function unverifiedSenderNotice(label: string): string;
129
+ /**
130
+ * §3.4 DR variant — a Double Ratchet frame whose claimed sender is the owner
131
+ * device this conversation belongs to. DR never carries owner power (#1836).
132
+ */
133
+ export declare function drOwnerClaimNotice(label: string): string;
134
+ /**
135
+ * A display name made safe to embed in the notice: control and bidi-override
136
+ * characters removed, whitespace collapsed, capped. Empty → null (use the
137
+ * fallback label).
138
+ */
139
+ export declare function sanitizeDeviceLabel(name: unknown): string | null;
140
+ export declare const NOTICE_PER_CONVERSATION_MS: number;
141
+ export declare const NOTICE_GLOBAL_WINDOW_MS: number;
142
+ export declare const NOTICE_GLOBAL_CAP = 20;
143
+ /**
144
+ * §3.4 rate limit, in memory: the first event per conversation per hour, and
145
+ * at most NOTICE_GLOBAL_CAP notices per hour across all conversations.
146
+ */
147
+ export declare class SecurityNoticeLimiter {
148
+ private readonly _lastPerConversation;
149
+ private _globalSent;
150
+ allow(conversationKey: string, now?: number): boolean;
151
+ }
152
+ export declare const KP_IDENTITY_BACKOFF_INITIAL_MS: number;
153
+ export declare const KP_IDENTITY_BACKOFF_MAX_MS: number;
154
+ /**
155
+ * Per (group, device) backoff for a KeyPackage the fulfilment guard dropped
156
+ * (LOW 3, #1839 review). While blocked, the pulls do not fetch a KeyPackage
157
+ * for that device at all (each fetch spends one server-side). Windows double
158
+ * from 5 min to a 1 h cap; one WARN per window. A KeyPackage that passes ends it.
159
+ */
160
+ export declare class KpIdentityBackoff {
161
+ private readonly _entries;
162
+ blocked(key: string, now: number): boolean;
163
+ /** Record a drop. `log` is true once per window (the first drop that opens it). */
164
+ note(key: string, now: number): {
165
+ log: boolean;
166
+ delayMs: number;
167
+ };
168
+ clear(key: string): void;
169
+ }
170
+ export declare const SECURITY_SUMMARY_MIN_MS: number;
171
+ export declare const SECURITY_SUMMARY_MAX_MS: number;
172
+ /**
173
+ * In-memory security counters (`name{reason}` → count). `doctor` is a separate
174
+ * offline process and cannot read them; the channel logs `summaryLine` from
175
+ * its delivery heartbeat instead, which is what the rollout canary greps.
176
+ */
177
+ export declare class SecurityCounters {
178
+ private readonly _counts;
179
+ inc(name: string, reason?: string): void;
180
+ snapshot(): Record<string, number>;
181
+ private _lastSummaryAt;
182
+ private _lastSummary;
183
+ /**
184
+ * A one-line summary to log now, or `null`. Only while some counter is
185
+ * non-zero: when the counts changed (at most every SECURITY_SUMMARY_MIN_MS),
186
+ * and at least every SECURITY_SUMMARY_MAX_MS while they stay non-zero.
187
+ */
188
+ summaryLine(now: number): string | null;
189
+ }
190
+ //# sourceMappingURL=dm-group-pins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dm-group-pins.d.ts","sourceRoot":"","sources":["../src/dm-group-pins.ts"],"names":[],"mappings":"AAsBA,qDAAqD;AACrD,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACjE,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;CACpE;AAED,gFAAgF;AAChF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAchC,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,gGAMzB,CAAC;AAEX;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAUlF;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,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pF,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAK1C,mFAAmF;IACnF,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAWjE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAGzB;AAED,eAAO,MAAM,uBAAuB,QAAa,CAAC;AAClD,eAAO,MAAM,uBAAuB,QAAc,CAAC;AAEnD;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAKxC,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIlC,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,YAAY,CAAM;IAE1B;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAUxC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * #1836 — a Double Ratchet (DR) frame never carries owner power.
3
+ *
4
+ * The DR 1:1 path has no owner verdict: whoever holds a DR session with this
5
+ * agent can send on it. On an honest server that is any DR peer (a teammate in
6
+ * a multi-user tenant). On a compromised server it is anyone, because a forged
7
+ * `resync_request` or `device_linked` re-keys the session. MLS is the owner
8
+ * path; DR is a fallback that delivers text with every owner power withheld.
9
+ *
10
+ * Refused on DR, on every receive path (live, DR delivery queue, sync, poll
11
+ * fallback):
12
+ * - `workspace_file_upload` — wrote any `.md` into the OpenClaw workspace,
13
+ * `AGENTS.md` included, on a signature checked against a key carried in
14
+ * the SAME message (self-signed, so it proved nothing);
15
+ * - `workspace_file_list` / `workspace_file_read` — read the workspace back;
16
+ * - `session_init` — replayed up to 100 history entries to the session;
17
+ * - a decision answer (`decision_response`, or the older `message` +
18
+ * `decision` shape) — it resolved `waitForDecision`, i.e. an owner
19
+ * approval.
20
+ *
21
+ * DR text that is delivered carries no `ownerDm1to1` attestation and no
22
+ * file-send turn token (#1762), and its call chain gets no turnless file
23
+ * authority (`_drTurnStore` in channel.ts). The bridges therefore keep it in
24
+ * their locked (non-owner) lane, and OpenClaw runs no slash command from it
25
+ * (`CommandAuthorized` keys on `ownerDm1to1`).
26
+ *
27
+ * #1800 PR B: a DR DM is also never the owner's to OpenClaw — it runs in its
28
+ * own `agentvault:unverified:<conv8>` session, labelled "Unverified sender",
29
+ * with command interpretation suppressed — and history reads it back as
30
+ * `sender: "unverified"`. Its claimed sender becomes no person-graph node.
31
+ *
32
+ * Every refusal is logged once, as a WARN, with ids truncated to 8 characters
33
+ * and no message content.
34
+ */
35
+ /** Which DR receive path a frame arrived on. */
36
+ export type DrPath = "live" | "dr_delivery" | "sync" | "poll";
37
+ /**
38
+ * What a DR frame asked for that DR may not do, or `null` when it may be
39
+ * delivered (as non-owner text) or ignored as before.
40
+ */
41
+ export declare function drRefusal(messageType: string, hasDecision: boolean): string | null;
42
+ /** One WARN for one refused DR frame. Never includes content. */
43
+ export declare function warnDrRefused(what: string, path: DrPath, ids: {
44
+ convId?: string;
45
+ messageId?: string;
46
+ senderDeviceId?: string;
47
+ }): void;
48
+ /** One WARN for DR text delivered with owner powers withheld. Never includes content. */
49
+ export declare function warnDrNonOwner(path: DrPath, ids: {
50
+ convId?: string;
51
+ messageId?: string;
52
+ senderDeviceId?: string;
53
+ }): void;
54
+ //# sourceMappingURL=dr-refusal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dr-refusal.d.ts","sourceRoot":"","sources":["../src/dr-refusal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAUH,gDAAgD;AAChD,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9D;;;GAGG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIlF;AAUD,iEAAiE;AACjE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE,IAAI,CAKN;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE,IAAI,CAMN"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * #1762 PR-1b (design §1.5, §2, §4) — never claiming a file that was not sent.
3
+ *
4
+ * One table for every TypeScript client: the notices the person reads when a
5
+ * file did not go, the matcher that recognises them, the tool-result wording
6
+ * a model sees, the per-turn staging line and prompt rules, the history line
7
+ * that records a sent file, the neutralizer that stops a model forging that
8
+ * line, and the prose matcher (`claimsAttachment`) the turn-end check uses.
9
+ *
10
+ * Nothing here ever names an absolute path: staging folders are shown
11
+ * workspace-relative (R3-9).
12
+ */
13
+ /** The FileSendResult codes a send can fail with (design §1.1, §4.2). */
14
+ export type FileSendCode = "file_not_allowed" | "file_not_found" | "file_too_large" | "upload_failed" | "room_file_not_permitted" | "file_target_mismatch" | "file_send_disabled" | "workspace_required" | "turn_ended" | "turn_no_consumer" | "no_conversation_ready" | "relay_not_connected" | "blocked_by_policy" | "unsupported_destination" | "delivery_failed" | "room_not_found";
15
+ export type FileSendResult = {
16
+ ok: true;
17
+ filename: string;
18
+ size: number;
19
+ mime: string;
20
+ clientMessageId: string;
21
+ } | {
22
+ ok: false;
23
+ code: FileSendCode;
24
+ filename?: string;
25
+ error: string;
26
+ };
27
+ export type FileSendTargetLike = {
28
+ kind: "owner";
29
+ conversationId?: string;
30
+ } | {
31
+ kind: "room";
32
+ roomId: string;
33
+ };
34
+ export declare function fileSendReason(code: FileSendCode): string;
35
+ /**
36
+ * The one notice per turn per conversation when a file did not go (§4.2).
37
+ * 1:1 names every failed file (up to 3 + "and N more") and the reason; a room
38
+ * gets the bare line, since the reason can say something about the owner's
39
+ * staging that another account's members should not read.
40
+ */
41
+ export declare function fileSendNoticeFor(code: FileSendCode, ctx: {
42
+ agentName: string;
43
+ kind: "dm" | "room";
44
+ filenames: string[];
45
+ }): string;
46
+ /**
47
+ * A file the server refused after it left (M7; round 2 item 12, round 3
48
+ * item 8). 1:1 names the file; a room gets the bare room line, like every
49
+ * other room file notice: another account's members read the room.
50
+ */
51
+ export declare function fileLostNoticeFor(ctx: {
52
+ agentName: string;
53
+ filename: string;
54
+ kind?: "dm" | "room";
55
+ }): string;
56
+ /** The turn-end line when a reply claims a file and none went (§4.4). Neutral on purpose. */
57
+ export declare const NO_ATTACHMENT_NOTICE = "(This reply has no attachment.)";
58
+ /** So a bridge never treats SecureChannel's own file notice as a reply it owes. */
59
+ export declare function isFileSendNotice(text: unknown): boolean;
60
+ /**
61
+ * What a model's `send_file` call returns (§2). A failure names the right
62
+ * folder: `folder` is the policy's `stagingPathFor(target)` (via
63
+ * `SecureChannel.stagingPathFor`), relative to the one base a path resolves
64
+ * against — never an absolute host path (R3-9).
65
+ */
66
+ export declare function fileSendToolResult(result: FileSendResult, target: FileSendTargetLike, folder: string | null): string;
67
+ /**
68
+ * The per-turn line that tells the model where THIS conversation's files go
69
+ * (N1, R3-9). `folder` comes from the policy (`stagingPathFor`); `null` means
70
+ * there is none (file send off, or a room id that cannot have a folder).
71
+ */
72
+ export declare function stagingLineFor(target: FileSendTargetLike, opts: {
73
+ folder: string | null;
74
+ roomsAllowed?: boolean;
75
+ }): string;
76
+ /** §4.3 — the rule each family puts in the prompt the model actually receives. */
77
+ export declare function FILE_SEND_RULE(tool: string): string;
78
+ /** §4.3 — Codex, content-only (§2.3). */
79
+ export declare const FILE_SEND_RULE_CONTENT: string;
80
+ /** §4.3 — where a family ends up with no roots, or the Codex tool failed to start. */
81
+ export declare const FILE_SEND_UNAVAILABLE: string;
82
+ /** The line a history renderer shows for an entry's `files`, authored by AgentVault. */
83
+ export declare function renderHistoryFiles(files: ReadonlyArray<{
84
+ filename: string;
85
+ size: number;
86
+ }>): string;
87
+ /** NFKC, Cf removed, whitespace collapsed, lowercased — the §1.5 normalization. */
88
+ export declare function normalizeForMatch(text: string): string;
89
+ /**
90
+ * Rewrite any model line that NORMALIZES to `[AgentVault system:` so it can
91
+ * never take the system shape in chat, history or later context (N10). The
92
+ * match is on the normalized line; the rewrite is on the ORIGINAL line, with
93
+ * no offset mapping: every `[` / `[` that precedes "agentvault" (ignoring Cf
94
+ * characters and whitespace, any case) becomes `[AgentVault-system (quoted):`'s
95
+ * opening, and the original prefix up to its colon is replaced (R3-8).
96
+ */
97
+ export declare function neutralizeSystemPrefix(text: string): string;
98
+ /**
99
+ * The RENDER-TIME neutralizer: every history-to-context renderer (family PRs)
100
+ * must pass each line NOT written by this agent — the owner's, another
101
+ * member's, a folded file's text — through this before it reaches the model,
102
+ * so only `renderHistoryFiles` can produce the system shape there.
103
+ */
104
+ export declare function neutralizeForeignLine(text: string): string;
105
+ /**
106
+ * Does `text` contain a first-person claim by the agent that it is sending or
107
+ * has sent a file? Code (fenced or inline), quotes (`>` lines) and
108
+ * SecureChannel's own notices are ignored. "I sent it earlier" is ignored only
109
+ * when history shows an ok file send to this conversation (`priorFileSend`).
110
+ * A bare it/this/that never counts as the file (R3-7).
111
+ */
112
+ export declare function claimsAttachment(text: unknown, opts?: {
113
+ priorFileSend?: boolean;
114
+ }): boolean;
115
+ //# sourceMappingURL=file-send-failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-send-failure.d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E;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CA4B/F"}
@@ -0,0 +1,251 @@
1
+ export declare function outboxFolderName(name: string | undefined, dataDirReal: string): string;
2
+ /** The backend caps the ciphertext at 5 MiB; XChaCha20-Poly1305 adds a 16-byte tag. */
3
+ export declare const MAX_FILE_SEND_BYTES: number;
4
+ /** Paths longer than this are refused before any filesystem call. */
5
+ export declare const MAX_FILE_SEND_PATH_BYTES = 4096;
6
+ /** A room id is joined into a path only in this exact shape (R3-3). */
7
+ export declare const ROOM_ID_RE: RegExp;
8
+ export type FileSendTarget = {
9
+ kind: "owner";
10
+ conversationId?: string;
11
+ } | {
12
+ kind: "room";
13
+ roomId: string;
14
+ };
15
+ export type FilePolicyCode = "file_not_allowed" | "file_not_found" | "file_too_large" | "file_send_disabled" | "workspace_required";
16
+ /**
17
+ * #1762 PR-O (§2.1, H7) — what a HOST (OpenClaw) adds to a send. The host
18
+ * already decides which local media a session may use; we intersect with it
19
+ * and never widen it.
20
+ * - `limitRoots`: the host's media roots. The file must be inside an
21
+ * AgentVault root AND inside one of these (lexically, and again on the
22
+ * resolved real path). An empty list refuses everything.
23
+ * - `sandboxed`: the session runs in the host's sandbox. Room targets are
24
+ * refused outright (N4); a 1:1 target runs the LEXICAL policy only and
25
+ * reads the bytes through `readFile` — the host path is never opened.
26
+ * Sandboxed with no reader → refused.
27
+ */
28
+ export interface FileSendHostOptions {
29
+ limitRoots?: readonly string[];
30
+ sandboxed?: boolean;
31
+ readFile?: (path: string) => Promise<Uint8Array>;
32
+ /**
33
+ * #1762 PR-X (review #1788): the caller gives up on this send when this aborts — the upload is
34
+ * cancelled and, if the bytes are already up, NO frame is written (`upload_failed`). Checked
35
+ * right before the write, with no await between, so a send is either refused or committed.
36
+ */
37
+ signal?: AbortSignal;
38
+ }
39
+ /** What `readForSend` takes from a host (built by SecureChannel from FileSendHostOptions). */
40
+ export interface FileReadHostOptions {
41
+ limitRoots?: readonly string[];
42
+ /**
43
+ * #1762 PR-P1c-2 (§13.13 "Files"): a ROOM target may also read from the
44
+ * workspace root — set by SecureChannel only while Full permissions is on.
45
+ * The workspace root excludes all of `agentvault-outbox/`, so `dm/`, other
46
+ * rooms' folders and `attachments/` stay out of reach either way.
47
+ */
48
+ roomWorkspace?: boolean;
49
+ /** Present = sandboxed: lexical policy only, then this reader (null = no reader → refused). */
50
+ sandboxRead?: ((path: string) => Promise<Uint8Array>) | null;
51
+ }
52
+ export type FileReadResult = {
53
+ ok: true;
54
+ bytes: Uint8Array;
55
+ filename: string;
56
+ mime: string;
57
+ size: number;
58
+ } | {
59
+ ok: false;
60
+ code: FilePolicyCode;
61
+ };
62
+ /** Test seams only: count reads on the fd; act between open and re-verify (the swap race). */
63
+ export interface FileReadIo {
64
+ onRead?: () => void;
65
+ afterOpen?: (path: string) => void;
66
+ /** Test seam: called after a prune listed `dir` and before it removes anything (the swap race). */
67
+ beforePruneRemove?: (dir: string) => void;
68
+ /** Test seam: called before each FILE is unlinked during a prune (round 3 race test). */
69
+ beforePruneUnlink?: (path: string) => void;
70
+ /** Test seam: called after the shared folder is opened and checked, before fchmod (round 3, item 6). */
71
+ beforeFchmod?: (path: string) => void;
72
+ }
73
+ export interface FileSendPolicyOptions {
74
+ dataDir: string;
75
+ /** The family's workspace, when it has one (bridges, a resolved OpenClaw workspace). */
76
+ workspaceDir?: string;
77
+ /** Defaults to `os.homedir()`. */
78
+ homeDir?: string;
79
+ /** The agent's folder name under `agentvault-outbox/` (default: the data dir's name). */
80
+ slug?: string;
81
+ /** Logs one line per refused root or refused send (code + a 12-char path hash, never the path). */
82
+ log?: (line: string) => void;
83
+ io?: FileReadIo;
84
+ }
85
+ export declare function mimeForFilename(filename: string): string;
86
+ /** Text-like mimes get a best-effort content scan (§1.2 step 5). Not a control. */
87
+ export declare function isTextMime(mime: string): boolean;
88
+ /** Our folder under a workspace (or beside the data dir). Never a user's own name. */
89
+ export declare const OUTBOX_FOLDER = "agentvault-outbox";
90
+ /**
91
+ * #1762 PR-X (§2.3) — would the policy refuse a file with this BASENAME
92
+ * wherever it sat? A dotfile, a denylisted basename (§3.3 step 3), or a
93
+ * denylisted component name. The content-only Codex tool checks the name it
94
+ * was given with this BEFORE it writes anything, so a refused name leaves
95
+ * nothing on disk; `readForSend` still applies the full policy at send time.
96
+ */
97
+ export declare function isDeniedSendFilename(name: string): boolean;
98
+ export declare class FileSendPolicy {
99
+ readonly outboxDir: string;
100
+ /** Whether the configured workspace became a 1:1 root (it is refused if it is $HOME, contains the data dir, …). */
101
+ readonly workspaceAccepted: boolean;
102
+ private readonly home;
103
+ private readonly homeLexical;
104
+ private readonly dataDir;
105
+ private readonly dataLexical;
106
+ private readonly workspace;
107
+ private readonly wsLexical;
108
+ /** The outbox as the configured paths spell it (the real path is `outboxDir`). */
109
+ private readonly outboxLexical;
110
+ /** `agentvault-outbox/` itself (shared by every agent of a workspace; never renamed). */
111
+ private readonly sharedDir;
112
+ private readonly sharedLexical;
113
+ /** THE resolution base: the workspace when accepted, else the outbox (lexical spelling). */
114
+ private readonly baseLexical;
115
+ private readonly log;
116
+ private readonly io;
117
+ private dmRoot;
118
+ private attachmentsRoot;
119
+ private workspaceRoot;
120
+ private readonly roomRoots;
121
+ /** Why file send is unavailable (an unsafe shared outbox), or null. Never "no root". */
122
+ private unavailable;
123
+ /** The code a send gets while unavailable: the outside-$HOME case is `workspace_required` (#1782 item 4). */
124
+ private unavailableCode;
125
+ /** This agent's folder name under `agentvault-outbox/`. */
126
+ readonly folder: string;
127
+ /** Absolute dirs never sent from (case-folded), each with the sub-paths that are allowed. */
128
+ private readonly denyDirs;
129
+ constructor(opts: FileSendPolicyOptions);
130
+ /**
131
+ * Create the outbox and `dm/` (fresh), and record every 1:1 root's identity.
132
+ * Call once at channel start. A root that cannot be made safe is simply not
133
+ * a root: the family runs without it and one line is logged.
134
+ */
135
+ init(): void;
136
+ /**
137
+ * Create `<outbox>/rooms/<roomId>/` freshly (on join, and for every room
138
+ * already persisted at start). Returns false — and creates nothing — for a
139
+ * room id not in the lowercase UUID shape (R3-3).
140
+ */
141
+ ensureRoomFolder(roomId: string): boolean;
142
+ /**
143
+ * The room went away (`room_left`, or `rooms_reconciled { pruned }`): move its
144
+ * folder to `<outbox>/left/<roomId>-<ts>/`, outside every root, kept for the
145
+ * owner. Only if the entry is still the directory we created (lstat +
146
+ * dev/ino); anything else is UNLINKED and never recursed into (R3-1).
147
+ */
148
+ retireRoomFolder(roomId: string): void;
149
+ /**
150
+ * The staging folder for a target as shown to the model. Never an absolute
151
+ * host path (R3-9):
152
+ * - with an accepted workspace: relative to it (`agentvault-outbox/<f>/dm/`),
153
+ * exactly what a relative `send_file` path resolves against;
154
+ * - with none, under $HOME: the `~/`-relative path (no username in it);
155
+ * - with none, OUTSIDE $HOME (round 3, item 7): `null` — there is no safe
156
+ * path to show (the host layout and any username would leak), so the
157
+ * family shows no staging line and file sends need a workspace there.
158
+ * `readForSend` still accepts the real path if the model finds it.
159
+ * `null` too for a room id that is not a lowercase UUID.
160
+ */
161
+ stagingPathFor(target: FileSendTarget): string | null;
162
+ /** Strictly inside $HOME (lexically): the only place a `~/` path can be shown. */
163
+ private underHome;
164
+ readForSend(target: FileSendTarget, rawPath: unknown, host?: FileReadHostOptions): Promise<FileReadResult>;
165
+ private rootsFor;
166
+ private lexicallyIn;
167
+ private reallyIn;
168
+ /** Dot segments below the root, denylisted basenames, denylisted absolute dirs. */
169
+ private denied;
170
+ private rootIntact;
171
+ private buildDenyDirs;
172
+ /**
173
+ * A configured workspace is accepted unless it is `/` or $HOME, CONTAINS the
174
+ * data dir or any protected folder, is inside the data dir, or is inside a
175
+ * CREDENTIAL folder (~/.ssh, ~/.aws, ~/.config, ~/.claude, ~/.codex,
176
+ * ~/.grok, the host-trust dir). Inside an agent home (~/.agentvault,
177
+ * ~/.openclaw, ~/.hermes) is fine: that is where the bridges' default
178
+ * `~/.agentvault/<bridge>/workspaces/<slug>` and OpenClaw's workspace live.
179
+ */
180
+ private acceptableRoot;
181
+ private existingRoot;
182
+ /**
183
+ * Rename `path` to `<staleDir>/.stale-<name>-<ts>` (never recursing). If the
184
+ * rename fails, a SYMLINK is unlinked (its target untouched); anything else
185
+ * — a regular file, a directory — is never deleted: the move fails.
186
+ */
187
+ private moveAside;
188
+ /**
189
+ * Keep only the newest KEEP_ASIDE entries of `dir` that match: the rest are
190
+ * removed. Each is lstat'ed first: a symlink or file is unlinked (never
191
+ * followed); a directory is removed recursively without following links.
192
+ */
193
+ private pruneAside;
194
+ /** Is `dir` still a real directory with the identity recorded in `held`? */
195
+ private sameDir;
196
+ /**
197
+ * Remove `path` (an entry of a directory the caller just checked) without
198
+ * EVER following a symlink (round 3, item 5). Node has no unlinkat, so a
199
+ * path-by-path walk could be redirected mid-walk by swapping a subfolder
200
+ * for a symlink. Every directory is first RENAMED into a fresh private
201
+ * `mkdtemp` folder (`.rm-<folder>-XXXXXX`, 0700, an unguessable name)
202
+ * inside its checked parent and walked only there; a symlink in place at
203
+ * the rename is moved and unlinked as a link (its target untouched).
204
+ *
205
+ * The residual (#1782 item 6): a same-user process that learns the private
206
+ * name can still swap a directory inside it in the gap between a check and
207
+ * one unlink — at most ONE file unlink can land elsewhere; the identity
208
+ * check before the next entry stops the walk.
209
+ */
210
+ private removeTree;
211
+ /**
212
+ * #1782 (item 7): remove this agent's own leftover `.rm-<folder>-XXXXXX`
213
+ * folders in `dir` (a walk that stopped early leaves one). Only names in
214
+ * exactly that shape, only in a directory that passes the strict check.
215
+ */
216
+ private removeOwnTrash;
217
+ /** Empty and remove a directory that `removeTree` moved into its private folder. */
218
+ private removeMoved;
219
+ /**
220
+ * `agentvault-outbox/`: created if missing; never renamed (it holds other
221
+ * agents' outboxes). A real directory of ours with a wider mode is chmod'ed
222
+ * to 0700. Returns true, or the reason file send is unavailable (a symlink,
223
+ * another owner, not a directory) — never silently "no root".
224
+ */
225
+ private ensureShared;
226
+ /** fchmod 0700 on `path` opened O_NOFOLLOW|O_DIRECTORY, only if it is still the directory in `seen`. */
227
+ private privateByFd;
228
+ /** The strict check every staging directory must pass: ours, 0700, a real dir where we expect it. */
229
+ private safeDir;
230
+ /**
231
+ * A container (the outbox, `rooms/`, `left/`): never a send root itself, so
232
+ * an existing one is KEPT if it passes the strict check; anything else is
233
+ * moved aside and recreated.
234
+ */
235
+ private ensureContainer;
236
+ /**
237
+ * A send root (`dm/`, `rooms/<R>/`) is ALWAYS freshly created (R3-2): mkdir
238
+ * 0700; on EEXIST the existing entry is renamed aside (kept, never deleted)
239
+ * and mkdir runs again; then the strict check; only then is (dev, ino) recorded.
240
+ */
241
+ private freshRoot;
242
+ /** Is the room's folder the one this process created, still intact? */
243
+ roomFolderIntact(roomId: string): boolean;
244
+ /** An existing EMPTY real directory is simply removed (nothing to keep). */
245
+ private removeIfEmptyDir;
246
+ /** For tests and diagnostics: the room folders currently accepted. */
247
+ roomFolders(): string[];
248
+ /** Every `.stale-*` entry in the outbox (diagnostics). */
249
+ staleEntries(): string[];
250
+ }
251
+ //# sourceMappingURL=file-send-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-send-policy.d.ts","sourceRoot":"","sources":["../src/file-send-policy.ts"],"names":[],"mappings":"AAmFA,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAGtF;AAKD,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,QAAiB,CAAC;AAClD,qEAAqE;AACrE,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAC7C,uEAAuE;AACvE,eAAO,MAAM,UAAU,QAAmE,CAAC;AAE3F,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3G,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG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