@mrciphersmith/roomyx 0.5.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -4,9 +4,341 @@ Notable changes to `@mrciphersmith/roomyx`. Generated release notes say what
4
4
  changed; this file exists for the two things they cannot say — **why**, and
5
5
  **what to do if you were relying on the old behaviour**.
6
6
 
7
- Format loosely follows [Keep a Changelog](https://keepachangelog.com). Versions
8
- are [semantic](https://semver.org), with the `0.x` convention that breaking
9
- changes land in the minor position.
7
+ Format loosely follows [Keep a Changelog](https://keepachangelog.com).
8
+
9
+ **Versioning:** in `0.x` the minor position is the breaking position, and the
10
+ patch position carries everything else — bug fixes *and* backward-compatible
11
+ additions. That is what `^0.6.0` already promises a consumer: it receives every
12
+ patch and never a minor. The rule, the reason, and an audit of the four of seven
13
+ releases that followed it are in
14
+ [`docs/roomyx/versioning.md`](docs/roomyx/versioning.md) and decision D-13.
15
+
16
+ ## [0.6.1] — 2026-09-10
17
+
18
+ **A patch, and the first release numbered by the rule rather than by feel.**
19
+ Nothing here is breaking — no export, command, flag or tool parameter is gone,
20
+ no default changed under a caller — so it takes the patch position and every
21
+ `^0.6.0` dependant gets it automatically. Under the old habit this would have
22
+ been `0.7.0`, which would have reached nobody without a manual bump. See
23
+ [`docs/roomyx/versioning.md`](docs/roomyx/versioning.md) and D-13.
24
+
25
+ Everything below is a defect that 0.6.0's own fixes introduced, or a
26
+ verification claim about them that turned out to be false. Both classes were
27
+ found by review rounds run *against the fixes* rather than against the code
28
+ they fixed — the class that is systematically under-found, because a fix
29
+ arrives framed as an answer and gets read as one. Full record in
30
+ [`docs/roomyx/fix-round-2026-09-09.md`](docs/roomyx/fix-round-2026-09-09.md).
31
+
32
+ ### Fixed — regressions 0.6.0 introduced
33
+
34
+ - **`roomyx mcp` worked once and then went dead.** The idle session sweeper
35
+ reasoned from roomyx's own TUI, which polls every second, and applied that to
36
+ clients whose next call comes when a model decides to. Measured: connect, call
37
+ a tool, idle 95 seconds, and the next call fails permanently — the SDK client
38
+ never clears its session id on a 404 and never re-initialises. Eviction is
39
+ one-way, so the window now means *certainly* gone, not probably.
40
+ - **A persistent tool error was appended to the transcript once per poll** —
41
+ about eighty identical lines a minute, each allocating a renderable that was
42
+ never freed, which is the pool exhaustion 0.6.0 fixed elsewhere arriving
43
+ through a different door. Reported once per distinct message now.
44
+ - **A request carrying no session id still minted an untracked transport.** The
45
+ 404 added in 0.6.0 closed the half where a *wrong* id was supplied and the
46
+ comment claimed both. (The unbounded memory growth this was filed under does
47
+ not reproduce — 400 such requests retain the same heap either way. The
48
+ mechanism was real; the leak was not.)
49
+ - **A stopped client could not be restarted.** `stop()` cancelled the pending
50
+ reconnect but left the handle set, and that handle is the single-flight token.
51
+ - **Every transcript export was refused in a container with no working
52
+ directory.** The containment check compared a value to the expression that had
53
+ produced it, and its other half inverted at the filesystem root — so the
54
+ message said the working directory had been escaped when nothing had.
55
+
56
+ ### Fixed — the rest of the review
57
+
58
+ - `--acknowledge-non-loopback` binds a host the rebinding guard will now accept.
59
+ It bound the address and then refused every request arriving at it.
60
+ - The unknown-session 404 is Host- and Origin-checked like every other response.
61
+ - `roomyx.rooms.list` no longer prunes the registry, so the MCP surface only
62
+ reads. It is a network-triggered write with a load-sensitive 500 ms probe
63
+ behind it.
64
+ - Liveness identifies the room. `room.get_state` carries `log_path` and the
65
+ probe compares it, so a recycled port can no longer resurrect a dead room. A
66
+ server without the field is treated as *not shown to be a different room*,
67
+ because wrongly pruning a live room costs more than keeping a stale one.
68
+ - `roomyx init` no longer clobbers a hand-edited staged skill; the duplicate
69
+ `ManagementServeOptions` is gone; `--toString` is refused like any other
70
+ unknown flag; the search counter no longer prints `0/N`.
71
+
72
+ ### Fixed — tests that were not holding what they claimed
73
+
74
+ Found by mutation: remove the fix, require the test to fail.
75
+
76
+ - The first-message fix, the client's shutdown ordering, the roster
77
+ skip-rebuild, the client's session release, and the server's shutdown
78
+ re-entry guard **all survived their own deletion** with the suite green. Each
79
+ is pinned now, and each pin was itself checked by mutation.
80
+ - Two testable units came out of code no test could reach — `runClient` and
81
+ `cli.ts` both refuse to be imported — so the ordering and the re-entry guard
82
+ are asserted directly rather than inferred from a subprocess.
83
+ - A raw NUL byte made one test file binary to git and invisible to ripgrep, so
84
+ the project's own mandated search path reported a fix as untested.
85
+ - Fixed sleeps standing in for conditions are predicate waits, through one
86
+ shared helper. The four that remain are two hang detectors and two assertions
87
+ about absence, where a duration is the right instrument.
88
+
89
+ ### Known
90
+
91
+ - **Neither reconnect mechanism is pinned by a test.** The generation counter
92
+ and the single-flight check can both be deleted with the suite green, and the
93
+ test written to close that gap does not: the full pre-fix shape passes it. It
94
+ is kept for a cheap invariant and labelled in its own header as *not* a
95
+ barrier, because a test that reads as one and is not is worse than none.
96
+
97
+ ## [0.6.0] — 2026-09-09
98
+
99
+ Two passes over the published 0.5.0: running it by hand and putting ten
100
+ screenshots of it in front of four reviewers, then a nine-reviewer read of the
101
+ whole repository. The first produced the TUI work below; the second produced
102
+ three blockers and thirteen major defects, and its report is
103
+ [`docs/roomyx/review-2026-09-09.md`](docs/roomyx/review-2026-09-09.md).
104
+
105
+ **The version is minor rather than patch because several things are breaking**,
106
+ which in `0.x` is where breaking changes go. `Enter` filters the stream instead
107
+ of opening a modal and `AgentModal` is deleted; `roomyx.skills.sync` over MCP no
108
+ longer takes `yes` or `dryRun`; `syncSkill` now refuses to write unless asked,
109
+ so an embedder that relied on the old default gets a refusal rather than a
110
+ file; and `RoomClient` loses `getAgentDetail` and `getLastSeenSeq`, `Footer`
111
+ loses `setWidth`.
112
+
113
+ **If you are on 0.5.0 or earlier, upgrade.** Three of the defects below cost
114
+ data or a session: a mistyped `--kind` makes a room unreadable forever, an idle
115
+ attached client dies of its own accord in about 2.7 hours, and one malformed log
116
+ line turns a client into a request storm.
117
+
118
+ ### Added
119
+
120
+ - **The transcript scrolls, and the arrows belong to it.** `↑`/`↓` by a line,
121
+ `PgUp`/`PgDn` by a page, `Ctrl-U`/`Ctrl-D` by a half, `g`/`G` to the top and
122
+ back to the bottom. The roster keeps its selection on `j`/`k`.
123
+
124
+ Before this, no key scrolled anything: the arrows moved the roster, so four
125
+ keypresses on a room taller than the pane moved one caret and left the stream
126
+ apparently frozen. A room that outgrew its pane could not be read back at
127
+ all.
128
+
129
+ **`:` opens the owner prompt.** `o` means *open* nearly everywhere and was
130
+ borrowed rather than chosen. It still works and is not documented, so a habit
131
+ from 0.5.0 does not break on upgrade.
132
+
133
+ The keymap is now data in `src/client/keymap.ts` rather than an `else if`
134
+ chain inside the keypress handler — which is how it could be wrong without
135
+ being visibly wrong, since there was no artefact anyone could read to answer
136
+ "what keys does this have?". A test asserts no two bindings claim the same
137
+ key, because a first-match-wins resolver silently shadows the loser.
138
+
139
+ - **A footer, generated from that keymap.** Keys on the right, liveness on the
140
+ left — and the liveness is a fact that *moves*: a message count and the age
141
+ of the newest message. A word that has always said the same thing stops being
142
+ read, which is precisely why a dead room looked like a live one; the header
143
+ differed from a working room by one word in the same ink. When the number
144
+ stops, the silence means something.
145
+
146
+ An empty room now says `connected · waiting for the first message` rather
147
+ than showing a void that reads as a hang. Scroll away from the bottom and the
148
+ footer says so and says how to return. On a terminal too narrow for
149
+ everything, hints drop one at a time by usefulness — the first version
150
+ dropped all of them at once, which took the keys away in the two states that
151
+ most need them.
152
+
153
+ Shipped in the same change as the rebind on purpose. A footer is a keymap's
154
+ confession: shipping it first would have printed `↑/↓ roster` on the screen
155
+ as documented behaviour, and made the correction more expensive.
156
+
157
+ - **The transcript has a hierarchy.** A message is a bright speaker name with a
158
+ dim `kind re #n` tag beside it, and the body indented underneath in a dimmer
159
+ ink, with a blank line between turns. Consecutive turns from one speaker
160
+ share a header — a real room had the same nine-character prefix nine times
161
+ running, which hides the one thing a header is for.
162
+
163
+ Before this every message was one line, one colour, one weight, and a wrapped
164
+ continuation began at the same column as a new turn, so sixteen messages were
165
+ a single grey wall. The indent is what makes a wrap read as a continuation.
166
+
167
+ It costs vertical space: a turn is three rows where it was one, so fewer
168
+ turns fit on a short terminal. The shared headers pay most of that back in a
169
+ room where people speak in runs.
170
+
171
+ - **The roster gives up its 24 columns below 80.** At 72 columns it was
172
+ spending a third of the terminal on a few short names while the messages
173
+ wrapped to 46. A fixed gutter is also where non-Latin names die — three CJK
174
+ characters are six cells, not three. Below the breakpoint the stream takes
175
+ the full width and the footer says how many participants are in the room;
176
+ widen the terminal and the list comes back.
177
+
178
+ - **Search, with `/` and `n`/`N`.** Matched case-insensitively against what is
179
+ on screen — the speaker's display name, the kind tag and the body — so
180
+ searching for `Ann` finds messages headed `Ann` rather than every message
181
+ from the id `a`. The footer names the live query and the match position, and
182
+ says `no matches` rather than standing still, because a search that finds
183
+ nothing must not look like one that found something.
184
+
185
+ - **`?` shows the full keymap,** generated from the same table the dispatcher
186
+ and the footer use. The footer teaches the handful of keys worth permanent
187
+ space; everything else lives here rather than in the source.
188
+
189
+ - **`w` writes what is on screen to a file** and names it. A terminal is a bad
190
+ place to search and a good place to read. It never overwrites — the next free
191
+ numbered name is used — and a filtered view gets its own file.
192
+
193
+ - **Connection changes are written into the transcript, not only the footer.**
194
+ A footer repainted at a fixed row, with the cursor parked in another pane, is
195
+ never spoken by a screen reader and never survives a `tee`. A `— disconnected,
196
+ retrying —` line in the stream lands in speech, in scrollback and in the log
197
+ at once.
198
+
199
+ ### Fixed
200
+
201
+ - **Closing the client no longer dumps a stack trace.** `SIGTERM`/`SIGINT`/
202
+ `SIGHUP` had no handler at all, so killing an attached client tore the
203
+ renderer down underneath a live poll: the poll lost its connection, called
204
+ `handleDisconnect`, and wrote "disconnected" into an already-destroyed text
205
+ buffer — `TextBuffer is destroyed`, ten frames of stack, at someone who just
206
+ closed a window. `q` and Ctrl-C escaped it only because that path happened to
207
+ stop the client first. All four now share one ordered shutdown that stops
208
+ polling before destroying the renderer.
209
+
210
+ - **Long messages are no longer silently cut.** `message-row.ts` set
211
+ `height: 1` with no wrapping, so every message was clipped at the pane width
212
+ with no ellipsis and nothing to scroll — and what got cut was the end of the
213
+ sentence, which in a room of arguing agents is where the claim is. Bodies now
214
+ wrap on word boundaries.
215
+
216
+ - **`kind` and `in_reply_to` are displayed.** Both are in `MessageEnvelope` and
217
+ both were written by the dispatcher and rendered by nothing. The
218
+ challenge/answer structure that is the point of the log schema was visible in
219
+ the log and invisible in the viewer of that log. Rows now read
220
+ `Ann [challenge re #1]: …`.
221
+
222
+ - **A pane holding its first messages before its first layout pass no longer
223
+ drops message 1.** The horizontal scrollbar occupies a viewport row whether
224
+ or not there is anything to scroll, leaving `maxScrollTop` at 1 on a pane
225
+ that is not full, so sticky-bottom scrolled down by one.
226
+
227
+ Narrower than [the backlog][backlog] claims, and that correction is recorded
228
+ there: the real client always paints a `[connecting…]` frame before its first
229
+ poll returns, so it never triggered this. No 0.4.0 or 0.5.0 user lost a
230
+ message to it. Fixed because it is one line and a trap for whoever later
231
+ makes the client paint after its first batch rather than before.
232
+
233
+ ### Fixed — from the full-repository review
234
+
235
+ A nine-reviewer pass over `src` and `test` found three blockers and thirteen
236
+ major defects; the report is [`docs/roomyx/review-2026-09-09.md`](docs/roomyx/review-2026-09-09.md)
237
+ and the work is flow 001. Every fix below was reproduced before and verified as
238
+ a regression barrier after — the fix is removed again and the test is required
239
+ to fail.
240
+
241
+ - **`roomyx room append` could make a room unreadable forever.** The reader
242
+ validated with zod; the writer had only TypeScript types, erased at the CLI
243
+ boundary where `--kind` was cast. `--kind bogus-kind` exited 0, wrote the
244
+ line, and every later read of that room threw — on an append-only log with no
245
+ repair command, while `serve` kept binding and `rooms list` kept calling the
246
+ room live. One schema, in `src/log/schema.ts`, is now imported by both
247
+ directions.
248
+
249
+ - **An idle attached client killed itself in about 2.7 hours.** `remove()` in
250
+ `@opentui/core` unlinks without freeing, and the roster was rebuilt on every
251
+ three-second state poll whether or not it had changed: five leaked renderables
252
+ a poll against a finite native pool. Detached rows are destroyed, and an
253
+ unchanged roster is not rebuilt.
254
+
255
+ - **One malformed log line turned a client into a request storm.** `callTool`
256
+ never read `isError`, so a tool error was indistinguishable from a dropped
257
+ transport, and each failing poll scheduled its own reconnect without stopping
258
+ the running loops — 510 connections in ten seconds, measured. Tool errors now
259
+ reach the transcript and the poll continues; reconnect is single-flight with a
260
+ generation counter and backs off to 30s.
261
+
262
+ - **`roomyx serve` would not exit on a signal while a client was attached** —
263
+ the normal state of a served room. The code that ended the connections sat
264
+ inside the callback that waits for them. Sessions close first,
265
+ `closeAllConnections()` bounds it, `SIGHUP` is handled, and deregistration
266
+ happens after the close rather than before, so a hung shutdown can no longer
267
+ hide a still-served room from the registry.
268
+
269
+ - **Concurrent `room append` produced duplicate `seq` values.** `seq` is the
270
+ transcript cursor, so a client polling between two colliding writes never
271
+ received the second message. The lockfile that had guarded the registry for
272
+ three rounds now guards the data too.
273
+
274
+ - **MCP sessions were never released.** Nothing sent the DELETE the SDK needs,
275
+ so every session a server ever accepted was retained — and stayed routable.
276
+ The client terminates its sessions, an unknown session id gets 404 instead of
277
+ a new transport, and an idle sweeper closes what a crashed client could not.
278
+
279
+ - **A roster id could direct the transcript export outside the working
280
+ directory** while the status bar reported otherwise. The id is sanitised and
281
+ the resolved path is checked against `cwd`.
282
+
283
+ - **`roomyx.skills.sync` over MCP wrote without the gate its own CLI help
284
+ promises.** `yes` and `dryRun` are off that tool's schema; the gate lives in
285
+ `syncSkill`, computed once and failing closed.
286
+
287
+ - **A dead room could be resurrected by a recycled port.** `isRoomLive` proved
288
+ only that something answered; the pid in the registry was never read. It is
289
+ now checked first.
290
+
291
+ - **The help overlay drew into its own border below 20 rows** — the clamp added
292
+ while fixing its height reintroduced the defect it fixed. It fits whatever
293
+ height it is given, and the `? or Esc closes` line is never what gets dropped.
294
+
295
+ - **A participant name of 23 characters rendered an empty roster row.** Word
296
+ wrapping moved it to a line that `height: 1` clipped, so the whole word
297
+ vanished while `j`/`k` still moved onto the row. Labels are clipped with a
298
+ marker.
299
+
300
+ - **Three regression tests no longer failed when their fix was removed.** Found
301
+ by mutation, restored the same way: the scrollbar fix is pinned at the
302
+ boundary heights where content exactly fills the pane, and the shutdown
303
+ ordering moved out of `runClient` — which no test can reach — into a unit that
304
+ asserts the order directly.
305
+
306
+ ### Known
307
+
308
+ - **A word ending exactly at the wrap column loses its last character** —
309
+ `whether scrolling or` draws as `whether scrollin` / `or`, with the `g` gone
310
+ rather than wrapped. Width-dependent: 120 columns is clean, 90 is not. Not
311
+ worked around, on purpose: a one-column right margin makes it disappear at
312
+ 60, 72, 108 and 120 and leaves it at 90, which would turn a reproducible
313
+ defect into an intermittent one. `test/client/wrap-defect.test.ts` holds the
314
+ reproduction as a tripwire that starts failing the day it is fixed upstream.
315
+
316
+ - **Nothing responds to a terminal resize.** Every dimension is read once at
317
+ construction, so a resized terminal leaves the footer off-screen, `PgUp`
318
+ overshooting, and the roster breakpoint stuck at its old answer. Deferred
319
+ deliberately: it is a feature rather than a repair, and it should land with
320
+ the display-cell width arithmetic below, which needs the same primitive.
321
+
322
+ - **The footer measures code units and calls them columns**, so a CJK
323
+ participant name eats the key hints — including the only on-screen statement
324
+ of how to quit. Deferred with the resize work for the same reason.
325
+
326
+ - **`room.get_transcript` has no `limit`,** and its consumer on the management
327
+ path is a language model: a cold attach at `since_seq: 0` is the whole log in
328
+ one block. A protocol change deserving a decision record, not a patch inside a
329
+ fix flow.
330
+
331
+ ### Fixed (continued)
332
+
333
+ - **`room append`'s refusal no longer asks you to assert something false.** It
334
+ ended "Pass `--force` if you know it isn't" — but the ordinary way to meet
335
+ that message is a room served by bare `roomyx serve`, which is genuinely live
336
+ and simply has no dispatcher, so there is no second writer to race. The
337
+ registry records that a room serves a path, not whether anything dispatches
338
+ into it, so the message now says what is known and leaves the judgement to
339
+ the operator.
340
+
341
+ [backlog]: docs/roomyx/improvement-backlog.md
10
342
 
11
343
  ## [0.5.0] — 2026-09-09
12
344
 
@@ -66,6 +398,19 @@ The security release. Every item here came out of a review of the published
66
398
  did-you-mean, missing and non-numeric values are refused, `--help` exits 0 on
67
399
  stdout, a bad command exits 1 on stderr, and `--` ends flag parsing.
68
400
 
401
+ ### Changed — breaking
402
+
403
+ - **`Enter` filters the stream instead of opening a modal, and the modal is
404
+ gone.** `AgentModal` could not be scrolled, did not compose with search, cost
405
+ a keypress to leave, and was pinned at `top: 2, left: 2` — so, being 70% of
406
+ the terminal wide, it lay across the roster it had been opened from and left
407
+ a selection arrow pointing at a name it had covered.
408
+
409
+ Filtering shows the same data from the transcript the client already has, in
410
+ the pane the reader is already in, and `Esc` clears it. The server's
411
+ `agent.detail` tool is unchanged; the client no longer needs it to answer
412
+ "show me this participant".
413
+
69
414
  ### Removed — breaking
70
415
 
71
416
  - **`roomyx.skills.sync` no longer accepts `targetPath`.** The MCP tool took a
package/README.md CHANGED
@@ -58,11 +58,46 @@ roomyx-client # auto-attaches when exactly one room is live
58
58
  roomyx-client --room r-a1b2c3
59
59
  ```
60
60
 
61
- In the TUI: `↑`/`↓` move through the roster, `Enter` opens the selected agent's
62
- modal, `Esc` closes it, `q` or `Ctrl-C` quits. `o` opens an owner command —
63
- pick `v`eto, `c`onstraint, `a`dd participant or `g`oal edit, type the body,
64
- `Enter` sends. While the prompt is open it owns the keyboard, so a `q` in a
65
- veto is text rather than a quit.
61
+ In the TUI, the transcript owns the arrows and the roster has its own keys:
62
+
63
+ | Key | |
64
+ | --- | --- |
65
+ | `↑` `↓` | scroll the transcript a line |
66
+ | `PgUp` `PgDn` | scroll a page; `Ctrl-U` / `Ctrl-D` a half page |
67
+ | `g` `G` | jump to the top, or back to following the newest message |
68
+ | `j` `k` | move the roster selection |
69
+ | `Enter` | filter the stream to the selected participant; `Esc` clears |
70
+ | `/` | search, then `n` / `N` for next and previous match |
71
+ | `:` | owner command — then `v`eto, `c`onstraint, `a`dd participant or `g`oal edit, type the body, `Enter` sends |
72
+ | `w` | write what is on screen to a file in the working directory |
73
+ | `?` | the full keymap |
74
+ | `q` `Ctrl-C` | quit |
75
+
76
+ Selecting a participant filters the stream where it is rather than opening a
77
+ window over it, so the filter composes with scrolling and with search, and
78
+ leaving it is `Esc` rather than a mode you have to remember you are in. A live
79
+ filter or search is named in the footer — a filter that is on but invisible
80
+ makes a busy room look like a quiet one.
81
+
82
+ `w` exists because a terminal is a bad place to search and a good place to
83
+ read. It never overwrites: the next free numbered name is used, and a filtered
84
+ view gets its own file.
85
+
86
+ The bottom line carries the same keys, so nothing here has to be memorised, and
87
+ next to them the room's liveness: a message count and the age of the newest
88
+ message, or a `DISCONNECTED` that stays put. Scroll away from the bottom and it
89
+ tells you so, and tells you how to get back.
90
+
91
+ While the owner prompt is open it owns the keyboard, so a `q` in a veto is text
92
+ rather than a quit.
93
+
94
+ Below 80 columns the roster gives up its gutter to the transcript and the
95
+ footer carries the participant count instead; widen the terminal and the list
96
+ comes back.
97
+
98
+ Up to 0.5.0 the arrows moved the roster and nothing scrolled at all, `o` opened
99
+ the owner prompt, and `Enter` opened a modal window over the roster. `o` still
100
+ works, so a habit does not break on upgrade, but `:` is the documented key.
66
101
 
67
102
  ## Commands
68
103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/roomyx",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "MCP server + terminal UI for startup-room: live room status, chat, per-agent modal, an installable room registry, and skill-sync.",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/cli/args.ts CHANGED
@@ -98,7 +98,12 @@ export function parseArgs(argv: string[], specs: FlagSpecs): ParsedArgs {
98
98
  continue;
99
99
  }
100
100
 
101
- const spec = specs[name];
101
+ // `specs[name]` resolves through the prototype chain, so `--toString`,
102
+ // `--constructor`, `--valueOf`, `--hasOwnProperty` and `--__proto__` all
103
+ // found a truthy spec, skipped the refusal below, and consumed the next
104
+ // argv token as a value — the module's stated invariant failing for exactly
105
+ // the shape of input it exists to catch.
106
+ const spec = Object.hasOwn(specs, name) ? specs[name] : undefined;
102
107
  if (!spec) {
103
108
  const hint = suggest(name, known);
104
109
  throw new ArgError(
package/src/cli.ts CHANGED
@@ -2,10 +2,13 @@
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { join, resolve } from "node:path";
4
4
  import { serve } from "./server/serve";
5
+ import { createServerShutdown } from "./server/shutdown";
5
6
  import { init } from "./installer/init";
6
7
  import { registerRoom, deregisterRoom, listLiveRooms } from "./installer/registry";
7
8
  import { syncSkill } from "./installer/skill-sync";
8
- import { appendMessage, createRoomLog, parseRoster } from "./log/write";
9
+ import { appendMessage, createRoomLog, LEGAL_KINDS, parseRoster } from "./log/write";
10
+ import { MESSAGE_KINDS } from "./log/schema";
11
+ import type { MessageEnvelope } from "./log/types";
9
12
  import { NAMED_TARGETS, resolveTargets } from "./installer/skill-targets";
10
13
  import { serveManagement } from "./mcp-management/server";
11
14
  import { ArgError, parseArgs, renderFlags } from "./cli/args";
@@ -37,6 +40,26 @@ function bundledSkillPath(): string {
37
40
 
38
41
  const REGISTRY_FLAG = { type: "string", describe: "Registry file (default .roomyx/rooms/registry.json)" } as const;
39
42
 
43
+ /**
44
+ * Wires the signals. The shutdown itself lives in `./server/shutdown`, where a
45
+ * test can reach it — this module runs its entry point on import.
46
+ *
47
+ * Written once because there were three copies and they had drifted: the two
48
+ * here handled SIGINT and SIGTERM and guarded nothing, while the client handled
49
+ * SIGHUP as well and guarded re-entry. So closing a terminal (SIGHUP) killed
50
+ * `roomyx serve` outright, skipping deregistration and leaving a stale registry
51
+ * entry — which a recycled port then resurrects as a live room.
52
+ *
53
+ * `cleanup` runs *after* the close resolves, not before. Deregistering first
54
+ * meant a shutdown that hung — and it hung whenever a client was attached —
55
+ * removed the room from the registry while the process kept running and kept
56
+ * the port. The room became invisible while still being served.
57
+ */
58
+ function runUntilSignal(close: () => Promise<void>, cleanup: () => void = () => undefined): void {
59
+ const shutdown = createServerShutdown(close, cleanup);
60
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.on(signal, shutdown);
61
+ }
62
+
40
63
  interface Command {
41
64
  usage: string;
42
65
  summary: string;
@@ -88,7 +111,7 @@ const COMMANDS: Record<string, Command> = {
88
111
  usage: "roomyx room append <path> --from <id> --body <text> [flags]",
89
112
  summary: "append a message to a room log",
90
113
  notes:
91
- "Refuses when a live room is serving that log: its dispatcher is the\n single writer (D-01a). --force overrides if you know the room is gone.",
114
+ "Refuses when a live room is serving that log: if that room has a\n dispatcher, the dispatcher is the single writer (D-01a). --force appends\n anyway — a room served by bare `roomyx serve` has no dispatcher to race.",
92
115
  flags: {
93
116
  from: { type: "string", describe: "Required. Participant id" },
94
117
  body: { type: "string", describe: "Required. The message" },
@@ -111,17 +134,41 @@ const COMMANDS: Record<string, Command> = {
111
134
  const registryPath = typeof flags.registry === "string" ? flags.registry : defaultRegistryPath();
112
135
  const serving = (await listLiveRooms(registryPath)).find((room) => room.logPath === absolute);
113
136
  if (serving) {
137
+ // The old wording ended "Pass --force if you know it isn't" — it asked
138
+ // the operator to assert the room is gone. But the common case for
139
+ // reaching this message is a room served by bare `roomyx serve`, where
140
+ // the room is genuinely live and simply has no dispatcher attached, so
141
+ // there is no second writer to race. The flag was the right escape
142
+ // hatch behind a claim that was false exactly when you needed it.
143
+ //
144
+ // roomyx cannot tell the two apart: the registry records that a room
145
+ // serves this path, not whether anything is dispatching into it. So
146
+ // say what is known and let the operator judge, rather than making
147
+ // --force mean something untrue.
114
148
  throw new ArgError(
115
- `A live room (${serving.id}) is serving this log; its dispatcher is the single writer (D-01). Pass --force if you know it isn't.`,
149
+ `A live room (${serving.id}) is serving this log. If it has a dispatcher, that dispatcher is the log's single writer (D-01a) and appending here races it. Pass --force to append anyway.`,
116
150
  );
117
151
  }
118
152
  }
