@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.
Files changed (97) hide show
  1. package/CONTRIBUTING.md +13 -4
  2. package/README.md +223 -1
  3. package/THIRD-PARTY-NOTICES.md +29 -0
  4. package/bin/multiagent-safety.js +9 -12
  5. package/package.json +4 -2
  6. package/skills/gitguardex/SKILL.md +28 -0
  7. package/skills/pr-lens/SKILL.md +87 -0
  8. package/src/abide.js +534 -0
  9. package/src/agents/activity.js +23 -4
  10. package/src/agents/inspect.js +15 -6
  11. package/src/agents/launch.js +6 -1
  12. package/src/agents/process-lease.js +84 -0
  13. package/src/agents/sessions.js +96 -16
  14. package/src/agents/start.js +18 -9
  15. package/src/agents/status.js +35 -14
  16. package/src/agents/supervise.js +87 -0
  17. package/src/budget/index.js +6 -1
  18. package/src/cli/args.js +71 -77
  19. package/src/cli/commands/agents.js +38 -10
  20. package/src/cli/commands/branch.js +116 -103
  21. package/src/cli/commands/claude.js +604 -50
  22. package/src/cli/commands/codex.js +359 -0
  23. package/src/cli/commands/context.js +52 -0
  24. package/src/cli/commands/mcp.js +5 -1
  25. package/src/cli/commands/pr.js +138 -3
  26. package/src/cli/commands/review.js +3 -1
  27. package/src/cli/commands/setup.js +25 -0
  28. package/src/cli/commands/status.js +128 -60
  29. package/src/cli/commands/storage.js +24 -0
  30. package/src/cli/commands/usage.js +48 -0
  31. package/src/cli/commands/watch.js +157 -47
  32. package/src/cli/commands/worktree-copy-ignored.js +38 -0
  33. package/src/cli/commands/worktree-estimate.js +69 -0
  34. package/src/cli/commands/worktree-hooks.js +62 -0
  35. package/src/cli/commands/worktree-navigation.js +71 -0
  36. package/src/cli/commands/worktree-provision.js +92 -0
  37. package/src/cli/main.js +229 -110
  38. package/src/cli/shared/gate-flags.js +131 -0
  39. package/src/cli/shared/scaffolding.js +31 -3
  40. package/src/cli/shared-locks.js +3 -1
  41. package/src/cockpit/pane-actions.js +43 -7
  42. package/src/context.js +373 -17
  43. package/src/doctor/index.js +29 -35
  44. package/src/finish/events.js +254 -0
  45. package/src/finish/index.js +322 -62
  46. package/src/finish/post-branch-finish-cleanup.js +316 -22
  47. package/src/finish/preflight.js +44 -1
  48. package/src/finish/progress.js +36 -0
  49. package/src/finish/review-gate.js +317 -127
  50. package/src/finish/review-receipt.js +156 -0
  51. package/src/finish/with-claims-lock.py +29 -0
  52. package/src/git/index.js +179 -42
  53. package/src/hooks/index.js +68 -3
  54. package/src/mcp/collect.js +61 -5
  55. package/src/mcp/server.js +4 -0
  56. package/src/output/index.js +167 -1
  57. package/src/pr-lens-publish.js +93 -0
  58. package/src/pr-lens.js +184 -0
  59. package/src/pr-respond.js +860 -0
  60. package/src/pr-review.js +519 -159
  61. package/src/pr.js +73 -14
  62. package/src/provider-binary.js +21 -0
  63. package/src/review-diff-context.js +90 -0
  64. package/src/review-fix.js +23 -17
  65. package/src/scaffold/agent-worktree-prep.js +14 -12
  66. package/src/scaffold/dependency-store.js +234 -0
  67. package/src/scaffold/index.js +13 -1
  68. package/src/scaffold/provision-approvals.js +83 -0
  69. package/src/scaffold/provision-config.js +169 -40
  70. package/src/shared-git-state.js +11 -1
  71. package/src/speckit/index.js +12 -1
  72. package/src/storage/run-artifacts.js +185 -0
  73. package/src/toolchain/index.js +322 -2
  74. package/src/worktree-copy-ignored.js +200 -0
  75. package/src/worktree-hook-worker.js +29 -0
  76. package/src/worktree-hooks.js +333 -0
  77. package/src/worktree-navigation.js +248 -0
  78. package/src/worktree-picker.js +89 -0
  79. package/src/worktree-quota.js +100 -0
  80. package/src/worktree-start.js +100 -0
  81. package/templates/AGENTS.multiagent-safety.md +8 -0
  82. package/templates/AGENTS.multiagent-safety.min.md +3 -1
  83. package/templates/codex/skills/gitguardex/SKILL.md +28 -0
  84. package/templates/codex/skills/opensrc/SKILL.md +24 -0
  85. package/templates/githooks/post-merge +16 -2
  86. package/templates/scripts/agent-autofinish-watch.sh +17 -18
  87. package/templates/scripts/agent-branch-finish.sh +180 -19
  88. package/templates/scripts/agent-branch-merge.sh +7 -32
  89. package/templates/scripts/agent-branch-start.sh +202 -43
  90. package/templates/scripts/agent-claude-stop-finish.sh +4 -27
  91. package/templates/scripts/agent-file-locks.py +257 -29
  92. package/templates/scripts/agent-preflight.sh +3 -0
  93. package/templates/scripts/agent-worktree-prune.sh +975 -63
  94. package/templates/scripts/codex-agent.sh +55 -5
  95. package/templates/scripts/lib/guardex-base-branch.sh +207 -0
  96. package/templates/scripts/openspec/init-change-workspace.sh +10 -18
  97. package/templates/scripts/review-bot-watch.sh +171 -4
