@inerrata-corporation/errata 2.0.5 → 2.0.6-dev.1983

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 +117 -23
  2. package/package.json +1 -1
package/errata.mjs CHANGED
@@ -19674,32 +19674,104 @@ function solutionForProblem(store, problemId) {
19674
19674
  const e = store.outEdges(problemId, ["SOLVED_BY"])[0];
19675
19675
  return e ? e.to : null;
19676
19676
  }
19677
- function anchorProblemToWorkingFile(store, problemId, relPath, workspaceId2, ts, provenance = "edited") {
19677
+ function anchorProblemToWorkingFile(store, problemId, relPath, workspaceId2, ts, provenance = "edited", opts = {}) {
19678
19678
  const p = store.getNode(problemId);
19679
19679
  if (!p || p.label !== "Problem") return false;
19680
19680
  if (!isAnchorableCodePath(relPath)) return false;
19681
19681
  const file2 = resolveFileNode(store, relPath, workspaceId2);
19682
19682
  if (!file2) return false;
19683
19683
  const already = new Set(store.outEdges(problemId, ["ANCHORED_AT"]).map((e) => e.to));
19684
- if (already.has(file2.id)) return true;
19685
- store.mergeEdge({
19686
- id: `edge_${digest({ from: problemId, type: "ANCHORED_AT", to: file2.id })}`.slice(0, 24),
19687
- from: problemId,
19688
- to: file2.id,
19689
- type: "ANCHORED_AT",
19690
- // witnessed = the agent's own declaration, F2-grade; edited = soft heuristic;
19691
- // hint-confirmed = a read-grade hint whose file was later edited while the
19692
- // problem stayed open (AC-hint-upgrade) — same soft tier as edited.
19693
- confidence: provenance === "witnessed" ? 0.4 : 0.3,
19694
- extractionSource: "agent-observed",
19695
- createdAt: ts,
19696
- lastSeenAt: ts,
19697
- navSuccesses: 0,
19698
- navFailures: 0,
19699
- attrs: { provisional: true, captureTime: true, anchorProvenance: provenance }
19700
- });
19684
+ const confidence = provenance === "witnessed" ? 0.4 : 0.3;
19685
+ if (!already.has(file2.id)) {
19686
+ store.mergeEdge({
19687
+ id: `edge_${digest({ from: problemId, type: "ANCHORED_AT", to: file2.id })}`.slice(0, 24),
19688
+ from: problemId,
19689
+ to: file2.id,
19690
+ type: "ANCHORED_AT",
19691
+ confidence,
19692
+ extractionSource: "agent-observed",
19693
+ createdAt: ts,
19694
+ lastSeenAt: ts,
19695
+ navSuccesses: 0,
19696
+ navFailures: 0,
19697
+ attrs: { provisional: true, captureTime: true, anchorProvenance: provenance }
19698
+ });
19699
+ }
19700
+ if (opts.line !== void 0 && opts.fileText !== void 0) {
19701
+ const sym = resolveEnclosingSymbol(store, file2.id, opts.line, opts.fileText);
19702
+ if (sym && !already.has(sym.id)) {
19703
+ store.mergeEdge({
19704
+ id: `edge_${digest({ from: problemId, type: "ANCHORED_AT", to: sym.id })}`.slice(0, 24),
19705
+ from: problemId,
19706
+ to: sym.id,
19707
+ type: "ANCHORED_AT",
19708
+ confidence,
19709
+ extractionSource: "agent-observed",
19710
+ createdAt: ts,
19711
+ lastSeenAt: ts,
19712
+ navSuccesses: 0,
19713
+ navFailures: 0,
19714
+ attrs: {
19715
+ provisional: true,
19716
+ captureTime: true,
19717
+ anchorProvenance: provenance,
19718
+ anchorLine: opts.line,
19719
+ enclosingSymbol: true
19720
+ }
19721
+ });
19722
+ }
19723
+ }
19701
19724
  return true;
19702
19725
  }
19726
+ function resolveEnclosingSymbol(store, fileId, line, fileText) {
19727
+ if (!Number.isFinite(line) || line < 1) return null;
19728
+ const row = Math.floor(line) - 1;
19729
+ const lineStarts = [0];
19730
+ for (let i2 = 0; i2 < fileText.length; i2++) if (fileText.charCodeAt(i2) === 10) lineStarts.push(i2 + 1);
19731
+ const rowOf = (index) => {
19732
+ let lo = 0;
19733
+ let hi = lineStarts.length - 1;
19734
+ while (lo < hi) {
19735
+ const mid = lo + hi + 1 >> 1;
19736
+ if (lineStarts[mid] <= index) lo = mid;
19737
+ else hi = mid - 1;
19738
+ }
19739
+ return lo;
19740
+ };
19741
+ let best = null;
19742
+ let bestStart = -1;
19743
+ let bestSpan = Number.POSITIVE_INFINITY;
19744
+ const seen = /* @__PURE__ */ new Set([fileId]);
19745
+ let frontier = [fileId];
19746
+ for (let depth = 0; depth < ENCLOSING_WALK_DEPTH && frontier.length > 0; depth++) {
19747
+ const next = [];
19748
+ for (const id of frontier) {
19749
+ for (const e of store.outEdges(id, ["DEFINES"])) {
19750
+ if (seen.has(e.to)) continue;
19751
+ seen.add(e.to);
19752
+ const n = store.getNode(e.to);
19753
+ if (!n) continue;
19754
+ next.push(n.id);
19755
+ if (!ENCLOSING_SYMBOL_KINDS.has(n.label)) continue;
19756
+ const startRow = n.attrs["startRow"];
19757
+ const startByte = n.attrs["startByte"];
19758
+ const endByte = n.attrs["endByte"];
19759
+ if (typeof startRow !== "number" || typeof startByte !== "number" || typeof endByte !== "number") continue;
19760
+ if (startRow < 0 || endByte < startByte) continue;
19761
+ const endRow = rowOf(Math.max(startByte, Math.min(endByte, fileText.length) - 1));
19762
+ if (row < startRow || row > endRow) continue;
19763
+ const span = endByte - startByte;
19764
+ if (startRow > bestStart || startRow === bestStart && span < bestSpan) {
19765
+ best = n;
19766
+ bestStart = startRow;
19767
+ bestSpan = span;
19768
+ }
19769
+ }
19770
+ }
19771
+ frontier = next;
19772
+ }
19773
+ return best;
19774
+ }
19703
19775
  function recordAnchorHint(store, problemId, relPath, provenance, ts) {
19704
19776
  const p = store.getNode(problemId);
19705
19777
  if (!p || p.label !== "Problem") return false;
@@ -19967,7 +20039,7 @@ function priorExposure(store, nodeId, atSeq) {
19967
20039
  if ((n.attrs["evictedCount"] ?? 0) > 0) return "evicted";
19968
20040
  return "unshown";
19969
20041
  }
19970
- var DESIGN_PROMOTE_AT, STATEMENT_ALIAS_CAP, RECURRENCE_DEBOUNCE_MS, PATTERN_DEDUP_COSINE, PATTERN_ALIAS_CAP, DEDUP_STOPWORDS, SAME_ANCHOR_DEDUP_JACCARD, EMPTY_FOLD_REPORT, SAME_ANCHOR_SCOUT_AUTO_COSINE, SAME_ANCHOR_SCOUT_MIN_COSINE, SAME_ANCHOR_NOMINATE_JACCARD, REOPEN_MIN_SOURCES, RECURRENCE_SOURCES_CAP, CITABLE_PRIOR_LABELS, MAX_ANCHOR_FILES, AUTO_MINT_PREFIX, FIX_CANDIDATE_ASK_LIMIT;
20042
+ var DESIGN_PROMOTE_AT, STATEMENT_ALIAS_CAP, RECURRENCE_DEBOUNCE_MS, PATTERN_DEDUP_COSINE, PATTERN_ALIAS_CAP, DEDUP_STOPWORDS, SAME_ANCHOR_DEDUP_JACCARD, EMPTY_FOLD_REPORT, SAME_ANCHOR_SCOUT_AUTO_COSINE, SAME_ANCHOR_SCOUT_MIN_COSINE, SAME_ANCHOR_NOMINATE_JACCARD, REOPEN_MIN_SOURCES, RECURRENCE_SOURCES_CAP, CITABLE_PRIOR_LABELS, MAX_ANCHOR_FILES, ENCLOSING_SYMBOL_KINDS, ENCLOSING_WALK_DEPTH, AUTO_MINT_PREFIX, FIX_CANDIDATE_ASK_LIMIT;
19971
20043
  var init_design_problem = __esm({
19972
20044
  "../../packages/local-graph/src/design-problem.ts"() {
19973
20045
  "use strict";
@@ -20030,6 +20102,19 @@ var init_design_problem = __esm({
20030
20102
  "AntiPattern"
20031
20103
  ]);
20032
20104
  MAX_ANCHOR_FILES = 5;
20105
+ ENCLOSING_SYMBOL_KINDS = /* @__PURE__ */ new Set([
20106
+ "Function",
20107
+ "Class",
20108
+ "Method",
20109
+ "Module",
20110
+ "Interface",
20111
+ "Const",
20112
+ "Enum",
20113
+ "TypeAlias",
20114
+ "Namespace",
20115
+ "Property"
20116
+ ]);
20117
+ ENCLOSING_WALK_DEPTH = 8;
20033
20118
  AUTO_MINT_PREFIX = "addressed by an edit to ";
20034
20119
  FIX_CANDIDATE_ASK_LIMIT = 5;
20035
20120
  }
@@ -23149,6 +23234,7 @@ __export(src_exports2, {
23149
23234
  repairLegacyAnchorsFromStatement: () => repairLegacyAnchorsFromStatement,
23150
23235
  resolveDesignProblemById: () => resolveDesignProblemById,
23151
23236
  resolveDesignProblemByStatement: () => resolveDesignProblemByStatement,
23237
+ resolveEnclosingSymbol: () => resolveEnclosingSymbol,
23152
23238
  resolveFoldCandidates: () => resolveFoldCandidates,
23153
23239
  resolveOsNode: () => resolveOsNode,
23154
23240
  retractDesignProblemById: () => retractDesignProblemById,
@@ -25280,8 +25366,8 @@ var init_config = __esm({
25280
25366
  "use strict";
25281
25367
  init_paths();
25282
25368
  LEGACY_CLOUD_URL = "https://inerrata-gateway.onrender.com";
25283
- DEFAULT_CLOUD_URL = true ? "https://inerrata.dev" : DEV_CLOUD_URL;
25284
- DEFAULT_UPDATE_CHANNEL = true ? "latest" : "dev";
25369
+ DEFAULT_CLOUD_URL = true ? "https://dev.inerrata.dev" : DEV_CLOUD_URL;
25370
+ DEFAULT_UPDATE_CHANNEL = false ? "latest" : "dev";
25285
25371
  }
25286
25372
  });
25287
25373
 
@@ -57848,7 +57934,7 @@ function createWatchBreaker(deps) {
57848
57934
  }
57849
57935
 
57850
57936
  // src/engine.ts
57851
- var DAEMON_VERSION = true ? "2.0.5" : "2.0.0-alpha.0";
57937
+ var DAEMON_VERSION = true ? "2.0.6-dev.1983" : "2.0.0-alpha.0";
57852
57938
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
57853
57939
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
57854
57940
  var GIT_OP_MUTE_MS = 4e3;
@@ -59000,7 +59086,15 @@ function createWorkspaceEngine(opts) {
59000
59086
  if (p.threadId) threads.set(p.threadId, designProblemId(p.statement));
59001
59087
  try {
59002
59088
  if (anchorPath) {
59003
- if (anchorProblemToWorkingFile(store, r.problemId, anchorPath, profile.id, t, anchorProvenance)) {
59089
+ let enclosing = {};
59090
+ if (p.location?.line !== void 0) {
59091
+ try {
59092
+ enclosing = { line: p.location.line, fileText: readFileSync24(join29(opts.workspaceRoot, anchorPath), "utf8") };
59093
+ } catch {
59094
+ enclosing = {};
59095
+ }
59096
+ }
59097
+ if (anchorProblemToWorkingFile(store, r.problemId, anchorPath, profile.id, t, anchorProvenance, enclosing)) {
59004
59098
  deriveContextFromAnchors(store, r.problemId, t);
59005
59099
  }
59006
59100
  } else if (hintPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.5",
3
+ "version": "2.0.6-dev.1983",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {