@seasb/metafab 1.0.0 → 2.0.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/README.md +28 -4
- package/dist/cli.js +118 -16
- package/dist/cli.js.map +1 -1
- package/dist/commands/build.d.ts +29 -0
- package/dist/commands/build.js +111 -25
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.js +13 -2
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/create.js +1 -0
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/env.d.ts +4 -0
- package/dist/commands/env.js +362 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/map.js +1 -2
- package/dist/commands/map.js.map +1 -1
- package/dist/commands/pipeline-add.js +1 -0
- package/dist/commands/pipeline-add.js.map +1 -1
- package/dist/commands/pipeline-remove.js +1 -0
- package/dist/commands/pipeline-remove.js.map +1 -1
- package/dist/commands/publish.js +8 -2
- package/dist/commands/publish.js.map +1 -1
- package/dist/core/build/agents.d.ts +7 -4
- package/dist/core/build/agents.js +16 -9
- package/dist/core/build/agents.js.map +1 -1
- package/dist/core/build/index.d.ts +1 -0
- package/dist/core/build/index.js +1 -0
- package/dist/core/build/index.js.map +1 -1
- package/dist/core/build/plan.d.ts +35 -1
- package/dist/core/build/plan.js +156 -36
- package/dist/core/build/plan.js.map +1 -1
- package/dist/core/build/preview.d.ts +39 -0
- package/dist/core/build/preview.js +344 -0
- package/dist/core/build/preview.js.map +1 -0
- package/dist/core/build/skill.d.ts +39 -0
- package/dist/core/build/skill.js +120 -41
- package/dist/core/build/skill.js.map +1 -1
- package/dist/core/check/index.d.ts +5 -1
- package/dist/core/check/index.js +8 -2
- package/dist/core/check/index.js.map +1 -1
- package/dist/core/config/parse.js +3 -0
- package/dist/core/config/parse.js.map +1 -1
- package/dist/core/config/source.d.ts +11 -0
- package/dist/core/config/source.js +23 -0
- package/dist/core/config/source.js.map +1 -1
- package/dist/core/config/validate.js +75 -37
- package/dist/core/config/validate.js.map +1 -1
- package/dist/core/config/writers.js +9 -1
- package/dist/core/config/writers.js.map +1 -1
- package/dist/core/edit/create.js +1 -1
- package/dist/core/edit/create.js.map +1 -1
- package/dist/core/edit/factory-yaml.js +4 -2
- package/dist/core/edit/factory-yaml.js.map +1 -1
- package/dist/core/edit/paths.js +8 -3
- package/dist/core/edit/paths.js.map +1 -1
- package/dist/core/edit/pipeline.js +12 -6
- package/dist/core/edit/pipeline.js.map +1 -1
- package/dist/core/env/condition.d.ts +40 -0
- package/dist/core/env/condition.js +283 -0
- package/dist/core/env/condition.js.map +1 -0
- package/dist/core/env/declarations.d.ts +16 -0
- package/dist/core/env/declarations.js +328 -0
- package/dist/core/env/declarations.js.map +1 -0
- package/dist/core/env/directives.d.ts +75 -0
- package/dist/core/env/directives.js +429 -0
- package/dist/core/env/directives.js.map +1 -0
- package/dist/core/env/git-config.d.ts +15 -0
- package/dist/core/env/git-config.js +110 -0
- package/dist/core/env/git-config.js.map +1 -0
- package/dist/core/env/imports.d.ts +60 -0
- package/dist/core/env/imports.js +217 -0
- package/dist/core/env/imports.js.map +1 -0
- package/dist/core/env/index.d.ts +6 -0
- package/dist/core/env/index.js +7 -0
- package/dist/core/env/index.js.map +1 -0
- package/dist/core/env/markdown.d.ts +22 -0
- package/dist/core/env/markdown.js +33 -0
- package/dist/core/env/markdown.js.map +1 -0
- package/dist/core/env/render.d.ts +13 -0
- package/dist/core/env/render.js +65 -0
- package/dist/core/env/render.js.map +1 -0
- package/dist/core/env/report.d.ts +29 -0
- package/dist/core/env/report.js +39 -0
- package/dist/core/env/report.js.map +1 -0
- package/dist/core/env/scenarios.d.ts +40 -0
- package/dist/core/env/scenarios.js +124 -0
- package/dist/core/env/scenarios.js.map +1 -0
- package/dist/core/env/select.d.ts +30 -0
- package/dist/core/env/select.js +191 -0
- package/dist/core/env/select.js.map +1 -0
- package/dist/core/env/types.d.ts +38 -0
- package/dist/core/env/types.js +2 -0
- package/dist/core/env/types.js.map +1 -0
- package/dist/core/env/validate.d.ts +25 -0
- package/dist/core/env/validate.js +212 -0
- package/dist/core/env/validate.js.map +1 -0
- package/dist/core/factory/factory-yaml.d.ts +14 -1
- package/dist/core/factory/factory-yaml.js +166 -3
- package/dist/core/factory/factory-yaml.js.map +1 -1
- package/dist/core/factory/load.js +2 -0
- package/dist/core/factory/load.js.map +1 -1
- package/dist/core/factory/types.d.ts +14 -1
- package/dist/core/factory/validate.d.ts +5 -2
- package/dist/core/factory/validate.js +31 -12
- package/dist/core/factory/validate.js.map +1 -1
- package/dist/core/hooks/script.js +24 -2
- package/dist/core/hooks/script.js.map +1 -1
- package/dist/core/import/run.js +17 -0
- package/dist/core/import/run.js.map +1 -1
- package/dist/core/publish/git-target.js +35 -22
- package/dist/core/publish/git-target.js.map +1 -1
- package/dist/core/publish/npm-target.js +11 -4
- package/dist/core/publish/npm-target.js.map +1 -1
- package/dist/core/publish/package-json.d.ts +1 -1
- package/dist/core/publish/prepare.d.ts +11 -0
- package/dist/core/publish/prepare.js +11 -2
- package/dist/core/publish/prepare.js.map +1 -1
- package/dist/core/publish/publish.js +15 -2
- package/dist/core/publish/publish.js.map +1 -1
- package/dist/core/publish/readme.js +1 -4
- package/dist/core/publish/readme.js.map +1 -1
- package/dist/core/sources/cache.js +108 -44
- package/dist/core/sources/cache.js.map +1 -1
- package/dist/core/sources/extract.js +35 -72
- package/dist/core/sources/extract.js.map +1 -1
- package/dist/core/sources/git.js +48 -34
- package/dist/core/sources/git.js.map +1 -1
- package/dist/core/sources/https.js +23 -13
- package/dist/core/sources/https.js.map +1 -1
- package/dist/core/sources/npm-cli.js +8 -0
- package/dist/core/sources/npm-cli.js.map +1 -1
- package/dist/core/sources/npm.js +59 -34
- package/dist/core/sources/npm.js.map +1 -1
- package/dist/core/sources/parse.d.ts +20 -6
- package/dist/core/sources/parse.js +75 -18
- package/dist/core/sources/parse.js.map +1 -1
- package/dist/core/sources/path.js +24 -9
- package/dist/core/sources/path.js.map +1 -1
- package/dist/core/sources/problems.d.ts +29 -0
- package/dist/core/sources/problems.js +36 -0
- package/dist/core/sources/problems.js.map +1 -0
- package/dist/core/sources/types.d.ts +1 -1
- package/dist/core/sources/validate.js +18 -13
- package/dist/core/sources/validate.js.map +1 -1
- package/dist/core/summary.d.ts +5 -3
- package/dist/core/summary.js +8 -2
- package/dist/core/summary.js.map +1 -1
- package/dist/core/update/run.js +15 -12
- package/dist/core/update/run.js.map +1 -1
- package/dist/errors.d.ts +14 -4
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/help.d.ts +7 -2
- package/dist/help.js +16 -2
- package/dist/help.js.map +1 -1
- package/dist/input.js +1 -0
- package/dist/input.js.map +1 -1
- package/dist/output.d.ts +1 -1
- package/dist/util/fs.d.ts +6 -0
- package/dist/util/fs.js +9 -0
- package/dist/util/fs.js.map +1 -1
- package/dist/util/yaml.d.ts +1 -1
- package/package.json +2 -1
- package/resources/metafab-skill/SKILL.md +76 -2
- package/dist/commands/not-implemented.d.ts +0 -2
- package/dist/commands/not-implemented.js +0 -19
- package/dist/commands/not-implemented.js.map +0 -1
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { didYouMean } from "../../util/suggest.js";
|
|
4
|
+
import { isNameFormatted } from "../factory/validate.js";
|
|
5
|
+
import { CONDITION_FIX, conditionFix, conditionProblems, conditionVariables, parseCondition, } from "./condition.js";
|
|
6
|
+
import { isVariableName } from "./declarations.js";
|
|
7
|
+
import { importTarget, realDisplayPath, resolveImport } from "./imports.js";
|
|
8
|
+
import { MAX_COMBINATIONS, combinations } from "./scenarios.js";
|
|
9
|
+
const DIRECTIVE_PATTERN = /^[ \t]*<!--[ \t]*factory:([A-Za-z0-9_-]*)(?:[ \t]+(.*?))?[ \t]*-->[ \t]*$/;
|
|
10
|
+
const FENCE_OPEN_PATTERN = /^[ \t]*(`{3,}|~{3,})/;
|
|
11
|
+
const DIRECTIVE_NAMES = [
|
|
12
|
+
"when",
|
|
13
|
+
"endwhen",
|
|
14
|
+
"switch",
|
|
15
|
+
"case",
|
|
16
|
+
"default",
|
|
17
|
+
"endswitch",
|
|
18
|
+
"import",
|
|
19
|
+
];
|
|
20
|
+
const WHOLE_LINE_MESSAGE = "A factory: directive must be one whole line: <!-- factory:<name> <arguments> -->";
|
|
21
|
+
const WHOLE_LINE_FIX = "Write it on one line: <!-- factory:<name> <arguments> -->";
|
|
22
|
+
const ONLY_BLANK_MESSAGE = "Only blank lines may come between factory:switch and its first case";
|
|
23
|
+
const ONLY_BLANK_FIX = "Move the text into a case";
|
|
24
|
+
const LAST_BRANCH_MESSAGE = "factory:default must be the last branch of its switch";
|
|
25
|
+
const LAST_BRANCH_FIX = "Move the factory:default to the end of the switch";
|
|
26
|
+
const BRANCH_MESSAGE = "factory:<name> must be directly inside a factory:switch";
|
|
27
|
+
const CASE_VALUES_MESSAGE = "factory:case needs one or more value names separated by spaces";
|
|
28
|
+
const CASE_VALUES_FIX = "Write <!-- factory:case <value> [<value> ...] -->";
|
|
29
|
+
const CYCLE_FIX = "Remove one of these imports, so the chain does not lead back to itself";
|
|
30
|
+
function stripBom(line) {
|
|
31
|
+
return line.startsWith("\uFEFF") ? line.slice(1) : line;
|
|
32
|
+
}
|
|
33
|
+
function indentOf(line) {
|
|
34
|
+
return /^[ \t]*/.exec(line)?.[0] ?? "";
|
|
35
|
+
}
|
|
36
|
+
function matchDirective(line) {
|
|
37
|
+
const match = DIRECTIVE_PATTERN.exec(stripBom(line));
|
|
38
|
+
if (match === null)
|
|
39
|
+
return undefined;
|
|
40
|
+
const args = match[2]?.trim();
|
|
41
|
+
return { name: match[1] ?? "", args: args === "" ? undefined : args };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* True for a line that means to be a directive but is not one: a broken
|
|
45
|
+
* `<!-- factory:` comment, or a `factory:` line inside a comment that spans
|
|
46
|
+
* several lines.
|
|
47
|
+
*/
|
|
48
|
+
function looksLikeDirective(line) {
|
|
49
|
+
return /^[ \t]*(?:<!--[ \t]*)?factory:/.test(stripBom(line));
|
|
50
|
+
}
|
|
51
|
+
function opensFence(line) {
|
|
52
|
+
const match = FENCE_OPEN_PATTERN.exec(line);
|
|
53
|
+
if (match === null)
|
|
54
|
+
return undefined;
|
|
55
|
+
const run = match[1];
|
|
56
|
+
return { char: run[0], length: run.length };
|
|
57
|
+
}
|
|
58
|
+
function closesFence(line, fence) {
|
|
59
|
+
const text = line.trim();
|
|
60
|
+
return text.length >= fence.length && Array.from(text).every((char) => char === fence.char);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The realpaths being expanded, starting with this file. A top-level file passes
|
|
64
|
+
* an empty chain, so its own realpath is added here: an import that leads back
|
|
65
|
+
* to the file being parsed is a loop. A file that is not on disk cannot be
|
|
66
|
+
* imported back, so an empty chain is kept.
|
|
67
|
+
*/
|
|
68
|
+
async function importChain(imports, route, chain) {
|
|
69
|
+
if (chain.length > 0)
|
|
70
|
+
return chain;
|
|
71
|
+
try {
|
|
72
|
+
return [await realpath(path.resolve(imports.factoryDir, ...route.split("/")))];
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return chain;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Parses a Markdown file into text and directive nodes. Problems carry the file
|
|
80
|
+
* and line, and parsing continues after each one, so a run reports every
|
|
81
|
+
* problem in a file. An import line is replaced by the nodes of the imported
|
|
82
|
+
* file, parsed as its own document: block balance, switches and fences are per
|
|
83
|
+
* file.
|
|
84
|
+
*/
|
|
85
|
+
export async function parseMarkdown(text, options) {
|
|
86
|
+
const { file, firstLine, variables: declared, imports, route } = options;
|
|
87
|
+
const chain = await importChain(imports, route, options.chain ?? []);
|
|
88
|
+
// An empty file has no lines, so it contributes no nodes: an import of an
|
|
89
|
+
// empty or frontmatter-only partial inserts nothing, not a blank line.
|
|
90
|
+
const lines = text === "" ? [] : text.split("\n");
|
|
91
|
+
const nodes = [];
|
|
92
|
+
const problems = [];
|
|
93
|
+
const names = new Set();
|
|
94
|
+
const stack = [];
|
|
95
|
+
let fence;
|
|
96
|
+
const error = (line, message, fix) => {
|
|
97
|
+
problems.push({ level: "error", file, line, message, fix });
|
|
98
|
+
};
|
|
99
|
+
const enclosing = () => stack.at(-1)?.variables ?? new Set();
|
|
100
|
+
const checkCombinations = (line, named) => {
|
|
101
|
+
const count = combinations(named, declared);
|
|
102
|
+
if (count <= MAX_COMBINATIONS)
|
|
103
|
+
return;
|
|
104
|
+
error(line, `Condition spans too many combinations: ${count} over ${[...named].join(", ")}; the limit is ${MAX_COMBINATIONS}`, "Split the condition, or nest fewer conditions");
|
|
105
|
+
};
|
|
106
|
+
const append = (node) => {
|
|
107
|
+
const frame = stack.at(-1);
|
|
108
|
+
if (frame === undefined) {
|
|
109
|
+
nodes.push(node);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (frame.kind === "when") {
|
|
113
|
+
frame.node.children.push(node);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const branch = frame.node.branches.at(-1);
|
|
117
|
+
if (branch === undefined) {
|
|
118
|
+
error(node.line, ONLY_BLANK_MESSAGE, ONLY_BLANK_FIX);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
branch.children.push(node);
|
|
122
|
+
};
|
|
123
|
+
const appendText = (line, content, blankCheck = true) => {
|
|
124
|
+
const frame = stack.at(-1);
|
|
125
|
+
if (blankCheck && frame?.kind === "switch" && frame.node.branches.length === 0) {
|
|
126
|
+
if (content.trim() !== "")
|
|
127
|
+
error(line, ONLY_BLANK_MESSAGE, ONLY_BLANK_FIX);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
append({ kind: "text", line, text: content });
|
|
131
|
+
};
|
|
132
|
+
const openWhen = (directive, line, raw) => {
|
|
133
|
+
const text = directive.args ?? "";
|
|
134
|
+
if (text === "") {
|
|
135
|
+
error(line, "factory:when needs a condition", "Write <!-- factory:when env.<variable> == <value> -->");
|
|
136
|
+
appendText(line, raw, false);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const parsed = parseCondition(text);
|
|
140
|
+
if ("error" in parsed) {
|
|
141
|
+
error(line, `Cannot read condition "${text}": ${parsed.error}`, CONDITION_FIX);
|
|
142
|
+
appendText(line, raw, false);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
for (const message of conditionProblems(parsed.condition, declared)) {
|
|
146
|
+
error(line, message, conditionFix(parsed.condition, declared));
|
|
147
|
+
}
|
|
148
|
+
const own = conditionVariables(parsed.condition);
|
|
149
|
+
const named = new Set([...enclosing(), ...own]);
|
|
150
|
+
checkCombinations(line, named);
|
|
151
|
+
const node = {
|
|
152
|
+
kind: "when",
|
|
153
|
+
line,
|
|
154
|
+
indent: indentOf(raw),
|
|
155
|
+
condition: parsed.condition,
|
|
156
|
+
children: [],
|
|
157
|
+
endLine: line,
|
|
158
|
+
};
|
|
159
|
+
append(node);
|
|
160
|
+
stack.push({ kind: "when", node, variables: named });
|
|
161
|
+
for (const name of own)
|
|
162
|
+
names.add(name);
|
|
163
|
+
};
|
|
164
|
+
const openSwitch = (directive, line, raw) => {
|
|
165
|
+
const text = directive.args ?? "";
|
|
166
|
+
const match = /^env\.(.*)$/.exec(text);
|
|
167
|
+
if (match === null || !isVariableName(match[1])) {
|
|
168
|
+
error(line, "factory:switch needs env.<variable>", "Write <!-- factory:switch env.<variable> -->");
|
|
169
|
+
appendText(line, raw, false);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const variable = match[1];
|
|
173
|
+
if (!declared.some((entry) => entry.name === variable)) {
|
|
174
|
+
error(line, `factory:switch names unknown variable "${variable}"`, didYouMean(variable, declared.map((entry) => entry.name)) ??
|
|
175
|
+
`Use one of: ${declared.map((entry) => entry.name).join(", ")}`);
|
|
176
|
+
}
|
|
177
|
+
const named = new Set([...enclosing(), variable]);
|
|
178
|
+
checkCombinations(line, named);
|
|
179
|
+
const node = {
|
|
180
|
+
kind: "switch",
|
|
181
|
+
line,
|
|
182
|
+
indent: indentOf(raw),
|
|
183
|
+
variable,
|
|
184
|
+
branches: [],
|
|
185
|
+
endLine: line,
|
|
186
|
+
};
|
|
187
|
+
append(node);
|
|
188
|
+
stack.push({ kind: "switch", node, variables: named });
|
|
189
|
+
names.add(variable);
|
|
190
|
+
};
|
|
191
|
+
const openBranch = (directive, line, raw) => {
|
|
192
|
+
const frame = stack.at(-1);
|
|
193
|
+
if (frame === undefined || frame.kind !== "switch") {
|
|
194
|
+
error(line, BRANCH_MESSAGE.replace("<name>", directive.name), "Move the line inside a factory:switch, or remove it");
|
|
195
|
+
appendText(line, raw, false);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const node = frame.node;
|
|
199
|
+
const declaredVariable = declared.find((entry) => entry.name === node.variable);
|
|
200
|
+
if (directive.name === "default") {
|
|
201
|
+
if (directive.args !== undefined) {
|
|
202
|
+
error(line, "factory:default takes no arguments", `Remove "${directive.args}"`);
|
|
203
|
+
}
|
|
204
|
+
if (node.branches.some((branch) => branch.kind === "default")) {
|
|
205
|
+
error(line, LAST_BRANCH_MESSAGE, LAST_BRANCH_FIX);
|
|
206
|
+
}
|
|
207
|
+
node.branches.push({
|
|
208
|
+
kind: "default",
|
|
209
|
+
line,
|
|
210
|
+
indent: indentOf(raw),
|
|
211
|
+
values: [],
|
|
212
|
+
children: [],
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const given = (directive.args ?? "").split(/\s+/).filter((value) => value !== "");
|
|
217
|
+
const values = [];
|
|
218
|
+
let malformed = given.length === 0;
|
|
219
|
+
for (const value of given) {
|
|
220
|
+
if (isNameFormatted(value))
|
|
221
|
+
values.push(value);
|
|
222
|
+
else
|
|
223
|
+
malformed = true;
|
|
224
|
+
}
|
|
225
|
+
if (malformed)
|
|
226
|
+
error(line, CASE_VALUES_MESSAGE, CASE_VALUES_FIX);
|
|
227
|
+
if (node.branches.some((branch) => branch.kind === "default")) {
|
|
228
|
+
error(line, LAST_BRANCH_MESSAGE, LAST_BRANCH_FIX);
|
|
229
|
+
}
|
|
230
|
+
const previous = new Map();
|
|
231
|
+
for (const branch of node.branches) {
|
|
232
|
+
for (const value of branch.values)
|
|
233
|
+
previous.set(value, branch.line);
|
|
234
|
+
}
|
|
235
|
+
const declaredValues = declaredVariable?.values.map((value) => value.name);
|
|
236
|
+
const kept = [];
|
|
237
|
+
for (const value of values) {
|
|
238
|
+
const earlier = previous.get(value);
|
|
239
|
+
if (earlier !== undefined) {
|
|
240
|
+
error(line, `Value "${value}" already has a case on line ${earlier}`, "Remove it from one case");
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
previous.set(value, line);
|
|
244
|
+
kept.push(value);
|
|
245
|
+
if (declaredValues !== undefined && !declaredValues.includes(value)) {
|
|
246
|
+
error(line, `factory:case names unknown value "${value}" of ${node.variable}`, didYouMean(value, declaredValues) ?? `Use one of: ${declaredValues.join(", ")}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
node.branches.push({
|
|
250
|
+
kind: "case",
|
|
251
|
+
line,
|
|
252
|
+
indent: indentOf(raw),
|
|
253
|
+
values: kept,
|
|
254
|
+
children: [],
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
const closeBlock = (directive, line) => {
|
|
258
|
+
const frame = stack.at(-1);
|
|
259
|
+
const expected = directive.name === "endwhen" ? "when" : "switch";
|
|
260
|
+
if (frame === undefined) {
|
|
261
|
+
error(line, `factory:${directive.name} has no matching factory:${expected}`, "Remove the line");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (frame.kind !== expected) {
|
|
265
|
+
error(line, `factory:${directive.name} cannot close the factory:${frame.kind} on line ${frame.node.line}`, "Close the inner block first");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (directive.args !== undefined) {
|
|
269
|
+
error(line, `factory:${directive.name} takes no arguments`, `Remove "${directive.args}"`);
|
|
270
|
+
}
|
|
271
|
+
frame.node.endLine = line;
|
|
272
|
+
stack.pop();
|
|
273
|
+
if (frame.kind !== "switch")
|
|
274
|
+
return;
|
|
275
|
+
if (frame.node.branches.some((branch) => branch.kind === "default"))
|
|
276
|
+
return;
|
|
277
|
+
const declaredVariable = declared.find((entry) => entry.name === frame.node.variable);
|
|
278
|
+
if (declaredVariable === undefined)
|
|
279
|
+
return;
|
|
280
|
+
const named = new Set(frame.node.branches.flatMap((branch) => branch.values));
|
|
281
|
+
const missing = declaredVariable.values
|
|
282
|
+
.map((value) => value.name)
|
|
283
|
+
.filter((value) => !named.has(value));
|
|
284
|
+
if (missing.length === 0)
|
|
285
|
+
return;
|
|
286
|
+
error(frame.node.line, `factory:switch over env.${frame.node.variable} has no case for ${missing.join(", ")}`, "Add a case for each, or a factory:default");
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Expands one import line: the imported body is parsed as its own document and
|
|
290
|
+
* its nodes become the import node's children, so its blocks are balanced in
|
|
291
|
+
* its own file. A failed import, or one that closes a loop, is an error on
|
|
292
|
+
* this line and inserts nothing.
|
|
293
|
+
*/
|
|
294
|
+
const expandImport = async (argument, line) => {
|
|
295
|
+
const target = importTarget(route, argument);
|
|
296
|
+
if (!target.ok) {
|
|
297
|
+
error(line, target.message, target.fix);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const resolved = await resolveImport(route, argument, imports);
|
|
301
|
+
if (!resolved.ok) {
|
|
302
|
+
error(line, resolved.message, resolved.fix);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// The chain compares realpaths, so a loop through two names of one file is
|
|
306
|
+
// still a loop; the message names the files from the one that repeats.
|
|
307
|
+
const start = chain.indexOf(resolved.real);
|
|
308
|
+
if (start !== -1) {
|
|
309
|
+
const loop = [...chain.slice(start), resolved.real].map((real) => realDisplayPath(imports, real));
|
|
310
|
+
error(line, `Import cycle: ${loop.join(" → ")}`, CYCLE_FIX);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
problems.push(...resolved.loaded.problems);
|
|
314
|
+
const imported = await parseMarkdown(resolved.loaded.text, {
|
|
315
|
+
file: `.factory/${target.target}`,
|
|
316
|
+
firstLine: resolved.loaded.firstLine,
|
|
317
|
+
variables: declared,
|
|
318
|
+
imports,
|
|
319
|
+
route: target.target,
|
|
320
|
+
chain: [...chain, resolved.real],
|
|
321
|
+
});
|
|
322
|
+
problems.push(...imported.problems);
|
|
323
|
+
for (const name of imported.variables)
|
|
324
|
+
names.add(name);
|
|
325
|
+
append({
|
|
326
|
+
kind: "import",
|
|
327
|
+
line,
|
|
328
|
+
path: argument,
|
|
329
|
+
file: `.factory/${target.target}`,
|
|
330
|
+
children: imported.nodes,
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
for (const [index, raw] of lines.entries()) {
|
|
334
|
+
const line = firstLine + index;
|
|
335
|
+
const content = stripBom(raw);
|
|
336
|
+
if (fence !== undefined) {
|
|
337
|
+
if (closesFence(content, fence))
|
|
338
|
+
fence = undefined;
|
|
339
|
+
append({ kind: "text", line, text: raw });
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const opened = opensFence(content);
|
|
343
|
+
if (opened !== undefined) {
|
|
344
|
+
fence = { ...opened, line, index };
|
|
345
|
+
append({ kind: "text", line, text: raw });
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const directive = matchDirective(content);
|
|
349
|
+
if (directive === undefined) {
|
|
350
|
+
if (looksLikeDirective(content))
|
|
351
|
+
error(line, WHOLE_LINE_MESSAGE, WHOLE_LINE_FIX);
|
|
352
|
+
appendText(line, raw);
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
switch (directive.name) {
|
|
356
|
+
case "when":
|
|
357
|
+
openWhen(directive, line, raw);
|
|
358
|
+
break;
|
|
359
|
+
case "switch":
|
|
360
|
+
openSwitch(directive, line, raw);
|
|
361
|
+
break;
|
|
362
|
+
case "case":
|
|
363
|
+
case "default":
|
|
364
|
+
openBranch(directive, line, raw);
|
|
365
|
+
break;
|
|
366
|
+
case "endwhen":
|
|
367
|
+
case "endswitch":
|
|
368
|
+
closeBlock(directive, line);
|
|
369
|
+
break;
|
|
370
|
+
case "import":
|
|
371
|
+
await expandImport(directive.args ?? "", line);
|
|
372
|
+
break;
|
|
373
|
+
case "start":
|
|
374
|
+
case "end":
|
|
375
|
+
error(line, `factory:${directive.name} marks the generated block in the root AGENTS.md and cannot appear in source`, "Remove the line");
|
|
376
|
+
appendText(line, raw, false);
|
|
377
|
+
break;
|
|
378
|
+
default:
|
|
379
|
+
error(line, `Unknown directive "factory:${directive.name}"`, didYouMean(directive.name, DIRECTIVE_NAMES) ??
|
|
380
|
+
"Use when, endwhen, switch, case, default, endswitch or import");
|
|
381
|
+
appendText(line, raw, false);
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (fence !== undefined) {
|
|
386
|
+
const followed = lines
|
|
387
|
+
.slice(fence.index + 1)
|
|
388
|
+
.some((raw) => matchDirective(stripBom(raw)) !== undefined);
|
|
389
|
+
if (followed) {
|
|
390
|
+
problems.push({
|
|
391
|
+
level: "warning",
|
|
392
|
+
file,
|
|
393
|
+
line: fence.line,
|
|
394
|
+
message: `The code fence on line ${fence.line} is never closed, so the directive lines after it are text`,
|
|
395
|
+
fix: "Close the fence",
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
while (stack.length > 0) {
|
|
400
|
+
const frame = stack.pop();
|
|
401
|
+
error(frame.node.line, `factory:${frame.kind} on line ${frame.node.line} is never closed in this file`, `Add <!-- factory:end${frame.kind} --> in the same file`);
|
|
402
|
+
}
|
|
403
|
+
return { file, nodes, problems, variables: names };
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Lines that are directives, outside fences: for format 1's warning and the
|
|
407
|
+
* frontmatter rule.
|
|
408
|
+
*/
|
|
409
|
+
export function directiveLines(text, firstLine = 1) {
|
|
410
|
+
const result = [];
|
|
411
|
+
let fence;
|
|
412
|
+
for (const [index, raw] of text.split("\n").entries()) {
|
|
413
|
+
const content = stripBom(raw);
|
|
414
|
+
if (fence !== undefined) {
|
|
415
|
+
if (closesFence(content, fence))
|
|
416
|
+
fence = undefined;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const opened = opensFence(content);
|
|
420
|
+
if (opened !== undefined) {
|
|
421
|
+
fence = opened;
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (matchDirective(content) !== undefined)
|
|
425
|
+
result.push(firstLine + index);
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
//# sourceMappingURL=directives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../src/core/env/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5E,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA8EhE,MAAM,iBAAiB,GACrB,2EAA2E,CAAC;AAC9E,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,eAAe,GAAG;IACtB,MAAM;IACN,SAAS;IACT,QAAQ;IACR,MAAM;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IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
import { runGit } from "../../util/git.js";
|
|
3
|
+
import type { GitConfigScope } from "./types.js";
|
|
4
|
+
export interface EnvConfigEntry {
|
|
5
|
+
scope: GitConfigScope;
|
|
6
|
+
variable: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
export type EnvConfigReader = (root: string) => Promise<{
|
|
10
|
+
entries: EnvConfigEntry[];
|
|
11
|
+
warnings: Problem[];
|
|
12
|
+
}>;
|
|
13
|
+
/** Reads `factory.env.*` for every scope through `run`, which tests inject. */
|
|
14
|
+
export declare function createEnvConfigReader(run?: typeof runGit): EnvConfigReader;
|
|
15
|
+
export declare const readEnvConfig: EnvConfigReader;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { runGit } from "../../util/git.js";
|
|
2
|
+
/** A problem with the selection is a problem with the declaration that needs it. */
|
|
3
|
+
const FILE = ".factory/factory.yaml";
|
|
4
|
+
const SCOPES = ["worktree", "local", "global", "system"];
|
|
5
|
+
/** One call for every variable and scope; `-z` keeps a newline inside a value. */
|
|
6
|
+
const ARGS = ["config", "-z", "--show-scope", "--get-regexp", "^factory\\.env\\."];
|
|
7
|
+
function isScope(value) {
|
|
8
|
+
return SCOPES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
function firstLine(text) {
|
|
11
|
+
for (const line of text.split(/\r?\n/)) {
|
|
12
|
+
const trimmed = line.trim();
|
|
13
|
+
if (trimmed !== "")
|
|
14
|
+
return trimmed;
|
|
15
|
+
}
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
function cannotRead(reason) {
|
|
19
|
+
return {
|
|
20
|
+
level: "warning",
|
|
21
|
+
file: FILE,
|
|
22
|
+
message: `Cannot read factory.env.* from Git config: ${reason}`,
|
|
23
|
+
fix: "Fix the Git config file, or select with --env or FACTORY_ENV_<VARIABLE>",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Stdout is a NUL-terminated pair of records per key: `<scope>\0`, then
|
|
28
|
+
* `<key>\n<value>\0`. The first newline ends the key, and everything after it
|
|
29
|
+
* is the value. A key with no value has no newline at all.
|
|
30
|
+
*/
|
|
31
|
+
function parseOutput(stdout) {
|
|
32
|
+
if (stdout === "")
|
|
33
|
+
return [];
|
|
34
|
+
if (!stdout.endsWith("\0"))
|
|
35
|
+
return undefined;
|
|
36
|
+
const records = stdout.slice(0, -1).split("\0");
|
|
37
|
+
if (records.length % 2 !== 0)
|
|
38
|
+
return undefined;
|
|
39
|
+
const entries = [];
|
|
40
|
+
for (let index = 0; index < records.length; index += 2) {
|
|
41
|
+
const scope = records[index];
|
|
42
|
+
const record = records[index + 1];
|
|
43
|
+
// `command` comes from `git -c` or GIT_CONFIG_*; a selection never comes
|
|
44
|
+
// from how one Git process was started, so it is skipped without a warning.
|
|
45
|
+
if (!isScope(scope))
|
|
46
|
+
continue;
|
|
47
|
+
const newline = record.indexOf("\n");
|
|
48
|
+
const key = newline === -1 ? record : record.slice(0, newline);
|
|
49
|
+
const value = newline === -1 ? "" : record.slice(newline + 1);
|
|
50
|
+
if (!key.startsWith("factory.env."))
|
|
51
|
+
continue;
|
|
52
|
+
// The variable is the whole suffix. A subsection, such as
|
|
53
|
+
// `factory.env.other.harness`, names no variable, so it is skipped.
|
|
54
|
+
const variable = key.slice("factory.env.".length);
|
|
55
|
+
if (variable === "" || variable.includes("."))
|
|
56
|
+
continue;
|
|
57
|
+
entries.push({ scope, variable, value });
|
|
58
|
+
}
|
|
59
|
+
return entries;
|
|
60
|
+
}
|
|
61
|
+
/** Reads `factory.env.*` for every scope through `run`, which tests inject. */
|
|
62
|
+
export function createEnvConfigReader(run = runGit) {
|
|
63
|
+
return async (root) => {
|
|
64
|
+
let result;
|
|
65
|
+
try {
|
|
66
|
+
result = await run(ARGS, { cwd: root });
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const code = error.code;
|
|
70
|
+
// Git is not installed: the selection continues without Git config.
|
|
71
|
+
if (code === "ENOENT")
|
|
72
|
+
return { entries: [], warnings: [] };
|
|
73
|
+
const reason = firstLine(error.message ?? "") || code || "git could not be run";
|
|
74
|
+
return { entries: [], warnings: [cannotRead(reason)] };
|
|
75
|
+
}
|
|
76
|
+
const stderr = firstLine(result.stderr);
|
|
77
|
+
// `--show-scope` arrived in Git 2.26, so an older Git refuses the option.
|
|
78
|
+
if (result.exitCode !== 0 &&
|
|
79
|
+
stderr.includes("unknown option") &&
|
|
80
|
+
stderr.includes("show-scope")) {
|
|
81
|
+
return {
|
|
82
|
+
entries: [],
|
|
83
|
+
warnings: [
|
|
84
|
+
{
|
|
85
|
+
level: "warning",
|
|
86
|
+
file: FILE,
|
|
87
|
+
message: "Git 2.26 or later is needed to read factory.env.* from Git config",
|
|
88
|
+
fix: "Upgrade Git, or select with --env or FACTORY_ENV_<VARIABLE>",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Git exits 1 when no key matches the pattern.
|
|
94
|
+
if (result.exitCode !== 0 && result.exitCode !== 1) {
|
|
95
|
+
return {
|
|
96
|
+
entries: [],
|
|
97
|
+
warnings: [
|
|
98
|
+
cannotRead(stderr === "" ? `git config exited with status ${result.exitCode}` : stderr),
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const entries = parseOutput(result.stdout);
|
|
103
|
+
if (entries === undefined) {
|
|
104
|
+
return { entries: [], warnings: [cannotRead("unexpected output from git config")] };
|
|
105
|
+
}
|
|
106
|
+
return { entries, warnings: [] };
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export const readEnvConfig = createEnvConfigReader();
|
|
110
|
+
//# sourceMappingURL=git-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-config.js","sourceRoot":"","sources":["../../../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AC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;iBACxF;aACF,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,mCAAmC,CAAC,CAAC,EAAE,CAAC;QACtF,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAoB,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
/** What a failed import reports, on the directive's line in the importing file. */
|
|
3
|
+
export interface ImportFailure {
|
|
4
|
+
ok: false;
|
|
5
|
+
message: string;
|
|
6
|
+
fix: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ImportCache {
|
|
9
|
+
/** Absolute `.factory` directory, native separators. */
|
|
10
|
+
factoryDir: string;
|
|
11
|
+
/** `realpath` of `.factory`, computed once. */
|
|
12
|
+
factoryReal?: string;
|
|
13
|
+
/**
|
|
14
|
+
* By realpath: what does not depend on the route a file was imported through,
|
|
15
|
+
* so a partial imported by ten files is read once per cache.
|
|
16
|
+
*/
|
|
17
|
+
files: Map<string, LoadedImport>;
|
|
18
|
+
}
|
|
19
|
+
export interface LoadedImport {
|
|
20
|
+
/** Repository-relative POSIX path of the file itself, such as `.factory/partials/sub-agents.md`. */
|
|
21
|
+
file: string;
|
|
22
|
+
/** The body, frontmatter removed, and one trailing newline dropped so the import replaces one line. */
|
|
23
|
+
text: string;
|
|
24
|
+
/** Line number of the body's first line in the file. */
|
|
25
|
+
firstLine: number;
|
|
26
|
+
/** The imported file's own problems: a directive in its frontmatter. */
|
|
27
|
+
problems: Problem[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A cache of imported files for one build or one `loadFactory`. Every file is
|
|
31
|
+
* keyed by its realpath, so an edited partial is always reread by the next run.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createImportCache(factoryDir: string): ImportCache;
|
|
34
|
+
/**
|
|
35
|
+
* Rules 1 to 5 for an import: the path is relative to the importing file, uses
|
|
36
|
+
* `/`, ends in `.md`, and stays inside `.factory/` once normalised. Pure: it
|
|
37
|
+
* works on factory-relative POSIX paths only, so a Windows-style path gives the
|
|
38
|
+
* same answer on every platform and nothing here touches the disk.
|
|
39
|
+
*/
|
|
40
|
+
export declare function importTarget(from: string, argument: string): {
|
|
41
|
+
ok: true;
|
|
42
|
+
target: string;
|
|
43
|
+
} | ImportFailure;
|
|
44
|
+
/**
|
|
45
|
+
* The repository-relative `.factory/<path>` name of a realpath, for messages
|
|
46
|
+
* such as an import loop's chain.
|
|
47
|
+
*/
|
|
48
|
+
export declare function realDisplayPath(cache: ImportCache, real: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves an import to the file's realpath and its loaded content, reporting
|
|
51
|
+
* every path rule of the spec on the directive's line. The walk reads directory
|
|
52
|
+
* listings and matches names exactly, so a wrong-case path fails the same way on
|
|
53
|
+
* a case-insensitive file system as on a case-sensitive one. Symbolic links, for
|
|
54
|
+
* the file and for any parent, must resolve inside the real `.factory/`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveImport(from: string, argument: string, cache: ImportCache): Promise<{
|
|
57
|
+
ok: true;
|
|
58
|
+
real: string;
|
|
59
|
+
loaded: LoadedImport;
|
|
60
|
+
} | ImportFailure>;
|