@@ -19,12 +19,12 @@ const {
19
19
  invokePackageAsset,
20
20
  } = require('../../core/runtime');
21
21
  const { runReviewGate } = require('../../finish/review-gate');
22
+ const { branchPreflightDuringCi } = require('../../finish/preflight');
22
23
  const { createFinishProgress, summarizeFinishRun } = require('../../finish/progress');
23
24
  const { autoCommitWorktreeForFinish } = require('../../finish');
24
25
  const { finish, merge } = require('./finish');
25
26
  const { locks } = require('../shared-locks');
26
-
27
- const REVIEW_PROVIDERS = ['codex', 'claude'];
27
+ const { REVIEW_PROVIDERS, applyGateFlagAt } = require('../shared/gate-flags');
28
28
 
29
29
  function printBranchFinishHelp() {
30
30
  console.log(`USAGE: ${SHORT_TOOL_NAME} branch finish [options]
@@ -50,11 +50,13 @@ VERIFICATION
50
50
  --gate-autofix Repair blocking review findings and review again
51
51
  --gate-autofix-rounds <n> Limit repair rounds to 1-5 (default: 1)
52
52
  --gate-baseline Ignore failures already present on the base branch
53
- --review-provider <name> Review provider: codex|claude
53
+ --no-gate-abide Skip abide's AGENTS.md rule verdicts in the review gate
54
+ --review-provider <name> Pin codex|claude (default: Codex, Claude if Codex cannot launch)
54
55
  --review-model <name> Model used by the review provider
55
56
  --review-timeout-ms <n> Positive review timeout in milliseconds
56
57
  --no-preflight Skip the repository preflight script
57
58
  --preflight Run the repository preflight script
59
+ --agent-quiet Compact output; retain warnings and gate failures
58
60
 
59
61
  COMMIT
60
62
  --no-auto-commit Refuse to auto-commit pending work
@@ -76,20 +78,29 @@ function isBranchFinishHelpRequest(args) {
76
78
  function splitGateReviewFlags(args) {
77
79
  const scriptArgs = [];
78
80
  let fastMode = false;
79
- let gateReview = false;
80
- let reviewProvider;
81
- let gateAutofix = false;
82
- let gateAutofixRounds = 1;
83
- let gateBaseline = false;
84
- let gateSerialCi = true;
85
- let reviewModel;
86
- let reviewTimeoutMs;
87
81
  let noAutoCommit = false;
88
82
  let commitMessage = '';
89
83
  let agentQuiet = false;
84
+ // Gate-flag options — populated by applyGateFlagAt below.
85
+ const gateOpts = {
86
+ gateReview: false,
87
+ reviewProvider: undefined,
88
+ reviewModel: undefined,
89
+ reviewTimeoutMs: undefined,
90
+ gateAutofix: false,
91
+ gateAutofixRounds: 1,
92
+ gateBaseline: false,
93
+ gateAbide: true,
94
+ gateSerialCi: true,
95
+ allowNoChecks: false,
96
+ };
90
97
  for (let index = 0; index < args.length; index += 1) {
91
98
  const arg = args[index];
92
- if (arg === '--fast') {
99
+ const consumed = applyGateFlagAt(args, index, gateOpts);
100
+ if (consumed > 0) {
101
+ // Gate flags are consumed here; applyGateFlagAt already validated them.
102
+ index += consumed - 1;
103
+ } else if (arg === '--fast') {
93
104
  fastMode = true;
94
105
  } else if (arg === '--agent-quiet') {
95
106
  agentQuiet = true;
@@ -101,58 +112,6 @@ function splitGateReviewFlags(args) {
101
112
  throw new Error('--commit-message requires a value');
102
113
  }
103
114
  index += 1;
104
- } else if (arg === '--gate-review') {
105
- gateReview = true;
106
- } else if (arg === '--no-gate-review' || arg === '--skip-review-gate') {
107
- gateReview = false;
108
- } else if (arg === '--gate-serial-ci') {
109
- gateSerialCi = true;
110
- } else if (arg === '--no-gate-serial-ci') {
111
- gateSerialCi = false;
112
- } else if (arg === '--review-model') {
113
- // Consume the value for the same reason as --review-provider: a bare
114
- // model name left behind becomes a positional the shell script rejects.
115
- reviewModel = args[index + 1] ?? '';
116
- index += 1;
117
- } else if (arg.startsWith('--review-model=')) {
118
- reviewModel = arg.slice('--review-model='.length);
119
- } else if (arg === '--review-timeout-ms' || arg.startsWith('--review-timeout-ms=')) {
120
- // The shell script does not know this gx-level gate flag either.
121
- reviewTimeoutMs = arg.includes('=') ? arg.slice('--review-timeout-ms='.length) : (args[index + 1] ?? '');
122
- if (!arg.includes('=')) index += 1;
123
- } else if (arg === '--gate-baseline') {
124
- gateBaseline = true;
125
- } else if (arg === '--no-gate-baseline') {
126
- gateBaseline = false;
127
- } else if (arg === '--gate-autofix') {
128
- gateAutofix = true;
129
- } else if (arg === '--no-gate-autofix') {
130
- gateAutofix = false;
131
- } else if (arg === '--gate-autofix-rounds' || arg.startsWith('--gate-autofix-rounds=')) {
132
- // Consume the value too, for the same reason as --review-provider: a bare
133
- // number left behind becomes a positional the shell script rejects.
134
- let raw;
135
- if (arg.includes('=')) {
136
- raw = arg.slice('--gate-autofix-rounds='.length);
137
- } else {
138
- raw = args[index + 1];
139
- index += 1;
140
- }
141
- const rounds = Number.parseInt(String(raw ?? ''), 10);
142
- if (!Number.isInteger(rounds) || rounds < 1 || rounds > 5) {
143
- throw new Error('--gate-autofix-rounds requires an integer between 1 and 5');
144
- }
145
- gateAutofixRounds = rounds;
146
- gateAutofix = true;
147
- } else if (arg === '--review-provider') {
148
- // Consume the value too — leaving it behind would hand the script a bare
149
- // "claude" positional and it would exit 1. A missing value becomes "" so
150
- // the check below rejects it, matching args.js: falling back to the
151
- // default here would gate with codex a caller who asked for claude.
152
- reviewProvider = args[index + 1] ?? '';
153
- index += 1;
154
- } else if (arg.startsWith('--review-provider=')) {
155
- reviewProvider = arg.slice('--review-provider='.length);
156
115
  } else {
157
116
  scriptArgs.push(arg);
158
117
  }
@@ -176,46 +135,22 @@ function splitGateReviewFlags(args) {
176
135
  throw new Error(`--fast cannot be combined with ${conflict}`);
177
136
  }
178
137
 
179
- gateReview = false;
180
- gateAutofix = false;
138
+ gateOpts.gateReview = false;
139
+ gateOpts.gateAutofix = false;
181
140
  if (!scriptArgs.includes('--via-pr')) scriptArgs.push('--via-pr');
182
141
  if (!scriptArgs.includes('--no-preflight')) scriptArgs.push('--no-preflight');
183
142
  }
184
143
 
185
- if (reviewProvider !== undefined) {
186
- reviewProvider = String(reviewProvider).trim().toLowerCase();
187
- // Fail closed on a typo rather than silently falling back to the default: a
188
- // caller who named a provider must not quietly get a different one.
189
- if (!REVIEW_PROVIDERS.includes(reviewProvider)) {
190
- throw new Error(`--review-provider requires a value of ${REVIEW_PROVIDERS.join('|')}`);
191
- }
192
- }
193
-
194
- if (reviewModel !== undefined) {
195
- reviewModel = String(reviewModel).trim();
196
- // Same fail-closed reasoning as --review-provider: a caller who named a
197
- // model must not silently get the provider's default one instead.
198
- if (!reviewModel || reviewModel.startsWith('-')) {
199
- throw new Error('--review-model requires a model name (e.g. sonnet)');
200
- }
201
- }
202
-
203
- if (reviewTimeoutMs !== undefined) {
204
- reviewTimeoutMs = Number.parseInt(String(reviewTimeoutMs ?? ''), 10);
205
- if (!Number.isInteger(reviewTimeoutMs) || reviewTimeoutMs <= 0) {
206
- throw new Error('--review-timeout-ms requires a positive integer');
144
+ if (gateOpts.gateReview) {
145
+ const mode = readFlagValue(scriptArgs, '--mode');
146
+ if (scriptArgs.includes('--direct-only') || scriptArgs.includes('--no-push') || (mode && mode !== 'pr')) {
147
+ throw new Error('--gate-review requires a push-enabled PR finish; direct/local modes are incompatible.');
207
148
  }
149
+ if (!scriptArgs.includes('--via-pr')) scriptArgs.push('--via-pr');
208
150
  }
209
151
 
210
152
  return {
211
- gateReview,
212
- reviewProvider,
213
- reviewModel,
214
- reviewTimeoutMs,
215
- gateAutofix,
216
- gateAutofixRounds,
217
- gateBaseline,
218
- gateSerialCi,
153
+ ...gateOpts,
219
154
  noAutoCommit,
220
155
  commitMessage,
221
156
  agentQuiet,
@@ -240,7 +175,7 @@ function isLinkedAgentWorktree(worktreePath) {
240
175
  }
241
176
 
242
177
  function isReadOnlyBranchStart(args) {
243
- return args.some((arg) => ['--help', '-h', 'help', '--print-name-only'].includes(arg));
178
+ return args.some((arg) => ['--help', '-h', 'help', '--print-name-only', '--preview'].includes(arg));
244
179
  }
245
180
 
246
181
  function recoverStaleManagedWorktrees(repoRoot) {
@@ -284,7 +219,32 @@ function branch(rawArgs) {
284
219
  if (subcommand === 'start') {
285
220
  const { target, passthrough } = extractTargetedArgs(rest);
286
221
  const repoRoot = resolveRepoRoot(target);
287
- if (!isReadOnlyBranchStart(passthrough)) recoverStaleManagedWorktrees(repoRoot);
222
+ const readOnly = isReadOnlyBranchStart(passthrough);
223
+ const quota = readOnly ? {} : require('../../worktree-quota').readWorktreeQuota(repoRoot);
224
+ if (!readOnly) {
225
+ const modeIndex = passthrough.indexOf('--provision-mode');
226
+ if (modeIndex >= 0 && !passthrough[modeIndex + 1]) throw new Error('--provision-mode requires a value');
227
+ require('../../scaffold/provision-config').provisioningMode({
228
+ mode: modeIndex >= 0 ? passthrough[modeIndex + 1] : undefined
229
+ });
230
+ }
231
+ if (passthrough.includes('--task-id')) {
232
+ if (passthrough.filter((arg) => arg === '--task-id').length !== 1)
233
+ throw new Error('--task-id must appear once');
234
+ require('../../worktree-start').validateTaskId(
235
+ passthrough[passthrough.indexOf('--task-id') + 1]
236
+ );
237
+ }
238
+ if (!isReadOnlyBranchStart(passthrough)) {
239
+ require('../../finish/post-branch-finish-cleanup').retryPendingFinishedCleanup(repoRoot, {
240
+ schedule: true
241
+ });
242
+ recoverStaleManagedWorktrees(repoRoot);
243
+ }
244
+ if ((passthrough.includes('--task-id') || Object.keys(quota).length) && !isReadOnlyBranchStart(passthrough)) {
245
+ require('../../worktree-start').invokeTaskStart(repoRoot, passthrough);
246
+ return;
247
+ }
288
248
  invokePackageAsset('branchStart', passthrough, { cwd: repoRoot });
289
249
  return;
290
250
  }
@@ -306,13 +266,27 @@ function branch(rawArgs) {
306
266
  gateAutofix,
307
267
  gateAutofixRounds,
308
268
  gateBaseline,
269
+ gateAbide,
309
270
  gateSerialCi,
271
+ allowNoChecks,
310
272
  noAutoCommit,
311
273
  commitMessage,
312
274
  agentQuiet,
313
275
  scriptArgs,
314
276
  } = splitGateReviewFlags(passthrough);
315
- const finishBranch = readFlagValue(scriptArgs, '--branch') || currentBranchName(repoRoot);
277
+ let finishBranch = readFlagValue(scriptArgs, '--branch');
278
+ if (!finishBranch) {
279
+ try {
280
+ finishBranch = currentBranchName(repoRoot);
281
+ } catch (err) {
282
+ if (err.message && err.message.includes('Detached HEAD')) {
283
+ throw new Error(
284
+ 'Detached HEAD: pass --branch <agent/* branch> to gx branch finish explicitly.',
285
+ );
286
+ }
287
+ throw err;
288
+ }
289
+ }
316
290
  const finishBase = resolveFinishBaseBranch(repoRoot, finishBranch, readFlagValue(scriptArgs, '--base'));
317
291
  const finishWorktree = listAgentWorktrees(repoRoot)
318
292
  .find((entry) => entry.branch === finishBranch)?.worktreePath || '';
@@ -364,9 +338,13 @@ function branch(rawArgs) {
364
338
  gateAutofix,
365
339
  gateAutofixRounds,
366
340
  gateBaseline,
341
+ gateAbide,
367
342
  gateSerialCi,
343
+ allowNoChecks,
344
+ agentQuiet,
368
345
  },
369
346
  progress,
347
+ preflight: branchPreflightDuringCi(repoRoot, scriptArgs, { activeCwd, agentQuiet, progress }),
370
348
  });
371
349
  } else {
372
350
  progress.skip('review', 'review gate disabled');
@@ -379,7 +357,10 @@ function branch(rawArgs) {
379
357
  GUARDEX_FINISH_ACTIVE_CWD: activeCwd,
380
358
  GUARDEX_FINISH_CHECKLIST: '1',
381
359
  GUARDEX_FINISH_GATE_DONE: gateReview ? '1' : '0',
382
- GUARDEX_FINISH_REQUIRE_PREFLIGHT: gateResult?.billingChecksWaived?.length > 0 ? '1' : '0',
360
+ GUARDEX_FINISH_PREFLIGHT_ONLY: '0',
361
+ GUARDEX_FINISH_REVIEWED_HEAD: gateResult?.reviewedHeadSha || '',
362
+ GUARDEX_FINISH_REVIEWED_BASE: gateResult?.reviewedBaseSha || '',
363
+ GUARDEX_FINISH_REQUIRE_PREFLIGHT: gateResult?.requiresLocalPreflight ? '1' : '0',
383
364
  ...progress.eventEnv,
384
365
  },
385
366
  };
@@ -395,7 +376,14 @@ function branch(rawArgs) {
395
376
  });
396
377
  process.stdout.write(`[gx:finish] ${JSON.stringify(summary)}\n`);
397
378
  if (result.status !== 0) {
398
- throw new Error(`branchFinish command failed with status ${result.status}`);
379
+ const stderrTail = String(result.stderr || '')
380
+ .split('\n')
381
+ .filter(Boolean)
382
+ .slice(-20)
383
+ .join('\n');
384
+ throw new Error(
385
+ `branchFinish command failed with status ${result.status}${stderrTail ? `\n${stderrTail}` : ''}`,
386
+ );
399
387
  }
400
388
  } else {
401
389
  invokePackageAsset('branchFinish', scriptArgs, assetOptions);
@@ -433,7 +421,9 @@ function pivot(rawArgs) {
433
421
  process.exitCode = 0;
434
422
  return;
435
423
  }
436
- const result = runPackageAsset('branchStart', passthrough, { cwd: repoRoot });
424
+ const result = isReadOnlyBranchStart(passthrough)
425
+ ? runPackageAsset('branchStart', passthrough, { cwd: repoRoot })
426
+ : require('../../worktree-start').runTaskStart(repoRoot, passthrough);
437
427
  if (result.stdout) process.stdout.write(result.stdout);
438
428
  if (result.stderr) process.stderr.write(result.stderr);
439
429
  if (result.status !== 0) {
@@ -479,6 +469,28 @@ function ship(rawArgs) {
479
469
  function worktree(rawArgs) {
480
470
  const activeCwd = process.cwd();
481
471
  const [subcommand, ...rest] = rawArgs;
472
+ if (subcommand === 'switch') return require('./worktree-navigation').switchWorktree(rest);
473
+ if (subcommand === 'hook') return require('./worktree-hooks').runWorktreeHooksCommand(rest);
474
+ if (subcommand === 'copy-ignored') return require('./worktree-copy-ignored').worktreeCopyIgnored(rest);
475
+ if (subcommand === 'estimate') return require('./worktree-estimate').worktreeEstimate(rest);
476
+ if (subcommand === 'prune-artifacts') return require('./storage').pruneArtifacts(rest);
477
+ if (subcommand === 'retry-cleanup') {
478
+ if (rest.length === 1 && ['--help', '-h'].includes(rest[0])) {
479
+ console.log(
480
+ 'Usage: gx worktree retry-cleanup [--target <repo>]\nRetry saved post-finish jobs safely. Active, dirty or claimed worktrees are preserved.\nJobs survive restarts; a later branch start also retries them. No system daemon is installed.'
481
+ );
482
+ return;
483
+ }
484
+ const { target, passthrough } = extractTargetedArgs(rest);
485
+ if (passthrough.length) throw new Error('Usage: gx worktree retry-cleanup [--target <repo>]');
486
+ return require('../../finish/post-branch-finish-cleanup').retryPendingFinishedCleanup(
487
+ resolveRepoRoot(target),
488
+ { schedule: true }
489
+ );
490
+ }
491
+ if (subcommand === 'approve-hooks' || subcommand === 'provision') {
492
+ return require('./worktree-provision').worktreeProvision(subcommand, rest);
493
+ }
482
494
  if (subcommand === 'prune') {
483
495
  const { target, passthrough } = extractTargetedArgs(rest);
484
496
  invokePackageAsset('worktreePrune', passthrough, {
@@ -487,10 +499,11 @@ function worktree(rawArgs) {
487
499
  });
488
500
  return;
489
501
  }
490
- throw new Error(`Usage: ${SHORT_TOOL_NAME} worktree prune [cleanup-options]`);
502
+ throw new Error(`Usage: ${SHORT_TOOL_NAME} worktree <switch|hook|copy-ignored|prune|provision|approve-hooks|estimate|retry-cleanup|prune-artifacts> [options]`);
491
503
  }
492
504
 
493
505
  module.exports = {
506
+ splitGateReviewFlags,
494
507
  branch,
495
508
  pivot,
496
509
  ship,