@rasensio/aidlc 1.47.0 → 1.49.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/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/roadmap.d.ts +10 -0
- package/dist/commands/roadmap.d.ts.map +1 -1
- package/dist/commands/roadmap.js +51 -1
- package/dist/commands/roadmap.js.map +1 -1
- package/dist/commands/spec.d.ts +22 -0
- package/dist/commands/spec.d.ts.map +1 -0
- package/dist/commands/spec.js +200 -0
- package/dist/commands/spec.js.map +1 -0
- package/dist/commands/transition.d.ts.map +1 -1
- package/dist/commands/transition.js +66 -1
- package/dist/commands/transition.js.map +1 -1
- package/dist/core/next-steps.d.ts.map +1 -1
- package/dist/core/next-steps.js +7 -0
- package/dist/core/next-steps.js.map +1 -1
- package/dist/core/types.d.ts +3 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/menu/roster.d.ts.map +1 -1
- package/dist/menu/roster.js +2 -0
- package/dist/menu/roster.js.map +1 -1
- package/dist/roadmap/next.d.ts +13 -0
- package/dist/roadmap/next.d.ts.map +1 -1
- package/dist/roadmap/next.js +26 -13
- package/dist/roadmap/next.js.map +1 -1
- package/dist/roadmap/rank.d.ts +76 -0
- package/dist/roadmap/rank.d.ts.map +1 -0
- package/dist/roadmap/rank.js +175 -0
- package/dist/roadmap/rank.js.map +1 -0
- package/dist/spec/corpus.d.ts +43 -0
- package/dist/spec/corpus.d.ts.map +1 -0
- package/dist/spec/corpus.js +155 -0
- package/dist/spec/corpus.js.map +1 -0
- package/dist/spec/delta.d.ts +17 -0
- package/dist/spec/delta.d.ts.map +1 -0
- package/dist/spec/delta.js +181 -0
- package/dist/spec/delta.js.map +1 -0
- package/dist/spec/fold.d.ts +30 -0
- package/dist/spec/fold.d.ts.map +1 -0
- package/dist/spec/fold.js +228 -0
- package/dist/spec/fold.js.map +1 -0
- package/dist/spec/types.d.ts +93 -0
- package/dist/spec/types.d.ts.map +1 -0
- package/dist/spec/types.js +9 -0
- package/dist/spec/types.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Give a backlog item a rank and keep every rank unique and gap-free
|
|
3
|
+
* (triage-sets-priority/AC-1 … triage-sets-priority/AC-12).
|
|
4
|
+
*
|
|
5
|
+
* `roadmap next` orders the backlog by `priority`, but until this module nothing
|
|
6
|
+
* wrote one: every rank was typed by hand, and they drift — an item leaving the
|
|
7
|
+
* backlog leaves a hole, and a second item typed at the same number ties. The
|
|
8
|
+
* roadmap skill *proposes* a rank at triage; this is what writes it once the person
|
|
9
|
+
* has answered, so "the others shift" is true by construction instead of being an
|
|
10
|
+
* agent's job across several files.
|
|
11
|
+
*
|
|
12
|
+
* Every ranked backlog item is renumbered 1…k on each call, not only the ones at or
|
|
13
|
+
* below the new rank. Shifting only the collisions would keep a hole at the top of
|
|
14
|
+
* a backlog whose first items had shipped forever.
|
|
15
|
+
*
|
|
16
|
+
* Reads and writes the PRIMARY checkout's roadmap (`roadmapRoot`), like every
|
|
17
|
+
* roadmap lookup that decides status. Unranked items are never written: ranking
|
|
18
|
+
* one item is not a decision about the others.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { writeFileSync } from 'node:fs';
|
|
23
|
+
import { join } from 'node:path';
|
|
24
|
+
import { readItemFields } from './item-fields.js';
|
|
25
|
+
import { compareCandidates, parsePriority } from './next.js';
|
|
26
|
+
import { frontmatter, listStatusAt, primaryCheckout, roadmapRoot, } from './paths.js';
|
|
27
|
+
/** What to paste into `.aidlc/config.yaml`, quoted by the refusal (AC-9). */
|
|
28
|
+
const DECLARE_SNIPPET = 'roadmap:\n item_fields:\n - name: priority\n required: false\n default: null';
|
|
29
|
+
/** The statuses searched to say where an item is when it is not in `backlog/` (AC-10). */
|
|
30
|
+
const ELSEWHERE = ['inbox', 'in-progress', 'done', 'hold'];
|
|
31
|
+
/**
|
|
32
|
+
* Whether the project declares `priority` in `roadmap.item_fields`.
|
|
33
|
+
*
|
|
34
|
+
* The new behaviour is opt-in through the same declaration `roadmap next`'s docs
|
|
35
|
+
* already describe; a project that has not made it is untouched.
|
|
36
|
+
*/
|
|
37
|
+
export function priorityDeclared(cwd) {
|
|
38
|
+
const fields = readItemFields(primaryCheckout(cwd));
|
|
39
|
+
return fields.kind === 'ok' && fields.fields.some((f) => f.name === 'priority');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set an item's `priority:` line to `rank`, editing the frontmatter as text.
|
|
43
|
+
*
|
|
44
|
+
* Text rather than re-serialization, as `writeHistoryEntry` does, so every other
|
|
45
|
+
* line keeps its quoting, comments and order (AC-4). A trailing `# comment` on the
|
|
46
|
+
* line itself survives too. With no `priority:` line, one is added as the last
|
|
47
|
+
* frontmatter line — where the framework's field writer puts extension fields.
|
|
48
|
+
*
|
|
49
|
+
* @returns The new contents, or null when there is no frontmatter.
|
|
50
|
+
*/
|
|
51
|
+
export function setPriorityLine(raw, rank) {
|
|
52
|
+
const fm = frontmatter(raw);
|
|
53
|
+
if (!fm)
|
|
54
|
+
return null;
|
|
55
|
+
const lines = fm.text.split('\n');
|
|
56
|
+
const at = lines.findIndex((l) => /^priority:/.test(l));
|
|
57
|
+
if (at === -1) {
|
|
58
|
+
// `fm.text` ends with a newline, so the last element is empty: insert before it.
|
|
59
|
+
lines.splice(lines.length - 1, 0, `priority: ${rank}`);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const comment = /\s+#.*$/.exec(lines[at].slice('priority:'.length));
|
|
63
|
+
lines[at] = `priority: ${rank}${comment ? comment[0] : ''}`;
|
|
64
|
+
}
|
|
65
|
+
return `${raw.slice(0, fm.start)}${lines.join('\n')}${raw.slice(fm.end)}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether `arg` names `item` — by file name, file name without `.md`, or `id` (AC-8).
|
|
69
|
+
*
|
|
70
|
+
* Compared against names already listed from disk and never joined into a path,
|
|
71
|
+
* so an argument like `../x` cannot reach outside the status directory: it simply
|
|
72
|
+
* matches nothing.
|
|
73
|
+
*/
|
|
74
|
+
function names(item, arg) {
|
|
75
|
+
return item.filename === arg || item.filename.replace(/\.md$/, '') === arg || item.id === arg;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Work out what ranking `itemArg` at `rankArg` would do, refusing before any write.
|
|
79
|
+
*
|
|
80
|
+
* Every refusal is decided here, so `applyRank` has nothing left to fail on but the
|
|
81
|
+
* filesystem.
|
|
82
|
+
*/
|
|
83
|
+
export function planRank(cwd, itemArg, rankArg) {
|
|
84
|
+
if (!priorityDeclared(cwd)) {
|
|
85
|
+
const fields = readItemFields(primaryCheckout(cwd));
|
|
86
|
+
const invalid = fields.kind === 'invalid' ? ` (roadmap.item_fields is ignored: ${fields.error})` : '';
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
detail: `this project does not declare \`priority\` in roadmap.item_fields${invalid}. ` +
|
|
90
|
+
`Add it to .aidlc/config.yaml to rank backlog items:\n${DECLARE_SNIPPET}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Commander hands over a string, so "0", "2.5", "-1" and "two" all land here (AC-11).
|
|
94
|
+
if (!/^[1-9][0-9]*$/.test(rankArg)) {
|
|
95
|
+
return { ok: false, detail: `rank must be a positive integer, got ${JSON.stringify(rankArg)}` };
|
|
96
|
+
}
|
|
97
|
+
const wanted = Number(rankArg);
|
|
98
|
+
const root = roadmapRoot(cwd);
|
|
99
|
+
const backlog = listStatusAt(root, 'backlog');
|
|
100
|
+
// A malformed rank is refused, never renumbered around: it is a value somebody typed,
|
|
101
|
+
// and only they know what they meant by it (AC-12).
|
|
102
|
+
const current = new Map();
|
|
103
|
+
for (const item of backlog) {
|
|
104
|
+
const data = frontmatter(item.raw)?.data ?? {};
|
|
105
|
+
const priority = parsePriority(data.priority);
|
|
106
|
+
if (priority === 'bad') {
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
detail: `backlog/${item.filename} has priority ${JSON.stringify(data.priority)}, which is not a ` +
|
|
110
|
+
'positive integer. Fix or clear it first — ranking would renumber around it.',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
current.set(item.filename, priority);
|
|
114
|
+
}
|
|
115
|
+
const matches = backlog.filter((item) => names(item, itemArg));
|
|
116
|
+
if (matches.length > 1) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
detail: `${JSON.stringify(itemArg)} matches more than one backlog item: ${matches.map((m) => m.filename).join(', ')}`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (matches.length === 0) {
|
|
123
|
+
for (const status of ELSEWHERE) {
|
|
124
|
+
const found = listStatusAt(root, status).find((item) => names(item, itemArg));
|
|
125
|
+
if (found) {
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
detail: `${found.filename} is in ${status}/, not backlog/. Only backlog items are ranked.`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { ok: false, detail: `no roadmap item matches ${JSON.stringify(itemArg)}` };
|
|
133
|
+
}
|
|
134
|
+
const target = matches[0];
|
|
135
|
+
const candidate = (item) => ({
|
|
136
|
+
file: item.filename,
|
|
137
|
+
id: item.id,
|
|
138
|
+
title: item.title,
|
|
139
|
+
priority: current.get(item.filename) ?? null,
|
|
140
|
+
});
|
|
141
|
+
const ranked = backlog
|
|
142
|
+
.filter((item) => item !== target && current.get(item.filename) !== null)
|
|
143
|
+
.sort((a, b) => compareCandidates(candidate(a), candidate(b)));
|
|
144
|
+
const rank = Math.min(wanted, ranked.length + 1);
|
|
145
|
+
ranked.splice(rank - 1, 0, target);
|
|
146
|
+
const order = [];
|
|
147
|
+
const writes = [];
|
|
148
|
+
for (const [index, item] of ranked.entries()) {
|
|
149
|
+
const next = index + 1;
|
|
150
|
+
order.push({ file: item.filename, title: item.title, priority: next, target: item === target });
|
|
151
|
+
if (current.get(item.filename) === next)
|
|
152
|
+
continue;
|
|
153
|
+
const updated = setPriorityLine(item.raw, next);
|
|
154
|
+
if (updated === null) {
|
|
155
|
+
return { ok: false, detail: `backlog/${item.filename} has no frontmatter to write a rank into` };
|
|
156
|
+
}
|
|
157
|
+
writes.push({ path: join(root, 'backlog', item.filename), raw: updated });
|
|
158
|
+
}
|
|
159
|
+
// listStatusAt sorts by file name, so the unranked tail is already in order (AC-5).
|
|
160
|
+
for (const item of backlog) {
|
|
161
|
+
if (item === target || current.get(item.filename) !== null)
|
|
162
|
+
continue;
|
|
163
|
+
order.push({ file: item.filename, title: item.title, priority: null, target: false });
|
|
164
|
+
}
|
|
165
|
+
return { ok: true, item: target.filename, rank, order, writes };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Write a plan's changed files. No history entry: `history` records status moves,
|
|
169
|
+
* and a rank is not one.
|
|
170
|
+
*/
|
|
171
|
+
export function applyRank(plan) {
|
|
172
|
+
for (const write of plan.writes)
|
|
173
|
+
writeFileSync(write.path, write.raw, 'utf8');
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=rank.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rank.js","sourceRoot":"","sources":["../../src/roadmap/rank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAsB,MAAM,WAAW,CAAC;AACjF,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,WAAW,GAGZ,MAAM,YAAY,CAAC;AAsBpB,6EAA6E;AAC7E,MAAM,eAAe,GACn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AE,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAqC;IAC7D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM;QAAE,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spec corpus: `.aidlc/specs/<capability>.md`, one file per capability,
|
|
3
|
+
* saying what the system does today (living-spec-corpus/AC-1).
|
|
4
|
+
*
|
|
5
|
+
* Read-only. Only the `### Requirement: <name>` blocks are parsed; a file's
|
|
6
|
+
* title, introduction and any other heading are never interpreted, which is
|
|
7
|
+
* what lets a fold leave them byte for byte (living-spec-corpus/AC-17).
|
|
8
|
+
*
|
|
9
|
+
* Requirements: living-spec-corpus/AC-1, living-spec-corpus/AC-2,
|
|
10
|
+
* living-spec-corpus/AC-9, living-spec-corpus/AC-17
|
|
11
|
+
*/
|
|
12
|
+
import type { CapabilitySpec } from './types.js';
|
|
13
|
+
export declare const SPECS_RELATIVE = ".aidlc/specs";
|
|
14
|
+
export declare const ARCHIVE_RELATIVE = ".aidlc/specs/archive";
|
|
15
|
+
export declare const REQUIREMENT_HEADING_RE: RegExp;
|
|
16
|
+
export declare const PROVENANCE_RE: RegExp;
|
|
17
|
+
export declare function isValidCapability(slug: string): boolean;
|
|
18
|
+
/** Identity of a requirement name: case and spacing are not part of it. */
|
|
19
|
+
export declare function requirementKey(name: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Normalise a requirement body: trailing whitespace off each line, leading and
|
|
22
|
+
* trailing blank lines dropped, blank-line runs collapsed to one. Re-wrapping
|
|
23
|
+
* whitespace by hand does not change a revision; changing a word does.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normaliseBody(body: string): string;
|
|
26
|
+
export declare function revisionOf(body: string): string;
|
|
27
|
+
export declare function provenanceLine(instance: string, date: string): string;
|
|
28
|
+
export declare function capabilityRelative(slug: string): string;
|
|
29
|
+
/** Parse one capability file's requirement blocks. */
|
|
30
|
+
export declare function parseCapability(text: string, capability: string, path: string): CapabilitySpec;
|
|
31
|
+
/**
|
|
32
|
+
* Read one capability file. `null` when the file does not exist. Throws on an
|
|
33
|
+
* invalid slug — callers validate first, and no path is built from one that
|
|
34
|
+
* fails (living-spec-corpus/AC-4).
|
|
35
|
+
*/
|
|
36
|
+
export declare function readCapability(projectRoot: string, slug: string): CapabilitySpec | null;
|
|
37
|
+
/**
|
|
38
|
+
* Every capability file, sorted by slug. `null` when the corpus directory does
|
|
39
|
+
* not exist. A `.md` file whose name is not a valid slug is not a capability
|
|
40
|
+
* and is skipped.
|
|
41
|
+
*/
|
|
42
|
+
export declare function listCapabilities(projectRoot: string): CapabilitySpec[] | null;
|
|
43
|
+
//# sourceMappingURL=corpus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corpus.d.ts","sourceRoot":"","sources":["../../src/spec/corpus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EAAE,cAAc,EAA8B,MAAM,YAAY,CAAC;AAE7E,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAC7C,eAAO,MAAM,gBAAgB,yBAA8B,CAAC;AAO5D,eAAO,MAAM,sBAAsB,QAAmD,CAAC;AAGvF,eAAO,MAAM,aAAa,QAAwD,CAAC;AAEnF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASlD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,sDAAsD;AACtD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,CAiE9F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAKvF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,EAAE,GAAG,IAAI,CAU7E"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spec corpus: `.aidlc/specs/<capability>.md`, one file per capability,
|
|
3
|
+
* saying what the system does today (living-spec-corpus/AC-1).
|
|
4
|
+
*
|
|
5
|
+
* Read-only. Only the `### Requirement: <name>` blocks are parsed; a file's
|
|
6
|
+
* title, introduction and any other heading are never interpreted, which is
|
|
7
|
+
* what lets a fold leave them byte for byte (living-spec-corpus/AC-17).
|
|
8
|
+
*
|
|
9
|
+
* Requirements: living-spec-corpus/AC-1, living-spec-corpus/AC-2,
|
|
10
|
+
* living-spec-corpus/AC-9, living-spec-corpus/AC-17
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { scanOutsideFences } from '../change/parser.js';
|
|
16
|
+
export const SPECS_RELATIVE = '.aidlc/specs';
|
|
17
|
+
export const ARCHIVE_RELATIVE = `${SPECS_RELATIVE}/archive`;
|
|
18
|
+
// The slug reaches a file path, so it is an allowlist, not a sanitiser
|
|
19
|
+
// (secure-defaults: path traversal).
|
|
20
|
+
const CAPABILITY_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
21
|
+
const MAX_CAPABILITY = 64;
|
|
22
|
+
export const REQUIREMENT_HEADING_RE = /^ {0,3}###[ \t]+Requirement:[ \t]*(.*?)[ \t]*$/;
|
|
23
|
+
/** Any heading that bounds a requirement block: levels 1–3. */
|
|
24
|
+
const BOUNDING_HEADING_RE = /^ {0,3}#{1,3}(?:[ \t]|$)/;
|
|
25
|
+
export const PROVENANCE_RE = /^_Last changed by (\S+), (\d{4}-\d{2}-\d{2})\._\s*$/;
|
|
26
|
+
export function isValidCapability(slug) {
|
|
27
|
+
return typeof slug === 'string' && slug.length <= MAX_CAPABILITY && CAPABILITY_RE.test(slug);
|
|
28
|
+
}
|
|
29
|
+
/** Identity of a requirement name: case and spacing are not part of it. */
|
|
30
|
+
export function requirementKey(name) {
|
|
31
|
+
return name.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Normalise a requirement body: trailing whitespace off each line, leading and
|
|
35
|
+
* trailing blank lines dropped, blank-line runs collapsed to one. Re-wrapping
|
|
36
|
+
* whitespace by hand does not change a revision; changing a word does.
|
|
37
|
+
*/
|
|
38
|
+
export function normaliseBody(body) {
|
|
39
|
+
const lines = body.split(/\r?\n/).map((l) => l.replace(/\s+$/, ''));
|
|
40
|
+
const out = [];
|
|
41
|
+
for (const line of lines) {
|
|
42
|
+
if (line === '' && (out.length === 0 || out[out.length - 1] === ''))
|
|
43
|
+
continue;
|
|
44
|
+
out.push(line);
|
|
45
|
+
}
|
|
46
|
+
while (out.length > 0 && out[out.length - 1] === '')
|
|
47
|
+
out.pop();
|
|
48
|
+
return out.join('\n');
|
|
49
|
+
}
|
|
50
|
+
export function revisionOf(body) {
|
|
51
|
+
return createHash('sha256').update(normaliseBody(body)).digest('hex').slice(0, 8);
|
|
52
|
+
}
|
|
53
|
+
export function provenanceLine(instance, date) {
|
|
54
|
+
return `_Last changed by ${instance}, ${date}._`;
|
|
55
|
+
}
|
|
56
|
+
export function capabilityRelative(slug) {
|
|
57
|
+
return `${SPECS_RELATIVE}/${slug}.md`;
|
|
58
|
+
}
|
|
59
|
+
/** Parse one capability file's requirement blocks. */
|
|
60
|
+
export function parseCapability(text, capability, path) {
|
|
61
|
+
const lines = text.split('\n');
|
|
62
|
+
const bounding = [];
|
|
63
|
+
const outside = new Set();
|
|
64
|
+
scanOutsideFences(lines, (line, i) => {
|
|
65
|
+
outside.add(i);
|
|
66
|
+
if (BOUNDING_HEADING_RE.test(line))
|
|
67
|
+
bounding.push(i);
|
|
68
|
+
});
|
|
69
|
+
const requirements = [];
|
|
70
|
+
const errors = [];
|
|
71
|
+
const seen = new Map();
|
|
72
|
+
bounding.forEach((start, n) => {
|
|
73
|
+
const heading = REQUIREMENT_HEADING_RE.exec(lines[start]);
|
|
74
|
+
if (!heading)
|
|
75
|
+
return;
|
|
76
|
+
const name = heading[1];
|
|
77
|
+
if (name === '') {
|
|
78
|
+
errors.push({ path, line: start + 1, message: 'requirement heading has no name' });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let end = n + 1 < bounding.length ? bounding[n + 1] : lines.length;
|
|
82
|
+
while (end > start + 1 && lines[end - 1].trim() === '')
|
|
83
|
+
end--;
|
|
84
|
+
let provenanceAt = -1;
|
|
85
|
+
let changedBy = null;
|
|
86
|
+
let changedOn = null;
|
|
87
|
+
for (let i = end - 1; i > start; i--) {
|
|
88
|
+
if (!outside.has(i))
|
|
89
|
+
continue;
|
|
90
|
+
const match = PROVENANCE_RE.exec(lines[i].trim());
|
|
91
|
+
if (match) {
|
|
92
|
+
provenanceAt = i;
|
|
93
|
+
changedBy = match[1];
|
|
94
|
+
changedOn = match[2];
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const body = lines
|
|
99
|
+
.slice(start + 1, end)
|
|
100
|
+
.filter((_, offset) => start + 1 + offset !== provenanceAt)
|
|
101
|
+
.join('\n');
|
|
102
|
+
const key = requirementKey(name);
|
|
103
|
+
const first = seen.get(key);
|
|
104
|
+
if (first !== undefined) {
|
|
105
|
+
errors.push({
|
|
106
|
+
path,
|
|
107
|
+
line: start + 1,
|
|
108
|
+
message: `requirement "${name}" is defined twice (first at line ${first})`,
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
seen.set(key, start + 1);
|
|
113
|
+
requirements.push({
|
|
114
|
+
name,
|
|
115
|
+
key,
|
|
116
|
+
revision: revisionOf(body),
|
|
117
|
+
changedBy,
|
|
118
|
+
changedOn,
|
|
119
|
+
startLine: start,
|
|
120
|
+
endLine: end,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
return { capability, path, requirements, errors };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Read one capability file. `null` when the file does not exist. Throws on an
|
|
127
|
+
* invalid slug — callers validate first, and no path is built from one that
|
|
128
|
+
* fails (living-spec-corpus/AC-4).
|
|
129
|
+
*/
|
|
130
|
+
export function readCapability(projectRoot, slug) {
|
|
131
|
+
if (!isValidCapability(slug))
|
|
132
|
+
throw new Error(`invalid capability name '${slug}'`);
|
|
133
|
+
const file = join(projectRoot, SPECS_RELATIVE, `${slug}.md`);
|
|
134
|
+
if (!existsSync(file))
|
|
135
|
+
return null;
|
|
136
|
+
return parseCapability(readFileSync(file, 'utf8'), slug, capabilityRelative(slug));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Every capability file, sorted by slug. `null` when the corpus directory does
|
|
140
|
+
* not exist. A `.md` file whose name is not a valid slug is not a capability
|
|
141
|
+
* and is skipped.
|
|
142
|
+
*/
|
|
143
|
+
export function listCapabilities(projectRoot) {
|
|
144
|
+
const dir = join(projectRoot, SPECS_RELATIVE);
|
|
145
|
+
if (!existsSync(dir))
|
|
146
|
+
return null;
|
|
147
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
148
|
+
.filter((e) => e.isFile() && e.name.endsWith('.md'))
|
|
149
|
+
.map((e) => e.name.slice(0, -3))
|
|
150
|
+
.filter(isValidCapability)
|
|
151
|
+
.sort()
|
|
152
|
+
.map((slug) => readCapability(projectRoot, slug))
|
|
153
|
+
.filter((c) => c !== null);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=corpus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corpus.js","sourceRoot":"","sources":["../../src/spec/corpus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,cAAc,UAAU,CAAC;AAE5D,uEAAuE;AACvE,qCAAqC;AACrC,MAAM,aAAa,GAAG,4BAA4B,CAAC;AACnD,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,sBAAsB,GAAG,gDAAgD,CAAC;AACvF,+DAA+D;AAC/D,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AACvD,MAAM,CAAC,MAAM,aAAa,GAAG,qDAAqD,CAAC;AAEnF,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,IAAI,cAAc,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/F,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU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AC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;SACnD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC/B,MAAM,CAAC,iBAAiB,CAAC;SACzB,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;SAChD,MAAM,CAAC,CAAC,CAAC,EAAuB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delta parser: the `## Spec delta` section of a requirements.md
|
|
3
|
+
* (living-spec-corpus/AC-5).
|
|
4
|
+
*
|
|
5
|
+
* Inside the section the grammar is closed and every departure is an error with
|
|
6
|
+
* its line, never a skip: a block the parser cannot read would otherwise fold
|
|
7
|
+
* as if it had not been written, and a parser narrower than the prose people
|
|
8
|
+
* write makes text invisible rather than malformed (lessons digest,
|
|
9
|
+
* change-management). Outside the section, a heading that looks like a delta
|
|
10
|
+
* but is not the exact one is a warning, for the same reason.
|
|
11
|
+
*
|
|
12
|
+
* Requirements: living-spec-corpus/AC-5, living-spec-corpus/AC-6,
|
|
13
|
+
* living-spec-corpus/AC-7, living-spec-corpus/AC-8, living-spec-corpus/AC-9
|
|
14
|
+
*/
|
|
15
|
+
import type { ParsedDelta } from './types.js';
|
|
16
|
+
export declare function parseDelta(text: string): ParsedDelta;
|
|
17
|
+
//# sourceMappingURL=delta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delta.d.ts","sourceRoot":"","sources":["../../src/spec/delta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAuB,WAAW,EAAa,MAAM,YAAY,CAAC;AAoB9E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAuJpD"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delta parser: the `## Spec delta` section of a requirements.md
|
|
3
|
+
* (living-spec-corpus/AC-5).
|
|
4
|
+
*
|
|
5
|
+
* Inside the section the grammar is closed and every departure is an error with
|
|
6
|
+
* its line, never a skip: a block the parser cannot read would otherwise fold
|
|
7
|
+
* as if it had not been written, and a parser narrower than the prose people
|
|
8
|
+
* write makes text invisible rather than malformed (lessons digest,
|
|
9
|
+
* change-management). Outside the section, a heading that looks like a delta
|
|
10
|
+
* but is not the exact one is a warning, for the same reason.
|
|
11
|
+
*
|
|
12
|
+
* Requirements: living-spec-corpus/AC-5, living-spec-corpus/AC-6,
|
|
13
|
+
* living-spec-corpus/AC-7, living-spec-corpus/AC-8, living-spec-corpus/AC-9
|
|
14
|
+
*/
|
|
15
|
+
import { scanOutsideFences } from '../change/parser.js';
|
|
16
|
+
import { isValidCapability, requirementKey } from './corpus.js';
|
|
17
|
+
const SECTION_RE = /^ {0,3}##[ \t]+spec delta[ \t]*$/i;
|
|
18
|
+
/** Ends the section: any level 1–2 heading. */
|
|
19
|
+
const SECTION_END_RE = /^ {0,3}#{1,2}(?:[ \t]|$)/;
|
|
20
|
+
const LEVEL3_RE = /^ {0,3}###(?:[ \t]|$)/;
|
|
21
|
+
const BLOCK_RE = /^ {0,3}###[ \t]+(ADDED|MODIFIED|REMOVED)[ \t]+([^:\s]+):[ \t]*(.*?)[ \t]*$/;
|
|
22
|
+
const NEAR_MISS_RE = /^ {0,3}#{1,6}[ \t]+spec[ \t]+(?:deltas?|changes?)\b/i;
|
|
23
|
+
// The same three emphasis variants the amendment parser accepts for its fields
|
|
24
|
+
// (living-spec-corpus/AC-6): authors write all three.
|
|
25
|
+
const BASE_RE = /^\s*(?:Base:|\*\*Base\*\*:|\*\*Base:\*\*)\s*(.*?)\s*$/;
|
|
26
|
+
const REVISION_RE = /^[0-9a-f]{8}$/;
|
|
27
|
+
const MAX_NAME = 120;
|
|
28
|
+
export function parseDelta(text) {
|
|
29
|
+
const lines = text.split('\n');
|
|
30
|
+
const outside = new Set();
|
|
31
|
+
scanOutsideFences(lines, (_line, i) => outside.add(i));
|
|
32
|
+
const errors = [];
|
|
33
|
+
const warnings = [];
|
|
34
|
+
let start = -1;
|
|
35
|
+
let end = lines.length;
|
|
36
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37
|
+
if (!outside.has(i))
|
|
38
|
+
continue;
|
|
39
|
+
const line = lines[i];
|
|
40
|
+
if (SECTION_RE.test(line)) {
|
|
41
|
+
if (start === -1) {
|
|
42
|
+
start = i;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// Reading only the first would fold half the author's changes.
|
|
46
|
+
errors.push({ line: i + 1, message: 'a second `## Spec delta` section; merge them into one' });
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (start !== -1 && end === lines.length && i > start && SECTION_END_RE.test(line)) {
|
|
50
|
+
end = i;
|
|
51
|
+
}
|
|
52
|
+
if (NEAR_MISS_RE.test(line)) {
|
|
53
|
+
warnings.push({
|
|
54
|
+
line: i + 1,
|
|
55
|
+
message: `"${line.trim()}" looks like a spec delta but only \`## Spec delta\` is read`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (start === -1) {
|
|
60
|
+
return { present: false, section: '', blocks: [], errors, warnings };
|
|
61
|
+
}
|
|
62
|
+
const raw = [];
|
|
63
|
+
for (let i = start + 1; i < end; i++) {
|
|
64
|
+
const isOutside = outside.has(i);
|
|
65
|
+
if (isOutside && LEVEL3_RE.test(lines[i])) {
|
|
66
|
+
raw.push({ heading: i, bodyLines: [] });
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
raw[raw.length - 1]?.bodyLines.push({ text: lines[i], index: i, outside: isOutside });
|
|
70
|
+
}
|
|
71
|
+
const blocks = [];
|
|
72
|
+
const seen = new Map();
|
|
73
|
+
for (const block of raw) {
|
|
74
|
+
const lineNo = block.heading + 1;
|
|
75
|
+
const match = BLOCK_RE.exec(lines[block.heading]);
|
|
76
|
+
if (!match) {
|
|
77
|
+
errors.push({
|
|
78
|
+
line: lineNo,
|
|
79
|
+
message: `"${lines[block.heading].trim()}" is not a delta block; write ` +
|
|
80
|
+
'`### ADDED|MODIFIED|REMOVED <capability>: <requirement name>`',
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const op = match[1];
|
|
85
|
+
const capability = match[2];
|
|
86
|
+
const name = match[3];
|
|
87
|
+
let ok = true;
|
|
88
|
+
if (!isValidCapability(capability)) {
|
|
89
|
+
errors.push({
|
|
90
|
+
line: lineNo,
|
|
91
|
+
message: `capability "${capability}" is not a lowercase kebab-case name of at most 64 characters`,
|
|
92
|
+
});
|
|
93
|
+
ok = false;
|
|
94
|
+
}
|
|
95
|
+
if (name === '' || name.length > MAX_NAME) {
|
|
96
|
+
errors.push({
|
|
97
|
+
line: lineNo,
|
|
98
|
+
message: name === '' ? 'the block names no requirement' : `requirement name is over ${MAX_NAME} characters`,
|
|
99
|
+
});
|
|
100
|
+
ok = false;
|
|
101
|
+
}
|
|
102
|
+
let base = null;
|
|
103
|
+
let baseCount = 0;
|
|
104
|
+
const body = [];
|
|
105
|
+
for (const b of block.bodyLines) {
|
|
106
|
+
const baseMatch = b.outside ? BASE_RE.exec(b.text) : null;
|
|
107
|
+
if (!baseMatch) {
|
|
108
|
+
body.push(b.text);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
baseCount++;
|
|
112
|
+
if (!REVISION_RE.test(baseMatch[1])) {
|
|
113
|
+
errors.push({
|
|
114
|
+
line: b.index + 1,
|
|
115
|
+
message: `Base "${baseMatch[1]}" is not a revision; copy the 8 characters \`aidlc spec show ${capability}\` prints`,
|
|
116
|
+
});
|
|
117
|
+
ok = false;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
base = baseMatch[1];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const bodyText = trimBlank(body).join('\n');
|
|
124
|
+
if (baseCount > 1) {
|
|
125
|
+
errors.push({ line: lineNo, message: 'the block has more than one Base line' });
|
|
126
|
+
ok = false;
|
|
127
|
+
}
|
|
128
|
+
if (op === 'ADDED' && baseCount > 0) {
|
|
129
|
+
errors.push({ line: lineNo, message: 'an ADDED block takes no Base: there is nothing to be based on' });
|
|
130
|
+
ok = false;
|
|
131
|
+
}
|
|
132
|
+
if (op !== 'ADDED' && baseCount === 0) {
|
|
133
|
+
errors.push({
|
|
134
|
+
line: lineNo,
|
|
135
|
+
message: `a ${op} block needs a \`Base: <revision>\` line from \`aidlc spec show ${capability}\``,
|
|
136
|
+
});
|
|
137
|
+
ok = false;
|
|
138
|
+
}
|
|
139
|
+
if (op !== 'REMOVED' && bodyText.trim() === '') {
|
|
140
|
+
errors.push({ line: lineNo, message: `a ${op} block needs the requirement's text` });
|
|
141
|
+
ok = false;
|
|
142
|
+
}
|
|
143
|
+
const key = requirementKey(name);
|
|
144
|
+
const identity = `${capability}\u0000${key}`;
|
|
145
|
+
const first = seen.get(identity);
|
|
146
|
+
if (first !== undefined) {
|
|
147
|
+
errors.push({
|
|
148
|
+
line: lineNo,
|
|
149
|
+
message: `requirement "${name}" in ${capability} is already changed by the block at line ${first}`,
|
|
150
|
+
});
|
|
151
|
+
ok = false;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
seen.set(identity, lineNo);
|
|
155
|
+
}
|
|
156
|
+
if (ok)
|
|
157
|
+
blocks.push({ op, capability, name, key, base, body: bodyText, line: lineNo });
|
|
158
|
+
}
|
|
159
|
+
// Prose before the first block is allowed; an empty section is not a delta.
|
|
160
|
+
if (raw.length === 0) {
|
|
161
|
+
errors.push({ line: start + 1, message: '`## Spec delta` has no blocks' });
|
|
162
|
+
}
|
|
163
|
+
errors.sort((a, b) => a.line - b.line);
|
|
164
|
+
return {
|
|
165
|
+
present: true,
|
|
166
|
+
section: trimBlank(lines.slice(start, end)).join('\n'),
|
|
167
|
+
blocks,
|
|
168
|
+
errors,
|
|
169
|
+
warnings,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function trimBlank(lines) {
|
|
173
|
+
let a = 0;
|
|
174
|
+
let b = lines.length;
|
|
175
|
+
while (a < b && lines[a].trim() === '')
|
|
176
|
+
a++;
|
|
177
|
+
while (b > a && lines[b - 1].trim() === '')
|
|
178
|
+
b--;
|
|
179
|
+
return lines.slice(a, b);
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=delta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delta.js","sourceRoot":"","sources":["../../src/spec/delta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGhE,MAAM,UAAU,GAAG,mCAAmC,CAAC;AACvD,+CAA+C;AAC/C,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAC1C,MAAM,QAAQ,GAAG,4EAA4E,CAAC;AAC9F,MAAM,YAAY,GAAG,sDAAsD,CAAC;AAE5E,+EAA+E;AAC/E,sDAAsD;AACtD,MAAM,OAAO,GAAG,uDAAuD,CAAC;AACxE,MAAM,WAAW,GAAG,eAAe,CAAC;AACpC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAOrB,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,iBAAiB,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,G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AAS,CAAC,KAAe;IAChC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,CAAC,EAAE,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,CAAC,EAAE,CAAC;IAChD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fold an instance's spec delta into the corpus (living-spec-corpus/AC-10).
|
|
3
|
+
*
|
|
4
|
+
* `planFold` reads and computes; `applyFold` is the only writer. The split is
|
|
5
|
+
* what makes a fold all-or-nothing: every file's new content exists in memory
|
|
6
|
+
* before the first write, so a conflict found in the last block leaves the
|
|
7
|
+
* corpus exactly as it was (living-spec-corpus/AC-11), and `--dry-run` and the
|
|
8
|
+
* completion check in `aidlc transition` are the same computation as the real
|
|
9
|
+
* fold rather than a second copy of it.
|
|
10
|
+
*
|
|
11
|
+
* Preconditions are checked against the corpus as it is *before* the fold, for
|
|
12
|
+
* every block, so the conflict list is complete — not just the first one found.
|
|
13
|
+
*
|
|
14
|
+
* Requirements: living-spec-corpus/AC-10, living-spec-corpus/AC-11,
|
|
15
|
+
* living-spec-corpus/AC-12, living-spec-corpus/AC-13,
|
|
16
|
+
* living-spec-corpus/AC-14, living-spec-corpus/AC-17
|
|
17
|
+
*/
|
|
18
|
+
import type { FoldPlan } from './types.js';
|
|
19
|
+
/** The archive record already written for this instance, if any (AC-13). */
|
|
20
|
+
export declare function findArchiveRecord(projectRoot: string, instance: string): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Compute what folding `instance` would do. Throws only when the instance name
|
|
23
|
+
* is not a single path segment or the instance does not exist.
|
|
24
|
+
*/
|
|
25
|
+
export declare function planFold(projectRoot: string, instance: string, now?: Date): FoldPlan;
|
|
26
|
+
/** Write a ready plan; anything else is a no-op. Archive record last (design D5). */
|
|
27
|
+
export declare function applyFold(plan: FoldPlan): void;
|
|
28
|
+
/** One line per error or conflict, for the CLI and for transition violations. */
|
|
29
|
+
export declare function describeIssues(plan: FoldPlan): string[];
|
|
30
|
+
//# sourceMappingURL=fold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fold.d.ts","sourceRoot":"","sources":["../../src/spec/fold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAeH,OAAO,KAAK,EAKV,QAAQ,EAET,MAAM,YAAY,CAAC;AAIpB,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWtF;AAeD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,QAAQ,CA6DhG;AAED,qFAAqF;AACrF,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAG9C;AAiID,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,CAQvD"}
|