@inerrata-corporation/errata 2.0.2-dev.206 → 2.0.2-dev.208

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 (2) hide show
  1. package/errata.mjs +78 -8
  2. package/package.json +1 -1
package/errata.mjs CHANGED
@@ -49652,6 +49652,39 @@ init_review2();
49652
49652
  import { closeSync, existsSync as existsSync12, fstatSync, openSync, readdirSync as readdirSync5, readSync, statSync as statSync3 } from "node:fs";
49653
49653
  import { basename as basename3, dirname as dirname8, join as join15 } from "node:path";
49654
49654
  import { homedir as homedir3 } from "node:os";
49655
+ function readFrom(path2, fromByte) {
49656
+ let fd;
49657
+ try {
49658
+ fd = openSync(path2, "r");
49659
+ } catch {
49660
+ return { text: "", nextOffset: fromByte };
49661
+ }
49662
+ try {
49663
+ const size = fstatSync(fd).size;
49664
+ const start2 = fromByte > 0 && fromByte <= size ? fromByte : 0;
49665
+ const len = size - start2;
49666
+ if (len <= 0) return { text: "", nextOffset: size };
49667
+ const buf = Buffer.allocUnsafe(len);
49668
+ readSync(fd, buf, 0, len, start2);
49669
+ return { text: buf.toString("utf8"), nextOffset: size };
49670
+ } catch {
49671
+ return { text: "", nextOffset: fromByte };
49672
+ } finally {
49673
+ closeSync(fd);
49674
+ }
49675
+ }
49676
+ function transcriptSize(path2) {
49677
+ try {
49678
+ const fd = openSync(path2, "r");
49679
+ try {
49680
+ return fstatSync(fd).size;
49681
+ } finally {
49682
+ closeSync(fd);
49683
+ }
49684
+ } catch {
49685
+ return 0;
49686
+ }
49687
+ }
49655
49688
  function readTail(path2, maxBytes) {
49656
49689
  let fd;
49657
49690
  try {
@@ -49729,7 +49762,13 @@ function isUserTurnBoundary(obj) {
49729
49762
  return blocks.some((b) => b["type"] === "text");
49730
49763
  }
49731
49764
  function readAssistantTurns(transcriptPath, includeThinking = true, maxBytes = 2e6) {
49732
- const raw2 = readTail(transcriptPath, maxBytes);
49765
+ return parseAssistantTurns(readTail(transcriptPath, maxBytes), includeThinking);
49766
+ }
49767
+ function readAssistantTurnsFrom(transcriptPath, fromByte, includeThinking = true) {
49768
+ const { text, nextOffset } = readFrom(transcriptPath, fromByte);
49769
+ return { turns: parseAssistantTurns(text, includeThinking), nextOffset };
49770
+ }
49771
+ function parseAssistantTurns(raw2, includeThinking) {
49733
49772
  if (!raw2) return [];
49734
49773
  const turns = [];
49735
49774
  const lines = raw2.split(/\r?\n/);
@@ -52276,7 +52315,7 @@ function startLoopLagMonitor(thresholdMs = 1e3) {
52276
52315
  }
52277
52316
 
52278
52317
  // src/engine.ts
52279
- var DAEMON_VERSION = true ? "2.0.2-dev.206" : "2.0.0-alpha.0";
52318
+ var DAEMON_VERSION = true ? "2.0.2-dev.208" : "2.0.0-alpha.0";
52280
52319
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
52281
52320
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
52282
52321
  var GIT_OP_MUTE_MS = 4e3;
@@ -52296,14 +52335,33 @@ function appendIdentityAudit(path2, record2, line) {
52296
52335
  var yieldToLoop = () => new Promise((r) => setImmediate(r));
52297
52336
  function loadTurnCursors(path2) {
52298
52337
  try {
52299
- return new Map(Object.entries(JSON.parse(readFileSync18(path2, "utf8"))));
52338
+ const raw2 = JSON.parse(readFileSync18(path2, "utf8"));
52339
+ return new Map(
52340
+ Object.entries(raw2).map(([k, v]) => [k, typeof v === "string" ? v : String(v?.uuid ?? "")])
52341
+ );
52300
52342
  } catch {
52301
52343
  return /* @__PURE__ */ new Map();
52302
52344
  }
52303
52345
  }
52304
- function saveTurnCursors(path2, cursors) {
52346
+ function loadTurnOffsets(path2) {
52305
52347
  try {
52306
- writeFileSync15(path2, JSON.stringify(Object.fromEntries(cursors)), "utf8");
52348
+ const raw2 = JSON.parse(readFileSync18(path2, "utf8"));
52349
+ const out2 = /* @__PURE__ */ new Map();
52350
+ for (const [k, v] of Object.entries(raw2)) {
52351
+ const off = typeof v === "object" && v !== null ? v.offset : void 0;
52352
+ if (typeof off === "number" && off >= 0) out2.set(k, off);
52353
+ }
52354
+ return out2;
52355
+ } catch {
52356
+ return /* @__PURE__ */ new Map();
52357
+ }
52358
+ }
52359
+ function saveTurnCursors(path2, cursors, offsets) {
52360
+ try {
52361
+ const merged = {};
52362
+ for (const [k, uuid3] of cursors) merged[k] = { uuid: uuid3, offset: offsets.get(k) ?? 0 };
52363
+ for (const [k, offset] of offsets) if (!merged[k]) merged[k] = { uuid: "", offset };
52364
+ writeFileSync15(path2, JSON.stringify(merged), "utf8");
52307
52365
  } catch {
52308
52366
  }
52309
52367
  }
@@ -52820,6 +52878,7 @@ function createWorkspaceEngine(opts) {
52820
52878
  };
52821
52879
  const turnCursorPath = join23(paths.configDir, "turn-cursors.json");
52822
52880
  const lastTurnUuid = loadTurnCursors(turnCursorPath);
52881
+ const turnOffset = loadTurnOffsets(turnCursorPath);
52823
52882
  const sessionLastProblem = /* @__PURE__ */ new Map();
52824
52883
  const sessionThreads = /* @__PURE__ */ new Map();
52825
52884
  const harvestTexts = async (sessionId, items) => {
@@ -53223,17 +53282,28 @@ function createWorkspaceEngine(opts) {
53223
53282
  }
53224
53283
  };
53225
53284
  const harvestTurns = async (sessionId, transcriptPath) => {
53285
+ const known = turnOffset.get(sessionId);
53226
53286
  let turns;
53287
+ let nextOffset;
53227
53288
  try {
53228
- turns = readAssistantTurns(transcriptPath);
53289
+ if (known === void 0) {
53290
+ turns = readAssistantTurns(transcriptPath);
53291
+ nextOffset = transcriptSize(transcriptPath);
53292
+ } else {
53293
+ ({ turns, nextOffset } = readAssistantTurnsFrom(transcriptPath, known));
53294
+ }
53229
53295
  } catch {
53230
53296
  return;
53231
53297
  }
53232
53298
  const fresh = turnsSince(turns, lastTurnUuid.get(sessionId));
53233
- if (fresh.length === 0) return;
53299
+ turnOffset.set(sessionId, nextOffset);
53300
+ if (fresh.length === 0) {
53301
+ saveTurnCursors(turnCursorPath, lastTurnUuid, turnOffset);
53302
+ return;
53303
+ }
53234
53304
  lastTurnUuid.set(sessionId, turns[turns.length - 1].uuid);
53235
53305
  await harvestTexts(sessionId, fresh);
53236
- saveTurnCursors(turnCursorPath, lastTurnUuid);
53306
+ saveTurnCursors(turnCursorPath, lastTurnUuid, turnOffset);
53237
53307
  };
53238
53308
  const seenMessageIds = /* @__PURE__ */ new Set();
53239
53309
  const onMessage = (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.2-dev.206",
3
+ "version": "2.0.2-dev.208",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {