@imdeadpool/guardex 8.2.0 → 8.3.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 -8
- package/bin/multiagent-safety.js +18 -1
- package/package.json +1 -1
- package/skills/gitguardex/SKILL.md +26 -2
- package/src/cli/args.js +10 -1
- package/src/cli/commands/agents.js +1 -0
- package/src/cli/commands/branch.js +52 -1
- package/src/cli/commands/finish.js +44 -2
- package/src/cli/shared-locks.js +4 -0
- package/src/doctor/index.js +26 -26
- package/src/finish/index.js +10 -2
- package/src/finish/post-branch-finish-cleanup.js +324 -0
- package/src/finish/review-gate.js +47 -6
- package/src/git/index.js +9 -4
- package/src/pr-checks.js +20 -5
- package/src/pr.js +122 -1
- package/src/scaffold/index.js +10 -0
- package/templates/AGENTS.multiagent-safety.md +37 -9
- package/templates/AGENTS.multiagent-safety.min.md +10 -4
- package/templates/codex/skills/gitguardex/SKILL.md +26 -2
- package/templates/githooks/pre-commit +40 -5
- package/templates/githooks/pre-push +72 -25
- package/templates/scripts/agent-branch-finish.sh +300 -21
- package/templates/scripts/agent-branch-start.sh +22 -2
- package/templates/scripts/agent-file-locks.py +88 -3
- package/templates/scripts/agent-preflight.sh +30 -0
- package/templates/scripts/agent-reconcile-openspec-tasks.js +105 -0
- package/templates/scripts/agent-worktree-prune.sh +396 -31
- package/templates/scripts/guardex-env.sh +291 -0
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
<p align="center">
|
|
21
21
|
<a href="#install">Install</a> ·
|
|
22
22
|
<a href="#the-problem">Why</a> ·
|
|
23
|
+
<a href="#what-gitguardex-can-do">Capabilities</a> ·
|
|
23
24
|
<a href="#daily-workflow">Workflow</a> ·
|
|
24
25
|
<a href="#code-assist-review-gate">Code assist</a> ·
|
|
25
26
|
<a href="#essential-commands">Commands</a>
|
|
@@ -56,19 +57,50 @@ Linux; use WSL on Windows.
|
|
|
56
57
|
Parallel agents can edit the same files, overwrite tests, or commit directly to
|
|
57
58
|
`main`. More agents can create more conflicts instead of more progress.
|
|
58
59
|
|
|
59
|
-
###
|
|
60
|
+
### What GitGuardex can do
|
|
60
61
|
|
|
61
62
|