119
153
 
154
+ // Refused here, in the grammar, so the error names the flag the operator
155
+ // typed rather than a field name from the on-disk schema. `appendMessage`
156
+ // validates too — that is the guard that cannot be bypassed — but a
157
+ // message about `--kind` belongs to the CLI that owns the flag.
158
+ const kind = typeof flags.kind === "string" ? flags.kind : undefined;
159
+ if (kind !== undefined && !(MESSAGE_KINDS as readonly string[]).includes(kind)) {
160
+ throw new ArgError(`Unknown --kind "${kind}". Known kinds: ${LEGAL_KINDS}.`);
161
+ }
162
+ const inReplyTo = typeof flags["in-reply-to"] === "number" ? flags["in-reply-to"] : undefined;
163
+ if (inReplyTo !== undefined && (!Number.isInteger(inReplyTo) || inReplyTo < 1)) {
164
+ throw new ArgError(`--in-reply-to must be a whole number of at least 1, not ${inReplyTo}.`);
165
+ }
166
+
120
167
  const message = appendMessage(absolute, {
121
168
  from,
122
169
  body,
123
- kind: typeof flags.kind === "string" ? (flags.kind as never) : undefined,
124
- inReplyTo: typeof flags["in-reply-to"] === "number" ? flags["in-reply-to"] : undefined,
170
+ kind: kind as MessageEnvelope["kind"],
171
+ inReplyTo,
125
172
  });
