@securecoms/agent-bridge 0.29.0 → 0.30.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 CHANGED
@@ -56,17 +56,23 @@ The bundled connectors give tools only to the agent owner's turns. Each harness
56
56
 
57
57
  On an older harness the connector reports its tool veto as inactive and refuses every turn that has no tool grant, so non-owner rooms go quiet instead of running tools unchecked. `/healthz` shows `harness_tool_veto_active` (true, false, or null when no connector is attached), the authenticated `GET /v1/status` shows the harness name and version, and the daemon logs `harness.tool_veto_inactive` once when an attached harness cannot veto. After upgrading the package, re-run `agent-bridge wire --harness openclaw` (or re-copy the Hermes connector files) so the harness loads the new connector, then restart the harness gateway.
58
58
 
59
- ### Room tool rule (0.26.6 and later)
59
+ ### Room tool rule (0.30.0 and later)
60
60
 
61
- In a room whose every member, including pending members and anyone who left but still holds an MLS leaf, is in the agent owner's org, a same-org human sender's turn may use `current_time` only. Cross-org and unknown rooms get no tools. The owner DM keeps `current_time` and `web_search`. Replies to room turns are re-classified when they are sent.
61
+ <!-- [COPY, approved by Eric 2026-10-12] -->
62
+
63
+ In a room whose every member, including pending members and anyone who left but still holds an MLS leaf, is in the agent owner's org, the agent gets the time, plus web search if you allow it (50 a day per room). Other rooms get no tools. The owner DM uses the tools the owner signed. Without signed settings, it keeps `current_time` and `web_search`. <!-- [COPY, approved by Eric 2026-10-12] --> Replies to room turns are re-classified when they are sent.
62
64
 
63
65
  Operator steps:
64
66
 
65
- - **Deploy order:** backend (already live), then this bridge, then `@securecoms/agent-runtime` 0.9.9. A new runtime on an old bridge offers no tools on the owner's relayed voice turns. Room grants need both the new bridge and the new runtime.
67
+ - **Deploy order:** backend (already live), then this bridge, then `@securecoms/agent-runtime` 0.13.0. A new runtime on an old bridge offers no tools on the owner's relayed voice turns. Room grants need both the new bridge and the new runtime.
66
68
  - **Re-wire connectors:** re-run `agent-bridge wire --harness ...` on every Hermes and OpenClaw host after upgrading. Connectors are copied at wire time and an upgrade does not refresh them. A bridge downgrade after re-wiring makes the new connectors refuse tools on the owner's voice turns.
67
69
  - **Kill switch:** `SECURECOMS_ROOM_DEFAULT_GRANTS` (bridge service environment, read at startup). Unset or `on` keeps the room default; any other value sends no tools on every room turn. It does not affect the owner DM. `SECURECOMS_OWNER_DM_DEFAULT_GRANTS` is unchanged.
70
+ - **Owner-signed grant switches:** `SECURECOMS_OWNER_DM_MANIFEST_GRANTS` and `SECURECOMS_ROOM_MANIFEST_GRANTS` (bridge service environment, read at startup). Unset or `on` keeps owner-signed tool settings in that place (the private chat, or rooms). Any other value makes that place use the fallback: today's default tools, limited to what the owner signed, plus `current_time`. These switches never add a tool. `SECURECOMS_OWNER_DM_DEFAULT_GRANTS` and `SECURECOMS_ROOM_DEFAULT_GRANTS` still override them and send no tools when off. <!-- [COPY, approved by Eric 2026-10-12] -->
71
+ - **Room search cap:** `SECURECOMS_ROOM_SEARCH_DAILY_CAP` lowers the daily `web_search` limit for each room. The default and the maximum are 50. Use a whole number from 0 to 50. `0` turns room search off, and the room gets no notice. Any other value is treated as 50, and the Connector logs one warning. **Set it in both the bridge service environment and the runtime service environment.** On macOS these are two launchd plists, and each has its own `EnvironmentVariables`. Each service reads it once at start, so restart both after a change. The count resets each UTC day. <!-- [COPY, approved by Eric 2026-10-12] -->
72
+ - **Agent search cap:** `SECURECOMS_AGENT_ROOM_SEARCH_DAILY_CAP` lowers the daily total of room `web_search` calls for one agent across all rooms. The default and the maximum are 200. Use a whole number from 0 to 200. `0` turns room search off. Any other value is treated as 200, and the Connector logs one warning. Set it in both service environments and restart both, as for the room cap. <!-- [COPY, approved by Eric 2026-10-12] -->
68
73
  - **Owner-DM epoch freshness:** owner-DM tools now also require a roster read at the agent's current MLS group and epoch. A wedged or group-less DM shows no tools. Diagnose with the `authz.decision` log fields `epoch_fresh`, `room_class`, `per_tool_consumer` and `room_kill_switch`.
