piroboros 0.0.0-stage → 0.2.0
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/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/NOTICE +39 -0
- package/README.md +140 -2
- package/agents/astrelia.md +31 -0
- package/agents/avaritia.md +31 -0
- package/agents/elaria.md +31 -0
- package/agents/nytheria.md +32 -0
- package/agents/raskreia.md +32 -0
- package/agents/samaela.md +40 -0
- package/agents/vaelia.md +35 -0
- package/agents/vesperia.md +45 -0
- package/bin/piroboros.mjs +17 -0
- package/dist/auth.js +105 -0
- package/dist/base.js +19 -0
- package/dist/chat/budget.js +87 -0
- package/dist/chat/compactloop.js +63 -0
- package/dist/chat/compactor.js +530 -0
- package/dist/chat/extension.js +36 -0
- package/dist/chat/hook.js +40 -0
- package/dist/chat/log.js +317 -0
- package/dist/chat/outbound.js +114 -0
- package/dist/chat/plan.js +64 -0
- package/dist/chat/prompt.js +115 -0
- package/dist/chat/status.js +37 -0
- package/dist/chat/stuck.js +83 -0
- package/dist/chat/tools.js +163 -0
- package/dist/chat/tree.js +73 -0
- package/dist/chat/turn.js +305 -0
- package/dist/chat/view.js +163 -0
- package/dist/conclave/agents.js +113 -0
- package/dist/conclave/pipeline.js +715 -0
- package/dist/conclave/report.js +43 -0
- package/dist/config.js +614 -0
- package/dist/durable.js +177 -0
- package/dist/guard.js +346 -0
- package/dist/lock.js +56 -0
- package/dist/main.js +348 -0
- package/dist/memory/akashic/api.js +121 -0
- package/dist/memory/akashic/confusables.js +41 -0
- package/dist/memory/akashic/scanner.js +67 -0
- package/dist/memory/akashic/snapshot.js +31 -0
- package/dist/memory/akashic/store.js +1254 -0
- package/dist/memory/akashic/tools.js +168 -0
- package/dist/memory/akashic/vault.js +984 -0
- package/dist/memory/host.js +124 -0
- package/dist/memory/mnemosia/adapters/akashic-memories.js +180 -0
- package/dist/memory/mnemosia/adapters/contract.js +219 -0
- package/dist/memory/mnemosia/agents.js +387 -0
- package/dist/memory/mnemosia/brief.js +890 -0
- package/dist/memory/mnemosia/claims.js +609 -0
- package/dist/memory/mnemosia/conflicts.js +769 -0
- package/dist/memory/mnemosia/escalation.js +257 -0
- package/dist/memory/mnemosia/feedback.js +108 -0
- package/dist/memory/mnemosia/filters.js +248 -0
- package/dist/memory/mnemosia/intent.js +221 -0
- package/dist/memory/mnemosia/open.js +34 -0
- package/dist/memory/mnemosia/orchestrator.js +926 -0
- package/dist/memory/mnemosia/plan.js +266 -0
- package/dist/memory/mnemosia/policy.js +426 -0
- package/dist/memory/mnemosia/progressive.js +550 -0
- package/dist/memory/mnemosia/provenance.js +458 -0
- package/dist/memory/mnemosia/qualifiers.js +428 -0
- package/dist/memory/mnemosia/rank.js +525 -0
- package/dist/memory/mnemosia/relations.js +156 -0
- package/dist/memory/mnemosia/requirements.js +138 -0
- package/dist/memory/mnemosia/rerank.js +253 -0
- package/dist/memory/mnemosia/retention.js +174 -0
- package/dist/memory/mnemosia/rollback.js +337 -0
- package/dist/memory/mnemosia/select.js +607 -0
- package/dist/memory/mnemosia/similarity.js +164 -0
- package/dist/memory/mnemosia/situation.js +251 -0
- package/dist/memory/mnemosia/task.js +418 -0
- package/dist/memory/mnemosia/temporal.js +136 -0
- package/dist/memory/mnemosia/tokens.js +66 -0
- package/dist/memory/mnemosia/tools.js +160 -0
- package/dist/memory/mnemosia/trace.js +306 -0
- package/dist/memory/mnemosia/types.js +298 -0
- package/dist/models.js +360 -0
- package/dist/paths.js +103 -0
- package/dist/redact.js +79 -0
- package/dist/runtime.js +378 -0
- package/dist/search-format.js +102 -0
- package/dist/search.js +351 -0
- package/dist/setup.js +366 -0
- package/dist/shell.js +110 -0
- package/dist/skills.js +311 -0
- package/dist/telemetry.js +84 -0
- package/dist/tui/app.js +1011 -0
- package/dist/tui/commands.js +121 -0
- package/dist/tui/keys.js +83 -0
- package/dist/tui/pane.js +387 -0
- package/dist/tui/panel.js +60 -0
- package/dist/tui/picker.js +25 -0
- package/dist/tui/sanitize.js +59 -0
- package/dist/tui/settings.js +198 -0
- package/dist/tui/setup.js +256 -0
- package/dist/tui/theme.js +26 -0
- package/dist/tui/thinking/parse.js +1094 -0
- package/dist/tui/thinking/select.js +86 -0
- package/dist/tui/thinking/state.js +137 -0
- package/dist/tui/thinking/types.js +3 -0
- package/dist/tui/thinking/view.js +74 -0
- package/dist/tui/viewport.js +208 -0
- package/dist/undo.js +258 -0
- package/dist/web.js +933 -0
- package/docs/conclave.md +21 -0
- package/docs/configuration.md +48 -0
- package/docs/development.md +25 -0
- package/docs/interface.md +33 -0
- package/docs/memory.md +11 -0
- package/docs/privacy.md +13 -0
- package/docs/tools.md +20 -0
- package/docs/web.md +38 -0
- package/models.json.example +34 -0
- package/package.json +76 -4
- package/settings.json.example +29 -0
- package/skills/conclave/SKILL.md +76 -0
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
// Ported from mnemosia/conflicts.ts @ f0a8ad4 (MIT; see NOTICE)
|
|
2
|
+
/**
|
|
3
|
+
* Conflict detection, classification and resolution (spec §14, design §11; Phase 2).
|
|
4
|
+
*
|
|
5
|
+
* Phase 1 shipped two of spec §14's ten classes — `TEMPORAL_SUCCESSION` and `UNRESOLVED` — and said
|
|
6
|
+
* so rather than stubbing the other eight. Phase 2 builds the whole **deterministic** taxonomy:
|
|
7
|
+
*
|
|
8
|
+
* | class | detector | phase |
|
|
9
|
+
* |---|---|---|
|
|
10
|
+
* | `TEMPORAL_SUCCESSION` | explicit `supersedes`; transitive chains; same statement, one scope | 1 → extended |
|
|
11
|
+
* | `UNRESOLVED` | anything detected and not classifiable into the other nine | 1 |
|
|
12
|
+
* | `SUMMARY_SOURCE_MISMATCH` | a summary claim whose declared source events resolve to nothing | **2** |
|
|
13
|
+
* | `SCOPE_DIFFERENCE` | the same statement under two `scope.project`s | **2** |
|
|
14
|
+
* | `BRANCH_DIFFERENCE` | a neighbourhood pair whose extracted branch qualifiers are disjoint | **2** |
|
|
15
|
+
* | `ENVIRONMENT_DIFFERENCE` | the same, for environment | **2** |
|
|
16
|
+
* | `PLAN_VERSUS_FACT` | a `{PLAN, FACT/OBSERVATION}` neighbourhood pair | **2** |
|
|
17
|
+
* | `PREFERENCE_CHANGE` | two PREFERENCE claims in a neighbourhood, different identities | **2** |
|
|
18
|
+
* | `DIRECT_CONTRADICTION` | a neighbourhood pair with one-sided negation or a differing `key: value` | **2** (deterministic subset) |
|
|
19
|
+
* | `AUTHORITY_DISAGREEMENT` | any contradiction whose sides differ ≥ 0.2 in authority | **2** |
|
|
20
|
+
*
|
|
21
|
+
* **There is no LLM anywhere in this file, and the general semantic case is still deferred.** Design
|
|
22
|
+
* §11 splits `DIRECT_CONTRADICTION` deliberately: the deterministic subset is a syntactic asymmetry
|
|
23
|
+
* — exactly one side negated, or a named setting given two values — and the general case ("we should
|
|
24
|
+
* cache aggressively" vs "the cache is the bottleneck") needs semantics. A neighbourhood pair that
|
|
25
|
+
* no predicate here explains is *not* reported as a contradiction. It is either explained by a
|
|
26
|
+
* qualifier, or it is redundancy that `select.ts`'s MMR penalty already handles, or — when something
|
|
27
|
+
* about it is genuinely undecidable — it is `UNRESOLVED` with `MARK_DISPUTED`, which is spec §14's
|
|
28
|
+
* documented fallback and a smaller claim than a guess.
|
|
29
|
+
*
|
|
30
|
+
* **Does a superseded claim's evidence still support its successor? No, and that is a decision.**
|
|
31
|
+
* The Phase 2 brief poses it directly. A `SUPERSEDES` edge says "this statement replaces that one";
|
|
32
|
+
* it does not say "the artifact that carried the old statement asserts the new one". Letting the
|
|
33
|
+
* retired artifact count toward the successor's `evidence_strength` would mean a claim could
|
|
34
|
+
* strengthen itself by retiring things — an incentive exactly backwards from what evidence is for,
|
|
35
|
+
* and one a poisoned artifact could exploit with a single `supersedes` field. So `rank.ts` counts
|
|
36
|
+
* only `SUPPORTS` edges (rank.ts:338 and `provenance.ts`'s `supportingArtifacts`), `SUPERSEDES`
|
|
37
|
+
* edges are recorded in the graph for traversal and for this file's classification, and the
|
|
38
|
+
* successor's strength is whatever its own evidence earns. The retired claim keeps its own evidence
|
|
39
|
+
* and stays in the briefing under `conflicts[]`.
|
|
40
|
+
*
|
|
41
|
+
* **Nothing here mutates the store**, unchanged from Phase 1: the outcomes are briefing-level.
|
|
42
|
+
* **Resolution demotes; it never deletes** — spec §14's closing line, "never silently erase a
|
|
43
|
+
* meaningful conflict", is the property every branch below is written to preserve.
|
|
44
|
+
*/
|
|
45
|
+
import { createHash } from "node:crypto";
|
|
46
|
+
import { buildProvenanceGraph } from "./provenance.js";
|
|
47
|
+
import { keyValueDivergence, negationDivergence, planVersusFact, preferenceChange, scopeDifference } from "./relations.js";
|
|
48
|
+
import { qualifiersDiverge } from "./qualifiers.js";
|
|
49
|
+
import { temporallyDisjoint } from "./temporal.js";
|
|
50
|
+
/* ------------------------------------------------------------------------------------------------
|
|
51
|
+
* Vocabulary
|
|
52
|
+
* ---------------------------------------------------------------------------------------------- */
|
|
53
|
+
/** Spec §14's ten classes, verbatim and in the spec's own order. */
|
|
54
|
+
export const CONFLICT_CLASSES = [
|
|
55
|
+
"DIRECT_CONTRADICTION",
|
|
56
|
+
"TEMPORAL_SUCCESSION",
|
|
57
|
+
"SCOPE_DIFFERENCE",
|
|
58
|
+
"BRANCH_DIFFERENCE",
|
|
59
|
+
"ENVIRONMENT_DIFFERENCE",
|
|
60
|
+
"PLAN_VERSUS_FACT",
|
|
61
|
+
"PREFERENCE_CHANGE",
|
|
62
|
+
"SUMMARY_SOURCE_MISMATCH",
|
|
63
|
+
"AUTHORITY_DISAGREEMENT",
|
|
64
|
+
"UNRESOLVED",
|
|
65
|
+
];
|
|
66
|
+
/**
|
|
67
|
+
* The outcomes a `ConflictRecord` may carry, after Phase 4.
|
|
68
|
+
*
|
|
69
|
+
* Still absent, with reasons: `SELECT_PRIMARY` needs a notion of a primary source Mnemosia does not
|
|
70
|
+
* have; `REQUEST_HUMAN_APPROVAL` belongs to `approvals.ts`, where a named human actually decides,
|
|
71
|
+
* and a conflict record is not a queue entry. `EXCLUDE_UNSAFE` is reached through `filters.ts`'s
|
|
72
|
+
* quarantine rather than through a conflict record.
|
|
73
|
+
*
|
|
74
|
+
* **`ESCALATE_TO_ELARIA` and `ESCALATE_TO_RASKREIA` become reachable in Phase 4, and the Phase 2
|
|
75
|
+
* rule that made them unreachable is preserved rather than repealed.** That rule was: a module that
|
|
76
|
+
* cannot route must not emit a routing label. `detectConflicts` still cannot route — it does not
|
|
77
|
+
* know who is asking, and a target that is also the requester is a loop it has no way to see — so it
|
|
78
|
+
* still emits only `DETERMINISTIC_CONFLICT_OUTCOMES` below, and `test/escalation.test.ts` asserts
|
|
79
|
+
* that. The two escalation labels are applied by `escalation.ts:routeEscalations`, which *is* handed
|
|
80
|
+
* the requesting agent and which produces an addressed `EscalationRequest` alongside every label it
|
|
81
|
+
* writes. The label and the thing behind it are produced by the same function or not at all.
|
|
82
|
+
*/
|
|
83
|
+
export const CONFLICT_OUTCOMES = ["SELECT_NEWER_VALID", "SELECT_HIGHER_AUTHORITY", "KEEP_SCOPE_SPECIFIC_VARIANTS", "INCLUDE_BOTH_WITH_QUALIFICATION", "MARK_DISPUTED", "REQUEST_VERIFICATION", "ESCALATE_TO_ELARIA", "ESCALATE_TO_RASKREIA"];
|
|
84
|
+
/**
|
|
85
|
+
* The subset `detectConflicts` itself may emit — every outcome that is a conclusion about the claims
|
|
86
|
+
* rather than a decision about who should look at them. Kept as its own constant so that "the
|
|
87
|
+
* detector never routes" is a machine-checked property rather than a comment.
|
|
88
|
+
*/
|
|
89
|
+
export const DETERMINISTIC_CONFLICT_OUTCOMES = ["SELECT_NEWER_VALID", "SELECT_HIGHER_AUTHORITY", "KEEP_SCOPE_SPECIFIC_VARIANTS", "INCLUDE_BOTH_WITH_QUALIFICATION", "MARK_DISPUTED", "REQUEST_VERIFICATION"];
|
|
90
|
+
/** The two Phase 4 routing labels. A record carrying one of these has an `EscalationRequest`. */
|
|
91
|
+
export const ESCALATION_OUTCOMES = ["ESCALATE_TO_ELARIA", "ESCALATE_TO_RASKREIA"];
|
|
92
|
+
export const CONFLICT_DETECTORS = [
|
|
93
|
+
"explicit_supersession",
|
|
94
|
+
"transitive_supersession",
|
|
95
|
+
"dangling_supersession",
|
|
96
|
+
"summary_source_mismatch",
|
|
97
|
+
"dedup_key_divergence",
|
|
98
|
+
"branch_qualifier",
|
|
99
|
+
"environment_qualifier",
|
|
100
|
+
"scope_qualifier",
|
|
101
|
+
"negation_divergence",
|
|
102
|
+
"key_value_divergence",
|
|
103
|
+
"preference_change",
|
|
104
|
+
"plan_versus_fact",
|
|
105
|
+
"temporal_validity",
|
|
106
|
+
"disputed_lifecycle",
|
|
107
|
+
];
|
|
108
|
+
/* ------------------------------------------------------------------------------------------------
|
|
109
|
+
* Helpers
|
|
110
|
+
* ---------------------------------------------------------------------------------------------- */
|
|
111
|
+
function conflictIdFor(detector, claimIds, subject) {
|
|
112
|
+
return createHash("sha256").update(`${detector}${[...claimIds].sort().join("")}${subject}`, "utf8").digest("hex").slice(0, 32);
|
|
113
|
+
}
|
|
114
|
+
function shortText(text, width = 90) {
|
|
115
|
+
const flat = text.replace(/\s+/gu, " ").trim();
|
|
116
|
+
return flat.length <= width ? flat : `${flat.slice(0, width - 1)}…`;
|
|
117
|
+
}
|
|
118
|
+
function isoDay(at) {
|
|
119
|
+
return new Date(at).toISOString().slice(0, 10);
|
|
120
|
+
}
|
|
121
|
+
function short(claimId) {
|
|
122
|
+
return claimId.slice(0, 12);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* `(effectiveAt desc, claimId asc)` — the newest claim, with a total tie-break.
|
|
126
|
+
*
|
|
127
|
+
* The tie-break is not decoration. Two claims extracted from the same artifact share its
|
|
128
|
+
* `createdAt`, so "newer wins" is genuinely undecided for them, and without a deterministic second
|
|
129
|
+
* key the winner would depend on the order the adapters happened to return rows in — which the §16
|
|
130
|
+
* determinism gate measures across three runs.
|
|
131
|
+
*/
|
|
132
|
+
function newerFirst(a, b) {
|
|
133
|
+
if (a.effectiveAt !== b.effectiveAt)
|
|
134
|
+
return b.effectiveAt - a.effectiveAt;
|
|
135
|
+
return a.claimId < b.claimId ? -1 : a.claimId > b.claimId ? 1 : 0;
|
|
136
|
+
}
|
|
137
|
+
const DEFAULT_NEIGHBOURHOOD = 0.6;
|
|
138
|
+
const DEFAULT_AUTHORITY_GAP = 0.2;
|
|
139
|
+
/* ------------------------------------------------------------------------------------------------
|
|
140
|
+
* Detection
|
|
141
|
+
* ---------------------------------------------------------------------------------------------- */
|
|
142
|
+
/**
|
|
143
|
+
* Detects, classifies and resolves conflicts over the accepted claim set.
|
|
144
|
+
*
|
|
145
|
+
* Detectors run in the order below, and a claim already explained by a stronger detector is not
|
|
146
|
+
* re-reported by a weaker one. The order is by *strength of the evidence for the conflict*, not by
|
|
147
|
+
* severity: an explicit `supersedes` link is a governance fact recorded by a human, a shared
|
|
148
|
+
* `dedupKey` is an identity fact computed by the pipeline, and a neighbourhood predicate is an
|
|
149
|
+
* inference from text — so they are tried in exactly that order and the first one that fires owns
|
|
150
|
+
* the explanation the reader is given.
|
|
151
|
+
*/
|
|
152
|
+
export function detectConflicts(input) {
|
|
153
|
+
const now = input.now ?? Date.now();
|
|
154
|
+
const claims = input.claims;
|
|
155
|
+
const policy = input.policy;
|
|
156
|
+
const neighbourhood = policy?.conflict.neighbourhoodThreshold ?? DEFAULT_NEIGHBOURHOOD;
|
|
157
|
+
const authorityGap = policy?.conflict.authorityGap ?? DEFAULT_AUTHORITY_GAP;
|
|
158
|
+
const graph = input.graph ?? buildProvenanceGraph({ claims, envelopes: input.envelopes ?? [], now, shingleSize: policy?.selection.shingleSize ?? 3, neighbourhoodThreshold: neighbourhood });
|
|
159
|
+
const byClaimId = new Map(claims.map((claim) => [claim.claimId, claim]));
|
|
160
|
+
const conflicts = [];
|
|
161
|
+
const demoted = new Map();
|
|
162
|
+
const explained = new Set();
|
|
163
|
+
/** Pairs already owned by a detector, keyed `ab` with a < b. */
|
|
164
|
+
const explainedPairs = new Set();
|
|
165
|
+
let danglingReferences = 0;
|
|
166
|
+
const pairKey = (a, b) => (a < b ? `${a}${b}` : `${b}${a}`);
|
|
167
|
+
const record = (entry) => {
|
|
168
|
+
conflicts.push(entry);
|
|
169
|
+
for (const claimId of entry.claimIds)
|
|
170
|
+
explained.add(claimId);
|
|
171
|
+
if (entry.claimIds.length === 2) {
|
|
172
|
+
const [first, second] = entry.claimIds;
|
|
173
|
+
if (first !== undefined && second !== undefined)
|
|
174
|
+
explainedPairs.add(pairKey(first, second));
|
|
175
|
+
}
|
|
176
|
+
for (const claimId of entry.supersededClaimIds) {
|
|
177
|
+
// First demotion wins, matching the first-match-wins rule filters.ts uses for rejections:
|
|
178
|
+
// a claim is attributed to the *first* reason it was demoted, not the last.
|
|
179
|
+
if (!demoted.has(claimId))
|
|
180
|
+
demoted.set(claimId, entry);
|
|
181
|
+
}
|
|
182
|
+
input.trace?.append({ state: "DETECT_CONFLICTS", event: "conflict", payload: { ...entry } });
|
|
183
|
+
};
|
|
184
|
+
const authority = (claimId) => input.authorityOf?.(claimId);
|
|
185
|
+
/* --- 1 & 2: explicit supersession, direct then transitive ----------------------------------- */
|
|
186
|
+
//
|
|
187
|
+
// The graph resolved `claim.supersedes` (which names artifacts) into claim-to-claim edges and
|
|
188
|
+
// closed them transitively, so "A supersedes B supersedes C" reaches C here without this loop
|
|
189
|
+
// having to walk anything.
|
|
190
|
+
for (const claim of [...claims].sort((a, b) => (a.claimId < b.claimId ? -1 : 1))) {
|
|
191
|
+
const provenance = graph.byClaim.get(claim.claimId);
|
|
192
|
+
if (provenance === undefined)
|
|
193
|
+
continue;
|
|
194
|
+
for (const targetId of provenance.supersedes) {
|
|
195
|
+
const target = byClaimId.get(targetId);
|
|
196
|
+
if (target === undefined)
|
|
197
|
+
continue;
|
|
198
|
+
record({
|
|
199
|
+
conflictId: conflictIdFor("explicit_supersession", [claim.claimId, targetId], "direct"),
|
|
200
|
+
conflictClass: "TEMPORAL_SUCCESSION",
|
|
201
|
+
outcome: "SELECT_NEWER_VALID",
|
|
202
|
+
detector: "explicit_supersession",
|
|
203
|
+
claimIds: [claim.claimId, targetId].sort(),
|
|
204
|
+
winnerClaimId: claim.claimId,
|
|
205
|
+
supersededClaimIds: [targetId],
|
|
206
|
+
unresolved: false,
|
|
207
|
+
similarity: null,
|
|
208
|
+
authorityGap: null,
|
|
209
|
+
chainDepth: 1,
|
|
210
|
+
rationale: `${short(claim.claimId)} carries an explicit supersedes link reaching ${short(targetId)}; explicit supersession is a governance fact, not an inference, so it settles the pair outright`,
|
|
211
|
+
qualification: `Superseded on ${isoDay(claim.effectiveAt)} by: "${shortText(claim.text)}"`,
|
|
212
|
+
detectedAt: now,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
// **PHASE 2 — transitive chains.** Everything reachable through more than one link. Reported
|
|
216
|
+
// separately from the direct pair because the reader's question differs: "this was replaced"
|
|
217
|
+
// versus "this was replaced by something that has itself since been replaced", and collapsing
|
|
218
|
+
// the two would hide the middle of the chain entirely.
|
|
219
|
+
const indirect = provenance.supersedesTransitive.filter((targetId) => !provenance.supersedes.includes(targetId) && byClaimId.has(targetId));
|
|
220
|
+
for (const targetId of indirect) {
|
|
221
|
+
record({
|
|
222
|
+
conflictId: conflictIdFor("transitive_supersession", [claim.claimId, targetId], "transitive"),
|
|
223
|
+
conflictClass: "TEMPORAL_SUCCESSION",
|
|
224
|
+
outcome: "SELECT_NEWER_VALID",
|
|
225
|
+
detector: "transitive_supersession",
|
|
226
|
+
claimIds: [claim.claimId, targetId].sort(),
|
|
227
|
+
winnerClaimId: claim.claimId,
|
|
228
|
+
supersededClaimIds: [targetId],
|
|
229
|
+
unresolved: false,
|
|
230
|
+
similarity: null,
|
|
231
|
+
authorityGap: null,
|
|
232
|
+
chainDepth: provenance.supersessionDepth,
|
|
233
|
+
rationale: `${short(targetId)} is retired through a supersession chain of ${provenance.supersessionDepth} link(s) ending at ${short(claim.claimId)}; every intermediate statement in the chain is itself superseded`,
|
|
234
|
+
qualification: `Superseded indirectly: a chain of ${provenance.supersessionDepth} replacements ends at "${shortText(claim.text)}" (${isoDay(claim.effectiveAt)}).`,
|
|
235
|
+
detectedAt: now,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
// Dangling: a `supersedes` reference that resolved to no claim in this run. Worth reporting
|
|
239
|
+
// rather than dropping — it tells the reader that the statement in front of them replaced one
|
|
240
|
+
// they cannot see, which is exactly the kind of thing a briefing exists to say out loud.
|
|
241
|
+
for (const reference of [...claim.supersedes].sort()) {
|
|
242
|
+
const resolved = graph.claimsByArtifact.get(reference) ?? graph.claimsByArtifact.get(`akashic-memory:${reference}`) ?? [];
|
|
243
|
+
if (resolved.some((claimId) => claimId !== claim.claimId && byClaimId.has(claimId)))
|
|
244
|
+
continue;
|
|
245
|
+
danglingReferences += 1;
|
|
246
|
+
record({
|
|
247
|
+
conflictId: conflictIdFor("dangling_supersession", [claim.claimId], reference),
|
|
248
|
+
conflictClass: "UNRESOLVED",
|
|
249
|
+
outcome: "MARK_DISPUTED",
|
|
250
|
+
detector: "dangling_supersession",
|
|
251
|
+
claimIds: [claim.claimId],
|
|
252
|
+
winnerClaimId: null,
|
|
253
|
+
// Nothing is demoted: the claim doing the superseding is not itself in doubt, and the
|
|
254
|
+
// thing it retired is not here to demote.
|
|
255
|
+
supersededClaimIds: [],
|
|
256
|
+
unresolved: true,
|
|
257
|
+
similarity: null,
|
|
258
|
+
authorityGap: null,
|
|
259
|
+
chainDepth: null,
|
|
260
|
+
rationale: `claim ${short(claim.claimId)} declares it supersedes ${reference}, which this run did not retrieve, so the superseded statement could not be inspected`,
|
|
261
|
+
qualification: `This statement explicitly supersedes ${reference}, which was not retrieved in this run — the replaced statement could not be checked.`,
|
|
262
|
+
detectedAt: now,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/* --- 3: SUMMARY_SOURCE_MISMATCH (design §11, Phase 2) --------------------------------------- */
|
|
267
|
+
//
|
|
268
|
+
// Design §11's trigger is "a summary claim whose `sourceEventIds` are absent/hash-mismatched",
|
|
269
|
+
// and `provenance.ts` computes exactly those two states:
|
|
270
|
+
//
|
|
271
|
+
// refs_unresolved every declared source event names something this run did not normalize
|
|
272
|
+
// refs_absent the summary declares no source events at all, though its schema requires them
|
|
273
|
+
// integrity_failed the artifact's own hash check failed (unreachable post-filter, kept total)
|
|
274
|
+
//
|
|
275
|
+
// It deliberately does **not** fire on `session_absent` — an AkashicForge compaction summary whose
|
|
276
|
+
// session contributed no primary event to *this* run. That is a fact about a retrieval that reads
|
|
277
|
+
// a few hundred of 11,182 events, not a fact about the summary, and classifying it as a conflict
|
|
278
|
+
// would report every summary in the corpus as poisoned. It is counted, it caps the claim's
|
|
279
|
+
// evidence strength through graph distance 3, and it is disclosed as a grounding gap — the same
|
|
280
|
+
// distinction design §16's Phase 1E note draws between a corpus fact and an availability fact.
|
|
281
|
+
for (const claim of [...claims].sort((a, b) => (a.claimId < b.claimId ? -1 : 1))) {
|
|
282
|
+
const provenance = graph.byClaim.get(claim.claimId);
|
|
283
|
+
if (provenance === undefined)
|
|
284
|
+
continue;
|
|
285
|
+
if (provenance.grounding !== "refs_unresolved" && provenance.grounding !== "refs_absent" && provenance.grounding !== "integrity_failed")
|
|
286
|
+
continue;
|
|
287
|
+
const detail = provenance.grounding === "refs_absent"
|
|
288
|
+
? "the summary cites no source events at all"
|
|
289
|
+
: provenance.grounding === "integrity_failed"
|
|
290
|
+
? "the summary artifact failed its integrity check"
|
|
291
|
+
: `the summary cites ${provenance.unresolvedRefs.length} source event(s) — ${provenance.unresolvedRefs.slice(0, 4).join(", ")}${provenance.unresolvedRefs.length > 4 ? ", …" : ""} — none of which names anything this run holds`;
|
|
292
|
+
record({
|
|
293
|
+
conflictId: conflictIdFor("summary_source_mismatch", [claim.claimId], provenance.grounding),
|
|
294
|
+
conflictClass: "SUMMARY_SOURCE_MISMATCH",
|
|
295
|
+
outcome: "REQUEST_VERIFICATION",
|
|
296
|
+
detector: "summary_source_mismatch",
|
|
297
|
+
claimIds: [claim.claimId],
|
|
298
|
+
winnerClaimId: null,
|
|
299
|
+
// Demoted, not dropped. An unsourceable summary claim may not stand as a confirmed fact,
|
|
300
|
+
// and deleting it would hide that the summary asserts it at all.
|
|
301
|
+
supersededClaimIds: [claim.claimId],
|
|
302
|
+
unresolved: true,
|
|
303
|
+
similarity: null,
|
|
304
|
+
authorityGap: null,
|
|
305
|
+
chainDepth: null,
|
|
306
|
+
rationale: `${short(claim.claimId)} reaches this run only through a summary whose own evidence cannot be located: ${detail}`,
|
|
307
|
+
qualification: `This statement comes from a summary that cannot account for its own sources (${detail}). Verify it against the underlying events before relying on it.`,
|
|
308
|
+
detectedAt: now,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/* --- 4: same dedupKey, different identity --------------------------------------------------- */
|
|
312
|
+
//
|
|
313
|
+
// Two cases, and Phase 2 finally has the right label for the second one:
|
|
314
|
+
//
|
|
315
|
+
// * **Same dedupKey, same scope.** Unreachable after `dedupeClaims`, because Phase 1B made
|
|
316
|
+
// `claimId = sha256(dedupKey ␟ scopeKey)`. Reachable only when a caller skips deduplication —
|
|
317
|
+
// a replayed trace, a replaced adapter — and handled as genuine TEMPORAL_SUCCESSION.
|
|
318
|
+
// * **Same dedupKey, different scope.** This is what actually survives. Phase 1 reported it as
|
|
319
|
+
// UNRESOLVED because it had no scope classifier; design §11 always assigned it
|
|
320
|
+
// `SCOPE_DIFFERENCE`, and Phase 2 delivers that, with spec §14's own
|
|
321
|
+
// `KEEP_SCOPE_SPECIFIC_VARIANTS` outcome. Neither side is demoted: they are two scoped
|
|
322
|
+
// statements, both true where they were recorded.
|
|
323
|
+
const byDedupKey = new Map();
|
|
324
|
+
for (const claim of claims) {
|
|
325
|
+
const bucket = byDedupKey.get(claim.dedupKey);
|
|
326
|
+
if (bucket === undefined)
|
|
327
|
+
byDedupKey.set(claim.dedupKey, [claim]);
|
|
328
|
+
else
|
|
329
|
+
bucket.push(claim);
|
|
330
|
+
}
|
|
331
|
+
for (const dedupKey of [...byDedupKey.keys()].sort()) {
|
|
332
|
+
const group = (byDedupKey.get(dedupKey) ?? []).slice().sort(newerFirst);
|
|
333
|
+
if (group.length < 2)
|
|
334
|
+
continue;
|
|
335
|
+
// **CORRECTED AFTER THE FIRST SEEDED MEASUREMENT.** Two entries sharing a `claimId` are the
|
|
336
|
+
// same claim handed in twice, not two versions of a statement, and reporting one as having
|
|
337
|
+
// superseded the other is a claim superseding itself. `dedupeClaims` collapses them in the
|
|
338
|
+
// live pipeline, so this is only reachable when a caller skips deduplication — which is exactly
|
|
339
|
+
// the path this detector exists to cover, and seed `N13` (a preference and a decision carrying
|
|
340
|
+
// identical text in one scope) is where it fired.
|
|
341
|
+
if (new Set(group.map((entry) => entry.claimId)).size < 2)
|
|
342
|
+
continue;
|
|
343
|
+
const [winner, ...losers] = group;
|
|
344
|
+
if (winner === undefined)
|
|
345
|
+
continue;
|
|
346
|
+
const scopesDiffer = new Set(group.map((claim) => `${claim.scope.level}:${claim.scope.project ?? "-"}`)).size > 1;
|
|
347
|
+
const ids = group.map((claim) => claim.claimId).sort();
|
|
348
|
+
for (let i = 0; i < ids.length; i += 1)
|
|
349
|
+
for (let j = i + 1; j < ids.length; j += 1)
|
|
350
|
+
explainedPairs.add(pairKey(ids[i] ?? "", ids[j] ?? ""));
|
|
351
|
+
if (scopesDiffer) {
|
|
352
|
+
record({
|
|
353
|
+
conflictId: conflictIdFor("dedup_key_divergence", ids, "scope"),
|
|
354
|
+
conflictClass: "SCOPE_DIFFERENCE",
|
|
355
|
+
outcome: "KEEP_SCOPE_SPECIFIC_VARIANTS",
|
|
356
|
+
detector: "dedup_key_divergence",
|
|
357
|
+
claimIds: ids,
|
|
358
|
+
winnerClaimId: null,
|
|
359
|
+
supersededClaimIds: [],
|
|
360
|
+
// Resolved: spec §14's KEEP_SCOPE_SPECIFIC_VARIANTS *is* the answer for a scoped pair.
|
|
361
|
+
// Phase 1 marked it unresolved only because it had no class to put it in.
|
|
362
|
+
unresolved: false,
|
|
363
|
+
similarity: 1,
|
|
364
|
+
authorityGap: null,
|
|
365
|
+
chainDepth: null,
|
|
366
|
+
rationale: `${group.length} claims share the normalized statement "${shortText(dedupKey, 60)}" across ${new Set(group.map((claim) => claim.scope.project ?? "global")).size} scopes; they are scope-specific variants of one statement, not competing versions of it`,
|
|
367
|
+
qualification: `The same statement is recorded in ${group.map((claim) => claim.scope.project ?? "global scope").join(" and ")}; each is valid in its own scope and both are kept.`,
|
|
368
|
+
detectedAt: now,
|
|
369
|
+
});
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
record({
|
|
373
|
+
conflictId: conflictIdFor("dedup_key_divergence", ids, "temporal"),
|
|
374
|
+
conflictClass: "TEMPORAL_SUCCESSION",
|
|
375
|
+
outcome: "SELECT_NEWER_VALID",
|
|
376
|
+
detector: "dedup_key_divergence",
|
|
377
|
+
claimIds: ids,
|
|
378
|
+
winnerClaimId: winner.claimId,
|
|
379
|
+
supersededClaimIds: losers.map((claim) => claim.claimId),
|
|
380
|
+
unresolved: false,
|
|
381
|
+
similarity: 1,
|
|
382
|
+
authorityGap: null,
|
|
383
|
+
chainDepth: null,
|
|
384
|
+
rationale: `${group.length} claims share the normalized statement "${shortText(dedupKey, 60)}" in one scope with distinct identities; the one effective at ${isoDay(winner.effectiveAt)} is the newest and wins`,
|
|
385
|
+
qualification: `An older recording of the same statement (effective ${losers.map((claim) => isoDay(claim.effectiveAt)).join(", ")}) was superseded by the version effective ${isoDay(winner.effectiveAt)}.`,
|
|
386
|
+
detectedAt: now,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/* --- 5: the neighbourhood detectors (design §11's Phase 2 block) ---------------------------- */
|
|
390
|
+
//
|
|
391
|
+
// One pass over the near-duplicate pairs the graph already computed. Per pair the predicates are
|
|
392
|
+
// tried in a fixed order and the first that fires owns the pair, because a difference with an
|
|
393
|
+
// ordinary explanation must not also be reported as a contradiction: two statements about two
|
|
394
|
+
// branches disagree about nothing, and telling the reader they contradict would be false.
|
|
395
|
+
let pairsUnexplained = 0;
|
|
396
|
+
for (const pair of graph.neighbours) {
|
|
397
|
+
const a = pair.a;
|
|
398
|
+
const b = pair.b;
|
|
399
|
+
if (pair.similarity < neighbourhood)
|
|
400
|
+
continue;
|
|
401
|
+
if (explainedPairs.has(pairKey(a.claimId, b.claimId)))
|
|
402
|
+
continue;
|
|
403
|
+
if (!byClaimId.has(a.claimId) || !byClaimId.has(b.claimId))
|
|
404
|
+
continue;
|
|
405
|
+
const qa = graph.byClaim.get(a.claimId)?.qualifiers ?? [];
|
|
406
|
+
const qb = graph.byClaim.get(b.claimId)?.qualifiers ?? [];
|
|
407
|
+
const ids = [a.claimId, b.claimId].sort();
|
|
408
|
+
const branch = qualifiersDiverge(qa, qb, "branch");
|
|
409
|
+
if (branch.diverges) {
|
|
410
|
+
record(qualifierRecord("branch_qualifier", "BRANCH_DIFFERENCE", ids, pair.similarity, branch.left, branch.right, "branch", now));
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const environment = qualifiersDiverge(qa, qb, "environment");
|
|
414
|
+
if (environment.diverges) {
|
|
415
|
+
record(qualifierRecord("environment_qualifier", "ENVIRONMENT_DIFFERENCE", ids, pair.similarity, environment.left, environment.right, "environment", now));
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (scopeDifference(a, b)) {
|
|
419
|
+
record({
|
|
420
|
+
conflictId: conflictIdFor("scope_qualifier", ids, "scope"),
|
|
421
|
+
conflictClass: "SCOPE_DIFFERENCE",
|
|
422
|
+
outcome: "KEEP_SCOPE_SPECIFIC_VARIANTS",
|
|
423
|
+
detector: "scope_qualifier",
|
|
424
|
+
claimIds: ids,
|
|
425
|
+
winnerClaimId: null,
|
|
426
|
+
supersededClaimIds: [],
|
|
427
|
+
unresolved: false,
|
|
428
|
+
similarity: pair.similarity,
|
|
429
|
+
authorityGap: null,
|
|
430
|
+
chainDepth: null,
|
|
431
|
+
rationale: `two near-identical statements (jaccard₃ ${pair.shingleSimilarity.toFixed(3)} / jaccard₁ ${pair.tokenSimilarity.toFixed(3)}) are recorded under different scopes — ${a.scope.project ?? "global"} and ${b.scope.project ?? "global"} — so they are scope-specific variants rather than competing claims`,
|
|
432
|
+
qualification: `Recorded separately for ${a.scope.project ?? "global scope"} and ${b.scope.project ?? "global scope"}; each holds in its own scope.`,
|
|
433
|
+
detectedAt: now,
|
|
434
|
+
});
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
// The deterministic DIRECT_CONTRADICTION subset.
|
|
438
|
+
const negation = negationDivergence(a.text, b.text);
|
|
439
|
+
const keyValues = keyValueDivergence(a.text, b.text);
|
|
440
|
+
if (negation.diverges || keyValues.length > 0) {
|
|
441
|
+
const detector = negation.diverges ? "negation_divergence" : "key_value_divergence";
|
|
442
|
+
const basis = negation.diverges
|
|
443
|
+
? `exactly one side carries a negation marker (${negation.negatedSide === "a" ? short(a.claimId) : short(b.claimId)})`
|
|
444
|
+
: keyValues.map((entry) => `\`${entry.key}\` is ${entry.left} on one side and ${entry.right} on the other`).join("; ");
|
|
445
|
+
// Spec §14's first consideration is effective time. Two statements whose validity intervals
|
|
446
|
+
// never met are a sequence, not a disagreement, and calling that a contradiction would put a
|
|
447
|
+
// resolved history in front of the reader as an open question.
|
|
448
|
+
if (temporallyDisjoint(a, b)) {
|
|
449
|
+
const [newer, older] = [a, b].sort(newerFirst);
|
|
450
|
+
record({
|
|
451
|
+
conflictId: conflictIdFor(detector, ids, "temporal"),
|
|
452
|
+
conflictClass: "TEMPORAL_SUCCESSION",
|
|
453
|
+
outcome: "SELECT_NEWER_VALID",
|
|
454
|
+
detector,
|
|
455
|
+
claimIds: ids,
|
|
456
|
+
winnerClaimId: newer.claimId,
|
|
457
|
+
supersededClaimIds: [older.claimId],
|
|
458
|
+
unresolved: false,
|
|
459
|
+
similarity: pair.similarity,
|
|
460
|
+
authorityGap: null,
|
|
461
|
+
chainDepth: null,
|
|
462
|
+
rationale: `${basis}, but the two validity intervals are disjoint — ${short(older.claimId)} was in force before ${short(newer.claimId)} took effect — so this is succession rather than contradiction (spec §14: consider effective time)`,
|
|
463
|
+
qualification: `Superseded in time: this held until ${isoDay(newer.effectiveAt)}, when "${shortText(newer.text)}" took effect.`,
|
|
464
|
+
detectedAt: now,
|
|
465
|
+
});
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
// AUTHORITY_DISAGREEMENT is design §11's classifier *over* the other detectors' output:
|
|
469
|
+
// "any contradiction whose sides differ ≥ 0.2 in authority". It is applied here rather than
|
|
470
|
+
// in a second pass so that the record carries one class rather than being emitted and then
|
|
471
|
+
// relabelled, which a replay could not tell from two different conflicts.
|
|
472
|
+
const authorityA = authority(a.claimId);
|
|
473
|
+
const authorityB = authority(b.claimId);
|
|
474
|
+
const gap = authorityA === undefined || authorityB === undefined ? null : Math.abs(authorityA - authorityB);
|
|
475
|
+
if (gap !== null && gap >= authorityGap && authorityA !== undefined && authorityB !== undefined) {
|
|
476
|
+
const winner = authorityA > authorityB ? a : b;
|
|
477
|
+
const loser = authorityA > authorityB ? b : a;
|
|
478
|
+
record({
|
|
479
|
+
conflictId: conflictIdFor(detector, ids, "authority"),
|
|
480
|
+
conflictClass: "AUTHORITY_DISAGREEMENT",
|
|
481
|
+
outcome: "SELECT_HIGHER_AUTHORITY",
|
|
482
|
+
detector,
|
|
483
|
+
claimIds: ids,
|
|
484
|
+
winnerClaimId: winner.claimId,
|
|
485
|
+
supersededClaimIds: [loser.claimId],
|
|
486
|
+
unresolved: false,
|
|
487
|
+
similarity: pair.similarity,
|
|
488
|
+
authorityGap: gap,
|
|
489
|
+
chainDepth: null,
|
|
490
|
+
rationale: `${basis}; the two sides differ by ${gap.toFixed(2)} in source authority (≥ ${authorityGap}), so the higher-standing source is preferred and the other is kept as context`,
|
|
491
|
+
qualification: `A lower-authority source states this differently; the higher-authority record is preferred. Both are shown.`,
|
|
492
|
+
detectedAt: now,
|
|
493
|
+
});
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
record({
|
|
497
|
+
conflictId: conflictIdFor(detector, ids, "contradiction"),
|
|
498
|
+
conflictClass: "DIRECT_CONTRADICTION",
|
|
499
|
+
outcome: "MARK_DISPUTED",
|
|
500
|
+
detector,
|
|
501
|
+
claimIds: ids,
|
|
502
|
+
winnerClaimId: null,
|
|
503
|
+
// Both sides are demoted: neither may stand as a confirmed fact while the other exists.
|
|
504
|
+
supersededClaimIds: ids,
|
|
505
|
+
unresolved: true,
|
|
506
|
+
similarity: pair.similarity,
|
|
507
|
+
authorityGap: gap,
|
|
508
|
+
chainDepth: null,
|
|
509
|
+
rationale: `two statements about the same subject (jaccard₃ ${pair.shingleSimilarity.toFixed(3)} / jaccard₁ ${pair.tokenSimilarity.toFixed(3)}) disagree and nothing settles it: ${basis}. Their validity intervals overlap and their sources are of comparable standing, so Mnemosia states the disagreement rather than picking a side`,
|
|
510
|
+
qualification: `Disputed: another retrieved statement contradicts this one (${basis}). Neither has been treated as established.`,
|
|
511
|
+
detectedAt: now,
|
|
512
|
+
});
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (preferenceChange(a, b)) {
|
|
516
|
+
const [newer, older] = [a, b].sort(newerFirst);
|
|
517
|
+
record({
|
|
518
|
+
conflictId: conflictIdFor("preference_change", ids, "preference"),
|
|
519
|
+
conflictClass: "PREFERENCE_CHANGE",
|
|
520
|
+
outcome: "SELECT_NEWER_VALID",
|
|
521
|
+
detector: "preference_change",
|
|
522
|
+
claimIds: ids,
|
|
523
|
+
winnerClaimId: newer.claimId,
|
|
524
|
+
supersededClaimIds: [older.claimId],
|
|
525
|
+
unresolved: false,
|
|
526
|
+
similarity: pair.similarity,
|
|
527
|
+
authorityGap: null,
|
|
528
|
+
chainDepth: null,
|
|
529
|
+
rationale: `two PREFERENCE claims about the same subject (jaccard₃ ${pair.shingleSimilarity.toFixed(3)} / jaccard₁ ${pair.tokenSimilarity.toFixed(3)}) were recorded at different times with different content; a preference is a standing instruction and the most recent statement of it is the one in force`,
|
|
530
|
+
qualification: `Superseded preference: the user restated this on ${isoDay(newer.effectiveAt)} as "${shortText(newer.text)}". The earlier wording is kept for context.`,
|
|
531
|
+
detectedAt: now,
|
|
532
|
+
});
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
const plan = planVersusFact(a, b);
|
|
536
|
+
if (plan.matches) {
|
|
537
|
+
const planClaim = plan.planSide === "a" ? a : b;
|
|
538
|
+
const factClaim = plan.planSide === "a" ? b : a;
|
|
539
|
+
record({
|
|
540
|
+
conflictId: conflictIdFor("plan_versus_fact", ids, "plan"),
|
|
541
|
+
conflictClass: "PLAN_VERSUS_FACT",
|
|
542
|
+
outcome: "INCLUDE_BOTH_WITH_QUALIFICATION",
|
|
543
|
+
detector: "plan_versus_fact",
|
|
544
|
+
claimIds: ids,
|
|
545
|
+
winnerClaimId: null,
|
|
546
|
+
// Neither is demoted. A plan and an observation about the same subject are both true
|
|
547
|
+
// statements of different kinds; the reader needs to know which is which, not to lose one.
|
|
548
|
+
supersededClaimIds: [],
|
|
549
|
+
unresolved: true,
|
|
550
|
+
similarity: pair.similarity,
|
|
551
|
+
authorityGap: null,
|
|
552
|
+
chainDepth: null,
|
|
553
|
+
rationale: `${short(planClaim.claimId)} is a PLAN and ${short(factClaim.claimId)} is a ${factClaim.claimType} about the same subject (jaccard₃ ${pair.shingleSimilarity.toFixed(3)} / jaccard₁ ${pair.tokenSimilarity.toFixed(3)}); an intention and an observation are not interchangeable and a briefing that presented the plan as the state of the world would be wrong`,
|
|
554
|
+
qualification: `One of these is an intention and the other is what was observed; they are shown together so the plan is not read as the outcome.`,
|
|
555
|
+
detectedAt: now,
|
|
556
|
+
});
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
// A near-duplicate that no predicate explains is not a conflict. It is redundancy, and
|
|
560
|
+
// `select.ts`'s λ·jaccard₃ penalty is what handles redundancy. Counted so the taxonomy's
|
|
561
|
+
// coverage is measurable rather than assumed.
|
|
562
|
+
pairsUnexplained += 1;
|
|
563
|
+
}
|
|
564
|
+
/* --- 6: temporal validity (Phase 2) --------------------------------------------------------- */
|
|
565
|
+
//
|
|
566
|
+
// A claim whose `effectiveAt` is in the future is maximally *fresh* and not yet *true*. Design §9
|
|
567
|
+
// clamps age at 0, so freshness cannot express this and would in fact reward it. There is no class
|
|
568
|
+
// in spec §14's closed ten for "a validity-window state", so it takes `UNRESOLVED`, which design
|
|
569
|
+
// §11 defines as the bucket for anything detected and not classifiable into the other nine.
|
|
570
|
+
for (const claim of [...claims].sort((a, b) => (a.claimId < b.claimId ? -1 : 1))) {
|
|
571
|
+
const provenance = graph.byClaim.get(claim.claimId);
|
|
572
|
+
if (provenance === undefined)
|
|
573
|
+
continue;
|
|
574
|
+
if (provenance.temporal.status !== "not_yet_effective")
|
|
575
|
+
continue;
|
|
576
|
+
if (explained.has(claim.claimId))
|
|
577
|
+
continue;
|
|
578
|
+
record({
|
|
579
|
+
conflictId: conflictIdFor("temporal_validity", [claim.claimId], "not_yet_effective"),
|
|
580
|
+
conflictClass: "UNRESOLVED",
|
|
581
|
+
outcome: "REQUEST_VERIFICATION",
|
|
582
|
+
detector: "temporal_validity",
|
|
583
|
+
claimIds: [claim.claimId],
|
|
584
|
+
winnerClaimId: null,
|
|
585
|
+
supersededClaimIds: [claim.claimId],
|
|
586
|
+
unresolved: true,
|
|
587
|
+
similarity: null,
|
|
588
|
+
authorityGap: null,
|
|
589
|
+
chainDepth: null,
|
|
590
|
+
rationale: `${short(claim.claimId)} does not take effect until ${isoDay(claim.effectiveAt)}; it is temporally valid in the future and is not a statement about the present, which freshness alone cannot express because a future effectiveAt clamps to age 0`,
|
|
591
|
+
qualification: `Not yet in force: this takes effect on ${isoDay(claim.effectiveAt)}. It is shown because it is scheduled, not because it is true now.`,
|
|
592
|
+
detectedAt: now,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
/* --- 7: DISPUTED lifecycle ------------------------------------------------------------------ */
|
|
596
|
+
//
|
|
597
|
+
// Design §12: DISPUTED is retrievable but "admitted only into `conflicts[]`, never
|
|
598
|
+
// `confirmed_facts[]`". Without a record here it would be admitted and then have nowhere to go.
|
|
599
|
+
for (const claim of [...claims].sort((a, b) => (a.claimId < b.claimId ? -1 : 1))) {
|
|
600
|
+
if (claim.lifecycle !== "DISPUTED")
|
|
601
|
+
continue;
|
|
602
|
+
if (explained.has(claim.claimId))
|
|
603
|
+
continue;
|
|
604
|
+
record({
|
|
605
|
+
conflictId: conflictIdFor("disputed_lifecycle", [claim.claimId], "lifecycle"),
|
|
606
|
+
conflictClass: "UNRESOLVED",
|
|
607
|
+
outcome: "MARK_DISPUTED",
|
|
608
|
+
detector: "disputed_lifecycle",
|
|
609
|
+
claimIds: [claim.claimId],
|
|
610
|
+
winnerClaimId: null,
|
|
611
|
+
supersededClaimIds: [claim.claimId],
|
|
612
|
+
unresolved: true,
|
|
613
|
+
similarity: null,
|
|
614
|
+
authorityGap: null,
|
|
615
|
+
chainDepth: null,
|
|
616
|
+
rationale: "the source marked this claim DISPUTED; design §12 admits DISPUTED into conflicts[] and nowhere else, and no counterpart was retrieved to weigh it against",
|
|
617
|
+
qualification: "The source marked this statement disputed. It is shown for context and must not be treated as an established fact.",
|
|
618
|
+
detectedAt: now,
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
/* --- assembly ------------------------------------------------------------------------------- */
|
|
622
|
+
const index = new Map();
|
|
623
|
+
const mandatory = new Set();
|
|
624
|
+
for (const entry of conflicts) {
|
|
625
|
+
for (const claimId of entry.claimIds) {
|
|
626
|
+
if (!byClaimId.has(claimId))
|
|
627
|
+
continue;
|
|
628
|
+
const bucket = index.get(claimId);
|
|
629
|
+
if (bucket === undefined)
|
|
630
|
+
index.set(claimId, [entry]);
|
|
631
|
+
else
|
|
632
|
+
bucket.push(entry);
|
|
633
|
+
if (entry.unresolved)
|
|
634
|
+
mandatory.add(claimId);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
for (const claimId of demoted.keys())
|
|
638
|
+
if (byClaimId.has(claimId))
|
|
639
|
+
mandatory.add(claimId);
|
|
640
|
+
const byClass = Object.fromEntries(CONFLICT_CLASSES.map((entry) => [entry, 0]));
|
|
641
|
+
const byOutcome = Object.fromEntries(CONFLICT_OUTCOMES.map((entry) => [entry, 0]));
|
|
642
|
+
const byDetector = Object.fromEntries(CONFLICT_DETECTORS.map((entry) => [entry, 0]));
|
|
643
|
+
for (const entry of conflicts) {
|
|
644
|
+
byClass[entry.conflictClass] += 1;
|
|
645
|
+
byOutcome[entry.outcome] += 1;
|
|
646
|
+
byDetector[entry.detector] += 1;
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
conflicts,
|
|
650
|
+
byClaimId: index,
|
|
651
|
+
demoted,
|
|
652
|
+
mandatory,
|
|
653
|
+
// Empty here, always. `detectConflicts` does not know who is reading, and presentation is a
|
|
654
|
+
// property of the reader. `applyConflictPresentation` fills it.
|
|
655
|
+
presented: new Set(),
|
|
656
|
+
graph,
|
|
657
|
+
stats: {
|
|
658
|
+
claimsIn: claims.length,
|
|
659
|
+
conflicts: conflicts.length,
|
|
660
|
+
byClass,
|
|
661
|
+
byOutcome,
|
|
662
|
+
byDetector,
|
|
663
|
+
demoted: demoted.size,
|
|
664
|
+
danglingReferences,
|
|
665
|
+
unresolved: conflicts.filter((entry) => entry.unresolved).length,
|
|
666
|
+
pairsExamined: graph.neighbours.length,
|
|
667
|
+
pairsUnexplained,
|
|
668
|
+
ungroundedSummaries: graph.stats.byGrounding.session_absent,
|
|
669
|
+
},
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function qualifierRecord(detector, conflictClass, ids, similarity, left, right, kind, now) {
|
|
673
|
+
return {
|
|
674
|
+
conflictId: conflictIdFor(detector, ids, kind),
|
|
675
|
+
conflictClass,
|
|
676
|
+
outcome: "KEEP_SCOPE_SPECIFIC_VARIANTS",
|
|
677
|
+
detector,
|
|
678
|
+
claimIds: ids,
|
|
679
|
+
winnerClaimId: null,
|
|
680
|
+
// Neither side loses. Design §2 made branch and environment *qualifiers*: two statements about
|
|
681
|
+
// two branches are both true, and demoting either would erase a distinction the reader needs.
|
|
682
|
+
supersededClaimIds: [],
|
|
683
|
+
unresolved: false,
|
|
684
|
+
similarity,
|
|
685
|
+
authorityGap: null,
|
|
686
|
+
chainDepth: null,
|
|
687
|
+
rationale: `two near-identical statements (similarity ${similarity.toFixed(3)}) carry disjoint ${kind} qualifiers — ${left.join("/")} versus ${right.join("/")} — so they describe different ${kind}es rather than disagreeing about one`,
|
|
688
|
+
qualification: `These describe different ${kind}es (${left.join("/")} and ${right.join("/")}); both are kept and neither generalizes to the other.`,
|
|
689
|
+
detectedAt: now,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
/** The qualification sentences attached to one claim, in record order. Empty when it is unconflicted. */
|
|
693
|
+
export function qualificationsFor(resolution, claimId) {
|
|
694
|
+
return (resolution.byClaimId.get(claimId) ?? []).map((entry) => entry.qualification);
|
|
695
|
+
}
|
|
696
|
+
/* ------------------------------------------------------------------------------------------------
|
|
697
|
+
* Presentation (Phase 4)
|
|
698
|
+
* ---------------------------------------------------------------------------------------------- */
|
|
699
|
+
/**
|
|
700
|
+
* Re-presents resolved conflicts as `INCLUDE_BOTH_WITH_QUALIFICATION` for a seat that asked for the
|
|
701
|
+
* disagreement rather than for Mnemosia's answer to it (`agents.ts`: Elaria and Nytheria).
|
|
702
|
+
*
|
|
703
|
+
* **What it does not do, and why.** It does not promote a demoted claim back into a factual section.
|
|
704
|
+
* Design §16 gates stale inclusion at **0** — a superseded or expired claim may appear only inside
|
|
705
|
+
* `conflicts[]` — and that gate is not a presentation preference any seat can opt out of. So the
|
|
706
|
+
* move is the other direction: the *winner* joins the loser inside `conflicts[]`, both carrying the
|
|
707
|
+
* record's qualification, and neither is offered to the reader as settled fact. That is spec §14's
|
|
708
|
+
* `INCLUDE_BOTH_WITH_QUALIFICATION` read exactly — include both, qualified — rather than
|
|
709
|
+
* "un-supersede the loser", which §14 has no outcome for and §16 forbids.
|
|
710
|
+
*
|
|
711
|
+
* The cost is real and is not hidden: a validator who takes this option gives up the factual section
|
|
712
|
+
* those winners would have occupied, and gets a conflicts block that shows the disagreement. That is
|
|
713
|
+
* the trade Elaria's role wants and Raskreia's does not, which is why the two share a ranking policy
|
|
714
|
+
* and differ here.
|
|
715
|
+
*
|
|
716
|
+
* Escalated conflicts are **not** re-presented: an `ESCALATE_TO_*` record is already unresolved by
|
|
717
|
+
* construction, both sides are already in `conflicts[]`, and rewriting its outcome would erase the
|
|
718
|
+
* routing label `escalation.ts` just applied.
|
|
719
|
+
*/
|
|
720
|
+
export function applyConflictPresentation(resolution, presentation) {
|
|
721
|
+
if (presentation === "resolved")
|
|
722
|
+
return resolution;
|
|
723
|
+
const presented = new Set();
|
|
724
|
+
const byOutcome = { ...resolution.stats.byOutcome };
|
|
725
|
+
const conflicts = resolution.conflicts.map((record) => {
|
|
726
|
+
// Only a conflict that *picked a side* has an answer to withhold. An unresolved or escalated
|
|
727
|
+
// record already shows both sides, and `KEEP_SCOPE_SPECIFIC_VARIANTS` already says both are
|
|
728
|
+
// correct where they were recorded — restating either as a qualified inclusion would replace a
|
|
729
|
+
// precise outcome with a vaguer one and lose information rather than add it.
|
|
730
|
+
if (record.unresolved || record.winnerClaimId === null)
|
|
731
|
+
return record;
|
|
732
|
+
if (record.outcome === "ESCALATE_TO_ELARIA" || record.outcome === "ESCALATE_TO_RASKREIA")
|
|
733
|
+
return record;
|
|
734
|
+
if (record.outcome === "INCLUDE_BOTH_WITH_QUALIFICATION" || record.outcome === "KEEP_SCOPE_SPECIFIC_VARIANTS")
|
|
735
|
+
return record;
|
|
736
|
+
presented.add(record.winnerClaimId);
|
|
737
|
+
byOutcome[record.outcome] -= 1;
|
|
738
|
+
byOutcome.INCLUDE_BOTH_WITH_QUALIFICATION += 1;
|
|
739
|
+
return {
|
|
740
|
+
...record,
|
|
741
|
+
outcome: "INCLUDE_BOTH_WITH_QUALIFICATION",
|
|
742
|
+
qualification: `${record.qualification} Both sides are shown because this seat receives disagreements rather than resolutions; Mnemosia's own reading was ${record.outcome}.`,
|
|
743
|
+
};
|
|
744
|
+
});
|
|
745
|
+
if (presented.size === 0)
|
|
746
|
+
return resolution;
|
|
747
|
+
const mandatory = new Set(resolution.mandatory);
|
|
748
|
+
// A claim moved into `conflicts[]` has to be *reserved* into it as well. Without this it competes
|
|
749
|
+
// for the 5%–25% conflicts share on marginal value alone, and the winner of a supersession — which
|
|
750
|
+
// by construction scored high enough to win — could be cut by quota, leaving the reader a demoted
|
|
751
|
+
// loser with no visible counterpart. That is strictly worse than not re-presenting at all.
|
|
752
|
+
for (const claimId of presented)
|
|
753
|
+
mandatory.add(claimId);
|
|
754
|
+
const byClaimId = new Map();
|
|
755
|
+
for (const record of conflicts) {
|
|
756
|
+
for (const claimId of record.claimIds) {
|
|
757
|
+
const list = byClaimId.get(claimId);
|
|
758
|
+
if (list === undefined)
|
|
759
|
+
byClaimId.set(claimId, [record]);
|
|
760
|
+
else
|
|
761
|
+
list.push(record);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
const byId = new Map(conflicts.map((record) => [record.conflictId, record]));
|
|
765
|
+
const demoted = new Map();
|
|
766
|
+
for (const [claimId, record] of resolution.demoted)
|
|
767
|
+
demoted.set(claimId, byId.get(record.conflictId) ?? record);
|
|
768
|
+
return { ...resolution, conflicts, byClaimId, demoted, mandatory, presented, stats: { ...resolution.stats, byOutcome } };
|
|
769
|
+
}
|