@inerrata-corporation/errata 2.0.2-dev.1097 → 2.0.2-dev.1109

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 +113 -1
  2. package/package.json +1 -1
package/errata.mjs CHANGED
@@ -53280,6 +53280,91 @@ function subagentTranscripts(mainTranscriptPath, sessionId) {
53280
53280
  refs.sort((a, b) => b.mtimeMs - a.mtimeMs);
53281
53281
  return refs;
53282
53282
  }
53283
+ function codexSessionRoots(env2 = process.env, home = homedir4()) {
53284
+ const roots = /* @__PURE__ */ new Set();
53285
+ const explicit = env2["ERRATA_CODEX_SESSIONS_DIRS"];
53286
+ if (explicit) {
53287
+ for (const d of explicit.split(":")) if (d.trim()) roots.add(d.trim());
53288
+ }
53289
+ if (env2["CODEX_HOME"]) roots.add(join16(env2["CODEX_HOME"], "sessions"));
53290
+ roots.add(join16(home, ".codex", "sessions"));
53291
+ return [...roots];
53292
+ }
53293
+ function readCodexRolloutCwd(path2) {
53294
+ let fd;
53295
+ try {
53296
+ fd = openSync(path2, "r");
53297
+ const CAP = 1e6;
53298
+ const chunk = 65536;
53299
+ let acc = Buffer.alloc(0);
53300
+ let pos = 0;
53301
+ let nl = -1;
53302
+ while (acc.length < CAP) {
53303
+ const buf = Buffer.allocUnsafe(chunk);
53304
+ const n = readSync(fd, buf, 0, chunk, pos);
53305
+ if (n <= 0) break;
53306
+ acc = acc.length === 0 ? buf.subarray(0, n) : Buffer.concat([acc, buf.subarray(0, n)]);
53307
+ pos += n;
53308
+ nl = acc.indexOf(10);
53309
+ if (nl >= 0) break;
53310
+ }
53311
+ const firstLine = acc.toString("utf8", 0, nl >= 0 ? nl : acc.length);
53312
+ try {
53313
+ const o = JSON.parse(firstLine);
53314
+ const meta3 = o?.type === "session_meta" ? o.payload ?? o : o.payload ?? o;
53315
+ const cwd = meta3?.cwd ?? o?.cwd;
53316
+ if (typeof cwd === "string") return cwd;
53317
+ } catch {
53318
+ }
53319
+ const m = firstLine.match(/"cwd"\s*:\s*"((?:[^"\\]|\\.)*)"/);
53320
+ return m ? JSON.parse(`"${m[1]}"`) : null;
53321
+ } catch {
53322
+ return null;
53323
+ } finally {
53324
+ if (fd !== void 0) try {
53325
+ closeSync(fd);
53326
+ } catch {
53327
+ }
53328
+ }
53329
+ }
53330
+ function codexRolloutsForCwd(cwd, opts = {}) {
53331
+ const sinceMs = opts.sinceMs ?? 0;
53332
+ const limit = opts.limit ?? 25;
53333
+ const out2 = [];
53334
+ for (const root of codexSessionRoots(opts.env, opts.home)) {
53335
+ if (!existsSync13(root)) continue;
53336
+ const stack = [{ dir: root, depth: 0 }];
53337
+ while (stack.length > 0) {
53338
+ const { dir, depth } = stack.pop();
53339
+ let names;
53340
+ try {
53341
+ names = readdirSync6(dir);
53342
+ } catch {
53343
+ continue;
53344
+ }
53345
+ for (const name2 of names) {
53346
+ const full = join16(dir, name2);
53347
+ let st;
53348
+ try {
53349
+ st = statSync4(full);
53350
+ } catch {
53351
+ continue;
53352
+ }
53353
+ if (st.isDirectory()) {
53354
+ if (depth < 3) stack.push({ dir: full, depth: depth + 1 });
53355
+ continue;
53356
+ }
53357
+ if (depth < 3) continue;
53358
+ if (!name2.startsWith("rollout-") || !name2.endsWith(".jsonl")) continue;
53359
+ if (st.mtimeMs < sinceMs) continue;
53360
+ if (readCodexRolloutCwd(full) !== cwd) continue;
53361
+ out2.push({ path: full, sessionId: `codex:${basename3(name2, ".jsonl")}`, mtimeMs: st.mtimeMs });
53362
+ }
53363
+ }
53364
+ }
53365
+ out2.sort((a, b) => b.mtimeMs - a.mtimeMs);
53366
+ return out2.slice(0, limit);
53367
+ }
53283
53368
 
