@inerrata-corporation/errata 2.0.17-dev.3562 → 2.0.17-dev.3571

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 (3) hide show
  1. package/errata.mjs +114 -42
  2. package/package.json +1 -1
  3. package/pass-worker.mjs +54 -33
package/errata.mjs CHANGED
@@ -22314,20 +22314,13 @@ var init_intent = __esm({
22314
22314
  function isLegacyAnchor(attrs) {
22315
22315
  return attrs?.["captureTime"] === true && attrs["anchorProvenance"] === void 0;
22316
22316
  }
22317
- function repairLegacyAnchorsFromStatement(store, ts) {
22318
- const report = {
22319
- repaired: [],
22320
- retiredGuesses: 0,
22321
- noPathNamed: 0,
22322
- pathUnknown: 0,
22323
- alreadyCorrect: 0
22324
- };
22317
+ function filePathResolver(store) {
22325
22318
  const byPath = /* @__PURE__ */ new Map();
22326
22319
  for (const f of store.findNodesByLabel("File")) {
22327
22320
  const path2 = String(f.attrs["relPath"] ?? f.description ?? "");
22328
22321
  if (path2) byPath.set(path2, { id: f.id, path: path2 });
22329
22322
  }
22330
- const resolvePath2 = (named) => {
22323
+ return (named) => {
22331
22324
  const exact = byPath.get(named);
22332
22325
  if (exact) return exact;
22333
22326
  const hits = [...byPath.values()].filter(
@@ -22335,6 +22328,40 @@ function repairLegacyAnchorsFromStatement(store, ts) {
22335
22328
  );
22336
22329
  return hits.length === 1 ? hits[0] : null;
22337
22330
  };
22331
+ }
22332
+ function statementTarget(statement, resolvePath2) {
22333
+ for (const m of statement.matchAll(STATEMENT_PATH_RE)) {
22334
+ const f = resolvePath2(m[0]);
22335
+ if (f) return f;
22336
+ }
22337
+ return null;
22338
+ }
22339
+ function restatedAnchor(problemId, fileId, restatedFrom, ts) {
22340
+ return {
22341
+ id: `edge_${digest({ from: problemId, type: "ANCHORED_AT", to: fileId })}`.slice(0, 24),
22342
+ from: problemId,
22343
+ to: fileId,
22344
+ type: "ANCHORED_AT",
22345
+ // Same confidence a capture-time anchor enters at: the source is the
22346
+ // agent's own statement either way, only the moment of reading differs.
22347
+ confidence: 0.4,
22348
+ extractionSource: "agent-observed",
22349
+ createdAt: ts,
22350
+ lastSeenAt: ts,
22351
+ navSuccesses: 0,
22352
+ navFailures: 0,
22353
+ attrs: { anchorProvenance: "restated", restatedFrom, restatedAt: ts }
22354
+ };
22355
+ }
22356
+ function repairLegacyAnchorsFromStatement(store, ts) {
22357
+ const report = {
22358
+ repaired: [],
22359
+ retiredGuesses: 0,
22360
+ noPathNamed: 0,
22361
+ pathUnknown: 0,
22362
+ alreadyCorrect: 0
22363
+ };
22364
+ const resolvePath2 = filePathResolver(store);
22338
22365
  for (const p of store.findNodesByLabel("Problem")) {
22339
22366
  try {
22340
22367
  const anchors = store.outEdges(p.id, ["ANCHORED_AT"]);
@@ -22374,25 +22401,7 @@ function repairLegacyAnchorsFromStatement(store, ts) {
22374
22401
  report.pathUnknown++;
22375
22402
  continue;
22376
22403
  }
22377
- store.mergeEdge({
22378
- id: `edge_${digest({ from: p.id, type: "ANCHORED_AT", to: target.id })}`.slice(0, 24),
22379
- from: p.id,
22380
- to: target.id,
22381
- type: "ANCHORED_AT",
22382
- // Same confidence a capture-time anchor enters at: the source is the
22383
- // agent's own statement either way, only the moment of reading differs.
22384
- confidence: 0.4,
22385
- extractionSource: "agent-observed",
22386
- createdAt: ts,
22387
- lastSeenAt: ts,
22388
- navSuccesses: 0,
22389
- navFailures: 0,
22390
- attrs: {
22391
- anchorProvenance: "restated",
22392
- restatedFrom: guessedPaths[0] ?? "",
22393
- restatedAt: ts
22394
- }
22395
- });
22404
+ store.mergeEdge(restatedAnchor(p.id, target.id, guessedPaths[0] ?? "", ts));
22396
22405
  for (const e of legacy) {
22397
22406
  if (e.to !== target.id) store.closeEdge(e.id, ts);
22398
22407
  }
@@ -22412,23 +22421,35 @@ function backfillLegacyAnchors(store, ts) {
22412
22421
  const report = {
22413
22422
  demotedEdges: 0,
22414
22423
  demotedProblems: 0,
22424
+ restatedProblems: 0,
22415
22425
  labeledEdges: 0,
22416
22426
  suspects: []
22417
22427
  };
22428
+ let resolvePath2;
22418
22429
  for (const p of store.findNodesByLabel("Problem")) {
22419
- const legacy = store.outEdges(p.id, ["ANCHORED_AT"]).filter((e) => isLegacyAnchor(e.attrs));
22420
- if (legacy.length === 0) continue;
22421
22430
  const resolved = p.attrs["resolvedAt"] !== void 0;
22431
+ const legacy = store.outEdges(p.id, ["ANCHORED_AT"]).filter((e) => isLegacyAnchor(e.attrs) || !resolved && e.attrs?.["anchorProvenance"] === "legacy");
22432
+ if (legacy.length === 0) continue;
22422
22433
  try {
22423
22434
  if (!resolved) {
22424
- for (const e of legacy) {
22435
+ resolvePath2 ??= filePathResolver(store);
22436
+ const target = statementTarget(String(p.description ?? ""), resolvePath2);
22437
+ if (target) {
22438
+ const guessed = store.getNode(legacy[0].to);
22439
+ store.mergeEdge(
22440
+ restatedAnchor(p.id, target.id, String(guessed?.attrs["relPath"] ?? guessed?.description ?? ""), ts)
22441
+ );
22442
+ report.restatedProblems++;
22443
+ }
22444
+ const retired = legacy.filter((e) => !(target && e.to === target.id));
22445
+ for (const e of retired) {
22425
22446
  const file2 = store.getNode(e.to);
22426
22447
  const path2 = String(file2?.attrs["relPath"] ?? file2?.description ?? "");
22427
22448
  if (path2) recordAnchorHint(store, p.id, path2, "legacy", ts);
22428
- store.deleteEdge(e.id);
22449
+ store.closeEdge(e.id, ts);
22429
22450
  report.demotedEdges++;
22430
22451
  }
22431
- report.demotedProblems++;
22452
+ if (retired.length > 0) report.demotedProblems++;
22432
22453
  continue;
22433
22454
  }
22434
22455
  for (const e of legacy) {
@@ -33036,6 +33057,7 @@ var init_consent = __esm({
33036
33057
  });
33037
33058
 
33038
33059
  // src/git-remote.ts
33060
+ import { spawnSync } from "node:child_process";
33039
33061
  import { existsSync as existsSync10, readFileSync as readFileSync8, statSync } from "node:fs";
33040
33062
  import { isAbsolute as isAbsolute2, join as join8, resolve as resolve2 } from "node:path";
33041
33063
  function resolveGitDir(root) {
@@ -33083,12 +33105,41 @@ function detectRepoLocator(root, remote) {
33083
33105
  const remotes = readRemotes(root);
33084
33106
  if (remotes.length === 0) return null;
33085
33107
  const pick2 = remote ? remotes.find((r) => r.name === remote) ?? null : remotes.find((r) => r.name === "origin") ?? (remotes.length === 1 ? remotes[0] : null);
33086
- return pick2 ? normalizeRepoLocator(pick2.url) : null;
33108
+ return pick2 ? normalizeRepoLocator(resolveSshHostAlias(pick2.url)) : null;
33109
+ }
33110
+ function sshConfigHostname(alias) {
33111
+ if (resolvedAliases.has(alias)) return resolvedAliases.get(alias);
33112
+ let host = null;
33113
+ try {
33114
+ const out2 = spawnSync("ssh", ["-G", alias], { encoding: "utf8", timeout: 3e3, windowsHide: true });
33115
+ if (out2.status === 0) host = /^hostname\s+(\S+)\s*$/im.exec(out2.stdout)?.[1]?.toLowerCase() ?? null;
33116
+ } catch {
33117
+ host = null;
33118
+ }
33119
+ resolvedAliases.set(alias, host);
33120
+ return host;
33087
33121
  }
33122
+ function resolveSshHostAlias(remoteUrl, resolveHost = sshConfigHostname) {
33123
+ const raw2 = remoteUrl.trim();
33124
+ const m = SSH_URL_REMOTE.exec(raw2) ?? (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw2) ? null : SSH_SCP_REMOTE.exec(raw2));
33125
+ if (!m) return raw2;
33126
+ const prefix = m[1];
33127
+ const alias = m[2];
33128
+ const rest2 = m[3];
33129
+ if (alias.length === 1 || CANONICAL_FORGE_HOSTS.has(alias.toLowerCase())) return raw2;
33130
+ const real = resolveHost(alias);
33131
+ if (!real || real === alias.toLowerCase()) return raw2;
33132
+ return SSH_URL_REMOTE.test(raw2) ? `${prefix}${real}${rest2}` : `${prefix}${real}:${rest2}`;
33133
+ }
33134
+ var CANONICAL_FORGE_HOSTS, SSH_SCP_REMOTE, SSH_URL_REMOTE, resolvedAliases;
33088
33135
  var init_git_remote = __esm({
33089
33136
  "src/git-remote.ts"() {
33090
33137
  "use strict";
33091
33138
  init_src();
33139
+ CANONICAL_FORGE_HOSTS = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org", "codeberg.org"]);
33140
+ SSH_SCP_REMOTE = /^((?:[^@/]+@)?)([^:/@]+):(?!\/\/)(.+)$/;
33141
+ SSH_URL_REMOTE = /^(ssh:\/\/(?:[^@/]+@)?)([^:/@]+)((?::\d+)?\/.*)$/i;
33142
+ resolvedAliases = /* @__PURE__ */ new Map();
33092
33143
  }
33093
33144
  });
33094
33145
 
@@ -82634,7 +82685,7 @@ function createWatchBreaker(deps) {
82634
82685
  }
82635
82686
 
82636
82687
  // src/engine.ts
82637
- var DAEMON_VERSION = true ? "2.0.17-dev.3562" : "2.0.0-alpha.0";
82688
+ var DAEMON_VERSION = true ? "2.0.17-dev.3571" : "2.0.0-alpha.0";
82638
82689
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
82639
82690
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
82640
82691
  var GIT_OP_MUTE_MS = 4e3;
@@ -91838,7 +91889,7 @@ function shouldUseOAuthLogin(flags2, env2 = process.env) {
91838
91889
  }
91839
91890
 
91840
91891
  // src/doctor.ts
91841
- import { spawnSync } from "node:child_process";
91892
+ import { spawnSync as spawnSync2 } from "node:child_process";
91842
91893
 
91843
91894
  // src/codex-runtime.ts
91844
91895
  import { readdirSync as readdirSync12, statSync as statSync9 } from "node:fs";
@@ -91873,7 +91924,7 @@ function resolveCodexExecutable(options = {}) {
91873
91924
  // src/doctor.ts
91874
91925
  function installedHarnessVersion(bin) {
91875
91926
  try {
91876
- const r = spawnSync(bin === "codex" ? resolveCodexExecutable() : bin, ["--version"], { encoding: "utf8", timeout: 3e3, windowsHide: true });
91927
+ const r = spawnSync2(bin === "codex" ? resolveCodexExecutable() : bin, ["--version"], { encoding: "utf8", timeout: 3e3, windowsHide: true });
91877
91928
  if (r.status !== 0 && !r.stdout) return null;
91878
91929
  const m = /(\d+\.\d+\.\d+)/.exec(`${r.stdout ?? ""}${r.stderr ?? ""}`);
91879
91930
  return m ? m[1] : null;
@@ -92991,8 +93042,9 @@ async function cmdInit() {
92991
93042
  console.log("");
92992
93043
  console.log("Privacy: your code, file contents, and raw error text never leave");
92993
93044
  console.log("this machine \u2014 only scrubbed, canonical lessons can (consent-gated).");
92994
- console.log("Cloud sync + telemetry are OFF in this alpha \u2014 turn them on with:");
92995
- console.log(" errata consent sync on # contribute canonical, scrubbed deltas");
93045
+ console.log("Cloud sync + telemetry are OFF until you choose otherwise:");
93046
+ console.log(" errata link # per repo: pick its project + what it shares, in the Console");
93047
+ console.log(" errata consent sync on # machine default for repos you haven't linked");
92996
93048
  console.log(" errata consent telemetry on # counts-only product metrics");
92997
93049
  console.log("To CONTRIBUTE to the shared graph you must ALSO attest this daemon:");
92998
93050
  console.log(" errata login # console sign-in (OAuth) \u2014 grants graph-write");
@@ -93014,7 +93066,7 @@ async function cmdInit() {
93014
93066
  return;
93015
93067
  }
93016
93068
  console.log("");
93017
- console.log("connecting your cloud account (init links this repo to its project)...");
93069
+ console.log("connecting your cloud account...");
93018
93070
  await cmdLoginOAuth(cfgNow);
93019
93071
  cfgNow = loadConfig();
93020
93072
  if (!hasCloudCredential(cfgNow)) {
@@ -93023,14 +93075,32 @@ async function cmdInit() {
93023
93075
  return;
93024
93076
  }
93025
93077
  }
93078
+ let profileNow = loadProfile(ROOT);
93079
+ if (process.stdout.isTTY && !rest.includes("--no-link") && !rest.includes("--no-login") && profileNow && !profileNow.projectId) {
93080
+ refreshRepoLocator(ROOT, profileNow);
93081
+ if (profileNow.repoLocator) {
93082
+ console.log("");
93083
+ console.log(`linking ${profileNow.repoLocator} to its project (choose org, team and privacy in the Console)...`);
93084
+ await cmdLink(rest.includes("--no-browser") ? ["--no-browser"] : []);
93085
+ if (process.exitCode === 1) {
93086
+ console.log(" (init itself succeeded \u2014 retry the link any time with `errata link`)");
93087
+ process.exitCode = 0;
93088
+ }
93089
+ profileNow = loadProfile(ROOT);
93090
+ }
93091
+ }
93026
93092
  console.log("");
93027
93093
  console.log("Next:");
93028
93094
  console.log(" errata start # observe this repo");
93029
93095
  if (!hasCloudCredential(cfgNow)) {
93030
93096
  console.log(" errata login # connect a cloud account (or: --token <key>)");
93031
93097
  }
93032
- if (!cfgNow.consent.sync) {
93033
- console.log(" errata consent sync on # contribute scrubbed, canonical lessons");
93098
+ if (!profileNow?.projectId) {
93099
+ if (profileNow?.repoLocator) {
93100
+ console.log(" errata link # link this repo to its project (sets its privacy choices)");
93101
+ } else {
93102
+ console.log(" git remote add origin <url> # then: errata link (a project is found by its remote)");
93103
+ }
93034
93104
  }
93035
93105
  console.log(" errata status # verify the whole chain");
93036
93106
  }
@@ -93794,6 +93864,8 @@ async function cmdLink(args2) {
93794
93864
  }
93795
93865
  profile.repoRemote = remote;
93796
93866
  profile.repoLocator = loc;
93867
+ } else {
93868
+ refreshRepoLocator(ROOT, profile);
93797
93869
  }
93798
93870
  if (!wantsLocal) {
93799
93871
  if (!profile.repoLocator) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.17-dev.3562",
3
+ "version": "2.0.17-dev.3571",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {
package/pass-worker.mjs CHANGED
@@ -27547,20 +27547,13 @@ var STATEMENT_PATH_RE = new RegExp(
27547
27547
  String.raw`(?:[\w.+-]+\/)+[\w.+-]+\.(?:${anchorableExtensionAlternation()})`,
27548
27548
  "g"
27549
27549
  );
27550
- function repairLegacyAnchorsFromStatement(store2, ts) {
27551
- const report = {
27552
- repaired: [],
27553
- retiredGuesses: 0,
27554
- noPathNamed: 0,
27555
- pathUnknown: 0,
27556
- alreadyCorrect: 0
27557
- };
27550
+ function filePathResolver(store2) {
27558
27551
  const byPath = /* @__PURE__ */ new Map();
27559
27552
  for (const f of store2.findNodesByLabel("File")) {
27560
27553
  const path = String(f.attrs["relPath"] ?? f.description ?? "");
27561
27554
  if (path) byPath.set(path, { id: f.id, path });
27562
27555
  }
27563
- const resolvePath = (named) => {
27556
+ return (named) => {
27564
27557
  const exact = byPath.get(named);
27565
27558
  if (exact) return exact;
27566
27559
  const hits = [...byPath.values()].filter(
@@ -27568,6 +27561,40 @@ function repairLegacyAnchorsFromStatement(store2, ts) {
27568
27561
  );
27569
27562
  return hits.length === 1 ? hits[0] : null;
27570
27563
  };
27564
+ }
27565
+ function statementTarget(statement, resolvePath) {
27566
+ for (const m of statement.matchAll(STATEMENT_PATH_RE)) {
27567
+ const f = resolvePath(m[0]);
27568
+ if (f) return f;
27569
+ }
27570
+ return null;
27571
+ }
27572
+ function restatedAnchor(problemId, fileId, restatedFrom, ts) {
27573
+ return {
27574
+ id: `edge_${digest({ from: problemId, type: "ANCHORED_AT", to: fileId })}`.slice(0, 24),
27575
+ from: problemId,
27576
+ to: fileId,
27577
+ type: "ANCHORED_AT",
27578
+ // Same confidence a capture-time anchor enters at: the source is the
27579
+ // agent's own statement either way, only the moment of reading differs.
27580
+ confidence: 0.4,
27581
+ extractionSource: "agent-observed",
27582
+ createdAt: ts,
27583
+ lastSeenAt: ts,
27584
+ navSuccesses: 0,
27585
+ navFailures: 0,
27586
+ attrs: { anchorProvenance: "restated", restatedFrom, restatedAt: ts }
27587
+ };
27588
+ }
27589
+ function repairLegacyAnchorsFromStatement(store2, ts) {
27590
+ const report = {
27591
+ repaired: [],
27592
+ retiredGuesses: 0,
27593
+ noPathNamed: 0,
27594
+ pathUnknown: 0,
27595
+ alreadyCorrect: 0
27596
+ };
27597
+ const resolvePath = filePathResolver(store2);
27571
27598
  for (const p of store2.findNodesByLabel("Problem")) {
27572
27599
  try {
27573
27600
  const anchors = store2.outEdges(p.id, ["ANCHORED_AT"]);
@@ -27607,25 +27634,7 @@ function repairLegacyAnchorsFromStatement(store2, ts) {
27607
27634
  report.pathUnknown++;
27608
27635
  continue;
27609
27636
  }
27610
- store2.mergeEdge({
27611
- id: `edge_${digest({ from: p.id, type: "ANCHORED_AT", to: target.id })}`.slice(0, 24),
27612
- from: p.id,
27613
- to: target.id,
27614
- type: "ANCHORED_AT",
27615
- // Same confidence a capture-time anchor enters at: the source is the
27616
- // agent's own statement either way, only the moment of reading differs.
27617
- confidence: 0.4,
27618
- extractionSource: "agent-observed",
27619
- createdAt: ts,
27620
- lastSeenAt: ts,
27621
- navSuccesses: 0,
27622
- navFailures: 0,
27623
- attrs: {
27624
- anchorProvenance: "restated",
27625
- restatedFrom: guessedPaths[0] ?? "",
27626
- restatedAt: ts
27627
- }
27628
- });
27637
+ store2.mergeEdge(restatedAnchor(p.id, target.id, guessedPaths[0] ?? "", ts));
27629
27638
  for (const e of legacy) {
27630
27639
  if (e.to !== target.id) store2.closeEdge(e.id, ts);
27631
27640
  }
@@ -27645,23 +27654,35 @@ function backfillLegacyAnchors(store2, ts) {
27645
27654
  const report = {
27646
27655
  demotedEdges: 0,
27647
27656
  demotedProblems: 0,
27657
+ restatedProblems: 0,
27648
27658
  labeledEdges: 0,
27649
27659
  suspects: []
27650
27660
  };
27661
+ let resolvePath;
27651
27662
  for (const p of store2.findNodesByLabel("Problem")) {
27652
- const legacy = store2.outEdges(p.id, ["ANCHORED_AT"]).filter((e) => isLegacyAnchor(e.attrs));
27653
- if (legacy.length === 0) continue;
27654
27663
  const resolved = p.attrs["resolvedAt"] !== void 0;
27664
+ const legacy = store2.outEdges(p.id, ["ANCHORED_AT"]).filter((e) => isLegacyAnchor(e.attrs) || !resolved && e.attrs?.["anchorProvenance"] === "legacy");
27665
+ if (legacy.length === 0) continue;
27655
27666
  try {
27656
27667
  if (!resolved) {
27657
- for (const e of legacy) {
27668
+ resolvePath ??= filePathResolver(store2);
27669
+ const target = statementTarget(String(p.description ?? ""), resolvePath);
27670
+ if (target) {
27671
+ const guessed = store2.getNode(legacy[0].to);
27672
+ store2.mergeEdge(
27673
+ restatedAnchor(p.id, target.id, String(guessed?.attrs["relPath"] ?? guessed?.description ?? ""), ts)
27674
+ );
27675
+ report.restatedProblems++;
27676
+ }
27677
+ const retired = legacy.filter((e) => !(target && e.to === target.id));
27678
+ for (const e of retired) {
27658
27679
  const file2 = store2.getNode(e.to);
27659
27680
  const path = String(file2?.attrs["relPath"] ?? file2?.description ?? "");
27660
27681
  if (path) recordAnchorHint(store2, p.id, path, "legacy", ts);
27661
- store2.deleteEdge(e.id);
27682
+ store2.closeEdge(e.id, ts);
27662
27683
  report.demotedEdges++;
27663
27684
  }
27664
- report.demotedProblems++;
27685
+ if (retired.length > 0) report.demotedProblems++;
27665
27686
  continue;
27666
27687
  }
27667
27688
  for (const e of legacy) {