@agentvault/claude-bridge 0.8.24 → 0.8.26

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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Room context for messages this agent reads but does not answer (2026-10-26).
3
+ *
4
+ * Under the #1107 rule an agent owes a reply only when it is @-mentioned (or
5
+ * @all / the owner rules in `owesRoomReply`). The bridge used to push EVERY room
6
+ * message into the model session anyway, and let the session suppress the
7
+ * reply. That bought the agent a full model turn per message it was never going
8
+ * to answer — measured on loopita (Opus, 1M context) at ~$0.27–0.31 per
9
+ * unaddressed message, ~$4–5 a day, for output that was thrown away.
10
+ *
11
+ * Now an unaddressed message costs nothing. It is held here, per room, and
12
+ * handed to the model as one block of context in front of the next message in
13
+ * that room that IS addressed to this agent — one turn, not N+1. Hermes reached
14
+ * the same place by a different road (`_record_room_message` +
15
+ * `_room_history_block` in plugin-hermes secure_channel.py): "read, not
16
+ * answered", kept, replayed on the turn it takes.
17
+ *
18
+ * The buffer is cleared once delivered. Unlike Hermes, these bridges drive a
19
+ * PERSISTENT model session, so once the block has been delivered the session
20
+ * remembers it — replaying it again would show the model the same messages
21
+ * twice.
22
+ *
23
+ * Bounded on purpose: per room by message count AND characters (oldest dropped
24
+ * first), and by number of rooms (least recently used room dropped). A room the
25
+ * agent is never addressed in must not grow without limit.
26
+ *
27
+ * ⚠️ The block lands INSIDE the turn that answers someone else — often the
28
+ * owner, and on some bridges a turn with tools. Every held message was written
29
+ * by another room member, possibly another tenant's agent, so nothing in it may
30
+ * be able to pass for bridge framing (PR #1458 review). Three layers:
31
+ * 1. sender names lose line breaks and brackets (`sanitizeLabel`);
32
+ * 2. every held text line is prefixed with "> ", so no held line can start
33
+ * with "[" and pose as a `[room … | owner]:` turn line;
34
+ * 3. the block is wrapped in delimiters carrying a fresh random id per turn,
35
+ * which a held message cannot know in advance and so cannot close early.
36
+ *
37
+ * COPIED into grok-room-bridge and muse-room-bridge. Each copy is OWNED by its
38
+ * bridge (see the "Copied-from ledger" in each bridge's README); a fix here does NOT
39
+ * reach the others.
40
+ */
41
+ export interface RoomContextEntry {
42
+ senderName: string;
43
+ text: string;
44
+ /** ISO time the message was sent (from the emit), or received if absent. */
45
+ at: string;
46
+ }
47
+ export interface RoomContextLimits {
48
+ /** Messages kept per room. */
49
+ maxMessages: number;
50
+ /** Characters kept per room (sender + text), oldest dropped first. */
51
+ maxChars: number;
52
+ /** Rooms tracked at once; the least recently used room is dropped. */
53
+ maxRooms: number;
54
+ /** One message's text is cut to this many characters. */
55
+ maxEntryChars: number;
56
+ }
57
+ export declare const DEFAULT_ROOM_CONTEXT_LIMITS: RoomContextLimits;
58
+ /**
59
+ * Cut `s` to at most `n` UTF-16 units without splitting a surrogate pair — a
60
+ * lone high surrogate left at the cut is invalid text (and garbles the turn).
61
+ */
62
+ export declare function cutSafe(s: string, n: number): string;
63
+ /**
64
+ * A display name or room name made safe to sit inside a bracketed framing
65
+ * line: no control characters or line breaks (a name with a newline would start
66
+ * a line of its own), no square brackets (which would close the frame early).
67
+ * Used for held senders AND for the live turn prefix (`roomTurnPrefix`).
68
+ */
69
+ export declare function sanitizeLabel(name: string, max?: number): string;
70
+ /** A fresh per-turn delimiter id: 12 hex chars from 6 random bytes. */
71
+ export declare function newContextId(): string;
72
+ export declare class RoomContextBuffer {
73
+ private readonly limits;
74
+ /** Insertion order IS recency order: a touched room is re-inserted at the end. */
75
+ private rooms;
76
+ constructor(limits?: Partial<RoomContextLimits>);
77
+ add(roomId: string, entry: RoomContextEntry): void;
78
+ /** The held messages for a room, oldest first. Does not clear. */
79
+ peek(roomId: string): {
80
+ entries: readonly RoomContextEntry[];
81
+ dropped: number;
82
+ };
83
+ clear(roomId: string): void;
84
+ size(roomId: string): number;
85
+ chars(roomId: string): number;
86
+ roomCount(): number;
87
+ }
88
+ /**
89
+ * The block placed in front of an addressed message. Empty string when there
90
+ * is nothing held — an empty "earlier in this room" header would claim the room
91
+ * was silent when it only means this process saw nothing (e.g. a restart).
92
+ *
93
+ * `id` defaults to a fresh random one; pass it only to make a test deterministic.
94
+ */
95
+ export declare function formatRoomContext(entries: readonly RoomContextEntry[], roomLabel: string, dropped?: number, id?: string): string;
96
+ //# sourceMappingURL=room-context.d.ts.map
package/dist/router.d.ts CHANGED
@@ -7,7 +7,9 @@ export interface PushLike {
7
7
  replyExpected?: boolean;
8
8
  toolEligibleSender?: boolean;
9
9
  armed?: () => boolean;
10
- }): void;
10
+ /** Held "earlier in this room" block — see room-context.ts. */
11
+ roomContext?: string;
12
+ }): unknown;
11
13
  }