53284
53369
  // src/prior-tags.ts
53285
53370
  init_src();
@@ -56501,13 +56586,14 @@ function createLivenessWatch(deps) {
56501
56586
  }
56502
56587
 
56503
56588
  // src/engine.ts
56504
- var DAEMON_VERSION = true ? "2.0.2-dev.1097" : "2.0.0-alpha.0";
56589
+ var DAEMON_VERSION = true ? "2.0.2-dev.1109" : "2.0.0-alpha.0";
56505
56590
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
56506
56591
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
56507
56592
  var GIT_OP_MUTE_MS = 4e3;
56508
56593
  var REINDEX_DEBOUNCE_MS = 200;
56509
56594
  var IDENTITY_AUDIT_MAX_BYTES = 16 * 1024 * 1024;
56510
56595
  var TURN_REPLAY_LOOKBACK_MS = 7 * 24 * 60 * 6e4;
56596
+ var CODEX_SWEEP_LOOKBACK_MS = 10 * 6e4;
56511
56597
  function appendIdentityAudit(path2, record2, line) {
56512
56598
  if (!record2.accepted && record2.score <= 0) return;
56513
56599
  try {
@@ -58026,10 +58112,35 @@ function createWorkspaceEngine(opts) {
58026
58112
  await yieldToLoop();
58027
58113
  await harvestSession(ref.sessionId, ref.path);
58028
58114
  }
58115
+ const codexRefs = codexRolloutsForCwd(opts.workspaceRoot, {
58116
+ sinceMs: Date.now() - TURN_REPLAY_LOOKBACK_MS,
58117
+ limit: 25
58118
+ });
58119
+ for (const ref of codexRefs) {
58120
+ await yieldToLoop();
58121
+ await harvestSession(ref.sessionId, ref.path);
58122
+ }
58029
58123
  } catch {
58030
58124
  }
58031
58125
  })();
58032
58126
  });
58127
+ const sweepCodexRollouts = () => {
58128
+ setImmediate(() => {
58129
+ void (async () => {
58130
+ try {
58131
+ const refs = codexRolloutsForCwd(opts.workspaceRoot, {
58132
+ sinceMs: Date.now() - CODEX_SWEEP_LOOKBACK_MS,
58133
+ limit: 10
58134
+ });
58135
+ for (const ref of refs) {
58136
+ await yieldToLoop();
58137
+ await harvestSession(ref.sessionId, ref.path);
58138
+ }
58139
+ } catch {
58140
+ }
58141
+ })();
58142
+ });
58143
+ };
58033
58144
  const designRollup = opts.designRollup ?? (process.env["ERRATA_ROLLUP"] === "1" ? haikuDesignRollup(process.env["ANTHROPIC_API_KEY"] ?? null) : void 0);
58034
58145
  const onSessionEnd = (e) => {
58035
58146
  if (!designRollup) return;
@@ -58168,6 +58279,7 @@ function createWorkspaceEngine(opts) {
58168
58279
  refreshContextNow();
58169
58280
  },
58170
58281
  async tick() {
58282
+ sweepCodexRollouts();
58171
58283
  maybeRefreshRemotePriors();
58172
58284
  const report = {
58173
58285
  generalizerEventsProcessed: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.2-dev.1097",
3
+ "version": "2.0.2-dev.1109",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {