@descent-vtt/spec-brief 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +264 -0
- package/README.md +90 -20
- package/dist/archive.d.ts +52 -2
- package/dist/archive.js +205 -37
- package/dist/archive.js.map +1 -1
- package/dist/brief.d.ts +2 -0
- package/dist/brief.js +5 -1
- package/dist/brief.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +48 -14
- package/dist/cli.js.map +1 -1
- package/dist/collisions.d.ts +43 -12
- package/dist/collisions.js +90 -58
- package/dist/collisions.js.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.js +58 -10
- package/dist/config.js.map +1 -1
- package/dist/corpus.d.ts +21 -1
- package/dist/corpus.js +51 -2
- package/dist/corpus.js.map +1 -1
- package/dist/engine.d.ts +33 -3
- package/dist/engine.js +112 -9
- package/dist/engine.js.map +1 -1
- package/dist/frontmatter.d.ts +18 -61
- package/dist/frontmatter.js +31 -300
- package/dist/frontmatter.js.map +1 -1
- package/dist/glob.d.ts +77 -54
- package/dist/glob.js +104 -433
- package/dist/glob.js.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts +1 -1
- package/dist/links.js +3 -4
- package/dist/links.js.map +1 -1
- package/dist/lint.d.ts +33 -2
- package/dist/lint.js +9 -2
- package/dist/lint.js.map +1 -1
- package/dist/markdown.d.ts +26 -23
- package/dist/markdown.js +60 -237
- package/dist/markdown.js.map +1 -1
- package/dist/plugins.d.ts +14 -0
- package/dist/plugins.js +142 -6
- package/dist/plugins.js.map +1 -1
- package/dist/report.d.ts +40 -3
- package/dist/report.js +227 -11
- package/dist/report.js.map +1 -1
- package/dist/rules.d.ts +22 -4
- package/dist/rules.js +175 -45
- package/dist/rules.js.map +1 -1
- package/dist/scaffold.d.ts +1 -1
- package/dist/scaffold.js +10 -9
- package/dist/scaffold.js.map +1 -1
- package/dist/schedule.d.ts +133 -0
- package/dist/schedule.js +265 -0
- package/dist/schedule.js.map +1 -0
- package/dist/scope.d.ts +52 -0
- package/dist/scope.js +56 -0
- package/dist/scope.js.map +1 -0
- package/dist/text.d.ts +13 -0
- package/dist/text.js +23 -0
- package/dist/text.js.map +1 -1
- package/dist/trigger.d.ts +17 -0
- package/dist/trigger.js +49 -0
- package/dist/trigger.js.map +1 -0
- package/dist/types.d.ts +14 -5
- package/dist/types.js.map +1 -1
- package/dist/vendor/spec-core/markdown/frontmatter.d.ts +103 -0
- package/dist/vendor/spec-core/markdown/frontmatter.js +459 -0
- package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -0
- package/dist/vendor/spec-core/markdown/headings.d.ts +45 -0
- package/dist/vendor/spec-core/markdown/headings.js +199 -0
- package/dist/vendor/spec-core/markdown/headings.js.map +1 -0
- package/dist/vendor/spec-core/markdown/index.d.ts +5 -0
- package/dist/vendor/spec-core/markdown/index.js +4 -0
- package/dist/vendor/spec-core/markdown/index.js.map +1 -0
- package/dist/vendor/spec-core/markdown/layout.d.ts +39 -0
- package/dist/vendor/spec-core/markdown/layout.js +28 -0
- package/dist/vendor/spec-core/markdown/layout.js.map +1 -0
- package/dist/vendor/spec-core/markdown/links.d.ts +22 -0
- package/dist/vendor/spec-core/markdown/links.js +364 -0
- package/dist/vendor/spec-core/markdown/links.js.map +1 -0
- package/dist/vendor/spec-core/markdown/lists.d.ts +22 -0
- package/dist/vendor/spec-core/markdown/lists.js +127 -0
- package/dist/vendor/spec-core/markdown/lists.js.map +1 -0
- package/dist/vendor/spec-core/markdown/scan.d.ts +36 -0
- package/dist/vendor/spec-core/markdown/scan.js +439 -0
- package/dist/vendor/spec-core/markdown/scan.js.map +1 -0
- package/dist/vendor/spec-core/markdown/syntax.d.ts +75 -0
- package/dist/vendor/spec-core/markdown/syntax.js +181 -0
- package/dist/vendor/spec-core/markdown/syntax.js.map +1 -0
- package/dist/vendor/spec-core/markdown/tables.d.ts +18 -0
- package/dist/vendor/spec-core/markdown/tables.js +86 -0
- package/dist/vendor/spec-core/markdown/tables.js.map +1 -0
- package/dist/vendor/spec-core/markdown/types.d.ts +287 -0
- package/dist/vendor/spec-core/markdown/types.js +9 -0
- package/dist/vendor/spec-core/markdown/types.js.map +1 -0
- package/dist/vendor/spec-core/path/index.d.ts +1 -0
- package/dist/vendor/spec-core/path/index.js +2 -0
- package/dist/vendor/spec-core/path/index.js.map +1 -0
- package/dist/vendor/spec-core/path/posix.d.ts +83 -0
- package/dist/vendor/spec-core/path/posix.js +150 -0
- package/dist/vendor/spec-core/path/posix.js.map +1 -0
- package/dist/vendor/spec-core/pattern/automaton.d.ts +129 -0
- package/dist/vendor/spec-core/pattern/automaton.js +340 -0
- package/dist/vendor/spec-core/pattern/automaton.js.map +1 -0
- package/dist/vendor/spec-core/pattern/charset.d.ts +58 -0
- package/dist/vendor/spec-core/pattern/charset.js +116 -0
- package/dist/vendor/spec-core/pattern/charset.js.map +1 -0
- package/dist/vendor/spec-core/pattern/glob.d.ts +121 -0
- package/dist/vendor/spec-core/pattern/glob.js +481 -0
- package/dist/vendor/spec-core/pattern/glob.js.map +1 -0
- package/dist/vendor/spec-core/pattern/index.d.ts +6 -0
- package/dist/vendor/spec-core/pattern/index.js +4 -0
- package/dist/vendor/spec-core/pattern/index.js.map +1 -0
- package/dist/vendor/spec-core/pattern/regex.d.ts +67 -0
- package/dist/vendor/spec-core/pattern/regex.js +813 -0
- package/dist/vendor/spec-core/pattern/regex.js.map +1 -0
- package/dist/vendor/spec-core/text/index.d.ts +2 -0
- package/dist/vendor/spec-core/text/index.js +2 -0
- package/dist/vendor/spec-core/text/index.js.map +1 -0
- package/dist/vendor/spec-core/text/lines.d.ts +72 -0
- package/dist/vendor/spec-core/text/lines.js +156 -0
- package/dist/vendor/spec-core/text/lines.js.map +1 -0
- package/package.json +3 -2
- package/schema.json +17 -0
- package/src/vendor/spec-core/LICENSE +21 -0
- package/src/vendor/spec-core/README.md +8 -0
package/dist/collisions.js
CHANGED
|
@@ -4,63 +4,70 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Scopes are compared as globs, not as strings. `src/auth/**` and
|
|
6
6
|
* `src/**\/session.ts` share no prefix a string comparison would see and both
|
|
7
|
-
* cover `src/auth/session.ts`; the
|
|
8
|
-
*
|
|
9
|
-
* is
|
|
7
|
+
* cover `src/auth/session.ts`; the witness search finds that, and names the
|
|
8
|
+
* file. What a brief protects it will not write, so a file either brief of a
|
|
9
|
+
* pair protects is no collision. A brief that declares no scope cannot be
|
|
10
|
+
* proven apart from anything, so it is reported as unscoped rather than
|
|
11
|
+
* silently counted as safe, and a pair the search could not decide is reported
|
|
12
|
+
* as undecided rather than as either.
|
|
13
|
+
*
|
|
14
|
+
* Two briefs that collide are one defect however many of their patterns
|
|
15
|
+
* meet: they are fixed together, by a wave, a dependency or a narrower scope.
|
|
16
|
+
* So a pair is one collision, carrying every pair of patterns that meets.
|
|
10
17
|
*/
|
|
11
18
|
import { lineOfField } from './brief.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return parsed.ok ? [{ pattern, glob: parsed.glob }] : [];
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function matrix(wave, briefs, isFile) {
|
|
19
|
+
import { waitingOnDeferred } from './corpus.js';
|
|
20
|
+
import { globBases, readingIn, WITNESS_BUDGET } from './glob.js';
|
|
21
|
+
import { configuredSeverity } from './lint.js';
|
|
22
|
+
import { meet, scopeOf } from './scope.js';
|
|
23
|
+
import { inWords } from './text.js';
|
|
24
|
+
function matrix(wave, briefs, scopes, budget) {
|
|
22
25
|
const collisions = [];
|
|
26
|
+
const undecided = [];
|
|
23
27
|
const shared = [];
|
|
24
|
-
const scoped = briefs.map((brief) =>
|
|
28
|
+
const scoped = briefs.map((brief) => scopes.get(brief));
|
|
25
29
|
for (let i = 0; i < scoped.length; i += 1) {
|
|
26
30
|
for (let j = i + 1; j < scoped.length; j += 1) {
|
|
27
31
|
const left = scoped[i];
|
|
28
32
|
const right = scoped[j];
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (witness !== null)
|
|
34
|
-
found.push({ a: left.brief, b: right.brief, patterns: [x.pattern, y.pattern], witness });
|
|
35
|
-
}
|
|
33
|
+
const meeting = meet(left, right, budget);
|
|
34
|
+
if (meeting.overlaps.length > 0) {
|
|
35
|
+
collisions.push({ a: left.brief, b: right.brief, overlaps: meeting.overlaps });
|
|
36
|
+
continue;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
if (meeting.undecided.length > 0) {
|
|
39
|
+
undecided.push({ a: left.brief, b: right.brief, patterns: meeting.undecided });
|
|
39
40
|
continue;
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
}
|
|
42
|
+
const leftDirs = new Set(left.affected.flatMap((s) => globBases(s.glob)).filter((d) => d !== ''));
|
|
43
|
+
const directories = [...new Set(right.affected.flatMap((s) => globBases(s.glob)))].filter((d) => leftDirs.has(d)).sort();
|
|
44
|
+
if (directories.length > 0)
|
|
45
|
+
shared.push({ a: left.brief, b: right.brief, directories });
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
const unscoped = briefs.length > 1 ? scoped.filter((s) => s.
|
|
47
|
-
return { wave, briefs, collisions, shared, unscoped };
|
|
48
|
+
const unscoped = briefs.length > 1 ? scoped.filter((s) => s.affected.length === 0).map((s) => s.brief) : [];
|
|
49
|
+
return { wave, briefs, collisions, undecided, shared, unscoped };
|
|
48
50
|
}
|
|
49
51
|
export function collisions(corpus, options = {}) {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
+
const reading = readingIn(options.repoFiles ?? null);
|
|
53
|
+
const budget = options.budget ?? WITNESS_BUDGET;
|
|
54
|
+
const deferred = corpus.live.filter((b) => b.status === 'deferred');
|
|
55
|
+
const waiting = waitingOnDeferred(corpus);
|
|
56
|
+
const held = new Set(waiting.map((w) => w.brief));
|
|
57
|
+
const live = corpus.live.filter((b) => b.status !== 'deferred' && !held.has(b));
|
|
58
|
+
const scopes = new Map(live.map((brief) => [brief, scopeOf(brief, reading)]));
|
|
52
59
|
if (options.all === true)
|
|
53
|
-
return { waves: [matrix(null,
|
|
60
|
+
return { waves: [matrix(null, live, scopes, budget)], unscheduled: [], deferred, waiting };
|
|
54
61
|
const byWave = new Map();
|
|
55
62
|
const unscheduled = [];
|
|
56
|
-
for (const brief of
|
|
63
|
+
for (const brief of live) {
|
|
57
64
|
if (brief.wave === null)
|
|
58
65
|
unscheduled.push(brief);
|
|
59
66
|
else
|
|
60
67
|
byWave.set(brief.wave, [...(byWave.get(brief.wave) ?? []), brief]);
|
|
61
68
|
}
|
|
62
|
-
const waves = [...byWave.keys()].sort((a, b) => a - b).map((wave) => matrix(wave, byWave.get(wave),
|
|
63
|
-
return { waves, unscheduled };
|
|
69
|
+
const waves = [...byWave.keys()].sort((a, b) => a - b).map((wave) => matrix(wave, byWave.get(wave), scopes, budget));
|
|
70
|
+
return { waves, unscheduled, deferred, waiting };
|
|
64
71
|
}
|
|
65
72
|
function label(brief) {
|
|
66
73
|
return brief.id ?? brief.name;
|
|
@@ -68,27 +75,44 @@ function label(brief) {
|
|
|
68
75
|
function where(wave) {
|
|
69
76
|
return wave === null ? 'among the live briefs' : `in wave ${wave}`;
|
|
70
77
|
}
|
|
78
|
+
function collisionMessage(c, wave) {
|
|
79
|
+
if (c.overlaps.length === 1) {
|
|
80
|
+
const only = c.overlaps[0];
|
|
81
|
+
return `"${only.patterns[1]}" overlaps ${label(c.a)}'s "${only.patterns[0]}" ${where(wave)}; both cover ${only.witness}`;
|
|
82
|
+
}
|
|
83
|
+
const each = c.overlaps.map((o) => `"${o.patterns[1]}" and ${label(c.a)}'s "${o.patterns[0]}" both cover ${o.witness}`);
|
|
84
|
+
return `overlaps ${label(c.a)} ${where(wave)} through ${c.overlaps.length} pairs of patterns: ${each.join('; ')}`;
|
|
85
|
+
}
|
|
86
|
+
/** A pair whose collision the search could not decide, as one finding on the later brief. */
|
|
87
|
+
export function undecidedFinding(severity, a, b, patterns, wave) {
|
|
88
|
+
const pairs = patterns.map(([x, y]) => `"${y}" and ${label(a)}'s "${x}"`);
|
|
89
|
+
return {
|
|
90
|
+
rule: 'collision-undecided',
|
|
91
|
+
severity,
|
|
92
|
+
message: `whether it can write a file ${label(a)} writes ${where(wave)} is undecided: the search met its budget for ${inWords(pairs)}`,
|
|
93
|
+
file: b.file,
|
|
94
|
+
line: lineOfField(b, 'affectedFiles') + 1,
|
|
95
|
+
brief: b.id ?? undefined,
|
|
96
|
+
hint: 'narrow one of the patterns, or run the two in different waves',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
71
99
|
/**
|
|
72
|
-
* The report as findings. One
|
|
73
|
-
* brief of the pair, which is usually the one still being written.
|
|
100
|
+
* The report as findings. One pair of briefs is one finding, placed on the
|
|
101
|
+
* later brief of the pair, which is usually the one still being written.
|
|
74
102
|
*/
|
|
75
103
|
export function collisionFindings(corpus, report) {
|
|
76
|
-
const severity = (id) => {
|
|
77
|
-
const rule = COLLISION_RULES.find((r) => r.id === id);
|
|
78
|
-
const setting = severityOf(corpus, id, rule.severity);
|
|
79
|
-
return setting === 'off' ? null : setting;
|
|
80
|
-
};
|
|
81
104
|
const findings = [];
|
|
82
|
-
const collision =
|
|
83
|
-
const
|
|
84
|
-
const
|
|
105
|
+
const collision = configuredSeverity(corpus, 'collision');
|
|
106
|
+
const undecided = configuredSeverity(corpus, 'collision-undecided');
|
|
107
|
+
const unscoped = configuredSeverity(corpus, 'unscoped');
|
|
108
|
+
const sharedDirectory = configuredSeverity(corpus, 'shared-directory');
|
|
85
109
|
for (const wave of report.waves) {
|
|
86
110
|
if (collision !== null) {
|
|
87
111
|
for (const c of wave.collisions) {
|
|
88
112
|
findings.push({
|
|
89
113
|
rule: 'collision',
|
|
90
114
|
severity: collision,
|
|
91
|
-
message:
|
|
115
|
+
message: collisionMessage(c, wave.wave),
|
|
92
116
|
file: c.b.file,
|
|
93
117
|
line: lineOfField(c.b, 'affectedFiles') + 1,
|
|
94
118
|
brief: c.b.id ?? undefined,
|
|
@@ -96,32 +120,40 @@ export function collisionFindings(corpus, report) {
|
|
|
96
120
|
});
|
|
97
121
|
}
|
|
98
122
|
}
|
|
123
|
+
if (undecided !== null) {
|
|
124
|
+
for (const u of wave.undecided)
|
|
125
|
+
findings.push(undecidedFinding(undecided, u.a, u.b, u.patterns, wave.wave));
|
|
126
|
+
}
|
|
99
127
|
if (sharedDirectory !== null) {
|
|
100
128
|
for (const s of wave.shared) {
|
|
101
129
|
findings.push({
|
|
102
130
|
rule: 'shared-directory',
|
|
103
131
|
severity: sharedDirectory,
|
|
104
|
-
message: `writes into ${s.
|
|
132
|
+
message: `writes into ${inWords(s.directories.map((d) => `${d}/`))}, as ${label(s.a)} does ${where(wave.wave)}`,
|
|
105
133
|
file: s.b.file,
|
|
106
134
|
line: lineOfField(s.b, 'affectedFiles') + 1,
|
|
107
135
|
brief: s.b.id ?? undefined,
|
|
136
|
+
hint: 'check that the two do not depend on one decision in that directory; if they do, order them',
|
|
108
137
|
});
|
|
109
138
|
}
|
|
110
139
|
}
|
|
111
140
|
if (unscoped !== null) {
|
|
112
|
-
for (const brief of wave.unscoped)
|
|
113
|
-
findings.push({
|
|
114
|
-
rule: 'unscoped',
|
|
115
|
-
severity: unscoped,
|
|
116
|
-
message: `declares no affectedFiles, so it cannot be checked against the ${wave.briefs.length - 1} other brief(s) ${where(wave.wave)}`,
|
|
117
|
-
file: brief.file,
|
|
118
|
-
line: 1,
|
|
119
|
-
brief: brief.id ?? undefined,
|
|
120
|
-
hint: 'list the files or globs this round writes under "affectedFiles"',
|
|
121
|
-
});
|
|
122
|
-
}
|
|
141
|
+
for (const brief of wave.unscoped)
|
|
142
|
+
findings.push(unscopedFinding(unscoped, brief, `the ${wave.briefs.length - 1} other brief(s) ${where(wave.wave)}`));
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
145
|
return findings;
|
|
126
146
|
}
|
|
147
|
+
/** A brief with no scope, which nothing can be proved apart from. */
|
|
148
|
+
export function unscopedFinding(severity, brief, others) {
|
|
149
|
+
return {
|
|
150
|
+
rule: 'unscoped',
|
|
151
|
+
severity,
|
|
152
|
+
message: `declares no affectedFiles, so it cannot be checked against ${others}`,
|
|
153
|
+
file: brief.file,
|
|
154
|
+
line: 1,
|
|
155
|
+
brief: brief.id ?? undefined,
|
|
156
|
+
hint: 'list the files or globs this round writes under "affectedFiles"',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
127
159
|
//# sourceMappingURL=collisions.js.map
|
package/dist/collisions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collisions.js","sourceRoot":"","sources":["../src/collisions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAa,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAuC5D,SAAS,MAAM,CAAC,KAAY,EAAE,MAA+C;IAC3E,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,MAAM,CAAC,IAAmB,EAAE,MAA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tI,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,IAAI,EAAE,CAAC;oBACP,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,SAAS;oBAC5B,IAAI,EAAE,iEAAiE;iBACxE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The collision matrix: which briefs scheduled to run side by side declare\n * scopes that can name the same file.\n *\n * Scopes are compared as globs, not as strings. `src/auth/**` and\n * `src/**\\/session.ts` share no prefix a string comparison would see and both\n * cover `src/auth/session.ts`; the intersection finds that, and names the file.\n * A brief that declares no scope cannot be proven apart from anything, so it\n * is reported as unscoped rather than silently counted as safe.\n */\n\nimport type { Brief } from './brief.js';\nimport { lineOfField } from './brief.js';\nimport type { Corpus } from './corpus.js';\nimport { type Glob, globBase, intersectGlobs, parseGlob } from './glob.js';\nimport { severityOf } from './lint.js';\nimport { COLLISION_RULES, type RuleInfo } from './rules.js';\nimport type { Finding, Severity } from './types.js';\n\nexport interface Collision {\n readonly a: Brief;\n readonly b: Brief;\n readonly patterns: readonly [string, string];\n /** A path both scopes cover. */\n readonly witness: string;\n}\n\nexport interface SharedDirectory {\n readonly a: Brief;\n readonly b: Brief;\n readonly directory: string;\n}\n\nexport interface WaveMatrix {\n /** `null` when every live brief is compared regardless of wave. */\n readonly wave: number | null;\n readonly briefs: readonly Brief[];\n readonly collisions: readonly Collision[];\n readonly shared: readonly SharedDirectory[];\n readonly unscoped: readonly Brief[];\n}\n\nexport interface CollisionReport {\n readonly waves: readonly WaveMatrix[];\n /** Live briefs with no wave, which the matrix does not place. */\n readonly unscheduled: readonly Brief[];\n}\n\nexport interface CollisionOptions {\n /** Compare every live brief with every other, whatever its wave. */\n readonly all?: boolean;\n /** Tracked files, which tell a literal file path from a directory. */\n readonly repoFiles?: readonly string[] | null;\n}\n\nfunction scopes(brief: Brief, isFile: ((path: string) => boolean) | undefined): { pattern: string; glob: Glob }[] {\n return brief.affectedFiles.flatMap((pattern) => {\n const parsed = parseGlob(pattern, { isFile });\n return parsed.ok ? [{ pattern, glob: parsed.glob }] : [];\n });\n}\n\nfunction matrix(wave: number | null, briefs: readonly Brief[], isFile: ((path: string) => boolean) | undefined): WaveMatrix {\n const collisions: Collision[] = [];\n const shared: SharedDirectory[] = [];\n const scoped = briefs.map((brief) => ({ brief, scopes: scopes(brief, isFile) }));\n for (let i = 0; i < scoped.length; i += 1) {\n for (let j = i + 1; j < scoped.length; j += 1) {\n const left = scoped[i] as (typeof scoped)[number];\n const right = scoped[j] as (typeof scoped)[number];\n const found: Collision[] = [];\n for (const x of left.scopes) {\n for (const y of right.scopes) {\n const witness = intersectGlobs(x.glob, y.glob);\n if (witness !== null) found.push({ a: left.brief, b: right.brief, patterns: [x.pattern, y.pattern], witness });\n }\n }\n collisions.push(...found);\n if (found.length > 0) continue;\n const leftDirs = new Set(left.scopes.map((s) => globBase(s.glob)).filter((d) => d !== ''));\n const common = [...new Set(right.scopes.map((s) => globBase(s.glob)))].filter((d) => leftDirs.has(d)).sort();\n for (const directory of common) shared.push({ a: left.brief, b: right.brief, directory });\n }\n }\n const unscoped = briefs.length > 1 ? scoped.filter((s) => s.scopes.length === 0).map((s) => s.brief) : [];\n return { wave, briefs, collisions, shared, unscoped };\n}\n\nexport function collisions(corpus: Corpus, options: CollisionOptions = {}): CollisionReport {\n const files = options.repoFiles === undefined || options.repoFiles === null ? null : new Set(options.repoFiles);\n const isFile = files === null ? undefined : (path: string): boolean => files.has(path);\n if (options.all === true) return { waves: [matrix(null, corpus.live, isFile)], unscheduled: [] };\n const byWave = new Map<number, Brief[]>();\n const unscheduled: Brief[] = [];\n for (const brief of corpus.live) {\n if (brief.wave === null) unscheduled.push(brief);\n else byWave.set(brief.wave, [...(byWave.get(brief.wave) ?? []), brief]);\n }\n const waves = [...byWave.keys()].sort((a, b) => a - b).map((wave) => matrix(wave, byWave.get(wave) as Brief[], isFile));\n return { waves, unscheduled };\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\nfunction where(wave: number | null): string {\n return wave === null ? 'among the live briefs' : `in wave ${wave}`;\n}\n\n/**\n * The report as findings. One collision is one finding, placed on the later\n * brief of the pair, which is usually the one still being written.\n */\nexport function collisionFindings(corpus: Corpus, report: CollisionReport): Finding[] {\n const severity = (id: string): Severity | null => {\n const rule = COLLISION_RULES.find((r) => r.id === id) as RuleInfo;\n const setting = severityOf(corpus, id, rule.severity);\n return setting === 'off' ? null : setting;\n };\n const findings: Finding[] = [];\n const collision = severity('collision');\n const unscoped = severity('unscoped');\n const sharedDirectory = severity('shared-directory');\n for (const wave of report.waves) {\n if (collision !== null) {\n for (const c of wave.collisions) {\n findings.push({\n rule: 'collision',\n severity: collision,\n message: `\"${c.patterns[1]}\" overlaps ${label(c.a)}'s \"${c.patterns[0]}\" ${where(wave.wave)}; both cover ${c.witness}`,\n file: c.b.file,\n line: lineOfField(c.b, 'affectedFiles') + 1,\n brief: c.b.id ?? undefined,\n hint: `run them in different waves, make one depend on the other, or narrow a scope`,\n });\n }\n }\n if (sharedDirectory !== null) {\n for (const s of wave.shared) {\n findings.push({\n rule: 'shared-directory',\n severity: sharedDirectory,\n message: `writes into ${s.directory}/, as ${label(s.a)} does ${where(wave.wave)}`,\n file: s.b.file,\n line: lineOfField(s.b, 'affectedFiles') + 1,\n brief: s.b.id ?? undefined,\n });\n }\n }\n if (unscoped !== null) {\n for (const brief of wave.unscoped) {\n findings.push({\n rule: 'unscoped',\n severity: unscoped,\n message: `declares no affectedFiles, so it cannot be checked against the ${wave.briefs.length - 1} other brief(s) ${where(wave.wave)}`,\n file: brief.file,\n line: 1,\n brief: brief.id ?? undefined,\n hint: 'list the files or globs this round writes under \"affectedFiles\"',\n });\n }\n }\n }\n return findings;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"collisions.js","sourceRoot":"","sources":["../src/collisions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OA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;IAC9E,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ;QACR,OAAO,EAAE,8DAA8D,MAAM,EAAE;QAC/E,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,SAAS;QAC5B,IAAI,EAAE,iEAAiE;KACxE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The collision matrix: which briefs scheduled to run side by side declare\n * scopes that can name the same file.\n *\n * Scopes are compared as globs, not as strings. `src/auth/**` and\n * `src/**\\/session.ts` share no prefix a string comparison would see and both\n * cover `src/auth/session.ts`; the witness search finds that, and names the\n * file. What a brief protects it will not write, so a file either brief of a\n * pair protects is no collision. A brief that declares no scope cannot be\n * proven apart from anything, so it is reported as unscoped rather than\n * silently counted as safe, and a pair the search could not decide is reported\n * as undecided rather than as either.\n *\n * Two briefs that collide are one defect however many of their patterns\n * meet: they are fixed together, by a wave, a dependency or a narrower scope.\n * So a pair is one collision, carrying every pair of patterns that meets.\n */\n\nimport type { Brief } from './brief.js';\nimport { lineOfField } from './brief.js';\nimport { type Corpus, waitingOnDeferred, type Waiting } from './corpus.js';\nimport { globBases, readingIn, WITNESS_BUDGET } from './glob.js';\nimport { configuredSeverity } from './lint.js';\nimport { meet, type Overlap, type Scope, scopeOf } from './scope.js';\nimport { inWords } from './text.js';\nimport type { Finding, Severity } from './types.js';\n\nexport type { Overlap } from './scope.js';\n\nexport interface Collision {\n readonly a: Brief;\n readonly b: Brief;\n /** Every pair of patterns that meets, `a`'s first; never empty. */\n readonly overlaps: readonly Overlap[];\n}\n\n/** Two briefs no pair of whose patterns is known to meet, and some pair the search could not decide. */\nexport interface UndecidedPair {\n readonly a: Brief;\n readonly b: Brief;\n /** The pairs of patterns, `a`'s first; never empty. */\n readonly patterns: readonly (readonly [string, string])[];\n}\n\nexport interface SharedDirectory {\n readonly a: Brief;\n readonly b: Brief;\n /** The directories both write into, sorted; never empty. */\n readonly directories: readonly string[];\n}\n\nexport interface WaveMatrix {\n /** `null` when every live brief is compared regardless of wave. */\n readonly wave: number | null;\n readonly briefs: readonly Brief[];\n readonly collisions: readonly Collision[];\n readonly undecided: readonly UndecidedPair[];\n readonly shared: readonly SharedDirectory[];\n readonly unscoped: readonly Brief[];\n}\n\nexport interface CollisionReport {\n readonly waves: readonly WaveMatrix[];\n /** Live briefs with no wave, which the matrix does not place. */\n readonly unscheduled: readonly Brief[];\n /** Deferred briefs, which wait for their trigger and run in no wave. */\n readonly deferred: readonly Brief[];\n /**\n * Briefs that depend on a deferred brief, or on one that waits on one. They\n * cannot start before the deferred work, so they run in no wave either, and\n * are compared with nothing - as `schedule` places them nowhere. By id.\n */\n readonly waiting: readonly Waiting[];\n}\n\nexport interface CollisionOptions {\n /** Compare every live brief with every other, whatever its wave. */\n readonly all?: boolean;\n /** The files the tree holds, which say whether a literal path is a file or a directory. */\n readonly repoFiles?: readonly string[] | null;\n /** How many states one witness search may visit before it answers `undecided`. */\n readonly budget?: number;\n}\n\nfunction matrix(wave: number | null, briefs: readonly Brief[], scopes: ReadonlyMap<Brief, Scope>, budget: number): WaveMatrix {\n const collisions: Collision[] = [];\n const undecided: UndecidedPair[] = [];\n const shared: SharedDirectory[] = [];\n const scoped = briefs.map((brief) => scopes.get(brief) as Scope);\n for (let i = 0; i < scoped.length; i += 1) {\n for (let j = i + 1; j < scoped.length; j += 1) {\n const left = scoped[i] as Scope;\n const right = scoped[j] as Scope;\n const meeting = meet(left, right, budget);\n if (meeting.overlaps.length > 0) {\n collisions.push({ a: left.brief, b: right.brief, overlaps: meeting.overlaps });\n continue;\n }\n if (meeting.undecided.length > 0) {\n undecided.push({ a: left.brief, b: right.brief, patterns: meeting.undecided });\n continue;\n }\n const leftDirs = new Set(left.affected.flatMap((s) => globBases(s.glob)).filter((d) => d !== ''));\n const directories = [...new Set(right.affected.flatMap((s) => globBases(s.glob)))].filter((d) => leftDirs.has(d)).sort();\n if (directories.length > 0) shared.push({ a: left.brief, b: right.brief, directories });\n }\n }\n const unscoped = briefs.length > 1 ? scoped.filter((s) => s.affected.length === 0).map((s) => s.brief) : [];\n return { wave, briefs, collisions, undecided, shared, unscoped };\n}\n\nexport function collisions(corpus: Corpus, options: CollisionOptions = {}): CollisionReport {\n const reading = readingIn(options.repoFiles ?? null);\n const budget = options.budget ?? WITNESS_BUDGET;\n const deferred = corpus.live.filter((b) => b.status === 'deferred');\n const waiting = waitingOnDeferred(corpus);\n const held = new Set(waiting.map((w) => w.brief));\n const live = corpus.live.filter((b) => b.status !== 'deferred' && !held.has(b));\n const scopes = new Map(live.map((brief) => [brief, scopeOf(brief, reading)]));\n if (options.all === true) return { waves: [matrix(null, live, scopes, budget)], unscheduled: [], deferred, waiting };\n const byWave = new Map<number, Brief[]>();\n const unscheduled: Brief[] = [];\n for (const brief of live) {\n if (brief.wave === null) unscheduled.push(brief);\n else byWave.set(brief.wave, [...(byWave.get(brief.wave) ?? []), brief]);\n }\n const waves = [...byWave.keys()].sort((a, b) => a - b).map((wave) => matrix(wave, byWave.get(wave) as Brief[], scopes, budget));\n return { waves, unscheduled, deferred, waiting };\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\nfunction where(wave: number | null): string {\n return wave === null ? 'among the live briefs' : `in wave ${wave}`;\n}\n\nfunction collisionMessage(c: Collision, wave: number | null): string {\n if (c.overlaps.length === 1) {\n const only = c.overlaps[0] as Overlap;\n return `\"${only.patterns[1]}\" overlaps ${label(c.a)}'s \"${only.patterns[0]}\" ${where(wave)}; both cover ${only.witness}`;\n }\n const each = c.overlaps.map((o) => `\"${o.patterns[1]}\" and ${label(c.a)}'s \"${o.patterns[0]}\" both cover ${o.witness}`);\n return `overlaps ${label(c.a)} ${where(wave)} through ${c.overlaps.length} pairs of patterns: ${each.join('; ')}`;\n}\n\n/** A pair whose collision the search could not decide, as one finding on the later brief. */\nexport function undecidedFinding(severity: Severity, a: Brief, b: Brief, patterns: readonly (readonly [string, string])[], wave: number | null): Finding {\n const pairs = patterns.map(([x, y]) => `\"${y}\" and ${label(a)}'s \"${x}\"`);\n return {\n rule: 'collision-undecided',\n severity,\n message: `whether it can write a file ${label(a)} writes ${where(wave)} is undecided: the search met its budget for ${inWords(pairs)}`,\n file: b.file,\n line: lineOfField(b, 'affectedFiles') + 1,\n brief: b.id ?? undefined,\n hint: 'narrow one of the patterns, or run the two in different waves',\n };\n}\n\n/**\n * The report as findings. One pair of briefs is one finding, placed on the\n * later brief of the pair, which is usually the one still being written.\n */\nexport function collisionFindings(corpus: Corpus, report: CollisionReport): Finding[] {\n const findings: Finding[] = [];\n const collision = configuredSeverity(corpus, 'collision');\n const undecided = configuredSeverity(corpus, 'collision-undecided');\n const unscoped = configuredSeverity(corpus, 'unscoped');\n const sharedDirectory = configuredSeverity(corpus, 'shared-directory');\n for (const wave of report.waves) {\n if (collision !== null) {\n for (const c of wave.collisions) {\n findings.push({\n rule: 'collision',\n severity: collision,\n message: collisionMessage(c, wave.wave),\n file: c.b.file,\n line: lineOfField(c.b, 'affectedFiles') + 1,\n brief: c.b.id ?? undefined,\n hint: `run them in different waves, make one depend on the other, or narrow a scope`,\n });\n }\n }\n if (undecided !== null) {\n for (const u of wave.undecided) findings.push(undecidedFinding(undecided, u.a, u.b, u.patterns, wave.wave));\n }\n if (sharedDirectory !== null) {\n for (const s of wave.shared) {\n findings.push({\n rule: 'shared-directory',\n severity: sharedDirectory,\n message: `writes into ${inWords(s.directories.map((d) => `${d}/`))}, as ${label(s.a)} does ${where(wave.wave)}`,\n file: s.b.file,\n line: lineOfField(s.b, 'affectedFiles') + 1,\n brief: s.b.id ?? undefined,\n hint: 'check that the two do not depend on one decision in that directory; if they do, order them',\n });\n }\n }\n if (unscoped !== null) {\n for (const brief of wave.unscoped) findings.push(unscopedFinding(unscoped, brief, `the ${wave.briefs.length - 1} other brief(s) ${where(wave.wave)}`));\n }\n }\n return findings;\n}\n\n/** A brief with no scope, which nothing can be proved apart from. */\nexport function unscopedFinding(severity: Severity, brief: Brief, others: string): Finding {\n return {\n rule: 'unscoped',\n severity,\n message: `declares no affectedFiles, so it cannot be checked against ${others}`,\n file: brief.file,\n line: 1,\n brief: brief.id ?? undefined,\n hint: 'list the files or globs this round writes under \"affectedFiles\"',\n };\n}\n"]}
|
package/dist/config.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ export interface SectionRule {
|
|
|
22
22
|
/** The section must hold at least one task item. */
|
|
23
23
|
readonly checklist: boolean;
|
|
24
24
|
readonly optional: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* What the section must answer. A new brief carries it as a comment under
|
|
27
|
+
* the heading, a finding that the section is missing or unwritten carries it
|
|
28
|
+
* as its hint, and `list` and `lint` report it, so a tool that helps write a
|
|
29
|
+
* brief can ask for each section without knowing its name in advance.
|
|
30
|
+
*/
|
|
31
|
+
readonly hint?: string | undefined;
|
|
25
32
|
}
|
|
26
33
|
export interface PluginReference {
|
|
27
34
|
readonly module: string;
|
|
@@ -47,6 +54,8 @@ export interface Config {
|
|
|
47
54
|
readonly field: string | null;
|
|
48
55
|
readonly draft: string | null;
|
|
49
56
|
readonly active: string;
|
|
57
|
+
/** The word for work put off until an event its `trigger` names; `null` when a repository has none. */
|
|
58
|
+
readonly deferred: string | null;
|
|
50
59
|
readonly archived: string;
|
|
51
60
|
};
|
|
52
61
|
readonly sections: readonly SectionRule[];
|
|
@@ -81,6 +90,8 @@ export declare class ConfigError extends Error {
|
|
|
81
90
|
* names its own sections means those sections and not the defaults as well.
|
|
82
91
|
*/
|
|
83
92
|
export declare function resolveConfig(raw: unknown, file?: string): Config;
|
|
93
|
+
/** The status words a repository uses, in lifecycle order. */
|
|
94
|
+
export declare function statusWords(config: Config): string[];
|
|
84
95
|
/** Parses the text of a configuration file. */
|
|
85
96
|
export declare function parseConfig(text: string, file: string): Config;
|
|
86
97
|
/**
|
package/dist/config.js
CHANGED
|
@@ -16,7 +16,7 @@ import { dirname, join } from 'node:path';
|
|
|
16
16
|
import { parseGlob } from './glob.js';
|
|
17
17
|
import { normalisePath } from './links.js';
|
|
18
18
|
import { toJsonSchema, validate } from './schema.js';
|
|
19
|
-
import { templateHoles } from './text.js';
|
|
19
|
+
import { inWords, templateHoles } from './text.js';
|
|
20
20
|
export const CONFIG_FILES = ['.spec-brief.json', 'spec-brief.json'];
|
|
21
21
|
/** The holes a banner line may use. */
|
|
22
22
|
export const BANNER_PLACEHOLDERS = [
|
|
@@ -47,6 +47,11 @@ const SECTION = {
|
|
|
47
47
|
mustContain: { ...STRINGS, description: 'Literal text the section must contain.' },
|
|
48
48
|
checklist: { type: 'boolean', description: 'The section must hold at least one "- [ ]" task item.' },
|
|
49
49
|
optional: { type: 'boolean', description: 'Checked when present, not required.' },
|
|
50
|
+
hint: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
minLength: 1,
|
|
53
|
+
description: 'What the section must answer: a comment under the heading in a new brief, and the hint of a finding that it is missing or unwritten.',
|
|
54
|
+
},
|
|
50
55
|
},
|
|
51
56
|
},
|
|
52
57
|
],
|
|
@@ -74,6 +79,11 @@ export const CONFIG_SCHEMA = {
|
|
|
74
79
|
field: { type: 'string', nullable: true, description: 'Front-matter key holding the status; null uses location only.' },
|
|
75
80
|
draft: { type: 'string', nullable: true, description: 'The word for a brief still being written, or null.' },
|
|
76
81
|
active: { type: 'string', minLength: 1, description: 'The word for a live brief.' },
|
|
82
|
+
deferred: {
|
|
83
|
+
type: 'string',
|
|
84
|
+
nullable: true,
|
|
85
|
+
description: 'The word for a live brief put off until the event its "trigger" names, or null. A deferred brief is never ready and runs in no wave.',
|
|
86
|
+
},
|
|
77
87
|
archived: { type: 'string', minLength: 1, description: 'The word for an archived brief.' },
|
|
78
88
|
},
|
|
79
89
|
},
|
|
@@ -133,19 +143,36 @@ export const DEFAULT_CONFIG = {
|
|
|
133
143
|
exclude: [],
|
|
134
144
|
template: null,
|
|
135
145
|
id: { source: 'filename', separator: '_', digits: 3 },
|
|
136
|
-
status: { field: 'status', draft: 'draft', active: 'active', archived: 'archived' },
|
|
146
|
+
status: { field: 'status', draft: 'draft', active: 'active', deferred: 'deferred', archived: 'archived' },
|
|
137
147
|
sections: [
|
|
138
|
-
section('Intent', {
|
|
148
|
+
section('Intent', {
|
|
149
|
+
aliases: ["Commander's Intent", 'Mission', 'Objective'],
|
|
150
|
+
hint: 'The state of the tree when this round is done, and why it matters. One paragraph.',
|
|
151
|
+
}),
|
|
139
152
|
section('Negative Scope', {
|
|
140
153
|
aliases: ['Out of Scope', 'Non-Goals', 'Not in Scope', 'What this round is NOT', 'What this brief does NOT do'],
|
|
154
|
+
hint: 'What this round must not do, even where it would look helpful.',
|
|
155
|
+
}),
|
|
156
|
+
section('Not Empowered', {
|
|
157
|
+
aliases: ['Non-Empowerment', 'Non-Empowerment List'],
|
|
158
|
+
optional: true,
|
|
159
|
+
hint: 'Files, interfaces and decisions this round may not change.',
|
|
160
|
+
}),
|
|
161
|
+
section('Invariants', {
|
|
162
|
+
aliases: ['Invariant Checklist', 'Definition of Done'],
|
|
163
|
+
checklist: true,
|
|
164
|
+
hint: 'Checks that must hold before the round is called done, each one a task item.',
|
|
141
165
|
}),
|
|
142
|
-
section('Not Empowered', { aliases: ['Non-Empowerment', 'Non-Empowerment List'], optional: true }),
|
|
143
|
-
section('Invariants', { aliases: ['Invariant Checklist', 'Definition of Done'], checklist: true }),
|
|
144
166
|
],
|
|
145
167
|
sectionOrder: false,
|
|
146
168
|
types: {
|
|
147
|
-
feature: [section('Acceptance Criteria', { checklist: true })],
|
|
148
|
-
defect: [
|
|
169
|
+
feature: [section('Acceptance Criteria', { checklist: true, hint: 'What a reviewer checks to accept the result, each one a task item.' })],
|
|
170
|
+
defect: [
|
|
171
|
+
section('The Defect, Measured', {
|
|
172
|
+
aliases: ['Reproduction'],
|
|
173
|
+
hint: 'How to reproduce the defect, and the measurement that shows it.',
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
149
176
|
refactor: [],
|
|
150
177
|
chore: [],
|
|
151
178
|
},
|
|
@@ -178,6 +205,7 @@ function sectionFrom(raw) {
|
|
|
178
205
|
mustContain: r['mustContain'] ?? [],
|
|
179
206
|
checklist: r['checklist'] ?? false,
|
|
180
207
|
optional: r['optional'] ?? false,
|
|
208
|
+
hint: r['hint'],
|
|
181
209
|
});
|
|
182
210
|
}
|
|
183
211
|
function pluginFrom(raw) {
|
|
@@ -234,6 +262,11 @@ export function resolveConfig(raw, file = 'configuration') {
|
|
|
234
262
|
throw new ConfigError(file, semantic);
|
|
235
263
|
return config;
|
|
236
264
|
}
|
|
265
|
+
/** The status words a repository uses, in lifecycle order. */
|
|
266
|
+
export function statusWords(config) {
|
|
267
|
+
const { draft, active, deferred, archived } = config.status;
|
|
268
|
+
return [draft, active, deferred, archived].filter((w) => w !== null);
|
|
269
|
+
}
|
|
237
270
|
/** What the schema cannot say: relationships between values. */
|
|
238
271
|
function checkConfig(config) {
|
|
239
272
|
const problems = [];
|
|
@@ -250,9 +283,22 @@ function checkConfig(config) {
|
|
|
250
283
|
const archive = inside('archive', config.archive);
|
|
251
284
|
if (briefs !== null && briefs === archive)
|
|
252
285
|
problems.push('"briefs" and "archive" must be different directories');
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
286
|
+
// Named by the statuses that share a word: a 0.1 configuration that spelt
|
|
287
|
+
// another status "deferred" meets the default for the new one here.
|
|
288
|
+
const sharing = new Map();
|
|
289
|
+
for (const key of ['draft', 'active', 'deferred', 'archived']) {
|
|
290
|
+
const word = config.status[key];
|
|
291
|
+
if (word === null)
|
|
292
|
+
continue;
|
|
293
|
+
const group = sharing.get(word.toLowerCase()) ?? { word, keys: [] };
|
|
294
|
+
group.keys.push(key);
|
|
295
|
+
sharing.set(word.toLowerCase(), group);
|
|
296
|
+
}
|
|
297
|
+
for (const { word, keys } of sharing.values()) {
|
|
298
|
+
if (keys.length < 2)
|
|
299
|
+
continue;
|
|
300
|
+
const orNull = keys.includes('deferred') ? ', or set "status.deferred" to null where no work is deferred' : '';
|
|
301
|
+
problems.push(`the status words must differ: "${word}" is the word for ${inWords(keys)}; give ${keys.length === 2 ? 'one of them' : 'all but one'} another word${orNull}`);
|
|
256
302
|
}
|
|
257
303
|
// A pattern that does not parse would match nothing, and a run over no briefs reads as clean.
|
|
258
304
|
for (const [key, pattern] of [['files', config.files], ...config.exclude.map((e) => ['exclude', e])]) {
|
|
@@ -331,6 +377,8 @@ export function initialConfig(briefs, archive) {
|
|
|
331
377
|
out['checklist'] = true;
|
|
332
378
|
if (s.optional)
|
|
333
379
|
out['optional'] = true;
|
|
380
|
+
if (s.hint !== undefined)
|
|
381
|
+
out['hint'] = s.hint;
|
|
334
382
|
return Object.keys(out).length === 1 ? s.name : out;
|
|
335
383
|
};
|
|
336
384
|
return {
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAe,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAyD1C,MAAM,CAAC,MAAM,YAAY,GAAsB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;AAEvF,uCAAuC;AACvC,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,MAAM;IACN,SAAS;IACT,IAAI;IACJ,QAAQ;IACR,UAAU;IACV,OAAO;IACP,IAAI;IACJ,OAAO;IACP,QAAQ;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,0EAA0E,CAAC;AAErG,MAAM,QAAQ,GAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,KAAK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AAC,aAAa,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC;QACjE,IAAI,CAAC,CAAC,SAAS;YAAE,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;QACzC,IAAI,CAAC,CAAC,QAAQ;YAAE,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACvC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;IACtD,CAAC,CAAC;IACF,OAAO;QACL,OAAO,EAAE,UAAU;QACnB,MAAM;QACN,OAAO;QACP,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC;QACrC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;QACzG,SAAS,EAAE;YACT,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK;YACxB,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,YAAY;YACtC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM;YAC1B,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI;SACvB;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Configuration: what it may say, what it says when it says nothing, and how a\n * file becomes a `Config`.\n *\n * Every repository that already keeps briefs keeps them its own way - where\n * they live, what the sections are called, which word means \"done\" - so the\n * conventions are data here rather than code. The defaults describe a brief\n * with the four parts every round needs: an intent, a negative scope, what the\n * round is not empowered to touch, and the invariants that prove it is done.\n *\n * A configuration that does not load stops the run. A typo that silently\n * falls back to defaults produces a clean-looking report about the wrong\n * rules, which is worse than no report.\n */\n\nimport { dirname, join } from 'node:path';\n\nimport { parseGlob } from './glob.js';\nimport { normalisePath } from './links.js';\nimport { type Schema, toJsonSchema, validate } from './schema.js';\nimport { templateHoles } from './text.js';\nimport type { SeveritySetting } from './types.js';\n\nexport interface SectionRule {\n readonly name: string;\n readonly aliases: readonly string[];\n /** Literal text the section must contain, compared exactly. */\n readonly mustContain: readonly string[];\n /** The section must hold at least one task item. */\n readonly checklist: boolean;\n readonly optional: boolean;\n}\n\nexport interface PluginReference {\n readonly module: string;\n readonly options: unknown;\n}\n\nexport interface Config {\n /** Directory of live briefs, relative to the root. */\n readonly briefs: string;\n /** Directory of archived briefs, relative to the root. */\n readonly archive: string;\n /** Glob a file name must match to be a brief. */\n readonly files: string;\n /** File-name globs that are never briefs, such as an index. */\n readonly exclude: readonly string[];\n /** A template for `new`, relative to the root; `null` builds one from `sections`. */\n readonly template: string | null;\n readonly id: {\n readonly source: 'filename' | 'frontmatter';\n readonly separator: string;\n readonly digits: number;\n };\n readonly status: {\n readonly field: string | null;\n readonly draft: string | null;\n readonly active: string;\n readonly archived: string;\n };\n readonly sections: readonly SectionRule[];\n readonly sectionOrder: boolean;\n readonly types: Readonly<Record<string, readonly SectionRule[]>>;\n readonly placeholders: readonly string[];\n readonly fields: readonly string[];\n readonly archiving: {\n readonly tasks: 'all' | readonly string[];\n readonly dispositions: readonly string[];\n readonly banner: readonly string[];\n readonly rewriteLinks: boolean;\n readonly freeze: boolean;\n readonly base: string | null;\n };\n readonly rules: Readonly<Record<string, SeveritySetting>>;\n readonly plugins: readonly PluginReference[];\n}\n\nexport const CONFIG_FILES: readonly string[] = ['.spec-brief.json', 'spec-brief.json'];\n\n/** The holes a banner line may use. */\nexport const BANNER_PLACEHOLDERS: readonly string[] = [\n 'date',\n 'summary',\n 'pr',\n 'commit',\n 'diffstat',\n 'links',\n 'id',\n 'title',\n 'author',\n];\n\nexport const SCHEMA_URL = 'https://raw.githubusercontent.com/DescentVTT/spec-brief/main/schema.json';\n\nconst SEVERITY: Schema = { type: 'string', enum: ['off', 'note', 'warning', 'error'] };\nconst STRINGS: Schema = { type: 'array', items: { type: 'string', minLength: 1 } };\n\nconst SECTION: Schema = {\n type: 'anyOf',\n description: 'A section name, or a section with aliases and content rules.',\n options: [\n { type: 'string', minLength: 1 },\n {\n type: 'object',\n required: ['name'],\n properties: {\n name: { type: 'string', minLength: 1, description: 'The heading text, compared without case or punctuation.' },\n aliases: { ...STRINGS, description: 'Other headings that fill this section.' },\n mustContain: { ...STRINGS, description: 'Literal text the section must contain.' },\n checklist: { type: 'boolean', description: 'The section must hold at least one \"- [ ]\" task item.' },\n optional: { type: 'boolean', description: 'Checked when present, not required.' },\n },\n },\n ],\n};\n\nexport const CONFIG_SCHEMA: Schema = {\n type: 'object',\n properties: {\n $schema: { type: 'string' },\n briefs: { type: 'string', minLength: 1, description: 'Directory of live briefs, relative to this file.' },\n archive: { type: 'string', minLength: 1, description: 'Directory of archived briefs, relative to this file.' },\n files: { type: 'string', minLength: 1, description: 'Glob a file name must match to be a brief.' },\n exclude: { ...STRINGS, description: 'File-name globs that are never briefs.' },\n template: { type: 'string', nullable: true, description: 'Template file for \"new\"; null builds one from the sections.' },\n id: {\n type: 'object',\n properties: {\n source: { type: 'string', enum: ['filename', 'frontmatter'], description: 'Where a brief id comes from.' },\n separator: { type: 'string', minLength: 1, description: 'Separates the id from the slug in a file name.' },\n digits: { type: 'integer', minimum: 1, maximum: 12, description: 'Width of an allocated numeric id.' },\n },\n },\n status: {\n type: 'object',\n properties: {\n field: { type: 'string', nullable: true, description: 'Front-matter key holding the status; null uses location only.' },\n draft: { type: 'string', nullable: true, description: 'The word for a brief still being written, or null.' },\n active: { type: 'string', minLength: 1, description: 'The word for a live brief.' },\n archived: { type: 'string', minLength: 1, description: 'The word for an archived brief.' },\n },\n },\n sections: { type: 'array', items: SECTION, description: 'Sections every live brief carries.' },\n sectionOrder: { type: 'boolean', description: 'Sections must appear in the order listed.' },\n types: {\n type: 'map',\n description: 'Brief types, each with the sections it adds.',\n values: { type: 'object', properties: { sections: { type: 'array', items: SECTION } } },\n },\n placeholders: { ...STRINGS, description: 'Words that mark a section as unwritten.' },\n fields: { ...STRINGS, description: 'Front-matter keys this repository uses beyond the built-in ones.' },\n archiving: {\n type: 'object',\n properties: {\n tasks: {\n type: 'anyOf',\n description: '\"all\", or the sections whose task items must be closed before archiving.',\n options: [{ type: 'string', enum: ['all'] }, STRINGS],\n },\n dispositions: { ...STRINGS, description: 'Text under an open box that closes it without a tick.' },\n banner: {\n type: 'array',\n items: { type: 'string' },\n description: 'Lines of the frozen banner; a line with an empty {placeholder} is left out, and an empty line separates paragraphs.',\n },\n rewriteLinks: { type: 'boolean', description: 'Rewrite relative links so they resolve from the new directory.' },\n freeze: { type: 'boolean', description: 'Record a content hash so later edits are caught.' },\n base: { type: 'string', nullable: true, description: 'Branch the diff is measured from, such as \"main\".' },\n },\n },\n rules: { type: 'map', values: SEVERITY, description: 'Severity per rule id.' },\n plugins: {\n type: 'array',\n description: 'Modules that contribute rules.',\n items: {\n type: 'anyOf',\n options: [\n { type: 'string', minLength: 1 },\n {\n type: 'object',\n required: ['module'],\n properties: { module: { type: 'string', minLength: 1 }, options: { type: 'any' } },\n },\n ],\n },\n },\n },\n};\n\nfunction section(name: string, extra: Partial<Omit<SectionRule, 'name'>> = {}): SectionRule {\n return { name, aliases: [], mustContain: [], checklist: false, optional: false, ...extra };\n}\n\nexport const DEFAULT_CONFIG: Config = {\n briefs: 'briefs',\n archive: 'briefs/archive',\n files: '[0-9]*.md',\n exclude: [],\n template: null,\n id: { source: 'filename', separator: '_', digits: 3 },\n status: { field: 'status', draft: 'draft', active: 'active', archived: 'archived' },\n sections: [\n section('Intent', { aliases: [\"Commander's Intent\", 'Mission', 'Objective'] }),\n section('Negative Scope', {\n aliases: ['Out of Scope', 'Non-Goals', 'Not in Scope', 'What this round is NOT', 'What this brief does NOT do'],\n }),\n section('Not Empowered', { aliases: ['Non-Empowerment', 'Non-Empowerment List'], optional: true }),\n section('Invariants', { aliases: ['Invariant Checklist', 'Definition of Done'], checklist: true }),\n ],\n sectionOrder: false,\n types: {\n feature: [section('Acceptance Criteria', { checklist: true })],\n defect: [section('The Defect, Measured', { aliases: ['Reproduction'] })],\n refactor: [],\n chore: [],\n },\n placeholders: ['TBD', 'TBA', 'TODO', 'FIXME', 'XXX', '???', '...', '\\u2026'],\n fields: [],\n archiving: {\n tasks: 'all',\n dispositions: ['**Delegated', '**Accepted debt', '**Rejected'],\n banner: [\n '**Archived {date}.**',\n '{summary}',\n 'Merged in pull request {pr}.',\n 'Recorded at commit `{commit}`: {diffstat}.',\n '{links}',\n 'The body below describes the tree before execution and is not maintained.',\n ],\n rewriteLinks: true,\n freeze: true,\n base: null,\n },\n rules: {},\n plugins: [],\n};\n\ntype Raw = Record<string, unknown>;\n\nfunction sectionFrom(raw: unknown): SectionRule {\n if (typeof raw === 'string') return section(raw);\n const r = raw as Raw;\n return section(r['name'] as string, {\n aliases: (r['aliases'] as string[] | undefined) ?? [],\n mustContain: (r['mustContain'] as string[] | undefined) ?? [],\n checklist: (r['checklist'] as boolean | undefined) ?? false,\n optional: (r['optional'] as boolean | undefined) ?? false,\n });\n}\n\nfunction pluginFrom(raw: unknown): PluginReference {\n if (typeof raw === 'string') return { module: raw, options: undefined };\n const r = raw as Raw;\n return { module: r['module'] as string, options: r['options'] };\n}\n\nexport class ConfigError extends Error {\n readonly problems: readonly string[];\n\n constructor(file: string, problems: readonly string[]) {\n super(`${file}: ${problems.join('; ')}`);\n this.name = 'ConfigError';\n this.problems = problems;\n }\n}\n\n/**\n * Builds a configuration from parsed JSON. Objects merge one level deep over\n * the defaults; lists and `types` replace them, because a repository that\n * names its own sections means those sections and not the defaults as well.\n */\nexport function resolveConfig(raw: unknown, file = 'configuration'): Config {\n const problems = validate(CONFIG_SCHEMA, raw);\n if (problems.length > 0) throw new ConfigError(file, problems);\n const r = raw as Raw;\n const d = DEFAULT_CONFIG;\n const merged = <T extends object>(key: string, base: T): T => ({ ...base, ...((r[key] as Partial<T>) ?? {}) });\n const archiving = merged('archiving', d.archiving);\n const config: Config = {\n briefs: (r['briefs'] as string | undefined) ?? d.briefs,\n archive: (r['archive'] as string | undefined) ?? (r['briefs'] === undefined ? d.archive : `${r['briefs'] as string}/archive`),\n files: (r['files'] as string | undefined) ?? d.files,\n exclude: (r['exclude'] as string[] | undefined) ?? d.exclude,\n template: r['template'] === undefined ? d.template : (r['template'] as string | null),\n id: merged('id', d.id),\n status: merged('status', d.status),\n sections: r['sections'] === undefined ? d.sections : (r['sections'] as unknown[]).map(sectionFrom),\n sectionOrder: (r['sectionOrder'] as boolean | undefined) ?? d.sectionOrder,\n types:\n r['types'] === undefined\n ? d.types\n : Object.fromEntries(\n Object.entries(r['types'] as Record<string, Raw>).map(([name, type]) => [\n name,\n ((type['sections'] as unknown[] | undefined) ?? []).map(sectionFrom),\n ]),\n ),\n placeholders: (r['placeholders'] as string[] | undefined) ?? d.placeholders,\n fields: (r['fields'] as string[] | undefined) ?? d.fields,\n archiving,\n rules: { ...d.rules, ...((r['rules'] as Record<string, SeveritySetting> | undefined) ?? {}) },\n plugins: ((r['plugins'] as unknown[] | undefined) ?? []).map(pluginFrom),\n };\n const semantic = checkConfig(config);\n if (semantic.length > 0) throw new ConfigError(file, semantic);\n return config;\n}\n\n/** What the schema cannot say: relationships between values. */\nfunction checkConfig(config: Config): string[] {\n const problems: string[] = [];\n const inside = (key: string, path: string): string | null => {\n try {\n return normalisePath(path);\n } catch {\n problems.push(`\"${key}\" must be a directory inside the repository, not \"${path}\"`);\n return null;\n }\n };\n const briefs = inside('briefs', config.briefs);\n const archive = inside('archive', config.archive);\n if (briefs !== null && briefs === archive) problems.push('\"briefs\" and \"archive\" must be different directories');\n const words = [config.status.draft, config.status.active, config.status.archived].filter((w) => w !== null);\n if (new Set(words.map((w) => w.toLowerCase())).size !== words.length) {\n problems.push('the status words for draft, active and archived must differ');\n }\n // A pattern that does not parse would match nothing, and a run over no briefs reads as clean.\n for (const [key, pattern] of [['files', config.files], ...config.exclude.map((e) => ['exclude', e] as const)] as const) {\n const parsed = parseGlob(pattern);\n if (!parsed.ok) problems.push(`\"${key}\" pattern \"${pattern}\": ${parsed.error}`);\n }\n // An unknown hole is never filled, and a line with an unfilled hole is left\n // out: a misspelt placeholder would silently drop its whole line.\n for (const line of config.archiving.banner) {\n for (const hole of templateHoles(line)) {\n if (!BANNER_PLACEHOLDERS.includes(hole)) {\n problems.push(`\"archiving.banner\" uses {${hole}}; the placeholders are ${BANNER_PLACEHOLDERS.map((p) => `{${p}}`).join(', ')}`);\n }\n }\n }\n return problems;\n}\n\n/** Parses the text of a configuration file. */\nexport function parseConfig(text: string, file: string): Config {\n let raw: unknown;\n try {\n raw = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);\n } catch (error) {\n throw new ConfigError(file, [`is not valid JSON (${(error as Error).message})`]);\n }\n return resolveConfig(raw, file);\n}\n\n/**\n * The configuration file for a directory: the nearest one at or above it.\n * `exists` is injected so discovery needs no filesystem of its own.\n */\nexport async function locateConfig(\n start: string,\n exists: (path: string) => Promise<boolean>,\n): Promise<string | undefined> {\n let directory = start;\n // Bounded by the depth of the path: each pass moves one directory up.\n for (let depth = 0; depth < 256; depth += 1) {\n const found: string[] = [];\n for (const name of CONFIG_FILES) {\n const candidate = join(directory, name);\n if (await exists(candidate)) found.push(candidate);\n }\n if (found.length > 1) {\n throw new ConfigError(directory, [`holds both ${CONFIG_FILES.join(' and ')}; keep one`]);\n }\n if (found[0] !== undefined) return found[0];\n const parent = dirname(directory);\n if (parent === directory) return undefined;\n directory = parent;\n }\n /* v8 ignore next -- no path is 256 directories deep; the bound exists so the loop ends by construction. */\n return undefined;\n}\n\n/** The JSON Schema published as `schema.json`. */\nexport function configJsonSchema(): Record<string, unknown> {\n return {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n $id: SCHEMA_URL,\n title: 'spec-brief configuration',\n ...toJsonSchema(CONFIG_SCHEMA),\n };\n}\n\n/** The configuration `init` writes: every default spelled out, so it can be edited rather than looked up. */\nexport function initialConfig(briefs: string, archive: string): Record<string, unknown> {\n const d = DEFAULT_CONFIG;\n const sectionJson = (s: SectionRule): unknown => {\n const out: Record<string, unknown> = { name: s.name };\n if (s.aliases.length > 0) out['aliases'] = s.aliases;\n if (s.mustContain.length > 0) out['mustContain'] = s.mustContain;\n if (s.checklist) out['checklist'] = true;\n if (s.optional) out['optional'] = true;\n return Object.keys(out).length === 1 ? s.name : out;\n };\n return {\n $schema: SCHEMA_URL,\n briefs,\n archive,\n files: d.files,\n id: d.id,\n status: d.status,\n sections: d.sections.map(sectionJson),\n types: Object.fromEntries(Object.entries(d.types).map(([k, v]) => [k, { sections: v.map(sectionJson) }])),\n archiving: {\n tasks: d.archiving.tasks,\n dispositions: d.archiving.dispositions,\n banner: d.archiving.banner,\n base: d.archiving.base,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAe,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAkEnD,MAAM,CAAC,MAAM,YAAY,GAAsB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;AAEvF,uCAAuC;AACvC,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,MAAM;IACN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GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;QACzG,SAAS,EAAE;YACT,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK;YACxB,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,YAAY;YACtC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM;YAC1B,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI;SACvB;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Configuration: what it may say, what it says when it says nothing, and how a\n * file becomes a `Config`.\n *\n * Every repository that already keeps briefs keeps them its own way - where\n * they live, what the sections are called, which word means \"done\" - so the\n * conventions are data here rather than code. The defaults describe a brief\n * with the four parts every round needs: an intent, a negative scope, what the\n * round is not empowered to touch, and the invariants that prove it is done.\n *\n * A configuration that does not load stops the run. A typo that silently\n * falls back to defaults produces a clean-looking report about the wrong\n * rules, which is worse than no report.\n */\n\nimport { dirname, join } from 'node:path';\n\nimport { parseGlob } from './glob.js';\nimport { normalisePath } from './links.js';\nimport { type Schema, toJsonSchema, validate } from './schema.js';\nimport { inWords, templateHoles } from './text.js';\nimport type { SeveritySetting } from './types.js';\n\nexport interface SectionRule {\n readonly name: string;\n readonly aliases: readonly string[];\n /** Literal text the section must contain, compared exactly. */\n readonly mustContain: readonly string[];\n /** The section must hold at least one task item. */\n readonly checklist: boolean;\n readonly optional: boolean;\n /**\n * What the section must answer. A new brief carries it as a comment under\n * the heading, a finding that the section is missing or unwritten carries it\n * as its hint, and `list` and `lint` report it, so a tool that helps write a\n * brief can ask for each section without knowing its name in advance.\n */\n readonly hint?: string | undefined;\n}\n\nexport interface PluginReference {\n readonly module: string;\n readonly options: unknown;\n}\n\nexport interface Config {\n /** Directory of live briefs, relative to the root. */\n readonly briefs: string;\n /** Directory of archived briefs, relative to the root. */\n readonly archive: string;\n /** Glob a file name must match to be a brief. */\n readonly files: string;\n /** File-name globs that are never briefs, such as an index. */\n readonly exclude: readonly string[];\n /** A template for `new`, relative to the root; `null` builds one from `sections`. */\n readonly template: string | null;\n readonly id: {\n readonly source: 'filename' | 'frontmatter';\n readonly separator: string;\n readonly digits: number;\n };\n readonly status: {\n readonly field: string | null;\n readonly draft: string | null;\n readonly active: string;\n /** The word for work put off until an event its `trigger` names; `null` when a repository has none. */\n readonly deferred: string | null;\n readonly archived: string;\n };\n readonly sections: readonly SectionRule[];\n readonly sectionOrder: boolean;\n readonly types: Readonly<Record<string, readonly SectionRule[]>>;\n readonly placeholders: readonly string[];\n readonly fields: readonly string[];\n readonly archiving: {\n readonly tasks: 'all' | readonly string[];\n readonly dispositions: readonly string[];\n readonly banner: readonly string[];\n readonly rewriteLinks: boolean;\n readonly freeze: boolean;\n readonly base: string | null;\n };\n readonly rules: Readonly<Record<string, SeveritySetting>>;\n readonly plugins: readonly PluginReference[];\n}\n\nexport const CONFIG_FILES: readonly string[] = ['.spec-brief.json', 'spec-brief.json'];\n\n/** The holes a banner line may use. */\nexport const BANNER_PLACEHOLDERS: readonly string[] = [\n 'date',\n 'summary',\n 'pr',\n 'commit',\n 'diffstat',\n 'links',\n 'id',\n 'title',\n 'author',\n];\n\nexport const SCHEMA_URL = 'https://raw.githubusercontent.com/DescentVTT/spec-brief/main/schema.json';\n\nconst SEVERITY: Schema = { type: 'string', enum: ['off', 'note', 'warning', 'error'] };\nconst STRINGS: Schema = { type: 'array', items: { type: 'string', minLength: 1 } };\n\nconst SECTION: Schema = {\n type: 'anyOf',\n description: 'A section name, or a section with aliases and content rules.',\n options: [\n { type: 'string', minLength: 1 },\n {\n type: 'object',\n required: ['name'],\n properties: {\n name: { type: 'string', minLength: 1, description: 'The heading text, compared without case or punctuation.' },\n aliases: { ...STRINGS, description: 'Other headings that fill this section.' },\n mustContain: { ...STRINGS, description: 'Literal text the section must contain.' },\n checklist: { type: 'boolean', description: 'The section must hold at least one \"- [ ]\" task item.' },\n optional: { type: 'boolean', description: 'Checked when present, not required.' },\n hint: {\n type: 'string',\n minLength: 1,\n description: 'What the section must answer: a comment under the heading in a new brief, and the hint of a finding that it is missing or unwritten.',\n },\n },\n },\n ],\n};\n\nexport const CONFIG_SCHEMA: Schema = {\n type: 'object',\n properties: {\n $schema: { type: 'string' },\n briefs: { type: 'string', minLength: 1, description: 'Directory of live briefs, relative to this file.' },\n archive: { type: 'string', minLength: 1, description: 'Directory of archived briefs, relative to this file.' },\n files: { type: 'string', minLength: 1, description: 'Glob a file name must match to be a brief.' },\n exclude: { ...STRINGS, description: 'File-name globs that are never briefs.' },\n template: { type: 'string', nullable: true, description: 'Template file for \"new\"; null builds one from the sections.' },\n id: {\n type: 'object',\n properties: {\n source: { type: 'string', enum: ['filename', 'frontmatter'], description: 'Where a brief id comes from.' },\n separator: { type: 'string', minLength: 1, description: 'Separates the id from the slug in a file name.' },\n digits: { type: 'integer', minimum: 1, maximum: 12, description: 'Width of an allocated numeric id.' },\n },\n },\n status: {\n type: 'object',\n properties: {\n field: { type: 'string', nullable: true, description: 'Front-matter key holding the status; null uses location only.' },\n draft: { type: 'string', nullable: true, description: 'The word for a brief still being written, or null.' },\n active: { type: 'string', minLength: 1, description: 'The word for a live brief.' },\n deferred: {\n type: 'string',\n nullable: true,\n description: 'The word for a live brief put off until the event its \"trigger\" names, or null. A deferred brief is never ready and runs in no wave.',\n },\n archived: { type: 'string', minLength: 1, description: 'The word for an archived brief.' },\n },\n },\n sections: { type: 'array', items: SECTION, description: 'Sections every live brief carries.' },\n sectionOrder: { type: 'boolean', description: 'Sections must appear in the order listed.' },\n types: {\n type: 'map',\n description: 'Brief types, each with the sections it adds.',\n values: { type: 'object', properties: { sections: { type: 'array', items: SECTION } } },\n },\n placeholders: { ...STRINGS, description: 'Words that mark a section as unwritten.' },\n fields: { ...STRINGS, description: 'Front-matter keys this repository uses beyond the built-in ones.' },\n archiving: {\n type: 'object',\n properties: {\n tasks: {\n type: 'anyOf',\n description: '\"all\", or the sections whose task items must be closed before archiving.',\n options: [{ type: 'string', enum: ['all'] }, STRINGS],\n },\n dispositions: { ...STRINGS, description: 'Text under an open box that closes it without a tick.' },\n banner: {\n type: 'array',\n items: { type: 'string' },\n description: 'Lines of the frozen banner; a line with an empty {placeholder} is left out, and an empty line separates paragraphs.',\n },\n rewriteLinks: { type: 'boolean', description: 'Rewrite relative links so they resolve from the new directory.' },\n freeze: { type: 'boolean', description: 'Record a content hash so later edits are caught.' },\n base: { type: 'string', nullable: true, description: 'Branch the diff is measured from, such as \"main\".' },\n },\n },\n rules: { type: 'map', values: SEVERITY, description: 'Severity per rule id.' },\n plugins: {\n type: 'array',\n description: 'Modules that contribute rules.',\n items: {\n type: 'anyOf',\n options: [\n { type: 'string', minLength: 1 },\n {\n type: 'object',\n required: ['module'],\n properties: { module: { type: 'string', minLength: 1 }, options: { type: 'any' } },\n },\n ],\n },\n },\n },\n};\n\nfunction section(name: string, extra: Partial<Omit<SectionRule, 'name'>> = {}): SectionRule {\n return { name, aliases: [], mustContain: [], checklist: false, optional: false, ...extra };\n}\n\nexport const DEFAULT_CONFIG: Config = {\n briefs: 'briefs',\n archive: 'briefs/archive',\n files: '[0-9]*.md',\n exclude: [],\n template: null,\n id: { source: 'filename', separator: '_', digits: 3 },\n status: { field: 'status', draft: 'draft', active: 'active', deferred: 'deferred', archived: 'archived' },\n sections: [\n section('Intent', {\n aliases: [\"Commander's Intent\", 'Mission', 'Objective'],\n hint: 'The state of the tree when this round is done, and why it matters. One paragraph.',\n }),\n section('Negative Scope', {\n aliases: ['Out of Scope', 'Non-Goals', 'Not in Scope', 'What this round is NOT', 'What this brief does NOT do'],\n hint: 'What this round must not do, even where it would look helpful.',\n }),\n section('Not Empowered', {\n aliases: ['Non-Empowerment', 'Non-Empowerment List'],\n optional: true,\n hint: 'Files, interfaces and decisions this round may not change.',\n }),\n section('Invariants', {\n aliases: ['Invariant Checklist', 'Definition of Done'],\n checklist: true,\n hint: 'Checks that must hold before the round is called done, each one a task item.',\n }),\n ],\n sectionOrder: false,\n types: {\n feature: [section('Acceptance Criteria', { checklist: true, hint: 'What a reviewer checks to accept the result, each one a task item.' })],\n defect: [\n section('The Defect, Measured', {\n aliases: ['Reproduction'],\n hint: 'How to reproduce the defect, and the measurement that shows it.',\n }),\n ],\n refactor: [],\n chore: [],\n },\n placeholders: ['TBD', 'TBA', 'TODO', 'FIXME', 'XXX', '???', '...', '\\u2026'],\n fields: [],\n archiving: {\n tasks: 'all',\n dispositions: ['**Delegated', '**Accepted debt', '**Rejected'],\n banner: [\n '**Archived {date}.**',\n '{summary}',\n 'Merged in pull request {pr}.',\n 'Recorded at commit `{commit}`: {diffstat}.',\n '{links}',\n 'The body below describes the tree before execution and is not maintained.',\n ],\n rewriteLinks: true,\n freeze: true,\n base: null,\n },\n rules: {},\n plugins: [],\n};\n\ntype Raw = Record<string, unknown>;\n\nfunction sectionFrom(raw: unknown): SectionRule {\n if (typeof raw === 'string') return section(raw);\n const r = raw as Raw;\n return section(r['name'] as string, {\n aliases: (r['aliases'] as string[] | undefined) ?? [],\n mustContain: (r['mustContain'] as string[] | undefined) ?? [],\n checklist: (r['checklist'] as boolean | undefined) ?? false,\n optional: (r['optional'] as boolean | undefined) ?? false,\n hint: r['hint'] as string | undefined,\n });\n}\n\nfunction pluginFrom(raw: unknown): PluginReference {\n if (typeof raw === 'string') return { module: raw, options: undefined };\n const r = raw as Raw;\n return { module: r['module'] as string, options: r['options'] };\n}\n\nexport class ConfigError extends Error {\n readonly problems: readonly string[];\n\n constructor(file: string, problems: readonly string[]) {\n super(`${file}: ${problems.join('; ')}`);\n this.name = 'ConfigError';\n this.problems = problems;\n }\n}\n\n/**\n * Builds a configuration from parsed JSON. Objects merge one level deep over\n * the defaults; lists and `types` replace them, because a repository that\n * names its own sections means those sections and not the defaults as well.\n */\nexport function resolveConfig(raw: unknown, file = 'configuration'): Config {\n const problems = validate(CONFIG_SCHEMA, raw);\n if (problems.length > 0) throw new ConfigError(file, problems);\n const r = raw as Raw;\n const d = DEFAULT_CONFIG;\n const merged = <T extends object>(key: string, base: T): T => ({ ...base, ...((r[key] as Partial<T>) ?? {}) });\n const archiving = merged('archiving', d.archiving);\n const config: Config = {\n briefs: (r['briefs'] as string | undefined) ?? d.briefs,\n archive: (r['archive'] as string | undefined) ?? (r['briefs'] === undefined ? d.archive : `${r['briefs'] as string}/archive`),\n files: (r['files'] as string | undefined) ?? d.files,\n exclude: (r['exclude'] as string[] | undefined) ?? d.exclude,\n template: r['template'] === undefined ? d.template : (r['template'] as string | null),\n id: merged('id', d.id),\n status: merged('status', d.status),\n sections: r['sections'] === undefined ? d.sections : (r['sections'] as unknown[]).map(sectionFrom),\n sectionOrder: (r['sectionOrder'] as boolean | undefined) ?? d.sectionOrder,\n types:\n r['types'] === undefined\n ? d.types\n : Object.fromEntries(\n Object.entries(r['types'] as Record<string, Raw>).map(([name, type]) => [\n name,\n ((type['sections'] as unknown[] | undefined) ?? []).map(sectionFrom),\n ]),\n ),\n placeholders: (r['placeholders'] as string[] | undefined) ?? d.placeholders,\n fields: (r['fields'] as string[] | undefined) ?? d.fields,\n archiving,\n rules: { ...d.rules, ...((r['rules'] as Record<string, SeveritySetting> | undefined) ?? {}) },\n plugins: ((r['plugins'] as unknown[] | undefined) ?? []).map(pluginFrom),\n };\n const semantic = checkConfig(config);\n if (semantic.length > 0) throw new ConfigError(file, semantic);\n return config;\n}\n\n/** The status words a repository uses, in lifecycle order. */\nexport function statusWords(config: Config): string[] {\n const { draft, active, deferred, archived } = config.status;\n return [draft, active, deferred, archived].filter((w) => w !== null);\n}\n\n/** What the schema cannot say: relationships between values. */\nfunction checkConfig(config: Config): string[] {\n const problems: string[] = [];\n const inside = (key: string, path: string): string | null => {\n try {\n return normalisePath(path);\n } catch {\n problems.push(`\"${key}\" must be a directory inside the repository, not \"${path}\"`);\n return null;\n }\n };\n const briefs = inside('briefs', config.briefs);\n const archive = inside('archive', config.archive);\n if (briefs !== null && briefs === archive) problems.push('\"briefs\" and \"archive\" must be different directories');\n // Named by the statuses that share a word: a 0.1 configuration that spelt\n // another status \"deferred\" meets the default for the new one here.\n const sharing = new Map<string, { word: string; keys: string[] }>();\n for (const key of ['draft', 'active', 'deferred', 'archived'] as const) {\n const word = config.status[key];\n if (word === null) continue;\n const group = sharing.get(word.toLowerCase()) ?? { word, keys: [] };\n group.keys.push(key);\n sharing.set(word.toLowerCase(), group);\n }\n for (const { word, keys } of sharing.values()) {\n if (keys.length < 2) continue;\n const orNull = keys.includes('deferred') ? ', or set \"status.deferred\" to null where no work is deferred' : '';\n problems.push(`the status words must differ: \"${word}\" is the word for ${inWords(keys)}; give ${keys.length === 2 ? 'one of them' : 'all but one'} another word${orNull}`);\n }\n // A pattern that does not parse would match nothing, and a run over no briefs reads as clean.\n for (const [key, pattern] of [['files', config.files], ...config.exclude.map((e) => ['exclude', e] as const)] as const) {\n const parsed = parseGlob(pattern);\n if (!parsed.ok) problems.push(`\"${key}\" pattern \"${pattern}\": ${parsed.error}`);\n }\n // An unknown hole is never filled, and a line with an unfilled hole is left\n // out: a misspelt placeholder would silently drop its whole line.\n for (const line of config.archiving.banner) {\n for (const hole of templateHoles(line)) {\n if (!BANNER_PLACEHOLDERS.includes(hole)) {\n problems.push(`\"archiving.banner\" uses {${hole}}; the placeholders are ${BANNER_PLACEHOLDERS.map((p) => `{${p}}`).join(', ')}`);\n }\n }\n }\n return problems;\n}\n\n/** Parses the text of a configuration file. */\nexport function parseConfig(text: string, file: string): Config {\n let raw: unknown;\n try {\n raw = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);\n } catch (error) {\n throw new ConfigError(file, [`is not valid JSON (${(error as Error).message})`]);\n }\n return resolveConfig(raw, file);\n}\n\n/**\n * The configuration file for a directory: the nearest one at or above it.\n * `exists` is injected so discovery needs no filesystem of its own.\n */\nexport async function locateConfig(\n start: string,\n exists: (path: string) => Promise<boolean>,\n): Promise<string | undefined> {\n let directory = start;\n // Bounded by the depth of the path: each pass moves one directory up.\n for (let depth = 0; depth < 256; depth += 1) {\n const found: string[] = [];\n for (const name of CONFIG_FILES) {\n const candidate = join(directory, name);\n if (await exists(candidate)) found.push(candidate);\n }\n if (found.length > 1) {\n throw new ConfigError(directory, [`holds both ${CONFIG_FILES.join(' and ')}; keep one`]);\n }\n if (found[0] !== undefined) return found[0];\n const parent = dirname(directory);\n if (parent === directory) return undefined;\n directory = parent;\n }\n /* v8 ignore next -- no path is 256 directories deep; the bound exists so the loop ends by construction. */\n return undefined;\n}\n\n/** The JSON Schema published as `schema.json`. */\nexport function configJsonSchema(): Record<string, unknown> {\n return {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n $id: SCHEMA_URL,\n title: 'spec-brief configuration',\n ...toJsonSchema(CONFIG_SCHEMA),\n };\n}\n\n/** The configuration `init` writes: every default spelled out, so it can be edited rather than looked up. */\nexport function initialConfig(briefs: string, archive: string): Record<string, unknown> {\n const d = DEFAULT_CONFIG;\n const sectionJson = (s: SectionRule): unknown => {\n const out: Record<string, unknown> = { name: s.name };\n if (s.aliases.length > 0) out['aliases'] = s.aliases;\n if (s.mustContain.length > 0) out['mustContain'] = s.mustContain;\n if (s.checklist) out['checklist'] = true;\n if (s.optional) out['optional'] = true;\n if (s.hint !== undefined) out['hint'] = s.hint;\n return Object.keys(out).length === 1 ? s.name : out;\n };\n return {\n $schema: SCHEMA_URL,\n briefs,\n archive,\n files: d.files,\n id: d.id,\n status: d.status,\n sections: d.sections.map(sectionJson),\n types: Object.fromEntries(Object.entries(d.types).map(([k, v]) => [k, { sections: v.map(sectionJson) }])),\n archiving: {\n tasks: d.archiving.tasks,\n dispositions: d.archiving.dispositions,\n banner: d.archiving.banner,\n base: d.archiving.base,\n },\n };\n}\n"]}
|