@mrciphersmith/roomyx 0.6.1 → 0.6.3
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 +77 -0
- package/README.md +53 -1
- package/package.json +5 -2
- package/src/cli/specs.ts +2 -0
- package/src/cli.ts +40 -1
- package/src/client/clip.ts +26 -0
- package/src/client/components/footer.ts +6 -2
- package/src/client/components/roster-sidebar.ts +1 -28
- package/src/client/components/status-bar.ts +17 -6
- package/src/client/index.ts +200 -226
- package/src/client/keymap.ts +7 -2
- package/src/client/screens/archive-list.ts +152 -0
- package/src/client/screens/chat-view.ts +14 -4
- package/src/client/viewer.ts +231 -0
- package/src/installer/history.ts +154 -0
- package/src/installer/registry.ts +14 -2
- package/src/log/store.ts +26 -3
package/src/log/store.ts
CHANGED
|
@@ -2,13 +2,32 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { messageLineSchema, stateLineSchema } from "./schema";
|
|
3
3
|
import type { AgentDetail, MessageEnvelope, RoomState, RosterEntry } from "./types";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* `JSON.parse`, with the one thing it never says: where.
|
|
7
|
+
*
|
|
8
|
+
* A line that is not valid JSON used to throw a bare `SyntaxError: Unexpected
|
|
9
|
+
* token` — no path, no line number — from inside a function whose whole purpose
|
|
10
|
+
* is to say `Invalid "message" line 12 in /path/room.jsonl`. Found by fuzzing:
|
|
11
|
+
* of two thousand damaged logs, every unparseable one refused without naming
|
|
12
|
+
* the file it had refused.
|
|
13
|
+
*/
|
|
14
|
+
function parseLine(text: string, describe: () => string): unknown {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(text);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(`${describe()}: not valid JSON — ${error instanceof Error ? error.message : String(error)}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
5
22
|
/**
|
|
6
23
|
* Reads the room log (see roomyx/README.md for the on-disk format) without
|
|
7
24
|
* ever writing to it. The first line is the state header; every following
|
|
8
25
|
* line is a message.
|
|
9
26
|
*/
|
|
10
27
|
export function loadRoomLog(path: string): { state: RoomState; messages: MessageEnvelope[] } {
|
|
11
|
-
|
|
28
|
+
// Editors add a byte-order mark; it is not part of the JSON and it made the
|
|
29
|
+
// first line unparseable, which made the whole room unreadable.
|
|
30
|
+
const raw = readFileSync(path, "utf8").replace(/^\uFEFF/, "");
|
|
12
31
|
const lines = raw.split("\n").filter((line) => line.trim().length > 0);
|
|
13
32
|
|
|
14
33
|
if (lines.length === 0) {
|
|
@@ -16,7 +35,9 @@ export function loadRoomLog(path: string): { state: RoomState; messages: Message
|
|
|
16
35
|
}
|
|
17
36
|
|
|
18
37
|
const [headerLine, ...rest] = lines as [string, ...string[]];
|
|
19
|
-
const headerResult = stateLineSchema.safeParse(
|
|
38
|
+
const headerResult = stateLineSchema.safeParse(
|
|
39
|
+
parseLine(headerLine, () => `Room log at ${path} must start with a valid "state" line`),
|
|
40
|
+
);
|
|
20
41
|
if (!headerResult.success) {
|
|
21
42
|
throw new Error(
|
|
22
43
|
`Room log at ${path} must start with a valid "state" line: ${headerResult.error.message}`,
|
|
@@ -31,7 +52,9 @@ export function loadRoomLog(path: string): { state: RoomState; messages: Message
|
|
|
31
52
|
};
|
|
32
53
|
|
|
33
54
|
const messages: MessageEnvelope[] = rest.map((line, index) => {
|
|
34
|
-
const result = messageLineSchema.safeParse(
|
|
55
|
+
const result = messageLineSchema.safeParse(
|
|
56
|
+
parseLine(line, () => `Invalid "message" line ${index + 2} in ${path}`),
|
|
57
|
+
);
|
|
35
58
|
if (!result.success) {
|
|
36
59
|
// +2: 1-indexed lines, plus the header line already consumed.
|
|
37
60
|
throw new Error(`Invalid "message" line ${index + 2} in ${path}: ${result.error.message}`);
|