@jbkjr/relay 1.2.2 → 1.3.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.
Files changed (47) hide show
  1. package/README.md +19 -12
  2. package/adapters/claude/relay/.claude-plugin/plugin.json +1 -1
  3. package/adapters/claude/relay/skills/discuss/SKILL.md +3 -0
  4. package/adapters/codex/AGENTS.snippet.md +2 -0
  5. package/adapters/codex/relay/.codex-plugin/plugin.json +1 -1
  6. package/adapters/codex/relay/skills/relay-discuss/SKILL.md +3 -0
  7. package/adapters/generate.mjs +6 -1
  8. package/codex-pin.json +2 -2
  9. package/dist/build-info.json +2 -2
  10. package/dist/cli.js +160 -2
  11. package/dist/confine/canary.js +19 -4
  12. package/dist/confine/probe.js +11 -3
  13. package/dist/core/approvals.js +29 -4
  14. package/dist/core/db.js +44 -2
  15. package/dist/core/identity.js +43 -3
  16. package/dist/core/ops.js +9 -9
  17. package/dist/core/retention.js +66 -12
  18. package/dist/core/room-clipboard.js +86 -0
  19. package/dist/core/room-policy.js +17 -0
  20. package/dist/core/room-terminal.js +227 -0
  21. package/dist/core/room-types.js +130 -0
  22. package/dist/core/rooms.js +839 -0
  23. package/dist/core/secrets.js +4 -0
  24. package/dist/core/shown.js +19 -3
  25. package/dist/core/storage.js +2 -2
  26. package/dist/install/doctor.js +1 -0
  27. package/dist/mcp/elicit.js +81 -0
  28. package/dist/mcp/host.js +121 -1
  29. package/dist/mcp/server.js +159 -11
  30. package/docs/UPGRADING.md +88 -0
  31. package/docs/pinned-codex.md +3 -1
  32. package/npm-shrinkwrap.json +2 -2
  33. package/package.json +1 -1
  34. package/scripts/codex-qualify/codex-qualifier.mjs +22 -8
  35. package/scripts/codex-qualify/codex-stage2.mjs +57 -5
  36. package/scripts/codex-qualify/stage2-parallel.mjs +200 -0
  37. package/test/fixtures/stable-surfaces/registry.json +25 -1
  38. package/test/fixtures/stable-surfaces/room.json +681 -0
  39. package/test/fixtures/stable-surfaces/tools-desktop.json +57 -0
  40. package/test/fixtures/stable-surfaces/tools.json +54 -0
  41. package/test/fixtures/stable-surfaces/usage.txt +11 -1
  42. package/test/fixtures/stage2-parallel/fake-driver.mjs +34 -0
  43. package/test/fixtures/stage2-parallel/harness.mjs +8 -0
  44. package/test/helpers.ts +20 -1
  45. package/test/never-policy.test.ts +4 -4
  46. package/test/stable-surfaces.test.ts +125 -1
  47. package/test/wp4-interlock.test.ts +1 -1
@@ -540,6 +540,63 @@
540
540
  }
541
541
  }
542
542
  },
543
+ "room": {
544
+ "type": "object",
545
+ "properties": {
546
+ "action": {
547
+ "type": "string",
548
+ "enum": [
549
+ "open",
550
+ "join",
551
+ "send",
552
+ "wait",
553
+ "transcript",
554
+ "close"
555
+ ]
556
+ },
557
+ "purpose": {
558
+ "type": "string",
559
+ "maxLength": 1000
560
+ },
561
+ "invite": {
562
+ "type": "string",
563
+ "maxLength": 256
564
+ },
565
+ "cursor": {
566
+ "type": "integer",
567
+ "minimum": 0,
568
+ "maximum": 9007199254740991
569
+ },
570
+ "text": {
571
+ "type": "string"
572
+ },
573
+ "stance": {
574
+ "type": "string",
575
+ "enum": [
576
+ "continue",
577
+ "agree",
578
+ "crux"
579
+ ]
580
+ },
581
+ "request_id": {
582
+ "type": "string",
583
+ "format": "uuid",
584
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
585
+ },
586
+ "wait_s": {
587
+ "type": "integer",
588
+ "minimum": 0,
589
+ "maximum": 21600
590
+ },
591
+ "session_token": {
592
+ "type": "string"
593
+ }
594
+ },
595
+ "required": [
596
+ "action"
597
+ ],
598
+ "additionalProperties": false
599
+ },
543
600
  "status": {
544
601
  "type": "object",
545
602
  "properties": {
@@ -684,6 +684,60 @@
684
684
  }
685
685
  }
