@imdeadpool/guardex 8.1.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 +57 -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 +15 -1
- package/src/cli/commands/agents.js +1 -0
- package/src/cli/commands/branch.js +84 -6
- package/src/cli/commands/finish.js +44 -2
- package/src/cli/shared-locks.js +4 -0
- package/src/doctor/index.js +26 -27
- package/src/finish/index.js +73 -20
- package/src/finish/post-branch-finish-cleanup.js +324 -0
- package/src/finish/progress.js +57 -3
- package/src/finish/review-gate.js +47 -6
- package/src/git/index.js +9 -4
- package/src/mcp/collect.js +84 -23
- package/src/mcp/server.js +35 -19
- 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 +119 -8
- 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,23 @@ 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
|
+
|
|
232
|
+
### v8.2.0
|
|
233
|
+
- Reduced agent preflight and finish token overhead.
|
|
234
|
+
- Preserved dirty worktrees during stale-worktree cleanup and exposed
|
|
235
|
+
command-specific cleanup help.
|
|
236
|
+
- Added the owning tmux pane and worktree to file-lock conflict output.
|
|
237
|
+
|
|
238
|
+
### v8.1.1
|
|
239
|
+
- Prevented `gx doctor` from pruning dirty detached or managed worktrees during
|
|
240
|
+
stale-worktree repair.
|
|
241
|
+
|
|
193
242
|
### v8.1.0
|
|
194
243
|
- Added shared Git lock state so independent clones coordinate file ownership.
|
|
195
244
|
- Aligned npm repository metadata with `opencue/gitguardex` for trusted OIDC
|
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;
|
|
@@ -1176,6 +1185,7 @@ function parseFinishArgs(rawArgs, defaults = {}) {
|
|
|
1176
1185
|
commitMessage: '',
|
|
1177
1186
|
mergeMode: fastMode ? 'pr' : (defaults.mergeMode || 'pr'),
|
|
1178
1187
|
fastMode,
|
|
1188
|
+
agentQuiet: false,
|
|
1179
1189
|
skipPreflight: fastMode,
|
|
1180
1190
|
// Precedence: explicit flag (set in the loop below) > defaults (caller) >
|
|
1181
1191
|
// GUARDEX_AUTO_SHIP env > hardcoded off. Note `defaults.gateReview === false`
|
|
@@ -1260,6 +1270,10 @@ function parseFinishArgs(rawArgs, defaults = {}) {
|
|
|
1260
1270
|
if (arg === '--fast') {
|
|
1261
1271
|
continue;
|
|
1262
1272
|
}
|
|
1273
|
+
if (arg === '--agent-quiet') {
|
|
1274
|
+
options.agentQuiet = true;
|
|
1275
|
+
continue;
|
|
1276
|
+
}
|
|
1263
1277
|
if (arg === '--wait-for-merge') {
|
|
1264
1278
|
options.waitForMerge = true;
|
|
1265
1279
|
continue;
|
|
@@ -19,13 +19,55 @@ const {
|
|
|
19
19
|
invokePackageAsset,
|
|
20
20
|
} = require('../../core/runtime');
|
|
21
21
|
const { runReviewGate } = require('../../finish/review-gate');
|
|
22
|
-
const { createFinishProgress } = require('../../finish/progress');
|
|
22
|
+
const { createFinishProgress, summarizeFinishRun } = require('../../finish/progress');
|
|
23
23
|
const { autoCommitWorktreeForFinish } = require('../../finish');
|
|
24
24
|
const { finish, merge } = require('./finish');
|
|
25
25
|
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
|
|
@@ -44,10 +86,13 @@ function splitGateReviewFlags(args) {
|
|
|
44
86
|
let reviewTimeoutMs;
|
|
45
87
|
let noAutoCommit = false;
|
|
46
88
|
let commitMessage = '';
|
|
89
|
+
let agentQuiet = false;
|
|
47
90
|
for (let index = 0; index < args.length; index += 1) {
|
|
48
91
|
const arg = args[index];
|
|
49
92
|
if (arg === '--fast') {
|
|
50
93
|
fastMode = true;
|
|
94
|
+
} else if (arg === '--agent-quiet') {
|
|
95
|
+
agentQuiet = true;
|
|
51
96
|
} else if (arg === '--no-auto-commit') {
|
|
52
97
|
noAutoCommit = true;
|
|
53
98
|
} else if (arg === '--commit-message') {
|
|
@@ -173,6 +218,7 @@ function splitGateReviewFlags(args) {
|
|
|
173
218
|
gateSerialCi,
|
|
174
219
|
noAutoCommit,
|
|
175
220
|
commitMessage,
|
|
221
|
+
agentQuiet,
|
|
176
222
|
scriptArgs,
|
|
177
223
|
};
|
|
178
224
|
}
|
|
@@ -202,6 +248,13 @@ function branch(rawArgs) {
|
|
|
202
248
|
return;
|
|
203
249
|
}
|
|
204
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
|
+
}
|
|
205
258
|
const { target, passthrough } = extractTargetedArgs(rest);
|
|
206
259
|
const repoRoot = resolveRepoRoot(target);
|
|
207
260
|
const {
|
|
@@ -215,6 +268,7 @@ function branch(rawArgs) {
|
|
|
215
268
|
gateSerialCi,
|
|
216
269
|
noAutoCommit,
|
|
217
270
|
commitMessage,
|
|
271
|
+
agentQuiet,
|
|
218
272
|
scriptArgs,
|
|
219
273
|
} = splitGateReviewFlags(passthrough);
|
|
220
274
|
const finishBranch = readFlagValue(scriptArgs, '--branch') || currentBranchName(repoRoot);
|
|
@@ -228,7 +282,12 @@ function branch(rawArgs) {
|
|
|
228
282
|
const autoCommitWorktree = finishWorktree && isLinkedAgentWorktree(finishWorktree)
|
|
229
283
|
? finishWorktree
|
|
230
284
|
: '';
|
|
231
|
-
const progress = createFinishProgress({
|
|
285
|
+
const progress = createFinishProgress({
|
|
286
|
+
repoRoot,
|
|
287
|
+
branch: finishBranch,
|
|
288
|
+
baseBranch: finishBase,
|
|
289
|
+
quiet: agentQuiet,
|
|
290
|
+
});
|
|
232
291
|
progress.start(
|
|
233
292
|
'prepare',
|
|
234
293
|
autoCommitWorktree ? 'checking worktree and pending changes' : 'resolving branch and finish policy',
|
|
@@ -236,7 +295,7 @@ function branch(rawArgs) {
|
|
|
236
295
|
const commitState = autoCommitWorktree
|
|
237
296
|
? autoCommitWorktreeForFinish(repoRoot, autoCommitWorktree, finishBranch, { noAutoCommit, commitMessage })
|
|
238
297
|
: { changed: false, committed: false };
|
|
239
|
-
if (commitState.committed) {
|
|
298
|
+
if (commitState.committed && !agentQuiet) {
|
|
240
299
|
console.log(`[${TOOL_NAME}] Auto-committed '${finishBranch}' before finish.`);
|
|
241
300
|
}
|
|
242
301
|
progress.complete(
|
|
@@ -246,8 +305,9 @@ function branch(rawArgs) {
|
|
|
246
305
|
// Fail-closed: runReviewGate throws on a dirty review, red CI, or a PR
|
|
247
306
|
// GitHub will not merge. Throwing here means the script never runs, so
|
|
248
307
|
// the merge never happens.
|
|
308
|
+
let gateResult;
|
|
249
309
|
if (gateReview) {
|
|
250
|
-
runReviewGate({
|
|
310
|
+
gateResult = runReviewGate({
|
|
251
311
|
repoRoot,
|
|
252
312
|
branch: finishBranch,
|
|
253
313
|
// Must match how the shell resolves --base when it is omitted, which
|
|
@@ -272,15 +332,33 @@ function branch(rawArgs) {
|
|
|
272
332
|
progress.skip('autofix', 'review gate disabled');
|
|
273
333
|
progress.skip('ci', 'review gate disabled; repository policy controls merge readiness');
|
|
274
334
|
}
|
|
275
|
-
|
|
335
|
+
const assetOptions = {
|
|
276
336
|
cwd: repoRoot,
|
|
277
337
|
env: {
|
|
278
338
|
GUARDEX_FINISH_ACTIVE_CWD: activeCwd,
|
|
279
339
|
GUARDEX_FINISH_CHECKLIST: '1',
|
|
280
340
|
GUARDEX_FINISH_GATE_DONE: gateReview ? '1' : '0',
|
|
341
|
+
GUARDEX_FINISH_REQUIRE_PREFLIGHT: gateResult?.billingChecksWaived?.length > 0 ? '1' : '0',
|
|
281
342
|
...progress.eventEnv,
|
|
282
343
|
},
|
|
283
|
-
}
|
|
344
|
+
};
|
|
345
|
+
if (agentQuiet) {
|
|
346
|
+
const result = runPackageAsset('branchFinish', scriptArgs, { ...assetOptions, stdio: 'pipe' });
|
|
347
|
+
const summary = summarizeFinishRun({
|
|
348
|
+
eventFile: progress.eventEnv.GUARDEX_FINISH_EVENT_FILE,
|
|
349
|
+
branch: finishBranch,
|
|
350
|
+
baseBranch: finishBase,
|
|
351
|
+
stdout: result.stdout,
|
|
352
|
+
stderr: result.stderr,
|
|
353
|
+
status: result.status,
|
|
354
|
+
});
|
|
355
|
+
process.stdout.write(`[gx:finish] ${JSON.stringify(summary)}\n`);
|
|
356
|
+
if (result.status !== 0) {
|
|
357
|
+
throw new Error(`branchFinish command failed with status ${result.status}`);
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
invokePackageAsset('branchFinish', scriptArgs, assetOptions);
|
|
361
|
+
}
|
|
284
362
|
return;
|
|
285
363
|
}
|
|
286
364
|
if (subcommand === 'merge') return merge(rest);
|
|
@@ -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,10 +1098,14 @@ 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',
|
|
1109
|
-
'--force-dirty',
|
|
1110
1109
|
];
|
|
1111
1110
|
if (baseBranch && baseBranch !== 'HEAD' && !baseBranch.startsWith('agent/')) {
|
|
1112
1111
|
args.push('--base', baseBranch);
|