@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,30 @@
|
|
|
1
|
+
import type { EnvConfigReader } from "./git-config.js";
|
|
2
|
+
import type { EnvVariable, ResolvedSelection } from "./types.js";
|
|
3
|
+
/** `harness` → `FACTORY_ENV_HARNESS`; `target-os` → `FACTORY_ENV_TARGET_OS`. */
|
|
4
|
+
export declare function envVariableName(variable: string): string;
|
|
5
|
+
/** Comma-separated value names, trimmed, without empties or repeats. */
|
|
6
|
+
export declare function splitValues(text: string): string[];
|
|
7
|
+
/**
|
|
8
|
+
* The `--env` option's arguments: `parseArgs` gives one string, a list of them,
|
|
9
|
+
* or a boolean when the option is written with no value.
|
|
10
|
+
*/
|
|
11
|
+
export declare function envOptions(value: unknown): string[];
|
|
12
|
+
export interface ResolveOptions {
|
|
13
|
+
root: string;
|
|
14
|
+
/** Raw `--env` arguments. */
|
|
15
|
+
options?: readonly string[];
|
|
16
|
+
/** Default `process.env`; tests inject one so no developer's variable leaks in. */
|
|
17
|
+
processEnv?: NodeJS.ProcessEnv;
|
|
18
|
+
/** Default `readEnvConfig`; tests inject a fake. */
|
|
19
|
+
readConfig?: EnvConfigReader;
|
|
20
|
+
}
|
|
21
|
+
/** The fix line for a variable or value a factory does not declare. */
|
|
22
|
+
export declare function declaredVariablesFix(names: readonly string[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves every declared variable's values from `--env`, the process
|
|
25
|
+
* environment, Git config, the declared default and finally every value.
|
|
26
|
+
*
|
|
27
|
+
* A bad `--env` throws a `MetafabError` with exit 1; an undeclared value from
|
|
28
|
+
* any other source is a warning and the next source applies.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveSelection(variables: readonly EnvVariable[], options: ResolveOptions): Promise<ResolvedSelection>;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ExitCode, MetafabError } from "../../errors.js";
|
|
2
|
+
import { didYouMean } from "../../util/suggest.js";
|
|
3
|
+
import { readEnvConfig } from "./git-config.js";
|
|
4
|
+
/** A problem with the selection is a problem with the declaration that needs it. */
|
|
5
|
+
const FILE = ".factory/factory.yaml";
|
|
6
|
+
/** Git config scopes, highest priority first. */
|
|
7
|
+
const SCOPES = ["worktree", "local", "global", "system"];
|
|
8
|
+
/** `harness` → `FACTORY_ENV_HARNESS`; `target-os` → `FACTORY_ENV_TARGET_OS`. */
|
|
9
|
+
export function envVariableName(variable) {
|
|
10
|
+
return `FACTORY_ENV_${variable.toUpperCase().replaceAll("-", "_")}`;
|
|
11
|
+
}
|
|
12
|
+
/** Comma-separated value names, trimmed, without empties or repeats. */
|
|
13
|
+
export function splitValues(text) {
|
|
14
|
+
const values = [];
|
|
15
|
+
for (const part of text.split(",")) {
|
|
16
|
+
const value = part.trim();
|
|
17
|
+
if (value === "" || values.includes(value))
|
|
18
|
+
continue;
|
|
19
|
+
values.push(value);
|
|
20
|
+
}
|
|
21
|
+
return values;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The `--env` option's arguments: `parseArgs` gives one string, a list of them,
|
|
25
|
+
* or a boolean when the option is written with no value.
|
|
26
|
+
*/
|
|
27
|
+
export function envOptions(value) {
|
|
28
|
+
if (typeof value === "string")
|
|
29
|
+
return [value];
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return value.filter((item) => typeof item === "string");
|
|
32
|
+
}
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
/** The fix line for a variable or value a factory does not declare. */
|
|
36
|
+
export function declaredVariablesFix(names) {
|
|
37
|
+
return names.length === 0
|
|
38
|
+
? "This factory declares no environment variables"
|
|
39
|
+
: `Declared variables: ${names.join(", ")}`;
|
|
40
|
+
}
|
|
41
|
+
/** Splits `--env <variable>=<values>`, reporting every bad argument at once. */
|
|
42
|
+
function parseOptions(variables, args) {
|
|
43
|
+
const byName = new Map(variables.map((variable) => [variable.name, variable]));
|
|
44
|
+
const declared = variables.map((variable) => variable.name);
|
|
45
|
+
const parsed = new Map();
|
|
46
|
+
const problems = [];
|
|
47
|
+
for (const arg of args) {
|
|
48
|
+
const equals = arg.indexOf("=");
|
|
49
|
+
if (equals === -1) {
|
|
50
|
+
problems.push({
|
|
51
|
+
level: "error",
|
|
52
|
+
file: FILE,
|
|
53
|
+
message: `--env needs <variable>=<values>: "${arg}"`,
|
|
54
|
+
fix: "Write --env <variable>=<values>, such as --env harness=opencode",
|
|
55
|
+
});
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const name = arg.slice(0, equals);
|
|
59
|
+
const text = arg.slice(equals + 1);
|
|
60
|
+
const variable = byName.get(name);
|
|
61
|
+
if (variable === undefined) {
|
|
62
|
+
problems.push({
|
|
63
|
+
level: "error",
|
|
64
|
+
file: FILE,
|
|
65
|
+
message: `--env names unknown variable "${name}"`,
|
|
66
|
+
fix: didYouMean(name, declared) ?? declaredVariablesFix(declared),
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (parsed.has(name)) {
|
|
71
|
+
problems.push({
|
|
72
|
+
level: "error",
|
|
73
|
+
file: FILE,
|
|
74
|
+
line: variable.line,
|
|
75
|
+
message: `--env names "${name}" twice`,
|
|
76
|
+
fix: `Pass --env ${name}=<values> once`,
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
parsed.set(name, text);
|
|
81
|
+
}
|
|
82
|
+
if (problems.length > 0) {
|
|
83
|
+
throw new MetafabError("Invalid --env", {
|
|
84
|
+
exitCode: ExitCode.Failed,
|
|
85
|
+
code: "invalid-env",
|
|
86
|
+
problems,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return parsed;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Drops the values the variable does not declare, warning about each one, and
|
|
93
|
+
* returns what is left in declaration order so the order given never matters.
|
|
94
|
+
*/
|
|
95
|
+
function keepDeclared(text, source, variable, declared, warnings) {
|
|
96
|
+
const kept = new Set();
|
|
97
|
+
for (const value of splitValues(text)) {
|
|
98
|
+
if (!declared.includes(value)) {
|
|
99
|
+
warnings.push({
|
|
100
|
+
level: "warning",
|
|
101
|
+
file: FILE,
|
|
102
|
+
line: variable.line,
|
|
103
|
+
message: `Ignored "${value}" from ${source}: ${variable.name} does not declare it`,
|
|
104
|
+
fix: `Declared values: ${declared.join(", ")}`,
|
|
105
|
+
});
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
kept.add(value);
|
|
109
|
+
}
|
|
110
|
+
return declared.filter((name) => kept.has(name));
|
|
111
|
+
}
|
|
112
|
+
/** The first source that yields a declared value wins, in the spec's order. */
|
|
113
|
+
function resolveVariable(variable, sources, warnings) {
|
|
114
|
+
const declared = variable.values.map((value) => value.name);
|
|
115
|
+
const name = variable.name;
|
|
116
|
+
const optionText = sources.optionValues.get(name);
|
|
117
|
+
if (optionText !== undefined) {
|
|
118
|
+
if (splitValues(optionText).length === 0) {
|
|
119
|
+
warnings.push({
|
|
120
|
+
level: "warning",
|
|
121
|
+
file: FILE,
|
|
122
|
+
line: variable.line,
|
|
123
|
+
message: `--env ${name}=${optionText} names no value`,
|
|
124
|
+
fix: `Write --env ${name}=<values>, such as --env ${name}=${declared[0] ?? "<value>"}`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const values = keepDeclared(optionText, `--env ${name}=${optionText}`, variable, declared, warnings);
|
|
129
|
+
if (values.length > 0)
|
|
130
|
+
return { variable: name, values, source: "option" };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const from = envVariableName(name);
|
|
134
|
+
const environmentText = sources.processEnv[from];
|
|
135
|
+
if (environmentText !== undefined) {
|
|
136
|
+
const values = keepDeclared(environmentText, from, variable, declared, warnings);
|
|
137
|
+
if (values.length > 0)
|
|
138
|
+
return { variable: name, values, source: "environment", from };
|
|
139
|
+
}
|
|
140
|
+
for (const scope of SCOPES) {
|
|
141
|
+
const scoped = sources.entries.filter((entry) => entry.variable === name && entry.scope === scope);
|
|
142
|
+
if (scoped.length === 0)
|
|
143
|
+
continue;
|
|
144
|
+
const source = `factory.env.${name} in ${scope} Git config`;
|
|
145
|
+
const kept = new Set();
|
|
146
|
+
for (const entry of scoped) {
|
|
147
|
+
for (const value of keepDeclared(entry.value, source, variable, declared, warnings)) {
|
|
148
|
+
kept.add(value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const values = declared.filter((value) => kept.has(value));
|
|
152
|
+
// A scope that sets the key decides it, even when every value is ignored.
|
|
153
|
+
if (values.length > 0)
|
|
154
|
+
return { variable: name, values, source: "git", scope };
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
const defaults = (variable.default ?? []).filter((value) => declared.includes(value));
|
|
158
|
+
if (defaults.length > 0) {
|
|
159
|
+
const values = declared.filter((value) => defaults.includes(value));
|
|
160
|
+
return { variable: name, values, source: "default" };
|
|
161
|
+
}
|
|
162
|
+
return { variable: name, values: [...declared], source: "all" };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Resolves every declared variable's values from `--env`, the process
|
|
166
|
+
* environment, Git config, the declared default and finally every value.
|
|
167
|
+
*
|
|
168
|
+
* A bad `--env` throws a `MetafabError` with exit 1; an undeclared value from
|
|
169
|
+
* any other source is a warning and the next source applies.
|
|
170
|
+
*/
|
|
171
|
+
export async function resolveSelection(variables, options) {
|
|
172
|
+
const optionValues = parseOptions(variables, options.options ?? []);
|
|
173
|
+
const selection = new Map();
|
|
174
|
+
if (variables.length === 0)
|
|
175
|
+
return { variables: [], selection, warnings: [] };
|
|
176
|
+
const { entries, warnings: readWarnings } = await (options.readConfig ?? readEnvConfig)(options.root);
|
|
177
|
+
const sources = {
|
|
178
|
+
optionValues,
|
|
179
|
+
processEnv: options.processEnv ?? process.env,
|
|
180
|
+
entries,
|
|
181
|
+
};
|
|
182
|
+
const warnings = [...readWarnings];
|
|
183
|
+
const resolved = [];
|
|
184
|
+
for (const variable of variables) {
|
|
185
|
+
const result = resolveVariable(variable, sources, warnings);
|
|
186
|
+
resolved.push(result);
|
|
187
|
+
selection.set(variable.name, result.values);
|
|
188
|
+
}
|
|
189
|
+
return { variables: resolved, selection, warnings };
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../../src/core/env/select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAShD,oFAAoF;AACpF,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC,iDAAiD;AACjD,MAAM,MAAM,GAA8B,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC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YAAY,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAuB,EAAE,CAAC;IACxC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
export interface EnvValue {
|
|
3
|
+
name: string;
|
|
4
|
+
/** The declared label, or `When <variable> is <value>`. */
|
|
5
|
+
label: string;
|
|
6
|
+
line: number;
|
|
7
|
+
}
|
|
8
|
+
export interface EnvVariable {
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
/** Declaration order, never empty after validation. */
|
|
12
|
+
values: EnvValue[];
|
|
13
|
+
/** Value names in declaration order, when the variable declares a default. */
|
|
14
|
+
default?: string[];
|
|
15
|
+
/** The variable's key line in `factory.yaml`. */
|
|
16
|
+
line: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Variable name → selected value names, in declaration order. Every declared
|
|
20
|
+
* variable has an entry.
|
|
21
|
+
*/
|
|
22
|
+
export type EnvSelection = ReadonlyMap<string, readonly string[]>;
|
|
23
|
+
export type SelectionSource = "option" | "environment" | "git" | "default" | "all";
|
|
24
|
+
export type GitConfigScope = "worktree" | "local" | "global" | "system";
|
|
25
|
+
export interface ResolvedVariable {
|
|
26
|
+
variable: string;
|
|
27
|
+
values: string[];
|
|
28
|
+
source: SelectionSource;
|
|
29
|
+
/** The Git config scope the selection came from, for `git`. */
|
|
30
|
+
scope?: GitConfigScope;
|
|
31
|
+
/** The `FACTORY_ENV_<VAR>` variable that supplied the selection, for `environment`. */
|
|
32
|
+
from?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ResolvedSelection {
|
|
35
|
+
variables: ResolvedVariable[];
|
|
36
|
+
selection: EnvSelection;
|
|
37
|
+
warnings: Problem[];
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/env/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
import type { Factory } from "../factory/types.js";
|
|
3
|
+
import type { MarkdownDocument } from "./directives.js";
|
|
4
|
+
import type { EnvVariable } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Rule 14 for a format 2 factory, and directives rule 5 for a format 1 one.
|
|
7
|
+
* Format 2 validates every directive, condition and switch in every branch of
|
|
8
|
+
* every file `build` renders, whatever the selection, and every `skills` entry.
|
|
9
|
+
* Format 1 copies directives as text, so each file that has one gets a single
|
|
10
|
+
* warning on its first directive line.
|
|
11
|
+
*/
|
|
12
|
+
export declare function environmentProblems(factory: Factory): Promise<Problem[]>;
|
|
13
|
+
/**
|
|
14
|
+
* The combination limit across an import: a block inside an imported file is
|
|
15
|
+
* classified together with the conditions around the import line, so the two
|
|
16
|
+
* files' variables can span more scenarios than either file alone. Each file's
|
|
17
|
+
* own parse checks its blocks against its own enclosing conditions, so this
|
|
18
|
+
* reports only the blocks an import pushes over the limit, on the import
|
|
19
|
+
* directive's line in the importing file.
|
|
20
|
+
*
|
|
21
|
+
* Rendering classifies each block over its enclosing conditions, so a renderer
|
|
22
|
+
* must treat these as errors too: without them it would enumerate every
|
|
23
|
+
* scenario of a block this reports.
|
|
24
|
+
*/
|
|
25
|
+
export declare function importCombinationProblems(document: MarkdownDocument, variables: readonly EnvVariable[]): Problem[];
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { didYouMean } from "../../util/suggest.js";
|
|
4
|
+
import { toLF } from "../../util/text.js";
|
|
5
|
+
import { collectSkillFiles, textContent } from "../build/skill.js";
|
|
6
|
+
import { conditionVariables } from "./condition.js";
|
|
7
|
+
import { directiveLines, parseMarkdown } from "./directives.js";
|
|
8
|
+
import { createImportCache } from "./imports.js";
|
|
9
|
+
import { markdownParts } from "./markdown.js";
|
|
10
|
+
import { MAX_COMBINATIONS, combinations } from "./scenarios.js";
|
|
11
|
+
const FACTORY_FILE = ".factory/factory.yaml";
|
|
12
|
+
const AGENTS_FILE = ".factory/AGENTS.md";
|
|
13
|
+
const FRONTMATTER_MESSAGE = "Directives are not allowed in frontmatter";
|
|
14
|
+
const FRONTMATTER_FIX = "Move the directive below the closing ---; name and description stay the same in every environment";
|
|
15
|
+
const FORMAT_ONE_FIX = "Set format: 2 in .factory/factory.yaml, or remove the directives";
|
|
16
|
+
/** True for a file `build` renders: its extension, lowercased, is `.md`. */
|
|
17
|
+
function isRenderedMarkdown(relative) {
|
|
18
|
+
return path.extname(relative).toLowerCase() === ".md";
|
|
19
|
+
}
|
|
20
|
+
async function readMarkdown(target, file, problems) {
|
|
21
|
+
let data;
|
|
22
|
+
try {
|
|
23
|
+
data = await readFile(target);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
problems.push({
|
|
27
|
+
level: "error",
|
|
28
|
+
file,
|
|
29
|
+
line: 1,
|
|
30
|
+
message: `Cannot read file ${file}`,
|
|
31
|
+
fix: "Check its permissions or restore the file",
|
|
32
|
+
});
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const text = textContent(data);
|
|
36
|
+
return text === undefined ? undefined : toLF(text);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Rule 14 for a format 2 factory, and directives rule 5 for a format 1 one.
|
|
40
|
+
* Format 2 validates every directive, condition and switch in every branch of
|
|
41
|
+
* every file `build` renders, whatever the selection, and every `skills` entry.
|
|
42
|
+
* Format 1 copies directives as text, so each file that has one gets a single
|
|
43
|
+
* warning on its first directive line.
|
|
44
|
+
*/
|
|
45
|
+
export async function environmentProblems(factory) {
|
|
46
|
+
const problems = [];
|
|
47
|
+
const yaml = factory.factoryYaml;
|
|
48
|
+
const format = yaml?.format ?? 1;
|
|
49
|
+
const variables = yaml?.env ?? [];
|
|
50
|
+
// One cache per run, so a partial imported by several files is read once and
|
|
51
|
+
// an edited partial is always reread by the next run.
|
|
52
|
+
const imports = createImportCache(factory.dir);
|
|
53
|
+
const checkFile = async (file, route, text, frontmatter) => {
|
|
54
|
+
if (format === 1) {
|
|
55
|
+
const lines = directiveLines(text);
|
|
56
|
+
if (lines.length > 0) {
|
|
57
|
+
problems.push({
|
|
58
|
+
level: "warning",
|
|
59
|
+
file,
|
|
60
|
+
line: lines[0],
|
|
61
|
+
message: `${file} has factory: directives, which need format: 2`,
|
|
62
|
+
fix: FORMAT_ONE_FIX,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const parts = frontmatter ? markdownParts(text) : undefined;
|
|
68
|
+
if (parts?.frontmatter !== undefined) {
|
|
69
|
+
for (const line of directiveLines(parts.frontmatter, 2)) {
|
|
70
|
+
problems.push({
|
|
71
|
+
level: "error",
|
|
72
|
+
file,
|
|
73
|
+
line,
|
|
74
|
+
message: FRONTMATTER_MESSAGE,
|
|
75
|
+
fix: FRONTMATTER_FIX,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const document = await parseMarkdown(parts?.body ?? text, {
|
|
80
|
+
file,
|
|
81
|
+
firstLine: parts?.firstLine ?? 1,
|
|
82
|
+
variables,
|
|
83
|
+
imports,
|
|
84
|
+
route,
|
|
85
|
+
chain: [],
|
|
86
|
+
});
|
|
87
|
+
problems.push(...document.problems);
|
|
88
|
+
problems.push(...importCombinationProblems(document, variables));
|
|
89
|
+
};
|
|
90
|
+
for (const skill of factory.skills) {
|
|
91
|
+
const sourcePath = `.factory/${skill.relDir}`;
|
|
92
|
+
const collected = await collectSkillFiles({ dir: path.join(factory.dir, ...skill.relDir.split("/")), name: skill.name, sourcePath }, { factoryDir: factory.dir });
|
|
93
|
+
for (const file of collected.files) {
|
|
94
|
+
if (!isRenderedMarkdown(file.relative))
|
|
95
|
+
continue;
|
|
96
|
+
const displayPath = `${sourcePath}/${file.relative}`;
|
|
97
|
+
const text = await readMarkdown(file.target, displayPath, problems);
|
|
98
|
+
if (text === undefined)
|
|
99
|
+
continue;
|
|
100
|
+
await checkFile(displayPath, `${skill.relDir}/${file.relative}`, text, true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// `.factory/AGENTS.md` is rendered whole, so it has no frontmatter to protect.
|
|
104
|
+
if (factory.agentsMd !== undefined) {
|
|
105
|
+
await checkFile(AGENTS_FILE, "AGENTS.md", factory.agentsMd, false);
|
|
106
|
+
}
|
|
107
|
+
if (format === 2)
|
|
108
|
+
problems.push(...conditionalSkillProblems(factory));
|
|
109
|
+
return dedupeProblems(problems);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The combination limit across an import: a block inside an imported file is
|
|
113
|
+
* classified together with the conditions around the import line, so the two
|
|
114
|
+
* files' variables can span more scenarios than either file alone. Each file's
|
|
115
|
+
* own parse checks its blocks against its own enclosing conditions, so this
|
|
116
|
+
* reports only the blocks an import pushes over the limit, on the import
|
|
117
|
+
* directive's line in the importing file.
|
|
118
|
+
*
|
|
119
|
+
* Rendering classifies each block over its enclosing conditions, so a renderer
|
|
120
|
+
* must treat these as errors too: without them it would enumerate every
|
|
121
|
+
* scenario of a block this reports.
|
|
122
|
+
*/
|
|
123
|
+
export function importCombinationProblems(document, variables) {
|
|
124
|
+
const problems = [];
|
|
125
|
+
const walk = (nodes, state) => {
|
|
126
|
+
for (const node of nodes) {
|
|
127
|
+
if (node.kind === "text")
|
|
128
|
+
continue;
|
|
129
|
+
if (node.kind === "import") {
|
|
130
|
+
walk(node.children, {
|
|
131
|
+
file: node.file ?? state.file,
|
|
132
|
+
origin: { file: state.file, line: node.line },
|
|
133
|
+
foreign: new Set([...state.foreign, ...state.local]),
|
|
134
|
+
local: new Set(),
|
|
135
|
+
});
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const own = node.kind === "when" ? conditionVariables(node.condition) : new Set([node.variable]);
|
|
139
|
+
const local = new Set([...state.local, ...own]);
|
|
140
|
+
const all = new Set([...state.foreign, ...local]);
|
|
141
|
+
if (state.origin !== undefined) {
|
|
142
|
+
const count = combinations(all, variables);
|
|
143
|
+
if (count > MAX_COMBINATIONS && combinations(local, variables) <= MAX_COMBINATIONS) {
|
|
144
|
+
problems.push({
|
|
145
|
+
level: "error",
|
|
146
|
+
file: state.origin.file,
|
|
147
|
+
line: state.origin.line,
|
|
148
|
+
message: `Condition on line ${node.line} of ${state.file} spans too many combinations here: ${count} over ${[...all].join(", ")}; the limit is ${MAX_COMBINATIONS}`,
|
|
149
|
+
fix: "Import it outside the enclosing blocks, or split the condition",
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const children = node.kind === "when" ? node.children : node.branches.flatMap((branch) => branch.children);
|
|
154
|
+
walk(children, { ...state, local });
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
walk(document.nodes, { file: document.file, foreign: new Set(), local: new Set() });
|
|
158
|
+
return problems;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Keeps one problem per file, line and message, so a partial imported by several
|
|
162
|
+
* files reports each of its own problems once.
|
|
163
|
+
*/
|
|
164
|
+
function dedupeProblems(problems) {
|
|
165
|
+
const seen = new Set();
|
|
166
|
+
return problems.filter((problem) => {
|
|
167
|
+
const key = `${problem.file}\u0000${problem.line ?? 0}\u0000${problem.message}`;
|
|
168
|
+
if (seen.has(key))
|
|
169
|
+
return false;
|
|
170
|
+
seen.add(key);
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The `skills` checks that need the loaded factory: each entry names a skill,
|
|
176
|
+
* and no workflow the pipeline names carries one, because the pipeline is the
|
|
177
|
+
* same for every developer and must name installed workflows.
|
|
178
|
+
*/
|
|
179
|
+
function conditionalSkillProblems(factory) {
|
|
180
|
+
const yaml = factory.factoryYaml;
|
|
181
|
+
if (yaml === undefined)
|
|
182
|
+
return [];
|
|
183
|
+
const problems = [];
|
|
184
|
+
const names = factory.skills.map((skill) => skill.name);
|
|
185
|
+
const pipeline = new Set(yaml.pipeline.map((entry) => entry.workflow));
|
|
186
|
+
for (const entry of yaml.skills) {
|
|
187
|
+
if (!names.includes(entry.name)) {
|
|
188
|
+
problems.push({
|
|
189
|
+
level: "error",
|
|
190
|
+
file: FACTORY_FILE,
|
|
191
|
+
line: entry.line,
|
|
192
|
+
message: `skills names unknown skill "${entry.name}"`,
|
|
193
|
+
fix: didYouMean(entry.name, names) ??
|
|
194
|
+
(names.length === 0
|
|
195
|
+
? "Remove the entry, or add the skill under .factory/skills/"
|
|
196
|
+
: `Use one of: ${names.join(", ")}`),
|
|
197
|
+
});
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (pipeline.has(entry.name)) {
|
|
201
|
+
problems.push({
|
|
202
|
+
level: "error",
|
|
203
|
+
file: FACTORY_FILE,
|
|
204
|
+
line: entry.line,
|
|
205
|
+
message: `"${entry.name}" is in the pipeline, so it cannot have a skills entry`,
|
|
206
|
+
fix: "Remove the entry: the pipeline names installed workflows for everyone",
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return problems;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../src/core/env/validate.ts"],"names":[],"mappings":"AAAA,OAA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AQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvE,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,QAAQ,CAAC,IAAI,CAAC;gBACZ,KAAK,EAAE,OAAO;gBACd,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,+BAA+B,KAAK,CAAC,IAAI,GAAG;gBACrD,GAAG,EACD,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;oBAC7B,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;wBACjB,CAAC,CAAC,2DAA2D;wBAC7D,CAAC,CAAC,eAAe,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;aACzC,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC;gBACZ,KAAK,EAAE,OAAO;gBACd,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,IAAI,KAAK,CAAC,IAAI,wDAAwD;gBAC/E,GAAG,EAAE,uEAAuE;aAC7E,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Document } from "yaml";
|
|
2
2
|
import type { Problem } from "../../errors.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { YamlDocument } from "../../util/yaml.js";
|
|
4
|
+
import type { EnvVariable } from "../env/types.js";
|
|
5
|
+
import type { FactoryYaml, PipelineEntry, Requirement, SkillCondition } from "./types.js";
|
|
4
6
|
export interface FactoryYamlParseResult {
|
|
5
7
|
yaml?: FactoryYaml;
|
|
6
8
|
pipeline?: PipelineEntry[];
|
|
@@ -13,4 +15,15 @@ export interface FactoryYamlParseResult {
|
|
|
13
15
|
* to convert safely.
|
|
14
16
|
*/
|
|
15
17
|
export declare function factoryAliasProblems(document: Document, text: string, file: string): Problem[];
|
|
18
|
+
/** The `skills` key of a `factory.yaml`: its value node and the line of the key. */
|
|
19
|
+
export interface SkillsField {
|
|
20
|
+
node: unknown;
|
|
21
|
+
line: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Rule 14: `skills` gives a condition to each skill that depends on the
|
|
25
|
+
* environment. Every problem is an error on the key's or entry's line, and the
|
|
26
|
+
* entries that parse are still returned, as pipeline entries are.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseSkillsField(field: SkillsField, parsed: YamlDocument, file: string, format: 1 | 2 | undefined, variables: readonly EnvVariable[], problems: Problem[]): SkillCondition[];
|
|
16
29
|
export declare function parseFactoryYaml(text: string, file: string): FactoryYamlParseResult;
|