686
686
  },
687
+ "room": {
688
+ "type": "object",
689
+ "properties": {
690
+ "action": {
691
+ "type": "string",
692
+ "enum": [
693
+ "open",
694
+ "join",
695
+ "send",
696
+ "wait",
697
+ "transcript",
698
+ "close"
699
+ ]
700
+ },
701
+ "purpose": {
702
+ "type": "string",
703
+ "maxLength": 1000
704
+ },
705
+ "invite": {
706
+ "type": "string",
707
+ "maxLength": 256
708
+ },
709
+ "cursor": {
710
+ "type": "integer",
711
+ "minimum": 0,
712
+ "maximum": 9007199254740991
713
+ },
714
+ "text": {
715
+ "type": "string"
716
+ },
717
+ "stance": {
718
+ "type": "string",
719
+ "enum": [
720
+ "continue",
721
+ "agree",
722
+ "crux"
723
+ ]
724
+ },
725
+ "request_id": {
726
+ "type": "string",
727
+ "format": "uuid",
728
+ "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
729
+ },
730
+ "wait_s": {
731
+ "type": "integer",
732
+ "minimum": 0,
733
+ "maximum": 21600
734
+ }
735
+ },
736
+ "required": [
737
+ "action"
738
+ ],
739
+ "additionalProperties": false
740
+ },
687
741
  "status": {
688
742
  "type": "object",
689
743
  "properties": {
@@ -11,6 +11,15 @@ relay — delegation, consultation, discussion and review across families of cod
11
11
  relay tree [run_id] [--watch] jobs, threads, discussions and reviews as one tree
12
12
  relay chat <discussion_id> tail a discussion; type a line to send it to both participants
13
13
  [--say "message"] [--print] one-shot forms: inject a message / print the transcript and exit
14
+ relay room new create a room; print one invitation prompt per conversation
15
+ (on macOS, then offer each on the clipboard in turn, clearing it after)
16
+ relay room list list rooms as JSON (no transcript or credentials)
17
+ relay room <id> follow a room; type a line to add terminal text
18
+ --print print the full transcript and exit (no terminal required)
19
+ --say "message" add one terminal line; print the JSON result
20
+ --reseat <member-1|member-2> review a seat, type the exact confirmation, print a new prompt
21
+ --close review the room, type the exact confirmation, close it
22
+ Room writes require your own interactive terminal.
14
23
  relay approvals approval requests waiting for a decision
15
24
  relay adopt <id> --to <fingerprint> explicitly authorize takeover by the connection named in status
16
25
  relay approve <request_id> [--job] [note] let a launched agent do what it asked: needs an
@@ -24,7 +33,8 @@ relay — delegation, consultation, discussion and review across families of cod
24
33
  (all finished runs if no id; unmerged branches are kept),
25
34
  relay's leftover temporary directories, and, if
26
35
  keep_records_days is set, records of runs with no
27
- activity for that many days
36
+ activity for that many days; rooms expire independently,
37
+ with transcripts kept for that many days after ending
28
38
  relay clean --forget <run_id> [--write]
29
39
  forget a finished run kept because its repository is gone:
30
40
  its records and relay's own files for it; prints what it
@@ -0,0 +1,34 @@
1
+ // A stand-in for codex-stage2.mjs in the parallel coordinator's tests: the same command line, and
2
+ // a verdict of the real shape, with what it does per role read from <dir>/../../behavior.json:
3
+ // { i30: {...}, main: {...} }, each { inFlightAfterMs, runMs, exit, state, skip: [ids], extra: [ids],
4
+ // noVerdict, hang, orphan, still, crash }. It records when it started in <dir>/../<role>-started.
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { spawn } from "node:child_process";
8
+ import { setTimeout as delay } from "node:timers/promises";
9
+ import { ITEMS, ITEM30_IN_FLIGHT, item, part, verdictOf } from "../../../scripts/codex-qualify/codex-stage2.mjs";
10
+ import { EXPECTED_PARTS } from "../../../scripts/codex-qualify/codex-pin-store.mjs";
11
+
12
+ const [, dir, version, bin, ...rest] = process.argv.slice(2);
13
+ const only = rest[rest.indexOf("--items") + 1].split(",");
14
+ const role = only.includes("30") ? "i30" : "main";
15
+ const b = JSON.parse(fs.readFileSync(path.join(dir, "..", "..", "behavior.json"), "utf8"))[role] ?? {};
16
+ fs.writeFileSync(path.join(dir, "..", `${role}-started`), String(Date.now()));
17
+ fs.writeFileSync(path.join(dir, "..", `${role}-argv.json`), JSON.stringify(process.argv.slice(2)));
18
+ // A detached descendant in its own group, as the driver's executors are: only the environment's scratch paths name it.
19
+ if (b.orphan) spawn(process.execPath, ["-e", "setInterval(()=>{},1000)"], { detached: true, stdio: "ignore" }).unref();
20
+ if (b.inFlightAfterMs !== undefined) setTimeout(() => fs.writeFileSync(path.join(dir, ITEM30_IN_FLIGHT), "{}\n"), b.inFlightAfterMs);
21
+ if (b.crash) { await delay(b.crash); process.exit(b.exit ?? 3); }
22
+ if (b.hang) setInterval(() => {}, 1000);
23
+ else {
24
+ await delay(b.runMs ?? 0);
25
+ const ran = new Set([...only.filter((id) => !(b.skip ?? []).includes(id)), ...(b.extra ?? [])]);
26
+ const items = Object.fromEntries(Object.keys(ITEMS).map((id) => [id, ran.has(id)
27
+ ? item(Object.fromEntries(EXPECTED_PARTS[id].map((n) => [n, part(id === "30" && b.state ? b.state : "passed", id === "30" && b.state === "failed" ? "fixture failure" : [])])))
28
+ : item({ run: part("not run", "not selected (--items)") })]));
29
+ const v = verdictOf(items);
30
+ const still = b.still ? ["fixture survivor 1"] : [];
31
+ if (still.length) { v.state = "failed"; v.ok = false; }
32
+ if (!b.noVerdict) fs.writeFileSync(path.join(dir, "stage2-verdict.json"), JSON.stringify({ ...v, mode: "serial", sweep: { left: [], still }, version, bin, oldBin: null, model: "fixture-model", relayPath: role === "main" ? "present" : "not tried", items: v.items }));
33
+ process.exit(b.exit ?? 0);
34
+ }
@@ -0,0 +1,8 @@
1
+ // Runs the parallel coordinator as its own process for the tests that signal it or supervise it:
2
+ // node harness.mjs '<json { o, opts }>'. The coordinator's driver is fake-driver.mjs.
3
+ import path from "node:path";
4
+ import { coordinate } from "../../../scripts/codex-qualify/stage2-parallel.mjs";
5
+
6
+ const { o, opts } = JSON.parse(process.argv[2]);
7
+ const r = await coordinate(o, { ...opts, driver: path.join(import.meta.dirname, "fake-driver.mjs") });
8
+ process.exit(r.code);
package/test/helpers.ts CHANGED
@@ -101,6 +101,12 @@ export interface Harness {
101
101
  * entry per connection (the auth token sent, and the user message's text).
102
102
  */
103
103
  inbox(): Promise<{ env: Record<string, string>; posts(): { token?: string; text: string }[] }>;
104
+ /**
105
+ * The stand-in clipboard every relay process of this harness uses (pbcopy and pbpaste through
106
+ * RELAY_TEST_SYSTEM_TOOLS, executables.ts systemTool): what it holds now, and every copy made, in
107
+ * order. No test reaches the person's own clipboard. `failCopies` makes pbcopy exit 1.
108
+ */
109
+ clipboard(): { held: string; copies: string[]; failCopies(fail: boolean): void };
104
110
  close(): Promise<void>;
105
111
  }
106
112
 
@@ -535,7 +541,14 @@ export async function harness(rules: Rule[] = [], config: Record<string, unknown
535
541
  // would send agents elsewhere, and relay rightly refuses to pass it on (tests that need one set it
536
542
  // through extraEnv).
537
543
  for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !k.startsWith("RELAY_") && !hostVar(k) && !HOME_VARS.includes(k)) env[k] = v;
538
- Object.assign(env, { HOME: userHome, STUB_TEMP_ROOT: fs.realpathSync(os.tmpdir()) }, extraEnv, { RELAY_HOME: home, RELAY_DEV_MODEL_STUB: "1", STUB_DIR: stub, STUB_SCENARIO: path.join(tmp, "scenario.json") });
544
+ // Stand-ins for pbcopy and pbpaste, under the system temp directory as testSystemTools requires:
545
+ // relay's room open puts a prompt on the clipboard, and no test may touch the person's own.
546
+ const clipDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "relay-clip-")));
547
+ const clipFile = path.join(clipDir, "clipboard"), clipLog = path.join(clipDir, "copies.jsonl"), clipFail = path.join(clipDir, "fail");
548
+ fs.writeFileSync(clipFile, "");
549
+ fs.writeFileSync(path.join(clipDir, "pbcopy"), `#!/bin/sh\n[ -e "${clipFail}" ] && exit 1\ncat > "${clipFile}"\n/usr/bin/python3 -c 'import json,sys; print(json.dumps(open(sys.argv[1]).read()))' "${clipFile}" >> "${clipLog}"\n`, { mode: 0o755 });
550
+ fs.writeFileSync(path.join(clipDir, "pbpaste"), `#!/bin/sh\ncat "${clipFile}"\n`, { mode: 0o755 });
551
+ Object.assign(env, { HOME: userHome, STUB_TEMP_ROOT: fs.realpathSync(os.tmpdir()), RELAY_TEST_SYSTEM_TOOLS: clipDir }, extraEnv, { RELAY_HOME: home, RELAY_DEV_MODEL_STUB: "1", STUB_DIR: stub, STUB_SCENARIO: path.join(tmp, "scenario.json") });
539
552
  scratchEnv(env);
