@north-light/crouter 0.3.224 → 0.3.225

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.
@@ -19,7 +19,7 @@
19
19
  // they belong to the compiled seam tier; neither needs tmux.
20
20
  import { after, before, test } from 'node:test';
21
21
  import assert from 'node:assert/strict';
22
- import { readFileSync, writeFileSync } from 'node:fs';
22
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
23
23
  import { join } from 'node:path';
24
24
  import { appendInbox, readCursor, readInboxSince } from '../../feed/inbox.js';
25
25
  import { registerWarmSpare, subscribe, updateNode } from '../../canvas/index.js';
@@ -243,9 +243,15 @@ test('a connected broker viewer keeps an obligation-free resident live', { timeo
243
243
  });
244
244
  reviveNode(nodeId, { resume: true });
245
245
  const boot = await h.awaitBoot(nodeId);
246
+ // awaitBoot returns on the boot proof, which is written BEFORE the broker's
247
+ // own `persistAttachState()` lays down the truthful zero state. Writing our
248
+ // presence first lets that boot write clobber it, and the daemon then parks a
249
+ // node the test believes is attended — wait for the broker's file to exist.
250
+ const attachPath = join(h.home, 'nodes', nodeId, 'job', 'attach.json');
251
+ await h.waitFor(() => existsSync(attachPath), { timeoutMs: 20_000, intervalMs: 20, label: 'broker persists its boot attach state' });
246
252
  // This is the presence written by a helloed direct attach, which has no
247
253
  // focuses-table row because it did not pass through the focus opener.
248
- writeFileSync(join(h.home, 'nodes', nodeId, 'job', 'attach.json'), JSON.stringify({ viewers: 1 }));
254
+ writeFileSync(attachPath, JSON.stringify({ viewers: 1 }));
249
255
  try {
250
256
  const seenAt = 15_000;
251
257
  await h.tick(seenAt);
@@ -55,6 +55,19 @@ function resolveSessionFile(nodeId, metaFile) {
55
55
  return raw;
56
56
  return null;
57
57
  }
58
+ /** The node's readable session file, or `null` when the node exists but nothing
59
+ * has been written to its session yet. pi's SessionManager computes a session's
60
+ * `.jsonl` path at `newSession()` and writes the file on the FIRST appended
61
+ * entry, so a freshly created node carries a bound `pi_session_file` that is
62
+ * not on disk until something is said. Throws only when the node itself is
63
+ * unknown. */
64
+ function readableSessionFile(nodeId) {
65
+ const node = getNode(nodeId);
66
+ if (node === null) {
67
+ throw new InputError({ error: 'not_found', message: `no node: ${nodeId}`, field: 'id', next: 'List nodes with `crtr node inspect list`.' });
68
+ }
69
+ return resolveSessionFile(nodeId, node.pi_session_file);
70
+ }
58
71
  function emptyStats(sessionId, sessionFile) {
59
72
  return {
60
73
  sessionFile,
@@ -266,6 +279,19 @@ export async function readNodeMessagesPage(nodeId, { cursor, limit = 200 }) {
266
279
  next: 'Use a limit from 1 through 500.',
267
280
  });
268
281
  }
282
+ // A node that exists but has said nothing has an EMPTY history, not a fault:
283
+ // its session file is not on disk until the first entry is appended, and a
284
+ // transcript read is how a UI opens a new conversation. Only this paged read
285
+ // can answer honestly — `/snapshot` would have to invent the engine state a
286
+ // never-run node does not have, so it and the raw `/session` export still
287
+ // reject the same state through `reconstructVisibleMessages`.
288
+ // Same shape a session-file-backed empty read produces: `messageIds` stays
289
+ // aligned 1:1 with `messages` (an absent `message_ids` would claim this read
290
+ // cannot identify entries, which is a different statement than "there are
291
+ // none"), and `nextCursor: null` is the same end-of-history marker an
292
+ // exhausted backward walk returns.
293
+ if (readableSessionFile(nodeId) === null)
294
+ return { messages: [], messageIds: [], nextCursor: null };
269
295
  const { messages, identified } = await reconstructVisibleMessages(nodeId);
270
296
  const before = cursor === undefined ? messages.length : decodeMessagesCursor(cursor, messages.length);
271
297
  let start = Math.max(0, before - limit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/crouter",
3
- "version": "0.3.224",
3
+ "version": "0.3.225",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/crouter",
3
- "version": "0.3.224",
3
+ "version": "0.3.225",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/crouter",
9
- "version": "0.3.224",
9
+ "version": "0.3.225",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {