@egawilldoit/factory 2.0.1 → 2.1.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 +5 -5
- package/bundle/bundle.json +7 -7
- package/bundle/files/skills/factory/SKILL.md +1 -1
- package/bundle/files/skills/factory-ship/SKILL.md +2 -2
- package/lib/cli.js +22 -13
- package/lib/fs-util.js +3 -0
- package/lib/gate.js +53 -21
- package/lib/github.js +7 -3
- package/lib/install.js +1 -1
- package/lib/ops-util.js +10 -1
- package/lib/policy.js +4 -1
- package/lib/recovery.js +2 -2
- package/lib/rollback.js +3 -2
- package/lib/uninstall.js +11 -3
- package/lib/update.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ v2.0.0 introduced the `factory-ship` skill, the `go auto` autonomous delivery ru
|
|
|
9
9
|
Requires Node.js 22 or later. The installer targets the shared `~/.agents/skills` location used by Codex and OpenCode. Start a fresh host session after installation.
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npx @egawilldoit/factory@
|
|
13
|
-
npx @egawilldoit/factory@
|
|
12
|
+
npx @egawilldoit/factory@latest install
|
|
13
|
+
npx @egawilldoit/factory@latest doctor
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
In Codex, use `$factory`. In T3/OpenCode, select `factory` in the skill menu or use `/skill:factory` where the client supports that command.
|
|
@@ -38,10 +38,10 @@ From a Git worktree with authenticated GitHub CLI access:
|
|
|
38
38
|
```sh
|
|
39
39
|
factory init
|
|
40
40
|
factory gate --pr 123 --base main --json
|
|
41
|
-
factory merge --pr 123 --base main --sha <full-head-sha> --json
|
|
41
|
+
factory merge --pr 123 --base main --sha <full-head-sha> --merge-method squash --json
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
`init` writes a starter `observe` policy and refuses to overwrite an existing one. Review policy changes on their own PR. The gate reads policy from the fetched target branch, defaults to `observe` when absent, and blocks autonomous merge when the candidate edits the policy. Autonomous merge requires `delivery.mode: "enforce"`, `delivery.maximumBoundary: "merge"`, an `eligible` verdict, and explicit user authorization. GitHub enforces native branch protection and the expected head atomically. Factory ignores the retired version 1 settings `delivery.requireCurrentReview` and `delivery.requireHumanReviewPaths`. Because GitHub's merge API has no expected-base SHA field,
|
|
44
|
+
`init` writes a starter `observe` policy and refuses to overwrite an existing one. Review policy changes on their own PR. The gate reads policy from the fetched target branch, defaults to `observe` when absent, and blocks autonomous merge when the candidate edits the policy. Autonomous merge requires `delivery.mode: "enforce"`, `delivery.maximumBoundary: "merge"`, an `eligible` verdict, and explicit user authorization. GitHub enforces native branch protection and the expected head atomically. Factory ignores the retired version 1 settings `delivery.requireCurrentReview` and `delivery.requireHumanReviewPaths`. Only `delivery.*` fields are enforced by the CLI; `review.*` and `steward.*` fields are advisory guidance for the agent. Set `delivery.mergeMethod` (`merge`, `squash`, or `rebase`) or pass `--merge-method` for repositories that restrict merge strategies. Because GitHub's merge API has no expected-base SHA field and fast checks can finish before slower workflows register, configure GitHub branch protection with required status checks and strict up-to-date branches.
|
|
45
45
|
|
|
46
46
|
For `go auto`, Factory confirms the primary and fallback subagent models/providers and the target branch in one batch before starting autonomous execution. The target defaults to the origin default branch for direct CLI use. GitHub is the supported delivery provider, and stewardship runs within the active agent session. See the [v2 acceptance runbook](docs/v2-release-evidence.md) for local and hosted evidence.
|
|
47
47
|
|
|
@@ -71,7 +71,7 @@ The portable contract is `templates/implementation-issue.md`; detailed guidance
|
|
|
71
71
|
|
|
72
72
|
The Cloudflare MCP channel supplies public released instructions only. It cannot access your repositories, execute work or change production. Its stable URL advances on a stable tagged release. Start by reading the version, then include that version in subsequent retrieval calls to avoid mixing releases.
|
|
73
73
|
|
|
74
|
-
ChatGPT custom MCP connection testing is deferred. No ChatGPT compatibility is claimed yet. The live endpoint is `https://ega-software-factory.a2003-2015.workers.dev/mcp`. Tool discovery, current/previous retrieval and content parity passed with the official MCP SDK.
|
|
74
|
+
ChatGPT custom MCP connection testing is deferred. No ChatGPT compatibility is claimed yet. The live endpoint is `https://ega-software-factory.a2003-2015.workers.dev/mcp`. Supports both stateless MCP `2026-07-28` (`server/discover` + per-request `_meta`) and legacy `initialize` revisions (`2025-11-25`, `2025-06-18`, `2025-03-26`). Tool discovery, current/previous retrieval and content parity passed with the official MCP SDK.
|
|
75
75
|
|
|
76
76
|
## Release and contributor setup
|
|
77
77
|
|
package/bundle/bundle.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "@egawilldoit/factory",
|
|
4
|
-
"version": "2.0
|
|
5
|
-
"sourceCommit": "
|
|
6
|
-
"builtAt": "2026-
|
|
4
|
+
"version": "2.1.0",
|
|
5
|
+
"sourceCommit": "4053617658aa6e6156cb933616684639b609ac9d",
|
|
6
|
+
"builtAt": "2026-12-05T11:03:01Z",
|
|
7
7
|
"skills": [
|
|
8
8
|
"factory",
|
|
9
9
|
"factory-plan",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
{
|
|
18
18
|
"path": "skills/factory/SKILL.md",
|
|
19
|
-
"sha256": "
|
|
20
|
-
"bytes":
|
|
19
|
+
"sha256": "3da18f22f1223088b16b1756975f87a004f736c8567ef035d73eb31a38ff61d7",
|
|
20
|
+
"bytes": 9026
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"path": "skills/factory-plan/SKILL.md",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
"path": "skills/factory-ship/SKILL.md",
|
|
39
|
-
"sha256": "
|
|
40
|
-
"bytes":
|
|
39
|
+
"sha256": "92a0f982b239914d28a52acdb0a455103a247300a88862940ee8a7354b5b0396",
|
|
40
|
+
"bytes": 4719
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"path": "skills/unslop/SKILL.md",
|
|
@@ -49,7 +49,7 @@ Choose only the work that the request and risk require:
|
|
|
49
49
|
|
|
50
50
|
Small, clear work may use one agent and skip formal planning. Material unknowns must be surfaced rather than buried in a plan.
|
|
51
51
|
|
|
52
|
-
If **go auto** is requested,
|
|
52
|
+
If **go auto** is requested, route to [factory-ship](../factory-ship/SKILL.md) and follow its `go auto` confirmation batch, fallback handling, and stop conditions.
|
|
53
53
|
|
|
54
54
|
If `factory-ship` is unavailable, use `../../references/pr-workflows.md` for authorized PR handoff, disclose the fallback, and honor every delivery limit. Require the deterministic gate for autonomous merge.
|
|
55
55
|
|
|
@@ -16,9 +16,9 @@ For **go auto**, ask one concise batch of questions using the host question tool
|
|
|
16
16
|
## Verify, publish, and steward
|
|
17
17
|
|
|
18
18
|
1. Reconcile the current Git head, worktree, target branch, and live PR. Verify the scoped change with `factory-verify`. Recover an existing PR for the branch before opening a new one. Respect repository policy, existing authorship, and the requested draft or ready state.
|
|
19
|
-
2. Use one independent reviewer where required and permitted. Respect the trusted policy's review and repair budgets and its stewardship setting (default: two reviewer runs and two repair attempts). Use a fresh
|
|
19
|
+
2. Use one independent reviewer where required and permitted. Respect the trusted policy's review and repair budgets and its stewardship setting (default: two reviewer runs and two repair attempts). Use a fresh delegated review per round with the selected model and provider using the host's delegation tool (for example, `delegate_task` on T3). Track findings as `S1 [blocker|should|nit] <file>:<line> <claim>` and record `fixed:`, `disagree:`, or `declined:` with evidence. Check `git diff --shortstat` before and after each repair to catch scope growth. Stop review at nits-only.
|
|
20
20
|
3. Fix reproduced CI failures, merge conflicts, and actionable review findings within scope, and verify each repair. After every steward push, report what changed, the proof, and the exact `git revert <sha>` command. Keep each push undoable without rewriting branch history.
|
|
21
|
-
4. Use only the native PR watcher when waiting is authorized and necessary. Keep one watcher per PR, owned by the main thread; delegated children never watch. Stay silent on no-op wakes.
|
|
21
|
+
4. Use only the native PR watcher when waiting is authorized and necessary. Keep one watcher per PR, owned by the main thread; delegated children never watch. Stay silent on no-op wakes. Unwatch any active PR watcher (for example, `unwatch_pull_request` on T3) before asking through the host question tool or handing off. Never substitute custom polling or a background loop.
|
|
22
22
|
5. Run `factory gate --pr <n> --base <branch> --json` before claiming readiness or merging. `observe-only` caps delivery at PR, `blocked` requires resolution or human handoff, and `unverified` requires evidence. Honor native branch protection. Never use `--admin` or silently disable auto-merge or merge queues.
|
|
23
23
|
6. For authorized eligible merges, run `factory merge --sha <verified-head> --pr <n> --base <branch> --json`. Confirm the actual provider state. Report deployment and live verification separately where in scope. At handoff, include the PR link, exact head SHA, gate verdict, and actionable reasons.
|
|
24
24
|
|
package/lib/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ const { rollback } = require('./rollback');
|
|
|
12
12
|
const { uninstall } = require('./uninstall');
|
|
13
13
|
|
|
14
14
|
const { evaluateGate, mergeCandidate, initRepository } = require('./gate');
|
|
15
|
+
const { MERGE_METHODS } = require('./policy');
|
|
15
16
|
|
|
16
17
|
const DELIVERY_COMMANDS = ['init', 'gate', 'merge'];
|
|
17
18
|
const INSTALLER_COMMANDS = ['install', 'update', 'doctor', 'rollback', 'uninstall'];
|
|
@@ -19,7 +20,7 @@ const INSTALLER_COMMANDS = ['install', 'update', 'doctor', 'rollback', 'uninstal
|
|
|
19
20
|
const COMMANDS = [...INSTALLER_COMMANDS, ...DELIVERY_COMMANDS];
|
|
20
21
|
|
|
21
22
|
function parse(argv) {
|
|
22
|
-
const opts = { destination: null, host: null, json: false, help: false, version: false };
|
|
23
|
+
const opts = { destination: null, host: null, mergeMethod: null, json: false, help: false, version: false };
|
|
23
24
|
const positional = [];
|
|
24
25
|
let error = null;
|
|
25
26
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -27,11 +28,12 @@ function parse(argv) {
|
|
|
27
28
|
if (arg === '--json') opts.json = true;
|
|
28
29
|
else if (arg === '--help' || arg === '-h') opts.help = true;
|
|
29
30
|
else if (arg === '--version' || arg === '-V') opts.version = true;
|
|
30
|
-
else if (/^--(?:destination|host|pr|base|sha)(?:=|$)/.test(arg)) {
|
|
31
|
+
else if (/^--(?:destination|host|pr|base|sha|merge-method)(?:=|$)/.test(arg)) {
|
|
31
32
|
const [option, ...inline] = arg.split('=');
|
|
32
33
|
const value = inline.length ? inline.join('=') : argv[i + 1];
|
|
33
34
|
if (value && (inline.length || !value.startsWith('-'))) {
|
|
34
|
-
|
|
35
|
+
const key = option === '--merge-method' ? 'mergeMethod' : option.slice(2);
|
|
36
|
+
opts[key] = value;
|
|
35
37
|
if (!inline.length) i++;
|
|
36
38
|
} else error ??= usage(`${option} requires a value.`);
|
|
37
39
|
}
|
|
@@ -42,6 +44,9 @@ function parse(argv) {
|
|
|
42
44
|
if (opts.host && !HOSTS.includes(opts.host)) {
|
|
43
45
|
error ??= usage(`Unsupported --host ${opts.host}. Use one of: ${HOSTS.join(', ')}.`);
|
|
44
46
|
}
|
|
47
|
+
if (opts.mergeMethod && !MERGE_METHODS.includes(opts.mergeMethod)) {
|
|
48
|
+
error ??= usage(`Unsupported --merge-method ${opts.mergeMethod}. Use one of: ${MERGE_METHODS.join(', ')}.`);
|
|
49
|
+
}
|
|
45
50
|
return { command, extra: positional, opts, error };
|
|
46
51
|
}
|
|
47
52
|
|
|
@@ -62,14 +67,15 @@ function helpText() {
|
|
|
62
67
|
' uninstall Remove only files owned by this installation',
|
|
63
68
|
'',
|
|
64
69
|
'Options:',
|
|
65
|
-
' --destination <path>
|
|
66
|
-
' --host <codex|opencode>
|
|
67
|
-
' --base <branch>
|
|
68
|
-
' --pr <number>
|
|
69
|
-
' --sha <sha>
|
|
70
|
-
' --
|
|
71
|
-
'
|
|
72
|
-
' -
|
|
70
|
+
' --destination <path> Bundle root (default: ~/.agents; skills go to <root>/skills)',
|
|
71
|
+
' --host <codex|opencode> Advisory host label recorded in the manifest',
|
|
72
|
+
' --base <branch> Target branch for gate or merge (default: origin default branch)',
|
|
73
|
+
' --pr <number> GitHub PR for gate or merge (default: current branch PR)',
|
|
74
|
+
' --sha <sha> Required full expected head SHA for merge',
|
|
75
|
+
' --merge-method <merge|squash|rebase> Merge method override for merge (default: policy value)',
|
|
76
|
+
' --json Emit a machine-readable JSON report',
|
|
77
|
+
' -V, --version Print the package version',
|
|
78
|
+
' -h, --help Show this help',
|
|
73
79
|
].join('\n');
|
|
74
80
|
}
|
|
75
81
|
|
|
@@ -86,7 +92,9 @@ function formatText(report, command, opts) {
|
|
|
86
92
|
if (report.policyFile) lines.push('Policy file: ' + report.policyFile);
|
|
87
93
|
if (report.verdict) lines.push('Verdict: ' + report.verdict);
|
|
88
94
|
if (report.candidate?.head) lines.push('Candidate: ' + report.candidate.head);
|
|
89
|
-
for (const reason of report.reasons || [])
|
|
95
|
+
for (const reason of report.reasons || []) {
|
|
96
|
+
lines.push('- ' + reason.code + (reason.detail ? `: ${reason.detail}` : ''));
|
|
97
|
+
}
|
|
90
98
|
if (report.merged) lines.push('Merged: ' + report.mergeSha);
|
|
91
99
|
if (report.destination) lines.push('Destination: ' + report.destination);
|
|
92
100
|
if (report.version) lines.push('Version: ' + report.version);
|
|
@@ -152,6 +160,7 @@ function main(argv) {
|
|
|
152
160
|
if (opts.destination || opts.host) throw usage('Installer options require an installer command.');
|
|
153
161
|
if (opts.pr && !/^[1-9]\d*$/.test(opts.pr)) throw usage('--pr must be a positive PR number.');
|
|
154
162
|
if (command !== 'merge' && opts.sha) throw usage('--sha is only supported by merge.');
|
|
163
|
+
if (command !== 'merge' && opts.mergeMethod) throw usage('--merge-method is only supported by merge.');
|
|
155
164
|
if (command === 'merge' && !/^[a-f0-9]{40}$/.test(opts.sha || '')) {
|
|
156
165
|
throw usage('merge requires --sha with a full 40-character GitHub head SHA.');
|
|
157
166
|
}
|
|
@@ -168,7 +177,7 @@ function main(argv) {
|
|
|
168
177
|
exitCode = report.ok ? EXIT.OK : EXIT.REFUSED;
|
|
169
178
|
}
|
|
170
179
|
} else {
|
|
171
|
-
if (opts.pr || opts.base || opts.sha) throw usage('Delivery options require a delivery command.');
|
|
180
|
+
if (opts.pr || opts.base || opts.sha || opts.mergeMethod) throw usage('Delivery options require a delivery command.');
|
|
172
181
|
const bundle = loadBundle(packageRoot());
|
|
173
182
|
assertBundle(bundle);
|
|
174
183
|
const dest = resolveDestination(opts);
|
package/lib/fs-util.js
CHANGED
|
@@ -143,11 +143,14 @@ function moveFile(src, dst) {
|
|
|
143
143
|
|
|
144
144
|
// Remove empty directories under root, deepest first, optionally skipping root.
|
|
145
145
|
function pruneEmptyDirs(root, skip) {
|
|
146
|
+
// Never traverse a symlinked root: readdir would leave the installation.
|
|
147
|
+
try { if (fs.lstatSync(root).isSymbolicLink()) return; } catch (_) { return; }
|
|
146
148
|
if (!isDirectory(root)) return;
|
|
147
149
|
const skipSet = new Set(skip || []);
|
|
148
150
|
const walk = (dir) => {
|
|
149
151
|
for (const name of fs.readdirSync(dir)) {
|
|
150
152
|
const p = path.join(dir, name);
|
|
153
|
+
try { if (fs.lstatSync(p).isSymbolicLink()) continue; } catch (_) { continue; }
|
|
151
154
|
if (isDirectory(p) && !skipSet.has(p)) {
|
|
152
155
|
walk(p);
|
|
153
156
|
try { fs.rmdirSync(p); } catch (_) {}
|
package/lib/gate.js
CHANGED
|
@@ -4,6 +4,12 @@ const { execFileSync } = require('node:child_process');
|
|
|
4
4
|
const { githubRepository, readPullRequest, mergePullRequest } = require('./github');
|
|
5
5
|
const { POLICY_FILE, loadPolicy, initPolicy } = require('./policy');
|
|
6
6
|
|
|
7
|
+
function sanitizeErrorDetail(value) {
|
|
8
|
+
if (!value) return null;
|
|
9
|
+
const text = String(value).replace(/\s+/g, ' ').trim();
|
|
10
|
+
return text ? text.slice(0, 240) : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
function command(executable, args, cwd) {
|
|
8
14
|
try {
|
|
9
15
|
return execFileSync(executable, args, {
|
|
@@ -11,8 +17,11 @@ function command(executable, args, cwd) {
|
|
|
11
17
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
12
18
|
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GH_PROMPT_DISABLED: '1' },
|
|
13
19
|
});
|
|
14
|
-
} catch {
|
|
15
|
-
|
|
20
|
+
} catch (cause) {
|
|
21
|
+
const detail = sanitizeErrorDetail(cause?.stderr || cause?.message);
|
|
22
|
+
const err = new Error(`${executable} ${args[0]} failed.`);
|
|
23
|
+
if (detail) err.detail = detail;
|
|
24
|
+
throw err;
|
|
16
25
|
}
|
|
17
26
|
}
|
|
18
27
|
|
|
@@ -20,10 +29,13 @@ function gitRunner(cwd) {
|
|
|
20
29
|
return args => command('git', args, cwd);
|
|
21
30
|
}
|
|
22
31
|
|
|
32
|
+
const isPolicyFile = file => file.toLowerCase() === POLICY_FILE.toLowerCase();
|
|
23
33
|
const splitPaths = output => output.split('\0').filter(Boolean).sort();
|
|
24
|
-
const testFile = /(?:^|\/)(?:__tests__|tests?|spec|__snapshots__)\/|\.(?:test|spec)\.[^/]
|
|
34
|
+
const testFile = /(?:^|\/)(?:__tests__|tests?|spec|__snapshots__)\/|\.(?:test|spec)\.[^/]+$|(?:^|\/)(?:test_[^/]+|[^/]+_test)\.(?:py|go|rb|rs|[cm]?[jt]sx?)$/i;
|
|
35
|
+
const gateScript = key => /test|lint|check|verify|coverage/i.test(key);
|
|
36
|
+
const lifecycleTarget = key => /^(?:pre|post)(.+)$/.exec(key)?.[1] ?? null;
|
|
25
37
|
const gateConfig = /(?:^|\/)(?:\.(?:eslint|oxlint|mocha)rc(?:\.[^/]+)?|(?:eslint|oxlint|jest|vitest|playwright|cypress|prettier|biome|tsconfig)(?:\.[^/]+)?\.(?:[cm]?[jt]s|jsonc?|ya?ml)|pytest\.ini|tox\.ini|pyproject\.toml|\.gitlab-ci\.yml|\.circleci\/config\.yml)$/i;
|
|
26
|
-
const skip = /\.\s*skip\s*\(|\b(?:xit|xdescribe|xtest)\s*\(/;
|
|
38
|
+
const skip = /\.\s*(?:skip|only)\s*\(|\b(?:xit|xdescribe|xtest|fit|fdescribe)\s*\(|@pytest\.mark\.skip\b|\bunittest\.skip\b|\bt\.Skip(?:f|Now)?\s*\(|#\[\s*ignore\b/;
|
|
27
39
|
|
|
28
40
|
function integrityFindings(git, range, paths) {
|
|
29
41
|
const findings = [];
|
|
@@ -33,7 +45,7 @@ function integrityFindings(git, range, paths) {
|
|
|
33
45
|
findings.push({ file, kind: 'gate-configuration-changed' });
|
|
34
46
|
}
|
|
35
47
|
if (deleted.has(file) && testFile.test(file)) findings.push({ file, kind: 'test-file-deleted' });
|
|
36
|
-
if (file
|
|
48
|
+
if (isPolicyFile(file)) continue;
|
|
37
49
|
if (/(?:^|\/)package\.json$/.test(file)) {
|
|
38
50
|
const [before, after] = range.split('..');
|
|
39
51
|
const readScripts = sha => {
|
|
@@ -43,15 +55,22 @@ function integrityFindings(git, range, paths) {
|
|
|
43
55
|
try {
|
|
44
56
|
const previous = readScripts(before);
|
|
45
57
|
const current = readScripts(after);
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
// Flag modifications or removals of existing scripts, plus new pre/post
|
|
59
|
+
// hooks attached to an existing gate script, without blocking independent new scripts.
|
|
60
|
+
const modified = Object.entries(previous).some(([key, value]) => current[key] !== value);
|
|
61
|
+
const hooksExistingGate = Object.keys(current).some(key => {
|
|
62
|
+
if (Object.hasOwn(previous, key)) return false;
|
|
63
|
+
const target = lifecycleTarget(key);
|
|
64
|
+
return Boolean(target && Object.hasOwn(previous, target) && gateScript(target));
|
|
65
|
+
});
|
|
66
|
+
if (modified || hooksExistingGate) {
|
|
48
67
|
findings.push({ file, kind: 'package-gate-changed' });
|
|
49
68
|
}
|
|
50
69
|
} catch {
|
|
51
70
|
findings.push({ file, kind: 'package-gate-unreadable' });
|
|
52
71
|
}
|
|
53
72
|
}
|
|
54
|
-
if (deleted.has(file)) continue;
|
|
73
|
+
if (deleted.has(file) || !testFile.test(file)) continue;
|
|
55
74
|
const patch = git(['--literal-pathspecs', 'diff', '--no-ext-diff', '--no-textconv',
|
|
56
75
|
'--no-renames', '--unified=0', range, '--', file]);
|
|
57
76
|
let line = null;
|
|
@@ -96,7 +115,7 @@ function evaluateGate({ cwd = process.cwd(), base, pr, gh = args => command('gh'
|
|
|
96
115
|
const range = `${candidate.mergeBase}..${candidate.head}`;
|
|
97
116
|
candidate.paths = splitPaths(git(['diff', '--no-renames', '--name-only', '-z', range, '--']));
|
|
98
117
|
if (!candidate.paths.length) add('blocked', 'EMPTY_DIFF');
|
|
99
|
-
if (candidate.paths.
|
|
118
|
+
if (candidate.paths.some(isPolicyFile)) add('blocked', 'POLICY_CHANGED', { paths: [POLICY_FILE] });
|
|
100
119
|
if (candidate.behind) {
|
|
101
120
|
const basePaths = new Set(splitPaths(git(['log', '--format=', '--name-only', '-z', '--no-renames',
|
|
102
121
|
'--diff-merges=first-parent', `${candidate.mergeBase}..${candidate.baseSha}`, '--'])));
|
|
@@ -105,8 +124,8 @@ function evaluateGate({ cwd = process.cwd(), base, pr, gh = args => command('gh'
|
|
|
105
124
|
}
|
|
106
125
|
try {
|
|
107
126
|
policy = loadPolicy(git, candidate.baseSha);
|
|
108
|
-
} catch {
|
|
109
|
-
add('blocked', 'INVALID_TRUSTED_POLICY');
|
|
127
|
+
} catch (err) {
|
|
128
|
+
add('blocked', 'INVALID_TRUSTED_POLICY', { detail: sanitizeErrorDetail(err?.detail || err?.message) });
|
|
110
129
|
}
|
|
111
130
|
if (policy) {
|
|
112
131
|
if (policy.delivery.requireGateIntegrity) {
|
|
@@ -117,8 +136,8 @@ function evaluateGate({ cwd = process.cwd(), base, pr, gh = args => command('gh'
|
|
|
117
136
|
add('observe-only', 'POLICY_CAPS_DELIVERY_AT_PR');
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
|
-
} catch {
|
|
121
|
-
add('unverified', 'GIT_EVIDENCE_UNAVAILABLE');
|
|
139
|
+
} catch (err) {
|
|
140
|
+
add('unverified', 'GIT_EVIDENCE_UNAVAILABLE', { detail: sanitizeErrorDetail(err?.detail || err?.message) });
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
if (policy) {
|
|
@@ -139,8 +158,8 @@ function evaluateGate({ cwd = process.cwd(), base, pr, gh = args => command('gh'
|
|
|
139
158
|
if (!hosted.hasCI) add('unverified', 'NO_HEAD_CI');
|
|
140
159
|
else if (!hosted.greenCI) add('blocked', 'HEAD_CI_NOT_GREEN');
|
|
141
160
|
}
|
|
142
|
-
} catch {
|
|
143
|
-
add('unverified', 'GITHUB_EVIDENCE_UNAVAILABLE');
|
|
161
|
+
} catch (err) {
|
|
162
|
+
add('unverified', 'GITHUB_EVIDENCE_UNAVAILABLE', { detail: sanitizeErrorDetail(err?.detail || err?.message) });
|
|
144
163
|
}
|
|
145
164
|
}
|
|
146
165
|
const verdict = ['blocked', 'unverified', 'observe-only'].find(level =>
|
|
@@ -148,7 +167,7 @@ function evaluateGate({ cwd = process.cwd(), base, pr, gh = args => command('gh'
|
|
|
148
167
|
return { ok: verdict === 'eligible' || verdict === 'observe-only', verdict, candidate, policy, repository: repo, pr: hosted, reasons };
|
|
149
168
|
}
|
|
150
169
|
|
|
151
|
-
function mergeCandidate({ sha, cwd = process.cwd(), gh = args => command('gh', args, cwd), ...options }) {
|
|
170
|
+
function mergeCandidate({ sha, mergeMethod, cwd = process.cwd(), gh = args => command('gh', args, cwd), ...options }) {
|
|
152
171
|
const result = evaluateGate({ ...options, cwd, gh });
|
|
153
172
|
if (result.verdict !== 'eligible' || result.candidate.head !== sha) {
|
|
154
173
|
const reasons = [...result.reasons];
|
|
@@ -160,15 +179,28 @@ function mergeCandidate({ sha, cwd = process.cwd(), gh = args => command('gh', a
|
|
|
160
179
|
if (upstream.split('\t')[0] !== result.candidate.baseSha) {
|
|
161
180
|
return { ...result, ok: false, verdict: 'unverified', reasons: [{ level: 'unverified', code: 'PR_BASE_MOVED' }] };
|
|
162
181
|
}
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
182
|
+
const method = mergeMethod || result.policy.delivery.mergeMethod || 'merge';
|
|
183
|
+
const mergeSha = mergePullRequest(gh, result.repository, result.pr.number, sha, method);
|
|
184
|
+
return { ...result, merged: true, mergeSha, mergeMethod: method };
|
|
185
|
+
} catch (err) {
|
|
186
|
+
return {
|
|
187
|
+
...result,
|
|
188
|
+
ok: false,
|
|
189
|
+
verdict: 'unverified',
|
|
190
|
+
reasons: [{ level: 'unverified', code: 'MERGE_NOT_CONFIRMED', detail: sanitizeErrorDetail(err?.detail || err?.message) }],
|
|
191
|
+
};
|
|
167
192
|
}
|
|
168
193
|
}
|
|
169
194
|
|
|
170
195
|
function initRepository(cwd = process.cwd()) {
|
|
171
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
ok: true,
|
|
198
|
+
policyFile: initPolicy(gitRunner(cwd)(['rev-parse', '--show-toplevel']).trim()),
|
|
199
|
+
notes: [
|
|
200
|
+
'delivery.* fields are enforced by the CLI; review.* and steward.* fields are advisory guidance for the agent.',
|
|
201
|
+
'Configure GitHub branch protection with required status checks and up-to-date branches before enabling enforce/merge.',
|
|
202
|
+
],
|
|
203
|
+
};
|
|
172
204
|
}
|
|
173
205
|
|
|
174
206
|
module.exports = { evaluateGate, mergeCandidate, initRepository, integrityFindings };
|
package/lib/github.js
CHANGED
|
@@ -73,9 +73,13 @@ function readPullRequest(gh, { repo, pr, branch, base, requireGreenCI }) {
|
|
|
73
73
|
return state;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
function mergePullRequest(gh, repo, number, sha) {
|
|
77
|
-
const
|
|
78
|
-
`repos/${repo}/pulls/${number}/merge`, '-f', `sha=${sha}`]
|
|
76
|
+
function mergePullRequest(gh, repo, number, sha, mergeMethod = 'merge') {
|
|
77
|
+
const args = ['api', '--hostname', 'github.com', '--method', 'PUT',
|
|
78
|
+
`repos/${repo}/pulls/${number}/merge`, '-f', `sha=${sha}`];
|
|
79
|
+
if (mergeMethod && mergeMethod !== 'merge') {
|
|
80
|
+
args.push('-f', `merge_method=${mergeMethod}`);
|
|
81
|
+
}
|
|
82
|
+
const result = JSON.parse(gh(args));
|
|
79
83
|
if (result.merged !== true) throw new Error('GitHub did not confirm the merge.');
|
|
80
84
|
return result.sha;
|
|
81
85
|
}
|
package/lib/install.js
CHANGED
package/lib/ops-util.js
CHANGED
|
@@ -45,10 +45,19 @@ function replaceManagedFiles(paths, sourceRoot, currentManifest, newManifest) {
|
|
|
45
45
|
throw refuse('Refusing to replace a file not owned by @egawilldoit/factory.', rel);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
// Write/overwrite new managed files atomically first so a mid-copy failure
|
|
49
|
+
// never leaves the existing installation gutted before recovery runs.
|
|
49
50
|
for (const rel of Object.keys(newManifest.files)) {
|
|
50
51
|
fsu.copyFileAtomic(path.join(sourceRoot, rel), installedPath(paths, rel));
|
|
51
52
|
}
|
|
53
|
+
if (currentManifest) {
|
|
54
|
+
for (const rel of Object.keys(currentManifest.files)) {
|
|
55
|
+
if (!Object.hasOwn(newManifest.files, rel)) {
|
|
56
|
+
const p = installedPath(paths, rel);
|
|
57
|
+
if (fsu.isFile(p)) fs.unlinkSync(p);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
function savePrevious(paths, currentManifest) {
|
package/lib/policy.js
CHANGED
|
@@ -4,11 +4,13 @@ const { writeFileSync } = require('node:fs');
|
|
|
4
4
|
const { join } = require('node:path');
|
|
5
5
|
|
|
6
6
|
const POLICY_FILE = '.factory.json';
|
|
7
|
+
const MERGE_METHODS = ['merge', 'squash', 'rebase'];
|
|
7
8
|
const DEFAULT_POLICY = {
|
|
8
9
|
schemaVersion: 1,
|
|
9
10
|
delivery: {
|
|
10
11
|
mode: 'observe',
|
|
11
12
|
maximumBoundary: 'pr',
|
|
13
|
+
mergeMethod: 'merge',
|
|
12
14
|
requireGreenCI: true,
|
|
13
15
|
requireGateIntegrity: true,
|
|
14
16
|
},
|
|
@@ -35,6 +37,7 @@ function parsePolicy(source) {
|
|
|
35
37
|
else if (typeof expected === 'number') valid = Number.isSafeInteger(value) && value >= 0;
|
|
36
38
|
else if (key === 'mode') valid = ['observe', 'enforce'].includes(value);
|
|
37
39
|
else if (key === 'maximumBoundary') valid = ['pr', 'merge'].includes(value);
|
|
40
|
+
else if (key === 'mergeMethod') valid = MERGE_METHODS.includes(value);
|
|
38
41
|
else if (key === 'depth') valid = ['light', 'standard', 'deep'].includes(value);
|
|
39
42
|
if (!valid) throw new Error(`Invalid policy field ${section}.${key}.`);
|
|
40
43
|
policy[section][key] = value;
|
|
@@ -58,4 +61,4 @@ function initPolicy(root) {
|
|
|
58
61
|
return path;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
module.exports = { DEFAULT_POLICY, POLICY_FILE, parsePolicy, loadPolicy, initPolicy };
|
|
64
|
+
module.exports = { DEFAULT_POLICY, MERGE_METHODS, POLICY_FILE, parsePolicy, loadPolicy, initPolicy };
|
package/lib/recovery.js
CHANGED
|
@@ -157,10 +157,10 @@ function clearTransient(paths) {
|
|
|
157
157
|
|
|
158
158
|
// Called at the start of every command that touches the installation. It never
|
|
159
159
|
// removes an active owner's lock and never overwrites unrecognised bytes.
|
|
160
|
-
function runRecovery(paths) {
|
|
160
|
+
function runRecovery(paths, { allowSelfLock = false } = {}) {
|
|
161
161
|
const state = inspectRecoveryState(paths);
|
|
162
162
|
|
|
163
|
-
if (state.lock && isPidAlive(state.lock.pid)) {
|
|
163
|
+
if (state.lock && isPidAlive(state.lock.pid) && !(allowSelfLock && state.lock.pid === process.pid)) {
|
|
164
164
|
throw recovery(
|
|
165
165
|
`An installer process (pid ${state.lock.pid}) still holds the lock.`,
|
|
166
166
|
`Refusing to clear an active lock. Wait for it to finish, then retry. Lock: ${paths.lockFile}`
|
package/lib/rollback.js
CHANGED
|
@@ -54,7 +54,8 @@ function rollback({ paths }) {
|
|
|
54
54
|
fsu.removeTree(paths.previousDir);
|
|
55
55
|
fsu.ensureDir(paths.previousDir);
|
|
56
56
|
for (const rel of Object.keys(current.files)) {
|
|
57
|
-
|
|
57
|
+
const src = path.join(tmp, rel);
|
|
58
|
+
if (fsu.isFile(src)) fsu.copyFileAtomic(src, path.join(paths.previousDir, rel));
|
|
58
59
|
}
|
|
59
60
|
fsu.writeJsonAtomic(paths.previousManifest, current);
|
|
60
61
|
fsu.removeTree(tmp);
|
|
@@ -68,7 +69,7 @@ function rollback({ paths }) {
|
|
|
68
69
|
notes,
|
|
69
70
|
};
|
|
70
71
|
} catch (err) {
|
|
71
|
-
try { runRecovery(paths); } catch (_) {}
|
|
72
|
+
try { runRecovery(paths, { allowSelfLock: true }); } catch (_) {}
|
|
72
73
|
throw err;
|
|
73
74
|
} finally {
|
|
74
75
|
releaseLock(paths);
|
package/lib/uninstall.js
CHANGED
|
@@ -36,9 +36,17 @@ function uninstall({ paths }) {
|
|
|
36
36
|
const p = path.join(paths.dest, rel);
|
|
37
37
|
if (fsu.isFile(p)) fs.unlinkSync(p);
|
|
38
38
|
}
|
|
39
|
-
// Remove
|
|
40
|
-
for (const name of SKILL_NAMES)
|
|
41
|
-
|
|
39
|
+
// Remove nested empty subdirectories (e.g. skills/<name>/agents) and owned roots.
|
|
40
|
+
for (const name of SKILL_NAMES) {
|
|
41
|
+
const skillDir = path.join(paths.skillsRoot, name);
|
|
42
|
+
fsu.pruneEmptyDirs(skillDir);
|
|
43
|
+
removeEmptyDir(skillDir);
|
|
44
|
+
}
|
|
45
|
+
for (const name of ['references', 'templates', 'docs']) {
|
|
46
|
+
const dir = path.join(paths.dest, name);
|
|
47
|
+
fsu.pruneEmptyDirs(dir);
|
|
48
|
+
removeEmptyDir(dir);
|
|
49
|
+
}
|
|
42
50
|
removeEmptyDir(paths.skillsRoot);
|
|
43
51
|
|
|
44
52
|
fsu.removeTree(paths.metaDir);
|
package/lib/update.js
CHANGED