540
553
 
541
554
  const clients: Client[] = [];
@@ -682,6 +695,11 @@ export async function harness(rules: Rule[] = [], config: Record<string, unknown
682
695
  };
683
696
  return {
684
697
  home, repo, env,
698
+ clipboard: () => ({
699
+ held: fs.readFileSync(clipFile, "utf8"),
700
+ copies: fs.existsSync(clipLog) ? fs.readFileSync(clipLog, "utf8").split("\n").filter(Boolean).map((l) => JSON.parse(l) as string) : [],
701
+ failCopies: (fail: boolean) => { if (fail) fs.writeFileSync(clipFail, ""); else fs.rmSync(clipFail, { force: true }); },
702
+ }),
685
703
  call: root.call,
686
704
  instance,
687
705
  log,
@@ -717,6 +735,7 @@ export async function harness(rules: Rule[] = [], config: Record<string, unknown
717
735
  inbox,
718
736
  close: async () => {
719
737
  for (const c of clients) await c.close().catch(() => {});
738
+ fs.rmSync(clipDir, { recursive: true, force: true });
720
739
  for (const s of servers) s.close();
721
740
  modelStub.close();
722
741
  // Leave nothing running if a test failed part-way.
@@ -289,19 +289,19 @@ test("checkpoint identity history retains both targets after protected symlink r
289
289
  } finally { f.close(); }
290
290
  });
291
291
 
292
- test("schema 4 stores the run floor in JSON params without migration and reconstructs old runs", () => {
292
+ test("schema 5 stores the run floor in JSON params without migration and reconstructs old runs", () => {
293
293
  const f = fixture();
294
294
  try {
295
295
  const file = path.join(process.env.RELAY_HOME!, "relay.db"); closeDbForTests();
296
296
  const old = new DatabaseSync(file);
297
- assert.equal((old.prepare("PRAGMA user_version").get() as any).user_version, 4);
297
+ assert.equal((old.prepare("PRAGMA user_version").get() as any).user_version, 5);
298
298
  assert.equal(old.prepare("PRAGMA table_info(runs)").all().some((c: any) => c.name === "never_floor_json"), false);
299
- // An existing schema-4 run has no private params yet. Reopening must not migrate it.
299
+ // An existing schema-5 run has no private params yet. Reopening must not migrate it.
300
300
  old.prepare("UPDATE runs SET config_json = json_remove(config_json, '$.params_json') WHERE id = ?").run(f.run);
301
301
  old.close();
302
302
  db();
303
303
  assert.equal(registryBackup(), null);
304
- assert.equal((db().prepare("PRAGMA user_version").get() as any).user_version, 4);
304
+ assert.equal((db().prepare("PRAGMA user_version").get() as any).user_version, 5);
305
305
  db().prepare("UPDATE runs SET config_json = json_set(config_json, '$.params_json.unrelated', 7) WHERE id = ?").run(f.run);
306
306
  const config = runConfig(f.run);
307
307
  assert.equal("params_json" in config, false, "private run params are not configuration");
@@ -18,6 +18,10 @@ import { pendingEvents } from "../dist/core/watch.js";
18
18
  import { TESTED_MACOS, testedMacOS } from "../dist/install/doctor.js";
19
19
  import { targetDef } from "../dist/targets/index.js";
20
20
  import { CLI } from "./helpers.ts";
21
+ import { createHash } from "node:crypto";
22
+ import * as rooms from "../dist/core/rooms.js";
23
+ import * as R from "../dist/core/room-types.js";
24
+ import { roomText } from "../dist/core/shown.js";
21
25
 
22
26
  const fixtures = path.join(import.meta.dirname, "fixtures", "stable-surfaces");
23
27
  function snapshot(name: string, value: unknown) {
@@ -31,6 +35,126 @@ function snapshot(name: string, value: unknown) {
31
35
  assert.equal(text, fs.readFileSync(file, "utf8"));
32
36
  }
33
37
 
38
+ test("stable surfaces: room views, caller cursors, endings and refusals", async (t) => {
39
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "relay-room-surface-"));
40
+ const saved = process.env.RELAY_HOME;
41
+ const at = Date.parse("2026-11-11T18:00:00.000Z");
42
+ const roomId = `rm_${"0".repeat(32)}`;
43
+ const members = [`m_${"1".repeat(32)}`, `m_${"2".repeat(32)}`];
44
+ const invites = [`ri1_${"3".repeat(32)}`, `ri1_${"4".repeat(32)}`];
45
+ const call: R.RoomCallEvidence = {
46
+ identity: { call_id: "fixture-call", scope: "conversation-token", harness: "fixture-host", family: "openai", subagent: false, singleton_violation: false,
47
+ codex: { malformed: false, metadata_present: false, thread_id: null, thread_source: null, turn_trigger: null, originator: null, sandbox: null, auto_review: null, approval_policy: null } },
48
+ eligibility: { eligible: true }, block_s: 50, host_wait_cap_s: null, sanitizeText: roomText,
49
+ };
50
+ const success = <T,>(value: T): Exclude<T, R.RoomFailure> => {
51
+ assert.ok(value && typeof value === "object" && !("error" in value) && !("refused" in value), JSON.stringify(value));
52
+ return value as Exclude<T, R.RoomFailure>;
53
+ };
54
+ try {
55
+ closeDbForTests();
56
+ process.env.RELAY_HOME = tmp;
57
+ t.mock.method(Date, "now", () => at);
58
+ const a = newInstance({ kind: "root" }, tmp, "codex"), b = newInstance({ kind: "root" }, tmp, "claude");
59
+ // Shared owners keep process-table details out of the fixture. Protocol admission is
60
+ // supplied explicitly; host eligibility has its own table-driven tests.
61
+ a.carried = b.carried = true;
62
+ const seed = () => {
63
+ for (const table of ["room_messages", "room_invites", "room_bindings", "room_members", "rooms", "room_exposures"]) db().prepare(`DELETE FROM ${table}`).run();
64
+ db().prepare("INSERT INTO rooms (id,state,created_at,expires_at,max_turns,origin) VALUES (?,'waiting',?,?,24,'terminal')").run(roomId, at, at + R.ROOM_LIFETIME_MS);
65
+ members.forEach((id, i) => {
66
+ db().prepare("INSERT INTO room_members (room_id,id,ordinal) VALUES (?,?,?)").run(roomId, id, i + 1);
67
+ const hash = createHash("sha256").update(R.ROOM_INVITE_DOMAIN).update(invites[i]).digest("hex");
68
+ db().prepare("INSERT INTO room_invites (code_hash,room_id,member_id,generation,expires_at) VALUES (?,?,?,1,?)").run(hash, roomId, id, at + R.ROOM_INVITE_LIFETIME_MS);
69
+ });
70
+ };
71
+ const join = (owner: typeof a, invite: string) => rooms.roomJoin(owner, { action: "join", invite }, call);
72
+ const pair = async () => { seed(); success(await join(a, invites[0])); success(await join(b, invites[1])); };
73
+ const send = (owner: typeof a, cursor: number, stance: R.RoomStance, n: number) => rooms.roomSend(owner, {
74
+ action: "send", cursor, text: "A bounded recommendation.", stance, request_id: `00000000-0000-4000-8000-${String(n).padStart(12, "0")}`,
75
+ }, call);
76
+ const wait = (owner: typeof a, cursor: number) => rooms.roomWait(owner, { action: "wait", cursor, wait_s: 0 }, call);
77
+ const results: Record<string, unknown> = {};
78
+ seed();
79
+ results.waiting = success(await join(a, invites[0]));
80
+ results.repeated_join = success(await join(a, invites[0]));
81
+ results.open = success(await join(b, invites[1]));
82
+ results.empty_wait = success(await wait(b, 0));
83
+ results.send = success(await send(a, 0, "continue", 1));
84
+ results.repeated_send = success(await send(a, 0, "continue", 1));
85
+ const message = success(await wait(b, 0));
86
+ assert.equal(message.user_confirmed_ignored, true);
87
+ assert.equal(message.messages[0].sender.member_id, members[0]);
88
+ results.member_message = message;
89
+ success(rooms.roomAddLine(roomId as R.RoomId, "A line from a terminal.", roomText));
90
+ const terminal = success(await wait(b, 1));
91
+ assert.equal(terminal.messages[0].sender.member_id, null);
92
+ results.terminal_line = terminal;
93
+ const page = success(await rooms.roomTranscript(a, { action: "transcript", cursor: 0 }, call));
94
+ assert.equal(page.remaining, 1);
95
+ assert.equal(page.through_seq, 1);
96
+ results.transcript_page = page;
97
+ const refused = await send(b, 0, "continue", 2);
98
+ assert.ok("refused" in refused && "messages" in refused);
99
+ results.refusal_with_view = refused;
100
+ results.refusal = await rooms.roomWait(b, { action: "wait", cursor: -1 }, call);
101
+ results.unavailable = await join(a, `ri1_${"f".repeat(32)}`);
102
+ assert.deepEqual(results.unavailable, { error: R.ROOM_UNAVAILABLE_ERROR, recovery: R.ROOM_UNAVAILABLE_RECOVERY });
103
+
104
+ await pair();
105
+ success(await send(a, 0, "agree", 1));
106
+ results.agreement = success(await send(b, 1, "agree", 2));
107
+ await pair();
108
+ success(await send(a, 0, "crux", 1));
109
+ results.crux = success(await send(b, 1, "continue", 2));
110
+ await pair();
111
+ db().prepare("UPDATE rooms SET turns = 23 WHERE id = ?").run(roomId);
112
+ results.turn_limit = success(await send(a, 0, "continue", 1));
113
+ await pair();
114
+ results.member_close = success(await rooms.roomClose(a, { action: "close", cursor: 0 }, call));
115
+ await pair();
116
+ results.terminal_close = success(rooms.roomCloseAtTerminal(roomId as R.RoomId));
117
+ results.terminal_closed_view = success(await wait(b, 0));
118
+ await pair();
119
+ db().prepare("UPDATE rooms SET expires_at = ? WHERE id = ?").run(at, roomId);
120
+ results.expired = success(await wait(b, 0));
121
+ for (const [key, reason] of [["agreement", "agreement"], ["crux", "crux"], ["turn_limit", "turn_limit"], ["member_close", "closed"], ["terminal_closed_view", "closed"], ["expired", "expired"]]) {
122
+ const ended = results[key] as R.RoomCloseResult;
123
+ assert.equal(ended.state, "ended"); assert.equal(ended.next, null); assert.equal(ended.ending.reason, reason);
124
+ }
125
+ await pair();
126
+ results.wait_turn_refusal = await wait(a, 0);
127
+ assert.ok("refused" in results.wait_turn_refusal && "messages" in results.wait_turn_refusal);
128
+ for (let n = 1; n < R.ROOM_READS_PER_SECOND; n++) success(await rooms.roomTranscript(a, { action: "transcript", cursor: 0 }, call));
129
+ results.read_rate_refusal = await wait(a, 0);
130
+ assert.deepEqual(results.read_rate_refusal, { refused: true, reason: "Refused: room limit reached: ROOM_READS_PER_SECOND; retry after 2026-11-11T18:00:01.000Z." });
131
+ // Revision 3: a conversation's open, on the person's yes in its host's prompt. Random ids and
132
+ // the invite are replaced by placeholders; the shape and every word around them are pinned.
133
+ for (const table of ["room_messages", "room_invites", "room_bindings", "room_members", "rooms"]) db().prepare(`DELETE FROM ${table}`).run();
134
+ rooms.resetRoomOpenRequestsForTests();
135
+ const opener = newInstance({ kind: "root" }, tmp, "codex");
136
+ const opened = success(await rooms.roomOpen(opener, { action: "open" }, call, { ask: async () => "yes", authorized: () => true, deliver: () => true }));
137
+ const placeholders = (text: string) => text
138
+ .replace(new RegExp(opened.room_id, "g"), "rm_<room>").replace(new RegExp(opened.member_id, "g"), "m_<member-1>")
139
+ .replace(new RegExp(opened.peer.member_id, "g"), "m_<member-2>").replace(/ri1_[0-9a-f]{32}/g, "ri1_<invite>");
140
+ results.opened = JSON.parse(placeholders(JSON.stringify(opened)));
141
+ const refusedOpen: Record<string, unknown> = {};
142
+ for (const answer of ["declined", "cancelled", "timed_out", "unverified", "unavailable"] as const) {
143
+ refusedOpen[answer] = await rooms.roomOpen(newInstance({ kind: "root" }, tmp, "codex"), { action: "open" }, call, { ask: async () => answer, authorized: () => true, deliver: () => true });
144
+ }
145
+ refusedOpen.no_prompt = await rooms.roomOpen(opener, { action: "open" }, call, null);
146
+ refusedOpen.clipboard_failed = await rooms.roomOpen(newInstance({ kind: "root" }, tmp, "codex"), { action: "open" }, call, { ask: async () => "yes", authorized: () => true, deliver: () => false });
147
+ refusedOpen.bound = await rooms.roomOpen(opener, { action: "open" }, call, { ask: async () => "yes", authorized: () => true, deliver: () => true });
148
+ results.open_refusals = refusedOpen;
149
+ snapshot("room.json", results);
150
+ } finally {
151
+ t.mock.restoreAll();
152
+ closeDbForTests();
153
+ if (saved === undefined) delete process.env.RELAY_HOME; else process.env.RELAY_HOME = saved;
154
+ fs.rmSync(tmp, { recursive: true, force: true });
155
+ }
156
+ });
157
+
34
158
  test("stable surfaces: Gemini jobs and threads withhold native resume and explain the confined continuation", () => {
35
159
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "relay-resume-surface-"));
36
160
  const saved = process.env.RELAY_HOME;
@@ -130,7 +254,7 @@ test("stable surfaces: CLI usage, version aliases and misuse status", () => {
130
254
  for (const alias of ["--version", "-v", "version"]) {
131
255
  const r = spawnSync(process.execPath, [CLI, alias], { encoding: "utf8" });
132
256
  assert.equal(r.status, 0);
133
- assert.equal(r.stdout, "relay 1.2.2\n");
257
+ assert.equal(r.stdout, "relay 1.3.1\n");
134
258
  }
135
259
  const bad = spawnSync(process.execPath, [CLI, "unknown-command"], { encoding: "utf8" });
136
260
  assert.equal(bad.status, 2);
@@ -43,7 +43,7 @@ for (const mode of ["local", "stage2"] as const) test(`WP4: ${mode} reservation
43
43
  finishLaunchReservation(f.run, id, { clean: true });
44
44
  assert.equal(overlayInterlock(other), null);
45
45
  assert.equal(launchReservationProblem(f.run), null);
46
- assert.equal((db().prepare("PRAGMA user_version").get() as any).user_version, 4);
46
+ assert.equal((db().prepare("PRAGMA user_version").get() as any).user_version, 5);
47
47
  } finally { f.close(); }
48
48
  });
49
49