@inerrata-corporation/errata 2.0.2-dev.361 → 2.0.2-dev.417

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.
@@ -16962,213 +16962,6 @@ function detectCommunitiesLeiden(input, opts = {}) {
16962
16962
  return normalize(assignment);
16963
16963
  }
16964
16964
 
16965
- // ../../packages/local-graph/src/abstraction.ts
16966
- var DEFAULT_MIN_CLUSTER_SIZE = 3;
16967
- var DEFAULT_MIN_DISTINCT_CONTEXTS = 2;
16968
- function sharedScope(l2, memberIds) {
16969
- const shared = (field) => {
16970
- const vals = /* @__PURE__ */ new Set();
16971
- for (const id of memberIds) {
16972
- const s = l2.getNode(id)?.attrs["scope"] ?? {};
16973
- if (typeof s[field] === "string") vals.add(s[field]);
16974
- }
16975
- return vals.size === 1 ? [...vals][0] : void 0;
16976
- };
16977
- const lang = shared("lang");
16978
- const versionRange = shared("versionRange");
16979
- return { ...lang ? { lang } : {}, ...versionRange ? { versionRange } : {} };
16980
- }
16981
- function buildCandidate(id, ts, members, contexts, originMachine, scope) {
16982
- return {
16983
- id,
16984
- label: "Claim",
16985
- description: "",
16986
- // empty — the harness distills the prose in P3
16987
- extractionConfidence: 0.4,
16988
- extractionSource: "agent-observed",
16989
- embedding: [],
16990
- cumulativeSurprise: 0,
16991
- peakSurprise: 0,
16992
- cumulativeHits: 1,
16993
- lastUpdatedAt: ts,
16994
- createdAt: ts,
16995
- memoryTier: "short-term",
16996
- pageRank: 0,
16997
- isLandmark: false,
16998
- community: null,
16999
- stability: "unstable",
17000
- attrs: {
17001
- abstractionLevel: ABSTRACTION_LEVEL.PRINCIPLE,
17002
- kind: "abstraction-candidate",
17003
- provisional: true,
17004
- pendingDistillation: true,
17005
- // membership is the unit of truth — the harness validates its fence against
17006
- // this set (P3 / C3) and may only phrase, never alter, it.
17007
- members,
17008
- memberContexts: contexts,
17009
- distinctContexts: contexts.length,
17010
- // standard Claim envelope so it crystallizes/syncs unchanged once distilled
17011
- truthKind: "contextual",
17012
- // Derived from members (P1): a single-language cluster becomes a lang-scoped
17013
- // principle; a cross-language one stays universal (`{}`).
17014
- scope,
17015
- groundedSupport: 0,
17016
- sources: [],
17017
- crystallized: "hypothesis",
17018
- confidence: 0.4,
17019
- ...originMachine ? { originMachine } : {}
17020
- }
17021
- };
17022
- }
17023
- function mergeGeneralizes(store, principleId, memberId, ts) {
17024
- store.mergeEdge({
17025
- id: `edge_${digest({ from: principleId, type: "GENERALIZES", to: memberId })}`.slice(0, 24),
17026
- from: principleId,
17027
- to: memberId,
17028
- type: "GENERALIZES",
17029
- confidence: 0.4,
17030
- extractionSource: "agent-observed",
17031
- createdAt: ts,
17032
- lastSeenAt: ts,
17033
- navSuccesses: 0,
17034
- navFailures: 0,
17035
- attrs: { provisional: true }
17036
- });
17037
- }
17038
- function induceAbstractions(l2, opts) {
17039
- const K = opts.minClusterSize ?? DEFAULT_MIN_CLUSTER_SIZE;
17040
- const minCtx = opts.minDistinctContexts ?? DEFAULT_MIN_DISTINCT_CONTEXTS;
17041
- const report = {
17042
- communities: 0,
17043
- candidatesMinted: 0,
17044
- candidatesExisting: 0,
17045
- skippedSmall: 0,
17046
- skippedSingleContext: 0,
17047
- generalizesEdges: 0
17048
- };
17049
- const ids = /* @__PURE__ */ new Set();
17050
- for (const label of PERCOLATING_LABELS) {
17051
- for (const n of l2.findNodesByLabel(label)) {
17052
- if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) >= ABSTRACTION_LEVEL.PRINCIPLE) {
17053
- continue;
17054
- }
17055
- if (n.attrs["resolvedAs"] === PROBLEM_RESOLUTION.FALSE_POSITIVE) continue;
17056
- ids.add(n.id);
17057
- }
17058
- }
17059
- if (ids.size === 0) return report;
17060
- const adj = /* @__PURE__ */ new Map();
17061
- const protect = [];
17062
- const add = (a, b, w) => {
17063
- const l = adj.get(a) ?? [];
17064
- l.push({ to: b, weight: w });
17065
- adj.set(a, l);
17066
- };
17067
- for (const id of ids) {
17068
- for (const e of l2.outEdges(id, [...PERCOLATING_EDGES])) {
17069
- if (!ids.has(e.to)) continue;
17070
- const conf = e.confidence > 0 ? e.confidence : 0.5;
17071
- const w = Math.max(EDGE_WEIGHT[e.type] ?? 1, 0.1) * conf;
17072
- add(id, e.to, w);
17073
- add(e.to, id, w);
17074
- if (isCausalProtected(e.type)) protect.push([id, e.to]);
17075
- }
17076
- }
17077
- const comm = detectCommunitiesLeiden({ nodeIds: [...ids], adj }, { protect });
17078
- report.communities = comm.count;
17079
- const members = /* @__PURE__ */ new Map();
17080
- for (const [id, c] of comm.community) {
17081
- const l = members.get(c) ?? [];
17082
- l.push(id);
17083
- members.set(c, l);
17084
- }
17085
- l2.transaction(() => {
17086
- for (const mem of members.values()) {
17087
- if (opts.touched && !mem.some((id) => opts.touched.has(id))) continue;
17088
- if (mem.length < K) {
17089
- report.skippedSmall++;
17090
- continue;
17091
- }
17092
- if (mem.some((id) => l2.inEdges(id, ["GENERALIZES"]).length > 0)) {
17093
- report.candidatesExisting++;
17094
- continue;
17095
- }
17096
- const contexts = /* @__PURE__ */ new Set();
17097
- for (const id of mem) {
17098
- const n = l2.getNode(id);
17099
- const obs = n?.attrs["observedInProjects"];
17100
- if (Array.isArray(obs)) {
17101
- for (const ws of obs) contexts.add(opts.contextOf(ws) ?? `project:${ws}`);
17102
- }
17103
- }
17104
- if (contexts.size < minCtx) {
17105
- report.skippedSingleContext++;
17106
- continue;
17107
- }
17108
- const sorted = [...mem].sort();
17109
- const principleId = `princ_${digest({ members: sorted })}`.slice(0, 56);
17110
- l2.mergeNode(
17111
- buildCandidate(principleId, opts.ts, sorted, [...contexts].sort(), opts.originMachine, sharedScope(l2, sorted))
17112
- );
17113
- for (const id of sorted) {
17114
- mergeGeneralizes(l2, principleId, id, opts.ts);
17115
- report.generalizesEdges++;
17116
- }
17117
- report.candidatesMinted++;
17118
- }
17119
- });
17120
- return report;
17121
- }
17122
- function revisitContradictedPrinciples(l2, ts) {
17123
- const report = { flagged: 0 };
17124
- l2.transaction(() => {
17125
- for (const n of l2.findNodesByLabel("Claim")) {
17126
- if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) < ABSTRACTION_LEVEL.PRINCIPLE) continue;
17127
- if (n.attrs["revisit"] === true) continue;
17128
- const members = Array.isArray(n.attrs["members"]) ? n.attrs["members"] : [];
17129
- const memberSet = new Set(members);
17130
- let reason = "";
17131
- for (const id of members) {
17132
- const m = l2.getNode(id);
17133
- if (!m) {
17134
- reason = `member ${id} was removed`;
17135
- break;
17136
- }
17137
- if (m.attrs["revisit"] === true) {
17138
- reason = `member "${m.description}" needs revisit`;
17139
- break;
17140
- }
17141
- const contradictors = [
17142
- ...l2.outEdges(id, ["CONTRADICTS"]).map((e) => e.to),
17143
- ...l2.inEdges(id, ["CONTRADICTS"]).map((e) => e.from)
17144
- ];
17145
- if (contradictors.some((other) => !memberSet.has(other))) {
17146
- reason = `member "${m.description}" is now contradicted by external evidence`;
17147
- break;
17148
- }
17149
- }
17150
- if (!reason) continue;
17151
- l2.updateNode(n.id, {
17152
- attrs: {
17153
- ...n.attrs,
17154
- revisit: true,
17155
- revisitReason: reason,
17156
- revisitSinceTs: ts,
17157
- provisional: true,
17158
- // re-queue for re-distillation (P3 re-name)
17159
- pendingDistillation: true
17160
- },
17161
- lastUpdatedAt: ts
17162
- });
17163
- report.flagged++;
17164
- }
17165
- });
17166
- return report;
17167
- }
17168
-
17169
- // ../../packages/local-graph/src/community.ts
17170
- init_src2();
17171
-
17172
16965
  // ../../packages/local-graph/src/triage.ts