126
173
  console.log(`Appended seq ${message.seq} from ${message.from}.`);
127
174
  },
@@ -160,12 +207,10 @@ const COMMANDS: Record<string, Command> = {
160
207
  console.log(`roomyx serving ${absoluteLogPath} at ${handle.url}`);
161
208
  console.log(`room ID: ${entry.id} — attach with \`roomyx-client --room ${entry.id}\``);
162
209
 
163
- const shutdown = () => {
164
- deregisterRoom(registryPath, entry.id);
165
- void handle.close().then(() => process.exit(0));
166
- };
167
- process.on("SIGINT", shutdown);
168
- process.on("SIGTERM", shutdown);
210
+ runUntilSignal(
211
+ () => handle.close(),
212
+ () => deregisterRoom(registryPath, entry.id),
213
+ );
169
214
  },
170
215
  },
171
216
 
@@ -228,11 +273,7 @@ const COMMANDS: Record<string, Command> = {
228
273
  console.log(`roomyx mcp listening at ${handle.url}`);
229
274
  console.log("tools: roomyx.rooms.list, roomyx.skills.sync");
230
275
 
231
- const shutdown = () => {
232
- void handle.close().then(() => process.exit(0));
233
- };
234
- process.on("SIGINT", shutdown);
235
- process.on("SIGTERM", shutdown);
276
+ runUntilSignal(() => handle.close());
236
277
  },
