@inerrata-corporation/errata 2.0.5-dev.1833 → 2.0.5-dev.1868

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 +116 -21
  2. package/package.json +1 -1
package/errata.mjs CHANGED
@@ -19674,32 +19674,105 @@ 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 bytes = Buffer.from(fileText, "utf8");
19730
+ const lineStarts = [0];
19731
+ for (let i2 = 0; i2 < bytes.length; i2++) if (bytes[i2] === 10) lineStarts.push(i2 + 1);
19732
+ const rowOf = (byte) => {
19733
+ let lo = 0;
19734
+ let hi = lineStarts.length - 1;
19735
+ while (lo < hi) {
19736
+ const mid = lo + hi + 1 >> 1;
19737
+ if (lineStarts[mid] <= byte) lo = mid;
19738
+ else hi = mid - 1;
19739
+ }
19740
+ return lo;
19741
+ };
19742
+ let best = null;
19743
+ let bestStart = -1;
19744
+ let bestSpan = Number.POSITIVE_INFINITY;
19745
+ const seen = /* @__PURE__ */ new Set([fileId]);
19746
+ let frontier = [fileId];
19747
+ for (let depth = 0; depth < ENCLOSING_WALK_DEPTH && frontier.length > 0; depth++) {
19748
+ const next = [];
19749
+ for (const id of frontier) {
19750
+ for (const e of store.outEdges(id, ["DEFINES"])) {
19751
+ if (seen.has(e.to)) continue;
19752
+ seen.add(e.to);
19753
+ const n = store.getNode(e.to);
19754
+ if (!n) continue;
19755
+ next.push(n.id);
19756
+ if (!ENCLOSING_SYMBOL_KINDS.has(n.label)) continue;
19757
+ const startRow = n.attrs["startRow"];
19758
+ const startByte = n.attrs["startByte"];
19759
+ const endByte = n.attrs["endByte"];
19760
+ if (typeof startRow !== "number" || typeof startByte !== "number" || typeof endByte !== "number") continue;
19761
+ if (startRow < 0 || endByte < startByte) continue;
19762
+ const endRow = rowOf(Math.max(startByte, Math.min(endByte, bytes.length) - 1));
19763
+ if (row < startRow || row > endRow) continue;
19764
+ const span = endByte - startByte;
19765
+ if (startRow > bestStart || startRow === bestStart && span < bestSpan) {
19766
+ best = n;
19767
+ bestStart = startRow;
19768
+ bestSpan = span;
19769
+ }
19770
+ }
19771
+ }
19772
+ frontier = next;
19773
+ }
19774
+ return best;
19775
+ }
19703
19776
  function recordAnchorHint(store, problemId, relPath, provenance, ts) {
19704
19777
  const p = store.getNode(problemId);
19705
19778
  if (!p || p.label !== "Problem") return false;
@@ -19967,7 +20040,7 @@ function priorExposure(store, nodeId, atSeq) {
19967
20040
  if ((n.attrs["evictedCount"] ?? 0) > 0) return "evicted";
19968
20041
  return "unshown";
19969
20042
  }
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;
20043
+ 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
20044
  var init_design_problem = __esm({
19972
20045
  "../../packages/local-graph/src/design-problem.ts"() {
19973
20046
  "use strict";
@@ -20030,6 +20103,19 @@ var init_design_problem = __esm({
20030
20103
  "AntiPattern"
20031
20104
  ]);
20032
20105
  MAX_ANCHOR_FILES = 5;
20106
+ ENCLOSING_SYMBOL_KINDS = /* @__PURE__ */ new Set([
20107
+ "Function",
20108
+ "Class",
20109
+ "Method",
20110
+ "Module",
20111
+ "Interface",
20112
+ "Const",
20113
+ "Enum",
20114
+ "TypeAlias",
20115
+ "Namespace",
20116
+ "Property"
20117
+ ]);
20118
+ ENCLOSING_WALK_DEPTH = 8;
20033
20119
  AUTO_MINT_PREFIX = "addressed by an edit to ";
20034
20120
  FIX_CANDIDATE_ASK_LIMIT = 5;
20035
20121
  }
@@ -23149,6 +23235,7 @@ __export(src_exports2, {
23149
23235
  repairLegacyAnchorsFromStatement: () => repairLegacyAnchorsFromStatement,
23150
23236
  resolveDesignProblemById: () => resolveDesignProblemById,
23151
23237
  resolveDesignProblemByStatement: () => resolveDesignProblemByStatement,
23238
+ resolveEnclosingSymbol: () => resolveEnclosingSymbol,
23152
23239
  resolveFoldCandidates: () => resolveFoldCandidates,
23153
23240
  resolveOsNode: () => resolveOsNode,
23154
23241
  retractDesignProblemById: () => retractDesignProblemById,
@@ -57848,7 +57935,7 @@ function createWatchBreaker(deps) {
57848
57935
  }
57849
57936
 
57850
57937
  // src/engine.ts
57851
- var DAEMON_VERSION = true ? "2.0.5-dev.1833" : "2.0.0-alpha.0";
57938
+ var DAEMON_VERSION = true ? "2.0.5-dev.1868" : "2.0.0-alpha.0";
57852
57939
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
57853
57940
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
57854
57941
  var GIT_OP_MUTE_MS = 4e3;
@@ -59000,7 +59087,15 @@ function createWorkspaceEngine(opts) {
59000
59087
  if (p.threadId) threads.set(p.threadId, designProblemId(p.statement));
59001
59088
  try {
59002
59089
  if (anchorPath) {
59003
- if (anchorProblemToWorkingFile(store, r.problemId, anchorPath, profile.id, t, anchorProvenance)) {
59090
+ let enclosing = {};
59091
+ if (p.location?.line !== void 0) {
59092
+ try {
59093
+ enclosing = { line: p.location.line, fileText: readFileSync24(join29(opts.workspaceRoot, anchorPath), "utf8") };
59094
+ } catch {
59095
+ enclosing = {};
59096
+ }
59097
+ }
59098
+ if (anchorProblemToWorkingFile(store, r.problemId, anchorPath, profile.id, t, anchorProvenance, enclosing)) {
59004
59099
  deriveContextFromAnchors(store, r.problemId, t);
59005
59100
  }
59006
59101
  } else if (hintPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.5-dev.1833",
3
+ "version": "2.0.5-dev.1868",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {