@seasb/metafab 2.0.0 → 2.1.1
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 +6 -0
- package/dist/cli.js +31 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/automations-list.d.ts +2 -0
- package/dist/commands/automations-list.js +81 -0
- package/dist/commands/automations-list.js.map +1 -0
- package/dist/commands/automations-plan.d.ts +2 -0
- package/dist/commands/automations-plan.js +146 -0
- package/dist/commands/automations-plan.js.map +1 -0
- package/dist/commands/automations-prompt.d.ts +2 -0
- package/dist/commands/automations-prompt.js +123 -0
- package/dist/commands/automations-prompt.js.map +1 -0
- package/dist/commands/automations-stub.d.ts +2 -0
- package/dist/commands/automations-stub.js +125 -0
- package/dist/commands/automations-stub.js.map +1 -0
- package/dist/commands/automations-sync.d.ts +2 -0
- package/dist/commands/automations-sync.js +104 -0
- package/dist/commands/automations-sync.js.map +1 -0
- package/dist/commands/create.js +18 -10
- package/dist/commands/create.js.map +1 -1
- package/dist/core/adopt.d.ts +4 -3
- package/dist/core/adopt.js +17 -10
- package/dist/core/adopt.js.map +1 -1
- package/dist/core/automations/account.d.ts +7 -0
- package/dist/core/automations/account.js +27 -0
- package/dist/core/automations/account.js.map +1 -0
- package/dist/core/automations/amp-schedule.d.ts +50 -0
- package/dist/core/automations/amp-schedule.js +272 -0
- package/dist/core/automations/amp-schedule.js.map +1 -0
- package/dist/core/automations/cron.d.ts +15 -0
- package/dist/core/automations/cron.js +75 -0
- package/dist/core/automations/cron.js.map +1 -0
- package/dist/core/automations/desired.d.ts +28 -0
- package/dist/core/automations/desired.js +95 -0
- package/dist/core/automations/desired.js.map +1 -0
- package/dist/core/automations/index.d.ts +10 -0
- package/dist/core/automations/index.js +11 -0
- package/dist/core/automations/index.js.map +1 -0
- package/dist/core/automations/load.d.ts +9 -0
- package/dist/core/automations/load.js +141 -0
- package/dist/core/automations/load.js.map +1 -0
- package/dist/core/automations/orca.d.ts +126 -0
- package/dist/core/automations/orca.js +513 -0
- package/dist/core/automations/orca.js.map +1 -0
- package/dist/core/automations/problems.d.ts +32 -0
- package/dist/core/automations/problems.js +110 -0
- package/dist/core/automations/problems.js.map +1 -0
- package/dist/core/automations/prompt.d.ts +38 -0
- package/dist/core/automations/prompt.js +211 -0
- package/dist/core/automations/prompt.js.map +1 -0
- package/dist/core/automations/stub.d.ts +40 -0
- package/dist/core/automations/stub.js +96 -0
- package/dist/core/automations/stub.js.map +1 -0
- package/dist/core/automations/types.d.ts +53 -0
- package/dist/core/automations/types.js +3 -0
- package/dist/core/automations/types.js.map +1 -0
- package/dist/core/automations/validate.d.ts +45 -0
- package/dist/core/automations/validate.js +594 -0
- package/dist/core/automations/validate.js.map +1 -0
- package/dist/core/build/agents.d.ts +16 -3
- package/dist/core/build/agents.js +125 -5
- package/dist/core/build/agents.js.map +1 -1
- package/dist/core/build/plan.js +51 -28
- package/dist/core/build/plan.js.map +1 -1
- package/dist/core/check/drift.js +5 -5
- package/dist/core/check/drift.js.map +1 -1
- package/dist/core/config/parse.js +7 -0
- package/dist/core/config/parse.js.map +1 -1
- package/dist/core/config/types.d.ts +5 -0
- package/dist/core/config/validate.d.ts +2 -1
- package/dist/core/config/validate.js +40 -1
- package/dist/core/config/validate.js.map +1 -1
- package/dist/core/edit/create.d.ts +14 -6
- package/dist/core/edit/create.js +124 -34
- package/dist/core/edit/create.js.map +1 -1
- package/dist/core/edit/map.js +3 -3
- package/dist/core/edit/map.js.map +1 -1
- package/dist/core/edit/pipeline.js +13 -9
- package/dist/core/edit/pipeline.js.map +1 -1
- package/dist/core/edit/skill.d.ts +5 -0
- package/dist/core/edit/skill.js +9 -0
- package/dist/core/edit/skill.js.map +1 -1
- package/dist/core/env/declarations.d.ts +2 -1
- package/dist/core/env/declarations.js +4 -3
- package/dist/core/env/declarations.js.map +1 -1
- package/dist/core/env/render.d.ts +12 -0
- package/dist/core/env/render.js +51 -0
- package/dist/core/env/render.js.map +1 -1
- package/dist/core/env/validate.js +79 -5
- package/dist/core/env/validate.js.map +1 -1
- package/dist/core/factory/discovery.d.ts +12 -2
- package/dist/core/factory/discovery.js +119 -2
- package/dist/core/factory/discovery.js.map +1 -1
- package/dist/core/factory/factory-yaml.d.ts +2 -1
- package/dist/core/factory/factory-yaml.js +4 -3
- package/dist/core/factory/factory-yaml.js.map +1 -1
- package/dist/core/factory/format.d.ts +26 -0
- package/dist/core/factory/format.js +34 -0
- package/dist/core/factory/format.js.map +1 -0
- package/dist/core/factory/load.d.ts +2 -2
- package/dist/core/factory/load.js +129 -16
- package/dist/core/factory/load.js.map +1 -1
- package/dist/core/factory/types.d.ts +24 -1
- package/dist/core/factory/validate.d.ts +31 -5
- package/dist/core/factory/validate.js +154 -22
- package/dist/core/factory/validate.js.map +1 -1
- package/dist/core/hooks/script.d.ts +22 -0
- package/dist/core/hooks/script.js +17 -3
- package/dist/core/hooks/script.js.map +1 -1
- package/dist/core/import/run.js +6 -2
- package/dist/core/import/run.js.map +1 -1
- package/dist/core/publish/package-json.d.ts +2 -1
- package/dist/core/publish/package-json.js.map +1 -1
- package/dist/core/publish/readme.js +13 -3
- package/dist/core/publish/readme.js.map +1 -1
- package/dist/core/publish/stage.js +18 -3
- package/dist/core/publish/stage.js.map +1 -1
- package/dist/core/sources/npm.js +3 -2
- package/dist/core/sources/npm.js.map +1 -1
- package/dist/core/sources/types.d.ts +2 -1
- package/dist/core/sources/validate.js +3 -2
- package/dist/core/sources/validate.js.map +1 -1
- package/dist/core/summary.js +49 -13
- package/dist/core/summary.js.map +1 -1
- package/package.json +2 -2
- package/resources/metafab-automations-skill/SKILL.md +53 -0
- package/resources/metafab-skill/SKILL.md +14 -7
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isAbsentError, readdirTyped } from "../../util/fs.js";
|
|
4
|
+
import { parseFrontmatter } from "../../util/frontmatter.js";
|
|
5
|
+
import { supportsFeature } from "../factory/format.js";
|
|
6
|
+
import { automationFile, automationFileProblem, automationMissingFileProblem, automationNameProblems, automationProblems, automationSkillFileProblem, parseAutomation, } from "./validate.js";
|
|
7
|
+
const AUTOMATIONS_DIR = "automations";
|
|
8
|
+
function byName(left, right) {
|
|
9
|
+
return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;
|
|
10
|
+
}
|
|
11
|
+
function readProblem(file, directory) {
|
|
12
|
+
return directory
|
|
13
|
+
? {
|
|
14
|
+
level: "error",
|
|
15
|
+
file,
|
|
16
|
+
line: 1,
|
|
17
|
+
message: `Cannot read directory ${file}`,
|
|
18
|
+
fix: "Check its permissions or restore the directory",
|
|
19
|
+
}
|
|
20
|
+
: {
|
|
21
|
+
level: "error",
|
|
22
|
+
file,
|
|
23
|
+
line: 1,
|
|
24
|
+
message: `Cannot read file ${file}`,
|
|
25
|
+
fix: "Check its permissions or restore the file",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Finds the automation's `automation.md` directly inside its directory, and
|
|
30
|
+
* reports every `SKILL.md` below it. Other files and directories are allowed.
|
|
31
|
+
*/
|
|
32
|
+
async function walkAutomation(dir, display, problems, top) {
|
|
33
|
+
let entries;
|
|
34
|
+
try {
|
|
35
|
+
entries = await readdirTyped(dir);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!isAbsentError(error)) {
|
|
39
|
+
problems.push(readProblem(display, true));
|
|
40
|
+
return { readable: false };
|
|
41
|
+
}
|
|
42
|
+
return { readable: true };
|
|
43
|
+
}
|
|
44
|
+
entries.sort(byName);
|
|
45
|
+
const found = { readable: true };
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
const childDisplay = `${display}/${entry.name}`;
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
if (entry.name.startsWith("."))
|
|
50
|
+
continue;
|
|
51
|
+
const nested = await walkAutomation(path.join(dir, entry.name), childDisplay, problems, false);
|
|
52
|
+
if (!nested.readable)
|
|
53
|
+
found.readable = false;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (entry.name === "SKILL.md") {
|
|
57
|
+
problems.push(automationSkillFileProblem(childDisplay));
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (top && entry.name === "automation.md" && found.file === undefined) {
|
|
61
|
+
found.file = path.join(dir, entry.name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return found;
|
|
65
|
+
}
|
|
66
|
+
async function readAutomation(target, name, problems, bodies) {
|
|
67
|
+
const file = automationFile(name);
|
|
68
|
+
let text;
|
|
69
|
+
try {
|
|
70
|
+
text = await readFile(target, "utf8");
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
problems.push(readProblem(file, false));
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const parsed = parseFrontmatter(text);
|
|
77
|
+
if (!parsed.ok) {
|
|
78
|
+
for (const problem of parsed.problems) {
|
|
79
|
+
problems.push({ level: "error", file, ...problem });
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const result = parseAutomation(name, parsed);
|
|
84
|
+
problems.push(...result.problems);
|
|
85
|
+
bodies.push(result.body);
|
|
86
|
+
return result.automation;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reads `.factory/automations/` for a format 2 factory: the layout rules, then
|
|
90
|
+
* every `automation.md` and the rules that need all of them. Format 1 has no
|
|
91
|
+
* automations, so it loads none; `loadFactory` warns when the directory is
|
|
92
|
+
* non-empty there.
|
|
93
|
+
*/
|
|
94
|
+
export async function loadAutomations(factoryDir, factory) {
|
|
95
|
+
const result = { list: [], bodies: [], problems: [] };
|
|
96
|
+
if (!supportsFeature(factory.factoryYaml?.format, "automations"))
|
|
97
|
+
return result;
|
|
98
|
+
const dir = path.join(factoryDir, AUTOMATIONS_DIR);
|
|
99
|
+
let entries;
|
|
100
|
+
try {
|
|
101
|
+
entries = await readdirTyped(dir);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (!isAbsentError(error))
|
|
105
|
+
result.problems.push(readProblem(".factory/automations", true));
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
entries.sort(byName);
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
if (entry.name.startsWith("."))
|
|
112
|
+
continue;
|
|
113
|
+
result.problems.push(...automationNameProblems(entry.name));
|
|
114
|
+
const display = `.factory/automations/${entry.name}`;
|
|
115
|
+
const walk = await walkAutomation(path.join(dir, entry.name), display, result.problems, true);
|
|
116
|
+
if (walk.file === undefined) {
|
|
117
|
+
if (walk.readable)
|
|
118
|
+
result.problems.push(automationMissingFileProblem(entry.name));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const automation = await readAutomation(walk.file, entry.name, result.problems, result.bodies);
|
|
122
|
+
if (automation !== undefined)
|
|
123
|
+
result.list.push(automation);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
// A file directly in `automations/`: only `run.md` is allowed.
|
|
127
|
+
if (entry.name === "run.md") {
|
|
128
|
+
result.runFile = ".factory/automations/run.md";
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (entry.name === "SKILL.md") {
|
|
132
|
+
result.problems.push(automationSkillFileProblem(".factory/automations/SKILL.md"));
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
result.problems.push(automationFileProblem(`.factory/automations/${entry.name}`));
|
|
136
|
+
}
|
|
137
|
+
result.list.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
138
|
+
result.problems.push(...automationProblems(result.list));
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/core/automations/load.ts"],"names":[],"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,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/F,IAAI,UAAU,KAAK,SAAS;gBAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3D,SAAS;QACX,CAAC;QAED,+DAA+D;QAC/D,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,CAAC,OAAO,GAAG,6BAA6B,CAAC;YAC/C,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC9B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,0BAA0B,CAAC,+BAA+B,CAAC,CAAC,CAAC;YAClF,SAAS;QACX,CAAC;QACD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,wBAAwB,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAC/B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7D,CAAC;IACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { MetafabError } from "../../errors.js";
|
|
2
|
+
import type { Factory } from "../factory/types.js";
|
|
3
|
+
import type { DesiredEntry } from "./desired.js";
|
|
4
|
+
/** Runs the `orca` CLI with an argument list, never through a shell. */
|
|
5
|
+
export interface OrcaRunner {
|
|
6
|
+
(args: string[]): Promise<{
|
|
7
|
+
exitCode: number;
|
|
8
|
+
stdout: string;
|
|
9
|
+
stderr: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
/** One automation as `orca automations list --json` reports it. */
|
|
13
|
+
export interface OrcaAutomation {
|
|
14
|
+
id: string;
|
|
15
|
+
/** Orca's name for the automation, which sync sets to `automation: <name>`. */
|
|
16
|
+
name: string;
|
|
17
|
+
prompt: string;
|
|
18
|
+
/** The cron, as `--trigger` gave it. */
|
|
19
|
+
rrule?: string;
|
|
20
|
+
timezone?: string;
|
|
21
|
+
agentId?: string;
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
/** Epoch milliseconds; the oldest of two registrations with one name is kept. */
|
|
24
|
+
createdAt?: number;
|
|
25
|
+
/** Where the automation runs; this is how a registration belongs to a repository. */
|
|
26
|
+
runContext?: {
|
|
27
|
+
path?: string;
|
|
28
|
+
};
|
|
29
|
+
/** `new_per_run` for a worktree run, `existing` for the main checkout. */
|
|
30
|
+
workspaceMode?: string;
|
|
31
|
+
/** `<repoId>::<path>` for the main checkout, and null for a worktree. */
|
|
32
|
+
workspaceId?: string | null;
|
|
33
|
+
baseBranch?: string;
|
|
34
|
+
/** Whether a worktree run runs the repository's setup: `run` or `skip`. */
|
|
35
|
+
setupDecision?: string;
|
|
36
|
+
/** Whether a run reuses its agent session; sync requires a fresh one. */
|
|
37
|
+
reuseSession?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** One call sync makes. `args` are the `orca` arguments, without the runner's flags. */
|
|
40
|
+
export interface OrcaChange {
|
|
41
|
+
kind: "create" | "update" | "disable" | "remove";
|
|
42
|
+
name: string;
|
|
43
|
+
args: string[];
|
|
44
|
+
/** For an update, the settings that differ, for the `~` line. */
|
|
45
|
+
fields: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface OrcaPlan {
|
|
48
|
+
changes: OrcaChange[];
|
|
49
|
+
/** Managed registrations that already match. */
|
|
50
|
+
unchanged: string[];
|
|
51
|
+
/** Entries titled `automation: ` that are not this factory's. */
|
|
52
|
+
leftAlone: string[];
|
|
53
|
+
/** The agent the planned registrations use. */
|
|
54
|
+
agent: string;
|
|
55
|
+
/** The main checkout the registrations name, for a `repo_not_found` fix. */
|
|
56
|
+
repoRoot: string;
|
|
57
|
+
}
|
|
58
|
+
export interface OrcaSyncResult {
|
|
59
|
+
created: string[];
|
|
60
|
+
updated: string[];
|
|
61
|
+
disabled: string[];
|
|
62
|
+
removed: string[];
|
|
63
|
+
unchanged: string[];
|
|
64
|
+
leftAlone: string[];
|
|
65
|
+
/** The changes that were applied, in plan order, for the human output. */
|
|
66
|
+
applied: OrcaChange[];
|
|
67
|
+
failure?: {
|
|
68
|
+
message: string;
|
|
69
|
+
fix: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** The human line for one change, as `sync orca` and `plan orca` print it. */
|
|
73
|
+
export declare function changeLine(change: OrcaChange): string;
|
|
74
|
+
/** A plan for one `sync orca` or `plan orca` run. */
|
|
75
|
+
export interface OrcaCommandPlan extends OrcaPlan {
|
|
76
|
+
desired: DesiredEntry[];
|
|
77
|
+
}
|
|
78
|
+
/** `orca` is not installed. */
|
|
79
|
+
export declare class OrcaMissingError extends MetafabError {
|
|
80
|
+
constructor();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The production runner: `orca [...args, --environment local, --json]`, so a
|
|
84
|
+
* paired remote Orca in the caller's environment never receives the sync.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createOrcaRunner(): OrcaRunner;
|
|
87
|
+
/**
|
|
88
|
+
* The repository's main checkout: the current checkout when Git says it is the
|
|
89
|
+
* main worktree, otherwise the first `worktree ` record of `git worktree list
|
|
90
|
+
* --porcelain`, which a sync run from a linked worktree names. Undefined when
|
|
91
|
+
* there is none, or it is bare, or it does not hold `.factory/` at this
|
|
92
|
+
* factory's relative path. `git worktree list` names the git directory rather
|
|
93
|
+
* than the checkout for a `--separate-git-dir` repository, which is why the
|
|
94
|
+
* current checkout wins when `--git-dir` and `--git-common-dir` agree.
|
|
95
|
+
*/
|
|
96
|
+
export declare function mainCheckout(factory: Factory): Promise<string | undefined>;
|
|
97
|
+
/** Reads the installed automations, or throws with Orca's message and fix. */
|
|
98
|
+
export declare function readOrcaAutomations(run: OrcaRunner, repoRoot: string): Promise<OrcaAutomation[]>;
|
|
99
|
+
/**
|
|
100
|
+
* The changes that make Orca match `desired`, or NeedsInput when the agent is
|
|
101
|
+
* missing. Nothing is written: `applyOrcaSync` runs the changes.
|
|
102
|
+
*/
|
|
103
|
+
export declare function planOrcaSync(input: {
|
|
104
|
+
desired: DesiredEntry[];
|
|
105
|
+
installed: OrcaAutomation[];
|
|
106
|
+
repoRoot: string;
|
|
107
|
+
factory: Factory;
|
|
108
|
+
account: string;
|
|
109
|
+
trunk: string;
|
|
110
|
+
agent?: string;
|
|
111
|
+
}): Promise<OrcaPlan>;
|
|
112
|
+
/** Runs the changes in plan order, stopping at the first call that fails. */
|
|
113
|
+
export declare function applyOrcaSync(changes: OrcaChange[], run: OrcaRunner, repoRoot: string): Promise<OrcaSyncResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Reads the files and Orca, then plans the sync: what both `sync orca` and
|
|
116
|
+
* `plan orca` need, before anything is written.
|
|
117
|
+
*/
|
|
118
|
+
export declare function prepareOrcaSync(input: {
|
|
119
|
+
factory: Factory;
|
|
120
|
+
account: string;
|
|
121
|
+
trunk: string;
|
|
122
|
+
agent?: string;
|
|
123
|
+
run: OrcaRunner;
|
|
124
|
+
}): Promise<OrcaCommandPlan>;
|
|
125
|
+
/** The result of a plan that is applied nowhere, as `--dry-run` reports it. */
|
|
126
|
+
export declare function plannedResult(plan: OrcaCommandPlan): OrcaSyncResult;
|