@mrciphersmith/roomyx 0.10.3 → 0.11.0

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
@@ -13,6 +13,46 @@ patch and never a minor. The rule, the reason, and an audit of the four of seven
13
13
  releases that followed it are in
14
14
  [`docs/roomyx/versioning.md`](docs/roomyx/versioning.md) and decision D-13.
15
15
 
16
+ ## [0.11.0] — 2026-09-10
17
+
18
+ A minor, for the reason D-13 gives: `room.get_state` now returns a **changed
19
+ result for a caller who asked for nothing different**. The log format also gained
20
+ an optional field and two message kinds, which is additive on its own.
21
+
22
+ ### Added
23
+
24
+ - **A room's state can change.** `goal_edit` and `add_participant` are message
25
+ kinds carrying the change in a new optional `change` field, and
26
+ `room.get_state` folds them: the header, then every edit in `seq` order, last
27
+ one winning. Before this, a room's state was its first line and nothing else —
28
+ so `goal_edit` and `add_participant` had **nowhere to land**, and
29
+ `updated_in_round` / `updated_by` sat in the schema with nothing writing them
30
+ since the format was defined.
31
+ - `room append --json <envelope>` accepts `change`, so an edit can be posted the
32
+ same way any other message is.
33
+
34
+ ### Notes
35
+
36
+ - **The edit is a message, and that is the point.** The header cannot be
37
+ rewritten (append-only) and cannot be followed by a second one (every line
38
+ after the first must be a message, or the room becomes unreadable forever). A
39
+ message is therefore the only representation available — and because it is a
40
+ message it lands in the transcript, which is where this project already puts
41
+ state changes so a person can see them.
42
+ - **Reading is a fold, never a rewrite.** The file keeps the contract the room was
43
+ created with; bytes and mtime are untouched by any read. A test asserts both.
44
+ - **The body stays prose.** `"raise the pass mark to 85"`, with the structure
45
+ beside it in `change` — a JSON blob in the message pane is unreadable.
46
+ - **An edit kind with no `change` is a valid message that is not an edit**, and
47
+ the fold skips it. Making that ill-formed would have invented a new way for a
48
+ log to become unreadable, which is the one thing this format cannot afford.
49
+ A `change` whose `type` does not match its kind *is* ill-formed and is refused
50
+ by the writer.
51
+ - **Known divergence, recorded rather than fixed:** `archiveRoom` summarises a
52
+ closed room from its header, so `rooms history` shows the goal the room was
53
+ *created* with, not the one it ended with. Deciding which of those the index
54
+ should record is a follow-up.
55
+
16
56
  ## [0.10.3] — 2026-09-10
17
57
 
18
58
  A patch. A new read tool, and no existing response changes.
package/README.md CHANGED
@@ -410,6 +410,38 @@ record; every subsequent line is a `message` record.
410
410
  - `roster` entries are `{ id, name }` — `id` is what `room.get_agent_detail`
411
411
  takes as `agent_id`; `name` is the display name used in `from`.
412
412
 
413
+ ### Edits: how a room's state changes
414
+
415
+ The first line is a room's **original** state and it is never rewritten — the log
416
+ is append-only, and it cannot be followed by a second `state` line either, because
417
+ every line after the first must be a `message`. So an edit is a **message**:
418
+
419
+ ```jsonl
420
+ {"type":"message","seq":5,"from":"owner","kind":"goal_edit","body":"raise the pass mark to 85","change":{"type":"goal_contract","goal_contract":{"version":1,"goal_statement":"...","criteria":"...","threshold":{"fail_below":60,"pass_at_or_above":85}}}}
421
+ {"type":"message","seq":6,"from":"owner","kind":"add_participant","body":"adding Omar","change":{"type":"roster","add":[{"id":"omar","name":"Омар"}]}}
422
+ ```
423
+
424
+ - `change` is **optional**, so every message written by an earlier version still
425
+ validates. It is present only on the two edit kinds, and its `type` must match
426
+ the kind: `goal_edit` carries a `goal_contract`, `add_participant` carries
427
+ `roster`.
428
+ - **What a room reads as** is its first line *folded* with every edit, in `seq`
429
+ order, last one winning. That is what `room.get_state` returns. The file keeps
430
+ the original contract — the fold is an interpretation, never a rewrite — so a
431
+ transcript stays exactly as it was written.
432
+ - An edit is also an ordinary message, so it appears in the transcript: this
433
+ project puts state changes in the transcript as text precisely so a person can
434
+ see what happened, rather than having it land in a record nobody reads.
435
+ - A `goal_edit` with no `change` is a **valid message that simply is not an
436
+ edit** — the fold ignores it, and nothing about it is an error. Whether an edit
437
+ kind *should* carry its change is a rule about applying a message, not about the
438
+ message being well-formed, and an ill-formed line would make a room unreadable
439
+ forever (the log has no repair command). A `change` whose `type` does not match
440
+ its kind **is** ill-formed, and the writer refuses it.
441
+ - The body of an edit is prose (`"raise the pass mark to 85"`), not JSON: the
442
+ transcript is what a person reads, and the structure travels beside it in
443
+ `change`.
444
+
413
445
  This format is this package's own design choice, not dictated by either JSON