237
278
  },
238
279
 
@@ -254,7 +295,9 @@ const COMMANDS: Record<string, Command> = {
254
295
  }
255
296
 
256
297
  const yes = flags.yes === true;
257
- const dryRun = flags["dry-run"] === true || !yes;
298
+ // The gate itself lives in `syncSkill` now, computed once for every
299
+ // surface — this line only forwards what the operator typed.
300
+ const dryRun = flags["dry-run"] === true;
258
301
  const configPath = typeof flags.config === "string" ? flags.config : defaultConfigPath();
259
302
  if (!existsSync(configPath)) {
260
303
  throw new ArgError(`No ${configPath}. Run \`roomyx init\` first.`);
@@ -273,7 +316,12 @@ const COMMANDS: Record<string, Command> = {
273
316
  if (result.written) {
274
317
  console.log(result.backedUpTo ? ` written (backup: ${result.backedUpTo})` : " written");
275
318
  } else {
276
- console.log(dryRun ? " would write (pass --yes to apply)" : " not written");
319
+ // "not written" was the message whenever `dryRun` was false, which
320
+ // after the gate moved into syncSkill meant the ordinary
321
+ // no-flags run reported a bare refusal instead of the sentence that
322
+ // says how to proceed. Branch on why nothing was written, not on
323
+ // which flag was passed.
324
+ console.log(result.wouldWrite ? " would write (pass --yes to apply)" : " not written");
277
325
  }
278
326
  }
279
327
  },
