@securecoms/agent-bridge 0.30.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.
@@ -0,0 +1,88 @@
1
+ import type { ServiceLog } from "../service-log.js";
2
+ /** An unparseable lock this young may be a holder mid-write. */
3
+ export declare const LOCK_PARTIAL_WRITE_GRACE_MS = 10000;
4
+ /** A takeover guard this old was left by a crashed takeover. */
5
+ export declare const LOCK_TAKEOVER_GUARD_STALE_MS = 30000;
6
+ /** Two boot-epoch reads further apart than this are two different boots. */
7
+ export declare const BOOT_TOLERANCE_SEC = 120;
8
+ /** A holder refreshes its lock's mtime this often (#808 N1). */
9
+ export declare const LOCK_HEARTBEAT_MS = 60000;
10
+ /** A same-kernel, other-hostname lock untouched for this long is abandoned. */
11
+ export declare const LOCK_FOREIGN_STALE_MS: number;
12
+ export type LockRefusal = "held" | "foreign_host" | "unreadable" | "busy" | "failed";
13
+ export type LockResult = "acquired" | LockRefusal;
14
+ /** Everything the lock reads about the machine. Injected in tests. */
15
+ export interface LockEnv {
16
+ pid: number;
17
+ hostname(): string;
18
+ /** Linux boot_id, or undefined where the platform has none. */
19
+ bootId(): string | undefined;
20
+ bootEpochSec(): number;
21
+ /** Linux /proc/<pid>/stat start time, or undefined (not Linux / no such pid). */
22
+ procStart(pid: number): string | undefined;
23
+ /** kill(pid, 0): true when running (EPERM counts as running). */
24
+ pidAlive(pid: number): boolean;
25
+ /** Test seam: runs after the takeover guard is taken, before the re-read. */
26
+ beforeTakeoverReread?(): void;
27
+ /** Test seam: runs after the stale lock is unlinked, before our create. */
28
+ beforeTakeoverCreate?(): void;
29
+ /** Test seam: runs after an O_EXCL create found the lock, before it is read. */
30
+ beforeLockRead?(): void;
31
+ }
32
+ /** Field 22 of /proc/<pid>/stat. The comm field (2) may contain spaces or
33
+ * parentheses, so fields are counted from the LAST ')'. */
34
+ export declare function procStartFromStat(stat: string): string | undefined;
35
+ export declare function pidAliveByKill(pid: number): boolean;
36
+ export declare const realLockEnv: LockEnv;
37
+ export declare class InstanceLock {
38
+ readonly path: string;
39
+ private readonly env;
40
+ private readonly log;
41
+ private readonly heartbeatMs;
42
+ held: boolean;
43
+ /** The exact body this process wrote (#808 N1): release and the ownership
44
+ * check compare the file against THIS, never against live machine facts
45
+ * (a hostname can change under a running process). */
46
+ private written;
47
+ private heartbeat;
48
+ /** The error behind the last `unreadable` / `failed`, for the caller's one
49
+ * log line (the lock itself never logs a refusal: it is retried per call). */
50
+ lastError: unknown;
51
+ /** PID read from the lock body of the live holder behind the last `held`. */
52
+ private holderPid;
53
+ constructor(path: string, env?: LockEnv, log?: ServiceLog, heartbeatMs?: number);
54
+ private body;
55
+ /** Try to hold the lock. Never throws (#808 L-e: machine reads included). */
56
+ acquire(): {
57
+ result: LockResult;
58
+ holderPid?: number;
59
+ };
60
+ /**
61
+ * True while the file is still exactly the body this process wrote. Read
62
+ * before every reserve (one small read), so a holder whose lock was taken
63
+ * while it was frozen stops before it spends (#808 N1). A lost lock is
64
+ * dropped: the caller then refuses, and later calls try to re-acquire.
65
+ */
66
+ stillHeld(): boolean;
67
+ private acquireUnguarded;
68
+ /** Remove the lock only while it is still exactly the body this process
69
+ * wrote (#808 N1: not the live hostname, which can change under us). */
70
+ release(): void;
71
+ private drop;
72
+ /** We hold it: remember what we wrote (the file as it is now, ours) and
73
+ * start the heartbeat. */
74
+ private took;
75
+ /** Refresh the mtime while the file is still ours; stop if it is not. */
76
+ private beat;
77
+ private sameBoot;
78
+ /** O_EXCL create with our body. A write failure removes the half-written
79
+ * file (it is ours: we created it) and reports `failed`, never throws. */
80
+ private create;
81
+ /**
82
+ * Replace a stale lock. Only the holder of the O_EXCL takeover guard may
83
+ * remove a lock, and only after re-reading it UNCHANGED, so two runtimes
84
+ * that both saw the same stale lock cannot each delete the other's new one.
85
+ * A fresh guard means a takeover is in progress: busy this time.
86
+ */
87
+ private takeOver;
88
+ }
@@ -1,4 +1,4 @@
1
1
  import type { ServiceConfig } from "./config.js";