414
446
  Schema: the specification defers the on-disk representation to implementation,
415
447
  and the schemas describe one message and one goal contract, not the log file as
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrciphersmith/roomyx",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
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.ts CHANGED
@@ -109,7 +109,7 @@ function bodyFromFile(file: string): string {
109
109
  return raw.replace(/\r?\n$/, "");
110
110
  }
111
111
 
112
- const ENVELOPE_KEYS = ["from", "body", "kind", "in_reply_to"] as const;
112
+ const ENVELOPE_KEYS = ["from", "body", "kind", "in_reply_to", "change"] as const;
113
113
 
114
114
  /**
115
115
  * Parses one envelope, refusing keys that would silently vanish.
@@ -135,7 +135,7 @@ function envelopeFrom(text: string): AppendMessageOptions {
135
135
  throw new ArgError(`--json has an unknown key "${key}". Allowed: ${ENVELOPE_KEYS.join(", ")}.`);
136
136
  }
137
137
  }
138
- const { from, body, kind, in_reply_to: inReplyTo } = envelope;
138
+ const { from, body, kind, in_reply_to: inReplyTo, change } = envelope;
139
139
  if (typeof from !== "string" || from === "") throw new ArgError('--json needs a non-empty "from".');
140
140
  if (typeof body !== "string") throw new ArgError('--json needs a string "body".');
141
141
  if (kind !== undefined && (typeof kind !== "string" || !(MESSAGE_KINDS as readonly string[]).includes(kind))) {
@@ -144,11 +144,20 @@ function envelopeFrom(text: string): AppendMessageOptions {
144
144
  if (inReplyTo !== undefined && (typeof inReplyTo !== "number" || !Number.isInteger(inReplyTo) || inReplyTo < 1)) {
145
145
  throw new ArgError('--json "in_reply_to" must be a whole number of at least 1.');
146
146
  }
147
+ // The change is passed through unexamined here and validated where the rule
148
+ // lives (the log's own schema, imported by the writer). Re-checking its shape
149
+ // in the CLI would be a second copy of a rule the log already owns — and the
150
+ // two copies would drift, which is the failure `src/log/schema.ts` exists to
151
+ // make impossible.
152
+ if (change !== undefined && (typeof change !== "object" || change === null)) {
153
+ throw new ArgError('--json "change" must be an object.');
154
+ }
147
155
  return {
148
156
  from,
149
157
  body,
150
158
  kind: kind as MessageEnvelope["kind"],
151
159
  inReplyTo: inReplyTo as number | undefined,
160
+ change: change as MessageEnvelope["change"],
152
161
  };
153
162
  }
154
163
 
package/src/log/schema.ts CHANGED
@@ -25,8 +25,19 @@ export const MESSAGE_KINDS = [
25
25
  "vote",
26
26
  "status",
27
27
  "research",
28
+ // D-19: the two kinds that change a room's state. The header cannot be
29
+ // rewritten and a second state line makes the room unreadable, so an edit is a
30
+ // message — and because it is a message it is also visible in the transcript,
31
+ // which is where this project already puts state changes.
32
+ "goal_edit",
33
+ "add_participant",
28
34
  ] as const;
29
35
 
36
+ /** The kinds that must carry a `change`, and which change each one means. */
37
+ export const EDIT_KINDS = { goal_edit: "goal_contract", add_participant: "roster" } as const;
38
+
39
+ export type EditKind = keyof typeof EDIT_KINDS;
40
+
30
41
  export const rosterEntrySchema = z.object({ id: z.string(), name: z.string() });
31
42
 
