@vedprakash-m/tenet 0.1.0 → 0.1.1
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/README.md +106 -52
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +70 -19
- package/dist/cli.js.map +1 -1
- package/dist/commands/check.js +4 -1
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/context.d.ts +12 -4
- package/dist/commands/context.js +6 -5
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/init.js +116 -28
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/onboard.js +70 -4
- package/dist/commands/onboard.js.map +1 -1
- package/dist/commands/upgrade.js +1 -1
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/verify.d.ts +2 -1
- package/dist/commands/verify.js +160 -14
- package/dist/commands/verify.js.map +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +130 -27
- package/dist/context/index.js.map +1 -1
- package/dist/core/messages.d.ts +5 -1
- package/dist/core/messages.js +5 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/output.d.ts +1 -0
- package/dist/core/output.js.map +1 -1
- package/dist/install/hosts.d.ts +2 -2
- package/dist/install/hosts.js +4 -2
- package/dist/install/hosts.js.map +1 -1
- package/dist/install/init.js +1 -0
- package/dist/install/init.js.map +1 -1
- package/dist/install/integrity.d.ts +4 -1
- package/dist/install/integrity.js +32 -8
- package/dist/install/integrity.js.map +1 -1
- package/dist/install/preflight.js +52 -3
- package/dist/install/preflight.js.map +1 -1
- package/dist/install/types.d.ts +5 -1
- package/dist/install/upgrade.js +163 -19
- package/dist/install/upgrade.js.map +1 -1
- package/dist/install/writes.d.ts +1 -0
- package/dist/install/writes.js +14 -12
- package/dist/install/writes.js.map +1 -1
- package/dist/onboard/bless.d.ts +10 -4
- package/dist/onboard/bless.js +150 -79
- package/dist/onboard/bless.js.map +1 -1
- package/dist/onboard/card.d.ts +9 -2
- package/dist/onboard/card.js +43 -12
- package/dist/onboard/card.js.map +1 -1
- package/dist/specs/anchors.d.ts +10 -0
- package/dist/specs/anchors.js +17 -0
- package/dist/specs/anchors.js.map +1 -1
- package/dist/specs/check.js +16 -9
- package/dist/specs/check.js.map +1 -1
- package/dist/specs/parse.d.ts +3 -0
- package/dist/specs/parse.js +60 -17
- package/dist/specs/parse.js.map +1 -1
- package/dist/verify/card.js +2 -1
- package/dist/verify/card.js.map +1 -1
- package/dist/verify/record.js +25 -4
- package/dist/verify/record.js.map +1 -1
- package/dist/verify/run-checks.js +8 -2
- package/dist/verify/run-checks.js.map +1 -1
- package/dist/views/specs-board.js +63 -53
- package/dist/views/specs-board.js.map +1 -1
- package/kit/CHANGELOG.md +26 -0
- package/kit/README.md +1 -1
- package/kit/schemas/results/context.json +3 -0
- package/kit/skills/draft-specs/SKILL.md +2 -2
- package/kit/skills/review-with-findings/SKILL.md +4 -3
- package/kit/skills/work-a-change/SKILL.md +2 -2
- package/kit/templates/pull-request.md +7 -5
- package/package.json +1 -1
- package/pkg/conformance/board/n04-over-budget/input.json +1 -1
- package/pkg/conformance/board/p07-ux-part-2/expected.md +4 -3
- package/pkg/conformance/card/p05-workflow-and-protected-surfaces-would-block/expected.json +4 -0
- package/pkg/conformance/card/p05-workflow-and-protected-surfaces-would-block/expected.md +1 -1
- package/pkg/conformance/check/n09-ci-budget-crossing/input.json +1 -1
- package/pkg/conformance/check/n12-local-budget-warning/input.json +1 -1
- package/pkg/conformance/scenarios/README.md +7 -3
- package/pkg/conformance/scenarios/s11-readme-walkthrough/expected/06-card.md +5 -2
- package/pkg/conformance/scenarios/s11-readme-walkthrough/expected/06-onboard-card.json +1 -1
- package/pkg/conformance/scenarios/s12-ux-walkthrough-existing/expected/06-card.md +5 -2
- package/pkg/conformance/scenarios/s12-ux-walkthrough-existing/expected/06-onboard-card.json +1 -1
- package/pkg/conformance/scenarios/s13-ux-walkthrough-new/expected/04-onboard-inventory.json +9 -9
- package/pkg/conformance/scenarios/s13-ux-walkthrough-new/expected/05-card.md +5 -2
- package/pkg/conformance/scenarios/s13-ux-walkthrough-new/expected/05-onboard-card.json +1 -1
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/README.md +4 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/kit/TENET.md +3 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/src/app.ts +6 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/blessed/tenet__specs__plan.md/plan.md +2 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/blessed/tenet__specs__plan.md/plan.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/blessed/tenet__specs__tech-spec.md/design.md +2 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/blessed/tenet__specs__tech-spec.md/design.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/blessed/tenet__specs__ux-spec.md/experience.md +2 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/blessed/tenet__specs__ux-spec.md/experience.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/specs/plan.md +7 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/specs/prd.md +24 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/specs/tech-spec.md +7 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/specs/ux-spec.md +7 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet/vision.md +15 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet.lock +7 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/before/tenet.yaml +20 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/expected/02-board.json +41 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/expected/09-check.json +19 -0
- package/pkg/conformance/scenarios/s14-bless-decide-later-and-questions/steps.json +141 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/README.md +3 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/app/core/x.py +2 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/b/two.py +2 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/kit/TENET.md +3 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/pyproject.toml +3 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__prd.md/app-core.md +2 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__prd.md/app-core.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__prd.md/global-rules.md +2 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__prd.md/global-rules.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__prd.md/secondary-module.md +2 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__prd.md/secondary-module.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__tech-spec.md/repo-conventions.md +41 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__specs__tech-spec.md/repo-conventions.md.anchors.json +1 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__vision.md/vision.md +2 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/blessed/tenet__vision.md/vision.md.anchors.json +3 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/specs/plan.md +7 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/specs/prd.md +19 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/specs/tech-spec.md +46 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/specs/ux-spec.md +7 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet/vision.md +7 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet.lock +7 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/before/tenet.yaml +20 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/expected/01-context-paths.json +27 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/expected/03-context-multi.json +29 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/expected/05-context-drafts.json +19 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/expected/07-mcp-drafts.json +50 -0
- package/pkg/conformance/scenarios/s15-context-paths-ranking/steps.json +133 -0
- package/pkg/conformance/scenarios/s16-verify-local-preview/before/README.md +3 -0
- package/pkg/conformance/scenarios/s16-verify-local-preview/expected/01-init.json +14 -0
- package/pkg/conformance/scenarios/s16-verify-local-preview/expected/14-local-preview.json +7 -0
- package/pkg/conformance/scenarios/s16-verify-local-preview/expected/18-command-change.json +8 -0
- package/pkg/conformance/scenarios/s16-verify-local-preview/steps.json +162 -0
package/dist/onboard/bless.js
CHANGED
|
@@ -6,9 +6,10 @@ import { isMap, parseDocument } from "yaml";
|
|
|
6
6
|
import { utcSeconds } from "../core/clock.js";
|
|
7
7
|
import { confine, writeAtomic } from "../core/fs.js";
|
|
8
8
|
import { git } from "../core/git.js";
|
|
9
|
+
import { sha256 } from "../core/hash.js";
|
|
9
10
|
import { readYaml } from "../core/yaml.js";
|
|
10
11
|
import { loadPolicy, ownersFor } from "../policy/index.js";
|
|
11
|
-
import { anchorBlock,
|
|
12
|
+
import { anchorBlock, anchorRecordsFor, citationParts } from "../specs/anchors.js";
|
|
12
13
|
import { resolveCitations } from "../specs/citations.js";
|
|
13
14
|
import { flags } from "../specs/flags.js";
|
|
14
15
|
import { parseDoc, sectionLocation } from "../specs/parse.js";
|
|
@@ -16,7 +17,7 @@ import { sectionDigest } from "../specs/sections.js";
|
|
|
16
17
|
import { createInterface } from "node:readline";
|
|
17
18
|
import { message } from "../core/messages.js";
|
|
18
19
|
import { fail } from "../core/output.js";
|
|
19
|
-
import { itemLine } from "../specs/parse.js";
|
|
20
|
+
import { isOpenSpecItem, itemLine, openItemsFor } from "../specs/parse.js";
|
|
20
21
|
export const blessText = {
|
|
21
22
|
description: "Read and bless specification sections in your terminal.",
|
|
22
23
|
owner: (options) => `Who is blessing? ${options} > `,
|
|
@@ -24,7 +25,11 @@ export const blessText = {
|
|
|
24
25
|
conflict: (id, text) => `Conflict ${id}: ${text}`,
|
|
25
26
|
postpone: "Decide later",
|
|
26
27
|
writeResolution: "Write a resolution, or press Enter to decide later > ",
|
|
27
|
-
contradiction:
|
|
28
|
+
contradiction: (ids) => `Does this choice contradict a drafted statement? Enter one of ${ids}, or type no > `,
|
|
29
|
+
question: (id, text) => `Question ${id}: ${text}\n 1. Answer\n 2. Not a blocker\n 3. Skip section`,
|
|
30
|
+
answer: "Write an answer > ",
|
|
31
|
+
skipped: (heading, ids) => `Skipping ${heading} · open items: ${ids}`,
|
|
32
|
+
revisit: "→ Run tenet bless when you’re ready to review the remaining sections.",
|
|
28
33
|
editConflict: (id) => `Edit ${id} to agree with the selected resolution.`,
|
|
29
34
|
conflictUnchanged: "The statement is unchanged. The conflict is still open.",
|
|
30
35
|
section: (heading, minutes, actions) => `${heading} (${minutes} min) · ${actions.join(" / ")}? `,
|
|
@@ -35,7 +40,8 @@ export const blessText = {
|
|
|
35
40
|
noLines: "(unavailable)",
|
|
36
41
|
textInForce: "Blessed text in force",
|
|
37
42
|
confirmSources: "Confirm these source changes? [y/N] ",
|
|
38
|
-
summary: (
|
|
43
|
+
summary: (count, total) => `Blessed ${count} of ${total} sections`,
|
|
44
|
+
nothingBlessed: "Nothing is in force yet",
|
|
39
45
|
commit: (root) => `→ git add -- ${root} && git commit -m "Bless specifications"`,
|
|
40
46
|
missingTarget: "the selected document or section was not found",
|
|
41
47
|
invalidOptions: "pass one document and one section at most",
|
|
@@ -52,34 +58,11 @@ export function readingMinutes(text) {
|
|
|
52
58
|
export function statements(section) {
|
|
53
59
|
return [...section.vision_items, ...section.requirements];
|
|
54
60
|
}
|
|
55
|
-
function belongs(item, doc, section) {
|
|
56
|
-
if (item.section === null)
|
|
57
|
-
return true;
|
|
58
|
-
return item.section === section.slug || item.section === section.heading ||
|
|
59
|
-
item.section === `${doc.path}#${section.slug}`;
|
|
60
|
-
}
|
|
61
|
-
function relevantOpen(doc, section) {
|
|
62
|
-
return doc.sections.flatMap((part) => [...part.conflicts, ...part.questions])
|
|
63
|
-
.filter((item) => belongs(item, doc, section) && (!item.checked || !(item.resolution ?? item.answer)));
|
|
64
|
-
}
|
|
65
61
|
function sourceLine(text, line) {
|
|
66
62
|
return line === null ? "" : text.replaceAll("\r\n", "\n").split("\n")[line - 1] ?? "";
|
|
67
63
|
}
|
|
68
64
|
export function parseBlessDocument(file, text, prefix) {
|
|
69
|
-
|
|
70
|
-
for (const section of doc.sections) {
|
|
71
|
-
for (const conflict of section.conflicts) {
|
|
72
|
-
if (conflict.resolution)
|
|
73
|
-
continue;
|
|
74
|
-
const line = sourceLine(text, itemLine(conflict));
|
|
75
|
-
const resolution = /(?:^|[\s;|])resolution:\s*(.+)$/i.exec(line)?.[1]?.trim();
|
|
76
|
-
if (!resolution)
|
|
77
|
-
continue;
|
|
78
|
-
conflict.resolution = resolution;
|
|
79
|
-
conflict.text = conflict.text.replace(/(?:^|[\s;|])resolution:.*$/i, "").replace(/[;|\s]+$/, "");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return doc;
|
|
65
|
+
return parseDoc(file, text, { prefix });
|
|
83
66
|
}
|
|
84
67
|
function choices(text) {
|
|
85
68
|
return [...text.matchAll(/\|\s*\d+:\s*([^|]+?)(?=\s*\||$)/g)].map((entry) => entry[1]?.trim() ?? "").filter(Boolean);
|
|
@@ -95,19 +78,16 @@ async function pick(ask, prompt, allowed, write) {
|
|
|
95
78
|
write(blessText.invalid);
|
|
96
79
|
}
|
|
97
80
|
}
|
|
98
|
-
async function
|
|
81
|
+
async function settleConflicts(state, ask, write, findings) {
|
|
99
82
|
for (const { path, id } of state.conflicts) {
|
|
100
83
|
const source = await state.read(path, "conflicts");
|
|
101
84
|
const conflict = source?.section.conflicts.find((item) => item.id === id);
|
|
102
|
-
if (!source || !conflict || (conflict
|
|
85
|
+
if (!source || !conflict || !isOpenSpecItem(conflict, "conflicts"))
|
|
103
86
|
continue;
|
|
104
87
|
write(blessText.conflict(id, conflict.text));
|
|
105
88
|
const line = sourceLine(source.text, itemLine(conflict));
|
|
106
|
-
const sections = source.doc.sections.filter((section) => governing(section) &&
|
|
107
|
-
const
|
|
108
|
-
findings.push(diagnostic("TN-BLESS-OPEN-CONFLICT", { slug: sections[0]?.slug ?? "conflicts", ids: id }));
|
|
109
|
-
return false;
|
|
110
|
-
};
|
|
89
|
+
const sections = source.doc.sections.filter((section) => governing(section) && openItemsFor(source.doc, section, "conflicts").includes(conflict));
|
|
90
|
+
const unresolved = () => diagnostic("TN-BLESS-OPEN-CONFLICT", { slug: sections[0]?.slug ?? "conflicts", ids: id });
|
|
111
91
|
const alternatives = choices(line);
|
|
112
92
|
let resolution;
|
|
113
93
|
if (alternatives.length) {
|
|
@@ -123,11 +103,13 @@ async function settle(state, ask, write, findings) {
|
|
|
123
103
|
if (resolution === null)
|
|
124
104
|
return false;
|
|
125
105
|
}
|
|
126
|
-
if (!resolution)
|
|
127
|
-
|
|
106
|
+
if (!resolution) {
|
|
107
|
+
findings.push({ ...unresolved(), severity: "warning" });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
128
110
|
const affected = /\(affects:\s*([^)]+)\)/i.exec(line)?.[1]?.split(",").map((entry) => entry.trim().toLowerCase());
|
|
129
111
|
const items = sections.flatMap(statements).filter((item) => !affected || affected.includes(item.id.toLowerCase()));
|
|
130
|
-
const answer = items.length ? await pick(ask, blessText.contradiction, ["no", ...items.map(({ id: itemId }) => itemId.toLowerCase())], write) : "no";
|
|
112
|
+
const answer = items.length ? await pick(ask, blessText.contradiction(items.map(({ id }) => id).join(", ")), ["no", ...items.map(({ id: itemId }) => itemId.toLowerCase())], write) : "no";
|
|
131
113
|
if (answer === null)
|
|
132
114
|
return false;
|
|
133
115
|
if (answer !== "no") {
|
|
@@ -139,18 +121,48 @@ async function settle(state, ask, write, findings) {
|
|
|
139
121
|
const remaining = updated?.doc.sections.flatMap(statements).find((entry) => entry.id === item?.id);
|
|
140
122
|
if (!updated || (remaining && cleanText(remaining.text) === cleanText(item?.text ?? ""))) {
|
|
141
123
|
write(blessText.conflictUnchanged);
|
|
142
|
-
|
|
124
|
+
findings.push(unresolved());
|
|
125
|
+
continue;
|
|
143
126
|
}
|
|
144
127
|
const current = updated.section.conflicts.find((entry) => entry.id === id);
|
|
145
128
|
if (current)
|
|
146
|
-
await state.
|
|
129
|
+
await state.resolve(updated, current, "resolution", resolution);
|
|
147
130
|
}
|
|
148
131
|
else {
|
|
149
|
-
await state.
|
|
132
|
+
await state.resolve(source, conflict, "resolution", resolution);
|
|
150
133
|
}
|
|
151
134
|
}
|
|
152
135
|
return true;
|
|
153
136
|
}
|
|
137
|
+
async function settleQuestions(state, initial, ask, write) {
|
|
138
|
+
let current = initial;
|
|
139
|
+
while (true) {
|
|
140
|
+
const question = openItemsFor(current.doc, current.section, "questions")[0];
|
|
141
|
+
if (!question)
|
|
142
|
+
return current;
|
|
143
|
+
write(blessText.question(question.id, question.text));
|
|
144
|
+
const choice = await pick(ask, "> ", ["1", "2", "3", "answer", "not a blocker", "skip section"], write);
|
|
145
|
+
if (choice === null)
|
|
146
|
+
return null;
|
|
147
|
+
if (choice === "3" || choice === "skip section") {
|
|
148
|
+
write(blessText.skipped(current.section.heading, question.id));
|
|
149
|
+
return "skip";
|
|
150
|
+
}
|
|
151
|
+
let answer = "Not a blocker";
|
|
152
|
+
if (choice === "1" || choice === "answer") {
|
|
153
|
+
do {
|
|
154
|
+
answer = await ask(blessText.answer);
|
|
155
|
+
if (answer === null)
|
|
156
|
+
return null;
|
|
157
|
+
} while (!answer);
|
|
158
|
+
}
|
|
159
|
+
await state.resolve(current, question, "answer", answer);
|
|
160
|
+
const updated = await state.read(current.doc.path, current.section.slug);
|
|
161
|
+
if (!updated)
|
|
162
|
+
return "skip";
|
|
163
|
+
current = updated;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
154
166
|
export async function blessSession(state, io = {}) {
|
|
155
167
|
const input = io.stdin ?? process.stdin;
|
|
156
168
|
const output = io.stdout ?? process.stdout;
|
|
@@ -179,13 +191,19 @@ export async function blessSession(state, io = {}) {
|
|
|
179
191
|
return null;
|
|
180
192
|
return answer.value.trim();
|
|
181
193
|
};
|
|
194
|
+
let changed = false;
|
|
182
195
|
const editableState = {
|
|
183
196
|
...state,
|
|
197
|
+
resolve: async (entry, item, field, value) => {
|
|
198
|
+
await state.resolve(entry, item, field, value);
|
|
199
|
+
changed = true;
|
|
200
|
+
},
|
|
184
201
|
edit: async (entry) => {
|
|
185
202
|
if (!terminalClosed)
|
|
186
203
|
lines.pause();
|
|
187
204
|
try {
|
|
188
205
|
await state.edit(entry);
|
|
206
|
+
changed ||= await readFile(entry.filename, "utf8") !== entry.text;
|
|
189
207
|
}
|
|
190
208
|
finally {
|
|
191
209
|
if (!terminalClosed)
|
|
@@ -194,17 +212,36 @@ export async function blessSession(state, io = {}) {
|
|
|
194
212
|
},
|
|
195
213
|
};
|
|
196
214
|
try {
|
|
197
|
-
if (!state.owners.length)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
215
|
+
if (!state.owners.length) {
|
|
216
|
+
findings.push(diagnostic("TN-SCHEMA", { path: "tenet.yaml", schema: "tenet-yaml", pointer: "/owners" }));
|
|
217
|
+
return { result, findings };
|
|
218
|
+
}
|
|
219
|
+
const ownerOptions = state.owners.map((_, i) => String(i + 1));
|
|
220
|
+
const onlyOwner = state.owners.length === 1;
|
|
221
|
+
if (onlyOwner)
|
|
222
|
+
ownerOptions.push("");
|
|
223
|
+
const owner = await pick(ask, blessText.owner(state.owners.map((id, i) => `${i + 1}. ${id}${onlyOwner ? " (Enter)" : ""}`).join(" ")), ownerOptions, write);
|
|
224
|
+
const by = owner === null ? undefined : state.owners[Number(owner || "1") - 1];
|
|
225
|
+
if (by && await settleConflicts(editableState, ask, write, findings)) {
|
|
202
226
|
for (const target of state.targets) {
|
|
227
|
+
const reviewStarted = now().valueOf();
|
|
203
228
|
while (!interrupted) {
|
|
204
|
-
const
|
|
205
|
-
if (!
|
|
229
|
+
const entry = await state.read(target.path, target.slug);
|
|
230
|
+
if (!entry)
|
|
206
231
|
break;
|
|
207
|
-
const
|
|
232
|
+
const conflicts = openItemsFor(entry.doc, entry.section, "conflicts");
|
|
233
|
+
if (conflicts.length) {
|
|
234
|
+
write(blessText.skipped(entry.section.heading, conflicts.map(({ id }) => id).join(", ")));
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
const current = await settleQuestions(editableState, entry, ask, write);
|
|
238
|
+
if (current === null) {
|
|
239
|
+
interrupted = true;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
if (current === "skip")
|
|
243
|
+
break;
|
|
244
|
+
const { section } = current;
|
|
208
245
|
const flags = state.flags(current);
|
|
209
246
|
if (section.text.trim())
|
|
210
247
|
write(section.text.trimEnd());
|
|
@@ -220,11 +257,6 @@ export async function blessSession(state, io = {}) {
|
|
|
220
257
|
continue;
|
|
221
258
|
}
|
|
222
259
|
const action = (selected === "later" ? "defer" : selected);
|
|
223
|
-
const open = relevantOpen(doc, section);
|
|
224
|
-
if ((action === "bless" || action === "confirm") && open.length) {
|
|
225
|
-
findings.push(diagnostic("TN-BLESS-OPEN-CONFLICT", { slug: section.slug, ids: open.map(({ id }) => id).join(", ") }));
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
260
|
let adopt = false;
|
|
229
261
|
const inferred = statements(section).filter((item) => item.origin === "inferred");
|
|
230
262
|
if (action === "bless" && inferred.length) {
|
|
@@ -262,11 +294,13 @@ export async function blessSession(state, io = {}) {
|
|
|
262
294
|
}
|
|
263
295
|
restore = choice === "y";
|
|
264
296
|
}
|
|
265
|
-
const
|
|
297
|
+
const minutes = Math.max(0, now().valueOf() - reviewStarted) / 60_000;
|
|
298
|
+
const errors = await state.commit(current, action, by, restore, adopt, minutes);
|
|
266
299
|
findings.push(...errors);
|
|
267
300
|
if (!errors.some((finding) => finding.severity === "error")) {
|
|
268
301
|
const key = { bless: "blessed", confirm: "confirmed", reject: "rejected", defer: "deferred" }[action];
|
|
269
302
|
result[key]++;
|
|
303
|
+
changed = true;
|
|
270
304
|
}
|
|
271
305
|
break;
|
|
272
306
|
}
|
|
@@ -275,11 +309,19 @@ export async function blessSession(state, io = {}) {
|
|
|
275
309
|
}
|
|
276
310
|
}
|
|
277
311
|
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
findings.push(findingFrom(error));
|
|
314
|
+
}
|
|
278
315
|
finally {
|
|
279
316
|
lines.close();
|
|
280
317
|
if (input === process.stdin)
|
|
281
318
|
process.off("SIGINT", stop);
|
|
282
319
|
result.minutes = Math.max(0, now().valueOf() - started) / 60_000;
|
|
320
|
+
const blessed = result.blessed + result.confirmed;
|
|
321
|
+
write(`\n${blessText.summary(blessed, state.targets.length)}`);
|
|
322
|
+
if (blessed === 0)
|
|
323
|
+
write(blessText.nothingBlessed);
|
|
324
|
+
write(changed ? blessText.commit(`"${state.records}"`) : blessText.revisit);
|
|
283
325
|
}
|
|
284
326
|
return { result, findings };
|
|
285
327
|
}
|
|
@@ -330,7 +372,7 @@ function reader(cwd) {
|
|
|
330
372
|
}
|
|
331
373
|
function targetsConflict(doc) {
|
|
332
374
|
return doc.sections.flatMap((section) => section.conflicts
|
|
333
|
-
.filter((
|
|
375
|
+
.filter((item) => isOpenSpecItem(item, "conflicts"))
|
|
334
376
|
.map(({ id }) => ({ path: doc.path, id })));
|
|
335
377
|
}
|
|
336
378
|
async function editInTerminal(filename, cwd) {
|
|
@@ -549,7 +591,7 @@ function findingFrom(error) {
|
|
|
549
591
|
return error.finding;
|
|
550
592
|
return diagnostic("TN-INTERNAL", { detail: error instanceof Error ? error.message : String(error) });
|
|
551
593
|
}
|
|
552
|
-
async function writeAction(ws, entry, action, by, restore, adopt) {
|
|
594
|
+
async function writeAction(ws, entry, action, by, restore, adopt, minutes) {
|
|
553
595
|
try {
|
|
554
596
|
await unchanged(entry);
|
|
555
597
|
const checked = adopt ? adoptStatements(entry, by, ws.prefix) : entry;
|
|
@@ -569,7 +611,7 @@ async function writeAction(ws, entry, action, by, restore, adopt) {
|
|
|
569
611
|
const errors = resolveCitations(relevant, read);
|
|
570
612
|
if (errors.length)
|
|
571
613
|
return errors;
|
|
572
|
-
const newAnchors =
|
|
614
|
+
const newAnchors = anchorRecordsFor(subject, read, ws.head);
|
|
573
615
|
const copyPath = await blessedCopyPath(ws, checked.doc.path, section.slug);
|
|
574
616
|
const digest = sectionDigest(subject.text);
|
|
575
617
|
if (action === "bless" && section.blessed_digest && section.blessed_digest !== digest) {
|
|
@@ -585,7 +627,7 @@ async function writeAction(ws, entry, action, by, restore, adopt) {
|
|
|
585
627
|
set("anchors", newAnchors.anchors);
|
|
586
628
|
set("blessed_copy", copyPath);
|
|
587
629
|
set("flags", section.digest === digest ? [] : ["edited"]);
|
|
588
|
-
patches.push({ path: copyPath, text: normalize(subject.text) }, { path: `${copyPath}.anchors.json`, text: `${JSON.stringify(newAnchors.
|
|
630
|
+
patches.push({ path: copyPath, text: normalize(subject.text) }, { path: `${copyPath}.anchors.json`, text: `${JSON.stringify(newAnchors.records, null, 2)}\n` });
|
|
589
631
|
measured = subject;
|
|
590
632
|
}
|
|
591
633
|
else if (section.blessed_digest) {
|
|
@@ -610,7 +652,7 @@ async function writeAction(ws, entry, action, by, restore, adopt) {
|
|
|
610
652
|
const counts = await countDraft(checked, measured, ws);
|
|
611
653
|
await persist(ws, patches, {
|
|
612
654
|
doc: checked.doc.path, section: section.slug, action, by, at: utcSeconds(ws.now),
|
|
613
|
-
minutes
|
|
655
|
+
minutes, statements: counts,
|
|
614
656
|
});
|
|
615
657
|
return [];
|
|
616
658
|
}
|
|
@@ -618,7 +660,25 @@ async function writeAction(ws, entry, action, by, restore, adopt) {
|
|
|
618
660
|
return [findingFrom(error)];
|
|
619
661
|
}
|
|
620
662
|
}
|
|
621
|
-
function
|
|
663
|
+
async function historicalRange(cwd, citation, start, end, revision, hash) {
|
|
664
|
+
const parsed = citationParts(citation);
|
|
665
|
+
if (!parsed || start === null || end === null || revision === null)
|
|
666
|
+
return null;
|
|
667
|
+
try {
|
|
668
|
+
const source = await git(["show", `${revision}:${parsed.path}`], { cwd });
|
|
669
|
+
const lines = source.replaceAll("\r\n", "\n").replaceAll("\r", "\n").split("\n");
|
|
670
|
+
if (lines.at(-1) === "")
|
|
671
|
+
lines.pop();
|
|
672
|
+
const text = lines.slice(start - 1, end).map((line) => line.replace(/[ \t]+$/, "")).join("\n");
|
|
673
|
+
if (hash !== null && `sha256:${sha256(text)}` !== hash)
|
|
674
|
+
return null;
|
|
675
|
+
return text;
|
|
676
|
+
}
|
|
677
|
+
catch {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
async function anchorsToShow(cwd, entry, read) {
|
|
622
682
|
const copy = entry.section.blessed_copy;
|
|
623
683
|
let old = {};
|
|
624
684
|
try {
|
|
@@ -627,12 +687,26 @@ function anchorsToShow(entry, read) {
|
|
|
627
687
|
old = JSON.parse(raw);
|
|
628
688
|
}
|
|
629
689
|
catch { /* Missing historical text is displayed as unavailable. */ }
|
|
630
|
-
const changes =
|
|
690
|
+
const changes = [];
|
|
691
|
+
for (const [citation, digest] of Object.entries(entry.section.anchors)) {
|
|
631
692
|
const next = anchorBlock(citation, read);
|
|
632
693
|
if (next?.hash === digest)
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
694
|
+
continue;
|
|
695
|
+
const stored = old[citation];
|
|
696
|
+
let before = typeof stored === "string" ? stored : blessText.noLines;
|
|
697
|
+
if (stored && typeof stored === "object" && !Array.isArray(stored)) {
|
|
698
|
+
const record = stored;
|
|
699
|
+
const start = typeof record.start === "number" ? record.start : null;
|
|
700
|
+
const end = typeof record.end === "number" ? record.end : null;
|
|
701
|
+
const revision = typeof record.blessed_at_rev === "string" ? record.blessed_at_rev : null;
|
|
702
|
+
const hash = typeof record.hash === "string" ? record.hash : null;
|
|
703
|
+
before = await historicalRange(cwd, citation, start, end, revision, hash) ??
|
|
704
|
+
(start !== null && end !== null
|
|
705
|
+
? `${citationParts(citation)?.path ?? citation}:${start}-${end}`
|
|
706
|
+
: blessText.noLines);
|
|
707
|
+
}
|
|
708
|
+
changes.push(blessText.before(citation, before), blessText.after(citation, next?.text ?? blessText.noLines));
|
|
709
|
+
}
|
|
636
710
|
const blessed = copy ? read(copy) : null;
|
|
637
711
|
return blessed === null ? changes : [blessText.textInForce, blessed.trimEnd(), ...changes];
|
|
638
712
|
}
|
|
@@ -650,7 +724,7 @@ export async function runBless(options = {}, io = {}) {
|
|
|
650
724
|
const records = portable(policy.paths.records);
|
|
651
725
|
const prefix = policy.specs.id_prefix;
|
|
652
726
|
const now = io.now ?? (() => new Date());
|
|
653
|
-
const ws = { cwd, head, records, prefix, now,
|
|
727
|
+
const ws = { cwd, head, records, prefix, now, write: io.write ?? writeAtomic };
|
|
654
728
|
const read = reader(cwd);
|
|
655
729
|
const load = async (relative) => {
|
|
656
730
|
const filename = await confine(relative, cwd);
|
|
@@ -678,39 +752,36 @@ export async function runBless(options = {}, io = {}) {
|
|
|
678
752
|
return { result: null, findings: [diagnostic("TN-USAGE-BLESS", { command: "bless", detail: blessText.missingTarget })] };
|
|
679
753
|
}
|
|
680
754
|
const conflicts = selected.flatMap(({ doc }) => targetsConflict(doc).filter(({ id }) => {
|
|
681
|
-
|
|
682
|
-
return targets.some((target) => target.path === doc.path && doc.sections.some((section) => section.slug === target.slug && conflict && belongs(conflict, doc, section)));
|
|
755
|
+
return targets.some((target) => target.path === doc.path && doc.sections.some((section) => section.slug === target.slug && openItemsFor(doc, section, "conflicts").some((item) => item.id === id)));
|
|
683
756
|
}));
|
|
684
|
-
|
|
757
|
+
return await blessSession({
|
|
685
758
|
owners: policy.owners?.length ? policy.owners.map(({ id }) => id) :
|
|
686
759
|
[...new Set(targets.flatMap(({ path }) => ownersFor(path)))],
|
|
687
760
|
targets,
|
|
688
761
|
conflicts,
|
|
762
|
+
records,
|
|
689
763
|
read: async (file, selector) => {
|
|
690
764
|
const entry = await load(file);
|
|
691
765
|
const section = entry?.doc.sections.find(({ slug, heading }) => slug === selector || heading === selector);
|
|
692
766
|
return entry && section ? { ...entry, section } : null;
|
|
693
767
|
},
|
|
694
768
|
edit: (entry) => (io.edit ?? editInTerminal)(entry.filename, cwd),
|
|
695
|
-
|
|
769
|
+
resolve: async (entry, item, field, value) => {
|
|
696
770
|
await unchanged(entry);
|
|
697
771
|
const lines = normalize(entry.text).split("\n");
|
|
698
|
-
const index = (itemLine(
|
|
772
|
+
const index = (itemLine(item) ?? 0) - 1;
|
|
699
773
|
const source = lines[index];
|
|
700
774
|
if (!source)
|
|
701
775
|
return;
|
|
702
|
-
|
|
776
|
+
const checked = source.replace(/^(\s*[-*+]\s+)(?:\[[ xX]\]\s+)?/, "$1[x] ");
|
|
777
|
+
const prompt = checked.replace(/(?:^|[;|\s])(?:resolution|answer):\s*.*$/i, "").replace(/[;|\s]*$/, "");
|
|
778
|
+
lines[index] = `${prompt} | ${field}: ${value}`;
|
|
703
779
|
await writeAtomic(entry.filename, lines.join("\n"));
|
|
704
780
|
},
|
|
705
|
-
commit: (entry, action, by, restore, adopt) => writeAction(ws, entry, action, by, restore, adopt),
|
|
781
|
+
commit: (entry, action, by, restore, adopt, minutes) => writeAction(ws, entry, action, by, restore, adopt, minutes),
|
|
706
782
|
flags: (entry) => flags(entry.section, read),
|
|
707
|
-
showAnchors: async (entry) => anchorsToShow(entry, read),
|
|
783
|
+
showAnchors: async (entry) => anchorsToShow(cwd, entry, read),
|
|
708
784
|
}, io);
|
|
709
|
-
if (result.result && result.result.blessed + result.result.confirmed + result.result.rejected + result.result.deferred > 0) {
|
|
710
|
-
const output = io.stdout ?? process.stdout;
|
|
711
|
-
output.write(`\n${blessText.summary(result.result)}\n${blessText.commit(`"${records}"`)}\n`);
|
|
712
|
-
}
|
|
713
|
-
return result;
|
|
714
785
|
}
|
|
715
786
|
catch (error) {
|
|
716
787
|
return { result: null, findings: [findingFrom(error)] };
|