daftari 3.0.0 → 3.1.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 +19 -0
- package/README.md +11 -5
- package/dist/access/locks.d.ts +1 -0
- package/dist/access/locks.d.ts.map +1 -1
- package/dist/access/locks.js +13 -0
- package/dist/access/locks.js.map +1 -1
- package/dist/access/rbac.js +3 -3
- package/dist/access/rbac.js.map +1 -1
- package/dist/asof/git-read.d.ts.map +1 -1
- package/dist/asof/git-read.js +4 -0
- package/dist/asof/git-read.js.map +1 -1
- package/dist/backfill/derive.d.ts.map +1 -1
- package/dist/backfill/derive.js +3 -0
- package/dist/backfill/derive.js.map +1 -1
- package/dist/curation/lint-voice.d.ts.map +1 -1
- package/dist/curation/lint-voice.js +1 -0
- package/dist/curation/lint-voice.js.map +1 -1
- package/dist/curation/lint.d.ts +1 -1
- package/dist/curation/lint.d.ts.map +1 -1
- package/dist/curation/lint.js +80 -0
- package/dist/curation/lint.js.map +1 -1
- package/dist/curation/positions.d.ts +29 -0
- package/dist/curation/positions.d.ts.map +1 -0
- package/dist/curation/positions.js +164 -0
- package/dist/curation/positions.js.map +1 -0
- package/dist/curation/staleness.d.ts +0 -7
- package/dist/curation/staleness.d.ts.map +1 -1
- package/dist/curation/staleness.js +0 -30
- package/dist/curation/staleness.js.map +1 -1
- package/dist/curation/tension.d.ts +5 -2
- package/dist/curation/tension.d.ts.map +1 -1
- package/dist/curation/tension.js +169 -103
- package/dist/curation/tension.js.map +1 -1
- package/dist/curation/vault-docs.d.ts +10 -0
- package/dist/curation/vault-docs.d.ts.map +1 -1
- package/dist/curation/vault-docs.js +101 -10
- package/dist/curation/vault-docs.js.map +1 -1
- package/dist/eval/llm-openrouter.d.ts.map +1 -1
- package/dist/eval/llm-openrouter.js +8 -0
- package/dist/eval/llm-openrouter.js.map +1 -1
- package/dist/frontmatter/schema.d.ts.map +1 -1
- package/dist/frontmatter/schema.js +118 -1
- package/dist/frontmatter/schema.js.map +1 -1
- package/dist/frontmatter/types.d.ts +26 -2
- package/dist/frontmatter/types.d.ts.map +1 -1
- package/dist/frontmatter/types.js +7 -0
- package/dist/frontmatter/types.js.map +1 -1
- package/dist/lifecycle/lock.d.ts +2 -0
- package/dist/lifecycle/lock.d.ts.map +1 -1
- package/dist/lifecycle/lock.js +98 -18
- package/dist/lifecycle/lock.js.map +1 -1
- package/dist/search/providers/openai-3-small.d.ts.map +1 -1
- package/dist/search/providers/openai-3-small.js +8 -0
- package/dist/search/providers/openai-3-small.js.map +1 -1
- package/dist/search/reindex.d.ts.map +1 -1
- package/dist/search/reindex.js +39 -13
- package/dist/search/reindex.js.map +1 -1
- package/dist/serve/index.d.ts +4 -1
- package/dist/serve/index.d.ts.map +1 -1
- package/dist/serve/index.js +28 -12
- package/dist/serve/index.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -1
- package/dist/storage/index-db.d.ts +1 -0
- package/dist/storage/index-db.d.ts.map +1 -1
- package/dist/storage/index-db.js +17 -2
- package/dist/storage/index-db.js.map +1 -1
- package/dist/tools/positions.d.ts +42 -0
- package/dist/tools/positions.d.ts.map +1 -0
- package/dist/tools/positions.js +711 -0
- package/dist/tools/positions.js.map +1 -0
- package/dist/tools/read.d.ts +24 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +186 -2
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/write.d.ts +25 -2
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +63 -10
- package/dist/tools/write.js.map +1 -1
- package/dist/utils/concurrency.d.ts +2 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +39 -0
- package/dist/utils/concurrency.js.map +1 -0
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +5 -1
- package/dist/utils/git.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Pure position logic for multi-principal contested beliefs (Slice 1).
|
|
2
|
+
//
|
|
3
|
+
// One claim doc carries a positions[] set (frontmatter/types.ts). This module
|
|
4
|
+
// owns id allocation, supersession, the R-1 conflict rule (assert × dispute;
|
|
5
|
+
// qualify conflicts with nothing), the contested derivation, and the
|
|
6
|
+
// foreign-position guard rule (LD-13). No I/O: the tools layer feeds it
|
|
7
|
+
// parsed frontmatter and writes the result back.
|
|
8
|
+
import { CONFIDENCES, } from "../frontmatter/types.js";
|
|
9
|
+
// Assigns the next sequential pos-NNN id. Scans EVERY entry (live and
|
|
10
|
+
// superseded — ids are never reused) for the highest numeric suffix,
|
|
11
|
+
// mirroring nextTensionId (tension.ts:139–150).
|
|
12
|
+
export function nextPositionId(existing) {
|
|
13
|
+
let max = 0;
|
|
14
|
+
for (const p of existing) {
|
|
15
|
+
const m = p.id.match(/^pos-(\d+)$/);
|
|
16
|
+
if (!m)
|
|
17
|
+
continue;
|
|
18
|
+
const n = Number.parseInt(m[1], 10);
|
|
19
|
+
if (Number.isFinite(n) && n > max)
|
|
20
|
+
max = n;
|
|
21
|
+
}
|
|
22
|
+
return `pos-${String(max + 1).padStart(3, "0")}`;
|
|
23
|
+
}
|
|
24
|
+
export function unsuperseded(positions) {
|
|
25
|
+
return positions.filter((p) => p.superseded_by == null);
|
|
26
|
+
}
|
|
27
|
+
// U-12 / LD-22: system-authored snapshot of a legacy doc's prior belief,
|
|
28
|
+
// minted by the first vault_assert on a doc whose typed positions is null.
|
|
29
|
+
// `principal: "unknown"` is a reserved, unforgeable identity — the tools
|
|
30
|
+
// layer rejects any live caller from claiming it (C-2 guard 1). Pure, no I/O.
|
|
31
|
+
export function legacySnapshot(fm) {
|
|
32
|
+
return {
|
|
33
|
+
id: "pos-000",
|
|
34
|
+
principal: "unknown",
|
|
35
|
+
stance: "assert",
|
|
36
|
+
statement: null,
|
|
37
|
+
confidence: fm.confidence,
|
|
38
|
+
provenance: fm.provenance,
|
|
39
|
+
valid_from: fm.valid_from,
|
|
40
|
+
superseded_by: null,
|
|
41
|
+
created: fm.updated,
|
|
42
|
+
sources: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// R-1 (locked): contested ⇔ the live set holds ≥1 assert AND ≥1 dispute.
|
|
46
|
+
// Stance-enum-only — no statement-text comparison anywhere in daftari.
|
|
47
|
+
export function isContested(positions) {
|
|
48
|
+
const live = unsuperseded(positions);
|
|
49
|
+
return live.some((p) => p.stance === "assert") && live.some((p) => p.stance === "dispute");
|
|
50
|
+
}
|
|
51
|
+
// The conflict pairs a (new) position forms: it against each LIVE position of
|
|
52
|
+
// the opposing stance. qualify opposes nothing. Pair order is (existing,
|
|
53
|
+
// incoming) so tension claims read chronologically.
|
|
54
|
+
export function conflictPairs(incoming, positions) {
|
|
55
|
+
const opposite = incoming.stance === "assert" ? "dispute" : incoming.stance === "dispute" ? "assert" : null;
|
|
56
|
+
if (opposite === null)
|
|
57
|
+
return [];
|
|
58
|
+
return unsuperseded(positions)
|
|
59
|
+
.filter((p) => p.id !== incoming.id && p.stance === opposite)
|
|
60
|
+
.map((p) => ({ a: p, b: incoming }));
|
|
61
|
+
}
|
|
62
|
+
// LD-11 ordering: confidence desc (high first), created desc, id asc.
|
|
63
|
+
export function comparePositions(a, b) {
|
|
64
|
+
const conf = CONFIDENCES.indexOf(b.confidence) - CONFIDENCES.indexOf(a.confidence);
|
|
65
|
+
if (conf !== 0)
|
|
66
|
+
return conf;
|
|
67
|
+
if (a.created !== b.created)
|
|
68
|
+
return a.created < b.created ? 1 : -1;
|
|
69
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
70
|
+
}
|
|
71
|
+
// LD-18: the dissent a ratified org stance carries — ids of unsuperseded
|
|
72
|
+
// positions whose stance opposes the ratified one under the R-1 rule
|
|
73
|
+
// (assert<->dispute; qualify opposes nothing). Computed by vault_consolidate
|
|
74
|
+
// at ratify time, LD-11 ordered — never hand-supplied.
|
|
75
|
+
export function dissentIds(positions, stance) {
|
|
76
|
+
const opposite = stance === "assert" ? "dispute" : stance === "dispute" ? "assert" : null;
|
|
77
|
+
if (opposite === null)
|
|
78
|
+
return [];
|
|
79
|
+
return unsuperseded(positions)
|
|
80
|
+
.filter((p) => p.stance === opposite)
|
|
81
|
+
.sort(comparePositions)
|
|
82
|
+
.map((p) => p.id);
|
|
83
|
+
}
|
|
84
|
+
// R-4: append the caller's new position; set THEIR prior live position's
|
|
85
|
+
// superseded_by to it. Never edits or deletes any other principal's entry;
|
|
86
|
+
// never mutates its inputs.
|
|
87
|
+
export function applyAssert(positions, input) {
|
|
88
|
+
const existing = positions ?? [];
|
|
89
|
+
const id = nextPositionId(existing);
|
|
90
|
+
const newPosition = {
|
|
91
|
+
id,
|
|
92
|
+
principal: input.principal,
|
|
93
|
+
stance: input.stance,
|
|
94
|
+
statement: input.statement,
|
|
95
|
+
confidence: input.confidence,
|
|
96
|
+
provenance: input.provenance,
|
|
97
|
+
valid_from: input.valid_from,
|
|
98
|
+
superseded_by: null,
|
|
99
|
+
created: input.created,
|
|
100
|
+
sources: input.sources,
|
|
101
|
+
};
|
|
102
|
+
let superseded = null;
|
|
103
|
+
const next = existing.map((p) => {
|
|
104
|
+
if (p.principal === input.principal && p.superseded_by == null) {
|
|
105
|
+
superseded = { ...p, superseded_by: id };
|
|
106
|
+
return superseded;
|
|
107
|
+
}
|
|
108
|
+
return p;
|
|
109
|
+
});
|
|
110
|
+
return { positions: [...next, newPosition], newPosition, superseded };
|
|
111
|
+
}
|
|
112
|
+
// LD-13 / R-12: the foreign-position guard rule, shared by vault_write's
|
|
113
|
+
// direct update path and its propose-only stage preview. Returns a human
|
|
114
|
+
// description of the first violation, or null when the update is legal.
|
|
115
|
+
//
|
|
116
|
+
// Violations: an existing entry whose principal !== user is REMOVED or
|
|
117
|
+
// ALTERED. One carve-out: an alteration whose ONLY delta is
|
|
118
|
+
// superseded_by null → the id of an incoming entry held by the SAME
|
|
119
|
+
// principal as the altered entry — a self-supersession replayed by a
|
|
120
|
+
// ratifier (vault_ratify dispatches staged writes under the ratifier's
|
|
121
|
+
// access). Appending entries — own or foreign — is deliberately NOT a
|
|
122
|
+
// violation (R-12 scopes to mutate/remove; ratify replay appends the
|
|
123
|
+
// proposer's new entry under the ratifier's identity).
|
|
124
|
+
export function foreignPositionViolation(before, after, user) {
|
|
125
|
+
const incoming = after ?? [];
|
|
126
|
+
const byId = new Map(incoming.map((p) => [p.id, p]));
|
|
127
|
+
for (const old of before) {
|
|
128
|
+
if (old.principal === user)
|
|
129
|
+
continue;
|
|
130
|
+
const next = byId.get(old.id);
|
|
131
|
+
if (!next) {
|
|
132
|
+
return `update removes position ${old.id} held by '${old.principal}'`;
|
|
133
|
+
}
|
|
134
|
+
if (samePosition(old, next))
|
|
135
|
+
continue;
|
|
136
|
+
const onlySupersededByChanged = samePosition(old, {
|
|
137
|
+
...next,
|
|
138
|
+
superseded_by: old.superseded_by,
|
|
139
|
+
});
|
|
140
|
+
const successor = next.superseded_by != null ? byId.get(next.superseded_by) : undefined;
|
|
141
|
+
if (onlySupersededByChanged &&
|
|
142
|
+
old.superseded_by == null &&
|
|
143
|
+
successor !== undefined &&
|
|
144
|
+
successor.principal === old.principal) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
return `update alters position ${old.id} held by '${old.principal}'`;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
function samePosition(a, b) {
|
|
152
|
+
return (a.id === b.id &&
|
|
153
|
+
a.principal === b.principal &&
|
|
154
|
+
a.stance === b.stance &&
|
|
155
|
+
a.statement === b.statement &&
|
|
156
|
+
a.confidence === b.confidence &&
|
|
157
|
+
a.provenance === b.provenance &&
|
|
158
|
+
a.valid_from === b.valid_from &&
|
|
159
|
+
a.superseded_by === b.superseded_by &&
|
|
160
|
+
a.created === b.created &&
|
|
161
|
+
a.sources.length === b.sources.length &&
|
|
162
|
+
a.sources.every((s, i) => s === b.sources[i]));
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=positions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positions.js","sourceRoot":"","sources":["../../src/curation/positions.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,qEAAqE;AACrE,wEAAwE;AACxE,iDAAiD;AAEjD,OAAO,EACL,WAAW,GAMZ,MAAM,yBAAyB,CAAC;AAEjC,sEAAsE;AACtE,qEAAqE;AACrE,gDAAgD;AAChD,MAAM,UAAU,cAAc,CAAC,QAAoB;IACjD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACpC,IAAI,CAAC,CAAC;YAAE,SAAS;QACjB,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG;YAAE,GAAG,GAAG,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,OAAO,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,SAAqB;IAChD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,yEAAyE;AACzE,2EAA2E;AAC3E,yEAAyE;AACzE,8EAA8E;AAC9E,MAAM,UAAU,cAAc,CAC5B,EAA6E;IAE7E,OAAO;QACL,EAAE,EAAE,SAAS;QACb,SAAS,EAAE,SAAS;QACpB,MAAM,EA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AAK,CAAC,CAAC,EAAE;QACb,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS;QAC3B,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QACrB,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS;QAC3B,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU;QAC7B,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU;QAC7B,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU;QAC7B,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,aAAa;QACnC,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO;QACvB,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM;QACrC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Result } from "../frontmatter/types.js";
|
|
2
1
|
export declare function ageInDays(dateISO: string, now?: Date): number;
|
|
3
2
|
export interface StalenessResult {
|
|
4
3
|
score: number;
|
|
@@ -10,10 +9,4 @@ export declare function computeStaleness(input: {
|
|
|
10
9
|
updated: string;
|
|
11
10
|
ttl_days: number | null;
|
|
12
11
|
}, now?: Date): StalenessResult;
|
|
13
|
-
export interface StaleFile {
|
|
14
|
-
path: string;
|
|
15
|
-
title: string;
|
|
16
|
-
staleness: StalenessResult;
|
|
17
|
-
}
|
|
18
|
-
export declare function listStaleFiles(vaultRoot: string, threshold?: number, now?: Date): Promise<Result<StaleFile[], Error>>;
|
|
19
12
|
//# sourceMappingURL=staleness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staleness.d.ts","sourceRoot":"","sources":["../../src/curation/staleness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"staleness.d.ts","sourceRoot":"","sources":["../../src/curation/staleness.ts"],"names":[],"mappings":"AAcA,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAIzE;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAKD,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACnD,GAAG,GAAE,IAAiB,GACrB,eAAe,CAejB"}
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
//
|
|
8
8
|
// This is advisory only. Nothing here edits a file or changes a status; it
|
|
9
9
|
// reports a number the curator (vault_lint, vault_status) can act on.
|
|
10
|
-
import { parseDocument } from "../frontmatter/parser.js";
|
|
11
|
-
import { ok } from "../frontmatter/types.js";
|
|
12
|
-
import { listFiles, readFile, resolveVaultPath } from "../storage/local.js";
|
|
13
10
|
const MS_PER_DAY = 86_400_000;
|
|
14
11
|
// Whole days between an ISO date (YYYY-MM-DD) and `now`. Negative if the date
|
|
15
12
|
// is in the future; NaN-safe — an unparseable date yields 0.
|
|
@@ -37,31 +34,4 @@ export function computeStaleness(input, now = new Date()) {
|
|
|
37
34
|
const score = Math.min(1, Math.max(0, ratio));
|
|
38
35
|
return { score, ageDays, ttlDays, expired: ageDays >= ttlDays };
|
|
39
36
|
}
|
|
40
|
-
// Scans the whole vault and returns documents whose decay score is at or above
|
|
41
|
-
// `threshold`, most stale first. The default threshold of 1.0 reports only
|
|
42
|
-
// documents at or past their TTL.
|
|
43
|
-
export async function listStaleFiles(vaultRoot, threshold = 1, now = new Date()) {
|
|
44
|
-
const list = await listFiles(vaultRoot);
|
|
45
|
-
if (!list.ok)
|
|
46
|
-
return list;
|
|
47
|
-
const stale = [];
|
|
48
|
-
for (const relPath of list.value) {
|
|
49
|
-
const resolved = resolveVaultPath(vaultRoot, relPath);
|
|
50
|
-
if (!resolved.ok)
|
|
51
|
-
continue;
|
|
52
|
-
const file = await readFile(resolved.value.absPath);
|
|
53
|
-
if (!file.ok)
|
|
54
|
-
continue;
|
|
55
|
-
const parsed = parseDocument(file.value);
|
|
56
|
-
if (!parsed.ok)
|
|
57
|
-
continue;
|
|
58
|
-
const fm = parsed.value.frontmatter;
|
|
59
|
-
const staleness = computeStaleness({ updated: fm.updated, ttl_days: fm.ttl_days }, now);
|
|
60
|
-
if (staleness.score >= threshold) {
|
|
61
|
-
stale.push({ path: relPath, title: fm.title, staleness });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
stale.sort((a, b) => b.staleness.score - a.staleness.score);
|
|
65
|
-
return ok(stale);
|
|
66
|
-
}
|
|
67
37
|
//# sourceMappingURL=staleness.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staleness.js","sourceRoot":"","sources":["../../src/curation/staleness.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,uEAAuE;AACvE,8EAA8E;AAC9E,0EAA0E;AAC1E,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,sEAAsE;AAEtE,
|
|
1
|
+
{"version":3,"file":"staleness.js","sourceRoot":"","sources":["../../src/curation/staleness.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,uEAAuE;AACvE,8EAA8E;AAC9E,0EAA0E;AAC1E,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,sEAAsE;AAEtE,MAAM,UAAU,GAAG,UAAU,CAAC;AAE9B,8EAA8E;AAC9E,6DAA6D;AAC7D,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,MAAY,IAAI,IAAI,EAAE;IAC/D,MAAM,IA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|
import { type Result } from "../frontmatter/types.js";
|
|
2
|
+
export declare const TENSIONS_LOCK_KEY = "__tensions__";
|
|
2
3
|
export declare const DEFAULT_TENSION_STATUS = "unresolved";
|
|
3
4
|
export declare const RESOLVED_TENSION_STATUS = "resolved";
|
|
4
|
-
export declare const TENSION_KINDS: readonly ["temporal", "factual", "interpretive", "inter-proposal", "unspecified"];
|
|
5
|
+
export declare const TENSION_KINDS: readonly ["temporal", "factual", "interpretive", "inter-proposal", "positional", "unspecified"];
|
|
5
6
|
export type TensionKind = (typeof TENSION_KINDS)[number];
|
|
6
7
|
export declare const LOGGABLE_TENSION_KINDS: readonly ["temporal", "factual", "interpretive"];
|
|
7
8
|
export type LoggableTensionKind = (typeof LOGGABLE_TENSION_KINDS)[number];
|
|
8
|
-
declare const ADDABLE_TENSION_KINDS: readonly ["temporal", "factual", "interpretive", "inter-proposal"];
|
|
9
|
+
declare const ADDABLE_TENSION_KINDS: readonly ["temporal", "factual", "interpretive", "inter-proposal", "positional"];
|
|
9
10
|
export type AddableTensionKind = (typeof ADDABLE_TENSION_KINDS)[number];
|
|
10
11
|
export declare const RESOLUTION_KINDS: readonly ["superseded", "corrected", "accepted", "invalid"];
|
|
11
12
|
export type ResolutionKind = (typeof RESOLUTION_KINDS)[number];
|
|
@@ -30,6 +31,8 @@ export interface TensionEntry {
|
|
|
30
31
|
decidedByPrincipal?: string;
|
|
31
32
|
resolved: boolean;
|
|
32
33
|
resolution?: TensionResolution;
|
|
34
|
+
positionA?: string;
|
|
35
|
+
positionB?: string;
|
|
33
36
|
}
|
|
34
37
|
export type TensionInput = Omit<TensionEntry, "date" | "status" | "kind" | "id" | "resolved" | "resolution"> & {
|
|
35
38
|
date?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tension.d.ts","sourceRoot":"","sources":["../../src/curation/tension.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tension.d.ts","sourceRoot":"","sources":["../../src/curation/tension.ts"],"names":[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,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,GAAE,IAAiB,GAAG,SAAS,GAAG,IAAI,CAQvF"}
|
package/dist/curation/tension.js
CHANGED
|
@@ -20,8 +20,14 @@
|
|
|
20
20
|
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
|
|
21
21
|
import { readFile, writeFile } from "node:fs/promises";
|
|
22
22
|
import { join } from "node:path";
|
|
23
|
+
import { acquireLock, mintLeaseHolder, openLockDb, releaseLock } from "../access/locks.js";
|
|
23
24
|
import { err, ok } from "../frontmatter/types.js";
|
|
24
25
|
import { ageInDays } from "./staleness.js";
|
|
26
|
+
// Reserved lock key for the tension-log read-modify-write (S3-b). Lock keys
|
|
27
|
+
// are otherwise canonical vault relPaths (#127/#128 rule, write.ts:642-645),
|
|
28
|
+
// and `__tensions__` is not a valid `.md` document path any write tool would
|
|
29
|
+
// ever key a lock on, so there is no real collision surface.
|
|
30
|
+
export const TENSIONS_LOCK_KEY = "__tensions__";
|
|
25
31
|
export const DEFAULT_TENSION_STATUS = "unresolved";
|
|
26
32
|
export const RESOLVED_TENSION_STATUS = "resolved";
|
|
27
33
|
// `inter-proposal` (#235): two pending staged actions contest the same
|
|
@@ -30,24 +36,32 @@ export const RESOLVED_TENSION_STATUS = "resolved";
|
|
|
30
36
|
// proposal ids. Deterministic outcome: both proposals stay pending, neither
|
|
31
37
|
// is promoted, the conflict is surfaced here — never last-write-wins, never
|
|
32
38
|
// silent.
|
|
39
|
+
//
|
|
40
|
+
// `positional` (U-3): a caller's position on a claim doc directly conflicts
|
|
41
|
+
// (R-1: assert × dispute) with another live position on the same doc.
|
|
42
|
+
// Logged automatically by vault_assert as a self-tension on the doc path
|
|
43
|
+
// (sourceA === sourceB === the doc), carrying `positionA`/`positionB` — the
|
|
44
|
+
// two conflicting positions' ids. Like inter-proposal, it is system-minted,
|
|
45
|
+
// never caller-loggable via vault_tension_log.
|
|
33
46
|
export const TENSION_KINDS = [
|
|
34
47
|
"temporal",
|
|
35
48
|
"factual",
|
|
36
49
|
"interpretive",
|
|
37
50
|
"inter-proposal",
|
|
51
|
+
"positional",
|
|
38
52
|
"unspecified",
|
|
39
53
|
];
|
|
40
54
|
// `unspecified` is for legacy entries only — never accepted on a new log.
|
|
41
|
-
// `inter-proposal`
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
55
|
+
// `inter-proposal` and `positional` are deliberately absent: both are
|
|
56
|
+
// system-generated, not a taxonomy callers pick from — vault_tension_log's
|
|
57
|
+
// kind enum is this constant, so keeping them out keeps the kinds off the
|
|
58
|
+
// public logging surface.
|
|
45
59
|
export const LOGGABLE_TENSION_KINDS = ["temporal", "factual", "interpretive"];
|
|
46
60
|
// The kinds addTension itself accepts: the caller-loggable set plus the
|
|
47
|
-
// system-generated inter-proposal
|
|
48
|
-
// stageActionWithConflictCheck, always as a
|
|
49
|
-
// target).
|
|
50
|
-
const ADDABLE_TENSION_KINDS = [...LOGGABLE_TENSION_KINDS, "inter-proposal"];
|
|
61
|
+
// system-generated inter-proposal and positional kinds (produced only by
|
|
62
|
+
// stageActionWithConflictCheck and vault_assert respectively, always as a
|
|
63
|
+
// self-tension on the contested target).
|
|
64
|
+
const ADDABLE_TENSION_KINDS = [...LOGGABLE_TENSION_KINDS, "inter-proposal", "positional"];
|
|
51
65
|
export const RESOLUTION_KINDS = ["superseded", "corrected", "accepted", "invalid"];
|
|
52
66
|
export function tensionsPath(vaultRoot) {
|
|
53
67
|
return join(vaultRoot, ".daftari", "tensions.md");
|
|
@@ -80,6 +94,10 @@ function renderEntry(entry) {
|
|
|
80
94
|
lines.push(`- **Source B:** ${entry.sourceB} says ${entry.claimB}`);
|
|
81
95
|
lines.push(`- **Status:** ${entry.status}`);
|
|
82
96
|
lines.push(`- **Logged by:** ${entry.loggedBy}`);
|
|
97
|
+
if (entry.positionA !== undefined)
|
|
98
|
+
lines.push(`- **Position A:** ${entry.positionA}`);
|
|
99
|
+
if (entry.positionB !== undefined)
|
|
100
|
+
lines.push(`- **Position B:** ${entry.positionB}`);
|
|
83
101
|
if (entry.decidedByPrincipal)
|
|
84
102
|
lines.push(`- **Decided by principal:** ${entry.decidedByPrincipal}`);
|
|
85
103
|
if (entry.resolution !== undefined) {
|
|
@@ -118,53 +136,79 @@ export async function addTension(vaultRoot, input) {
|
|
|
118
136
|
return err(new Error(`addTension 'kind' must be one of: ${ADDABLE_TENSION_KINDS.join(", ")} ` +
|
|
119
137
|
`(unspecified is for legacy entries only)`));
|
|
120
138
|
}
|
|
121
|
-
// An inter-proposal tension is by construction a
|
|
122
|
-
// contested target — enforce the shape so
|
|
123
|
-
// be minted between arbitrary, unrelated
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
// An inter-proposal or positional tension is by construction a
|
|
140
|
+
// self-tension on the contested target — enforce the shape so these
|
|
141
|
+
// system-generated kinds cannot be minted between arbitrary, unrelated
|
|
142
|
+
// documents.
|
|
143
|
+
if ((input.kind === "inter-proposal" || input.kind === "positional") &&
|
|
144
|
+
input.sourceA.trim() !== input.sourceB.trim()) {
|
|
145
|
+
return err(new Error(`addTension: a '${input.kind}' tension is a self-tension — sourceA ` +
|
|
126
146
|
"and sourceB must both be the contested target path"));
|
|
127
147
|
}
|
|
148
|
+
if (input.kind === "positional" &&
|
|
149
|
+
(typeof input.positionA !== "string" ||
|
|
150
|
+
input.positionA.trim().length === 0 ||
|
|
151
|
+
typeof input.positionB !== "string" ||
|
|
152
|
+
input.positionB.trim().length === 0)) {
|
|
153
|
+
return err(new Error("addTension: a 'positional' tension requires both 'positionA' and 'positionB'"));
|
|
154
|
+
}
|
|
155
|
+
const lockDbResult = openLockDb(vaultRoot);
|
|
156
|
+
if (!lockDbResult.ok)
|
|
157
|
+
return lockDbResult;
|
|
158
|
+
const lockDb = lockDbResult.value;
|
|
159
|
+
const holder = mintLeaseHolder(input.loggedBy);
|
|
128
160
|
try {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// one synchronous breath with no intervening await, so two concurrent
|
|
133
|
-
// addTension calls — e.g. the inter-proposal conflict check firing from
|
|
134
|
-
// two contending stagings, the exact scenario #235 targets — can never
|
|
135
|
-
// mint the same tension-NNN id. Per-process, which is sufficient under
|
|
136
|
-
// the one-process-per-vault rule (.daftari/process.lock).
|
|
137
|
-
let raw = "";
|
|
161
|
+
const lock = acquireLock(lockDb, TENSIONS_LOCK_KEY, holder);
|
|
162
|
+
if (!lock.ok)
|
|
163
|
+
return err(new Error(`cannot update tension log: ${lock.error.message}`));
|
|
138
164
|
try {
|
|
139
|
-
|
|
165
|
+
mkdirSync(join(vaultRoot, ".daftari"), { recursive: true });
|
|
166
|
+
// Critical section (mirrors stageAction's id allocation in
|
|
167
|
+
// staged-actions.ts): read the log, allocate the next id, and append in
|
|
168
|
+
// one synchronous breath with no intervening await, so two concurrent
|
|
169
|
+
// addTension calls — e.g. the inter-proposal conflict check firing from
|
|
170
|
+
// two contending stagings, the exact scenario #235 targets — can never
|
|
171
|
+
// mint the same tension-NNN id. The `__tensions__` lease above makes
|
|
172
|
+
// this an enforced invariant rather than an accident of the
|
|
173
|
+
// one-process-per-vault rule, and serializes it against resolveTension.
|
|
174
|
+
let raw = "";
|
|
175
|
+
try {
|
|
176
|
+
raw = readFileSync(tensionsPath(vaultRoot), "utf-8");
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
if (e.code !== "ENOENT")
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
182
|
+
const entry = {
|
|
183
|
+
id: nextTensionId(parseTensionLog(raw)),
|
|
184
|
+
date: input.date ?? new Date().toISOString().slice(0, 10),
|
|
185
|
+
title: input.title.trim(),
|
|
186
|
+
kind: input.kind,
|
|
187
|
+
sourceA: input.sourceA.trim(),
|
|
188
|
+
claimA: input.claimA.trim(),
|
|
189
|
+
sourceB: input.sourceB.trim(),
|
|
190
|
+
claimB: input.claimB.trim(),
|
|
191
|
+
status: input.status ?? DEFAULT_TENSION_STATUS,
|
|
192
|
+
loggedBy: input.loggedBy.trim(),
|
|
193
|
+
...(input.decidedByPrincipal != null && input.decidedByPrincipal.trim().length > 0
|
|
194
|
+
? { decidedByPrincipal: input.decidedByPrincipal.trim() }
|
|
195
|
+
: {}),
|
|
196
|
+
...(input.positionA !== undefined ? { positionA: input.positionA } : {}),
|
|
197
|
+
...(input.positionB !== undefined ? { positionB: input.positionB } : {}),
|
|
198
|
+
resolved: false,
|
|
199
|
+
};
|
|
200
|
+
// A leading blank line keeps this block separated from the previous one.
|
|
201
|
+
appendFileSync(tensionsPath(vaultRoot), `\n${renderEntry(entry)}`);
|
|
202
|
+
return ok(entry);
|
|
140
203
|
}
|
|
141
204
|
catch (e) {
|
|
142
|
-
|
|
143
|
-
|
|
205
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
206
|
+
return err(new Error(`cannot append to tension log: ${reason}`));
|
|
144
207
|
}
|
|
145
|
-
const entry = {
|
|
146
|
-
id: nextTensionId(parseTensionLog(raw)),
|
|
147
|
-
date: input.date ?? new Date().toISOString().slice(0, 10),
|
|
148
|
-
title: input.title.trim(),
|
|
149
|
-
kind: input.kind,
|
|
150
|
-
sourceA: input.sourceA.trim(),
|
|
151
|
-
claimA: input.claimA.trim(),
|
|
152
|
-
sourceB: input.sourceB.trim(),
|
|
153
|
-
claimB: input.claimB.trim(),
|
|
154
|
-
status: input.status ?? DEFAULT_TENSION_STATUS,
|
|
155
|
-
loggedBy: input.loggedBy.trim(),
|
|
156
|
-
...(input.decidedByPrincipal != null && input.decidedByPrincipal.trim().length > 0
|
|
157
|
-
? { decidedByPrincipal: input.decidedByPrincipal.trim() }
|
|
158
|
-
: {}),
|
|
159
|
-
resolved: false,
|
|
160
|
-
};
|
|
161
|
-
// A leading blank line keeps this block separated from the previous one.
|
|
162
|
-
appendFileSync(tensionsPath(vaultRoot), `\n${renderEntry(entry)}`);
|
|
163
|
-
return ok(entry);
|
|
164
208
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
209
|
+
finally {
|
|
210
|
+
releaseLock(lockDb, TENSIONS_LOCK_KEY, holder);
|
|
211
|
+
lockDb.close();
|
|
168
212
|
}
|
|
169
213
|
}
|
|
170
214
|
// `- **Source A:** <path> says <claim>` → { path, claim }. The path is
|
|
@@ -240,6 +284,12 @@ function parseBlock(block) {
|
|
|
240
284
|
else if (label === "logged by") {
|
|
241
285
|
entry.loggedBy = value.trim();
|
|
242
286
|
}
|
|
287
|
+
else if (label === "position a") {
|
|
288
|
+
entry.positionA = value.trim();
|
|
289
|
+
}
|
|
290
|
+
else if (label === "position b") {
|
|
291
|
+
entry.positionB = value.trim();
|
|
292
|
+
}
|
|
243
293
|
else if (label === "decided by principal") {
|
|
244
294
|
entry.decidedByPrincipal = value.trim();
|
|
245
295
|
}
|
|
@@ -315,66 +365,80 @@ export async function listTensions(vaultRoot, status) {
|
|
|
315
365
|
// the matched entry is updated, and the file is rewritten in place. The
|
|
316
366
|
// leading-blank-line convention of the append path is preserved.
|
|
317
367
|
export async function resolveTension(vaultRoot, id, resolution) {
|
|
318
|
-
|
|
368
|
+
const lockDbResult = openLockDb(vaultRoot);
|
|
369
|
+
if (!lockDbResult.ok)
|
|
370
|
+
return lockDbResult;
|
|
371
|
+
const lockDb = lockDbResult.value;
|
|
372
|
+
const holder = mintLeaseHolder(resolution.resolved_by);
|
|
319
373
|
try {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
374
|
+
const lock = acquireLock(lockDb, TENSIONS_LOCK_KEY, holder);
|
|
375
|
+
if (!lock.ok)
|
|
376
|
+
return err(new Error(`cannot update tension log: ${lock.error.message}`));
|
|
377
|
+
let raw;
|
|
378
|
+
try {
|
|
379
|
+
raw = await readFile(tensionsPath(vaultRoot), "utf-8");
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
if (e.code === "ENOENT") {
|
|
383
|
+
return err(new Error(`tension not found: ${id}`));
|
|
384
|
+
}
|
|
385
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
386
|
+
return err(new Error(`cannot read tension log: ${reason}`));
|
|
387
|
+
}
|
|
388
|
+
// Split the file into a leading preamble (anything before the first
|
|
389
|
+
// entry) plus a list of entry blocks. Reassembled the same way.
|
|
390
|
+
const segments = raw.split(/(?=^## )/m);
|
|
391
|
+
const preamble = segments[0]?.startsWith("## ") ? "" : (segments[0] ?? "");
|
|
392
|
+
const blocks = segments.filter((s) => s.startsWith("## "));
|
|
393
|
+
let matched = null;
|
|
394
|
+
let matchIdx = -1;
|
|
395
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
396
|
+
const entry = parseBlock(blocks[i].trim());
|
|
397
|
+
if (!entry || entry.id !== id)
|
|
398
|
+
continue;
|
|
399
|
+
matched = entry;
|
|
400
|
+
matchIdx = i;
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
if (!matched || matchIdx === -1) {
|
|
324
404
|
return err(new Error(`tension not found: ${id}`));
|
|
325
405
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
// captures the "## " marker at the start of each block, so we re-add the
|
|
359
|
-
// blank-line prefix on rewrite.
|
|
360
|
-
const rewritten = blocks.map((b, i) => {
|
|
361
|
-
if (i !== matchIdx)
|
|
362
|
-
return b;
|
|
363
|
-
// The new block content includes its trailing newline.
|
|
364
|
-
const rendered = renderEntry(updated);
|
|
365
|
-
// Preserve the same separator the original block had: count leading
|
|
366
|
-
// newlines on the original to keep the file's spacing stable.
|
|
367
|
-
const leading = (b.match(/^\n*/)?.[0] ?? "").length;
|
|
368
|
-
return `${"\n".repeat(leading)}${rendered}`;
|
|
369
|
-
});
|
|
370
|
-
const next = preamble + rewritten.join("");
|
|
371
|
-
try {
|
|
372
|
-
await writeFile(tensionsPath(vaultRoot), next);
|
|
373
|
-
return ok(updated);
|
|
406
|
+
if (matched.resolved) {
|
|
407
|
+
return err(new Error(`tension is already resolved: ${id}`));
|
|
408
|
+
}
|
|
409
|
+
const updated = {
|
|
410
|
+
...matched,
|
|
411
|
+
status: RESOLVED_TENSION_STATUS,
|
|
412
|
+
resolved: true,
|
|
413
|
+
resolution,
|
|
414
|
+
};
|
|
415
|
+
// Preserve the leading blank line of the original block: every block in the
|
|
416
|
+
// file (except possibly the first) is preceded by one blank line. The split
|
|
417
|
+
// captures the "## " marker at the start of each block, so we re-add the
|
|
418
|
+
// blank-line prefix on rewrite.
|
|
419
|
+
const rewritten = blocks.map((b, i) => {
|
|
420
|
+
if (i !== matchIdx)
|
|
421
|
+
return b;
|
|
422
|
+
// The new block content includes its trailing newline.
|
|
423
|
+
const rendered = renderEntry(updated);
|
|
424
|
+
// Preserve the same separator the original block had: count leading
|
|
425
|
+
// newlines on the original to keep the file's spacing stable.
|
|
426
|
+
const leading = (b.match(/^\n*/)?.[0] ?? "").length;
|
|
427
|
+
return `${"\n".repeat(leading)}${rendered}`;
|
|
428
|
+
});
|
|
429
|
+
const next = preamble + rewritten.join("");
|
|
430
|
+
try {
|
|
431
|
+
await writeFile(tensionsPath(vaultRoot), next);
|
|
432
|
+
return ok(updated);
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
436
|
+
return err(new Error(`cannot write tension log: ${reason}`));
|
|
437
|
+
}
|
|
374
438
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
439
|
+
finally {
|
|
440
|
+
releaseLock(lockDb, TENSIONS_LOCK_KEY, holder);
|
|
441
|
+
lockDb.close();
|
|
378
442
|
}
|
|
379
443
|
}
|
|
380
444
|
// --- Phase 4: aging -------------------------------------------------------
|
|
@@ -417,6 +481,8 @@ export const STALE_TIER_LINT_COPY = {
|
|
|
417
481
|
"inter-proposal": "Unresolved inter-proposal tension — competing proposals have contested the same " +
|
|
418
482
|
"document for months. Ratify one and reject the rest, or reject them all; the " +
|
|
419
483
|
"review queue is not a resolution.",
|
|
484
|
+
positional: "Unresolved positional tension — two principals still hold conflicting positions on " +
|
|
485
|
+
"this doc. Decide explicitly: `accepted` if both stand, `invalid` if mis-logged.",
|
|
420
486
|
};
|
|
421
487
|
// Boundary inclusivity: a tension exactly 30 days old is fresh, 31 days is
|
|
422
488
|
// aging, 90 days is aging, 91 days is stale. The thresholds in the table match
|