32
43
  export const goalContractSchema = z.object({
@@ -49,11 +60,68 @@ export const stateLineSchema = z.object({
49
60
  roster: z.array(rosterEntrySchema),
50
61
  });
51
62
 
52
- export const messageLineSchema = z.object({
53
- type: z.literal("message"),
54
- seq: z.number().int().min(1),
55
- from: z.string().min(1),
56
- in_reply_to: z.number().int().min(1).optional(),
57
- kind: messageKindSchema.optional(),
58
- body: z.string(),
59
- });
63
+ /**
64
+ * What an edit message changes, as a discriminated payload.
65
+ *
66
+ * It travels in a field of its own rather than in `body` because the transcript
67
+ * is what a person reads: a JSON blob in the message pane is unreadable, and the
68
+ * body of an edit stays a sentence ("raise the pass mark to 85").
69
+ */
70
+ export const messageChangeSchema = z.discriminatedUnion("type", [
71
+ z.object({ type: z.literal("goal_contract"), goal_contract: goalContractSchema }),
72
+ z.object({ type: z.literal("roster"), add: z.array(rosterEntrySchema).min(1) }),
73
+ ]);
74
+
75
+ export type MessageChange = z.infer<typeof messageChangeSchema>;
76
+
77
+ /**
78
+ * The log's message contract, and the one place the edit rule is expressed.
79
+ *
80
+ * D-08 is why the rule lives here rather than in the writer and the reader
81
+ * separately: "a writer whose output its own reader rejects is the thing this
82
+ * module exists to make impossible". The writer refuses on this rule and the fold
83
+ * skips on it — two uses of one rule, not two rules.
84
+ *
85
+ * `change` is optional, which is what keeps the format change additive: every
86
+ * message written by every earlier version still validates.
87
+ */
88
+ export const messageLineSchema = z
89
+ .object({
90
+ type: z.literal("message"),
91
+ seq: z.number().int().min(1),
92
+ from: z.string().min(1),
93
+ in_reply_to: z.number().int().min(1).optional(),
94
+ kind: messageKindSchema.optional(),
95
+ body: z.string(),
96
+ change: messageChangeSchema.optional(),
97
+ })
98
+ .superRefine((message, ctx) => {
99
+ // Shape rules only — deliberately not "an edit kind must carry a change".
100
+ //
101
+ // That rule would make the message *invalid*, and an invalid line makes a room
102
+ // unreadable forever: the log is append-only with no repair command. So a
103
+ // `goal_edit` with no change is a **valid message that simply is not an
104
+ // edit**, and the fold ignores it. Whether an edit kind carries its change is
105
+ // a rule about *applying* a message, not about the message being well-formed,
106
+ // and conflating the two would have invented a new way for a log to die.
107
+ if (message.change === undefined) return;
108
+
109
+ const expected = message.kind === undefined ? undefined : EDIT_KINDS[message.kind as EditKind];
110
+ if (expected === undefined) {
111
+ // A change on an ordinary message will never be applied by anything, so
112
+ // accepting it would let a writer believe it changed state it did not.
113
+ ctx.addIssue({
114
+ code: "custom",
115
+ path: ["change"],
116
+ message: `a "change" requires an edit kind (${Object.keys(EDIT_KINDS).join(", ")}), not "${message.kind ?? "none"}"`,
117
+ });
118
+ return;
119
+ }
120
+ if (message.change.type !== expected) {
121
+ ctx.addIssue({
122
+ code: "custom",
123
+ path: ["change", "type"],
124
+ message: `kind "${message.kind}" carries a "${message.change.type}" change; it must be "${expected}"`,
125
+ });
126
+ }
127
+ });
package/src/log/store.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { messageLineSchema, stateLineSchema } from "./schema";
3
- import type { AgentDelta, AgentDetail, MessageEnvelope, RoomState, RosterEntry } from "./types";
3
+ import type { MessageChange } from "./schema";
4
+ import type { AgentDelta, AgentDetail, GoalContract, MessageEnvelope, RoomState, RosterEntry } from "./types";
4
5
 
5
6
  /**
6
7
  * `JSON.parse`, with the one thing it never says: where.
@@ -56,13 +57,6 @@ export function loadRoomLog(path: string): { state: RoomState; messages: Message
56
57
  );
57
58
  }
58
59
 
59
- const state: RoomState = {
60
- goal_contract: headerResult.data.goal_contract,
61
- roster: headerResult.data.roster,
62
- // The reader knows which file it read; the state header does not carry it.
63
- log_path: path,
64
- };
65
-
66
60
  const messages: MessageEnvelope[] = rest.map((line, index) => {
67
61
  const result = messageLineSchema.safeParse(
68
62
  parseLine(line, () => `Invalid "message" line ${index + 2} in ${path}`),
@@ -75,9 +69,64 @@ export function loadRoomLog(path: string): { state: RoomState; messages: Message
75
69
  return envelope;
76
70
  });
77
71
 
72
+ const state: RoomState = {
73
+ // The header is the room's ORIGINAL contract and the base every edit is
74
+ // applied to; it is never reinterpreted as one of them.
75
+ ...foldEdits({ goal_contract: headerResult.data.goal_contract, roster: headerResult.data.roster }, messages),
76
+ // The reader knows which file it read; the state header does not carry it.
77
+ log_path: path,
78
+ };
79
+
78
80
  return { state, messages };
79
81
  }
80
82
 
83
+ /**
84
+ * A room's current state, from its original state and every edit since.
85
+ *
86
+ * The reason this exists at all: a room's state lives in the first line and that
87
+ * line cannot be rewritten (append-only) and cannot be followed by a second one
88
+ * (`loadRoomLog` requires every following line to be a message, so a second state
89
+ * line makes the room unreadable forever). D-19 therefore makes an edit a
90
+ * *message* — which also puts it in the transcript, where this project already
91
+ * puts state changes so a person can see what happened.
92
+ *
93
+ * In `seq` order, last edit wins. A message whose kind is an edit kind but which
94
+ * carries no change is not an edit and is skipped: it is a valid message that
95
+ * happens to be tagged, and the schema deliberately does not make it invalid,
96
+ * because an invalid line would kill the room.
97
+ *
98
+ * Nothing here writes. The fold is an interpretation of an append-only log, and
99
+ * the header keeps the contract the room was created with.
100
+ */
101
+ export function foldEdits(
102
+ base: { goal_contract: GoalContract; roster: RosterEntry[] },
103
+ messages: MessageEnvelope[],
104
+ ): { goal_contract: GoalContract; roster: RosterEntry[] } {
105
+ let goalContract = base.goal_contract;
106
+ let roster = base.roster;
107
+
108
+ for (const message of [...messages].sort((a, b) => a.seq - b.seq)) {
109
+ const change: MessageChange | undefined = message.change;
110
+ if (change === undefined) continue;
111
+ if (change.type === "goal_contract") {
112
+ goalContract = {
113
+ ...change.goal_contract,
114
+ // The schema has carried these since the beginning with nothing writing
115
+ // them; an edit is exactly what they were designed for.
116
+ updated_by: "owner",
117
+ updated_in_round: message.seq,
118
+ };
119
+ continue;
120
+ }
121
+ // "add", not "set": the roster grows, and replacing it would silently drop
122
+ // everyone an earlier message had introduced.
123
+ const known = new Set(roster.map((entry) => entry.id));
124
+ roster = [...roster, ...change.add.filter((entry) => !known.has(entry.id))];
125
+ }
126
+
127
+ return { goal_contract: goalContract, roster };
128
+ }
129
+
81
130
  /** Messages with seq strictly greater than sinceSeq, in log order. */
82
131
  export function getTranscript(messages: MessageEnvelope[], sinceSeq: number): MessageEnvelope[] {
83
132
  return messages.filter((m) => m.seq > sinceSeq);
package/src/log/types.ts CHANGED
@@ -1,9 +1,22 @@
1
+ import type { MessageChange } from "./schema";
2
+
1
3
  export interface MessageEnvelope {
2
4
  seq: number;
3
5
  from: string;
4
6
  in_reply_to?: number;
5
- kind?: "pitch" | "question" | "challenge" | "answer" | "vote" | "status" | "research";
7
+ kind?:
8
+ | "pitch"
9
+ | "question"
10
+ | "challenge"
11
+ | "answer"
12
+ | "vote"
13
+ | "status"
14
+ | "research"
15
+ | "goal_edit"
16
+ | "add_participant";
6
17
  body: string;
18
+ /** Present only on an edit message; see `EDIT_KINDS` and D-19. */
19
+ change?: MessageChange;
7
20
  }
8
21
 
9
22
  export interface RosterEntry {
package/src/log/write.ts CHANGED
@@ -20,6 +20,7 @@ function describeInvalid(error: z.ZodError): string {
20
20
  const field = issue.path.join(".") || "message";
21
21
  if (field === "kind") return `kind must be one of: ${LEGAL_KINDS}`;
22
22
  if (field === "in_reply_to") return "in-reply-to must be a whole number of at least 1";
23
+ if (field === "change") return issue.message;
23
24
  return `${field}: ${issue.message}`;
24
25
  })
25
26
  .join("; ");
@@ -47,6 +48,8 @@ export interface AppendMessageOptions {
47
48
  body: string;
48
49
  kind?: MessageEnvelope["kind"];
49
50
  inReplyTo?: number;
51
+ /** Required by the edit kinds, refused on everything else — enforced by the schema. */
52
+ change?: MessageEnvelope["change"];
50
53
  }
51
54
 
52
55
  /** Refuses to overwrite: a room log is append-only, and clobbering one loses a session. */
@@ -111,20 +114,21 @@ export function appendMessages(
111
114
  }
112
115
 
113
116
  export function appendMessage(path: string, options: AppendMessageOptions): MessageEnvelope & { type: "message" } {
114
- if (!existsSync(path)) {
115
- throw new Error(`${path} does not exist. Create it with \`roomyx room new\` first.`);
116
- }
117
- // Allocating `seq` and writing the line is one critical section, not two.
118
- // `nextSeq` reads the whole file and returns max+1, and nothing stood between
119
- // that and the append: three concurrent `roomyx room append` calls all
120
- // allocated `seq: 1` and all three landed on disk. `seq` is the transcript
121
- // cursor, so a client polling between two colliding writes advances past both
122
- // and never receives the second message — on disk, invisible in the TUI,
123
- // permanently.
117
+ // Delegates to the batch path rather than assembling the envelope again.
124
118
  //
125
- // The registry has had this discipline for three rounds of review. The data
126
- // did not.
127
- return withLock(path, () => writeMessage(path, options));
119
+ // It used to have its own inline construction and its own `writeMessage`, and
120
+ // the two copies had already drifted: this one silently dropped `change`, so an
121
+ // edit appended one message at a time was written without the thing that made
122
+ // it an edit — valid by the schema, accepted, and never applied. Fixing that
123
+ // instance by adding one spread would have left the class: two places building
124
+ // one envelope. There is now one implementation, and the only thing this
125
+ // function adds is the single-message shape of the answer.
126
+ const written = appendMessages(path, [options]);
127
+ const first = written[0];
128
+ if (first === undefined) {
129
+ throw new Error(`${path}: appending one message produced nothing. This is a bug: report it.`);
130
+ }
131
+ return first;
128
132
  }
129
133
 
130
134
  function buildMessage(seq: number, options: AppendMessageOptions): MessageEnvelope & { type: "message" } {
@@ -135,6 +139,7 @@ function buildMessage(seq: number, options: AppendMessageOptions): MessageEnvelo
135
139
  body: options.body,
136
140
  ...(options.kind ? { kind: options.kind } : {}),
137
141
  ...(options.inReplyTo !== undefined ? { in_reply_to: options.inReplyTo } : {}),
142
+ ...(options.change !== undefined ? { change: options.change } : {}),
138
143
  };
139
144
  }
140
145
 
@@ -143,25 +148,6 @@ function validate(message: MessageEnvelope & { type: "message" }): void {
143
148
  if (!parsed.success) throw new LogWriteError(describeInvalid(parsed.error));
144
149
  }
145
150
 
146
- function writeMessage(path: string, options: AppendMessageOptions): MessageEnvelope & { type: "message" } {
147
- const message: MessageEnvelope & { type: "message" } = {
148
- type: "message",
149
- seq: nextSeq(path),
150
- from: options.from,
151
- body: options.body,
152
- ...(options.kind ? { kind: options.kind } : {}),
153
- ...(options.inReplyTo !== undefined ? { in_reply_to: options.inReplyTo } : {}),
154
- };
155
-
156
- // Validated against the reader's own schema, before the write rather than
157
- // after it. The log is append-only and roomyx ships no repair command, so a
158
- // line the reader refuses is not a failed write — it is a room nobody can
159
- // open again. Types alone did not hold this: they are erased at the CLI
160
- // boundary, where `--kind` arrived as an unchecked string.
161
- validate(message);
162
- appendFileSync(path, JSON.stringify(message) + "\n");
163
- return message;
164
- }
165
151
 
166
152
  /** `id:Name,id2:Name2` — the shape the CLI takes and the log stores. */
167
153
  export function parseRoster(spec: string): RosterEntry[] {