@@ -303,7 +351,7 @@ function topLevelHelp(): string {
303
351
  ].join("\n");
304
352
  }
305
353
 
306
- function commandHelp(name: string, command: Command): string {
354
+ function commandHelp(command: Command): string {
307
355
  const table = renderFlags(command.flags);
308
356
  return [
309
357
  command.usage,
@@ -345,7 +393,7 @@ async function main(): Promise<void> {
345
393
 
346
394
  const parsed = parseArgs(matched.rest, matched.command.flags);
347
395
  if (parsed.help) {
348
- console.log(commandHelp(matched.name, matched.command));
396
+ console.log(commandHelp(matched.command));
349
397
  return;
350
398
  }
351
399
  await matched.command.run(parsed);
@@ -0,0 +1,53 @@
1
+ import { TextRenderable } from "@opentui/core";
2
+ import type { RenderContext } from "@opentui/core";
3
+ import { footerHints } from "../keymap";
4
+
5
+ /**
6
+ * The bottom line: what the room is doing on the left, what your keys are on
7
+ * the right.
8
+ *
9
+ * Two reviewers arrived at this independently and it closes four separate
10
+ * complaints — an empty room that looked hung, a dead room that looked live, a
11
+ * keymap advertised nowhere, and a scroll position with no indicator. It is
12
+ * deliberately one row: the transcript is the product, and a help panel that
13
+ * costs five rows on a 24-row terminal would be paid for by the thing people
14
+ * came to read.
15
+ *
16
+ * The hints come from the keymap rather than from a string written here, so
17
+ * the footer cannot drift from what the keys actually do.
18
+ */
19
+ export class Footer {
20
+ readonly node: TextRenderable;
21
+ private liveness = "";
22
+ private scrollNote: string | null = null;
23
+ private readonly width: number;
24
+
25
+ constructor(ctx: RenderContext, options: { width: number }) {
26
+ this.width = options.width;
27
+ this.node = new TextRenderable(ctx, { content: "", height: 1 });
28
+ this.render();
29
+ }
30
+
31
+ setLiveness(liveness: string): void {
32
+ this.liveness = liveness;
33
+ this.render();
34
+ }
35
+
36
+ /** Set while the reader has scrolled away from the bottom, null at the bottom. */
37
+ setScrollNote(note: string | null): void {
38
+ this.scrollNote = note;
39
+ this.render();
40
+ }
41
+
42
+ private render(): void {
43
+ const left = this.scrollNote === null ? this.liveness : `${this.liveness} · ${this.scrollNote}`;
44
+ // The left half wins the space it needs — knowing the room is dead matters
45
+ // more than being reminded which key quits — but the hints give way one at
46
+ // a time rather than all at once. The first version dropped every hint the
47
+ // moment the line did not fit, which took them away in exactly the two
48
+ // states that most need them: an empty room, and a scrolled one.
49
+ const right = footerHints(Math.max(0, this.width - left.length - 2));
50
+ const gap = this.width - left.length - right.length;
51
+ this.node.content = right === "" || gap < 2 ? left.slice(0, Math.max(0, this.width)) : `${left}${" ".repeat(gap)}${right}`;
52
+ }
53
+ }