12
14
  export interface RouterDeps {
13
15
  /**
@@ -1,10 +1,38 @@
1
1
  import { type ServiceBackend } from "./backend.js";
2
+ /**
3
+ * #913 item 2 / 2026-10-25 — what it takes to remove this agent's service.
4
+ *
5
+ * `attachLifecycle` routes every terminal signal here, and most of them mean
6
+ * the device is ALIVE:
7
+ *
8
+ * session_replaced another session took over — the device still exists
9
+ * device_jwt_expired the JWT aged out — the device still exists
10
+ * reconnect_loop gave up reconnecting — the device still exists
11
+ *
12
+ * This used to key on the reason string `device_revoked`. That was not proof:
13
+ * on 2026-10-25 a PAUSED (suspended) device's reissue 403 was mapped to
14
+ * "device_revoked" and this function removed loopita's launchd service — the
15
+ * owner switched the agent back on and nothing was installed to resume.
16
+ *
17
+ * So it now keys on the channel's CONFIRMED verdict only. SecureChannel sets
18
+ * `deviceGone: true` on `auth_failed` exclusively after the public status
19
+ * endpoint answered REVOKED or the device row is gone (404). Any reason string
20
+ * without that verdict — including `device_revoked` — leaves the service alone.
21
+ * An older channel that never sets the flag therefore never uninstalls: the
22
+ * safe direction.
23
+ */
24
+ export interface TerminalVerdict {
25
+ reason: string;
26
+ /** Set by SecureChannel only when the status endpoint CONFIRMED revoked/deleted. */
27
+ deviceGone?: boolean;
28
+ }
2
29
  export interface SelfUninstallDeps {
3
30
  backend?: ServiceBackend;
4
31
  log?: (msg: string) => void;
5
32
  }
6
33
  /**
7
- * Remove this agent's supervised service after its device was revoked.
34
+ * Remove this agent's supervised service after its device was CONFIRMED
35
+ * revoked or deleted.
8
36
  *
9
37
  * Returns whether a service was actually removed. NEVER throws: this runs on
10
38
  * the shutdown path, and a cleanup that cannot happen must not stop the bridge
@@ -15,5 +43,5 @@ export interface SelfUninstallDeps {
15
43
  * and LEAVES the credentials on disk. A false positive therefore costs the
16
44
  * customer a re-install, not their identity.
17
45
  */
18
- export declare function selfUninstallOnTerminal(reason: string, env: NodeJS.ProcessEnv, deps?: SelfUninstallDeps): boolean;
46
+ export declare function selfUninstallOnTerminal(verdict: TerminalVerdict, env: NodeJS.ProcessEnv, deps?: SelfUninstallDeps): boolean;
19
47
  //# sourceMappingURL=self-uninstall.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"self-uninstall.d.ts","sourceRoot":"","sources":["../../src/service/self-uninstall.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAuBlE,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAoCT"}
1
+ {"version":3,"file":"self-uninstall.d.ts","sourceRoot":"","sources":["../../src/service/self-uninstall.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAGlE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAoCT"}
package/dist/session.d.ts CHANGED
@@ -174,12 +174,16 @@ export declare class PersistentClaudeSession {
174
174
  * turn is granted full worker tool access (same as an owner DM turn). Reading
175
175
  * it live (not capturing a boolean) is what lets a mid-turn disarm deny the
176
176
  * next tool call. Bound by wireBridge to the ArmingState for this turn's room.
177
+ * @param opts.roomContext — room messages this agent read but was not
178
+ * addressed by (room-context.ts), placed in front of `text` in the SAME user
179
+ * message: one model turn, never one per held message.
177
180
  */
178
181
  push(text: string, reply?: ReplySink, opts?: {
179
182
  autoReplyOnText?: boolean;
180
183
  replyExpected?: boolean;
181
184
  toolEligibleSender?: boolean;
182
185
  armed?: () => boolean;
186
+ roomContext?: string;
183
187
  }): void;
184
188
  /** Route a say-tool message to the reply bound to the in-flight message, falling
185
189
  * back to opts.onSay. This is what closes the DM→room leak: the destination is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvault/claude-bridge",
3
- "version": "0.8.24",
3
+ "version": "0.8.26",
4
4
  "type": "module",
5
5
  "description": "AgentVault Claude Bridge — daemon for bridging a Claude agent into secure E2E-encrypted AgentVault 1:1 direct messages and rooms.",
6
6
  "main": "dist/index.js",