@inerrata-corporation/errata 2.0.2-dev.206 → 2.0.2-dev.211
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/errata.mjs +109 -12
- 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
|
-
|
|
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/);
|
|
@@ -50583,7 +50622,9 @@ var EMPTY = {
|
|
|
50583
50622
|
detached: 0,
|
|
50584
50623
|
reopened: 0,
|
|
50585
50624
|
witnessed: 0,
|
|
50586
|
-
cloudTwins: []
|
|
50625
|
+
cloudTwins: [],
|
|
50626
|
+
reminted: 0,
|
|
50627
|
+
recoverable: 0
|
|
50587
50628
|
};
|
|
50588
50629
|
function markerPath(configDir) {
|
|
50589
50630
|
return join16(configDir, "constraint-backfill.json");
|
|
@@ -50649,8 +50690,11 @@ function backfillConstraintKind(store, opts) {
|
|
|
50649
50690
|
detached: 0,
|
|
50650
50691
|
reopened: 0,
|
|
50651
50692
|
witnessed: 0,
|
|
50652
|
-
cloudTwins: []
|
|
50693
|
+
cloudTwins: [],
|
|
50694
|
+
reminted: 0,
|
|
50695
|
+
recoverable: 0
|
|
50653
50696
|
};
|
|
50697
|
+
const missing = [];
|
|
50654
50698
|
const seen = /* @__PURE__ */ new Set();
|
|
50655
50699
|
const work = [];
|
|
50656
50700
|
for (const statement of statements) {
|
|
@@ -50658,7 +50702,10 @@ function backfillConstraintKind(store, opts) {
|
|
|
50658
50702
|
if (seen.has(id)) continue;
|
|
50659
50703
|
seen.add(id);
|
|
50660
50704
|
const node2 = store.getNode(id);
|
|
50661
|
-
if (!node2 || node2.label !== "Problem")
|
|
50705
|
+
if (!node2 || node2.label !== "Problem") {
|
|
50706
|
+
missing.push(statement);
|
|
50707
|
+
continue;
|
|
50708
|
+
}
|
|
50662
50709
|
const isWitnessed = citedByFix.has(priorHandle(node2)) || citedByFix.has(id) || [...citedByFix].some((c) => c && id.startsWith(c));
|
|
50663
50710
|
const fabricated = [];
|
|
50664
50711
|
for (const e of store.outEdges(id, ["SOLVED_BY"])) {
|
|
@@ -50680,7 +50727,26 @@ function backfillConstraintKind(store, opts) {
|
|
|
50680
50727
|
}
|
|
50681
50728
|
if (stamp || fabricated.length > 0) work.push({ id, fabricated, stamp });
|
|
50682
50729
|
}
|
|
50683
|
-
|
|
50730
|
+
report.recoverable = opts.remint ? 0 : missing.length;
|
|
50731
|
+
if (opts.dryRun) {
|
|
50732
|
+
report.reminted = opts.remint ? missing.length : 0;
|
|
50733
|
+
return report;
|
|
50734
|
+
}
|
|
50735
|
+
if (opts.remint && missing.length > 0) {
|
|
50736
|
+
store.transaction(() => {
|
|
50737
|
+
for (const statement of missing) {
|
|
50738
|
+
try {
|
|
50739
|
+
const r = ingestDesignProblem(
|
|
50740
|
+
store,
|
|
50741
|
+
{ problem: statement, kind: "constraint" },
|
|
50742
|
+
{ workspaceId: "", source: `constraint-remint:v${BACKFILL_VERSION}`, ts: opts.now }
|
|
50743
|
+
);
|
|
50744
|
+
if (r.created) report.reminted++;
|
|
50745
|
+
} catch {
|
|
50746
|
+
}
|
|
50747
|
+
}
|
|
50748
|
+
});
|
|
50749
|
+
}
|
|
50684
50750
|
store.transaction(() => {
|
|
50685
50751
|
for (const w of work) {
|
|
50686
50752
|
const node2 = store.getNode(w.id);
|
|
@@ -52276,7 +52342,7 @@ function startLoopLagMonitor(thresholdMs = 1e3) {
|
|
|
52276
52342
|
}
|
|
52277
52343
|
|
|
52278
52344
|
// src/engine.ts
|
|
52279
|
-
var DAEMON_VERSION = true ? "2.0.2-dev.
|
|
52345
|
+
var DAEMON_VERSION = true ? "2.0.2-dev.211" : "2.0.0-alpha.0";
|
|
52280
52346
|
var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
|
|
52281
52347
|
var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
|
|
52282
52348
|
var GIT_OP_MUTE_MS = 4e3;
|
|
@@ -52296,14 +52362,33 @@ function appendIdentityAudit(path2, record2, line) {
|
|
|
52296
52362
|
var yieldToLoop = () => new Promise((r) => setImmediate(r));
|
|
52297
52363
|
function loadTurnCursors(path2) {
|
|
52298
52364
|
try {
|
|
52299
|
-
|
|
52365
|
+
const raw2 = JSON.parse(readFileSync18(path2, "utf8"));
|
|
52366
|
+
return new Map(
|
|
52367
|
+
Object.entries(raw2).map(([k, v]) => [k, typeof v === "string" ? v : String(v?.uuid ?? "")])
|
|
52368
|
+
);
|
|
52300
52369
|
} catch {
|
|
52301
52370
|
return /* @__PURE__ */ new Map();
|
|
52302
52371
|
}
|
|
52303
52372
|
}
|
|
52304
|
-
function
|
|
52373
|
+
function loadTurnOffsets(path2) {
|
|
52305
52374
|
try {
|
|
52306
|
-
|
|
52375
|
+
const raw2 = JSON.parse(readFileSync18(path2, "utf8"));
|
|
52376
|
+
const out2 = /* @__PURE__ */ new Map();
|
|
52377
|
+
for (const [k, v] of Object.entries(raw2)) {
|
|
52378
|
+
const off = typeof v === "object" && v !== null ? v.offset : void 0;
|
|
52379
|
+
if (typeof off === "number" && off >= 0) out2.set(k, off);
|
|
52380
|
+
}
|
|
52381
|
+
return out2;
|
|
52382
|
+
} catch {
|
|
52383
|
+
return /* @__PURE__ */ new Map();
|
|
52384
|
+
}
|
|
52385
|
+
}
|
|
52386
|
+
function saveTurnCursors(path2, cursors, offsets) {
|
|
52387
|
+
try {
|
|
52388
|
+
const merged = {};
|
|
52389
|
+
for (const [k, uuid3] of cursors) merged[k] = { uuid: uuid3, offset: offsets.get(k) ?? 0 };
|
|
52390
|
+
for (const [k, offset] of offsets) if (!merged[k]) merged[k] = { uuid: "", offset };
|
|
52391
|
+
writeFileSync15(path2, JSON.stringify(merged), "utf8");
|
|
52307
52392
|
} catch {
|
|
52308
52393
|
}
|
|
52309
52394
|
}
|
|
@@ -52820,6 +52905,7 @@ function createWorkspaceEngine(opts) {
|
|
|
52820
52905
|
};
|
|
52821
52906
|
const turnCursorPath = join23(paths.configDir, "turn-cursors.json");
|
|
52822
52907
|
const lastTurnUuid = loadTurnCursors(turnCursorPath);
|
|
52908
|
+
const turnOffset = loadTurnOffsets(turnCursorPath);
|
|
52823
52909
|
const sessionLastProblem = /* @__PURE__ */ new Map();
|
|
52824
52910
|
const sessionThreads = /* @__PURE__ */ new Map();
|
|
52825
52911
|
const harvestTexts = async (sessionId, items) => {
|
|
@@ -53223,17 +53309,28 @@ function createWorkspaceEngine(opts) {
|
|
|
53223
53309
|
}
|
|
53224
53310
|
};
|
|
53225
53311
|
const harvestTurns = async (sessionId, transcriptPath) => {
|
|
53312
|
+
const known = turnOffset.get(sessionId);
|
|
53226
53313
|
let turns;
|
|
53314
|
+
let nextOffset;
|
|
53227
53315
|
try {
|
|
53228
|
-
|
|
53316
|
+
if (known === void 0) {
|
|
53317
|
+
turns = readAssistantTurns(transcriptPath);
|
|
53318
|
+
nextOffset = transcriptSize(transcriptPath);
|
|
53319
|
+
} else {
|
|
53320
|
+
({ turns, nextOffset } = readAssistantTurnsFrom(transcriptPath, known));
|
|
53321
|
+
}
|
|
53229
53322
|
} catch {
|
|
53230
53323
|
return;
|
|
53231
53324
|
}
|
|
53232
53325
|
const fresh = turnsSince(turns, lastTurnUuid.get(sessionId));
|
|
53233
|
-
|
|
53326
|
+
turnOffset.set(sessionId, nextOffset);
|
|
53327
|
+
if (fresh.length === 0) {
|
|
53328
|
+
saveTurnCursors(turnCursorPath, lastTurnUuid, turnOffset);
|
|
53329
|
+
return;
|
|
53330
|
+
}
|
|
53234
53331
|
lastTurnUuid.set(sessionId, turns[turns.length - 1].uuid);
|
|
53235
53332
|
await harvestTexts(sessionId, fresh);
|
|
53236
|
-
saveTurnCursors(turnCursorPath, lastTurnUuid);
|
|
53333
|
+
saveTurnCursors(turnCursorPath, lastTurnUuid, turnOffset);
|
|
53237
53334
|
};
|
|
53238
53335
|
const seenMessageIds = /* @__PURE__ */ new Set();
|
|
53239
53336
|
const onMessage = (e) => {
|