17173
16966
  init_src();
17174
16967
  init_src();
@@ -17421,6 +17214,213 @@ function revisitStaleRoutes(l2, ts, opts = {}) {
17421
17214
  }
17422
17215
  var DRIFT_VALUES = new Set(Object.values(DRIFT_KIND));
17423
17216
 
17217
+ // ../../packages/local-graph/src/abstraction.ts
17218
+ var DEFAULT_MIN_CLUSTER_SIZE = 3;
17219
+ var DEFAULT_MIN_DISTINCT_CONTEXTS = 2;
17220
+ function sharedScope(l2, memberIds) {
17221
+ const shared = (field) => {
17222
+ const vals = /* @__PURE__ */ new Set();
17223
+ for (const id of memberIds) {
17224
+ const s = l2.getNode(id)?.attrs["scope"] ?? {};
17225
+ if (typeof s[field] === "string") vals.add(s[field]);
17226
+ }
17227
+ return vals.size === 1 ? [...vals][0] : void 0;
17228
+ };
17229
+ const lang = shared("lang");
17230
+ const versionRange = shared("versionRange");
17231
+ return { ...lang ? { lang } : {}, ...versionRange ? { versionRange } : {} };
17232
+ }
17233
+ function buildCandidate(id, ts, members, contexts, originMachine, scope) {
17234
+ return {
17235
+ id,
17236
+ label: "Claim",
17237
+ description: "",
17238
+ // empty — the harness distills the prose in P3
17239
+ extractionConfidence: 0.4,
17240
+ extractionSource: "agent-observed",
17241
+ embedding: [],
17242
+ cumulativeSurprise: 0,
17243
+ peakSurprise: 0,
17244
+ cumulativeHits: 1,
17245
+ lastUpdatedAt: ts,
17246
+ createdAt: ts,
17247
+ memoryTier: "short-term",
17248
+ pageRank: 0,
17249
+ isLandmark: false,
17250
+ community: null,
17251
+ stability: "unstable",
17252
+ attrs: {
17253
+ abstractionLevel: ABSTRACTION_LEVEL.PRINCIPLE,
17254
+ kind: "abstraction-candidate",
17255
+ provisional: true,
17256
+ pendingDistillation: true,
17257
+ // membership is the unit of truth — the harness validates its fence against
17258
+ // this set (P3 / C3) and may only phrase, never alter, it.
17259
+ members,
17260
+ memberContexts: contexts,
17261
+ distinctContexts: contexts.length,
17262
+ // standard Claim envelope so it crystallizes/syncs unchanged once distilled
17263
+ truthKind: "contextual",
17264
+ // Derived from members (P1): a single-language cluster becomes a lang-scoped
17265
+ // principle; a cross-language one stays universal (`{}`).
17266
+ scope,
17267
+ groundedSupport: 0,
17268
+ sources: [],
17269
+ crystallized: "hypothesis",
17270
+ confidence: 0.4,
17271
+ ...originMachine ? { originMachine } : {}
17272
+ }
17273
+ };
17274
+ }
17275
+ function mergeGeneralizes(store, principleId, memberId, ts) {
17276
+ store.mergeEdge({
17277
+ id: `edge_${digest({ from: principleId, type: "GENERALIZES", to: memberId })}`.slice(0, 24),
17278
+ from: principleId,
17279
+ to: memberId,
17280
+ type: "GENERALIZES",
17281
+ confidence: 0.4,
17282
+ extractionSource: "agent-observed",
17283
+ createdAt: ts,
17284
+ lastSeenAt: ts,
17285
+ navSuccesses: 0,
17286
+ navFailures: 0,
17287
+ attrs: { provisional: true }
17288
+ });
17289
+ }
17290
+ function induceAbstractions(l2, opts) {
17291
+ const K = opts.minClusterSize ?? DEFAULT_MIN_CLUSTER_SIZE;
17292
+ const minCtx = opts.minDistinctContexts ?? DEFAULT_MIN_DISTINCT_CONTEXTS;
17293
+ const report = {
17294
+ communities: 0,
17295
+ candidatesMinted: 0,
17296
+ candidatesExisting: 0,
17297
+ skippedSmall: 0,
17298
+ skippedSingleContext: 0,
17299
+ generalizesEdges: 0
17300
+ };
17301
+ const ids = /* @__PURE__ */ new Set();
17302
+ for (const label of PERCOLATING_LABELS) {
17303
+ for (const n of l2.findNodesByLabel(label)) {
17304
+ if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) >= ABSTRACTION_LEVEL.PRINCIPLE) {
17305
+ continue;
17306
+ }
17307
+ if (n.attrs["resolvedAs"] === PROBLEM_RESOLUTION.FALSE_POSITIVE) continue;
17308
+ ids.add(n.id);
17309
+ }
17310
+ }
17311
+ if (ids.size === 0) return report;
17312
+ const adj = /* @__PURE__ */ new Map();
17313
+ const protect = [];
17314
+ const add = (a, b, w) => {
17315
+ const l = adj.get(a) ?? [];
17316
+ l.push({ to: b, weight: w });
17317
+ adj.set(a, l);
17318
+ };
17319
+ for (const id of ids) {
17320
+ for (const e of l2.outEdges(id, [...PERCOLATING_EDGES])) {
17321
+ if (!ids.has(e.to)) continue;
17322
+ const conf = e.confidence > 0 ? e.confidence : 0.5;
17323
+ const w = Math.max(EDGE_WEIGHT[e.type] ?? 1, 0.1) * conf;
17324
+ add(id, e.to, w);
17325
+ add(e.to, id, w);
17326
+ if (isCausalProtected(e.type)) protect.push([id, e.to]);
17327
+ }
17328
+ }
17329
+ const comm = detectCommunitiesLeiden({ nodeIds: [...ids], adj }, { protect });
17330
+ report.communities = comm.count;
17331
+ const members = /* @__PURE__ */ new Map();
17332
+ for (const [id, c] of comm.community) {
17333
+ const l = members.get(c) ?? [];
17334
+ l.push(id);
17335
+ members.set(c, l);
17336
+ }
17337
+ l2.transaction(() => {
17338
+ for (const mem of members.values()) {
17339
+ if (opts.touched && !mem.some((id) => opts.touched.has(id))) continue;
17340
+ if (mem.length < K) {
17341
+ report.skippedSmall++;
17342
+ continue;
17343
+ }
17344
+ if (mem.some((id) => l2.inEdges(id, ["GENERALIZES"]).length > 0)) {
17345
+ report.candidatesExisting++;
17346
+ continue;
17347
+ }
17348
+ const contexts = /* @__PURE__ */ new Set();
17349
+ for (const id of mem) {
17350
+ const n = l2.getNode(id);
17351
+ const obs = n?.attrs["observedInProjects"];
17352
+ if (Array.isArray(obs)) {
17353
+ for (const ws of obs) contexts.add(opts.contextOf(ws) ?? `project:${ws}`);
17354
+ }
17355
+ }
17356
+ if (contexts.size < minCtx) {
17357
+ report.skippedSingleContext++;
17358
+ continue;
17359
+ }
17360
+ const sorted = [...mem].sort();
17361
+ const principleId = `princ_${digest({ members: sorted })}`.slice(0, 56);
17362
+ l2.mergeNode(
17363
+ buildCandidate(principleId, opts.ts, sorted, [...contexts].sort(), opts.originMachine, sharedScope(l2, sorted))
17364
+ );
17365
+ for (const id of sorted) {
17366
+ mergeGeneralizes(l2, principleId, id, opts.ts);
17367
+ report.generalizesEdges++;
17368
+ }
17369
+ report.candidatesMinted++;
17370
+ }
17371
+ });
17372
+ return report;
17373
+ }
17374
+ function revisitContradictedPrinciples(l2, ts) {
17375
+ const report = { flagged: 0 };
17376
+ l2.transaction(() => {
17377
+ for (const n of l2.findNodesByLabel("Claim")) {
17378
+ if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) < ABSTRACTION_LEVEL.PRINCIPLE) continue;
17379
+ if (n.attrs["revisit"] === true) continue;
17380
+ const members = Array.isArray(n.attrs["members"]) ? n.attrs["members"] : [];
17381
+ const memberSet = new Set(members);
17382
+ let reason = "";
17383
+ for (const id of members) {
17384
+ const m = l2.getNode(id);
17385
+ if (!m) {
17386
+ reason = `member ${id} was removed`;
17387
+ break;
17388
+ }
17389
+ if (m.attrs["revisit"] === true) {
17390
+ reason = `member "${m.description}" needs revisit`;
17391
+ break;
17392
+ }
17393
+ const contradictors = [
17394
+ ...l2.outEdges(id, ["CONTRADICTS"]).map((e) => e.to),
17395
+ ...l2.inEdges(id, ["CONTRADICTS"]).map((e) => e.from)
17396
+ ];
17397
+ if (contradictors.some((other) => !memberSet.has(other))) {
17398
+ reason = `member "${m.description}" is now contradicted by external evidence`;
17399
+ break;
17400
+ }
17401
+ }
17402
+ if (!reason) continue;
17403
+ l2.updateNode(n.id, {
17404
+ attrs: {
17405
+ ...n.attrs,
17406
+ revisit: true,
17407
+ revisitReason: reason,
17408
+ revisitSinceTs: ts,
17409
+ provisional: true,
17410
+ // re-queue for re-distillation (P3 re-name)
17411
+ pendingDistillation: true
17412
+ },
17413
+ lastUpdatedAt: ts
17414
+ });
17415
+ report.flagged++;
17416
+ }
17417
+ });
17418
+ return report;
17419
+ }
17420
+
17421
+ // ../../packages/local-graph/src/community.ts
17422
+ init_src2();
17423
+
17424
17424
  // ../../packages/local-graph/src/problem-dedup.ts
17425
17425
  init_src();
17426
17426
  init_src();