2
2
  /** A deterministic launchd LaunchAgent plist. ProgramArguments re-invoke the
3
- * running bin in run mode; KeepAlive restarts on crash, RunAtLoad starts at login. */
3
+ * running bin in run mode; KeepAlive{SuccessfulExit:false} restarts only on a non-zero exit (a clean exit stays down), RunAtLoad starts at login. */
4
4
  export declare function renderLaunchdPlist(cfg: ServiceConfig): string;
@@ -1,11 +1,9 @@
1
1
  import type { AgentFleetEntry } from "./fleet.js";
2
+ import { type DaemonHealth } from "./install-prep.js";
2
3
  export interface StatusDeps {
3
4
  readFleet: () => AgentFleetEntry[];
4
- probeConnect: (port: number) => boolean;
5
- getHealth: (port: number) => {
6
- agent_sessions?: number;
7
- evictions?: number;
8
- } | null;
5
+ /** Routed `/healthz` probe (P-2): null unless the daemon answered a 200. */
6
+ getHealth: (port: number) => DaemonHealth | null;
9
7
  }
10
8
  export interface AgentStatusRow {
11
9
  slug: string;
@@ -1,4 +1,4 @@
1
1
  import type { ServiceConfig } from "./config.js";
2
2
  /** A systemd --user unit. ExecStart re-invokes the running bin in run mode;
3
- * Restart=always supervises crashes. WantedBy=default.target enables at login. */
3
+ * Restart=on-failure supervises crashes only (a clean exit stays down). WantedBy=default.target enables at login. */
4
4
  export declare function renderSystemdUnit(cfg: ServiceConfig): string;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const BRIDGE_VERSION = "0.30.0";
1
+ export declare const BRIDGE_VERSION = "0.30.1";
@@ -34,6 +34,9 @@ export declare const INFLIGHT_STALE_AFTER_MS: number;
34
34
  * consumer, so it never carried its notes.
35
35
  */
36
36
  export declare const HELLO_WAIT_MS = 2000;
37
+ /** C9: the close code a superseded bridge sends its local runtime sockets;
38
+ * the same code the server sends the bridge (spec §4.1.5, OQ-9). */
39
+ export declare const WS_CLOSE_SESSION_SUPERSEDED = 4409;
37
40
  /** Spec §8.5: the hello-reply feature that tells the runtime it may offer memory_note on this socket. */
38
41
  export declare const MEMORY_NOTES_FEATURE = "memory_notes";
39
42
  /** Semantic memory 7b (spec §7.2 Q4): the hello feature a runtime declares to receive `memory.recall`; the bridge echoes it. */
@@ -52,4 +55,5 @@ export declare const WS_AGENT_MEMBERS: readonly ["ackRuntimeMessages", "action",
52
55
  export type WsAgent = Pick<BridgeAgent, (typeof WS_AGENT_MEMBERS)[number]>;
53
56
  export declare function attachAgentWebSocket(server: HttpServer, agent: WsAgent, opts: AgentWebSocketOptions): {
54
57
  close(): void;
58
+ enterSessionSuperseded(): void;
55
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@securecoms/agent-bridge",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.5.0"