@imdeadpool/guardex 8.4.0 → 8.4.2
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/CONTRIBUTING.md +13 -4
- package/README.md +223 -1
- package/THIRD-PARTY-NOTICES.md +29 -0
- package/bin/multiagent-safety.js +9 -12
- package/package.json +4 -2
- package/skills/gitguardex/SKILL.md +28 -0
- package/skills/pr-lens/SKILL.md +87 -0
- package/src/abide.js +534 -0
- package/src/agents/activity.js +23 -4
- package/src/agents/inspect.js +15 -6
- package/src/agents/launch.js +6 -1
- package/src/agents/process-lease.js +84 -0
- package/src/agents/sessions.js +96 -16
- package/src/agents/start.js +18 -9
- package/src/agents/status.js +35 -14
- package/src/agents/supervise.js +87 -0
- package/src/budget/index.js +6 -1
- package/src/cli/args.js +71 -77
- package/src/cli/commands/agents.js +38 -10
- package/src/cli/commands/branch.js +116 -103
- package/src/cli/commands/claude.js +604 -50
- package/src/cli/commands/codex.js +359 -0
- package/src/cli/commands/context.js +52 -0
- package/src/cli/commands/mcp.js +5 -1
- package/src/cli/commands/pr.js +138 -3
- package/src/cli/commands/review.js +3 -1
- package/src/cli/commands/setup.js +25 -0
- package/src/cli/commands/status.js +128 -60
- package/src/cli/commands/storage.js +24 -0
- package/src/cli/commands/usage.js +48 -0
- package/src/cli/commands/watch.js +157 -47
- package/src/cli/commands/worktree-copy-ignored.js +38 -0
- package/src/cli/commands/worktree-estimate.js +69 -0
- package/src/cli/commands/worktree-hooks.js +62 -0
- package/src/cli/commands/worktree-navigation.js +71 -0
- package/src/cli/commands/worktree-provision.js +92 -0
- package/src/cli/main.js +229 -110
- package/src/cli/shared/gate-flags.js +131 -0
- package/src/cli/shared/scaffolding.js +31 -3
- package/src/cli/shared-locks.js +3 -1
- package/src/cockpit/pane-actions.js +43 -7
- package/src/context.js +373 -17
- package/src/doctor/index.js +29 -35
- package/src/finish/events.js +254 -0
- package/src/finish/index.js +322 -62
- package/src/finish/post-branch-finish-cleanup.js +316 -22
- package/src/finish/preflight.js +44 -1
- package/src/finish/progress.js +36 -0
- package/src/finish/review-gate.js +317 -127
- package/src/finish/review-receipt.js +156 -0
- package/src/finish/with-claims-lock.py +29 -0
- package/src/git/index.js +179 -42
- package/src/hooks/index.js +68 -3
- package/src/mcp/collect.js +61 -5
- package/src/mcp/server.js +4 -0
- package/src/output/index.js +167 -1
- package/src/pr-lens-publish.js +93 -0
- package/src/pr-lens.js +184 -0
- package/src/pr-respond.js +860 -0
- package/src/pr-review.js +519 -159
- package/src/pr.js +73 -14
- package/src/provider-binary.js +21 -0
- package/src/review-diff-context.js +90 -0
- package/src/review-fix.js +23 -17
- package/src/scaffold/agent-worktree-prep.js +14 -12
- package/src/scaffold/dependency-store.js +234 -0
- package/src/scaffold/index.js +13 -1
- package/src/scaffold/provision-approvals.js +83 -0
- package/src/scaffold/provision-config.js +169 -40
- package/src/shared-git-state.js +11 -1
- package/src/speckit/index.js +12 -1
- package/src/storage/run-artifacts.js +185 -0
- package/src/toolchain/index.js +322 -2
- package/src/worktree-copy-ignored.js +200 -0
- package/src/worktree-hook-worker.js +29 -0
- package/src/worktree-hooks.js +333 -0
- package/src/worktree-navigation.js +248 -0
- package/src/worktree-picker.js +89 -0
- package/src/worktree-quota.js +100 -0
- package/src/worktree-start.js +100 -0
- package/templates/AGENTS.multiagent-safety.md +8 -0
- package/templates/AGENTS.multiagent-safety.min.md +3 -1
- package/templates/codex/skills/gitguardex/SKILL.md +28 -0
- package/templates/codex/skills/opensrc/SKILL.md +24 -0
- package/templates/githooks/post-merge +16 -2
- package/templates/scripts/agent-autofinish-watch.sh +17 -18
- package/templates/scripts/agent-branch-finish.sh +180 -19
- package/templates/scripts/agent-branch-merge.sh +7 -32
- package/templates/scripts/agent-branch-start.sh +202 -43
- package/templates/scripts/agent-claude-stop-finish.sh +4 -27
- package/templates/scripts/agent-file-locks.py +257 -29
- package/templates/scripts/agent-preflight.sh +3 -0
- package/templates/scripts/agent-worktree-prune.sh +975 -63
- package/templates/scripts/codex-agent.sh +55 -5
- package/templates/scripts/lib/guardex-base-branch.sh +207 -0
- package/templates/scripts/openspec/init-change-workspace.sh +10 -18
- package/templates/scripts/review-bot-watch.sh +171 -4
package/src/cli/main.js
CHANGED
|
@@ -9,68 +9,33 @@
|
|
|
9
9
|
//
|
|
10
10
|
// All handler bodies were extracted verbatim during the v7.0.43 refactor.
|
|
11
11
|
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const {
|
|
13
|
+
cp,
|
|
14
|
+
path,
|
|
15
|
+
packageJson,
|
|
16
|
+
TOOL_NAME,
|
|
17
|
+
SHORT_TOOL_NAME,
|
|
18
|
+
DEPRECATED_COMMAND_ALIASES,
|
|
19
|
+
CLI_COMMAND_HELP
|
|
20
|
+
} = require('../context');
|
|
21
|
+
const { usage, startTransientSpinner, commandHelpLines, commandCatalogJson } = require('../output');
|
|
18
22
|
const {
|
|
19
23
|
maybeSuggestCommand,
|
|
20
24
|
normalizeCommandOrThrow,
|
|
21
25
|
warnDeprecatedAlias,
|
|
22
|
-
extractFlag
|
|
26
|
+
extractFlag
|
|
23
27
|
} = require('./dispatch');
|
|
24
28
|
const {
|
|
25
29
|
isInteractiveTerminal,
|
|
26
30
|
legacyDefaultStatusEnabled,
|
|
27
31
|
defaultCockpitDisabled,
|
|
28
|
-
parseBooleanLike
|
|
32
|
+
parseBooleanLike
|
|
29
33
|
} = require('./shared/repo-env');
|
|
30
34
|
const { resolveRepoRoot } = require('../git');
|
|
31
35
|
|
|
32
|
-
// Subcommand modules
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const { onboard } = require('./commands/onboard');
|
|
36
|
-
const { install, fix, scan } = require('./commands/bootstrap');
|
|
37
|
-
const { doctor } = require('./commands/doctor');
|
|
38
|
-
const { review, prReview } = require('./commands/review');
|
|
39
|
-
const { pr: prCommand } = require('./commands/pr');
|
|
40
|
-
const { claude: claudeCommand } = require('./commands/claude');
|
|
41
|
-
const { agents } = require('./commands/agents');
|
|
42
|
-
const { mcp } = require('./commands/mcp');
|
|
43
|
-
const { report } = require('./commands/report');
|
|
44
|
-
const { release } = require('./commands/release');
|
|
45
|
-
const { watch } = require('./commands/watch');
|
|
46
|
-
const {
|
|
47
|
-
prompt,
|
|
48
|
-
printAgentsSnippet,
|
|
49
|
-
copyPrompt,
|
|
50
|
-
copyCommands,
|
|
51
|
-
} = require('./commands/prompt');
|
|
52
|
-
const {
|
|
53
|
-
branch,
|
|
54
|
-
pivot,
|
|
55
|
-
ship,
|
|
56
|
-
locks,
|
|
57
|
-
worktree,
|
|
58
|
-
} = require('./commands/branch');
|
|
59
|
-
const {
|
|
60
|
-
cleanup,
|
|
61
|
-
merge,
|
|
62
|
-
finish,
|
|
63
|
-
sync,
|
|
64
|
-
} = require('./commands/finish');
|
|
65
|
-
const {
|
|
66
|
-
hook,
|
|
67
|
-
internal,
|
|
68
|
-
installAgentSkills,
|
|
69
|
-
migrate,
|
|
70
|
-
submodule,
|
|
71
|
-
cockpit,
|
|
72
|
-
protect,
|
|
73
|
-
} = require('./commands/misc');
|
|
36
|
+
// Subcommand modules are required lazily inside each dispatch branch so
|
|
37
|
+
// `node bin/multiagent-safety.js --version` (and any other cheap command)
|
|
38
|
+
// does not pay the cost of loading all 20+ handlers up front.
|
|
74
39
|
|
|
75
40
|
// `gx` (no args) — auto-doctor wiring. Reused only by the default flow.
|
|
76
41
|
function autoDoctorEnabledForCurrentSession() {
|
|
@@ -84,12 +49,12 @@ function autoDoctorEnabledForCurrentSession() {
|
|
|
84
49
|
function shouldAutoRunDoctorFromStatus(statusPayload) {
|
|
85
50
|
const repo = statusPayload?.repo || {};
|
|
86
51
|
return Boolean(
|
|
87
|
-
autoDoctorEnabledForCurrentSession()
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
52
|
+
autoDoctorEnabledForCurrentSession() &&
|
|
53
|
+
repo.inGitRepo &&
|
|
54
|
+
repo.guardexEnabled !== false &&
|
|
55
|
+
repo.serviceStatus === 'degraded' &&
|
|
56
|
+
repo.scan &&
|
|
57
|
+
Number(repo.scan.findings || 0) > 0
|
|
93
58
|
);
|
|
94
59
|
}
|
|
95
60
|
|
|
@@ -97,16 +62,16 @@ function runCliSubprocessWithSpinner(args, options = {}) {
|
|
|
97
62
|
return new Promise((resolve, reject) => {
|
|
98
63
|
const spinner = options.spinnerMessage
|
|
99
64
|
? startTransientSpinner(options.spinnerMessage, {
|
|
100
|
-
|
|
101
|
-
|
|
65
|
+
prefix: options.spinnerPrefix || `[${TOOL_NAME}]`
|
|
66
|
+
})
|
|
102
67
|
: { stop() {} };
|
|
103
68
|
const child = cp.spawn(process.execPath, [path.resolve(__filename), ...args], {
|
|
104
69
|
cwd: options.cwd || process.cwd(),
|
|
105
70
|
env: {
|
|
106
71
|
...process.env,
|
|
107
|
-
GUARDEX_AUTO_DOCTOR: '0'
|
|
72
|
+
GUARDEX_AUTO_DOCTOR: '0'
|
|
108
73
|
},
|
|
109
|
-
stdio: ['inherit', 'pipe', 'pipe']
|
|
74
|
+
stdio: ['inherit', 'pipe', 'pipe']
|
|
110
75
|
});
|
|
111
76
|
|
|
112
77
|
const stopSpinner = () => spinner.stop();
|
|
@@ -135,20 +100,146 @@ async function maybeAutoRunDoctorFromDefaultStatus(statusPayload) {
|
|
|
135
100
|
}
|
|
136
101
|
|
|
137
102
|
const target = statusPayload?.repo?.target || process.cwd();
|
|
138
|
-
console.log(
|
|
103
|
+
console.log(
|
|
104
|
+
`[${TOOL_NAME}] Auto-repair: repo safety is degraded. Running '${SHORT_TOOL_NAME} doctor --current' now.`
|
|
105
|
+
);
|
|
139
106
|
process.exitCode = await runCliSubprocessWithSpinner(
|
|
140
107
|
['doctor', '--target', target, '--current'],
|
|
141
108
|
{
|
|
142
109
|
cwd: target,
|
|
143
110
|
spinnerPrefix: `[${TOOL_NAME}] Auto-repair:`,
|
|
144
|
-
spinnerMessage: 'preparing doctor workspace'
|
|
145
|
-
}
|
|
111
|
+
spinnerMessage: 'preparing doctor workspace'
|
|
112
|
+
}
|
|
146
113
|
);
|
|
147
114
|
return true;
|
|
148
115
|
}
|
|
149
116
|
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// `--help` must never fail.
|
|
119
|
+
//
|
|
120
|
+
// Measured before this: of the 24 catalogued commands, 16 answered `--help`
|
|
121
|
+
// with "[gitguardex] Unknown option: --help" and exit 1. A human shrugs and
|
|
122
|
+
// opens the README; a caller driving the CLI reads exit 1 as "that command
|
|
123
|
+
// does not work" and has no other way to discover the flags.
|
|
124
|
+
//
|
|
125
|
+
// Two layers, and the split between them is what keeps this from rotting:
|
|
126
|
+
//
|
|
127
|
+
// 1. hasRenderableHelp() — fires ONLY for a command CLI_COMMAND_HELP has
|
|
128
|
+
// written help for. Anything else (budget, ci-init, watch, mcp, an
|
|
129
|
+
// unknown name) is left to the command itself.
|
|
130
|
+
// 2. printHelpForRejectedHelpFlag() — fires only AFTER a command threw,
|
|
131
|
+
// converting its own "Unknown option: --help" into help. Because it
|
|
132
|
+
// runs on failure, it can never shadow help a command prints
|
|
133
|
+
// successfully, whether or not anybody remembered to list that command.
|
|
134
|
+
//
|
|
135
|
+
// The first cut gated layer 1 on a hand-written COMMANDS_WITH_NATIVE_HELP
|
|
136
|
+
// set built from the catalogue. The dispatcher handles more commands than the
|
|
137
|
+
// catalogue lists, so `gx budget --help` lost its own 17-line help (seven
|
|
138
|
+
// flags, gone) and printed a 4-line stub instead. The gate is derived from
|
|
139
|
+
// the table now: no list to keep in sync, and a command nobody wrote an entry
|
|
140
|
+
// for keeps whatever it already did.
|
|
141
|
+
|
|
142
|
+
const HELP_FLAGS = new Set(['--help', '-h']);
|
|
143
|
+
|
|
144
|
+
// Layer 1's gate: is there real help to render for this command? A
|
|
145
|
+
// `nativeHelp: true` entry means "the command owns its help" and renders
|
|
146
|
+
// nothing, so it is not renderable here either.
|
|
147
|
+
function hasRenderableHelp(command) {
|
|
148
|
+
// Object.hasOwn, not a bare lookup: CLI_COMMAND_HELP is a plain object, so
|
|
149
|
+
// `CLI_COMMAND_HELP['constructor']` is Object.prototype.constructor — truthy,
|
|
150
|
+
// with no `nativeHelp` — and `gx help constructor` answered
|
|
151
|
+
// "USAGE: gx constructor [options]" with exit 0. Same false positive as an
|
|
152
|
+
// unknown command name, reached through the prototype.
|
|
153
|
+
if (!Object.hasOwn(CLI_COMMAND_HELP, command)) return false;
|
|
154
|
+
const entry = CLI_COMMAND_HELP[command];
|
|
155
|
+
return Boolean(entry) && entry.nativeHelp !== true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// True when a help flag is being asked of the command ITSELF rather than of
|
|
159
|
+
// one of its subcommands. `gx worktree --help` and
|
|
160
|
+
// `gx doctor --target /tmp --help` qualify; `gx worktree retry-cleanup
|
|
161
|
+
// --help` does not — that one belongs to the subcommand.
|
|
162
|
+
//
|
|
163
|
+
// Every command here dispatches as `const [subcommand, ...rest] = rawArgs`,
|
|
164
|
+
// so a subcommand can only be the FIRST token. Scanning further would
|
|
165
|
+
// misread a flag's value: in `--target /tmp --help`, `/tmp` looks positional
|
|
166
|
+
// but is not a subcommand.
|
|
167
|
+
function helpFlagIsTopLevel(rest) {
|
|
168
|
+
if (!rest.length) return false;
|
|
169
|
+
if (!String(rest[0]).startsWith('-')) return false;
|
|
170
|
+
return rest.some((arg) => HELP_FLAGS.has(arg));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function printCommandHelp(command) {
|
|
174
|
+
console.log(commandHelpLines(command).join('\n'));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Layer 2. Only rewrites a failure that is unmistakably "you asked me for
|
|
178
|
+
// help": a help flag in argv AND a rejection naming it, or a bare usage
|
|
179
|
+
// string. Any other error still fails with its own message.
|
|
180
|
+
//
|
|
181
|
+
// The exit code follows what was actually wrong:
|
|
182
|
+
// - the command only choked on the help flag -> 0, this was a help request
|
|
183
|
+
// - a help flag was the first thing asked for -> 0, same
|
|
184
|
+
// - a positional before it was ALSO rejected -> 1, the call was invalid
|
|
185
|
+
// So `gx mcp --help` succeeds while `gx worktree badsubcommand --help` still
|
|
186
|
+
// fails — printing the help either way, but never calling an invalid
|
|
187
|
+
// invocation a success.
|
|
188
|
+
function printHelpForRejectedHelpFlag(argv, error) {
|
|
189
|
+
if (!argv.length) return false;
|
|
190
|
+
const [rawCommand, ...rest] = argv;
|
|
191
|
+
if (!rest.some((arg) => HELP_FLAGS.has(arg))) return false;
|
|
192
|
+
const message = String((error && error.message) || '');
|
|
193
|
+
const rejectedHelp = /Unknown [^:]*:\s*(--help|-h)\s*$/.test(message);
|
|
194
|
+
const bareUsage = /^Usage:/.test(message);
|
|
195
|
+
if (!rejectedHelp && !bareUsage) return false;
|
|
196
|
+
let command;
|
|
197
|
+
try {
|
|
198
|
+
command = normalizeCommandOrThrow(rawCommand);
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
// A deprecated alias routes to another command, so its help lives there.
|
|
203
|
+
// `gx help init` has already printed the deprecation hint by now.
|
|
204
|
+
const alias = DEPRECATED_COMMAND_ALIASES.get(command);
|
|
205
|
+
const helpCommand = alias && alias.target ? alias.target : command;
|
|
206
|
+
|
|
207
|
+
const invalidArguments = bareUsage && !helpFlagIsTopLevel(rest);
|
|
208
|
+
if (bareUsage) {
|
|
209
|
+
// The command's own usage string is more specific than the registry
|
|
210
|
+
// entry, so lead with it.
|
|
211
|
+
console.log(message);
|
|
212
|
+
console.log('');
|
|
213
|
+
}
|
|
214
|
+
printCommandHelp(helpCommand);
|
|
215
|
+
if (invalidArguments) {
|
|
216
|
+
process.exitCode = 1;
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// `gx help <command>` is the shape a caller reaches for first, so make it
|
|
222
|
+
// exactly `gx <command> --help`. Normalising argv in one place means the two
|
|
223
|
+
// spellings can never drift, and a command with native help still gets to
|
|
224
|
+
// print its own.
|
|
225
|
+
//
|
|
226
|
+
// Layer 2 must normalise with the SAME function: it runs in runFromBin, where
|
|
227
|
+
// process.argv is still the un-rewritten `['help', 'init']`, and it looks for
|
|
228
|
+
// a help flag in the arguments. Reading raw argv there made `gx help init`
|
|
229
|
+
// fall through to a bare "Unknown option: --help".
|
|
230
|
+
function normalizeHelpArgv(argv) {
|
|
231
|
+
if (
|
|
232
|
+
argv.length > 1 &&
|
|
233
|
+
(argv[0] === 'help' || argv[0] === '--help' || argv[0] === '-h') &&
|
|
234
|
+
!String(argv[1]).startsWith('-')
|
|
235
|
+
) {
|
|
236
|
+
return [argv[1], '--help', ...argv.slice(2)];
|
|
237
|
+
}
|
|
238
|
+
return argv;
|
|
239
|
+
}
|
|
240
|
+
|
|
150
241
|
async function main() {
|
|
151
|
-
const args = process.argv.slice(2);
|
|
242
|
+
const args = normalizeHelpArgv(process.argv.slice(2));
|
|
152
243
|
|
|
153
244
|
if (args.length === 0) {
|
|
154
245
|
if (isInteractiveTerminal() && !legacyDefaultStatusEnabled() && !defaultCockpitDisabled()) {
|
|
@@ -156,14 +247,15 @@ async function main() {
|
|
|
156
247
|
const cockpitModule = require('../cockpit');
|
|
157
248
|
cockpitModule.openDefaultCockpit({
|
|
158
249
|
resolveRepoRoot,
|
|
159
|
-
toolName: TOOL_NAME
|
|
250
|
+
toolName: TOOL_NAME
|
|
160
251
|
});
|
|
161
252
|
process.exitCode = 0;
|
|
162
253
|
return;
|
|
163
254
|
}
|
|
255
|
+
const toolchainModule = require('../toolchain');
|
|
164
256
|
toolchainModule.maybeSelfUpdateBeforeStatus();
|
|
165
257
|
toolchainModule.maybeOpenSpecUpdateBeforeStatus();
|
|
166
|
-
const statusPayload = status([]);
|
|
258
|
+
const statusPayload = require('./commands/status').status([]);
|
|
167
259
|
await maybeAutoRunDoctorFromDefaultStatus(statusPayload);
|
|
168
260
|
return;
|
|
169
261
|
}
|
|
@@ -172,12 +264,24 @@ async function main() {
|
|
|
172
264
|
const command = normalizeCommandOrThrow(rawCommand);
|
|
173
265
|
|
|
174
266
|
if (command === '--help' || command === '-h' || command === 'help') {
|
|
267
|
+
// One call, machine-readable: every group, command, subcommand and the
|
|
268
|
+
// flags worth naming. Saves an agent 24 `--help` round-trips.
|
|
269
|
+
if (rest.includes('--json')) {
|
|
270
|
+
console.log(JSON.stringify(commandCatalogJson(), null, 2));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
175
273
|
usage();
|
|
176
274
|
return;
|
|
177
275
|
}
|
|
178
276
|
|
|
277
|
+
// Layer 1 (see the note above hasRenderableHelp).
|
|
278
|
+
if (helpFlagIsTopLevel(rest) && hasRenderableHelp(command)) {
|
|
279
|
+
printCommandHelp(command);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
179
283
|
if (command === '--version' || command === '-v' || command === 'version') {
|
|
180
|
-
|
|
284
|
+
require('../toolchain').maybeSelfUpdateBeforeStatus();
|
|
181
285
|
console.log(packageJson.version);
|
|
182
286
|
return;
|
|
183
287
|
}
|
|
@@ -185,60 +289,68 @@ async function main() {
|
|
|
185
289
|
// Deprecated direct aliases — route to new surface and warn once.
|
|
186
290
|
if (DEPRECATED_COMMAND_ALIASES.has(command)) {
|
|
187
291
|
warnDeprecatedAlias(command);
|
|
188
|
-
if (command === 'init') return setup(rest);
|
|
189
|
-
if (command === 'install') return install(rest);
|
|
190
|
-
if (command === 'fix') return fix(rest);
|
|
191
|
-
if (command === 'scan') return scan(rest);
|
|
192
|
-
if (command === 'copy-prompt') return copyPrompt();
|
|
193
|
-
if (command === 'copy-commands') return copyCommands();
|
|
194
|
-
if (command === 'print-agents-snippet')
|
|
195
|
-
|
|
292
|
+
if (command === 'init') return require('./commands/setup').setup(rest);
|
|
293
|
+
if (command === 'install') return require('./commands/bootstrap').install(rest);
|
|
294
|
+
if (command === 'fix') return require('./commands/bootstrap').fix(rest);
|
|
295
|
+
if (command === 'scan') return require('./commands/bootstrap').scan(rest);
|
|
296
|
+
if (command === 'copy-prompt') return require('./commands/prompt').copyPrompt();
|
|
297
|
+
if (command === 'copy-commands') return require('./commands/prompt').copyCommands();
|
|
298
|
+
if (command === 'print-agents-snippet')
|
|
299
|
+
return require('./commands/prompt').printAgentsSnippet();
|
|
300
|
+
if (command === 'review') return require('./commands/review').review(rest);
|
|
196
301
|
}
|
|
197
302
|
|
|
198
303
|
if (command === 'status') {
|
|
199
304
|
const { found: strict, remaining } = extractFlag(rest, '--strict');
|
|
200
|
-
if (strict) return scan(remaining);
|
|
201
|
-
return status(remaining);
|
|
305
|
+
if (strict) return require('./commands/bootstrap').scan(remaining);
|
|
306
|
+
return require('./commands/status').status(remaining);
|
|
202
307
|
}
|
|
203
308
|
|
|
204
309
|
if (command === 'setup') {
|
|
205
310
|
const installOnly = extractFlag(rest, '--install-only', '--only-install');
|
|
206
|
-
if (installOnly.found) return install(installOnly.remaining);
|
|
311
|
+
if (installOnly.found) return require('./commands/bootstrap').install(installOnly.remaining);
|
|
207
312
|
const repairOnly = extractFlag(installOnly.remaining, '--repair', '--fix-only');
|
|
208
|
-
if (repairOnly.found) return fix(repairOnly.remaining);
|
|
209
|
-
return setup(repairOnly.remaining);
|
|
313
|
+
if (repairOnly.found) return require('./commands/bootstrap').fix(repairOnly.remaining);
|
|
314
|
+
return require('./commands/setup').setup(repairOnly.remaining);
|
|
210
315
|
}
|
|
211
316
|
|
|
212
|
-
if (command === 'onboard' || command === 'welcome')
|
|
213
|
-
|
|
214
|
-
if (command === '
|
|
215
|
-
if (command === 'pr') return
|
|
216
|
-
if (command === '
|
|
217
|
-
if (command === '
|
|
218
|
-
if (command === '
|
|
219
|
-
if (command === '
|
|
220
|
-
if (command === '
|
|
221
|
-
if (command === '
|
|
222
|
-
if (command === '
|
|
223
|
-
if (command === '
|
|
224
|
-
if (command === '
|
|
225
|
-
if (command === '
|
|
226
|
-
if (command === '
|
|
227
|
-
if (command === '
|
|
228
|
-
if (command === '
|
|
229
|
-
if (command === '
|
|
230
|
-
if (command === '
|
|
231
|
-
if (command === '
|
|
232
|
-
|
|
233
|
-
if (command === '
|
|
234
|
-
if (command === '
|
|
235
|
-
if (command === '
|
|
236
|
-
if (command === '
|
|
237
|
-
if (command === '
|
|
238
|
-
if (command === '
|
|
239
|
-
if (command === '
|
|
240
|
-
if (command === '
|
|
241
|
-
if (command === '
|
|
317
|
+
if (command === 'onboard' || command === 'welcome')
|
|
318
|
+
return require('./commands/onboard').onboard(rest);
|
|
319
|
+
if (command === 'prompt') return require('./commands/prompt').prompt(rest);
|
|
320
|
+
if (command === 'pr-review') return require('./commands/review').prReview(rest);
|
|
321
|
+
if (command === 'pr') return require('./commands/pr').pr(rest);
|
|
322
|
+
if (command === 'claude') return require('./commands/claude').claude(rest);
|
|
323
|
+
if (command === 'codex') return require('./commands/codex').codex(rest);
|
|
324
|
+
if (command === 'doctor') return require('./commands/doctor').doctor(rest);
|
|
325
|
+
if (command === 'context') return require('./commands/context').agentContext(rest);
|
|
326
|
+
if (command === 'usage') return require('./commands/usage').usage(rest);
|
|
327
|
+
if (command === 'branch') return require('./commands/branch').branch(rest);
|
|
328
|
+
if (command === 'switch') return require('./commands/worktree-navigation').switchWorktree(rest);
|
|
329
|
+
if (command === 'shell-init') return require('./commands/worktree-navigation').shellInit(rest);
|
|
330
|
+
if (command === 'pivot') return require('./commands/branch').pivot(rest);
|
|
331
|
+
if (command === 'ship') return require('./commands/branch').ship(rest);
|
|
332
|
+
if (command === 'locks') return require('./commands/branch').locks(rest);
|
|
333
|
+
if (command === 'worktree') return require('./commands/branch').worktree(rest);
|
|
334
|
+
if (command === 'hook') return require('./commands/misc').hook(rest);
|
|
335
|
+
if (command === 'migrate') return require('./commands/misc').migrate(rest);
|
|
336
|
+
if (command === 'install-agent-skills')
|
|
337
|
+
return require('./commands/misc').installAgentSkills(rest);
|
|
338
|
+
if (command === 'internal') return require('./commands/misc').internal(rest);
|
|
339
|
+
if (command === 'agents') return require('./commands/agents').agents(rest);
|
|
340
|
+
if (command === 'mcp') return require('./commands/mcp').mcp(rest);
|
|
341
|
+
if (command === 'cockpit') return require('./commands/misc').cockpit(rest);
|
|
342
|
+
if (command === 'merge') return require('./commands/finish').merge(rest);
|
|
343
|
+
if (command === 'finish') return require('./commands/finish').finish(rest);
|
|
344
|
+
if (command === 'report') return require('./commands/report').report(rest);
|
|
345
|
+
if (command === 'protect') return require('./commands/misc').protect(rest);
|
|
346
|
+
if (command === 'sync') return require('./commands/finish').sync(rest);
|
|
347
|
+
if (command === 'submodule') return require('./commands/misc').submodule(rest);
|
|
348
|
+
if (command === 'cleanup') return require('./commands/finish').cleanup(rest);
|
|
349
|
+
if (command === 'release') return require('./commands/release').release(rest);
|
|
350
|
+
if (command === 'watch') return require('./commands/watch').watch(rest);
|
|
351
|
+
if (command === 'budget') return require('../budget').runBudgetCommand(rest);
|
|
352
|
+
if (command === 'ci-init') return require('../ci-init').runCiInitCommand(rest);
|
|
353
|
+
if (command === 'speckit') return require('../speckit').runSpeckitCommand(rest);
|
|
242
354
|
|
|
243
355
|
const suggestion = maybeSuggestCommand(command);
|
|
244
356
|
if (suggestion) {
|
|
@@ -251,6 +363,9 @@ async function runFromBin() {
|
|
|
251
363
|
try {
|
|
252
364
|
await main();
|
|
253
365
|
} catch (error) {
|
|
366
|
+
if (printHelpForRejectedHelpFlag(normalizeHelpArgv(process.argv.slice(2)), error)) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
254
369
|
console.error(`[${TOOL_NAME}] ${error.message}`);
|
|
255
370
|
process.exitCode = 1;
|
|
256
371
|
}
|
|
@@ -263,4 +378,8 @@ if (require.main === module) {
|
|
|
263
378
|
module.exports = {
|
|
264
379
|
main,
|
|
265
380
|
runFromBin,
|
|
381
|
+
normalizeHelpArgv,
|
|
382
|
+
hasRenderableHelp,
|
|
383
|
+
helpFlagIsTopLevel,
|
|
384
|
+
printHelpForRejectedHelpFlag
|
|
266
385
|
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Shared gate-flag parser used by both `gx branch finish` (splitGateReviewFlags
|
|
2
|
+
// in commands/branch.js) and `gx finish` / `gx ship` (parseFinishArgs in
|
|
3
|
+
// cli/args.js). Centralising here removes the duplicate per-flag switch arms
|
|
4
|
+
// that previously existed in both callers.
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const REVIEW_PROVIDERS = ['codex', 'claude'];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Try to consume a single gate-review flag at rawArgs[index], writing the
|
|
12
|
+
* result into `opts`. Returns the number of positions consumed (1 for
|
|
13
|
+
* boolean flags, 2 when the next element is the flag's value, 1 for inline
|
|
14
|
+
* `--flag=value` forms), or 0 when the arg at `index` is not a gate flag and
|
|
15
|
+
* the caller should handle it.
|
|
16
|
+
*
|
|
17
|
+
* Recognised opts keys written:
|
|
18
|
+
* gateReview, reviewProvider, reviewModel, reviewTimeoutMs,
|
|
19
|
+
* gateAutofix, gateAutofixRounds, gateBaseline, gateAbide,
|
|
20
|
+
* gateSerialCi, allowNoChecks.
|
|
21
|
+
*
|
|
22
|
+
* Both space-separated (`--flag value`) and inline (`--flag=value`) forms are
|
|
23
|
+
* accepted. Validation is performed inline; errors are thrown immediately.
|
|
24
|
+
*
|
|
25
|
+
* @param {string[]} rawArgs Full argv being parsed.
|
|
26
|
+
* @param {number} index Index of the current arg.
|
|
27
|
+
* @param {object} opts Options object to mutate.
|
|
28
|
+
* @returns {number} Positions consumed (0 = not a gate flag).
|
|
29
|
+
*/
|
|
30
|
+
function applyGateFlagAt(rawArgs, index, opts) {
|
|
31
|
+
const arg = rawArgs[index];
|
|
32
|
+
|
|
33
|
+
if (arg === '--gate-review') {
|
|
34
|
+
opts.gateReview = true;
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
if (arg === '--no-gate-review' || arg === '--skip-review-gate') {
|
|
38
|
+
opts.gateReview = false;
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
if (arg === '--allow-no-checks') {
|
|
42
|
+
opts.allowNoChecks = true;
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
if (arg === '--gate-baseline') {
|
|
46
|
+
opts.gateBaseline = true;
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
if (arg === '--no-gate-baseline') {
|
|
50
|
+
opts.gateBaseline = false;
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
if (arg === '--gate-abide') {
|
|
54
|
+
opts.gateAbide = true;
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
if (arg === '--no-gate-abide') {
|
|
58
|
+
opts.gateAbide = false;
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
if (arg === '--gate-autofix') {
|
|
62
|
+
opts.gateAutofix = true;
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
if (arg === '--no-gate-autofix') {
|
|
66
|
+
opts.gateAutofix = false;
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
if (arg === '--gate-serial-ci') {
|
|
70
|
+
opts.gateSerialCi = true;
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
if (arg === '--no-gate-serial-ci') {
|
|
74
|
+
opts.gateSerialCi = false;
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (arg === '--gate-autofix-rounds' || arg.startsWith('--gate-autofix-rounds=')) {
|
|
79
|
+
const inline = arg.includes('=');
|
|
80
|
+
const raw = inline ? arg.slice('--gate-autofix-rounds='.length) : rawArgs[index + 1];
|
|
81
|
+
const rounds = Number.parseInt(String(raw ?? ''), 10);
|
|
82
|
+
if (!Number.isInteger(rounds) || rounds < 1 || rounds > 5) {
|
|
83
|
+
throw new Error('--gate-autofix-rounds requires an integer between 1 and 5');
|
|
84
|
+
}
|
|
85
|
+
opts.gateAutofixRounds = rounds;
|
|
86
|
+
opts.gateAutofix = true;
|
|
87
|
+
return inline ? 1 : 2;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (arg === '--review-provider' || arg.startsWith('--review-provider=')) {
|
|
91
|
+
const inline = arg.includes('=');
|
|
92
|
+
const raw = inline ? arg.slice('--review-provider='.length) : (rawArgs[index + 1] ?? '');
|
|
93
|
+
const value = String(raw).trim().toLowerCase();
|
|
94
|
+
// Fail closed on a typo rather than silently falling back to the default:
|
|
95
|
+
// a caller who named a provider must not quietly get a different one.
|
|
96
|
+
if (!REVIEW_PROVIDERS.includes(value)) {
|
|
97
|
+
throw new Error(`--review-provider requires a value of ${REVIEW_PROVIDERS.join('|')}`);
|
|
98
|
+
}
|
|
99
|
+
opts.reviewProvider = value;
|
|
100
|
+
return inline ? 1 : 2;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (arg === '--review-model' || arg.startsWith('--review-model=')) {
|
|
104
|
+
const inline = arg.includes('=');
|
|
105
|
+
const value = String(
|
|
106
|
+
inline ? arg.slice('--review-model='.length) : (rawArgs[index + 1] ?? '')
|
|
107
|
+
).trim();
|
|
108
|
+
// Same fail-closed reasoning as --review-provider: a caller who named a
|
|
109
|
+
// model must not silently get the provider's default one instead.
|
|
110
|
+
if (!value || value.startsWith('-')) {
|
|
111
|
+
throw new Error('--review-model requires a model name (e.g. sonnet)');
|
|
112
|
+
}
|
|
113
|
+
opts.reviewModel = value;
|
|
114
|
+
return inline ? 1 : 2;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (arg === '--review-timeout-ms' || arg.startsWith('--review-timeout-ms=')) {
|
|
118
|
+
const inline = arg.includes('=');
|
|
119
|
+
const raw = inline ? arg.slice('--review-timeout-ms='.length) : (rawArgs[index + 1] ?? '');
|
|
120
|
+
const ms = Number.parseInt(String(raw), 10);
|
|
121
|
+
if (!Number.isInteger(ms) || ms <= 0) {
|
|
122
|
+
throw new Error('--review-timeout-ms requires a positive integer');
|
|
123
|
+
}
|
|
124
|
+
opts.reviewTimeoutMs = ms;
|
|
125
|
+
return inline ? 1 : 2;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = { REVIEW_PROVIDERS, applyGateFlagAt };
|
|
@@ -23,6 +23,19 @@ const {
|
|
|
23
23
|
readBranchDisplayName,
|
|
24
24
|
lockRegistryStatus,
|
|
25
25
|
} = require('../../git');
|
|
26
|
+
|
|
27
|
+
// Repo-level opt-out: `git config --add multiagent.managedSkip <path>` names a
|
|
28
|
+
// managed file the repo removed on purpose. setup/fix never recreate it and
|
|
29
|
+
// scan does not report it missing.
|
|
30
|
+
function readManagedSkip(repoRoot) {
|
|
31
|
+
const result = gitRun(repoRoot, ['config', '--get-all', 'multiagent.managedSkip'], { allowFailure: true });
|
|
32
|
+
if (result.status !== 0) return new Set();
|
|
33
|
+
return new Set(String(result.stdout || '').split('\n').map((entry) => entry.trim()).filter(Boolean));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function managedSkipOperation(relativePath) {
|
|
37
|
+
return { status: 'skipped', file: relativePath, note: 'multiagent.managedSkip' };
|
|
38
|
+
}
|
|
26
39
|
const {
|
|
27
40
|
toDestinationPath,
|
|
28
41
|
ensureGeneratedScriptShim,
|
|
@@ -137,7 +150,13 @@ function runInstallInternal(options) {
|
|
|
137
150
|
|
|
138
151
|
operations.push(...ensureOmxScaffold(repoRoot, Boolean(options.dryRun)));
|
|
139
152
|
|
|
153
|
+
const managedSkip = readManagedSkip(repoRoot);
|
|
154
|
+
const templateFiles = TEMPLATE_FILES.filter((entry) => !managedSkip.has(toDestinationPath(entry)));
|
|
140
155
|
for (const templateFile of TEMPLATE_FILES) {
|
|
156
|
+
if (managedSkip.has(toDestinationPath(templateFile))) {
|
|
157
|
+
operations.push(managedSkipOperation(toDestinationPath(templateFile)));
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
141
160
|
operations.push(
|
|
142
161
|
copyTemplateFile(
|
|
143
162
|
repoRoot,
|
|
@@ -147,7 +166,7 @@ function runInstallInternal(options) {
|
|
|
147
166
|
),
|
|
148
167
|
);
|
|
149
168
|
}
|
|
150
|
-
operations.push(...materializePackageRepoTemplateFiles(repoRoot,
|
|
169
|
+
operations.push(...materializePackageRepoTemplateFiles(repoRoot, templateFiles, Boolean(options.dryRun)));
|
|
151
170
|
operations.push(...ensureTargetedLegacyWorkflowShims(repoRoot, options));
|
|
152
171
|
for (const hookName of HOOK_NAMES) {
|
|
153
172
|
const hookRelativePath = path.posix.join('.githooks', hookName);
|
|
@@ -199,14 +218,20 @@ function runFixInternal(options) {
|
|
|
199
218
|
|
|
200
219
|
operations.push(...ensureOmxScaffold(repoRoot, Boolean(options.dryRun)));
|
|
201
220
|
|
|
221
|
+
const managedSkip = readManagedSkip(repoRoot);
|
|
222
|
+
const templateFiles = TEMPLATE_FILES.filter((entry) => !managedSkip.has(toDestinationPath(entry)));
|
|
202
223
|
for (const templateFile of TEMPLATE_FILES) {
|
|
224
|
+
if (managedSkip.has(toDestinationPath(templateFile))) {
|
|
225
|
+
operations.push(managedSkipOperation(toDestinationPath(templateFile)));
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
203
228
|
if (shouldForceManagedPath(options, toDestinationPath(templateFile))) {
|
|
204
229
|
operations.push(copyTemplateFile(repoRoot, templateFile, true, Boolean(options.dryRun)));
|
|
205
230
|
continue;
|
|
206
231
|
}
|
|
207
232
|
operations.push(ensureTemplateFilePresent(repoRoot, templateFile, Boolean(options.dryRun)));
|
|
208
233
|
}
|
|
209
|
-
operations.push(...materializePackageRepoTemplateFiles(repoRoot,
|
|
234
|
+
operations.push(...materializePackageRepoTemplateFiles(repoRoot, templateFiles, Boolean(options.dryRun)));
|
|
210
235
|
operations.push(...ensureTargetedLegacyWorkflowShims(repoRoot, options));
|
|
211
236
|
for (const hookName of HOOK_NAMES) {
|
|
212
237
|
const hookRelativePath = path.posix.join('.githooks', hookName);
|
|
@@ -280,7 +305,9 @@ function runScanInternal(options) {
|
|
|
280
305
|
...REQUIRED_MANAGED_REPO_FILES,
|
|
281
306
|
];
|
|
282
307
|
|
|
308
|
+
const managedSkip = readManagedSkip(repoRoot);
|
|
283
309
|
for (const relativePath of requiredPaths) {
|
|
310
|
+
if (managedSkip.has(relativePath)) continue;
|
|
284
311
|
const absolutePath = path.join(repoRoot, relativePath);
|
|
285
312
|
if (!fs.existsSync(absolutePath)) {
|
|
286
313
|
findings.push({
|
|
@@ -294,7 +321,8 @@ function runScanInternal(options) {
|
|
|
294
321
|
|
|
295
322
|
const hooksPathResult = gitRun(repoRoot, ['config', '--get', 'core.hooksPath'], { allowFailure: true });
|
|
296
323
|
const hooksPath = hooksPathResult.status === 0 ? hooksPathResult.stdout.trim() : '';
|
|
297
|
-
|
|
324
|
+
// An absolute path to this repo's own .githooks is the same setting.
|
|
325
|
+
if (hooksPath !== '.githooks' && path.resolve(repoRoot, hooksPath || '.') !== path.join(repoRoot, '.githooks')) {
|
|
298
326
|
findings.push({
|
|
299
327
|
level: 'warn',
|
|
300
328
|
code: 'hooks-path-mismatch',
|