@seasb/metafab 0.0.0-stage → 1.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 +47 -2
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +317 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +70 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +41 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +74 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +24 -0
- package/dist/commands/detach.js.map +1 -0
- package/dist/commands/diff.d.ts +2 -0
- package/dist/commands/diff.js +35 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/import.d.ts +2 -0
- package/dist/commands/import.js +107 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +77 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/map.d.ts +2 -0
- package/dist/commands/map.js +43 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/not-implemented.d.ts +2 -0
- package/dist/commands/not-implemented.js +19 -0
- package/dist/commands/not-implemented.js.map +1 -0
- package/dist/commands/pipeline-add.d.ts +2 -0
- package/dist/commands/pipeline-add.js +67 -0
- package/dist/commands/pipeline-add.js.map +1 -0
- package/dist/commands/pipeline-remove.d.ts +2 -0
- package/dist/commands/pipeline-remove.js +44 -0
- package/dist/commands/pipeline-remove.js.map +1 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +147 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/types.d.ts +45 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +97 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/core/adopt.d.ts +53 -0
- package/dist/core/adopt.js +676 -0
- package/dist/core/adopt.js.map +1 -0
- package/dist/core/build/agents.d.ts +23 -0
- package/dist/core/build/agents.js +60 -0
- package/dist/core/build/agents.js.map +1 -0
- package/dist/core/build/index.d.ts +4 -0
- package/dist/core/build/index.js +5 -0
- package/dist/core/build/index.js.map +1 -0
- package/dist/core/build/markers.d.ts +34 -0
- package/dist/core/build/markers.js +97 -0
- package/dist/core/build/markers.js.map +1 -0
- package/dist/core/build/plan.d.ts +48 -0
- package/dist/core/build/plan.js +792 -0
- package/dist/core/build/plan.js.map +1 -0
- package/dist/core/build/skill.d.ts +60 -0
- package/dist/core/build/skill.js +275 -0
- package/dist/core/build/skill.js.map +1 -0
- package/dist/core/check/drift.d.ts +13 -0
- package/dist/core/check/drift.js +205 -0
- package/dist/core/check/drift.js.map +1 -0
- package/dist/core/check/index.d.ts +12 -0
- package/dist/core/check/index.js +78 -0
- package/dist/core/check/index.js.map +1 -0
- package/dist/core/check/markers.d.ts +9 -0
- package/dist/core/check/markers.js +220 -0
- package/dist/core/check/markers.js.map +1 -0
- package/dist/core/config/destinations.d.ts +5 -0
- package/dist/core/config/destinations.js +20 -0
- package/dist/core/config/destinations.js.map +1 -0
- package/dist/core/config/load.d.ts +4 -0
- package/dist/core/config/load.js +41 -0
- package/dist/core/config/load.js.map +1 -0
- package/dist/core/config/parse.d.ts +8 -0
- package/dist/core/config/parse.js +198 -0
- package/dist/core/config/parse.js.map +1 -0
- package/dist/core/config/source.d.ts +14 -0
- package/dist/core/config/source.js +44 -0
- package/dist/core/config/source.js.map +1 -0
- package/dist/core/config/types.d.ts +48 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config/validate.d.ts +11 -0
- package/dist/core/config/validate.js +351 -0
- package/dist/core/config/validate.js.map +1 -0
- package/dist/core/config/writers.d.ts +14 -0
- package/dist/core/config/writers.js +261 -0
- package/dist/core/config/writers.js.map +1 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/config.js +8 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/discovery.d.ts +34 -0
- package/dist/core/discovery.js +272 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/edit/create.d.ts +18 -0
- package/dist/core/edit/create.js +190 -0
- package/dist/core/edit/create.js.map +1 -0
- package/dist/core/edit/document.d.ts +4 -0
- package/dist/core/edit/document.js +16 -0
- package/dist/core/edit/document.js.map +1 -0
- package/dist/core/edit/factory-yaml.d.ts +17 -0
- package/dist/core/edit/factory-yaml.js +211 -0
- package/dist/core/edit/factory-yaml.js.map +1 -0
- package/dist/core/edit/files.d.ts +6 -0
- package/dist/core/edit/files.js +47 -0
- package/dist/core/edit/files.js.map +1 -0
- package/dist/core/edit/index.d.ts +9 -0
- package/dist/core/edit/index.js +10 -0
- package/dist/core/edit/index.js.map +1 -0
- package/dist/core/edit/map.d.ts +24 -0
- package/dist/core/edit/map.js +82 -0
- package/dist/core/edit/map.js.map +1 -0
- package/dist/core/edit/names.d.ts +2 -0
- package/dist/core/edit/names.js +17 -0
- package/dist/core/edit/names.js.map +1 -0
- package/dist/core/edit/paths.d.ts +8 -0
- package/dist/core/edit/paths.js +76 -0
- package/dist/core/edit/paths.js.map +1 -0
- package/dist/core/edit/pipeline.d.ts +19 -0
- package/dist/core/edit/pipeline.js +146 -0
- package/dist/core/edit/pipeline.js.map +1 -0
- package/dist/core/edit/skill.d.ts +1 -0
- package/dist/core/edit/skill.js +10 -0
- package/dist/core/edit/skill.js.map +1 -0
- package/dist/core/factory/discovery.d.ts +9 -0
- package/dist/core/factory/discovery.js +139 -0
- package/dist/core/factory/discovery.js.map +1 -0
- package/dist/core/factory/factory-yaml.d.ts +16 -0
- package/dist/core/factory/factory-yaml.js +375 -0
- package/dist/core/factory/factory-yaml.js.map +1 -0
- package/dist/core/factory/index.d.ts +5 -0
- package/dist/core/factory/index.js +6 -0
- package/dist/core/factory/index.js.map +1 -0
- package/dist/core/factory/lines.d.ts +8 -0
- package/dist/core/factory/lines.js +11 -0
- package/dist/core/factory/lines.js.map +1 -0
- package/dist/core/factory/load.d.ts +4 -0
- package/dist/core/factory/load.js +81 -0
- package/dist/core/factory/load.js.map +1 -0
- package/dist/core/factory/requires.d.ts +9 -0
- package/dist/core/factory/requires.js +123 -0
- package/dist/core/factory/requires.js.map +1 -0
- package/dist/core/factory/types.d.ts +45 -0
- package/dist/core/factory/types.js +2 -0
- package/dist/core/factory/types.js.map +1 -0
- package/dist/core/factory/validate.d.ts +41 -0
- package/dist/core/factory/validate.js +441 -0
- package/dist/core/factory/validate.js.map +1 -0
- package/dist/core/hooks/index.d.ts +8 -0
- package/dist/core/hooks/index.js +15 -0
- package/dist/core/hooks/index.js.map +1 -0
- package/dist/core/hooks/script.d.ts +21 -0
- package/dist/core/hooks/script.js +34 -0
- package/dist/core/hooks/script.js.map +1 -0
- package/dist/core/hooks/sync.d.ts +17 -0
- package/dist/core/hooks/sync.js +262 -0
- package/dist/core/hooks/sync.js.map +1 -0
- package/dist/core/import/conflicts.d.ts +82 -0
- package/dist/core/import/conflicts.js +256 -0
- package/dist/core/import/conflicts.js.map +1 -0
- package/dist/core/import/copy.d.ts +10 -0
- package/dist/core/import/copy.js +76 -0
- package/dist/core/import/copy.js.map +1 -0
- package/dist/core/import/file-tree.d.ts +43 -0
- package/dist/core/import/file-tree.js +107 -0
- package/dist/core/import/file-tree.js.map +1 -0
- package/dist/core/import/index.d.ts +5 -0
- package/dist/core/import/index.js +6 -0
- package/dist/core/import/index.js.map +1 -0
- package/dist/core/import/pipeline-changes.d.ts +8 -0
- package/dist/core/import/pipeline-changes.js +89 -0
- package/dist/core/import/pipeline-changes.js.map +1 -0
- package/dist/core/import/run.d.ts +76 -0
- package/dist/core/import/run.js +258 -0
- package/dist/core/import/run.js.map +1 -0
- package/dist/core/init/gitattributes.d.ts +20 -0
- package/dist/core/init/gitattributes.js +89 -0
- package/dist/core/init/gitattributes.js.map +1 -0
- package/dist/core/init/index.d.ts +4 -0
- package/dist/core/init/index.js +5 -0
- package/dist/core/init/index.js.map +1 -0
- package/dist/core/init/name.d.ts +1 -0
- package/dist/core/init/name.js +4 -0
- package/dist/core/init/name.js.map +1 -0
- package/dist/core/init/run.d.ts +51 -0
- package/dist/core/init/run.js +261 -0
- package/dist/core/init/run.js.map +1 -0
- package/dist/core/init/targets.d.ts +17 -0
- package/dist/core/init/targets.js +87 -0
- package/dist/core/init/targets.js.map +1 -0
- package/dist/core/merge.d.ts +88 -0
- package/dist/core/merge.js +239 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/publish/exclude.d.ts +9 -0
- package/dist/core/publish/exclude.js +32 -0
- package/dist/core/publish/exclude.js.map +1 -0
- package/dist/core/publish/git-target.d.ts +32 -0
- package/dist/core/publish/git-target.js +447 -0
- package/dist/core/publish/git-target.js.map +1 -0
- package/dist/core/publish/index.d.ts +10 -0
- package/dist/core/publish/index.js +11 -0
- package/dist/core/publish/index.js.map +1 -0
- package/dist/core/publish/npm-target.d.ts +15 -0
- package/dist/core/publish/npm-target.js +170 -0
- package/dist/core/publish/npm-target.js.map +1 -0
- package/dist/core/publish/package-json.d.ts +31 -0
- package/dist/core/publish/package-json.js +74 -0
- package/dist/core/publish/package-json.js.map +1 -0
- package/dist/core/publish/prepare.d.ts +24 -0
- package/dist/core/publish/prepare.js +93 -0
- package/dist/core/publish/prepare.js.map +1 -0
- package/dist/core/publish/provenance.d.ts +1 -0
- package/dist/core/publish/provenance.js +20 -0
- package/dist/core/publish/provenance.js.map +1 -0
- package/dist/core/publish/publish.d.ts +13 -0
- package/dist/core/publish/publish.js +130 -0
- package/dist/core/publish/publish.js.map +1 -0
- package/dist/core/publish/readme.d.ts +22 -0
- package/dist/core/publish/readme.js +112 -0
- package/dist/core/publish/readme.js.map +1 -0
- package/dist/core/publish/stage.d.ts +19 -0
- package/dist/core/publish/stage.js +333 -0
- package/dist/core/publish/stage.js.map +1 -0
- package/dist/core/publish/types.d.ts +71 -0
- package/dist/core/publish/types.js +2 -0
- package/dist/core/publish/types.js.map +1 -0
- package/dist/core/requires/check.d.ts +15 -0
- package/dist/core/requires/check.js +83 -0
- package/dist/core/requires/check.js.map +1 -0
- package/dist/core/requires/index.d.ts +4 -0
- package/dist/core/requires/index.js +5 -0
- package/dist/core/requires/index.js.map +1 -0
- package/dist/core/requires/inspect.d.ts +44 -0
- package/dist/core/requires/inspect.js +114 -0
- package/dist/core/requires/inspect.js.map +1 -0
- package/dist/core/requires/paths.d.ts +29 -0
- package/dist/core/requires/paths.js +83 -0
- package/dist/core/requires/paths.js.map +1 -0
- package/dist/core/requires/setup.d.ts +37 -0
- package/dist/core/requires/setup.js +147 -0
- package/dist/core/requires/setup.js.map +1 -0
- package/dist/core/setup.d.ts +27 -0
- package/dist/core/setup.js +84 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/core/sources/cache.d.ts +38 -0
- package/dist/core/sources/cache.js +200 -0
- package/dist/core/sources/cache.js.map +1 -0
- package/dist/core/sources/containment.d.ts +21 -0
- package/dist/core/sources/containment.js +50 -0
- package/dist/core/sources/containment.js.map +1 -0
- package/dist/core/sources/env.d.ts +12 -0
- package/dist/core/sources/env.js +28 -0
- package/dist/core/sources/env.js.map +1 -0
- package/dist/core/sources/extract.d.ts +25 -0
- package/dist/core/sources/extract.js +676 -0
- package/dist/core/sources/extract.js.map +1 -0
- package/dist/core/sources/git-process.d.ts +26 -0
- package/dist/core/sources/git-process.js +51 -0
- package/dist/core/sources/git-process.js.map +1 -0
- package/dist/core/sources/git.d.ts +41 -0
- package/dist/core/sources/git.js +511 -0
- package/dist/core/sources/git.js.map +1 -0
- package/dist/core/sources/https.d.ts +21 -0
- package/dist/core/sources/https.js +208 -0
- package/dist/core/sources/https.js.map +1 -0
- package/dist/core/sources/index.d.ts +13 -0
- package/dist/core/sources/index.js +14 -0
- package/dist/core/sources/index.js.map +1 -0
- package/dist/core/sources/npm-cli.d.ts +19 -0
- package/dist/core/sources/npm-cli.js +43 -0
- package/dist/core/sources/npm-cli.js.map +1 -0
- package/dist/core/sources/npm.d.ts +29 -0
- package/dist/core/sources/npm.js +386 -0
- package/dist/core/sources/npm.js.map +1 -0
- package/dist/core/sources/parse.d.ts +32 -0
- package/dist/core/sources/parse.js +389 -0
- package/dist/core/sources/parse.js.map +1 -0
- package/dist/core/sources/path.d.ts +10 -0
- package/dist/core/sources/path.js +316 -0
- package/dist/core/sources/path.js.map +1 -0
- package/dist/core/sources/redact.d.ts +2 -0
- package/dist/core/sources/redact.js +70 -0
- package/dist/core/sources/redact.js.map +1 -0
- package/dist/core/sources/resolve.d.ts +9 -0
- package/dist/core/sources/resolve.js +29 -0
- package/dist/core/sources/resolve.js.map +1 -0
- package/dist/core/sources/types.d.ts +86 -0
- package/dist/core/sources/types.js +2 -0
- package/dist/core/sources/types.js.map +1 -0
- package/dist/core/sources/validate.d.ts +9 -0
- package/dist/core/sources/validate.js +111 -0
- package/dist/core/sources/validate.js.map +1 -0
- package/dist/core/summary.d.ts +77 -0
- package/dist/core/summary.js +405 -0
- package/dist/core/summary.js.map +1 -0
- package/dist/core/update/clashes.d.ts +63 -0
- package/dist/core/update/clashes.js +192 -0
- package/dist/core/update/clashes.js.map +1 -0
- package/dist/core/update/detach.d.ts +21 -0
- package/dist/core/update/detach.js +38 -0
- package/dist/core/update/detach.js.map +1 -0
- package/dist/core/update/diff.d.ts +58 -0
- package/dist/core/update/diff.js +180 -0
- package/dist/core/update/diff.js.map +1 -0
- package/dist/core/update/fetch.d.ts +34 -0
- package/dist/core/update/fetch.js +73 -0
- package/dist/core/update/fetch.js.map +1 -0
- package/dist/core/update/index.d.ts +6 -0
- package/dist/core/update/index.js +7 -0
- package/dist/core/update/index.js.map +1 -0
- package/dist/core/update/restore.d.ts +20 -0
- package/dist/core/update/restore.js +195 -0
- package/dist/core/update/restore.js.map +1 -0
- package/dist/core/update/run.d.ts +113 -0
- package/dist/core/update/run.js +1132 -0
- package/dist/core/update/run.js.map +1 -0
- package/dist/core/update/select.d.ts +39 -0
- package/dist/core/update/select.js +157 -0
- package/dist/core/update/select.js.map +1 -0
- package/dist/core/update/spelling.d.ts +51 -0
- package/dist/core/update/spelling.js +185 -0
- package/dist/core/update/spelling.js.map +1 -0
- package/dist/core/update/trees.d.ts +24 -0
- package/dist/core/update/trees.js +72 -0
- package/dist/core/update/trees.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +46 -0
- package/dist/help.js +103 -0
- package/dist/help.js.map +1 -0
- package/dist/input.d.ts +25 -0
- package/dist/input.js +173 -0
- package/dist/input.js.map +1 -0
- package/dist/output.d.ts +21 -0
- package/dist/output.js +37 -0
- package/dist/output.js.map +1 -0
- package/dist/util/frontmatter.d.ts +12 -0
- package/dist/util/frontmatter.js +58 -0
- package/dist/util/frontmatter.js.map +1 -0
- package/dist/util/fs.d.ts +32 -0
- package/dist/util/fs.js +126 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/git-names.d.ts +8 -0
- package/dist/util/git-names.js +25 -0
- package/dist/util/git-names.js.map +1 -0
- package/dist/util/git.d.ts +12 -0
- package/dist/util/git.js +33 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/suggest.d.ts +6 -0
- package/dist/util/suggest.js +48 -0
- package/dist/util/suggest.js.map +1 -0
- package/dist/util/text.d.ts +8 -0
- package/dist/util/text.js +19 -0
- package/dist/util/text.js.map +1 -0
- package/dist/util/version.d.ts +7 -0
- package/dist/util/version.js +13 -0
- package/dist/util/version.js.map +1 -0
- package/dist/util/yaml.d.ts +30 -0
- package/dist/util/yaml.js +201 -0
- package/dist/util/yaml.js.map +1 -0
- package/package.json +51 -4
- package/resources/metafab-skill/SKILL.md +99 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { lstat, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readdirTyped } from "../../util/fs.js";
|
|
4
|
+
import { FACTORY_TEMPLATES_PREFIX, factoryRelative, requirementPathProblem } from "../requires/paths.js";
|
|
5
|
+
import { isInsideAbsolute } from "../sources/containment.js";
|
|
6
|
+
function isAbsentError(error) {
|
|
7
|
+
const code = error?.code;
|
|
8
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
9
|
+
}
|
|
10
|
+
function templateProblem(requirement, file, message, fix) {
|
|
11
|
+
return { level: "error", file, line: requirement.line, message, fix };
|
|
12
|
+
}
|
|
13
|
+
function skillProblem(requirement, file, template) {
|
|
14
|
+
return templateProblem(requirement, file, `Template "${template}" is part of a skill, so it would be installed`, "Move it out of the skill directory");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Rule 13's skill half: no directory from `.factory/templates/` down to the
|
|
18
|
+
* template's own directory may hold an entry named `SKILL.md`, in any case, so
|
|
19
|
+
* the template is never installed as part of a skill. The check reads each
|
|
20
|
+
* directory itself with `readdirTyped` rather than using `factory.skills`,
|
|
21
|
+
* because discovery skips dot directories and matches `SKILL.md` exactly.
|
|
22
|
+
*/
|
|
23
|
+
async function skillTemplateProblem(factory, requirement, template, file) {
|
|
24
|
+
const relative = factoryRelative(template);
|
|
25
|
+
const segments = relative.split("/");
|
|
26
|
+
const base = segments[segments.length - 1] ?? "";
|
|
27
|
+
if (base.toLowerCase() === "skill.md")
|
|
28
|
+
return skillProblem(requirement, file, template);
|
|
29
|
+
for (let depth = 1; depth < segments.length; depth += 1) {
|
|
30
|
+
const parts = segments.slice(0, depth);
|
|
31
|
+
const relativeDir = parts.join("/");
|
|
32
|
+
const directory = path.join(factory.dir, ...parts);
|
|
33
|
+
let entries;
|
|
34
|
+
try {
|
|
35
|
+
entries = await readdirTyped(directory);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// An absent directory is reported by the template's own existence check.
|
|
39
|
+
if (isAbsentError(error))
|
|
40
|
+
return undefined;
|
|
41
|
+
return {
|
|
42
|
+
level: "error",
|
|
43
|
+
file: `.factory/${relativeDir}`,
|
|
44
|
+
line: 1,
|
|
45
|
+
message: `Cannot read directory .factory/${relativeDir}`,
|
|
46
|
+
fix: "Check its permissions or restore the directory",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (entries.some((entry) => entry.name.toLowerCase() === "skill.md")) {
|
|
50
|
+
return skillProblem(requirement, file, template);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Rule 13: each `requires` template is a file under `.factory/templates/` that
|
|
57
|
+
* `import` and `update` may copy, and that `build` never installs as a skill.
|
|
58
|
+
* A caller has already parsed `factory.yaml`, so a template with no prefix or
|
|
59
|
+
* an unsafe path is reported here rather than by rule 12.
|
|
60
|
+
*/
|
|
61
|
+
export async function requirementTemplateProblems(factory, requires, file) {
|
|
62
|
+
const problems = [];
|
|
63
|
+
const factoryReal = await realpath(factory.dir).catch(() => undefined);
|
|
64
|
+
for (const requirement of requires) {
|
|
65
|
+
const template = requirement.template;
|
|
66
|
+
if (template === undefined)
|
|
67
|
+
continue;
|
|
68
|
+
if (!template.startsWith(FACTORY_TEMPLATES_PREFIX) ||
|
|
69
|
+
requirementPathProblem(factoryRelative(template)) !== undefined) {
|
|
70
|
+
problems.push(templateProblem(requirement, file, `Template "${template}" must be a file in .factory/templates/`, "Move the template into .factory/templates/ and update the path"));
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const skill = await skillTemplateProblem(factory, requirement, template, file);
|
|
74
|
+
if (skill !== undefined) {
|
|
75
|
+
problems.push(skill);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const absolute = path.join(factory.root, ...template.split("/"));
|
|
79
|
+
let info;
|
|
80
|
+
try {
|
|
81
|
+
info = await lstat(absolute);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (isAbsentError(error)) {
|
|
85
|
+
problems.push(templateProblem(requirement, file, `Template "${template}" does not exist`, "Add the file or correct the path"));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
problems.push(templateProblem(requirement, file, `Cannot read file ${template}`, "Check its permissions or restore the file"));
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const notRegular = () => {
|
|
93
|
+
problems.push(templateProblem(requirement, file, `Template "${template}" is not a regular file inside .factory/`, "Replace it with a file"));
|
|
94
|
+
};
|
|
95
|
+
// A link at the template itself is followed below. So is a link in any
|
|
96
|
+
// parent: `lstat` resolves intermediate links, so a directory link under
|
|
97
|
+
// `.factory/templates/` would make a file outside `.factory/` look like a
|
|
98
|
+
// regular template. The real path of every template must stay inside the
|
|
99
|
+
// factory, whatever spelling led there.
|
|
100
|
+
if (!info.isSymbolicLink() && !info.isFile()) {
|
|
101
|
+
notRegular();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let resolved;
|
|
105
|
+
try {
|
|
106
|
+
resolved = await realpath(absolute);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// A dangling link has nothing to resolve.
|
|
110
|
+
notRegular();
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (factoryReal === undefined || !isInsideAbsolute(factoryReal, resolved)) {
|
|
114
|
+
notRegular();
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const target = await stat(resolved).catch(() => undefined);
|
|
118
|
+
if (target === undefined || !target.isFile())
|
|
119
|
+
notRegular();
|
|
120
|
+
}
|
|
121
|
+
return problems;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=requires.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requires.js","sourceRoot":"","sources":["../../../src/core/factory/requires.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B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,eAAe,CACb,WAAW,EACX,IAAI,EACJ,aAAa,QAAQ,0CAA0C,EAC/D,wBAAwB,CACzB,CACF,CAAC;QACJ,CAAC,CAAC;QAEF,uEAAuE;QACvE,yEAAyE;QACzE,0EAA0E;QAC1E,yEAAyE;QACzE,wCAAwC;QACxC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YAC7C,UAAU,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QAED,IAAI,QAAgB,CAAC;QACrB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,0CAA0C;YAC1C,UAAU,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QACD,IAAI,WAAW,KAAK,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC1E,UAAU,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAAE,UAAU,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Document } from "yaml";
|
|
2
|
+
import type { Problem } from "../../errors.js";
|
|
3
|
+
export interface Factory {
|
|
4
|
+
root: string;
|
|
5
|
+
dir: string;
|
|
6
|
+
factoryYaml?: FactoryYaml;
|
|
7
|
+
agentsMd?: string;
|
|
8
|
+
skills: Skill[];
|
|
9
|
+
problems: Problem[];
|
|
10
|
+
}
|
|
11
|
+
export interface FactoryYaml {
|
|
12
|
+
format: 1;
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
pipeline: PipelineEntry[];
|
|
16
|
+
/** Repository files the workflows need outside `.factory/`; empty when none. */
|
|
17
|
+
requires: Requirement[];
|
|
18
|
+
doc: Document.Parsed;
|
|
19
|
+
}
|
|
20
|
+
export interface PipelineEntry {
|
|
21
|
+
workflow: string;
|
|
22
|
+
stop?: string;
|
|
23
|
+
line: number;
|
|
24
|
+
}
|
|
25
|
+
export interface Requirement {
|
|
26
|
+
/** Repository-relative, `/`-separated. */
|
|
27
|
+
path: string;
|
|
28
|
+
description: string;
|
|
29
|
+
/** Repository-relative, starts with `.factory/templates/`. */
|
|
30
|
+
template?: string;
|
|
31
|
+
/** Line of the entry in `factory.yaml`. */
|
|
32
|
+
line: number;
|
|
33
|
+
}
|
|
34
|
+
export interface Skill {
|
|
35
|
+
name: string;
|
|
36
|
+
relDir: string;
|
|
37
|
+
group: string;
|
|
38
|
+
isWorkflow: boolean;
|
|
39
|
+
frontmatter: Record<string, unknown>;
|
|
40
|
+
frontmatterLines: {
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
};
|
|
44
|
+
title?: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/factory/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
import type { Factory, PipelineEntry, Requirement, Skill } from "./types.js";
|
|
3
|
+
export declare const KNOWN_FACTORY_FIELDS: readonly ["format", "name", "description", "pipeline", "requires"];
|
|
4
|
+
export declare const RESERVED_PIPELINE_OPTIONS: readonly ["stage", "find", "where"];
|
|
5
|
+
export declare const RESERVED_CONTAINERS: readonly ["workflows", "skills", "templates", "scripts", "scorers", "rules", "runtimes"];
|
|
6
|
+
export declare function skillFile(skill: Skill): string;
|
|
7
|
+
export declare function slugify(value: string): string;
|
|
8
|
+
export declare function rule1RequiredFields(skill: Skill): Problem[];
|
|
9
|
+
export declare function rule2NameMatchesDirectory(skill: Skill): Problem[];
|
|
10
|
+
export declare function ruleTopLevelSkill(file: string): Problem[];
|
|
11
|
+
export declare function rule3NoNestedSkills(file: string, line: number, nestedDir: string, parentDir: string): Problem[];
|
|
12
|
+
export declare function rule4UniqueNames(skills: Skill[]): Problem[];
|
|
13
|
+
export declare function rule5NameFormat(skill: Skill): Problem[];
|
|
14
|
+
export declare function rule6SkillGrammar(skill: Skill): Problem[];
|
|
15
|
+
export interface FactoryField {
|
|
16
|
+
value: unknown;
|
|
17
|
+
line: number;
|
|
18
|
+
node?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export declare function isFormatOne(field: FactoryField): boolean;
|
|
21
|
+
export declare function rule7FactoryYaml(file: string, fields: {
|
|
22
|
+
format?: FactoryField;
|
|
23
|
+
name?: FactoryField;
|
|
24
|
+
}): Problem[];
|
|
25
|
+
export declare function rule8PipelineWorkflows(pipeline: PipelineEntry[], skills: Skill[]): Problem[];
|
|
26
|
+
export declare function rule9PipelineOptions(file: string, key: string, line: number): Problem[];
|
|
27
|
+
/** Rule 12: a required path is safe to create in any repository. */
|
|
28
|
+
export declare function rule12RequirementPath(file: string, requirement: Requirement): Problem[];
|
|
29
|
+
/**
|
|
30
|
+
* Rule 12, uniqueness: no two required paths are equal when letter case is
|
|
31
|
+
* ignored, and none is below another. The entry listed later is the one
|
|
32
|
+
* reported, because it is the one that repeats or nests.
|
|
33
|
+
*/
|
|
34
|
+
export declare function rule12UniqueRequirements(file: string, requirements: Requirement[]): Problem[];
|
|
35
|
+
export declare function rule10ReservedPrefix(skill: Skill): Problem[];
|
|
36
|
+
export declare function rule11ReservedContainer(file: string): Problem[];
|
|
37
|
+
export declare function rule6UnknownFactoryField(file: string, key: string, line: number): Problem[];
|
|
38
|
+
export declare function rule6UnknownPipelineOption(file: string, key: string, line: number): Problem[];
|
|
39
|
+
export declare function rule6FactoryName(file: string, field: FactoryField): Problem[];
|
|
40
|
+
export declare function rule6FactoryDescription(file: string, field: FactoryField): Problem[];
|
|
41
|
+
export declare function validateFactory(factory: Factory): Problem[];
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { isScalar } from "yaml";
|
|
2
|
+
import { isSingleLine } from "../../util/text.js";
|
|
3
|
+
import { didYouMean } from "../../util/suggest.js";
|
|
4
|
+
import { requirementPathProblem } from "../requires/paths.js";
|
|
5
|
+
import { descriptionLine, nameLine } from "./lines.js";
|
|
6
|
+
export const KNOWN_FACTORY_FIELDS = ["format", "name", "description", "pipeline", "requires"];
|
|
7
|
+
export const RESERVED_PIPELINE_OPTIONS = ["stage", "find", "where"];
|
|
8
|
+
export const RESERVED_CONTAINERS = [
|
|
9
|
+
"workflows",
|
|
10
|
+
"skills",
|
|
11
|
+
"templates",
|
|
12
|
+
"scripts",
|
|
13
|
+
"scorers",
|
|
14
|
+
"rules",
|
|
15
|
+
"runtimes",
|
|
16
|
+
];
|
|
17
|
+
const MAX_SKILL_NAME_LENGTH = 64;
|
|
18
|
+
const SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
19
|
+
const FACTORY_NAME_PATTERN = /^[a-z0-9-]+$/;
|
|
20
|
+
const YAML_INTEGER_PATTERN = /^(?:[-+]?[0-9]+|0o[0-7]+|0x[0-9a-fA-F]+)$/;
|
|
21
|
+
const RESERVED_PREFIX = "metafab";
|
|
22
|
+
export function skillFile(skill) {
|
|
23
|
+
return `.factory/${skill.relDir}/SKILL.md`;
|
|
24
|
+
}
|
|
25
|
+
export function slugify(value) {
|
|
26
|
+
const slug = value
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
29
|
+
.replace(/-{2,}/g, "-")
|
|
30
|
+
.replace(/^-+|-+$/g, "")
|
|
31
|
+
.slice(0, MAX_SKILL_NAME_LENGTH)
|
|
32
|
+
.replace(/-+$/g, "");
|
|
33
|
+
return slug === "" ? "skill" : slug;
|
|
34
|
+
}
|
|
35
|
+
export function rule1RequiredFields(skill) {
|
|
36
|
+
const problems = [];
|
|
37
|
+
const file = skillFile(skill);
|
|
38
|
+
if (skill.frontmatter.name === undefined) {
|
|
39
|
+
problems.push({
|
|
40
|
+
level: "error",
|
|
41
|
+
file,
|
|
42
|
+
line: skill.frontmatterLines.start,
|
|
43
|
+
message: 'SKILL.md is missing a "name" field',
|
|
44
|
+
fix: `Add a name: ${skill.name} field`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (skill.frontmatter.description === undefined) {
|
|
48
|
+
problems.push({
|
|
49
|
+
level: "error",
|
|
50
|
+
file,
|
|
51
|
+
line: skill.frontmatterLines.start,
|
|
52
|
+
message: 'SKILL.md is missing a "description" field',
|
|
53
|
+
fix: "Add a description field",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return problems;
|
|
57
|
+
}
|
|
58
|
+
export function rule2NameMatchesDirectory(skill) {
|
|
59
|
+
const name = skill.frontmatter.name;
|
|
60
|
+
if (typeof name !== "string" || name === "" || name === skill.name)
|
|
61
|
+
return [];
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
level: "error",
|
|
65
|
+
file: skillFile(skill),
|
|
66
|
+
line: nameLine(skill),
|
|
67
|
+
message: `Skill name "${name}" does not match its directory "${skill.name}"`,
|
|
68
|
+
fix: `Change name to '${skill.name}' or rename the directory`,
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
export function ruleTopLevelSkill(file) {
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
level: "error",
|
|
76
|
+
file,
|
|
77
|
+
line: 1,
|
|
78
|
+
message: "SKILL.md must live inside a skill directory",
|
|
79
|
+
fix: "Move it into a directory such as .factory/skills/<name>/SKILL.md",
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
export function rule3NoNestedSkills(file, line, nestedDir, parentDir) {
|
|
84
|
+
return [
|
|
85
|
+
{
|
|
86
|
+
level: "error",
|
|
87
|
+
file,
|
|
88
|
+
line,
|
|
89
|
+
message: `Nested skill directory: "${nestedDir}"`,
|
|
90
|
+
fix: `Move ${nestedDir} out of ${parentDir}`,
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
export function rule4UniqueNames(skills) {
|
|
95
|
+
const problems = [];
|
|
96
|
+
const firstByName = new Map();
|
|
97
|
+
for (const skill of skills) {
|
|
98
|
+
const name = skill.frontmatter.name;
|
|
99
|
+
if (typeof name !== "string" || name === "")
|
|
100
|
+
continue;
|
|
101
|
+
const first = firstByName.get(name);
|
|
102
|
+
if (first === undefined) {
|
|
103
|
+
firstByName.set(name, skill);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
problems.push({
|
|
107
|
+
level: "error",
|
|
108
|
+
file: skillFile(skill),
|
|
109
|
+
line: nameLine(skill),
|
|
110
|
+
message: `Duplicate skill name "${name}"`,
|
|
111
|
+
fix: `Rename one of: ${skillFile(first)}, ${skillFile(skill)}`,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return problems;
|
|
115
|
+
}
|
|
116
|
+
export function rule5NameFormat(skill) {
|
|
117
|
+
const name = skill.frontmatter.name;
|
|
118
|
+
if (typeof name !== "string" || name === "")
|
|
119
|
+
return [];
|
|
120
|
+
if (name.length <= MAX_SKILL_NAME_LENGTH && SKILL_NAME_PATTERN.test(name))
|
|
121
|
+
return [];
|
|
122
|
+
return [
|
|
123
|
+
{
|
|
124
|
+
level: "error",
|
|
125
|
+
file: skillFile(skill),
|
|
126
|
+
line: nameLine(skill),
|
|
127
|
+
message: `Skill name "${name}" is not a valid Agent Skill name`,
|
|
128
|
+
fix: `Use a name like '${slugify(name)}'`,
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
export function rule6SkillGrammar(skill) {
|
|
133
|
+
const problems = [];
|
|
134
|
+
const file = skillFile(skill);
|
|
135
|
+
const name = skill.frontmatter.name;
|
|
136
|
+
if (name !== undefined && (typeof name !== "string" || name === "")) {
|
|
137
|
+
problems.push({
|
|
138
|
+
level: "error",
|
|
139
|
+
file,
|
|
140
|
+
line: nameLine(skill),
|
|
141
|
+
message: '"name" must be a non-empty string',
|
|
142
|
+
fix: `Add a name: ${skill.name} field`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const description = skill.frontmatter.description;
|
|
146
|
+
if (description !== undefined) {
|
|
147
|
+
if (typeof description !== "string" || description === "") {
|
|
148
|
+
problems.push({
|
|
149
|
+
level: "error",
|
|
150
|
+
file,
|
|
151
|
+
line: descriptionLine(skill),
|
|
152
|
+
message: '"description" must be a non-empty string',
|
|
153
|
+
fix: "Write a one-line description",
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else if (!isSingleLine(description)) {
|
|
157
|
+
problems.push({
|
|
158
|
+
level: "error",
|
|
159
|
+
file,
|
|
160
|
+
line: descriptionLine(skill),
|
|
161
|
+
message: '"description" must be a single line',
|
|
162
|
+
fix: "Write the description on one line",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return problems;
|
|
167
|
+
}
|
|
168
|
+
export function isFormatOne(field) {
|
|
169
|
+
if (field.node === undefined)
|
|
170
|
+
return field.value === 1;
|
|
171
|
+
if (!isScalar(field.node) || field.node.type !== "PLAIN" || field.node.value !== 1)
|
|
172
|
+
return false;
|
|
173
|
+
return typeof field.node.source === "string" && YAML_INTEGER_PATTERN.test(field.node.source);
|
|
174
|
+
}
|
|
175
|
+
export function rule7FactoryYaml(file, fields) {
|
|
176
|
+
const problems = [];
|
|
177
|
+
if (fields.format === undefined) {
|
|
178
|
+
problems.push({
|
|
179
|
+
level: "error",
|
|
180
|
+
file,
|
|
181
|
+
line: 1,
|
|
182
|
+
message: 'factory.yaml is missing "format"',
|
|
183
|
+
fix: "Add format: 1",
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (!isFormatOne(fields.format)) {
|
|
187
|
+
problems.push({
|
|
188
|
+
level: "error",
|
|
189
|
+
file,
|
|
190
|
+
line: fields.format.line,
|
|
191
|
+
message: '"format" must be the integer 1',
|
|
192
|
+
fix: "Set format to 1",
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (fields.name === undefined) {
|
|
196
|
+
problems.push({
|
|
197
|
+
level: "error",
|
|
198
|
+
file,
|
|
199
|
+
line: 1,
|
|
200
|
+
message: 'factory.yaml is missing "name"',
|
|
201
|
+
fix: "Add a name field",
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return problems;
|
|
205
|
+
}
|
|
206
|
+
export function rule8PipelineWorkflows(pipeline, skills) {
|
|
207
|
+
const problems = [];
|
|
208
|
+
const file = ".factory/factory.yaml";
|
|
209
|
+
const workflowNames = skills.filter((skill) => skill.isWorkflow).map((skill) => skill.name);
|
|
210
|
+
const workflowSet = new Set(workflowNames);
|
|
211
|
+
const otherSkillNames = new Set(skills.filter((skill) => !skill.isWorkflow).map((skill) => skill.name));
|
|
212
|
+
const seen = new Set();
|
|
213
|
+
for (const entry of pipeline) {
|
|
214
|
+
if (!workflowSet.has(entry.workflow)) {
|
|
215
|
+
const suggestion = didYouMean(entry.workflow, workflowNames);
|
|
216
|
+
const isNonWorkflowSkill = otherSkillNames.has(entry.workflow);
|
|
217
|
+
problems.push({
|
|
218
|
+
level: "error",
|
|
219
|
+
file,
|
|
220
|
+
line: entry.line,
|
|
221
|
+
message: isNonWorkflowSkill
|
|
222
|
+
? `Pipeline entry "${entry.workflow}" is a skill, not a workflow`
|
|
223
|
+
: `Pipeline names unknown workflow "${entry.workflow}"`,
|
|
224
|
+
fix: suggestion ??
|
|
225
|
+
(isNonWorkflowSkill
|
|
226
|
+
? "Move the skill under .factory/workflows/ or remove the entry"
|
|
227
|
+
: "Add it under .factory/workflows/ or remove the entry"),
|
|
228
|
+
});
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (seen.has(entry.workflow)) {
|
|
232
|
+
problems.push({
|
|
233
|
+
level: "error",
|
|
234
|
+
file,
|
|
235
|
+
line: entry.line,
|
|
236
|
+
message: `Duplicate pipeline entry "${entry.workflow}"`,
|
|
237
|
+
fix: `Remove one of the "${entry.workflow}" entries`,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
seen.add(entry.workflow);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return problems;
|
|
245
|
+
}
|
|
246
|
+
export function rule9PipelineOptions(file, key, line) {
|
|
247
|
+
if (!RESERVED_PIPELINE_OPTIONS.includes(key))
|
|
248
|
+
return [];
|
|
249
|
+
return [
|
|
250
|
+
{
|
|
251
|
+
level: "error",
|
|
252
|
+
file,
|
|
253
|
+
line,
|
|
254
|
+
message: `Pipeline option "${key}" is reserved for a future version`,
|
|
255
|
+
fix: `Remove the "${key}" option`,
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
/** Rule 12: a required path is safe to create in any repository. */
|
|
260
|
+
export function rule12RequirementPath(file, requirement) {
|
|
261
|
+
const phrase = requirementPathProblem(requirement.path);
|
|
262
|
+
if (phrase === undefined)
|
|
263
|
+
return [];
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
level: "error",
|
|
267
|
+
file,
|
|
268
|
+
line: requirement.line,
|
|
269
|
+
message: `Required path "${requirement.path}" ${phrase}`,
|
|
270
|
+
fix: "Use a repository-relative file path outside .factory/, such as docs/factory.md",
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Rule 12, uniqueness: no two required paths are equal when letter case is
|
|
276
|
+
* ignored, and none is below another. The entry listed later is the one
|
|
277
|
+
* reported, because it is the one that repeats or nests.
|
|
278
|
+
*/
|
|
279
|
+
export function rule12UniqueRequirements(file, requirements) {
|
|
280
|
+
const problems = [];
|
|
281
|
+
for (let index = 0; index < requirements.length; index += 1) {
|
|
282
|
+
const later = requirements[index];
|
|
283
|
+
const folded = later.path.toLowerCase();
|
|
284
|
+
for (let earlierIndex = 0; earlierIndex < index; earlierIndex += 1) {
|
|
285
|
+
const earlier = requirements[earlierIndex];
|
|
286
|
+
const earlierFolded = earlier.path.toLowerCase();
|
|
287
|
+
if (folded === earlierFolded) {
|
|
288
|
+
problems.push({
|
|
289
|
+
level: "error",
|
|
290
|
+
file,
|
|
291
|
+
line: later.line,
|
|
292
|
+
message: `Required path "${later.path}" repeats "${earlier.path}"`,
|
|
293
|
+
fix: "Remove one of the entries",
|
|
294
|
+
});
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
const [container, contained] = folded.startsWith(`${earlierFolded}/`)
|
|
298
|
+
? [earlier, later]
|
|
299
|
+
: earlierFolded.startsWith(`${folded}/`)
|
|
300
|
+
? [later, earlier]
|
|
301
|
+
: [undefined, undefined];
|
|
302
|
+
if (container === undefined || contained === undefined)
|
|
303
|
+
continue;
|
|
304
|
+
problems.push({
|
|
305
|
+
level: "error",
|
|
306
|
+
file,
|
|
307
|
+
line: later.line,
|
|
308
|
+
message: `Required path "${contained.path}" is inside required path "${container.path}"`,
|
|
309
|
+
fix: "Remove one of the entries",
|
|
310
|
+
});
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return problems;
|
|
315
|
+
}
|
|
316
|
+
export function rule10ReservedPrefix(skill) {
|
|
317
|
+
const name = skill.frontmatter.name;
|
|
318
|
+
if (typeof name !== "string" || !name.startsWith(RESERVED_PREFIX))
|
|
319
|
+
return [];
|
|
320
|
+
return [
|
|
321
|
+
{
|
|
322
|
+
level: "error",
|
|
323
|
+
file: skillFile(skill),
|
|
324
|
+
line: nameLine(skill),
|
|
325
|
+
message: `Skill name "${name}" uses the reserved "metafab" prefix`,
|
|
326
|
+
fix: 'Rename the skill so the name does not start with "metafab"',
|
|
327
|
+
},
|
|
328
|
+
];
|
|
329
|
+
}
|
|
330
|
+
const RESERVED_SKILL_PATH = /^\.factory\/([^/]+)\/SKILL\.md$/;
|
|
331
|
+
export function rule11ReservedContainer(file) {
|
|
332
|
+
const dir = RESERVED_SKILL_PATH.exec(file)?.[1] ?? file;
|
|
333
|
+
return [
|
|
334
|
+
{
|
|
335
|
+
level: "error",
|
|
336
|
+
file,
|
|
337
|
+
line: 1,
|
|
338
|
+
message: `${dir} is a reserved directory and cannot be a skill`,
|
|
339
|
+
fix: `Move the SKILL.md into .factory/${dir}/<name>/`,
|
|
340
|
+
},
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
export function rule6UnknownFactoryField(file, key, line) {
|
|
344
|
+
const suggestion = didYouMean(key, KNOWN_FACTORY_FIELDS);
|
|
345
|
+
return [
|
|
346
|
+
{
|
|
347
|
+
level: "error",
|
|
348
|
+
file,
|
|
349
|
+
line,
|
|
350
|
+
message: `Unknown field "${key}" in factory.yaml`,
|
|
351
|
+
fix: suggestion ??
|
|
352
|
+
`Remove the field or use a known name: ${KNOWN_FACTORY_FIELDS.join(", ")}`,
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
}
|
|
356
|
+
export function rule6UnknownPipelineOption(file, key, line) {
|
|
357
|
+
const suggestion = didYouMean(key, ["stop"]);
|
|
358
|
+
return [
|
|
359
|
+
{
|
|
360
|
+
level: "error",
|
|
361
|
+
file,
|
|
362
|
+
line,
|
|
363
|
+
message: `Unknown pipeline option "${key}"`,
|
|
364
|
+
fix: suggestion ?? 'Remove the option or use the "stop" option',
|
|
365
|
+
},
|
|
366
|
+
];
|
|
367
|
+
}
|
|
368
|
+
export function rule6FactoryName(file, field) {
|
|
369
|
+
const value = field.value;
|
|
370
|
+
if (typeof value !== "string" || value === "") {
|
|
371
|
+
return [
|
|
372
|
+
{
|
|
373
|
+
level: "error",
|
|
374
|
+
file,
|
|
375
|
+
line: field.line,
|
|
376
|
+
message: '"name" must be a non-empty string',
|
|
377
|
+
fix: "Add a name field",
|
|
378
|
+
},
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
if (!FACTORY_NAME_PATTERN.test(value)) {
|
|
382
|
+
return [
|
|
383
|
+
{
|
|
384
|
+
level: "error",
|
|
385
|
+
file,
|
|
386
|
+
line: field.line,
|
|
387
|
+
message: '"name" must use lowercase ASCII letters, digits, and hyphens',
|
|
388
|
+
fix: `Use a name like "${slugify(value)}"`,
|
|
389
|
+
},
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
return [];
|
|
393
|
+
}
|
|
394
|
+
export function rule6FactoryDescription(file, field) {
|
|
395
|
+
if (typeof field.value !== "string" || field.value === "") {
|
|
396
|
+
return [
|
|
397
|
+
{
|
|
398
|
+
level: "error",
|
|
399
|
+
file,
|
|
400
|
+
line: field.line,
|
|
401
|
+
message: '"description" must be a non-empty string',
|
|
402
|
+
fix: "Write a one-line description",
|
|
403
|
+
},
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
if (!isSingleLine(field.value)) {
|
|
407
|
+
return [
|
|
408
|
+
{
|
|
409
|
+
level: "error",
|
|
410
|
+
file,
|
|
411
|
+
line: field.line,
|
|
412
|
+
message: '"description" must be a single line',
|
|
413
|
+
fix: "Write the description on one line",
|
|
414
|
+
},
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
export function validateFactory(factory) {
|
|
420
|
+
const problems = [];
|
|
421
|
+
for (const skill of factory.skills) {
|
|
422
|
+
problems.push(...rule1RequiredFields(skill));
|
|
423
|
+
problems.push(...rule6SkillGrammar(skill));
|
|
424
|
+
const name = skill.frontmatter.name;
|
|
425
|
+
if (typeof name === "string" && name !== "") {
|
|
426
|
+
problems.push(...rule2NameMatchesDirectory(skill));
|
|
427
|
+
problems.push(...rule5NameFormat(skill));
|
|
428
|
+
problems.push(...rule10ReservedPrefix(skill));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
problems.push(...rule4UniqueNames(factory.skills));
|
|
432
|
+
if (factory.factoryYaml !== undefined) {
|
|
433
|
+
problems.push(...rule8PipelineWorkflows(factory.factoryYaml.pipeline, factory.skills));
|
|
434
|
+
for (const requirement of factory.factoryYaml.requires) {
|
|
435
|
+
problems.push(...rule12RequirementPath(".factory/factory.yaml", requirement));
|
|
436
|
+
}
|
|
437
|
+
problems.push(...rule12UniqueRequirements(".factory/factory.yaml", factory.factoryYaml.requires));
|
|
438
|
+
}
|
|
439
|
+
return problems;
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=validate.js.map
|