@davidbyoung/software-factory 0.1.5 → 0.1.6
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 +9 -8
- package/dist/cli.mjs +12 -0
- package/dist/config.d.mts +57 -3
- package/dist/config.mjs +268 -18
- package/dist/deps.d.mts +6 -4
- package/dist/deps.mjs +29 -7
- package/dist/doctor.d.mts +3 -0
- package/dist/doctor.mjs +7 -4
- package/dist/explain.d.mts +12 -1
- package/dist/explain.mjs +47 -32
- package/dist/init.mjs +6 -4
- package/dist/lib/default-branch.d.mts +1 -1
- package/dist/lib/default-branch.mjs +2 -2
- package/dist/preset-commands.d.mts +65 -0
- package/dist/preset-commands.mjs +1148 -0
- package/dist/preset.d.mts +169 -0
- package/dist/preset.mjs +550 -0
- package/dist/remove.mjs +34 -1
- package/dist/session-start.d.mts +3 -0
- package/dist/session-start.mjs +12 -1
- package/dist/sync.d.mts +42 -7
- package/dist/sync.mjs +165 -31
- package/docs/builds.md +12 -11
- package/docs/cli.md +21 -2
- package/docs/configuration.md +65 -13
- package/docs/developing.md +9 -2
- package/docs/github/by-hand.md +5 -5
- package/docs/github/reference.md +2 -17
- package/docs/github/setup.md +1 -1
- package/docs/glossary.md +12 -2
- package/docs/limitations.md +3 -0
- package/docs/plugins.md +16 -5
- package/docs/presets.md +410 -0
- package/docs/quick-start.md +20 -17
- package/docs/skills.md +21 -16
- package/docs/updating.md +14 -7
- package/docs/workflow.md +12 -13
- package/package.json +1 -1
- package/settings.schema.json +52 -3
- package/skills/factory-deps/SKILL.md +23 -12
- package/skills/factory-design/SKILL.md +1 -1
- package/skills/factory-resolve-conflicts/SKILL.md +6 -0
- package/workflows/factory-claude-review.yml +7 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ request to read. You decide what merges.
|
|
|
36
36
|
flowchart LR
|
|
37
37
|
A[You write a ticket] --> B[Refine: a session asks your decisions and writes the spec]
|
|
38
38
|
B --> C{You approve}
|
|
39
|
-
C -->|
|
|
39
|
+
C -->|"run /factory-build N in a session"| D[Build: on your machine]
|
|
40
40
|
C -->|move its card to Ready| E[Build: in the cloud]
|
|
41
41
|
D --> F[A pull request, with tests and a review]
|
|
42
42
|
E --> F
|
|
@@ -101,13 +101,14 @@ else is optional and comes later.
|
|
|
101
101
|
|
|
102
102
|
**Guides**
|
|
103
103
|
|
|
104
|
-
| Page | For
|
|
105
|
-
| -------------------------------------------------------------- |
|
|
106
|
-
| [Adopting it in an existing repository](docs/existing-repo.md) | Not JavaScript, an existing board, a team
|
|
107
|
-
| [Plugins](docs/plugins.md) | Putting your own skills and agents to work
|
|
108
|
-
| [
|
|
109
|
-
| [
|
|
110
|
-
| [
|
|
104
|
+
| Page | For |
|
|
105
|
+
| -------------------------------------------------------------- | -------------------------------------------- |
|
|
106
|
+
| [Adopting it in an existing repository](docs/existing-repo.md) | Not JavaScript, an existing board, a team |
|
|
107
|
+
| [Plugins](docs/plugins.md) | Putting your own skills and agents to work |
|
|
108
|
+
| [Presets](docs/presets.md) | Sharing settings across several repositories |
|
|
109
|
+
| [Builds in the cloud](docs/builds.md) | Starting builds from your board |
|
|
110
|
+
| [Updating](docs/updating.md) | Getting a new version |
|
|
111
|
+
| [What it changes, and removing it](docs/removing.md) | Everything it adds, and how to undo it |
|
|
111
112
|
|
|
112
113
|
**Reference**
|
|
113
114
|
|
package/dist/cli.mjs
CHANGED
|
@@ -141,6 +141,18 @@ export const COMMANDS = [
|
|
|
141
141
|
args: "",
|
|
142
142
|
run: async (argv) => (await import("./remove.mjs")).run(argv),
|
|
143
143
|
},
|
|
144
|
+
...[
|
|
145
|
+
["add", "NAME [--yes] [--dry-run]"],
|
|
146
|
+
["remove", "NAME [--yes] [--dry-run]"],
|
|
147
|
+
["choices", ""],
|
|
148
|
+
["choose", "KEY PRESET"],
|
|
149
|
+
["check", ""],
|
|
150
|
+
["changes", "REF"],
|
|
151
|
+
].map(([sub, args]) => ({
|
|
152
|
+
words: ["preset", sub],
|
|
153
|
+
args,
|
|
154
|
+
run: async (argv) => (await import("./preset-commands.mjs")).run([sub, ...argv]),
|
|
155
|
+
})),
|
|
144
156
|
{
|
|
145
157
|
words: ["config", "get"],
|
|
146
158
|
args: "KEY",
|
package/dist/config.d.mts
CHANGED
|
@@ -174,6 +174,7 @@ export declare function parseSettings(raw: unknown, exists: (path: string) => bo
|
|
|
174
174
|
export declare function patternWarnings(s: Settings, files: string[]): string[];
|
|
175
175
|
type YamlLoad = (text: string) => unknown;
|
|
176
176
|
export type Deps = {
|
|
177
|
+
/** `.claude/factory.yaml`, or the file FACTORY_SETTINGS names. */
|
|
177
178
|
readFile: () => string;
|
|
178
179
|
exists: (path: string) => boolean;
|
|
179
180
|
/** Whether an npm package resolves from the repository's root. */
|
|
@@ -182,13 +183,62 @@ export type Deps = {
|
|
|
182
183
|
loadYaml: () => Promise<YamlLoad>;
|
|
183
184
|
out: (line: string) => void;
|
|
184
185
|
err: (line: string) => void;
|
|
186
|
+
/** Where the settings come from when every command reads the lock:
|
|
187
|
+
* `check` stops on a stale one. Unset, they are resolved from the files
|
|
188
|
+
* the lock is made from. */
|
|
189
|
+
lock?: {
|
|
190
|
+
read: () => string | null;
|
|
191
|
+
check: boolean;
|
|
192
|
+
};
|
|
193
|
+
/** `.claude/factory.choices.yaml`, null when there is none. */
|
|
194
|
+
readChoices?: () => string | null;
|
|
195
|
+
/** Where presets are installed from. */
|
|
196
|
+
root?: string;
|
|
197
|
+
/** Which of the settings files differ from the last commit. */
|
|
198
|
+
changed?: () => string[];
|
|
199
|
+
/** A package's installed version: null when it is not installed, and
|
|
200
|
+
* undefined where there is no node_modules to look in. */
|
|
201
|
+
installed?: (pkg: string) => string | null | undefined;
|
|
185
202
|
};
|
|
186
203
|
export declare const NO_DEPENDENCIES = "The factory's settings cannot be read until dependencies are installed: run npm ci.";
|
|
204
|
+
/** The settings resolved from the files the lock is made from: the
|
|
205
|
+
* presets, `.claude/factory.yaml`, and the choices between them. */
|
|
206
|
+
export type Resolved = {
|
|
207
|
+
settings: Settings;
|
|
208
|
+
resolution: import("./preset.mts").Resolution;
|
|
209
|
+
presets: import("./preset.mts").Found[];
|
|
210
|
+
/** `.claude/factory.yaml` as written, and its text. */
|
|
211
|
+
own: Record<string, unknown>;
|
|
212
|
+
ownText: string;
|
|
213
|
+
choices: Record<string, string>;
|
|
214
|
+
choicesText: string | null;
|
|
215
|
+
/** Whether a path exists, counting the files the presets ship. */
|
|
216
|
+
exists: (path: string) => boolean;
|
|
217
|
+
};
|
|
218
|
+
/** The choices file read as a map from a key to a preset's name. */
|
|
219
|
+
export declare function parseChoices(text: string | null, load: YamlLoad): Record<string, string>;
|
|
220
|
+
/** The settings combined from the factory's defaults, each preset in
|
|
221
|
+
* `presets`, and `.claude/factory.yaml`, as `factory sync` combines them
|
|
222
|
+
* into the lock. `factoryFile` and `ownFile` say which preset files are
|
|
223
|
+
* kept back: the factory's own, and the repository's own. */
|
|
224
|
+
export declare function resolveFiles(d: Deps, keep?: {
|
|
225
|
+
factoryFile?: (path: string) => boolean;
|
|
226
|
+
ownFile?: (path: string) => boolean;
|
|
227
|
+
}): Promise<Resolved>;
|
|
228
|
+
/** Why the lock `d` reads is stale, or null when it is current or `d`
|
|
229
|
+
* reads none. */
|
|
230
|
+
export declare function staleOf(d: Deps): Promise<string | null>;
|
|
231
|
+
/** The lines of the lock's `settings` block, as `factory config explain`
|
|
232
|
+
* printed them when the lock was written. */
|
|
233
|
+
export declare function lockSettingsLines(text: string): string[];
|
|
187
234
|
/** The settings file: FACTORY_SETTINGS where it is set, for trying settings
|
|
188
235
|
* against a board without changing the repository's, and otherwise the
|
|
189
236
|
* repository's own. */
|
|
190
237
|
export declare const settingsPath: (root: string, env?: Record<string, string | undefined>) => string;
|
|
191
|
-
|
|
238
|
+
/** The settings of the checkout at `root`, read from its lock, or from
|
|
239
|
+
* the lock FACTORY_LOCK names without checking it is current, or from the
|
|
240
|
+
* settings file FACTORY_SETTINGS names with no lock at all. */
|
|
241
|
+
export declare const defaultDeps: (root?: string, env?: Record<string, string | undefined>) => Deps;
|
|
192
242
|
/** The column each state shows in on the board, null for none. */
|
|
193
243
|
export declare function columnsOf(s: Settings): Columns;
|
|
194
244
|
/** The board's names for the fields the sync writes, null for none. */
|
|
@@ -197,8 +247,12 @@ export declare function fieldNamesOf(s: Settings): {
|
|
|
197
247
|
runsIn: string | null;
|
|
198
248
|
cost: string | null;
|
|
199
249
|
};
|
|
200
|
-
/** The settings of the checkout the
|
|
201
|
-
|
|
250
|
+
/** The settings of the checkout at `root` resolved from the files the lock
|
|
251
|
+
* is made from, for the commands that make or check the lock. */
|
|
252
|
+
export declare const filesDeps: (root?: string, env?: Record<string, string | undefined>) => Deps;
|
|
253
|
+
/** The settings of the checkout the command runs in: from its lock, or
|
|
254
|
+
* resolved from the files where `d` reads no lock. */
|
|
255
|
+
export declare function loadSettings(d?: Deps): Promise<Settings>;
|
|
202
256
|
/** Every plugin the factory will use, in the roles' order: the settings'
|
|
203
257
|
* own, and the factory's for each role they leave out. The refiner and the
|
|
204
258
|
* prover are always there. The factory's test reviewer is there unless the
|
package/dist/config.mjs
CHANGED
|
@@ -78,6 +78,9 @@ const roleKeys = () => Object.fromEntries(ROLES.map((role) => {
|
|
|
78
78
|
shape.kind,
|
|
79
79
|
...(shape.files === "none" ? [] : ["files"]),
|
|
80
80
|
...(shape.labels === "none" ? [] : ["labels"]),
|
|
81
|
+
// Only the repository's own settings leave out a plugin that a
|
|
82
|
+
// preset adds, and only from a list.
|
|
83
|
+
...(shape.list ? ["off"] : []),
|
|
81
84
|
],
|
|
82
85
|
];
|
|
83
86
|
}));
|
|
@@ -126,6 +129,7 @@ export const SETTINGS_KEYS = {
|
|
|
126
129
|
"": [
|
|
127
130
|
"version",
|
|
128
131
|
"repository",
|
|
132
|
+
"presets",
|
|
129
133
|
"tickets",
|
|
130
134
|
"code-host",
|
|
131
135
|
"builds",
|
|
@@ -359,7 +363,16 @@ function pluginsWritten(v) {
|
|
|
359
363
|
return [plugin(written, key, role)];
|
|
360
364
|
if (!Array.isArray(written))
|
|
361
365
|
return fail(key, "must be a list");
|
|
362
|
-
|
|
366
|
+
// A plugin left out with `off: true` is not used, and its role still
|
|
367
|
+
// counts as written.
|
|
368
|
+
return written.flatMap((item, i) => {
|
|
369
|
+
if (isObj(item) && "off" in item) {
|
|
370
|
+
if (item.off !== true)
|
|
371
|
+
fail(`${key}[${i}].off`, "must be true");
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
return [plugin(item, `${key}[${i}]`, role)];
|
|
375
|
+
});
|
|
363
376
|
}),
|
|
364
377
|
testReviewersWritten: at("test-reviewer") !== undefined,
|
|
365
378
|
};
|
|
@@ -419,6 +432,7 @@ export function parseSettings(raw, exists, built = BUILT) {
|
|
|
419
432
|
fail(key, `moved to commands.${key}`);
|
|
420
433
|
}
|
|
421
434
|
const top = object(written, "");
|
|
435
|
+
strings(top.presets, "presets");
|
|
422
436
|
if (typeof top.repository !== "string" ||
|
|
423
437
|
!/^[\w.-]+\/[\w.-]+$/.test(top.repository))
|
|
424
438
|
fail("repository", "must be owner/name");
|
|
@@ -571,31 +585,243 @@ export function patternWarnings(s, files) {
|
|
|
571
585
|
export const NO_DEPENDENCIES = "The factory's settings cannot be read until dependencies are installed: run npm ci.";
|
|
572
586
|
/** js-yaml is loaded when needed, so a checkout without dependencies gets
|
|
573
587
|
* one line saying what to do rather than a stack trace. */
|
|
574
|
-
async function
|
|
575
|
-
return parseSettings(await readRaw(d), d.exists);
|
|
576
|
-
}
|
|
577
|
-
/** The file as it is written, before any default is filled in. */
|
|
578
|
-
async function readRaw(d) {
|
|
579
|
-
let load;
|
|
588
|
+
async function yamlOf(d) {
|
|
580
589
|
try {
|
|
581
|
-
|
|
590
|
+
return await d.loadYaml();
|
|
582
591
|
}
|
|
583
592
|
catch {
|
|
584
593
|
throw new SettingsError(NO_DEPENDENCIES);
|
|
585
594
|
}
|
|
595
|
+
}
|
|
596
|
+
const readOrNull = (path) => {
|
|
597
|
+
try {
|
|
598
|
+
return readFileSync(path, "utf8");
|
|
599
|
+
}
|
|
600
|
+
catch {
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
/** The choices file read as a map from a key to a preset's name. */
|
|
605
|
+
export function parseChoices(text, load) {
|
|
606
|
+
if (text === null)
|
|
607
|
+
return {};
|
|
608
|
+
const bad = () => new SettingsError('.claude/factory.choices.yaml: each line must be KEY: "PRESET"');
|
|
609
|
+
let v;
|
|
610
|
+
try {
|
|
611
|
+
v = load(text);
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
throw bad();
|
|
615
|
+
}
|
|
616
|
+
if (v === null || v === undefined)
|
|
617
|
+
return {};
|
|
618
|
+
if (!isObj(v) || Object.values(v).some((x) => typeof x !== "string"))
|
|
619
|
+
throw bad();
|
|
620
|
+
return v;
|
|
621
|
+
}
|
|
622
|
+
/** The settings combined from the factory's defaults, each preset in
|
|
623
|
+
* `presets`, and `.claude/factory.yaml`, as `factory sync` combines them
|
|
624
|
+
* into the lock. `factoryFile` and `ownFile` say which preset files are
|
|
625
|
+
* kept back: the factory's own, and the repository's own. */
|
|
626
|
+
export async function resolveFiles(d, keep = {}) {
|
|
627
|
+
const load = await yamlOf(d);
|
|
628
|
+
let ownText;
|
|
629
|
+
let own;
|
|
586
630
|
try {
|
|
587
|
-
|
|
631
|
+
ownText = d.readFile();
|
|
632
|
+
own = load(ownText);
|
|
588
633
|
}
|
|
589
634
|
catch (e) {
|
|
590
635
|
throw new SettingsError(`${SETTINGS_FILE}: ${e.message}`);
|
|
591
636
|
}
|
|
637
|
+
const P = await import("./preset.mjs");
|
|
638
|
+
const top = isObj(own) ? own : {};
|
|
639
|
+
const names = isObj(own) ? strings(top.presets, "presets") : [];
|
|
640
|
+
const twice = names.find((n, i) => names.indexOf(n) !== i);
|
|
641
|
+
if (twice)
|
|
642
|
+
throw new SettingsError(`presets: ${twice} is listed twice`);
|
|
643
|
+
const root = d.root ?? repoRoot();
|
|
644
|
+
const presets = [];
|
|
645
|
+
const layers = [];
|
|
646
|
+
const ships = new Map();
|
|
647
|
+
for (const name of names) {
|
|
648
|
+
let found;
|
|
649
|
+
try {
|
|
650
|
+
found = P.findPreset(root, name);
|
|
651
|
+
}
|
|
652
|
+
catch (e) {
|
|
653
|
+
if (e instanceof P.PresetError)
|
|
654
|
+
throw new SettingsError(e.message);
|
|
655
|
+
throw e;
|
|
656
|
+
}
|
|
657
|
+
let raw;
|
|
658
|
+
try {
|
|
659
|
+
raw = load(readFileSync(join(found.dir, P.PRESET_FILE), "utf8"));
|
|
660
|
+
}
|
|
661
|
+
catch (e) {
|
|
662
|
+
throw new SettingsError(`${name}: ${e.message}`);
|
|
663
|
+
}
|
|
664
|
+
const fault = P.presetFaults(raw)[0];
|
|
665
|
+
if (fault)
|
|
666
|
+
throw new SettingsError(`${name}: ${fault.key}: ${fault.message}`);
|
|
667
|
+
// The version is the preset file's own, and never the repository's.
|
|
668
|
+
const { version: _, ...settings } = raw;
|
|
669
|
+
presets.push(found);
|
|
670
|
+
layers.push({ name, raw: settings });
|
|
671
|
+
ships.set(name, P.shipped(found.dir));
|
|
672
|
+
}
|
|
673
|
+
layers.push({ name: P.OWN, raw: top });
|
|
674
|
+
const choicesText = d.readChoices?.() ?? null;
|
|
675
|
+
const choices = parseChoices(choicesText, load);
|
|
676
|
+
let resolution;
|
|
677
|
+
try {
|
|
678
|
+
resolution = P.combine({ layers, choices, ships, ...keep });
|
|
679
|
+
}
|
|
680
|
+
catch (e) {
|
|
681
|
+
if (e instanceof P.PresetError)
|
|
682
|
+
throw new SettingsError(e.message);
|
|
683
|
+
throw e;
|
|
684
|
+
}
|
|
685
|
+
const exists = (path) => d.exists(path) || resolution.files.has(path);
|
|
686
|
+
let settings;
|
|
687
|
+
try {
|
|
688
|
+
settings = parseSettings(isObj(own) ? resolution.raw : own, exists);
|
|
689
|
+
}
|
|
690
|
+
catch (e) {
|
|
691
|
+
throw e instanceof SettingsError ? fromPreset(e, resolution) : e;
|
|
692
|
+
}
|
|
693
|
+
return {
|
|
694
|
+
settings,
|
|
695
|
+
resolution,
|
|
696
|
+
presets,
|
|
697
|
+
own: top,
|
|
698
|
+
ownText,
|
|
699
|
+
choices,
|
|
700
|
+
choicesText,
|
|
701
|
+
exists,
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
/** A fault the settings' check found in a value a preset gave, named by
|
|
705
|
+
* that preset rather than by `.claude/factory.yaml`. */
|
|
706
|
+
function fromPreset(e, r) {
|
|
707
|
+
const m = new RegExp(`^${SETTINGS_FILE.replace(/\./g, "\\.")}: ([^:]+): `).exec(e.message);
|
|
708
|
+
if (!m)
|
|
709
|
+
return e;
|
|
710
|
+
const key = m[1].replace(/\[\d+\]/g, "");
|
|
711
|
+
for (let at = key; at; at = at.includes(".") ? at.slice(0, at.lastIndexOf(".")) : "") {
|
|
712
|
+
const from = r.sources.get(at)?.from;
|
|
713
|
+
if (from === undefined)
|
|
714
|
+
continue;
|
|
715
|
+
if (!from || from === SETTINGS_FILE)
|
|
716
|
+
return e;
|
|
717
|
+
return new SettingsError(`${from}: ${e.message.slice(SETTINGS_FILE.length + 2)}`);
|
|
718
|
+
}
|
|
719
|
+
return e;
|
|
720
|
+
}
|
|
721
|
+
/** Why the lock `d` reads is stale, or null when it is current or `d`
|
|
722
|
+
* reads none. */
|
|
723
|
+
export async function staleOf(d) {
|
|
724
|
+
if (!d.lock)
|
|
725
|
+
return null;
|
|
726
|
+
const load = await yamlOf(d);
|
|
727
|
+
const P = await import("./preset.mjs");
|
|
728
|
+
const root = d.root ?? repoRoot();
|
|
729
|
+
let own;
|
|
730
|
+
try {
|
|
731
|
+
own = d.readFile();
|
|
732
|
+
}
|
|
733
|
+
catch {
|
|
734
|
+
own = null;
|
|
735
|
+
}
|
|
736
|
+
return P.staleReason({
|
|
737
|
+
lock: d.lock.read(),
|
|
738
|
+
own,
|
|
739
|
+
choices: d.readChoices?.() ?? null,
|
|
740
|
+
changed: d.changed ?? (() => []),
|
|
741
|
+
installed: d.installed ??
|
|
742
|
+
((pkg) => existsSync(join(root, "node_modules"))
|
|
743
|
+
? (P.findPackage(root, pkg)?.version ?? null)
|
|
744
|
+
: undefined),
|
|
745
|
+
load,
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
/** The settings in the lock, after checking it is current where `check`
|
|
749
|
+
* says to. */
|
|
750
|
+
async function fromLock(d, lock) {
|
|
751
|
+
const load = await yamlOf(d);
|
|
752
|
+
const P = await import("./preset.mjs");
|
|
753
|
+
if (lock.check) {
|
|
754
|
+
const reason = await staleOf(d);
|
|
755
|
+
if (reason)
|
|
756
|
+
throw new SettingsError(reason);
|
|
757
|
+
}
|
|
758
|
+
const text = lock.read();
|
|
759
|
+
if (text === null)
|
|
760
|
+
throw new SettingsError(P.staleMessages.missing);
|
|
761
|
+
let parsed;
|
|
762
|
+
try {
|
|
763
|
+
parsed = P.readLock(text, load);
|
|
764
|
+
}
|
|
765
|
+
catch (e) {
|
|
766
|
+
throw new SettingsError(`${P.LOCK_FILE}: ${e.message}`);
|
|
767
|
+
}
|
|
768
|
+
if (!parsed.settings)
|
|
769
|
+
throw new SettingsError(P.staleMessages.earlier);
|
|
770
|
+
return { settings: parseSettings(parsed.settings, d.exists), text };
|
|
771
|
+
}
|
|
772
|
+
/** The lines of the lock's `settings` block, as `factory config explain`
|
|
773
|
+
* printed them when the lock was written. */
|
|
774
|
+
export function lockSettingsLines(text) {
|
|
775
|
+
const lines = text.split("\n");
|
|
776
|
+
const start = lines.indexOf("settings:");
|
|
777
|
+
if (start < 0)
|
|
778
|
+
return [];
|
|
779
|
+
const out = [];
|
|
780
|
+
for (const line of lines.slice(start + 1)) {
|
|
781
|
+
if (line && !line.startsWith(" "))
|
|
782
|
+
break;
|
|
783
|
+
out.push(line.slice(2));
|
|
784
|
+
}
|
|
785
|
+
return out;
|
|
592
786
|
}
|
|
593
787
|
/** The settings file: FACTORY_SETTINGS where it is set, for trying settings
|
|
594
788
|
* against a board without changing the repository's, and otherwise the
|
|
595
789
|
* repository's own. */
|
|
596
790
|
export const settingsPath = (root, env = process.env) => env.FACTORY_SETTINGS || `${root}/${SETTINGS_FILE}`;
|
|
597
|
-
|
|
598
|
-
|
|
791
|
+
/** The settings of the checkout at `root`, read from its lock, or from
|
|
792
|
+
* the lock FACTORY_LOCK names without checking it is current, or from the
|
|
793
|
+
* settings file FACTORY_SETTINGS names with no lock at all. */
|
|
794
|
+
export const defaultDeps = (root = repoRoot(), env = process.env) => ({
|
|
795
|
+
readFile: () => readFileSync(settingsPath(root, env), "utf8"),
|
|
796
|
+
root,
|
|
797
|
+
readChoices: () => env.FACTORY_SETTINGS
|
|
798
|
+
? null
|
|
799
|
+
: readOrNull(join(root, ".claude/factory.choices.yaml")),
|
|
800
|
+
lock: env.FACTORY_LOCK
|
|
801
|
+
? { read: () => readOrNull(env.FACTORY_LOCK), check: false }
|
|
802
|
+
: env.FACTORY_SETTINGS
|
|
803
|
+
? undefined
|
|
804
|
+
: {
|
|
805
|
+
read: () => readOrNull(join(root, ".claude/factory.lock")),
|
|
806
|
+
check: true,
|
|
807
|
+
},
|
|
808
|
+
changed: () => {
|
|
809
|
+
try {
|
|
810
|
+
return execFileSync("git", [
|
|
811
|
+
"status",
|
|
812
|
+
"--porcelain",
|
|
813
|
+
"--",
|
|
814
|
+
SETTINGS_FILE,
|
|
815
|
+
".claude/factory.choices.yaml",
|
|
816
|
+
], { cwd: root, encoding: "utf8" })
|
|
817
|
+
.split("\n")
|
|
818
|
+
.filter(Boolean)
|
|
819
|
+
.map((l) => l.slice(3));
|
|
820
|
+
}
|
|
821
|
+
catch {
|
|
822
|
+
return [];
|
|
823
|
+
}
|
|
824
|
+
},
|
|
599
825
|
exists: (path) => existsSync(`${root}/${path}`),
|
|
600
826
|
hasPackage: (name) => {
|
|
601
827
|
try {
|
|
@@ -628,8 +854,16 @@ export function fieldNamesOf(s) {
|
|
|
628
854
|
cost: s.tickets.fields.cost,
|
|
629
855
|
};
|
|
630
856
|
}
|
|
631
|
-
/** The settings of the checkout the
|
|
632
|
-
|
|
857
|
+
/** The settings of the checkout at `root` resolved from the files the lock
|
|
858
|
+
* is made from, for the commands that make or check the lock. */
|
|
859
|
+
export const filesDeps = (root = repoRoot(), env = process.env) => ({ ...defaultDeps(root, env), lock: undefined });
|
|
860
|
+
/** The settings of the checkout the command runs in: from its lock, or
|
|
861
|
+
* resolved from the files where `d` reads no lock. */
|
|
862
|
+
export async function loadSettings(d = defaultDeps()) {
|
|
863
|
+
return d.lock
|
|
864
|
+
? (await fromLock(d, d.lock)).settings
|
|
865
|
+
: (await resolveFiles(d)).settings;
|
|
866
|
+
}
|
|
633
867
|
function lookup(s, key) {
|
|
634
868
|
if (key === "specs.check")
|
|
635
869
|
return s.specCheck;
|
|
@@ -702,11 +936,22 @@ export async function main(argv, d) {
|
|
|
702
936
|
d.err("Usage: factory config get KEY | config check | config explain | plugins [ROLE]");
|
|
703
937
|
return 2;
|
|
704
938
|
}
|
|
939
|
+
// `config check` reads the files the lock is made from, so it can say
|
|
940
|
+
// what is wrong with them while the lock is stale; everything else reads
|
|
941
|
+
// the lock.
|
|
705
942
|
let s;
|
|
706
|
-
let
|
|
943
|
+
let resolved = null;
|
|
944
|
+
let lockText = null;
|
|
707
945
|
try {
|
|
708
|
-
|
|
709
|
-
|
|
946
|
+
if (d.lock && command !== "check") {
|
|
947
|
+
const read = await fromLock(d, d.lock);
|
|
948
|
+
s = read.settings;
|
|
949
|
+
lockText = read.text;
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
resolved = await resolveFiles({ ...d, lock: undefined });
|
|
953
|
+
s = resolved.settings;
|
|
954
|
+
}
|
|
710
955
|
}
|
|
711
956
|
catch (e) {
|
|
712
957
|
if (!(e instanceof SettingsError))
|
|
@@ -727,8 +972,13 @@ export async function main(argv, d) {
|
|
|
727
972
|
return 0;
|
|
728
973
|
}
|
|
729
974
|
if (command === "explain") {
|
|
730
|
-
|
|
731
|
-
|
|
975
|
+
if (lockText !== null) {
|
|
976
|
+
for (const line of lockSettingsLines(lockText))
|
|
977
|
+
d.out(line);
|
|
978
|
+
return 0;
|
|
979
|
+
}
|
|
980
|
+
const { explainLines, markerOf } = await import("./explain.mjs");
|
|
981
|
+
for (const line of await explainLines(s, markerOf(resolved.resolution), resolved.exists))
|
|
732
982
|
d.out(line);
|
|
733
983
|
return 0;
|
|
734
984
|
}
|
package/dist/deps.d.mts
CHANGED
|
@@ -21,15 +21,17 @@ export type Bump = {
|
|
|
21
21
|
* patch only. */
|
|
22
22
|
export declare function isMajor(title: string): boolean;
|
|
23
23
|
/** What the skill does with a bump, in the order its steps take them.
|
|
24
|
-
* `branch` is the default branch, which a conflicting bump merges
|
|
25
|
-
|
|
24
|
+
* `branch` is the default branch, which a conflicting bump merges, and
|
|
25
|
+
* `synced` the packages whose update needs `factory sync`: the factory's
|
|
26
|
+
* own and each preset's. */
|
|
27
|
+
export declare function nextStep(bump: Bump, branch: string, synced?: string[]): string;
|
|
26
28
|
/** Every check on the bump's commit, not a fixed list of names: passed, or
|
|
27
29
|
* the names that failed and the names still running. */
|
|
28
30
|
export declare function checksLine(bump: Bump): string;
|
|
29
|
-
export declare function formatBump(bump: Bump, branch: string): string[];
|
|
31
|
+
export declare function formatBump(bump: Bump, branch: string, synced?: string[]): string[];
|
|
30
32
|
/** `defaultBranch` gives the default branch's name, and rejects when it
|
|
31
33
|
* cannot be told. It is asked only when a pull request is listed. */
|
|
32
|
-
export declare function main(p: CodeHost, out: (line: string) => void, argv: string[], defaultBranch: () => Promise<string
|
|
34
|
+
export declare function main(p: CodeHost, out: (line: string) => void, argv: string[], defaultBranch: () => Promise<string>, synced?: string[]): Promise<number>;
|
|
33
35
|
/** `factory deps`. */
|
|
34
36
|
export declare function run(argv?: string[]): Promise<number>;
|
|
35
37
|
export {};
|
package/dist/deps.mjs
CHANGED
|
@@ -18,8 +18,10 @@ export function isMajor(title) {
|
|
|
18
18
|
return match !== null && match[1] !== match[2];
|
|
19
19
|
}
|
|
20
20
|
/** What the skill does with a bump, in the order its steps take them.
|
|
21
|
-
* `branch` is the default branch, which a conflicting bump merges
|
|
22
|
-
|
|
21
|
+
* `branch` is the default branch, which a conflicting bump merges, and
|
|
22
|
+
* `synced` the packages whose update needs `factory sync`: the factory's
|
|
23
|
+
* own and each preset's. */
|
|
24
|
+
export function nextStep(bump, branch, synced = []) {
|
|
23
25
|
if (bump.mergeableState === "unknown")
|
|
24
26
|
return "leave: state not computed yet";
|
|
25
27
|
if (bump.checks.some((c) => c.status !== "completed"))
|
|
@@ -31,6 +33,8 @@ export function nextStep(bump, branch) {
|
|
|
31
33
|
steps.push(`merge ${branch} (step 2)`);
|
|
32
34
|
if (failing(bump).length > 0)
|
|
33
35
|
steps.push(`fix ${failing(bump).join(", ")} (step 3)`);
|
|
36
|
+
if (synced.some((name) => bump.title.includes(name)))
|
|
37
|
+
steps.push("sync (step 4)");
|
|
34
38
|
if (bump.major)
|
|
35
39
|
steps.push("migrate (step 4)");
|
|
36
40
|
return steps.length > 0 ? steps.join("; ") : "nothing: waits on its merge";
|
|
@@ -68,13 +72,13 @@ export function checksLine(bump) {
|
|
|
68
72
|
].filter(Boolean);
|
|
69
73
|
return `checks: ${parts.join("; ")}`;
|
|
70
74
|
}
|
|
71
|
-
export function formatBump(bump, branch) {
|
|
75
|
+
export function formatBump(bump, branch, synced = []) {
|
|
72
76
|
return [
|
|
73
77
|
`#${bump.number} ${bump.title}`,
|
|
74
78
|
` ${bump.major ? "major" : "minor or patch"}; head ${bump.head} at ${bump.sha.slice(0, 7)}; mergeable ${bump.mergeableState}; auto-merge ${bump.autoMerge ? "on" : "off"}`,
|
|
75
79
|
` ${checksLine(bump)}`,
|
|
76
80
|
` earlier shepherd comments: ${bump.shepherdComments}`,
|
|
77
|
-
` next: ${nextStep(bump, branch)}`,
|
|
81
|
+
` next: ${nextStep(bump, branch, synced)}`,
|
|
78
82
|
];
|
|
79
83
|
}
|
|
80
84
|
async function readBump(p, number) {
|
|
@@ -98,7 +102,7 @@ async function readBump(p, number) {
|
|
|
98
102
|
}
|
|
99
103
|
/** `defaultBranch` gives the default branch's name, and rejects when it
|
|
100
104
|
* cannot be told. It is asked only when a pull request is listed. */
|
|
101
|
-
export async function main(p, out, argv, defaultBranch) {
|
|
105
|
+
export async function main(p, out, argv, defaultBranch, synced = []) {
|
|
102
106
|
try {
|
|
103
107
|
const pulls = (await p.listOpen())
|
|
104
108
|
.filter((pull) => pull.author === "dependabot[bot]")
|
|
@@ -115,7 +119,7 @@ export async function main(p, out, argv, defaultBranch) {
|
|
|
115
119
|
}
|
|
116
120
|
const branch = await defaultBranch();
|
|
117
121
|
for (const pull of pulls) {
|
|
118
|
-
formatBump(await readBump(p, pull.number), branch).forEach((l) => out(l));
|
|
122
|
+
formatBump(await readBump(p, pull.number), branch, synced).forEach((l) => out(l));
|
|
119
123
|
}
|
|
120
124
|
return 0;
|
|
121
125
|
}
|
|
@@ -124,6 +128,24 @@ export async function main(p, out, argv, defaultBranch) {
|
|
|
124
128
|
return argv.includes("--any") ? 2 : 1;
|
|
125
129
|
}
|
|
126
130
|
}
|
|
131
|
+
/** The factory's package and each preset's the lock records, whose
|
|
132
|
+
* updates each need a sync. */
|
|
133
|
+
async function syncedPackages(root) {
|
|
134
|
+
const { readFileSync } = await import("node:fs");
|
|
135
|
+
const { join } = await import("node:path");
|
|
136
|
+
const { PACKAGE } = await import("./sync.mjs");
|
|
137
|
+
const { readLock, splitName, LOCK_FILE } = await import("./preset.mjs");
|
|
138
|
+
const { load } = await import("js-yaml");
|
|
139
|
+
const own = JSON.parse(readFileSync(join(PACKAGE, "package.json"), "utf8"))
|
|
140
|
+
.name;
|
|
141
|
+
try {
|
|
142
|
+
const lock = readLock(readFileSync(join(root, LOCK_FILE), "utf8"), load);
|
|
143
|
+
return [own, ...new Set(lock.presets.map((p) => splitName(p.name).pkg))];
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return [own];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
127
149
|
/** `factory deps`. */
|
|
128
150
|
export async function run(argv = []) {
|
|
129
151
|
const { repository, codeHost } = await reachOf(process.env);
|
|
@@ -133,5 +155,5 @@ export async function run(argv = []) {
|
|
|
133
155
|
return main(p, (line) => console.log(line), argv, () => needDefaultBranch({
|
|
134
156
|
...branchDeps(repoRoot()),
|
|
135
157
|
host: () => p.defaultBranch(),
|
|
136
|
-
}));
|
|
158
|
+
}), await syncedPackages(repoRoot()));
|
|
137
159
|
}
|
package/dist/doctor.d.mts
CHANGED
|
@@ -12,6 +12,9 @@ export type DoctorDeps = {
|
|
|
12
12
|
installed: string;
|
|
13
13
|
locked: string | null;
|
|
14
14
|
};
|
|
15
|
+
/** Whether the lock is current, and each preset it records is installed
|
|
16
|
+
* and has a Dependabot group of its own. */
|
|
17
|
+
lockChecks?: () => Promise<Check[]>;
|
|
15
18
|
root: string;
|
|
16
19
|
hasCommand: (name: string) => boolean;
|
|
17
20
|
tools: Registry;
|
package/dist/doctor.mjs
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
// being set.
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
|
-
import { defaultDeps,
|
|
9
|
+
import { defaultDeps, filesDeps, repoRoot, resolveFiles, staleOf, } from "./config.mjs";
|
|
10
|
+
import { presetChecks } from "./preset-commands.mjs";
|
|
10
11
|
import { hasCommand } from "./lib/has-command.mjs";
|
|
11
12
|
import { neededSecrets, PART_TEXT, PARTS, partsOn, } from "./parts.mjs";
|
|
12
13
|
import { branchDeps, CANNOT_TELL, needDefaultBranch, NoDefaultBranch, } from "./lib/default-branch.mjs";
|
|
@@ -72,6 +73,7 @@ export async function checks(d) {
|
|
|
72
73
|
text: `Version ${installed} is installed, but the repository records ${locked}`,
|
|
73
74
|
fix: compareVersions(installed, locked) < 0 ? "Run npm ci" : SYNC,
|
|
74
75
|
});
|
|
76
|
+
out.push(...((await d.lockChecks?.()) ?? []));
|
|
75
77
|
const chosen = {
|
|
76
78
|
codeHost: s.codeHost.type,
|
|
77
79
|
tickets: s.tickets.type,
|
|
@@ -164,10 +166,11 @@ export async function main(_argv, d) {
|
|
|
164
166
|
}
|
|
165
167
|
/** The checks, run in the repository this command runs in. */
|
|
166
168
|
export function doctorDeps(root = repoRoot()) {
|
|
167
|
-
const
|
|
169
|
+
const resolved = () => resolveFiles(filesDeps(root));
|
|
168
170
|
return {
|
|
169
|
-
settings,
|
|
170
|
-
outOfStep: async (s) => differences(root, plan(PACKAGE, root,
|
|
171
|
+
settings: async () => (await resolved()).settings,
|
|
172
|
+
outOfStep: async (s) => differences(root, await plan(PACKAGE, root, await resolved(), await needDefaultBranch(branchDeps(root, process.env, async () => s)))),
|
|
173
|
+
lockChecks: async () => presetChecks(root, await staleOf(defaultDeps(root))),
|
|
171
174
|
versions: () => {
|
|
172
175
|
const installed = JSON.parse(readFileSync(join(PACKAGE, "package.json"), "utf8")).version;
|
|
173
176
|
let locked = null;
|
package/dist/explain.d.mts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { type Settings } from "./config.mts";
|
|
2
|
+
import { type Resolution } from "./preset.mts";
|
|
3
|
+
/** The mark of the value at `path`, or of one item of the list there:
|
|
4
|
+
* `item` is the item for a list of values and the plugin's name for a
|
|
5
|
+
* list of plugins. */
|
|
6
|
+
export type Marker = {
|
|
7
|
+
value: (path: string[]) => string | null;
|
|
8
|
+
item: (path: string[], item: unknown) => string | null;
|
|
9
|
+
plugin: (path: string[], name: string) => string | null;
|
|
10
|
+
};
|
|
11
|
+
/** The marks of the values a resolution combined. */
|
|
12
|
+
export declare function markerOf(r: Resolution): Marker;
|
|
2
13
|
/** `exists` says whether a path from the root exists, for the plugins the
|
|
3
14
|
* factory uses where the settings name none. */
|
|
4
|
-
export declare function explainLines(s: Settings,
|
|
15
|
+
export declare function explainLines(s: Settings, marks: Marker, exists: (path: string) => boolean): Promise<string[]>;
|