@inerrata-corporation/errata 2.0.2-dev.95 → 2.0.2-dev.982
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.
- package/consolidate-worker.mjs +590 -238
- package/errata.mjs +8504 -2292
- package/package.json +1 -1
- package/pass-worker.mjs +1311 -297
package/consolidate-worker.mjs
CHANGED
|
@@ -133,7 +133,14 @@ var init_castalia = __esm({
|
|
|
133
133
|
"SOLVED_BY",
|
|
134
134
|
"MITIGATES",
|
|
135
135
|
"REPORTED_FAILURE",
|
|
136
|
-
"CONTRADICTS"
|
|
136
|
+
"CONTRADICTS",
|
|
137
|
+
// Motif twin-faces (KN-twin-faces): failure-face motif → remedy-face motif
|
|
138
|
+
// across layers (AntiPattern/Weakness ↔ Technique/Pattern). Same
|
|
139
|
+
// problem→fix direction as FIXED_BY/SOLVED_BY. Minted by the nightly LLM
|
|
140
|
+
// twin-face pass — these are the near-identical cross-layer pairs the
|
|
141
|
+
// polarity gate (finding 5) correctly refuses to FUSE; the link carries
|
|
142
|
+
// what fusion can't.
|
|
143
|
+
"REMEDIED_BY"
|
|
137
144
|
];
|
|
138
145
|
CONCEPTUAL_EDGES = [
|
|
139
146
|
"INSTANCE_OF",
|
|
@@ -223,6 +230,10 @@ var init_castalia = __esm({
|
|
|
223
230
|
CAUSED_BY: 3,
|
|
224
231
|
FIXED_BY: 3,
|
|
225
232
|
SOLVED_BY: 3,
|
|
233
|
+
// Twin-face link (failure motif → remedy motif, KN-twin-faces) — causal-grade
|
|
234
|
+
// but a notch below witnessed FIXED_BY/SOLVED_BY: the pairing is an LLM
|
|
235
|
+
// judgment over descriptions, not an agent-witnessed resolution.
|
|
236
|
+
REMEDIED_BY: 2.5,
|
|
226
237
|
MANIFESTS_AS: 2,
|
|
227
238
|
ESCALATES_TO: 1.5,
|
|
228
239
|
AFFECTS: 1.2,
|
|
@@ -662,7 +673,7 @@ function lemma(token) {
|
|
|
662
673
|
}
|
|
663
674
|
return token;
|
|
664
675
|
}
|
|
665
|
-
function
|
|
676
|
+
function tokenize(text, resolve) {
|
|
666
677
|
const matches = text.normalize("NFC").toLowerCase().match(TOKEN_RE) ?? [];
|
|
667
678
|
const out = /* @__PURE__ */ new Set();
|
|
668
679
|
for (const raw of matches) {
|
|
@@ -672,11 +683,14 @@ function conceptTokens(text) {
|
|
|
672
683
|
out.add(token);
|
|
673
684
|
continue;
|
|
674
685
|
}
|
|
675
|
-
const canonical =
|
|
686
|
+
const canonical = resolve(token);
|
|
676
687
|
out.add(canonical ?? lemma(token));
|
|
677
688
|
}
|
|
678
689
|
return [...out].sort();
|
|
679
690
|
}
|
|
691
|
+
function conceptTokens(text) {
|
|
692
|
+
return tokenize(text, resolveCanonicalId);
|
|
693
|
+
}
|
|
680
694
|
function conceptBag(text) {
|
|
681
695
|
return conceptTokens(text).join(" ");
|
|
682
696
|
}
|
|
@@ -15203,7 +15217,12 @@ var init_edge_rules = __esm({
|
|
|
15203
15217
|
// ── Taxonomy (Track 4 Stream C: MITRE CWE `ChildOf` → `Weakness —IS_A→ Weakness`) ──
|
|
15204
15218
|
IS_A: { from: ["Weakness"], to: ["Weakness"] },
|
|
15205
15219
|
// ── Conceptual (v1 taxonomy.ts: instance → motif/pattern reference) ──
|
|
15206
|
-
|
|
15220
|
+
// `AntiPattern` joined the target set 2026-08-02: it is one of the three motif
|
|
15221
|
+
// kinds (generalizer motifs.ts `layerOf`: pattern | technique | antipattern) and
|
|
15222
|
+
// the SUPPRESSED-close path mints `Problem ─INSTANCE_OF→ AntiPattern` as the
|
|
15223
|
+
// negative-knowledge binding ("silenced, not solved") — the original three-label
|
|
15224
|
+
// rule predates AntiPattern joining the motif layer and silently ate that edge.
|
|
15225
|
+
INSTANCE_OF: { to: ["Pattern", "AntiPattern", "Weakness", "Technique"] },
|
|
15207
15226
|
IMPLEMENTS: { from: ["Solution", "Language", "Component"], to: ["Pattern", "Technique"] },
|
|
15208
15227
|
MATCHES: { to: ["Pattern"] },
|
|
15209
15228
|
// ── Artifact evidence (v1 taxonomy.ts artifact rows) ──
|
|
@@ -15304,6 +15323,23 @@ var init_wire = __esm({
|
|
|
15304
15323
|
/** Canonical human-readable description (no raw paths — daemon scrubs; server rechecks). */
|
|
15305
15324
|
description: external_exports.string().min(1).max(4e3),
|
|
15306
15325
|
attrs: external_exports.record(external_exports.string(), external_exports.unknown()).default({}),
|
|
15326
|
+
/** One-way origin key of the SESSION that minted this node (`ws_…`, a
|
|
15327
|
+
* truncated digest — never the raw session id). Stamped onto the created
|
|
15328
|
+
* node as `authoringSession`, which is the independence unit for the
|
|
15329
|
+
* evidence channels: the session that authored a claim may not corroborate
|
|
15330
|
+
* or refute it, while a DIFFERENT session on the same checkout may (alyssa,
|
|
15331
|
+
* 2026-07-31 — the workspace key made every witness on a single-checkout
|
|
15332
|
+
* deployment a self-corroboration). Optional + additive: absent leaves the
|
|
15333
|
+
* gate fail-open for that node, exactly today's behaviour. */
|
|
15334
|
+
originSession: external_exports.string().min(3).max(64).optional(),
|
|
15335
|
+
/** Epoch ms of the ORIGINATING local node's creation — when the knowledge was
|
|
15336
|
+
* actually captured, as opposed to when its public twin reached the cloud.
|
|
15337
|
+
* Stored as `observedAt`; the network board's chronological view orders on
|
|
15338
|
+
* it. Without this the wire carried NO timestamp at all, so a node captured
|
|
15339
|
+
* days ago surfaced as "new" the moment it was generalized and published —
|
|
15340
|
+
* the board showed ingest order wearing a chronology's clothes. Optional +
|
|
15341
|
+
* additive: absent keeps ingest-time ordering for that node. */
|
|
15342
|
+
originCreatedAtMs: external_exports.number().int().positive().optional(),
|
|
15307
15343
|
extractionSource: external_exports.enum(INGEST_EXTRACTION_SOURCES),
|
|
15308
15344
|
validationSource: external_exports.enum(VALIDATION_SOURCES).optional(),
|
|
15309
15345
|
/** Org-membrane (M2): the daemon's anchor tag — it owns the lockfile, so it
|
|
@@ -15404,7 +15440,7 @@ var init_canonicalize = __esm({
|
|
|
15404
15440
|
|
|
15405
15441
|
// ../../packages/shared/src/nlp/triage-canon.ts
|
|
15406
15442
|
function canonicalizeToken(t) {
|
|
15407
|
-
const base = t.trim().toLowerCase().replace(/
|
|
15443
|
+
const base = t.trim().toLowerCase().replace(/(?!^)@.*$|\s.*$/, "");
|
|
15408
15444
|
if (!base) return "";
|
|
15409
15445
|
return resolveCanonicalId(base) ?? base;
|
|
15410
15446
|
}
|
|
@@ -15486,6 +15522,51 @@ var init_review = __esm({
|
|
|
15486
15522
|
}
|
|
15487
15523
|
});
|
|
15488
15524
|
|
|
15525
|
+
// ../../packages/local-shared/src/anchorable.ts
|
|
15526
|
+
function anchorableExtensionAlternation() {
|
|
15527
|
+
return BY_LENGTH.map((e) => e.slice(1).replace(/[+.]/g, (c) => `\\${c}`)).join("|");
|
|
15528
|
+
}
|
|
15529
|
+
var ANCHORABLE_EXTENSIONS, BY_LENGTH;
|
|
15530
|
+
var init_anchorable = __esm({
|
|
15531
|
+
"../../packages/local-shared/src/anchorable.ts"() {
|
|
15532
|
+
"use strict";
|
|
15533
|
+
ANCHORABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
15534
|
+
// typescript provider
|
|
15535
|
+
".ts",
|
|
15536
|
+
".tsx",
|
|
15537
|
+
".js",
|
|
15538
|
+
".jsx",
|
|
15539
|
+
".mjs",
|
|
15540
|
+
".cjs",
|
|
15541
|
+
// python / go / rust / ruby / csharp providers
|
|
15542
|
+
".py",
|
|
15543
|
+
".go",
|
|
15544
|
+
".rs",
|
|
15545
|
+
".rb",
|
|
15546
|
+
".cs",
|
|
15547
|
+
// cpp provider — every variant it parses, not just the three that were listed
|
|
15548
|
+
".c",
|
|
15549
|
+
".h",
|
|
15550
|
+
".cpp",
|
|
15551
|
+
".cc",
|
|
15552
|
+
".cxx",
|
|
15553
|
+
".c++",
|
|
15554
|
+
".hpp",
|
|
15555
|
+
".hh",
|
|
15556
|
+
".hxx",
|
|
15557
|
+
".h++",
|
|
15558
|
+
// CUDA — the cpp provider parses these too. Missed when this list was first
|
|
15559
|
+
// transcribed by hand; the parity test caught them on its very first run,
|
|
15560
|
+
// which is the argument for the test existing.
|
|
15561
|
+
".cu",
|
|
15562
|
+
".cuh",
|
|
15563
|
+
// no provider yet; the grammar ships. Inert, not wrong — see above.
|
|
15564
|
+
".java"
|
|
15565
|
+
]);
|
|
15566
|
+
BY_LENGTH = [...ANCHORABLE_EXTENSIONS].sort((a, b) => b.length - a.length);
|
|
15567
|
+
}
|
|
15568
|
+
});
|
|
15569
|
+
|
|
15489
15570
|
// ../../packages/local-shared/src/sqlite-adapter.ts
|
|
15490
15571
|
function openDatabase(path) {
|
|
15491
15572
|
const db = new DatabaseSync(path);
|
|
@@ -15498,6 +15579,7 @@ function openDatabase(path) {
|
|
|
15498
15579
|
db.exec("PRAGMA journal_mode = WAL");
|
|
15499
15580
|
db.exec("PRAGMA synchronous = NORMAL");
|
|
15500
15581
|
db.exec("PRAGMA busy_timeout = 5000");
|
|
15582
|
+
db.exec("PRAGMA journal_size_limit = 67108864");
|
|
15501
15583
|
} catch {
|
|
15502
15584
|
}
|
|
15503
15585
|
}
|
|
@@ -15533,7 +15615,7 @@ function openDatabase(path) {
|
|
|
15533
15615
|
return db.prepare(`PRAGMA ${key}`).get();
|
|
15534
15616
|
},
|
|
15535
15617
|
transaction(fn) {
|
|
15536
|
-
db.exec("BEGIN");
|
|
15618
|
+
db.exec("BEGIN IMMEDIATE");
|
|
15537
15619
|
try {
|
|
15538
15620
|
const r = fn();
|
|
15539
15621
|
db.exec("COMMIT");
|
|
@@ -15587,10 +15669,21 @@ var init_src2 = __esm({
|
|
|
15587
15669
|
init_profile();
|
|
15588
15670
|
init_daemon_wire();
|
|
15589
15671
|
init_review();
|
|
15672
|
+
init_anchorable();
|
|
15590
15673
|
init_sqlite_adapter();
|
|
15591
15674
|
}
|
|
15592
15675
|
});
|
|
15593
15676
|
|
|
15677
|
+
// ../../packages/indexer/src/parse-cache.ts
|
|
15678
|
+
var ENTRY_TTL_MS, MAX_ENTRY_BYTES;
|
|
15679
|
+
var init_parse_cache = __esm({
|
|
15680
|
+
"../../packages/indexer/src/parse-cache.ts"() {
|
|
15681
|
+
"use strict";
|
|
15682
|
+
ENTRY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
15683
|
+
MAX_ENTRY_BYTES = 2 * 1024 * 1024;
|
|
15684
|
+
}
|
|
15685
|
+
});
|
|
15686
|
+
|
|
15594
15687
|
// ../../packages/indexer/src/simhash.ts
|
|
15595
15688
|
var MASK64;
|
|
15596
15689
|
var init_simhash = __esm({
|
|
@@ -15613,6 +15706,7 @@ var init_pipeline = __esm({
|
|
|
15613
15706
|
"../../packages/indexer/src/pipeline.ts"() {
|
|
15614
15707
|
"use strict";
|
|
15615
15708
|
init_src2();
|
|
15709
|
+
init_parse_cache();
|
|
15616
15710
|
init_identity2();
|
|
15617
15711
|
}
|
|
15618
15712
|
});
|
|
@@ -15752,9 +15846,32 @@ var LOCAL_RULE_OVERRIDES = {
|
|
|
15752
15846
|
to: [...CODE_NODE_LABELS, "Symbol"]
|
|
15753
15847
|
},
|
|
15754
15848
|
REVEALED_BY: null,
|
|
15755
|
-
PRODUCED: null
|
|
15849
|
+
PRODUCED: null,
|
|
15850
|
+
// FIXED_BY locally ALSO carries the fix-provenance sense: `resolveProblem`
|
|
15851
|
+
// attributes a closed Problem to the fixing `Episode` (PLAN_PLASTICITY §2.1)
|
|
15852
|
+
// alongside the cloud's Problem→Solution knowledge claim. Same shape as
|
|
15853
|
+
// PRODUCED/REVEALED_BY above — an Episode is code-layer and never drains, so
|
|
15854
|
+
// the cloud door's `to: [Solution]` rule is untouched. The `from` constraint
|
|
15855
|
+
// stays: the reversed (Solution)-FIXED_BY->(...) splash bug is the reason
|
|
15856
|
+
// this rule exists at all.
|
|
15857
|
+
FIXED_BY: { from: EDGE_RULES["FIXED_BY"]?.from, to: ["Solution", "Episode"] }
|
|
15756
15858
|
};
|
|
15757
|
-
|
|
15859
|
+
function localEdgeViolation(fromLabel, type, toLabel) {
|
|
15860
|
+
if (type in LOCAL_RULE_OVERRIDES) {
|
|
15861
|
+
const rule = LOCAL_RULE_OVERRIDES[type];
|
|
15862
|
+
if (!rule) return null;
|
|
15863
|
+
if (fromLabel && rule.from && !rule.from.includes(fromLabel)) {
|
|
15864
|
+
return `${type} cannot originate from ${fromLabel} locally (allowed: ${rule.from.join(", ")})`;
|
|
15865
|
+
}
|
|
15866
|
+
if (toLabel && rule.to && !rule.to.includes(toLabel)) {
|
|
15867
|
+
return `${type} cannot target ${toLabel} locally (allowed: ${rule.to.join(", ")})`;
|
|
15868
|
+
}
|
|
15869
|
+
return null;
|
|
15870
|
+
}
|
|
15871
|
+
const verdict = isValidEdge(fromLabel, type, toLabel);
|
|
15872
|
+
return verdict.ok ? null : verdict.reason ?? "edge rule violation";
|
|
15873
|
+
}
|
|
15874
|
+
var SCHEMA_VERSION = 6;
|
|
15758
15875
|
var SCHEMA_SQL = `
|
|
15759
15876
|
CREATE TABLE IF NOT EXISTS schema_version (
|
|
15760
15877
|
version INTEGER PRIMARY KEY
|
|
@@ -15769,6 +15886,21 @@ CREATE TABLE IF NOT EXISTS store_meta (
|
|
|
15769
15886
|
value TEXT NOT NULL
|
|
15770
15887
|
);
|
|
15771
15888
|
|
|
15889
|
+
-- Durable ledger of edges the ontology gate REFUSED, keyed by edge type.
|
|
15890
|
+
-- Durable rather than in-memory for one specific reason: the status command runs
|
|
15891
|
+
-- in a SEPARATE process and opens its own store handle, so a counter living on
|
|
15892
|
+
-- the instance reads 0 there forever. That is exactly how a producer rejecting
|
|
15893
|
+
-- 100% of its output stayed invisible for 17 days. Persisting it also survives
|
|
15894
|
+
-- the daemon restart that would otherwise erase the evidence.
|
|
15895
|
+
-- Keyed by type because a systematic producer bug shows up as ONE type
|
|
15896
|
+
-- dominating; sample keeps the latest reason so the count is actionable.
|
|
15897
|
+
CREATE TABLE IF NOT EXISTS edge_rejections (
|
|
15898
|
+
type TEXT PRIMARY KEY,
|
|
15899
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
15900
|
+
last_at INTEGER NOT NULL,
|
|
15901
|
+
sample TEXT
|
|
15902
|
+
);
|
|
15903
|
+
|
|
15772
15904
|
CREATE TABLE IF NOT EXISTS nodes (
|
|
15773
15905
|
id TEXT PRIMARY KEY,
|
|
15774
15906
|
label TEXT NOT NULL,
|
|
@@ -16145,6 +16277,16 @@ var SqliteGraphStore = class {
|
|
|
16145
16277
|
if (!cols.has(name)) this.db.exec(ddl);
|
|
16146
16278
|
}
|
|
16147
16279
|
}
|
|
16280
|
+
if (from < 6) {
|
|
16281
|
+
this.db.exec(`
|
|
16282
|
+
CREATE TABLE IF NOT EXISTS edge_rejections (
|
|
16283
|
+
type TEXT PRIMARY KEY,
|
|
16284
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
16285
|
+
last_at INTEGER NOT NULL,
|
|
16286
|
+
sample TEXT
|
|
16287
|
+
)
|
|
16288
|
+
`);
|
|
16289
|
+
}
|
|
16148
16290
|
this.db.prepare("UPDATE schema_version SET version = ?").run(SCHEMA_VERSION);
|
|
16149
16291
|
});
|
|
16150
16292
|
}
|
|
@@ -16226,6 +16368,7 @@ var SqliteGraphStore = class {
|
|
|
16226
16368
|
const violation = this.edgeRuleViolation(edge);
|
|
16227
16369
|
if (violation) {
|
|
16228
16370
|
this.rejectedEdgeCount++;
|
|
16371
|
+
this.recordEdgeRejection(edge.type, violation, edge.lastSeenAt || edge.createdAt || 0);
|
|
16229
16372
|
console.warn(`[local-graph] rejected edge ${edge.from}-[:${edge.type}]->${edge.to}: ${violation}`);
|
|
16230
16373
|
return;
|
|
16231
16374
|
}
|
|
@@ -16250,22 +16393,51 @@ var SqliteGraphStore = class {
|
|
|
16250
16393
|
* overlay consulted first. Returns the reason string on a documented-
|
|
16251
16394
|
* forbidden combination, else null. Point lookups on the id PK — negligible
|
|
16252
16395
|
* next to the insert itself. */
|
|
16253
|
-
|
|
16254
|
-
|
|
16255
|
-
|
|
16256
|
-
|
|
16257
|
-
|
|
16258
|
-
|
|
16259
|
-
|
|
16260
|
-
|
|
16261
|
-
|
|
16262
|
-
|
|
16263
|
-
|
|
16264
|
-
|
|
16265
|
-
|
|
16396
|
+
/** Upsert one refusal into the durable ledger. Best-effort: a bookkeeping
|
|
16397
|
+
* failure must never turn a refused edge into a thrown write. */
|
|
16398
|
+
recordEdgeRejection(type, reason, at) {
|
|
16399
|
+
try {
|
|
16400
|
+
this.db.prepare(
|
|
16401
|
+
`INSERT INTO edge_rejections (type, count, last_at, sample) VALUES (?, 1, ?, ?)
|
|
16402
|
+
ON CONFLICT(type) DO UPDATE SET
|
|
16403
|
+
count = count + 1, last_at = excluded.last_at, sample = excluded.sample`
|
|
16404
|
+
).run(type, at, reason.slice(0, 200));
|
|
16405
|
+
} catch {
|
|
16406
|
+
}
|
|
16407
|
+
}
|
|
16408
|
+
/** Refusals recorded by the ontology gate, per edge type, newest activity first.
|
|
16409
|
+
* Durable across restarts and readable from any process (see the table note). */
|
|
16410
|
+
edgeRejections() {
|
|
16411
|
+
try {
|
|
16412
|
+
return this.db.prepare(
|
|
16413
|
+
"SELECT type, count, last_at AS lastAt, sample FROM edge_rejections ORDER BY count DESC, last_at DESC"
|
|
16414
|
+
).all();
|
|
16415
|
+
} catch {
|
|
16416
|
+
return [];
|
|
16417
|
+
}
|
|
16418
|
+
}
|
|
16419
|
+
/** Drop ledger entries whose last refusal predates `cutoff`. A still-misbehaving
|
|
16420
|
+
* producer keeps refreshing `last_at` and survives; a fixed one fades out. */
|
|
16421
|
+
pruneEdgeRejections(cutoff) {
|
|
16422
|
+
try {
|
|
16423
|
+
this.db.prepare("DELETE FROM edge_rejections WHERE last_at < ?").run(cutoff);
|
|
16424
|
+
} catch {
|
|
16425
|
+
}
|
|
16426
|
+
}
|
|
16427
|
+
/** Clear the ledger outright, whole or per type — operator escape hatch. */
|
|
16428
|
+
clearEdgeRejections(type) {
|
|
16429
|
+
try {
|
|
16430
|
+
if (type) this.db.prepare("DELETE FROM edge_rejections WHERE type = ?").run(type);
|
|
16431
|
+
else this.db.exec("DELETE FROM edge_rejections");
|
|
16432
|
+
} catch {
|
|
16266
16433
|
}
|
|
16267
|
-
|
|
16268
|
-
|
|
16434
|
+
}
|
|
16435
|
+
edgeRuleViolation(edge) {
|
|
16436
|
+
return localEdgeViolation(
|
|
16437
|
+
this.getNode(edge.from)?.label,
|
|
16438
|
+
edge.type,
|
|
16439
|
+
this.getNode(edge.to)?.label
|
|
16440
|
+
);
|
|
16269
16441
|
}
|
|
16270
16442
|
updateEdge(id, patch) {
|
|
16271
16443
|
this.stmts.updateEdge.run({
|
|
@@ -16402,6 +16574,163 @@ var SqliteGraphStore = class {
|
|
|
16402
16574
|
const rows = this.db.prepare("SELECT from_id, to_id, type FROM edges WHERE valid_to IS NULL").all();
|
|
16403
16575
|
return rows.map((r) => ({ from: r.from_id, to: r.to_id, type: r.type }));
|
|
16404
16576
|
}
|
|
16577
|
+
getMeta(key) {
|
|
16578
|
+
const r = this.db.prepare("SELECT value FROM store_meta WHERE key = ?").get(key);
|
|
16579
|
+
return r?.value ?? null;
|
|
16580
|
+
}
|
|
16581
|
+
setMeta(key, value) {
|
|
16582
|
+
this.db.prepare(
|
|
16583
|
+
"INSERT INTO store_meta (key, value) VALUES (:key, :value) ON CONFLICT(key) DO UPDATE SET value = excluded.value"
|
|
16584
|
+
).run({ key, value });
|
|
16585
|
+
}
|
|
16586
|
+
dirtyNodeIdsSince(ts) {
|
|
16587
|
+
const rows = this.db.prepare("SELECT id FROM nodes WHERE valid_to IS NULL AND last_updated_at > ?").all(ts);
|
|
16588
|
+
return rows.map((r) => r.id);
|
|
16589
|
+
}
|
|
16590
|
+
/** Endpoints of edges TOUCHED since `ts` — created, re-seen, or CLOSED.
|
|
16591
|
+
* Closures matter as much as additions: a node that lost inflow is rank-dirty
|
|
16592
|
+
* while its own row never updated, so removal endpoints must seed the
|
|
16593
|
+
* incremental region or the stale inflow persists until the full backstop. */
|
|
16594
|
+
edgeEndpointsTouchedSince(ts) {
|
|
16595
|
+
const rows = this.db.prepare(
|
|
16596
|
+
`SELECT from_id, to_id FROM edges
|
|
16597
|
+
WHERE (valid_to IS NULL AND (created_at > :ts OR last_seen_at > :ts))
|
|
16598
|
+
OR (valid_to IS NOT NULL AND valid_to > :ts)`
|
|
16599
|
+
).all({ ts });
|
|
16600
|
+
return rows.map((r) => ({ from: r.from_id, to: r.to_id }));
|
|
16601
|
+
}
|
|
16602
|
+
/** Lightweight out-edges for a SET of sources, chunked IN-lists — the region
|
|
16603
|
+
* assembly path for incremental PageRank (per-node outEdges() at region
|
|
16604
|
+
* scale re-creates the 106k-prepared-calls problem the batch scan solved). */
|
|
16605
|
+
outEdgesForMany(ids) {
|
|
16606
|
+
return this.edgesForMany(ids, "from_id");
|
|
16607
|
+
}
|
|
16608
|
+
inEdgesForMany(ids) {
|
|
16609
|
+
return this.edgesForMany(ids, "to_id");
|
|
16610
|
+
}
|
|
16611
|
+
/** Stored pageRank for a SET of ids (live rows only — a closed id is simply
|
|
16612
|
+
* absent, which is how incremental region assembly drops dead endpoints). */
|
|
16613
|
+
ranksForMany(ids) {
|
|
16614
|
+
const out = /* @__PURE__ */ new Map();
|
|
16615
|
+
const CHUNK = 400;
|
|
16616
|
+
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
16617
|
+
const chunk = ids.slice(i, i + CHUNK);
|
|
16618
|
+
const placeholders = chunk.map(() => "?").join(", ");
|
|
16619
|
+
const rows = this.db.prepare(
|
|
16620
|
+
`SELECT id, page_rank FROM nodes WHERE id IN (${placeholders}) AND valid_to IS NULL`
|
|
16621
|
+
).all(...chunk);
|
|
16622
|
+
for (const r of rows) out.set(r.id, r.page_rank);
|
|
16623
|
+
}
|
|
16624
|
+
return out;
|
|
16625
|
+
}
|
|
16626
|
+
/** The minimal row set the landmark sweep needs — landmark CANDIDATES
|
|
16627
|
+
* (Pattern/RootCause), everything currently flagged, and every
|
|
16628
|
+
* persistent-tier node (force-landmarks). A few thousand rows, so the
|
|
16629
|
+
* incremental path can refresh the GLOBAL landmark set without the 179k-row
|
|
16630
|
+
* scanLiveNodes materialization. */
|
|
16631
|
+
landmarkSweepRows() {
|
|
16632
|
+
const rows = this.db.prepare(
|
|
16633
|
+
`SELECT id, label, page_rank, is_landmark, memory_tier, extraction_source FROM nodes
|
|
16634
|
+
WHERE valid_to IS NULL
|
|
16635
|
+
AND (memory_tier = 'persistent' OR is_landmark = 1 OR label IN ('Pattern', 'RootCause'))`
|
|
16636
|
+
).all();
|
|
16637
|
+
return rows.map((r) => ({
|
|
16638
|
+
id: r.id,
|
|
16639
|
+
label: r.label,
|
|
16640
|
+
pageRank: r.page_rank,
|
|
16641
|
+
isLandmark: r.is_landmark === 1,
|
|
16642
|
+
memoryTier: r.memory_tier,
|
|
16643
|
+
extractionSource: r.extraction_source
|
|
16644
|
+
}));
|
|
16645
|
+
}
|
|
16646
|
+
edgesForMany(ids, col) {
|
|
16647
|
+
const out = [];
|
|
16648
|
+
const CHUNK = 400;
|
|
16649
|
+
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
16650
|
+
const chunk = ids.slice(i, i + CHUNK);
|
|
16651
|
+
const placeholders = chunk.map(() => "?").join(", ");
|
|
16652
|
+
const rows = this.db.prepare(
|
|
16653
|
+
`SELECT from_id, to_id, type FROM edges WHERE ${col} IN (${placeholders}) AND valid_to IS NULL`
|
|
16654
|
+
).all(...chunk);
|
|
16655
|
+
for (const r of rows) out.push({ from: r.from_id, to: r.to_id, type: r.type });
|
|
16656
|
+
}
|
|
16657
|
+
return out;
|
|
16658
|
+
}
|
|
16659
|
+
checkpointWal() {
|
|
16660
|
+
try {
|
|
16661
|
+
const r = this.db.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get();
|
|
16662
|
+
return r ?? null;
|
|
16663
|
+
} catch {
|
|
16664
|
+
return null;
|
|
16665
|
+
}
|
|
16666
|
+
}
|
|
16667
|
+
reviveReobserved(relPaths, workspaceId, since) {
|
|
16668
|
+
let revived = 0;
|
|
16669
|
+
const CHUNK = 400;
|
|
16670
|
+
for (let i = 0; i < relPaths.length; i += CHUNK) {
|
|
16671
|
+
const slice = relPaths.slice(i, i + CHUNK);
|
|
16672
|
+
if (slice.length === 0) continue;
|
|
16673
|
+
const r = this.db.prepare(
|
|
16674
|
+
`UPDATE nodes SET valid_to = NULL
|
|
16675
|
+
WHERE valid_to IS NOT NULL
|
|
16676
|
+
AND last_updated_at >= ?
|
|
16677
|
+
AND json_extract(attrs_json, '$.workspaceId') = ?
|
|
16678
|
+
AND json_extract(attrs_json, '$.relPath') IN (${slice.map(() => "?").join(",")})`
|
|
16679
|
+
).run(since, workspaceId, ...slice);
|
|
16680
|
+
revived += Number(r.changes);
|
|
16681
|
+
}
|
|
16682
|
+
if (revived > 0) this.mutations++;
|
|
16683
|
+
return revived;
|
|
16684
|
+
}
|
|
16685
|
+
recentEdgeAttrCoverage(marker, attr, limit) {
|
|
16686
|
+
const r = this.db.prepare(
|
|
16687
|
+
`SELECT COUNT(*) AS total,
|
|
16688
|
+
COALESCE(SUM(CASE WHEN json_extract(attrs_json, '$.' || ?) = 1 THEN 1 ELSE 0 END), 0) AS count
|
|
16689
|
+
FROM (SELECT attrs_json FROM edges
|
|
16690
|
+
WHERE valid_to IS NULL AND attrs_json LIKE ?
|
|
16691
|
+
ORDER BY created_at DESC LIMIT ?)`
|
|
16692
|
+
).get(attr, `%${marker}%`, limit);
|
|
16693
|
+
return { count: Number(r.count), total: Number(r.total) };
|
|
16694
|
+
}
|
|
16695
|
+
liveNodeIds(ids) {
|
|
16696
|
+
const live = /* @__PURE__ */ new Set();
|
|
16697
|
+
const CHUNK = 900;
|
|
16698
|
+
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
16699
|
+
const slice = ids.slice(i, i + CHUNK);
|
|
16700
|
+
if (slice.length === 0) continue;
|
|
16701
|
+
const rows = this.db.prepare(
|
|
16702
|
+
`SELECT id FROM nodes WHERE valid_to IS NULL AND id IN (${slice.map(() => "?").join(",")})`
|
|
16703
|
+
).all(...slice);
|
|
16704
|
+
for (const r of rows) live.add(r.id);
|
|
16705
|
+
}
|
|
16706
|
+
return live;
|
|
16707
|
+
}
|
|
16708
|
+
/**
|
|
16709
|
+
* Live edges WITH their endpoint labels and ids, resolved in ONE join.
|
|
16710
|
+
*
|
|
16711
|
+
* The ontology sweep needs (id, type, fromLabel, toLabel) for every live edge.
|
|
16712
|
+
* Doing that as `scanLiveEdges()` + two `getNode()` calls is 2N node reads —
|
|
16713
|
+
* 550,000 on this store — and each one deserializes the node's embedding blob.
|
|
16714
|
+
* Measured: the sweep did not finish in 10 minutes. As a single join it is one
|
|
16715
|
+
* query over an index-covered scan. Labels only; nothing here touches embeddings.
|
|
16716
|
+
*/
|
|
16717
|
+
scanLiveEdgeRows() {
|
|
16718
|
+
const rows = this.db.prepare(
|
|
16719
|
+
`SELECT e.id, e.from_id, e.to_id, e.type, a.label AS from_label, b.label AS to_label
|
|
16720
|
+
FROM edges e
|
|
16721
|
+
LEFT JOIN nodes a ON a.id = e.from_id AND a.valid_to IS NULL
|
|
16722
|
+
LEFT JOIN nodes b ON b.id = e.to_id AND b.valid_to IS NULL
|
|
16723
|
+
WHERE e.valid_to IS NULL`
|
|
16724
|
+
).all();
|
|
16725
|
+
return rows.map((r) => ({
|
|
16726
|
+
id: r.id,
|
|
16727
|
+
from: r.from_id,
|
|
16728
|
+
to: r.to_id,
|
|
16729
|
+
type: r.type,
|
|
16730
|
+
fromLabel: r.from_label ?? void 0,
|
|
16731
|
+
toLabel: r.to_label ?? void 0
|
|
16732
|
+
}));
|
|
16733
|
+
}
|
|
16405
16734
|
/** Live nodes whose attrs.relPath is one of `relPaths`. Uses the nodes_relpath
|
|
16406
16735
|
* expression index so the incremental reindex fetches only the changed files'
|
|
16407
16736
|
* symbols instead of scanning every versioned node. */
|
|
@@ -16422,6 +16751,10 @@ var SqliteGraphStore = class {
|
|
|
16422
16751
|
if (!live) return null;
|
|
16423
16752
|
const version2 = live.version ?? 1;
|
|
16424
16753
|
const frozenId = `${liveId}@v${version2}`;
|
|
16754
|
+
if (this.getNode(frozenId)) {
|
|
16755
|
+
this.stmts.advanceLive.run({ live_id: liveId, t });
|
|
16756
|
+
return frozenId;
|
|
16757
|
+
}
|
|
16425
16758
|
this.stmts.freezeCopy.run({ frozen_id: frozenId, live_id: liveId, t });
|
|
16426
16759
|
this.mergeEdge({
|
|
16427
16760
|
id: `edge_superseded_${frozenId}`,
|
|
@@ -16480,6 +16813,7 @@ var CAUSAL_FAMILY = [
|
|
|
16480
16813
|
|
|
16481
16814
|
// ../../packages/local-graph/src/justification.ts
|
|
16482
16815
|
init_src();
|
|
16816
|
+
init_src2();
|
|
16483
16817
|
|
|
16484
16818
|
// ../../packages/local-graph/src/credit.ts
|
|
16485
16819
|
init_src2();
|
|
@@ -16496,11 +16830,28 @@ init_src();
|
|
|
16496
16830
|
// ../../packages/local-graph/src/design-problem.ts
|
|
16497
16831
|
init_src();
|
|
16498
16832
|
init_src();
|
|
16499
|
-
init_src2();
|
|
16500
16833
|
|
|
16501
16834
|
// ../../packages/local-graph/src/problem-package-link.ts
|
|
16502
16835
|
init_src();
|
|
16503
16836
|
|
|
16837
|
+
// ../../packages/local-graph/src/design-problem.ts
|
|
16838
|
+
init_src2();
|
|
16839
|
+
|
|
16840
|
+
// ../../packages/local-graph/src/problem-dedup.ts
|
|
16841
|
+
init_src();
|
|
16842
|
+
init_src();
|
|
16843
|
+
|
|
16844
|
+
// ../../packages/local-graph/src/intent.ts
|
|
16845
|
+
init_src();
|
|
16846
|
+
|
|
16847
|
+
// ../../packages/local-graph/src/anchor-backfill.ts
|
|
16848
|
+
init_src();
|
|
16849
|
+
init_src2();
|
|
16850
|
+
var STATEMENT_PATH_RE = new RegExp(
|
|
16851
|
+
String.raw`(?:[\w.+-]+\/)+[\w.+-]+\.(?:${anchorableExtensionAlternation()})`,
|
|
16852
|
+
"g"
|
|
16853
|
+
);
|
|
16854
|
+
|
|
16504
16855
|
// ../../packages/local-graph/src/percolate.ts
|
|
16505
16856
|
init_src2();
|
|
16506
16857
|
var PERCOLATING_LABELS = ["Claim", "Problem", "Solution"];
|
|
@@ -16771,219 +17122,13 @@ function detectCommunitiesLeiden(input, opts = {}) {
|
|
|
16771
17122
|
return normalize(assignment);
|
|
16772
17123
|
}
|
|
16773
17124
|
|
|
16774
|
-
// ../../packages/local-graph/src/abstraction.ts
|
|
16775
|
-
var DEFAULT_MIN_CLUSTER_SIZE = 3;
|
|
16776
|
-
var DEFAULT_MIN_DISTINCT_CONTEXTS = 2;
|
|
16777
|
-
function sharedScope(l2, memberIds) {
|
|
16778
|
-
const shared = (field) => {
|
|
16779
|
-
const vals = /* @__PURE__ */ new Set();
|
|
16780
|
-
for (const id of memberIds) {
|
|
16781
|
-
const s = l2.getNode(id)?.attrs["scope"] ?? {};
|
|
16782
|
-
if (typeof s[field] === "string") vals.add(s[field]);
|
|
16783
|
-
}
|
|
16784
|
-
return vals.size === 1 ? [...vals][0] : void 0;
|
|
16785
|
-
};
|
|
16786
|
-
const lang = shared("lang");
|
|
16787
|
-
const versionRange = shared("versionRange");
|
|
16788
|
-
return { ...lang ? { lang } : {}, ...versionRange ? { versionRange } : {} };
|
|
16789
|
-
}
|
|
16790
|
-
function buildCandidate(id, ts, members, contexts, originMachine, scope) {
|
|
16791
|
-
return {
|
|
16792
|
-
id,
|
|
16793
|
-
label: "Claim",
|
|
16794
|
-
description: "",
|
|
16795
|
-
// empty — the harness distills the prose in P3
|
|
16796
|
-
extractionConfidence: 0.4,
|
|
16797
|
-
extractionSource: "agent-observed",
|
|
16798
|
-
embedding: [],
|
|
16799
|
-
cumulativeSurprise: 0,
|
|
16800
|
-
peakSurprise: 0,
|
|
16801
|
-
cumulativeHits: 1,
|
|
16802
|
-
lastUpdatedAt: ts,
|
|
16803
|
-
createdAt: ts,
|
|
16804
|
-
memoryTier: "short-term",
|
|
16805
|
-
pageRank: 0,
|
|
16806
|
-
isLandmark: false,
|
|
16807
|
-
community: null,
|
|
16808
|
-
stability: "unstable",
|
|
16809
|
-
attrs: {
|
|
16810
|
-
abstractionLevel: ABSTRACTION_LEVEL.PRINCIPLE,
|
|
16811
|
-
kind: "abstraction-candidate",
|
|
16812
|
-
provisional: true,
|
|
16813
|
-
pendingDistillation: true,
|
|
16814
|
-
// membership is the unit of truth — the harness validates its fence against
|
|
16815
|
-
// this set (P3 / C3) and may only phrase, never alter, it.
|
|
16816
|
-
members,
|
|
16817
|
-
memberContexts: contexts,
|
|
16818
|
-
distinctContexts: contexts.length,
|
|
16819
|
-
// standard Claim envelope so it crystallizes/syncs unchanged once distilled
|
|
16820
|
-
truthKind: "contextual",
|
|
16821
|
-
// Derived from members (P1): a single-language cluster becomes a lang-scoped
|
|
16822
|
-
// principle; a cross-language one stays universal (`{}`).
|
|
16823
|
-
scope,
|
|
16824
|
-
groundedSupport: 0,
|
|
16825
|
-
sources: [],
|
|
16826
|
-
crystallized: "hypothesis",
|
|
16827
|
-
confidence: 0.4,
|
|
16828
|
-
...originMachine ? { originMachine } : {}
|
|
16829
|
-
}
|
|
16830
|
-
};
|
|
16831
|
-
}
|
|
16832
|
-
function mergeGeneralizes(store, principleId, memberId, ts) {
|
|
16833
|
-
store.mergeEdge({
|
|
16834
|
-
id: `edge_${digest({ from: principleId, type: "GENERALIZES", to: memberId })}`.slice(0, 24),
|
|
16835
|
-
from: principleId,
|
|
16836
|
-
to: memberId,
|
|
16837
|
-
type: "GENERALIZES",
|
|
16838
|
-
confidence: 0.4,
|
|
16839
|
-
extractionSource: "agent-observed",
|
|
16840
|
-
createdAt: ts,
|
|
16841
|
-
lastSeenAt: ts,
|
|
16842
|
-
navSuccesses: 0,
|
|
16843
|
-
navFailures: 0,
|
|
16844
|
-
attrs: { provisional: true }
|
|
16845
|
-
});
|
|
16846
|
-
}
|
|
16847
|
-
function induceAbstractions(l2, opts) {
|
|
16848
|
-
const K = opts.minClusterSize ?? DEFAULT_MIN_CLUSTER_SIZE;
|
|
16849
|
-
const minCtx = opts.minDistinctContexts ?? DEFAULT_MIN_DISTINCT_CONTEXTS;
|
|
16850
|
-
const report = {
|
|
16851
|
-
communities: 0,
|
|
16852
|
-
candidatesMinted: 0,
|
|
16853
|
-
candidatesExisting: 0,
|
|
16854
|
-
skippedSmall: 0,
|
|
16855
|
-
skippedSingleContext: 0,
|
|
16856
|
-
generalizesEdges: 0
|
|
16857
|
-
};
|
|
16858
|
-
const ids = /* @__PURE__ */ new Set();
|
|
16859
|
-
for (const label of PERCOLATING_LABELS) {
|
|
16860
|
-
for (const n of l2.findNodesByLabel(label)) {
|
|
16861
|
-
if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) >= ABSTRACTION_LEVEL.PRINCIPLE) {
|
|
16862
|
-
continue;
|
|
16863
|
-
}
|
|
16864
|
-
if (n.attrs["resolvedAs"] === PROBLEM_RESOLUTION.FALSE_POSITIVE) continue;
|
|
16865
|
-
ids.add(n.id);
|
|
16866
|
-
}
|
|
16867
|
-
}
|
|
16868
|
-
if (ids.size === 0) return report;
|
|
16869
|
-
const adj = /* @__PURE__ */ new Map();
|
|
16870
|
-
const protect = [];
|
|
16871
|
-
const add = (a, b, w) => {
|
|
16872
|
-
const l = adj.get(a) ?? [];
|
|
16873
|
-
l.push({ to: b, weight: w });
|
|
16874
|
-
adj.set(a, l);
|
|
16875
|
-
};
|
|
16876
|
-
for (const id of ids) {
|
|
16877
|
-
for (const e of l2.outEdges(id, [...PERCOLATING_EDGES])) {
|
|
16878
|
-
if (!ids.has(e.to)) continue;
|
|
16879
|
-
const conf = e.confidence > 0 ? e.confidence : 0.5;
|
|
16880
|
-
const w = Math.max(EDGE_WEIGHT[e.type] ?? 1, 0.1) * conf;
|
|
16881
|
-
add(id, e.to, w);
|
|
16882
|
-
add(e.to, id, w);
|
|
16883
|
-
if (isCausalProtected(e.type)) protect.push([id, e.to]);
|
|
16884
|
-
}
|
|
16885
|
-
}
|
|
16886
|
-
const comm = detectCommunitiesLeiden({ nodeIds: [...ids], adj }, { protect });
|
|
16887
|
-
report.communities = comm.count;
|
|
16888
|
-
const members = /* @__PURE__ */ new Map();
|
|
16889
|
-
for (const [id, c] of comm.community) {
|
|
16890
|
-
const l = members.get(c) ?? [];
|
|
16891
|
-
l.push(id);
|
|
16892
|
-
members.set(c, l);
|
|
16893
|
-
}
|
|
16894
|
-
l2.transaction(() => {
|
|
16895
|
-
for (const mem of members.values()) {
|
|
16896
|
-
if (opts.touched && !mem.some((id) => opts.touched.has(id))) continue;
|
|
16897
|
-
if (mem.length < K) {
|
|
16898
|
-
report.skippedSmall++;
|
|
16899
|
-
continue;
|
|
16900
|
-
}
|
|
16901
|
-
if (mem.some((id) => l2.inEdges(id, ["GENERALIZES"]).length > 0)) {
|
|
16902
|
-
report.candidatesExisting++;
|
|
16903
|
-
continue;
|
|
16904
|
-
}
|
|
16905
|
-
const contexts = /* @__PURE__ */ new Set();
|
|
16906
|
-
for (const id of mem) {
|
|
16907
|
-
const n = l2.getNode(id);
|
|
16908
|
-
const obs = n?.attrs["observedInProjects"];
|
|
16909
|
-
if (Array.isArray(obs)) {
|
|
16910
|
-
for (const ws of obs) contexts.add(opts.contextOf(ws) ?? `project:${ws}`);
|
|
16911
|
-
}
|
|
16912
|
-
}
|
|
16913
|
-
if (contexts.size < minCtx) {
|
|
16914
|
-
report.skippedSingleContext++;
|
|
16915
|
-
continue;
|
|
16916
|
-
}
|
|
16917
|
-
const sorted = [...mem].sort();
|
|
16918
|
-
const principleId = `princ_${digest({ members: sorted })}`.slice(0, 56);
|
|
16919
|
-
l2.mergeNode(
|
|
16920
|
-
buildCandidate(principleId, opts.ts, sorted, [...contexts].sort(), opts.originMachine, sharedScope(l2, sorted))
|
|
16921
|
-
);
|
|
16922
|
-
for (const id of sorted) {
|
|
16923
|
-
mergeGeneralizes(l2, principleId, id, opts.ts);
|
|
16924
|
-
report.generalizesEdges++;
|
|
16925
|
-
}
|
|
16926
|
-
report.candidatesMinted++;
|
|
16927
|
-
}
|
|
16928
|
-
});
|
|
16929
|
-
return report;
|
|
16930
|
-
}
|
|
16931
|
-
function revisitContradictedPrinciples(l2, ts) {
|
|
16932
|
-
const report = { flagged: 0 };
|
|
16933
|
-
l2.transaction(() => {
|
|
16934
|
-
for (const n of l2.findNodesByLabel("Claim")) {
|
|
16935
|
-
if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) < ABSTRACTION_LEVEL.PRINCIPLE) continue;
|
|
16936
|
-
if (n.attrs["revisit"] === true) continue;
|
|
16937
|
-
const members = Array.isArray(n.attrs["members"]) ? n.attrs["members"] : [];
|
|
16938
|
-
const memberSet = new Set(members);
|
|
16939
|
-
let reason = "";
|
|
16940
|
-
for (const id of members) {
|
|
16941
|
-
const m = l2.getNode(id);
|
|
16942
|
-
if (!m) {
|
|
16943
|
-
reason = `member ${id} was removed`;
|
|
16944
|
-
break;
|
|
16945
|
-
}
|
|
16946
|
-
if (m.attrs["revisit"] === true) {
|
|
16947
|
-
reason = `member "${m.description}" needs revisit`;
|
|
16948
|
-
break;
|
|
16949
|
-
}
|
|
16950
|
-
const contradictors = [
|
|
16951
|
-
...l2.outEdges(id, ["CONTRADICTS"]).map((e) => e.to),
|
|
16952
|
-
...l2.inEdges(id, ["CONTRADICTS"]).map((e) => e.from)
|
|
16953
|
-
];
|
|
16954
|
-
if (contradictors.some((other) => !memberSet.has(other))) {
|
|
16955
|
-
reason = `member "${m.description}" is now contradicted by external evidence`;
|
|
16956
|
-
break;
|
|
16957
|
-
}
|
|
16958
|
-
}
|
|
16959
|
-
if (!reason) continue;
|
|
16960
|
-
l2.updateNode(n.id, {
|
|
16961
|
-
attrs: {
|
|
16962
|
-
...n.attrs,
|
|
16963
|
-
revisit: true,
|
|
16964
|
-
revisitReason: reason,
|
|
16965
|
-
revisitSinceTs: ts,
|
|
16966
|
-
provisional: true,
|
|
16967
|
-
// re-queue for re-distillation (P3 re-name)
|
|
16968
|
-
pendingDistillation: true
|
|
16969
|
-
},
|
|
16970
|
-
lastUpdatedAt: ts
|
|
16971
|
-
});
|
|
16972
|
-
report.flagged++;
|
|
16973
|
-
}
|
|
16974
|
-
});
|
|
16975
|
-
return report;
|
|
16976
|
-
}
|
|
16977
|
-
|
|
16978
|
-
// ../../packages/local-graph/src/community.ts
|
|
16979
|
-
init_src2();
|
|
16980
|
-
|
|
16981
17125
|
// ../../packages/local-graph/src/triage.ts
|
|
16982
17126
|
init_src();
|
|
16983
17127
|
init_src();
|
|
16984
17128
|
init_src();
|
|
16985
17129
|
init_src2();
|
|
16986
|
-
function semNode(id, label, description, ts, attrs) {
|
|
17130
|
+
function semNode(store, id, label, description, ts, attrs) {
|
|
17131
|
+
const seq = SEMANTIC_NODE_LABELS.includes(label) ? store.nextIngestSeq() : void 0;
|
|
16987
17132
|
return {
|
|
16988
17133
|
id,
|
|
16989
17134
|
label,
|
|
@@ -17001,6 +17146,7 @@ function semNode(id, label, description, ts, attrs) {
|
|
|
17001
17146
|
isLandmark: false,
|
|
17002
17147
|
community: null,
|
|
17003
17148
|
stability: "unstable",
|
|
17149
|
+
...seq !== void 0 ? { createdAtSeq: seq, lastReinforcedAtSeq: seq } : {},
|
|
17004
17150
|
attrs
|
|
17005
17151
|
};
|
|
17006
17152
|
}
|
|
@@ -17031,7 +17177,7 @@ function recordTriageObservation(l2, obs, ts) {
|
|
|
17031
17177
|
const buckets = [...triageContextBuckets(canonicalizeContext(obs.context)), TRIAGE_GLOBAL_BUCKET];
|
|
17032
17178
|
l2.transaction(() => {
|
|
17033
17179
|
if (!l2.getNode(presentingId)) {
|
|
17034
|
-
l2.mergeNode(semNode(presentingId, "Problem", statement, ts, { scope: {} }));
|
|
17180
|
+
l2.mergeNode(semNode(l2, presentingId, "Problem", statement, ts, { scope: {} }));
|
|
17035
17181
|
}
|
|
17036
17182
|
const tri = l2.getNode(triageId);
|
|
17037
17183
|
const seen = {
|
|
@@ -17045,7 +17191,7 @@ function recordTriageObservation(l2, obs, ts) {
|
|
|
17045
17191
|
});
|
|
17046
17192
|
} else {
|
|
17047
17193
|
l2.mergeNode(
|
|
17048
|
-
semNode(triageId, "Triage", `differential for: ${statement}`, ts, {
|
|
17194
|
+
semNode(l2, triageId, "Triage", `differential for: ${statement}`, ts, {
|
|
17049
17195
|
statement,
|
|
17050
17196
|
perContextSeen: seen
|
|
17051
17197
|
})
|
|
@@ -17057,7 +17203,7 @@ function recordTriageObservation(l2, obs, ts) {
|
|
|
17057
17203
|
}
|
|
17058
17204
|
if (!l2.getNode(obs.causeId)) {
|
|
17059
17205
|
l2.mergeNode(
|
|
17060
|
-
semNode(obs.causeId, obs.causeLabel ?? "RootCause", obs.causeDescription ?? "(cause)", ts, {
|
|
17206
|
+
semNode(l2, obs.causeId, obs.causeLabel ?? "RootCause", obs.causeDescription ?? "(cause)", ts, {
|
|
17061
17207
|
scope: {}
|
|
17062
17208
|
})
|
|
17063
17209
|
);
|
|
@@ -17230,9 +17376,212 @@ function revisitStaleRoutes(l2, ts, opts = {}) {
|
|
|
17230
17376
|
}
|
|
17231
17377
|
var DRIFT_VALUES = new Set(Object.values(DRIFT_KIND));
|
|
17232
17378
|
|
|
17233
|
-
// ../../packages/local-graph/src/
|
|
17234
|
-
|
|
17235
|
-
|
|
17379
|
+
// ../../packages/local-graph/src/abstraction.ts
|
|
17380
|
+
var DEFAULT_MIN_CLUSTER_SIZE = 3;
|
|
17381
|
+
var DEFAULT_MIN_DISTINCT_CONTEXTS = 2;
|
|
17382
|
+
function sharedScope(l2, memberIds) {
|
|
17383
|
+
const shared = (field) => {
|
|
17384
|
+
const vals = /* @__PURE__ */ new Set();
|
|
17385
|
+
for (const id of memberIds) {
|
|
17386
|
+
const s = l2.getNode(id)?.attrs["scope"] ?? {};
|
|
17387
|
+
if (typeof s[field] === "string") vals.add(s[field]);
|
|
17388
|
+
}
|
|
17389
|
+
return vals.size === 1 ? [...vals][0] : void 0;
|
|
17390
|
+
};
|
|
17391
|
+
const lang = shared("lang");
|
|
17392
|
+
const versionRange = shared("versionRange");
|
|
17393
|
+
return { ...lang ? { lang } : {}, ...versionRange ? { versionRange } : {} };
|
|
17394
|
+
}
|
|
17395
|
+
function buildCandidate(id, ts, members, contexts, originMachine, scope) {
|
|
17396
|
+
return {
|
|
17397
|
+
id,
|
|
17398
|
+
label: "Claim",
|
|
17399
|
+
description: "",
|
|
17400
|
+
// empty — the harness distills the prose in P3
|
|
17401
|
+
extractionConfidence: 0.4,
|
|
17402
|
+
extractionSource: "agent-observed",
|
|
17403
|
+
embedding: [],
|
|
17404
|
+
cumulativeSurprise: 0,
|
|
17405
|
+
peakSurprise: 0,
|
|
17406
|
+
cumulativeHits: 1,
|
|
17407
|
+
lastUpdatedAt: ts,
|
|
17408
|
+
createdAt: ts,
|
|
17409
|
+
memoryTier: "short-term",
|
|
17410
|
+
pageRank: 0,
|
|
17411
|
+
isLandmark: false,
|
|
17412
|
+
community: null,
|
|
17413
|
+
stability: "unstable",
|
|
17414
|
+
attrs: {
|
|
17415
|
+
abstractionLevel: ABSTRACTION_LEVEL.PRINCIPLE,
|
|
17416
|
+
kind: "abstraction-candidate",
|
|
17417
|
+
provisional: true,
|
|
17418
|
+
pendingDistillation: true,
|
|
17419
|
+
// membership is the unit of truth — the harness validates its fence against
|
|
17420
|
+
// this set (P3 / C3) and may only phrase, never alter, it.
|
|
17421
|
+
members,
|
|
17422
|
+
memberContexts: contexts,
|
|
17423
|
+
distinctContexts: contexts.length,
|
|
17424
|
+
// standard Claim envelope so it crystallizes/syncs unchanged once distilled
|
|
17425
|
+
truthKind: "contextual",
|
|
17426
|
+
// Derived from members (P1): a single-language cluster becomes a lang-scoped
|
|
17427
|
+
// principle; a cross-language one stays universal (`{}`).
|
|
17428
|
+
scope,
|
|
17429
|
+
groundedSupport: 0,
|
|
17430
|
+
sources: [],
|
|
17431
|
+
crystallized: "hypothesis",
|
|
17432
|
+
confidence: 0.4,
|
|
17433
|
+
...originMachine ? { originMachine } : {}
|
|
17434
|
+
}
|
|
17435
|
+
};
|
|
17436
|
+
}
|
|
17437
|
+
function mergeGeneralizes(store, principleId, memberId, ts) {
|
|
17438
|
+
store.mergeEdge({
|
|
17439
|
+
id: `edge_${digest({ from: principleId, type: "GENERALIZES", to: memberId })}`.slice(0, 24),
|
|
17440
|
+
from: principleId,
|
|
17441
|
+
to: memberId,
|
|
17442
|
+
type: "GENERALIZES",
|
|
17443
|
+
confidence: 0.4,
|
|
17444
|
+
extractionSource: "agent-observed",
|
|
17445
|
+
createdAt: ts,
|
|
17446
|
+
lastSeenAt: ts,
|
|
17447
|
+
navSuccesses: 0,
|
|
17448
|
+
navFailures: 0,
|
|
17449
|
+
attrs: { provisional: true }
|
|
17450
|
+
});
|
|
17451
|
+
}
|
|
17452
|
+
function induceAbstractions(l2, opts) {
|
|
17453
|
+
const K = opts.minClusterSize ?? DEFAULT_MIN_CLUSTER_SIZE;
|
|
17454
|
+
const minCtx = opts.minDistinctContexts ?? DEFAULT_MIN_DISTINCT_CONTEXTS;
|
|
17455
|
+
const report = {
|
|
17456
|
+
communities: 0,
|
|
17457
|
+
candidatesMinted: 0,
|
|
17458
|
+
candidatesExisting: 0,
|
|
17459
|
+
skippedSmall: 0,
|
|
17460
|
+
skippedSingleContext: 0,
|
|
17461
|
+
generalizesEdges: 0
|
|
17462
|
+
};
|
|
17463
|
+
const ids = /* @__PURE__ */ new Set();
|
|
17464
|
+
for (const label of PERCOLATING_LABELS) {
|
|
17465
|
+
for (const n of l2.findNodesByLabel(label)) {
|
|
17466
|
+
if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) >= ABSTRACTION_LEVEL.PRINCIPLE) {
|
|
17467
|
+
continue;
|
|
17468
|
+
}
|
|
17469
|
+
if (n.attrs["resolvedAs"] === PROBLEM_RESOLUTION.FALSE_POSITIVE) continue;
|
|
17470
|
+
ids.add(n.id);
|
|
17471
|
+
}
|
|
17472
|
+
}
|
|
17473
|
+
if (ids.size === 0) return report;
|
|
17474
|
+
const adj = /* @__PURE__ */ new Map();
|
|
17475
|
+
const protect = [];
|
|
17476
|
+
const add = (a, b, w) => {
|
|
17477
|
+
const l = adj.get(a) ?? [];
|
|
17478
|
+
l.push({ to: b, weight: w });
|
|
17479
|
+
adj.set(a, l);
|
|
17480
|
+
};
|
|
17481
|
+
for (const id of ids) {
|
|
17482
|
+
for (const e of l2.outEdges(id, [...PERCOLATING_EDGES])) {
|
|
17483
|
+
if (!ids.has(e.to)) continue;
|
|
17484
|
+
const conf = e.confidence > 0 ? e.confidence : 0.5;
|
|
17485
|
+
const w = Math.max(EDGE_WEIGHT[e.type] ?? 1, 0.1) * conf;
|
|
17486
|
+
add(id, e.to, w);
|
|
17487
|
+
add(e.to, id, w);
|
|
17488
|
+
if (isCausalProtected(e.type)) protect.push([id, e.to]);
|
|
17489
|
+
}
|
|
17490
|
+
}
|
|
17491
|
+
const comm = detectCommunitiesLeiden({ nodeIds: [...ids], adj }, { protect });
|
|
17492
|
+
report.communities = comm.count;
|
|
17493
|
+
const members = /* @__PURE__ */ new Map();
|
|
17494
|
+
for (const [id, c] of comm.community) {
|
|
17495
|
+
const l = members.get(c) ?? [];
|
|
17496
|
+
l.push(id);
|
|
17497
|
+
members.set(c, l);
|
|
17498
|
+
}
|
|
17499
|
+
l2.transaction(() => {
|
|
17500
|
+
for (const mem of members.values()) {
|
|
17501
|
+
if (opts.touched && !mem.some((id) => opts.touched.has(id))) continue;
|
|
17502
|
+
if (mem.length < K) {
|
|
17503
|
+
report.skippedSmall++;
|
|
17504
|
+
continue;
|
|
17505
|
+
}
|
|
17506
|
+
if (mem.some((id) => l2.inEdges(id, ["GENERALIZES"]).length > 0)) {
|
|
17507
|
+
report.candidatesExisting++;
|
|
17508
|
+
continue;
|
|
17509
|
+
}
|
|
17510
|
+
const contexts = /* @__PURE__ */ new Set();
|
|
17511
|
+
for (const id of mem) {
|
|
17512
|
+
const n = l2.getNode(id);
|
|
17513
|
+
const obs = n?.attrs["observedInProjects"];
|
|
17514
|
+
if (Array.isArray(obs)) {
|
|
17515
|
+
for (const ws of obs) contexts.add(opts.contextOf(ws) ?? `project:${ws}`);
|
|
17516
|
+
}
|
|
17517
|
+
}
|
|
17518
|
+
if (contexts.size < minCtx) {
|
|
17519
|
+
report.skippedSingleContext++;
|
|
17520
|
+
continue;
|
|
17521
|
+
}
|
|
17522
|
+
const sorted = [...mem].sort();
|
|
17523
|
+
const principleId = `princ_${digest({ members: sorted })}`.slice(0, 56);
|
|
17524
|
+
l2.mergeNode(
|
|
17525
|
+
buildCandidate(principleId, opts.ts, sorted, [...contexts].sort(), opts.originMachine, sharedScope(l2, sorted))
|
|
17526
|
+
);
|
|
17527
|
+
for (const id of sorted) {
|
|
17528
|
+
mergeGeneralizes(l2, principleId, id, opts.ts);
|
|
17529
|
+
report.generalizesEdges++;
|
|
17530
|
+
}
|
|
17531
|
+
report.candidatesMinted++;
|
|
17532
|
+
}
|
|
17533
|
+
});
|
|
17534
|
+
return report;
|
|
17535
|
+
}
|
|
17536
|
+
function revisitContradictedPrinciples(l2, ts) {
|
|
17537
|
+
const report = { flagged: 0 };
|
|
17538
|
+
l2.transaction(() => {
|
|
17539
|
+
for (const n of l2.findNodesByLabel("Claim")) {
|
|
17540
|
+
if (Number(n.attrs["abstractionLevel"] ?? ABSTRACTION_LEVEL.CONCRETE) < ABSTRACTION_LEVEL.PRINCIPLE) continue;
|
|
17541
|
+
if (n.attrs["revisit"] === true) continue;
|
|
17542
|
+
const members = Array.isArray(n.attrs["members"]) ? n.attrs["members"] : [];
|
|
17543
|
+
const memberSet = new Set(members);
|
|
17544
|
+
let reason = "";
|
|
17545
|
+
for (const id of members) {
|
|
17546
|
+
const m = l2.getNode(id);
|
|
17547
|
+
if (!m) {
|
|
17548
|
+
reason = `member ${id} was removed`;
|
|
17549
|
+
break;
|
|
17550
|
+
}
|
|
17551
|
+
if (m.attrs["revisit"] === true) {
|
|
17552
|
+
reason = `member "${m.description}" needs revisit`;
|
|
17553
|
+
break;
|
|
17554
|
+
}
|
|
17555
|
+
const contradictors = [
|
|
17556
|
+
...l2.outEdges(id, ["CONTRADICTS"]).map((e) => e.to),
|
|
17557
|
+
...l2.inEdges(id, ["CONTRADICTS"]).map((e) => e.from)
|
|
17558
|
+
];
|
|
17559
|
+
if (contradictors.some((other) => !memberSet.has(other))) {
|
|
17560
|
+
reason = `member "${m.description}" is now contradicted by external evidence`;
|
|
17561
|
+
break;
|
|
17562
|
+
}
|
|
17563
|
+
}
|
|
17564
|
+
if (!reason) continue;
|
|
17565
|
+
l2.updateNode(n.id, {
|
|
17566
|
+
attrs: {
|
|
17567
|
+
...n.attrs,
|
|
17568
|
+
revisit: true,
|
|
17569
|
+
revisitReason: reason,
|
|
17570
|
+
revisitSinceTs: ts,
|
|
17571
|
+
provisional: true,
|
|
17572
|
+
// re-queue for re-distillation (P3 re-name)
|
|
17573
|
+
pendingDistillation: true
|
|
17574
|
+
},
|
|
17575
|
+
lastUpdatedAt: ts
|
|
17576
|
+
});
|
|
17577
|
+
report.flagged++;
|
|
17578
|
+
}
|
|
17579
|
+
});
|
|
17580
|
+
return report;
|
|
17581
|
+
}
|
|
17582
|
+
|
|
17583
|
+
// ../../packages/local-graph/src/community.ts
|
|
17584
|
+
init_src2();
|
|
17236
17585
|
|
|
17237
17586
|
// ../../packages/local-graph/src/tools.ts
|
|
17238
17587
|
init_src();
|
|
@@ -17240,6 +17589,9 @@ init_src();
|
|
|
17240
17589
|
// ../../packages/local-graph/src/principle-sync.ts
|
|
17241
17590
|
init_src2();
|
|
17242
17591
|
|
|
17592
|
+
// ../../packages/local-graph/src/mechanism-liveness.ts
|
|
17593
|
+
var STALL_MIN_SPAN_MS = 60 * 60 * 1e3;
|
|
17594
|
+
|
|
17243
17595
|
// src/reconcile.ts
|
|
17244
17596
|
init_src3();
|
|
17245
17597
|
function isLive(n) {
|