69
- - **Restart residual:** after a bridge restart, a reply to a room turn granted before the restart is not re-classified. Only `current_time` output can be affected.
74
+ - **Restart residual:** after a bridge restart, a reply to a room turn granted before the restart is not re-classified. `current_time` and `web_search` output can be affected. <!-- [COPY, approved by Eric 2026-10-12] -->
75
+ - **`sqlite` database path:** a `sqlite` database path must be its real path. On macOS `/tmp` is `/private/tmp`, so a path under `/tmp` is refused. <!-- [COPY, approved by Eric 2026-10-12] -->
70
76
  - **Post-deploy probe:** count `connect.roster_mirror_unresolved` warnings and rooms reading `unknown`. A high rate means roster mirror drift is hiding room tools.
71
77
 
72
78
  ---
@@ -596,6 +602,68 @@ The loopback hop carries plaintext by design — the agent is the endpoint and t
596
602
 
597
603
  ---
598
604
 
605
+ ## Owner signing key (tool settings)
606
+
607
+ <!-- [COPY, approved by Eric 2026-10-12] owner-signed tool grants spec 2026-10-12 section 10 K-19. -->
608
+
609
+ The Connector can hold the owner's signing key, so it can check that a message
610
+ or a tool setting really came from the agent's owner. The SecureComs server
611
+ never supplies this key. The Connector reads it only from two files on this
612
+ machine, once, when it starts.
613
+
614
+ **Format.** The key file is `owner-signing-key.json` and holds exactly three
615
+ fields, nothing else:
616
+
617
+ ```json
618
+ {
619
+ "owner_identity_id": "0a0a0a0a-1111-4222-8333-444444444444",
620
+ "key_algo": "ed25519",
621
+ "public_key": "<base64 of the 32-byte Ed25519 public key>"
622
+ }
623
+ ```
624
+
625
+ `owner_identity_id` is the owner's identity id in lowercase. The credential
626
+ file can carry the same object under `owner_signing_key`. If both are present
627
+ they must match exactly; if they differ the Connector uses neither.
628
+
629
+ **Location.** `owner-signing-key.json` sits in the same folder as the
630
+ credential file.
631
+
632
+ **No symbolic links.** A key file that is a symbolic link is refused, and the
633
+ Connector then uses no key at all, whatever the credential holds.
634
+
635
+ **Permissions.** Keep the file at mode `0600`, like the credential. A looser
636
+ mode is logged as a warning and the key is still used.
637
+
638
+ **Setting or changing the key.** Use the `pin` command. All three flags are
639
+ required:
640
+
641
+ ```bash
642
+ agent-bridge pin --credential <credential.json> --file <owner-signing-key.json> --agent <agent_identity_id>
643
+ ```
644
+
645
+ The key file must be in the same folder as the credential file, and
646
+ `--agent` must be the credential's own agent identity, so the command cannot
647
+ change another agent's credential. It prints the agent identity before it
648
+ changes anything. It rewrites the key file and the credential's
649
+ `owner_signing_key` together, through temporary files and renames, so an
650
+ interrupted run leaves either the old key, the new key, or no key, never a
651
+ wrong one. Restart the Connector afterwards to use the key.
652
+
653
+ **Counters.** Each owner-signed tool setting carries a counter that only goes
654
+ up. Pinning the same key again keeps the stored counter. Pinning a new key
655
+ starts a new counter, and the old key's stored settings are dropped.
656
+
657
+ ### Upgrade note
658
+
659
+ <!-- [COPY, approved by Eric 2026-10-12] owner-signed tool grants spec 2026-10-12 section 10 K-27. -->
660
+
661
+ Owner messages stored before this release cannot be verified, because they
662
+ were stored without their signature. On a Connector that holds the owner's
663
+ signing key, a redelivered old message runs without tools or memory.
664
+
665
+ ---
666
+
599
667
  ## Attachments and any-language agents