|
|
62
63
|
|
|
63
64
|
GitGuardex gives every task an isolated lane:
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
<p align="center">
|
|
67
|
+
<strong>Start lane → Claim files → Build → Verify → PR → Merge → Cleanup</strong>
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
#### 🔒 Isolate and coordinate
|
|
71
|
+
|
|
72
|
+
- **Dedicated task lanes** — each `agent/*` branch gets its own worktree, so
|
|
73
|
+
agents never share a working directory.
|
|
74
|
+
- **Shared file ownership** — independent lanes and clones coordinate claims
|
|
75
|
+
before editing.
|
|
76
|
+
- **Protected base branches** — changes to `main`, `dev`, and `master` must go
|
|
77
|
+
through a PR.
|
|
78
|
+
|
|
79
|
+
#### ✅ Ship with evidence
|
|
80
|
+
|
|
81
|
+
- **Preflight, CI, and optional AI review** — broken or risky changes stop
|
|
82
|
+
before merge.
|
|
83
|
+
- **Safe finish** — merge the PR, then remove its temporary branch and
|
|
84
|
+
worktree.
|
|
85
|
+
- **Correct base targeting** — persist and validate each lane's base so an
|
|
86
|
+
unattended finish cannot use another checkout's target. ([#745](https://github.com/opencue/gitguardex/pull/745), [#750](https://github.com/opencue/gitguardex/pull/750), [#751](https://github.com/opencue/gitguardex/pull/751))
|
|
87
|
+
- **Billing-aware CI fallback** — waive only named checks that GitHub could not
|
|
88
|
+
start because of billing, while keeping repository preflight mandatory.
|
|
89
|
+
([#743](https://github.com/opencue/gitguardex/pull/743))
|
|
90
|
+
- **OpenSpec progress reconciliation** — merge conflicting `tasks.md` progress
|
|
91
|
+
deterministically and validate it before continuing. ([#753](https://github.com/opencue/gitguardex/pull/753))
|
|
92
|
+
- **Reusable successful preflight** — reuse proof only while the source HEAD,
|
|
93
|
+
base commit, command, and script stay unchanged; billing-waiver preflights
|
|
94
|
+
are never cached. ([#757](https://github.com/opencue/gitguardex/pull/757))
|
|
95
|
+
|
|
96
|
+
#### 🧹 Recover without losing work
|
|
97
|
+
|
|
98
|
+
- **Fail-closed cleanup** — preserve dirty, locked, open-PR, blocked, or
|
|
99
|
+
uncertain lanes; close idle clean worktrees without deleting their branches.
|
|
100
|
+
([#741](https://github.com/opencue/gitguardex/pull/741), [#744](https://github.com/opencue/gitguardex/pull/744), [#746](https://github.com/opencue/gitguardex/pull/746), [#752](https://github.com/opencue/gitguardex/pull/752))
|
|
101
|
+
- **Workspace hygiene** — safely remove successful detached lanes, avoid stale
|
|
102
|
+
VS Code worktree providers, and keep `gx branch finish --help` free of
|
|
103
|
+
repository side effects. ([#742](https://github.com/opencue/gitguardex/pull/742), [#747](https://github.com/opencue/gitguardex/pull/747), [#748](https://github.com/opencue/gitguardex/pull/748), [#754](https://github.com/opencue/gitguardex/pull/754))
|
|
72
104
|
|
|
73
105
|
---
|
|
74
106
|
|
|
@@ -190,6 +222,13 @@ finds the last published GitHub release, and writes one grouped GitHub release b
|
|
|
190
222
|
<details>
|
|
191
223
|
<summary><strong>v8.x</strong></summary>
|
|
192
224
|
|
|
225
|
+
### v8.3.0
|
|
226
|
+
- Added adaptive direct-main agent work and branch-targeted `gx sync`.
|
|
227
|
+
- Made worktree cleanup safer by preserving active or locked lanes while pruning
|
|
228
|
+
only eligible merged or opted-in clean lanes.
|
|
229
|
+
- Persisted and validated explicit finish bases, recognized SHA-256 null object
|
|
230
|
+
IDs, and prevented stale VS Code worktree providers.
|
|
231
|
+
|
|
193
232
|
### v8.2.0
|
|
194
233
|
- Reduced agent preflight and finish token overhead.
|
|
195
234
|
- Preserved dirty worktrees during stale-worktree cleanup and exposed
|
package/bin/multiagent-safety.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { runFromBin } = require('../src/cli/main');
|
|
4
|
+
const {
|
|
5
|
+
cleanupFinishedDetachedWorktree,
|
|
6
|
+
hasLiveProcessInWorktree,
|
|
7
|
+
prepareBranchFinishCleanup,
|
|
8
|
+
scheduleFinishedDetachedWorktreeCleanup
|
|
9
|
+
} = require('../src/finish/post-branch-finish-cleanup');
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
const finishCleanup = prepareBranchFinishCleanup(process.argv.slice(2), process.cwd());
|
|
12
|
+
|
|
13
|
+
void runFromBin().then(() => {
|
|
14
|
+
if (!process.exitCode && finishCleanup) {
|
|
15
|
+
process.chdir(finishCleanup.repoRoot);
|
|
16
|
+
if (hasLiveProcessInWorktree(finishCleanup.worktreePath)) {
|
|
17
|
+
scheduleFinishedDetachedWorktreeCleanup(finishCleanup);
|
|
18
|
+
} else {
|
|
19
|
+
cleanupFinishedDetachedWorktree(finishCleanup);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imdeadpool/guardex",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "Guardian T-Rex for your multi-agent repo. Isolated worktrees, file locks, and PR-only merges stop parallel Codex & Claude agents from overwriting each other's work. Auto-wires Oh My Codex, Oh My Claude, OpenSpec, and Caveman.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"preferGlobal": true,
|
|
@@ -10,6 +10,30 @@ Use when a GitGuardex-managed repository needs safe edits or multi-agent coordin
|
|
|
10
10
|
Bootstrap: `gx setup`
|
|
11
11
|
Ops: `gx branch start "<task>" "<agent>"`, `gx locks claim --branch "<agent-branch>" <file...>`, `gx branch finish --branch "<agent-branch>" --base <base> --via-pr --wait-for-merge --cleanup`, `gx finish --all`, `gx cleanup`
|
|
12
12
|
|
|
13
|
+
## Choose the lane before editing
|
|
14
|
+
|
|
15
|
+
Worktree policy is strict `always` unless the repo opts into `adaptive` with
|
|
16
|
+
`GUARDEX_WORKTREE_MODE=adaptive` in `.env` or
|
|
17
|
+
`git config --local multiagent.worktreeMode adaptive`.
|
|
18
|
+
|
|
19
|
+
1. Run `gx status`. In adaptive mode, also inspect `list_agents` (or
|
|
20
|
+
`gx mcp list-agents --no-prs`), the current dirty paths, and `who_owns` for
|
|
21
|
+
every intended file.
|
|
22
|
+
2. Stay on the current checkout only for bounded, single-agent work with no
|
|
23
|
+
competing writer, claimed target, or dirty-path overlap.
|
|
24
|
+
3. Pivot to a new isolated lane when the task is substantial/long-lived,
|
|
25
|
+
another writer is active in the repo, a target is owned or dirty elsewhere,
|
|
26
|
+
or the scope expands. Use
|
|
27
|
+
`gx branch start --new --no-transfer "<bounded task>" "<agent>"`.
|
|
28
|
+
4. Re-run the radar before expanding scope. Never overwrite another lane's
|
|
29
|
+
changes. If direct work already has edits when a pivot becomes necessary,
|
|
30
|
+
transfer only those known edits deliberately; do not absorb unrelated files.
|
|
31
|
+
|
|
32
|
+
Direct adaptive work supports file edits, `git add`/ordinary commit/push, and
|
|
33
|
+
bounded test/lint/build commands. Custom executors, scripts, or history rewrites
|
|
34
|
+
pivot to an isolated lane. Isolated work uses claims and the gated
|
|
35
|
+
`gx branch finish` flow below.
|
|
36
|
+
|
|
13
37
|
## Keep the default workflow lean
|
|
14
38
|
|
|
15
39
|
- Default to direct T1 work in code and tests. Do not create OpenSpec artifacts from task wording alone.
|
|
@@ -24,11 +48,11 @@ Before parallel work, inspect the field with the MCP `list_agents` tool or the C
|
|
|
24
48
|
gx mcp list-agents --no-prs
|
|
25
49
|
```
|
|
26
50
|
|
|
27
|
-
For every file a writer may touch, check ownership, create an isolated lane, then claim it:
|
|
51
|
+
For every file a parallel writer may touch, check ownership, create an isolated lane, then claim it:
|
|
28
52
|
|
|
29
53
|
```sh
|
|
30
54
|
gx mcp who-owns path/to/file.ts
|
|
31
|
-
gx branch start "<bounded task>" "<agent>"
|
|
55
|
+
gx branch start --new --no-transfer "<bounded task>" "<agent>"
|
|
32
56
|
gx locks claim --branch "<agent-branch>" path/to/file.ts
|
|
33
57
|
```
|
|
34
58
|
|
package/src/cli/args.js
CHANGED
|
@@ -960,7 +960,8 @@ function parseCleanupArgs(rawArgs) {
|
|
|
960
960
|
dryRun: false,
|
|
961
961
|
forceDirty: false,
|
|
962
962
|
keepRemote: false,
|
|
963
|
-
keepCleanWorktrees:
|
|
963
|
+
keepCleanWorktrees: true,
|
|
964
|
+
includeCleanLinkedWorktrees: false,
|
|
964
965
|
includePrMerged: false,
|
|
965
966
|
idleMinutes: 0,
|
|
966
967
|
watch: false,
|
|
@@ -1014,6 +1015,14 @@ function parseCleanupArgs(rawArgs) {
|
|
|
1014
1015
|
options.keepCleanWorktrees = true;
|
|
1015
1016
|
continue;
|
|
1016
1017
|
}
|
|
1018
|
+
if (arg === '--prune-clean-worktrees') {
|
|
1019
|
+
options.keepCleanWorktrees = false;
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
if (arg === '--include-clean-linked-worktrees') {
|
|
1023
|
+
options.includeCleanLinkedWorktrees = true;
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1017
1026
|
if (arg === '--include-pr-merged') {
|
|
1018
1027
|
options.includePrMerged = true;
|
|
1019
1028
|
continue;
|
|
@@ -26,6 +26,48 @@ const { locks } = require('../shared-locks');
|
|
|
26
26
|
|
|
27
27
|
const REVIEW_PROVIDERS = ['codex', 'claude'];
|
|
28
28
|
|
|
29
|
+
function printBranchFinishHelp() {
|
|
30
|
+
console.log(`USAGE: ${SHORT_TOOL_NAME} branch finish [options]
|
|
31
|
+
|
|
32
|
+
Finish an agent branch by committing pending work, publishing it, opening or
|
|
33
|
+
updating a PR, enforcing optional gates, merging, and cleaning up.
|
|
34
|
+
|
|
35
|
+
TARGET
|
|
36
|
+
--target <path> Target repository (default: current directory)
|
|
37
|
+
--branch <branch> Agent branch to finish (default: current branch)
|
|
38
|
+
--base <branch> Destination branch
|
|
39
|
+
|
|
40
|
+
PUBLISH AND MERGE
|
|
41
|
+
--via-pr Finish through a pull request
|
|
42
|
+
--direct-only Finish by direct merge only
|
|
43
|
+
--no-push Do not push the branch
|
|
44
|
+
--wait-for-merge Wait until the PR is merged
|
|
45
|
+
--cleanup Remove the finished worktree and branch
|
|
46
|
+
--keep-remote-branch Preserve the remote branch after merge
|
|
47
|
+
|
|
48
|
+
VERIFICATION
|
|
49
|
+
--gate-review Require AI review and green CI before merge
|
|
50
|
+
--gate-autofix Repair blocking review findings and review again
|
|
51
|
+
--gate-autofix-rounds <n> Limit repair rounds to 1-5 (default: 1)
|
|
52
|
+
--gate-baseline Ignore failures already present on the base branch
|
|
53
|
+
--review-provider <name> Review provider: codex|claude
|
|
54
|
+
--review-model <name> Model used by the review provider
|
|
55
|
+
--review-timeout-ms <n> Positive review timeout in milliseconds
|
|
56
|
+
--no-preflight Skip the repository preflight script
|
|
57
|
+
--preflight Run the repository preflight script
|
|
58
|
+
|
|
59
|
+
COMMIT
|
|
60
|
+
--no-auto-commit Refuse to auto-commit pending work
|
|
61
|
+
--commit-message <message> Message for the automatic finish commit
|
|
62
|
+
|
|
63
|
+
-h, --help Show this help without touching the repository`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isBranchFinishHelpRequest(args) {
|
|
67
|
+
return args.some((arg) => arg === '--help' || arg === '-h')
|
|
68
|
+
|| (args.length === 1 && args[0] === 'help');
|
|
69
|
+
}
|
|
70
|
+
|
|
29
71
|
// Review-gate and auto-commit options are gx-level flags.
|
|
30
72
|
// agent-branch-finish.sh does not parse them (it exits 1 on the unknown
|
|
31
73
|
// argument), and its --via-pr path merges the moment the PR opens, so the shell
|
|
@@ -206,6 +248,13 @@ function branch(rawArgs) {
|
|
|
206
248
|
return;
|
|
207
249
|
}
|
|
208
250
|
if (subcommand === 'finish') {
|
|
251
|
+
// Help is a read-only control path. Handle it before target resolution,
|
|
252
|
+
// worktree discovery, progress initialization, or the automatic commit.
|
|
253
|
+
if (isBranchFinishHelpRequest(rest)) {
|
|
254
|
+
printBranchFinishHelp();
|
|
255
|
+
process.exitCode = 0;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
209
258
|
const { target, passthrough } = extractTargetedArgs(rest);
|
|
210
259
|
const repoRoot = resolveRepoRoot(target);
|
|
211
260
|
const {
|
|
@@ -256,8 +305,9 @@ function branch(rawArgs) {
|
|
|
256
305
|
// Fail-closed: runReviewGate throws on a dirty review, red CI, or a PR
|
|
257
306
|
// GitHub will not merge. Throwing here means the script never runs, so
|
|
258
307
|
// the merge never happens.
|
|
308
|
+
let gateResult;
|
|
259
309
|
if (gateReview) {
|
|
260
|
-
runReviewGate({
|
|
310
|
+
gateResult = runReviewGate({
|
|
261
311
|
repoRoot,
|
|
262
312
|
branch: finishBranch,
|
|
263
313
|
// Must match how the shell resolves --base when it is omitted, which
|
|
@@ -288,6 +338,7 @@ function branch(rawArgs) {
|
|
|
288
338
|
GUARDEX_FINISH_ACTIVE_CWD: activeCwd,
|
|
289
339
|
GUARDEX_FINISH_CHECKLIST: '1',
|
|
290
340
|
GUARDEX_FINISH_GATE_DONE: gateReview ? '1' : '0',
|
|
341
|
+
GUARDEX_FINISH_REQUIRE_PREFLIGHT: gateResult?.billingChecksWaived?.length > 0 ? '1' : '0',
|
|
291
342
|
...progress.eventEnv,
|
|
292
343
|
},
|
|
293
344
|
};
|
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
// `gx cleanup`, `gx merge`, `gx finish`, `gx sync` — thin wrappers around
|
|
2
2
|
// the finishCommands module. Pure code-motion from src/cli/main.js.
|
|
3
3
|
const finishCommands = require('../../finish');
|
|
4
|
+
const { resolveRepoRoot, listAgentWorktrees, branchExists } = require('../../git');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Translate `gx sync --branch <agent/*>` into the existing worktree-oriented
|
|
8
|
+
* `--target` form. Sync changes the checked-out branch, so a named branch must
|
|
9
|
+
* already have a linked worktree instead of being checked out behind the
|
|
10
|
+
* caller's back.
|
|
11
|
+
*
|
|
12
|
+
* @param {ReadonlyArray<string>} rawArgs CLI argv slice for the sync command.
|
|
13
|
+
* @returns {string[]} Arguments accepted by the core sync parser.
|
|
14
|
+
*/
|
|
15
|
+
function resolveSyncBranchTarget(rawArgs) {
|
|
16
|
+
const args = [...rawArgs];
|
|
17
|
+
const branchIndex = args.indexOf('--branch');
|
|
18
|
+
if (branchIndex === -1) return args;
|
|
19
|
+
|
|
20
|
+
const branch = args[branchIndex + 1];
|
|
21
|
+
if (!branch) throw new Error('--branch requires an agent/* branch value');
|
|
22
|
+
if (!branch.startsWith('agent/')) {
|
|
23
|
+
throw new Error(`--branch must reference an agent/* branch (received: ${branch})`);
|
|
24
|
+
}
|
|
25
|
+
if (args.includes('--all-agent-branches')) {
|
|
26
|
+
throw new Error('--branch cannot be combined with --all-agent-branches');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const targetIndex = args.indexOf('--target');
|
|
30
|
+
const target = targetIndex === -1 ? process.cwd() : args[targetIndex + 1];
|
|
31
|
+
if (!target) throw new Error('--target requires a path value');
|
|
32
|
+
|
|
33
|
+
const repoRoot = resolveRepoRoot(target);
|
|
34
|
+
const worktree = listAgentWorktrees(repoRoot).find((entry) => entry.branch === branch);
|
|
35
|
+
if (!worktree) {
|
|
36
|
+
if (!branchExists(repoRoot, branch)) throw new Error(`Local branch not found: ${branch}`);
|
|
37
|
+
throw new Error(`Agent branch '${branch}' is not checked out in a linked worktree`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
args.splice(branchIndex, 2);
|
|
41
|
+
const normalizedTargetIndex = args.indexOf('--target');
|
|
42
|
+
if (normalizedTargetIndex === -1) args.push('--target', worktree.worktreePath);
|
|
43
|
+
else args[normalizedTargetIndex + 1] = worktree.worktreePath;
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
4
46
|
|
|
5
47
|
function cleanup(rawArgs) {
|
|
6
48
|
return finishCommands.cleanup(rawArgs);
|
|
@@ -15,12 +57,12 @@ function finish(rawArgs, defaults = {}) {
|
|
|
15
57
|
}
|
|
16
58
|
|
|
17
59
|
function sync(rawArgs) {
|
|
18
|
-
return finishCommands.sync(rawArgs);
|
|
60
|
+
return finishCommands.sync(resolveSyncBranchTarget(rawArgs));
|
|
19
61
|
}
|
|
20
62
|
|
|
21
63
|
module.exports = {
|
|
22
64
|
cleanup,
|
|
23
65
|
merge,
|
|
24
66
|
finish,
|
|
25
|
-
sync
|
|
67
|
+
sync
|
|
26
68
|
};
|
package/src/cli/shared-locks.js
CHANGED
|
@@ -35,6 +35,7 @@ function parseLockOperation(args) {
|
|
|
35
35
|
branch: '',
|
|
36
36
|
agent: process.env.GUARDEX_AGENT_ID || '',
|
|
37
37
|
allowDelete: false,
|
|
38
|
+
allowUnclaimed: false,
|
|
38
39
|
staged: false,
|
|
39
40
|
files: []
|
|
40
41
|
};
|
|
@@ -56,6 +57,8 @@ function parseLockOperation(args) {
|
|
|
56
57
|
parsed.agent = arg.slice('--agent='.length);
|
|
57
58
|
} else if (arg === '--allow-delete') {
|
|
58
59
|
parsed.allowDelete = true;
|
|
60
|
+
} else if (arg === '--allow-unclaimed') {
|
|
61
|
+
parsed.allowUnclaimed = true;
|
|
59
62
|
} else if (arg === '--staged') {
|
|
60
63
|
parsed.staged = true;
|
|
61
64
|
} else if (arg.startsWith('-')) {
|
|
@@ -212,6 +215,7 @@ function sharedValidate(repoRoot, args, parsed) {
|
|
|
212
215
|
const files = parsed.staged ? stagedFiles(repoRoot) : parsed.files;
|
|
213
216
|
try {
|
|
214
217
|
for (const file of files) {
|
|
218
|
+
if (parsed.allowUnclaimed && !sharedGitState.getLock(repoRoot, file)) continue;
|
|
215
219
|
sharedGitState.validateLock(repoRoot, { file, branch: parsed.branch, agent: parsed.agent });
|
|
216
220
|
}
|
|
217
221
|
} catch (error) {
|
package/src/doctor/index.js
CHANGED
|
@@ -50,7 +50,6 @@ const {
|
|
|
50
50
|
} = require('../sandbox');
|
|
51
51
|
const { ensureOmxScaffold, configureHooks } = require('../scaffold');
|
|
52
52
|
const { detectRecoverableAutoFinishConflict, printAutoFinishSummary, isTerseMode } = require('../output');
|
|
53
|
-
const { autoCommitWorktreeForFinish } = require('../finish');
|
|
54
53
|
const { runReviewGate } = require('../finish/review-gate');
|
|
55
54
|
|
|
56
55
|
/**
|
|
@@ -980,49 +979,45 @@ function autoFinishReadyAgentBranches(repoRoot, options = {}) {
|
|
|
980
979
|
continue;
|
|
981
980
|
}
|
|
982
981
|
|
|
983
|
-
|
|
982
|
+
const branchBase = readGitConfig(repoRoot, `branch.${branch}.guardexBase`) || baseBranch;
|
|
983
|
+
if (!branchBase || branchBase === 'HEAD' || branchBase.startsWith('agent/')) {
|
|
984
984
|
summary.skipped += 1;
|
|
985
|
-
summary.details.push(`[skip] ${branch}:
|
|
985
|
+
summary.details.push(`[skip] ${branch}: recorded base is missing or invalid.`);
|
|
986
986
|
continue;
|
|
987
987
|
}
|
|
988
988
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
} catch (error) {
|
|
993
|
-
summary.failed += 1;
|
|
994
|
-
summary.details.push(`[fail] ${branch}: unable to compute ahead/behind (${error.message}).`);
|
|
989
|
+
if (branch === branchBase) {
|
|
990
|
+
summary.skipped += 1;
|
|
991
|
+
summary.details.push(`[skip] ${branch}: source branch equals base branch.`);
|
|
995
992
|
continue;
|
|
996
993
|
}
|
|
997
994
|
|
|
998
995
|
const branchWorktree = branchWorktrees.get(branch) || '';
|
|
999
996
|
if (branchWorktree && hasSignificantWorkingTreeChanges(branchWorktree)) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
} catch (error) {
|
|
1006
|
-
summary.failed += 1;
|
|
1007
|
-
summary.details.push(`[fail] ${branch}: auto-commit failed (${error.message}).`);
|
|
1008
|
-
continue;
|
|
1009
|
-
}
|
|
997
|
+
summary.skipped += 1;
|
|
998
|
+
summary.details.push(
|
|
999
|
+
`[skip] ${branch}: dirty worktree; refusing unattended auto-commit or sync (${branchWorktree}).`,
|
|
1000
|
+
);
|
|
1001
|
+
continue;
|
|
1010
1002
|
}
|
|
1011
1003
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1004
|
+
let counts;
|
|
1005
|
+
try {
|
|
1006
|
+
counts = aheadBehind(repoRoot, branch, branchBase);
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
summary.failed += 1;
|
|
1009
|
+
summary.details.push(`[fail] ${branch}: unable to compute ahead/behind (${error.message}).`);
|
|
1015
1010
|
continue;
|
|
1016
1011
|
}
|
|
1017
1012
|
|
|
1018
|
-
if (
|
|
1013
|
+
if (counts.ahead <= 0) {
|
|
1019
1014
|
summary.skipped += 1;
|
|
1020
|
-
summary.details.push(`[skip] ${branch}:
|
|
1015
|
+
summary.details.push(`[skip] ${branch}: already merged into ${branchBase}.`);
|
|
1021
1016
|
continue;
|
|
1022
1017
|
}
|
|
1023
1018
|
|
|
1024
1019
|
const gateOutcome = runAutoShipGateForBranch(
|
|
1025
|
-
{ autoShip, fallbackMode, repoRoot, branch, baseBranch },
|
|
1020
|
+
{ autoShip, fallbackMode, repoRoot, branch, baseBranch: branchBase },
|
|
1026
1021
|
{ runReviewGate: options.runReviewGate },
|
|
1027
1022
|
);
|
|
1028
1023
|
if (gateOutcome.skip) {
|
|
@@ -1036,7 +1031,7 @@ function autoFinishReadyAgentBranches(repoRoot, options = {}) {
|
|
|
1036
1031
|
'--branch',
|
|
1037
1032
|
branch,
|
|
1038
1033
|
'--base',
|
|
1039
|
-
|
|
1034
|
+
branchBase,
|
|
1040
1035
|
];
|
|
1041
1036
|
if (fallbackMode === 'local') {
|
|
1042
1037
|
finishArgs.push('--direct-only', '--no-push');
|
|
@@ -1103,6 +1098,11 @@ function pruneStaleAgentWorktrees(repoRoot, options = {}) {
|
|
|
1103
1098
|
|
|
1104
1099
|
const args = [
|
|
1105
1100
|
'--idle-minutes', String(idleMinutes),
|
|
1101
|
+
// Doctor may retire clean inactive lanes after the grace period, but the
|
|
1102
|
+
// prune asset must classify them from PR metadata first. Open PRs, dirty
|
|
1103
|
+
// worktrees, and live processes remain fail-closed recovery points.
|
|
1104
|
+
'--prune-stale-lanes',
|
|
1105
|
+
'--preserve-open-prs',
|
|
1106
1106
|
'--delete-branches',
|
|
1107
1107
|
'--delete-remote-branches',
|
|
1108
1108
|
'--include-pr-merged',
|
package/src/finish/index.js
CHANGED
|
@@ -223,7 +223,10 @@ OPTIONS
|
|
|
223
223
|
--dry-run Print actions without changing branches or worktrees
|
|
224
224
|
--force-dirty Allow cleanup of dirty worktrees
|
|
225
225
|
--keep-remote Keep remote agent branches
|
|
226
|
-
--
|
|
226
|
+
--prune-clean-worktrees Explicitly prune clean, unmerged agent worktrees
|
|
227
|
+
--keep-clean-worktrees Preserve clean, unmerged agent worktrees (default)
|
|
228
|
+
--include-clean-linked-worktrees
|
|
229
|
+
Also prune clean linked worktrees outside managed agent directories
|
|
227
230
|
--include-pr-merged Treat branches from merged PRs as merged
|
|
228
231
|
--idle-minutes <n> Only consider worktrees idle for at least n minutes
|
|
229
232
|
--watch Repeat cleanup cycles (defaults idle threshold to 60)
|
|
@@ -255,6 +258,9 @@ OPTIONS
|
|
|
255
258
|
if (!options.keepCleanWorktrees) {
|
|
256
259
|
args.push('--only-dirty-worktrees');
|
|
257
260
|
}
|
|
261
|
+
if (options.includeCleanLinkedWorktrees) {
|
|
262
|
+
args.push('--include-clean-linked-worktrees');
|
|
263
|
+
}
|
|
258
264
|
if (options.includePrMerged) {
|
|
259
265
|
args.push('--include-pr-merged');
|
|
260
266
|
}
|
|
@@ -564,8 +570,9 @@ function finish(rawArgs, defaults = {}) {
|
|
|
564
570
|
// Opt-in merge gate (--gate-review / gx ship): enforce a clean AI review +
|
|
565
571
|
// green CI + GitHub-mergeable verdict BEFORE the shell merge runs. Throws on
|
|
566
572
|
// failure, which the catch below turns into a finish failure (no merge).
|
|
573
|
+
let gateResult;
|
|
567
574
|
if (options.mergeMode === 'pr' && options.gateReview) {
|
|
568
|
-
runReviewGate({
|
|
575
|
+
gateResult = runReviewGate({
|
|
569
576
|
repoRoot, worktreePath, branch, baseBranch, options, progress,
|
|
570
577
|
});
|
|
571
578
|
} else {
|
|
@@ -596,6 +603,7 @@ function finish(rawArgs, defaults = {}) {
|
|
|
596
603
|
GUARDEX_FINISH_ACTIVE_CWD: activeCwd,
|
|
597
604
|
GUARDEX_FINISH_CHECKLIST: '1',
|
|
598
605
|
GUARDEX_FINISH_GATE_DONE: options.gateReview ? '1' : '0',
|
|
606
|
+
GUARDEX_FINISH_REQUIRE_PREFLIGHT: gateResult?.billingChecksWaived?.length > 0 ? '1' : '0',
|
|
599
607
|
...progress.eventEnv,
|
|
600
608
|
},
|
|
601
609
|
});
|