daftari 2.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 +33 -0
- package/README.md +471 -366
- 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 +4 -0
- package/dist/backfill/derive.js.map +1 -1
- package/dist/court/index.d.ts.map +1 -1
- package/dist/court/index.js +48 -0
- package/dist/court/index.js.map +1 -1
- package/dist/court/triage.d.ts +5 -0
- package/dist/court/triage.d.ts.map +1 -0
- package/dist/court/triage.js +71 -0
- package/dist/court/triage.js.map +1 -0
- package/dist/curation/lint-voice.d.ts.map +1 -1
- package/dist/curation/lint-voice.js +2 -1
- 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 +85 -5
- 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/read-heat.d.ts +16 -0
- package/dist/curation/read-heat.d.ts.map +1 -0
- package/dist/curation/read-heat.js +52 -0
- package/dist/curation/read-heat.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/structural.d.ts +1 -1
- package/dist/curation/structural.d.ts.map +1 -1
- package/dist/curation/structural.js +8 -7
- package/dist/curation/structural.js.map +1 -1
- package/dist/curation/tension-triage.d.ts +57 -0
- package/dist/curation/tension-triage.d.ts.map +1 -0
- package/dist/curation/tension-triage.js +155 -0
- package/dist/curation/tension-triage.js.map +1 -0
- 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 +119 -1
- package/dist/frontmatter/schema.js.map +1 -1
- package/dist/frontmatter/types.d.ts +29 -2
- package/dist/frontmatter/types.d.ts.map +1 -1
- package/dist/frontmatter/types.js +13 -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/hybrid.d.ts +1 -1
- package/dist/search/hybrid.d.ts.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/sleep/cycle.d.ts.map +1 -1
- package/dist/sleep/cycle.js +27 -11
- package/dist/sleep/cycle.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/curation.d.ts +2 -0
- package/dist/tools/curation.d.ts.map +1 -1
- package/dist/tools/curation.js +141 -0
- package/dist/tools/curation.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 +190 -6
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/search.js +3 -3
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/write.d.ts +32 -2
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +130 -16
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structural.js","sourceRoot":"","sources":["../../src/curation/structural.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,2EAA2E;AAC3E,yEAAyE;AACzE,4DAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"structural.js","sourceRoot":"","sources":["../../src/curation/structural.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,2EAA2E;AAC3E,yEAAyE;AACzE,4DAA4D;AAC5D,yEAAyE;AACzE,4BAA4B;AAC5B,yEAAyE;AACzE,uEAAuE;AACvE,uEAAuE;AACvE,yCAAyC;AACzC,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,wEAAwE;A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AM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAE/E,IAAI,CAAC,MAAM,IAAI,kBAAkB,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAExD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,MAAM,EAAE,CAAC;QACX,KAAK,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACvB,KAAK,CAAC,IAAI,CACR,sEAAsE,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI;YAChH,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAC9B,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM;QACN,oBAAoB,EAAE,kBAAkB;QACxC,MAAM,EAAE,qBAAqB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;KACjD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Confidence, Criticality, Provenance, Tier } from "../frontmatter/types.js";
|
|
2
|
+
import { type Result } from "../frontmatter/types.js";
|
|
3
|
+
import { type ReadHeat } from "./read-heat.js";
|
|
4
|
+
import { type TensionEntry, type TensionKind } from "./tension.js";
|
|
5
|
+
import { type HiddenDownstream } from "./tension-blast.js";
|
|
6
|
+
export interface TriageDocMeta {
|
|
7
|
+
tier: Tier | null;
|
|
8
|
+
confidence: Confidence;
|
|
9
|
+
criticality: Criticality | null;
|
|
10
|
+
provenance: Provenance | null;
|
|
11
|
+
updated_by: string | null;
|
|
12
|
+
created?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TriageBlast {
|
|
15
|
+
primary_blast: number;
|
|
16
|
+
advisory_blast: number;
|
|
17
|
+
hidden_downstream: HiddenDownstream;
|
|
18
|
+
}
|
|
19
|
+
export interface TriageSide {
|
|
20
|
+
path: string;
|
|
21
|
+
claim: string;
|
|
22
|
+
tier: Tier | null;
|
|
23
|
+
confidence: Confidence | null;
|
|
24
|
+
read_heat: ReadHeat | null;
|
|
25
|
+
criticality: Criticality | null;
|
|
26
|
+
provenance: Provenance | null;
|
|
27
|
+
updated_by: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface TriageTension {
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
kind: TensionKind;
|
|
33
|
+
age_days: number;
|
|
34
|
+
a: TriageSide;
|
|
35
|
+
b: TriageSide;
|
|
36
|
+
primary_blast: number | null;
|
|
37
|
+
advisory_blast: number | null;
|
|
38
|
+
hidden_downstream: HiddenDownstream | null;
|
|
39
|
+
}
|
|
40
|
+
export interface TriageCluster {
|
|
41
|
+
cluster_id: string;
|
|
42
|
+
documents: string[];
|
|
43
|
+
tensions: TriageTension[];
|
|
44
|
+
}
|
|
45
|
+
export interface TensionTriageResult {
|
|
46
|
+
cluster_count: number;
|
|
47
|
+
tension_count: number;
|
|
48
|
+
clusters: TriageCluster[];
|
|
49
|
+
}
|
|
50
|
+
export interface TriageInputs {
|
|
51
|
+
docMeta: Map<string, TriageDocMeta>;
|
|
52
|
+
readHeat: Map<string, ReadHeat>;
|
|
53
|
+
blastByTension: Map<string, TriageBlast>;
|
|
54
|
+
}
|
|
55
|
+
export declare function computeTensionTriage(tensions: TensionEntry[], inputs: TriageInputs, now?: Date): TensionTriageResult;
|
|
56
|
+
export declare function loadTensionTriage(vaultRoot: string, now?: Date, entryFilter?: (entries: TensionEntry[]) => TensionEntry[], windowDays?: number): Promise<Result<TensionTriageResult, Error>>;
|
|
57
|
+
//# sourceMappingURL=tension-triage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tension-triage.d.ts","sourceRoot":"","sources":["../../src/curation/tension-triage.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,E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,UAAU,CAAC;IACd,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iBAAiB,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CAC1C;AA0CD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,YAAY,EAAE,EACxB,MAAM,EAAE,YAAY,EACpB,GAAG,GAAE,IAAiB,GACrB,mBAAmB,CAiCrB;AAaD,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,GAAG,GAAE,IAAiB,EACtB,WAAW,GAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAa,EACnE,UAAU,GAAE,MAA8B,GACzC,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAgD7C"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Tension Triage Card (Story 1) — the pure engine.
|
|
2
|
+
//
|
|
3
|
+
// Composes the vault's LIVE tensions into a human-legible card: each tension
|
|
4
|
+
// grouped by cluster, annotated with its blast, and — per contested side —
|
|
5
|
+
// tier, confidence, and read-heat. The point is legibility, not automation:
|
|
6
|
+
// this function computes NO composite severity score. Ranking the queue is the
|
|
7
|
+
// human's job in v0; a learned priority function is a later, separate concern.
|
|
8
|
+
//
|
|
9
|
+
// Purity: all vault-derived inputs (doc metadata, read-heat, per-tension blast)
|
|
10
|
+
// are passed in already resolved, so the composition is testable with synthetic
|
|
11
|
+
// data and never touches the filesystem or the RBAC layer. The async loader in
|
|
12
|
+
// the tool wires the real vault reads.
|
|
13
|
+
import { err, ok } from "../frontmatter/types.js";
|
|
14
|
+
import { computeReadHeat } from "./read-heat.js";
|
|
15
|
+
import { readReadLog } from "./read-log.js";
|
|
16
|
+
import { ageInDays } from "./staleness.js";
|
|
17
|
+
import { listTensions } from "./tension.js";
|
|
18
|
+
import { bucketHiddenDownstream, buildReverseLinkMap, buildReverseSourceMap, computeBlast, } from "./tension-blast.js";
|
|
19
|
+
import { computeTensionClusters } from "./tension-clusters.js";
|
|
20
|
+
import { loadDocuments } from "./vault-docs.js";
|
|
21
|
+
const READ_HEAT_WINDOW_DAYS = 30;
|
|
22
|
+
function sideFor(path, claim, inputs) {
|
|
23
|
+
const m = inputs.docMeta.get(path);
|
|
24
|
+
return {
|
|
25
|
+
path,
|
|
26
|
+
claim,
|
|
27
|
+
tier: m ? m.tier : null,
|
|
28
|
+
confidence: m ? m.confidence : null,
|
|
29
|
+
read_heat: inputs.readHeat.get(path) ?? null,
|
|
30
|
+
criticality: m ? m.criticality : null,
|
|
31
|
+
provenance: m ? m.provenance : null,
|
|
32
|
+
updated_by: m ? m.updated_by : null,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function enrich(tension, inputs, now) {
|
|
36
|
+
const b = tension.id ? inputs.blastByTension.get(tension.id) : undefined;
|
|
37
|
+
return {
|
|
38
|
+
id: tension.id ?? "",
|
|
39
|
+
title: tension.title,
|
|
40
|
+
kind: tension.kind,
|
|
41
|
+
age_days: ageInDays(tension.date, now),
|
|
42
|
+
a: sideFor(tension.sourceA, tension.claimA, inputs),
|
|
43
|
+
b: sideFor(tension.sourceB, tension.claimB, inputs),
|
|
44
|
+
primary_blast: b ? b.primary_blast : null,
|
|
45
|
+
advisory_blast: b ? b.advisory_blast : null,
|
|
46
|
+
hidden_downstream: b ? b.hidden_downstream : null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Live-contested scope, mirroring tension-clusters' inScope: unresolved,
|
|
50
|
+
// non-accepted, real two-endpoint edge. Kept local so the module has no
|
|
51
|
+
// cross-dependency on a private helper.
|
|
52
|
+
function inScope(t) {
|
|
53
|
+
if (t.resolved)
|
|
54
|
+
return false;
|
|
55
|
+
if (t.resolution?.kind === "accepted")
|
|
56
|
+
return false;
|
|
57
|
+
if (!t.sourceA || !t.sourceB)
|
|
58
|
+
return false;
|
|
59
|
+
if (t.sourceA === t.sourceB)
|
|
60
|
+
return false;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
export function computeTensionTriage(tensions, inputs, now = new Date()) {
|
|
64
|
+
const scoped = tensions.filter(inScope);
|
|
65
|
+
// Reuse the cluster computation for grouping + deterministic size-desc order.
|
|
66
|
+
const { clusters } = computeTensionClusters(scoped, now);
|
|
67
|
+
// doc path → cluster id, so each tension routes to its cluster bucket.
|
|
68
|
+
const clusterOfDoc = new Map();
|
|
69
|
+
for (const c of clusters) {
|
|
70
|
+
for (const doc of c.documents)
|
|
71
|
+
clusterOfDoc.set(doc, c.id);
|
|
72
|
+
}
|
|
73
|
+
const tensionsByCluster = new Map();
|
|
74
|
+
for (const t of scoped) {
|
|
75
|
+
const cid = clusterOfDoc.get(t.sourceA);
|
|
76
|
+
if (cid === undefined)
|
|
77
|
+
continue;
|
|
78
|
+
if (!tensionsByCluster.has(cid))
|
|
79
|
+
tensionsByCluster.set(cid, []);
|
|
80
|
+
tensionsByCluster.get(cid).push(t);
|
|
81
|
+
}
|
|
82
|
+
const triageClusters = clusters.map((c) => {
|
|
83
|
+
const raw = tensionsByCluster.get(c.id) ?? [];
|
|
84
|
+
const enriched = raw
|
|
85
|
+
.map((t) => enrich(t, inputs, now))
|
|
86
|
+
// Oldest first; tie-break on id ascending for a stable order.
|
|
87
|
+
.sort((x, y) => (y.age_days !== x.age_days ? y.age_days - x.age_days : x.id < y.id ? -1 : 1));
|
|
88
|
+
return { cluster_id: c.id, documents: c.documents, tensions: enriched };
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
cluster_count: triageClusters.length,
|
|
92
|
+
tension_count: scoped.length,
|
|
93
|
+
clusters: triageClusters,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// Async loader: reads the vault's tensions, documents, read log, and computes
|
|
97
|
+
// per-tension blast, then feeds them all into computeTensionTriage. Mirrors
|
|
98
|
+
// loadTensionClusters' Result + entryFilter signature — the visibility policy
|
|
99
|
+
// (#212) is injected by the tool layer so this module never imports RBAC.
|
|
100
|
+
//
|
|
101
|
+
// Blast is seeded on BOTH endpoints of each tension (the contested pair): the
|
|
102
|
+
// downstream of the pair is what a resolver's change would touch. The reverse
|
|
103
|
+
// maps are built once and reused across every tension. hidden_downstream is
|
|
104
|
+
// "none" here — the RBAC recompute (#217) lives in the tool handler, not the
|
|
105
|
+
// loader (v0 default: apply the entryFilter, don't replicate per-tension
|
|
106
|
+
// kept/hidden downstream counting).
|
|
107
|
+
export async function loadTensionTriage(vaultRoot, now = new Date(), entryFilter = (e) => e, windowDays = READ_HEAT_WINDOW_DAYS) {
|
|
108
|
+
const tensionsResult = await listTensions(vaultRoot);
|
|
109
|
+
if (!tensionsResult.ok)
|
|
110
|
+
return err(tensionsResult.error);
|
|
111
|
+
const tensions = entryFilter(tensionsResult.value);
|
|
112
|
+
const docsResult = await loadDocuments(vaultRoot);
|
|
113
|
+
if (!docsResult.ok)
|
|
114
|
+
return err(docsResult.error);
|
|
115
|
+
const docs = docsResult.value;
|
|
116
|
+
const docMeta = new Map();
|
|
117
|
+
const readHeatDocs = [];
|
|
118
|
+
for (const d of docs) {
|
|
119
|
+
docMeta.set(d.path, {
|
|
120
|
+
tier: d.frontmatter.tier,
|
|
121
|
+
confidence: d.frontmatter.confidence,
|
|
122
|
+
criticality: d.frontmatter.criticality,
|
|
123
|
+
provenance: d.frontmatter.provenance,
|
|
124
|
+
updated_by: d.frontmatter.updated_by,
|
|
125
|
+
created: d.frontmatter.created,
|
|
126
|
+
});
|
|
127
|
+
readHeatDocs.push({ file: d.path, created: d.frontmatter.created });
|
|
128
|
+
}
|
|
129
|
+
const readLogResult = await readReadLog(vaultRoot);
|
|
130
|
+
if (!readLogResult.ok)
|
|
131
|
+
return err(readLogResult.error);
|
|
132
|
+
const readHeat = computeReadHeat(readLogResult.value, readHeatDocs, {
|
|
133
|
+
now,
|
|
134
|
+
windowDays,
|
|
135
|
+
});
|
|
136
|
+
const reverseSource = buildReverseSourceMap(docs);
|
|
137
|
+
const reverseLink = buildReverseLinkMap(docs);
|
|
138
|
+
const blastByTension = new Map();
|
|
139
|
+
for (const t of tensions.filter(inScope)) {
|
|
140
|
+
if (!t.id)
|
|
141
|
+
continue;
|
|
142
|
+
const { primary_blast, advisory_blast } = computeBlast({
|
|
143
|
+
seeds: [t.sourceA, t.sourceB],
|
|
144
|
+
reverseSource,
|
|
145
|
+
reverseLink,
|
|
146
|
+
});
|
|
147
|
+
blastByTension.set(t.id, {
|
|
148
|
+
primary_blast,
|
|
149
|
+
advisory_blast,
|
|
150
|
+
hidden_downstream: bucketHiddenDownstream(0),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return ok(computeTensionTriage(tensions, { docMeta, readHeat, blastByTension }, now));
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=tension-triage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tension-triage.js","sourceRoot":"","sources":["../../src/curation/tension-triage.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,EAAE;AACF,gFAAgF;AAChF,gFAAgF;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,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,CAAC,CAAC,EAAE;YAAE,SAAS;QACpB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,YAAY,CAAC;YACrD,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC;YAC7B,aAAa;YACb,WAAW;SACZ,CAAC,CAAC;QACH,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,aAAa;YACb,cAAc;YACd,iBAAiB,EAAE,sBAAsB,CAAC,CAAC,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,CAAC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;AACxF,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
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":[],"mappings":"AAwBA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAO/D,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,eAAO,MAAM,sBAAsB,eAAe,CAAC;AACnD,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAelD,eAAO,MAAM,aAAa,iGAOhB,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAOzD,eAAO,MAAM,sBAAsB,kDAAmD,CAAC;AACvF,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAM1E,QAAA,MAAM,qBAAqB,kFAAuE,CAAC;AACnG,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,gBAAgB,6DAA8D,CAAC;AAC5F,MAAM,MAAM,cA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AgHD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,EAAE,CAU3D;AAID,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,KAAK,CAAC,CAAC,CAYxC;AAMD,wBAAsB,cAAc,CAClC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,iBAAiB,GAC5B,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CA8EtC;AA8BD,eAAO,MAAM,WAAW,sCAAuC,CAAC;AAChE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAKrD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,CAcpF,CAAC;AAKF,wBAAgB,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
|