600
668
 
601
669
  The daemon is the universal substrate: an agent in any language (Python, Go,
@@ -867,6 +935,82 @@ copied after the owner's next typed message.
867
935
 
868
936
  ---
869
937
 
938
+ ## Release notes: 0.30.1
939
+
940
+ <!-- [COPY, approved by Eric 2026-10-14] -->
941
+
942
+ 0.30.1 makes sure only one copy of an agent runs, and makes install say
943
+ clearly when the agent did not start.
944
+
945
+ - **Reinstall once after you upgrade.** Run the install command again for
946
+ each agent. It writes a new service file. The old file restarts the
947
+ Connector every time it stops, so a refused second copy would keep
948
+ restarting and print the "already running" message every 10 seconds.
949
+ - **One copy per agent on a computer.** A second copy of the same agent
950
+ stops before it connects and prints: `This agent is already running on this
951
+ computer (process <pid>). Stop that copy first, or run: agent-bridge status`
952
+ - **Port already in use.** If another program holds the Connector's port, the
953
+ agent does not start and prints: `Port <n> is already in use by another
954
+ program on this computer, so the agent did not start.`
955
+ - **Install checks that the agent really started.** Install now waits up to
956
+ 75 seconds for the Connector to answer its health check. If it does not
957
+ answer, install fails and names the service log.
958
+ - **Install refuses a second install of the same agent.** If the agent is
959
+ already installed in another folder or with a different key, install stops
960
+ before it changes anything and prints: `This agent is already installed in
961
+ <dir> with a different key. Uninstall it first: agent-bridge uninstall
962
+ --label <label>`. A downloaded copy such as `margo (1).json` installs as the
963
+ same agent, not as a new one.
964
+ - **The service restarts only after a failure.** On macOS the new service
965
+ file restarts the Connector only when it exits with an error. On Linux the
966
+ unit uses `Restart=on-failure`.
967
+ - **Prepared for one active connection per agent.** When the server reports
968
+ that the agent connected from another place, this copy stops all network
969
+ traffic and prints: `This agent connected from another place, so this copy
970
+ stopped. Stop the other copy, then restart this one.` It stays stopped and
971
+ does not restart itself. The server side of this check is not turned on yet.
972
+
973
+ ---
974
+
975
+ ## Release notes: 0.30.0
976
+
977
+ <!-- [COPY, approved by Eric 2026-10-12] -->
978
+
979
+ 0.30.0 lets the owner choose which read tools an agent has, and the Connector
980
+ checks that choice against the owner's own signing key. Install it together
981
+ with `@securecoms/agent-runtime` 0.13.0 and restart both. See "Owner signing
982
+ key (tool settings)" above.
983
+
984
+ - **Owner-set tools.** In the web app the owner chooses tools for the private
985
+ chat (`web_search`, `fetch_url`, `http_request` with GET, `sql_query`) and
986
+ for rooms in the owner's org (`web_search`). `current_time` is always on.
987
+ - **A key is required.** The choice takes effect only on a Connector that
988
+ holds the owner's signing key (the `pin` command). Without a key, the
989
+ agent keeps today's tools: `current_time` and `web_search` in the private
990
+ chat, `current_time` in rooms.
991
+ - **What the Connector checks.** It checks the owner's signature on each
992
+ private-chat message and on the tool settings. A message it has already
993
+ processed gets no tools. If the settings the server sends differ from what
994
+ the owner signed, the agent falls back to today's tools, limited to what the
995
+ owner signed.
996
+ - **Signed targets.** The endpoints for `http_request` and the databases for
997
+ `sql_query` come from the signed settings only. A `sqlite` path must be its
998
+ real path.
999
+ - **Room web search.** Rooms in the owner's org can use `web_search`. The
1000
+ limit is 50 calls a day for each room and 200 a day for each agent (UTC
1001
+ days). The agent posts one notice in a room when that room reaches its limit.
1002
+ - **Agent frameworks.** An agent that runs through another agent framework
1003
+ (Hermes or OpenClaw) gets no tools from SecureComs once it holds a key and
1004
+ signed settings.
1005
+ - **Older runtime.** With `@securecoms/agent-runtime` 0.12.2 or older, the
1006
+ Connector uses the fallback in every place.
1007
+ - **Off switches.** `SECURECOMS_OWNER_DM_MANIFEST_GRANTS` and
1008
+ `SECURECOMS_ROOM_MANIFEST_GRANTS` are new. See "Room tool rule" above.
1009
+ - **Upgrade note.** Owner messages stored before this release cannot be
1010
+ verified. See "Upgrade note" above.
1011
+
1012
+ ---
1013
+
870
1014
  ## Release notes: 0.29.0
871
1015
 
872
1016
  <!-- [COPY, NEW] Approved by Eric 2026-10-11 (plan Task 37). -->
@@ -887,11 +1031,14 @@ together with `@securecoms/agent-runtime` 0.12.0 and restart both. See
887
1031
  - **Off switches.** A new credential key, `memory.enabled: false`, turns memory
888
1032
  off on the machine. `SECURECOMS_TOOL_DENY=memory_note` now removes only the
889
1033
  pin and forget tool; automatic memory continues.
890
- - **Skills in the owner's private chat.** With runtime 0.12.0, the memory
891
- tool gate refuses every skill on the owner's private-chat turns. Only
892
- `current_time`, `echo`, `memory_note`, and `web_search`, `fetch_url`,
893
- `http_request` (GET) and `sql_query` with arguments that pass the gate, run
894
- there. Skills in rooms are not changed.
1034
+ <!-- [COPY, approved by Eric 2026-10-12] skills spec 2026-10-12 section 7 C-5. -->
1035
+ - **Tools in the owner's private chat.** With runtime 0.12.0 or later, the
1036
+ memory tool gate checks every tool call on the owner's private-chat turns.
1037
+ The tools this bridge grants there are `current_time`, which runs as usual,
1038
+ and `web_search`, which runs when its query does not repeat a number, link,
1039
+ address or wording from memory or the chat history that the owner did not
1040
+ type in that message. Custom skills are not offered on any turn, in the
1041
+ private chat or in rooms, and were not before this release.
895
1042
  - **`/healthz`.** New `memory_hot_bytes`, `memory_deadline_misses`,
896
1043
  `memory_reads`, `memory_reads_discarded` and `pid`.
897
1044
 
package/dist/bin.d.ts CHANGED
@@ -1,9 +1,22 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * SecureComs Agent Bridge — HTTP daemon entry point.
4
+ * Long-running diagnostics go to stderr through the content-free service
5
+ * logger. The local bearer token is persisted to the `bridge-token` file (see
6
+ * tokenFile below); startup emits only a fixed token-loaded event, never the
7
+ * token, its fingerprint, or its path. This prevents the former
8
+ * `BRIDGE_TOKEN=<value>` leak into journald/launchd logs.
9
+ */
10
+ import { type BridgeConfig } from "./config.js";
2
11
  import { BridgeAgent } from "./bridge-agent.js";
3
12
  import { createHttpServer } from "./http-server.js";
4
13
  import { attachAgentWebSocket } from "./ws-server.js";
14
+ import { createServer as netCreateServer } from "node:net";
15
+ import { type DaemonHealth } from "./service/install-prep.js";
5
16
  import { type ResolveNodeDeps } from "./service/resolve-node.js";
6
17
  import { type Harness } from "./service/wire.js";
18
+ import { type ServiceLog } from "./service-log.js";
19
+ import { type LockResult } from "./service/instance-lock.js";
7
20
  export declare function nodeMajorOk(version: string): boolean;
8
21
  /**
9
22
  * A redacted bearer-token hint for explicit foreground install output: a short
@@ -11,10 +24,13 @@ export declare function nodeMajorOk(version: string): boolean;
11
24
  * diagnostics do not call this helper or expose even the hint.
12
25
  */
13
26
  export declare function tokenFingerprint(token: string): string;
14
- export declare function parseVerb(argv: string[]): "install" | "uninstall" | "status" | "wire" | "unwire" | "models" | null;
27
+ export declare function parseVerb(argv: string[]): "install" | "uninstall" | "status" | "wire" | "unwire" | "models" | "pin" | null;
15
28
  export declare function slugFromCredentialPath(credentialPath: string): string;
16
29
  export declare function chooseInstallExecPath(runningExecPath: string, override: string | undefined, deps: ResolveNodeDeps): string;
30
+ export declare function realGetHealth(port: number): DaemonHealth | null;
17
31
  export declare function realCopyConnector(srcDir: string, dstDir: string, harness: Harness): void;
32
+ /** The stderr line (with newline) a failed service verb prints. */
33
+ export declare function formatServiceError(verb: string, e: unknown): string;
18
34
  /**
19
35
  * Markdown memory 7a, N-L5: start the agent, THEN create the HTTP server and
20
36
  * attach /v1/ws. start() applies the runtime config (and any clear issued
@@ -35,3 +51,69 @@ export declare function startThenServe(agent: BridgeAgent, opts: {
35
51
  closeAllSseStreams: () => void;
36
52
  agentWs: ReturnType<typeof attachAgentWebSocket>;
37
53
  }>;
54
+ /** B1 `held` poll (spec §4.1.2, audit r2 M-3): the holder may be this same
55
+ * service's previous process, still inside shutdown()'s 8 s drain window. */
56
+ export declare const HELD_POLL_TOTAL_MS = 10000;
57
+ export declare const HELD_POLL_INTERVAL_MS = 500;
58
+ /** Extra acquires after the poll when "held" carries no holder pid (a takeover
59
+ * race). M1 names a real pid or is not printed. */
60
+ export declare const HELD_NO_PID_REACQUIRES = 3;
61
+ /** shutdown()'s hard-exit fallback for a hung agent.close() drain (ADR-0008 H1). */
62
+ export declare const SHUTDOWN_HARD_EXIT_MS = 8000;
63
+ /** The lock surface runMode uses (InstanceLock in production). */
64
+ export interface RunModeLock {
65
+ acquire(): {
66
+ result: LockResult;
67
+ holderPid?: number;
68
+ };
69
+ release(): void;
70
+ lastError?: unknown;
71
+ }
72
+ /**
73
+ * Everything run mode touches outside the process, injected so the start
74
+ * order, the refusal exits and the release timing are testable
75
+ * (bin-run-mode.test.ts). `exit` never returns in production; runMode
76
+ * returns right after calling it so a recording test double also stops.
77
+ */
78
+ export interface RunModeDeps {
79
+ credentialPath: string;
80
+ storePath?: string;
81
+ argv: string[];
82
+ env: NodeJS.ProcessEnv;
83
+ home: string;
84
+ newLock(path: string): RunModeLock;
85
+ newAgent(cfg: BridgeConfig): BridgeAgent;
86
+ /** The B2 pre-bind's socket layer (node:net in production). */
87
+ net: {
88
+ createServer: typeof netCreateServer;
89
+ };
90
+ serve: typeof startThenServe;
91
+ now(): number;
92
+ sleep(ms: number): Promise<void>;
93
+ /** Arms the shutdown hard-exit fallback; returns its cancel. */
94
+ setHardExitTimer(cb: () => void, ms: number): () => void;
95
+ onSignal(signal: "SIGINT" | "SIGTERM", handler: () => void): void;
96
+ /** Synchronous `process.once("exit")` registration. */
97
+ onExit(handler: () => void): void;
98
+ exit(code: number): void;
99
+ /** One line of approved user-facing copy (spec §8). */
100
+ print(line: string): void;
101
+ log: ServiceLog;
102
+ }
103
+ /**
104
+ * The daemon's run mode (spec §4.1.1). Order, each step gated on the last:
105
+ * 1. loadConfig (+ daemon args, bind check);
106
+ * 2. canonical-UUID check of identity_id (it becomes a path);
107
+ * 3. B1 per-identity lock at ~/.securecoms/locks/<identity_id>.lock;
108
+ * 4. resolveToken (it can WRITE the token file, so only after the lock);
109
+ * 5. B2 pre-bind of daemon.port: a bare net server that destroys every
110
+ * connection, so a taken port refuses before the store opens or any
111
+ * call to SecureComs is made;
112
+ * 6. new BridgeAgent (opens the SQLite MLS store);
113
+ * 7. startThenServe, then hand the pre-bound handle to the HTTP server.
114
+ * The lock is released only after agent.close() settles (audit H-2): in the
115
+ * close().finally, in the hard-exit fallback, and in a synchronous exit
116
+ * backstop. Never at shutdown() entry: a second copy must not open the MLS
117
+ * store while this one is still draining it.
118
+ */
119
+ export declare function runMode(deps: RunModeDeps): Promise<void>;