@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
@@ -87,7 +87,8 @@ function rollbackShared(repoRoot, records, restore) {
87
87
  }
88
88
  if (failures.length) {
89
89
  process.stderr.write(
90
- `[${TOOL_NAME}] Warning: shared Git rollback was incomplete: ${failures.join('; ')}\n`
90
+ `[${TOOL_NAME}] Warning: shared Git rollback was incomplete: ${failures.join('; ')}\n` +
91
+ ` Run \`gx locks status\` to inspect the current lock state.\n`
91
92
  );
92
93
  }
93
94
  }
@@ -220,6 +221,7 @@ function sharedValidate(repoRoot, args, parsed) {
220
221
  }
221
222
  } catch (error) {
222
223
  if (local.stdout) process.stdout.write(local.stdout);
224
+ if (local.stderr) process.stderr.write(local.stderr);
223
225
  sharedFailure(error);
224
226
  return;
225
227
  }
@@ -1,10 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  const cp = require('node:child_process');
4
+ const fs = require('node:fs');
4
5
  const path = require('node:path');
5
6
  const { readCockpitSettings } = require('./settings');
6
7
  const { PANE_MENU_ACTION_IDS } = require('./pane-menu');
7
8
 
9
+ const LONG_RUNNING_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
10
+
8
11
  const ACTION_ALIASES = new Map([
9
12
  ['finish-pr', 'finish'],
10
13
  ['finish / pr', 'finish'],
@@ -202,11 +205,17 @@ function callHook(label, fn, payload, fallbackMessage) {
202
205
  function runCommand(context, cmd, args = [], options = {}) {
203
206
  const runner = typeof context.runCommand === 'function' ? context.runCommand : defaultRunCommand;
204
207
  const rendered = renderCommand(cmd, args);
205
- const payload = normalizeResult(runner(cmd, args, options));
208
+ const raw = runner(cmd, args, options);
209
+ const timedOut = raw && raw.error && raw.error.code === 'ETIMEDOUT';
210
+ const payload = normalizeResult(raw);
206
211
  const detail = payload.ok ? payload.stdout : payload.stderr || payload.stdout;
212
+ const timeoutMins = options.timeout ? Math.round(options.timeout / 60000) : 0;
213
+ const failMsg = timedOut
214
+ ? `Command timed out after ${timeoutMins} min: ${rendered}`
215
+ : `Command failed: ${detail.trim() || rendered}`;
207
216
  return resultShape({
208
217
  ok: payload.ok,
209
- message: payload.ok ? 'Command completed.' : `Command failed: ${detail.trim() || rendered}`,
218
+ message: payload.ok ? 'Command completed.' : failMsg,
210
219
  command: rendered,
211
220
  stdout: payload.stdout,
212
221
  stderr: payload.stderr,
@@ -217,9 +226,35 @@ function commandExists(context, cmd) {
217
226
  if (typeof context.commandExists === 'function') {
218
227
  return Boolean(context.commandExists(cmd));
219
228
  }
220
- const runner = typeof context.runCommand === 'function' ? context.runCommand : defaultRunCommand;
221
- const result = normalizeResult(runner('which', [cmd], { cwd: resolveRepoRoot(context) }));
222
- return result.ok && result.stdout.trim().length > 0;
229
+ // When a custom runCommand is provided (e.g. in tests), use it with `which`
230
+ // so the caller can control the mock result. In production (defaultRunCommand),
231
+ // use an fs.accessSync PATH scan to avoid depending on `which` being available
232
+ // (it may be absent in Alpine / minimal containers).
233
+ if (typeof context.runCommand === 'function') {
234
+ const result = normalizeResult(
235
+ context.runCommand('which', [cmd], { cwd: resolveRepoRoot(context) }),
236
+ );
237
+ return result.ok && result.stdout.trim().length > 0;
238
+ }
239
+ const envPath = process.env.PATH || '';
240
+ const sep = process.platform === 'win32' ? ';' : ':';
241
+ const extensions =
242
+ process.platform === 'win32'
243
+ ? ['', ...(process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean)]
244
+ : [''];
245
+ for (const dir of envPath.split(sep)) {
246
+ if (!dir) continue;
247
+ for (const extension of extensions) {
248
+ const candidate = path.join(dir, cmd + extension);
249
+ try {
250
+ fs.accessSync(candidate, fs.constants.X_OK);
251
+ if (fs.statSync(candidate).isFile()) return true;
252
+ } catch {
253
+ // Try the next executable extension.
254
+ }
255
+ }
256
+ }
257
+ return false;
223
258
  }
224
259
 
225
260
  function requireBranch(context, actionName) {
@@ -286,7 +321,7 @@ function runSync(context) {
286
321
  const args = ['sync', '--target', required.worktreePath];
287
322
  const base = firstString(context.base, context.baseBranch, selectedSession(context).base);
288
323
  if (base) args.push('--base', base);
289
- return runCommand(context, context.gxCommand || 'gx', args, { cwd: required.worktreePath });
324
+ return runCommand(context, context.gxCommand || 'gx', args, { cwd: required.worktreePath, timeout: LONG_RUNNING_TIMEOUT_MS });
290
325
  }
291
326
 
292
327
  function runFinish(context) {
@@ -306,7 +341,7 @@ function runFinish(context) {
306
341
  '--wait-for-merge',
307
342
  '--cleanup',
308
343
  ],
309
- { cwd: resolveRepoRoot(context) },
344
+ { cwd: resolveRepoRoot(context), timeout: LONG_RUNNING_TIMEOUT_MS },
310
345
  );
311
346
  }
312
347
 
@@ -587,6 +622,7 @@ function dispatchPaneAction(action, context = {}) {
587
622
  module.exports = {
588
623
  COCKPIT_INTENT_ALIASES,
589
624
  PANE_ACTION_HANDLERS,
625
+ commandExists,
590
626
  dispatchCockpitIntent,
591
627
  dispatchPaneAction,
592
628
  normalizeAction,
package/src/context.js CHANGED
@@ -19,6 +19,8 @@ if (!process.env.GUARDEX_NODE_BIN) {
19
19
  const LEGACY_NAMES = ['guardex', 'multiagent-safety'];
20
20
  const GLOBAL_INSTALL_COMMAND = `npm i -g ${packageJson.name}`;
21
21
  const OPENSPEC_PACKAGE = '@fission-ai/openspec';
22
+ const CODEGRAPH_PACKAGE = '@colbymchenry/codegraph';
23
+ const OPENSRC_PACKAGE = 'opensrc';
22
24
  const OMC_PACKAGE = 'oh-my-claude-sisyphus';
23
25
  const OMC_REPO_URL = 'https://github.com/Yeachan-Heo/oh-my-claudecode';
24
26
  // Colony was published under @imdeadpool/colony-cli historically; the new
@@ -39,6 +41,8 @@ const GLOBAL_TOOLCHAIN_SERVICES = [
39
41
  dependencyUrl: OMC_REPO_URL,
40
42
  },
41
43
  { name: OPENSPEC_PACKAGE, packageName: OPENSPEC_PACKAGE },
44
+ { name: 'codegraph', packageName: CODEGRAPH_PACKAGE },
45
+ { name: 'opensrc', packageName: OPENSRC_PACKAGE },
42
46
  { name: 'colony', packageName: COLONY_PACKAGE },
43
47
  {
44
48
  name: '@imdeadpool/codex-account-switcher',
@@ -81,27 +85,17 @@ function resolveGithubCliBin(env = process.env) {
81
85
  return commandAvailable('ghx') ? 'ghx' : 'gh';
82
86
  }
83
87
 
84
- const GH_BIN = resolveGithubCliBin();
85
88
  const RTK_BIN = process.env.GUARDEX_RTK_BIN || 'rtk';
86
- const REQUIRED_SYSTEM_TOOLS = [
87
- {
88
- name: 'gh',
89
- displayName: GH_BIN === 'ghx' ? 'GitHub (ghx proxy)' : 'GitHub (gh)',
90
- command: GH_BIN,
91
- installHint: 'https://cli.github.com/',
92
- },
93
- {
94
- name: 'rtk',
95
- displayName: 'RTK (rtk)',
96
- command: RTK_BIN,
97
- installHint: 'Install RTK and ensure `rtk` is on PATH.',
98
- },
99
- ];
89
+ // GH_BIN and REQUIRED_SYSTEM_TOOLS are exported as lazy getters (see module.exports)
90
+ // so that commandAvailable('ghx') is not called at require time on every gx invocation.
91
+ let _ghBin;
92
+ let _requiredSystemTools;
100
93
  const MAINTAINER_RELEASE_REPO = path.resolve(
101
94
  process.env.GUARDEX_RELEASE_REPO || PACKAGE_ROOT,
102
95
  );
103
96
  const NPM_BIN = process.env.GUARDEX_NPM_BIN || 'npm';
104
97
  const OPENSPEC_BIN = process.env.GUARDEX_OPENSPEC_BIN || 'openspec';
98
+ const CODEGRAPH_BIN = process.env.GUARDEX_CODEGRAPH_BIN || 'codegraph';
105
99
  const SCORECARD_BIN = process.env.GUARDEX_SCORECARD_BIN || 'scorecard';
106
100
  const GIT_PROTECTED_BRANCHES_KEY = 'multiagent.protectedBranches';
107
101
  const GIT_BASE_BRANCH_KEY = 'multiagent.baseBranch';
@@ -261,6 +255,10 @@ const USER_LEVEL_SKILL_ASSETS = [
261
255
  source: path.join(TEMPLATE_ROOT, 'codex', 'skills', 'guardex-merge-skills-to-dev', 'SKILL.md'),
262
256
  destination: path.join('.codex', 'skills', 'guardex-merge-skills-to-dev', 'SKILL.md'),
263
257
  },
258
+ {
259
+ source: path.join(TEMPLATE_ROOT, 'codex', 'skills', 'opensrc', 'SKILL.md'),
260
+ destination: path.join('.codex', 'skills', 'opensrc', 'SKILL.md'),
261
+ },
264
262
  {
265
263
  source: path.join(TEMPLATE_ROOT, 'claude', 'commands', 'gitguardex.md'),
266
264
  destination: path.join('.claude', 'commands', 'gitguardex.md'),
@@ -351,12 +349,16 @@ const COMMAND_TYPO_ALIASES = new Map([
351
349
  ['scna', 'scan'],
352
350
  ]);
353
351
  const SUGGESTIBLE_COMMANDS = [
352
+ 'usage',
353
+ 'context',
354
354
  'status',
355
355
  'setup',
356
356
  'onboard',
357
357
  'doctor',
358
358
  'branch',
359
359
  'pivot',
360
+ 'switch',
361
+ 'shell-init',
360
362
  'ship',
361
363
  'locks',
362
364
  'worktree',
@@ -410,6 +412,8 @@ const CLI_COMMAND_GROUPS = [
410
412
  commands: [
411
413
  ['pivot', 'Auto-pivot from a protected branch into a fresh agent worktree (single tool call for AI agents)'],
412
414
  ['branch', 'CLI-owned branch workflow surface (start/finish/merge)'],
415
+ ['switch', 'Navigate by branch, path or PR, with searchable worktree picker'],
416
+ ['shell-init', 'Print shell integration for gx switch (bash, zsh, fish)'],
413
417
  ['ship', 'Stage + commit + push + PR + auto-merge + cleanup (alias for `finish --via-pr --wait-for-merge --cleanup`)'],
414
418
  ['finish', 'Commit + PR + merge completed agent branches (--all, --branch)'],
415
419
  ['merge', 'Create/reuse an integration lane and merge overlapping agent branches'],
@@ -421,6 +425,7 @@ const CLI_COMMAND_GROUPS = [
421
425
  label: 'Coordination',
422
426
  description: 'File locks, worktrees, hooks, and protected-branch policy.',
423
427
  commands: [
428
+ ['context', 'Compact repo context, peer agents, and batched file ownership (JSON, read-only)'],
424
429
  ['locks', 'CLI-owned file lock surface (claim/allow-delete/release/status/validate)'],
425
430
  ['worktree', 'CLI-owned worktree cleanup surface (prune)'],
426
431
  ['hook', 'Hook dispatch/install surface used by managed shims'],
@@ -431,6 +436,7 @@ const CLI_COMMAND_GROUPS = [
431
436
  label: 'Agents & reports',
432
437
  description: 'Review / cleanup bots, AI setup prompts, and safety reports.',
433
438
  commands: [
439
+ ['usage', 'Agent token and estimated cost reports through the installed ccusage CLI'],
434
440
  ['agents', 'Start/stop repo-scoped review + cleanup bots'],
435
441
  ['pr-review', 'Run local Codex/Claude PR review; post inline GitHub comments, write an artifact, or --fix the findings'],
436
442
  ['cockpit', 'Create or attach to a repo tmux cockpit session'],
@@ -450,6 +456,330 @@ const CLI_COMMAND_GROUPS = [
450
456
  ],
451
457
  },
452
458
  ];
459
+ // CLI_COMMAND_HELP backs `gx <command> --help` for every command that does
460
+ // not print its own usage, and `gx --help --json` for all of them.
461
+ //
462
+ // Why it exists: before this table, 16 of the 24 catalogued commands answered
463
+ // `--help` with "[gitguardex] Unknown option: --help" and a non-zero exit —
464
+ // the worst possible answer for any caller trying to discover the interface,
465
+ // and especially for an agent, which reads a non-zero exit as "the command
466
+ // failed" and has no other way to enumerate the flags.
467
+ //
468
+ // Single source of truth per command: a command that already prints good help
469
+ // of its own carries only `nativeHelp: true` here, so this table never
470
+ // restates (and never drifts from) text the command itself owns.
471
+ //
472
+ // `flags` is deliberately NOT the full parsed surface — `parseFinishArgs`
473
+ // alone accepts 39 flags. It is the subset worth naming first. The drift
474
+ // guard in test/command-help.test.js is one-directional: every flag named
475
+ // here must exist as a literal in src/, so the help cannot invent a flag.
476
+ // It does not require every parsed flag to be documented.
477
+ const CLI_COMMAND_HELP = {
478
+ usage: { nativeHelp: true },
479
+ context: { nativeHelp: true },
480
+ onboard: { nativeHelp: true },
481
+ pivot: { nativeHelp: true },
482
+ switch: { nativeHelp: true },
483
+ 'shell-init': { nativeHelp: true },
484
+ cleanup: { nativeHelp: true },
485
+ locks: { nativeHelp: true },
486
+ hook: { nativeHelp: true },
487
+ protect: { nativeHelp: true },
488
+ speckit: { nativeHelp: true },
489
+ prompt: { nativeHelp: true },
490
+
491
+ setup: {
492
+ usage: 'gx setup [options]',
493
+ summary: 'Install, repair, and verify the guardrails in a repo. Idempotent — safe to re-run.',
494
+ flags: [
495
+ ['--install-only', 'Install the managed surface without running the verify pass'],
496
+ ['--repair', 'Repair drift only (same as `gx doctor`)'],
497
+ ['--target <path>', 'Act on another repo instead of the current directory'],
498
+ ['--current', 'Only this repo; do not walk into nested repos or submodules'],
499
+ ['--recursive', 'Also set up nested repos found below the target'],
500
+ ['--include-submodules', 'Also set up the repo\'s submodules'],
501
+ ['--skip-speckit', 'Do not install the Spec Kit slash skills'],
502
+ ['--dry-run', 'Print what would change without writing'],
503
+ ['--json', 'Machine-readable result'],
504
+ ],
505
+ examples: ['gx setup', 'gx setup --repair', 'gx setup --target ../other-repo'],
506
+ },
507
+
508
+ doctor: {
509
+ usage: 'gx doctor [options]',
510
+ summary: 'Repair drift in the managed surface, then verify it. Auto-sandboxes when run on a protected base.',
511
+ flags: [
512
+ ['--target <path>', 'Act on another repo instead of the current directory'],
513
+ ['--current', 'Only this repo; skip nested repos and submodules'],
514
+ ['--json', 'Machine-readable result'],
515
+ ['--dry-run', 'Report findings without repairing'],
516
+ ['--keep-stale-locks', 'Do not reap file locks from abandoned worktrees'],
517
+ ['--verbose-auto-finish', 'Full auto-finish detail instead of the compact summary'],
518
+ ],
519
+ examples: ['gx doctor', 'gx doctor --json', 'gx doctor --target ../other-repo'],
520
+ },
521
+
522
+ status: {
523
+ usage: 'gx status [options]',
524
+ summary: 'Report CLI + service health. Read-only — never modifies files.',
525
+ flags: [
526
+ ['--strict', 'Run the stricter scan instead of the health summary'],
527
+ ['--verbose', 'Include per-check detail'],
528
+ ['--target <path>', 'Act on another repo instead of the current directory'],
529
+ ['--json', 'Machine-readable result'],
530
+ ],
531
+ examples: ['gx status', 'gx status --json'],
532
+ notes: ['`gx` with no arguments opens the cockpit on a TTY and falls back to this on a pipe.'],
533
+ },
534
+
535
+ migrate: {
536
+ usage: 'gx migrate [options]',
537
+ summary: 'Convert a legacy repo-local install to the zero-copy, CLI-owned surface.',
538
+ flags: [
539
+ ['--target <path>', 'Act on another repo instead of the current directory'],
540
+ ['--dry-run', 'Print the migration plan without applying it'],
541
+ ['--force', 'Migrate even when the repo looks already migrated'],
542
+ ],
543
+ examples: ['gx migrate --dry-run', 'gx migrate'],
544
+ },
545
+
546
+ branch: {
547
+ usage: 'gx branch <start|finish|merge> [options]',
548
+ summary: 'The branch workflow surface: open an agent lane, land it, or merge overlapping lanes.',
549
+ subcommands: [
550
+ ['start "<task>" "<agent>"', 'Create an agent branch + isolated worktree and print its path'],
551
+ ['finish', 'Commit, push, PR and merge the lane (see `gx finish`)'],
552
+ ['merge', 'Merge overlapping agent branches through an integration lane (see `gx merge`)'],
553
+ ],
554
+ flags: [
555
+ ['--base <branch>', 'Base the lane on this branch instead of the repo default'],
556
+ ['--task-id <id>', 'Reuse an explicit task id in the branch name'],
557
+ ['--print-name-only', 'Print the branch name and nothing else'],
558
+ ['--target <path>', 'Act on another repo instead of the current directory'],
559
+ ],
560
+ examples: [
561
+ 'gx branch start "fix the pull latency" "claude"',
562
+ 'gx branch finish --branch agent/claude/my-lane --via-pr --wait-for-merge',
563
+ ],
564
+ notes: ['On a protected base, prefer `gx pivot` — it is one call and needs no bypass env var.'],
565
+ },
566
+
567
+ ship: {
568
+ usage: 'gx ship [options]',
569
+ summary: 'Stage, commit, push, open a PR, wait for the merge, then clean up. Alias for '
570
+ + '`finish --via-pr --wait-for-merge --cleanup --gate-review`.',
571
+ flags: [
572
+ ['--branch <agent/...>', 'Ship one named lane instead of the current one'],
573
+ ['--commit-message <msg>', 'Use this commit message instead of the generated one'],
574
+ ['--base <branch>', 'Target this base branch'],
575
+ ['--no-gate-review', 'Skip the AI-review merge gate (the gate is ON by default)'],
576
+ ['--fast', 'Skip the gate and the preflight — use only on a lane you already verified'],
577
+ ['--dry-run', 'Print the plan without pushing or merging'],
578
+ ],
579
+ examples: ['gx ship', 'gx ship --branch agent/claude/my-lane'],
580
+ notes: [
581
+ 'The merge gate is fail-CLOSED here: review must be clean and CI green before the merge.',
582
+ 'Bare `gx finish --wait-for-merge` is fail-OPEN by comparison — prefer `ship` or `--gate-review`.',
583
+ ],
584
+ },
585
+
586
+ finish: {
587
+ usage: 'gx finish [options]',
588
+ summary: 'Commit, PR and merge completed agent branches.',
589
+ flags: [
590
+ ['--branch <agent/...>', 'Finish one named lane'],
591
+ ['--all', 'Finish every ready agent lane in the repo'],
592
+ ['--via-pr', 'Land through a pull request instead of a direct merge'],
593
+ ['--wait-for-merge', 'Block until the PR is merged'],
594
+ ['--gate-review', 'Fail-closed gate: require a clean AI review + green CI before merging'],
595
+ ['--cleanup', 'Prune the branch and worktree after the merge'],
596
+ ['--no-auto-commit', 'Refuse to commit for you; fail if the tree is dirty'],
597
+ ['--commit-message <msg>', 'Use this commit message'],
598
+ ['--base <branch>', 'Target this base branch'],
599
+ ['--dry-run', 'Print the plan without pushing or merging'],
600
+ ],
601
+ examples: [
602
+ 'gx finish --branch agent/claude/my-lane --via-pr --wait-for-merge --cleanup',
603
+ 'gx finish --all --dry-run',
604
+ ],
605
+ notes: ['`--wait-for-merge` alone does NOT gate the merge; add `--gate-review` or use `gx ship`.'],
606
+ },
607
+
608
+ merge: {
609
+ usage: 'gx merge [options]',
610
+ summary: 'Create or reuse an integration lane and merge overlapping agent branches into it.',
611
+ flags: [
612
+ ['--branch <agent/...>', 'Add this lane to the integration branch (repeatable)'],
613
+ ['--agent <name>', 'Merge every lane owned by this agent'],
614
+ ['--into <branch>', 'Use an existing integration branch'],
615
+ ['--base <branch>', 'Base the integration lane on this branch'],
616
+ ['--task <name>', 'Name the integration lane'],
617
+ ['--target <path>', 'Act on another repo instead of the current directory'],
618
+ ],
619
+ examples: ['gx merge --agent claude', 'gx merge --branch agent/a/one --branch agent/b/two'],
620
+ },
621
+
622
+ sync: {
623
+ usage: 'gx sync [options]',
624
+ summary: 'Bring agent branches up to date with origin/<base>.',
625
+ flags: [
626
+ ['--base <branch>', 'Sync against this base instead of the repo default'],
627
+ ['--branch <agent/...>', 'Sync one named lane'],
628
+ ['--all-agent-branches', 'Sync every agent lane'],
629
+ ['--check', 'Report what is behind without changing anything'],
630
+ ['--ff-only', 'Refuse anything but a fast-forward'],
631
+ ['--strategy <name>', 'Reconcile with this strategy instead of the default'],
632
+ ['--allow-dirty', 'Sync even with uncommitted changes present'],
633
+ ['--dry-run', 'Print the plan without moving any ref'],
634
+ ['--json', 'Machine-readable result'],
635
+ ],
636
+ examples: ['gx sync --check', 'gx sync --all-agent-branches --ff-only'],
637
+ },
638
+
639
+ worktree: {
640
+ usage: 'gx worktree <switch|hook|copy-ignored|prune|provision|approve-hooks|estimate|retry-cleanup|prune-artifacts> [options]',
641
+ summary: 'The worktree surface: prune stale lanes, provision a new one, or measure disk cost.',
642
+ subcommands: [
643
+ ['switch', 'Select a worktree by branch, path or PR, or open the picker'],
644
+ ['hook', 'Approve, run and inspect native worktree lifecycle hooks'],
645
+ ['copy-ignored', 'Explicitly copy selected ignored files without overwriting targets'],
646
+ ['prune', 'Remove worktrees whose branch is merged or abandoned'],
647
+ ['provision', 'Provision a worktree for an existing branch'],
648
+ ['approve-hooks', 'Approve the managed hooks inside a provisioned worktree'],
649
+ ['estimate', 'Read-only tracked-blob size estimate for a new worktree'],
650
+ ['retry-cleanup', 'Retry saved post-finish cleanup jobs (active/dirty/claimed lanes are preserved)'],
651
+ ['prune-artifacts', 'Drop registered, unchanged logs and cache from completed runs'],
652
+ ],
653
+ flags: [
654
+ ['--target <path>', 'Act on another repo instead of the current directory'],
655
+ ['--dry-run', 'Print actions without removing anything'],
656
+ ['--json', 'Machine-readable result (estimate)'],
657
+ ],
658
+ examples: ['gx worktree prune --dry-run', 'gx worktree estimate --json'],
659
+ },
660
+
661
+ agents: {
662
+ usage: 'gx agents <subcommand> [options]',
663
+ summary: 'Repo-scoped review and cleanup bots, plus the agent inbox and lane inspection.',
664
+ subcommands: [
665
+ ['status', 'Show the running bots and the agent lanes (the default with no subcommand)'],
666
+ ['start', 'Start the review + cleanup bots for this repo (--cleanup-only: just the cleanup bot)'],
667
+ ['stop', 'Stop them'],
668
+ ['finish', 'Finish an agent lane by session or branch'],
669
+ ['files', 'Show which files each lane has touched'],
670
+ ['diff', 'Show one lane\'s diff'],
671
+ ['locks', 'Show the file locks each lane holds'],
672
+ ['jump', 'Open a terminal in a lane\'s worktree'],
673
+ ['send', 'Send a message to another agent\'s inbox'],
674
+ ['inbox', 'Read this agent\'s inbox'],
675
+ ['ack', 'Acknowledge an inbox message'],
676
+ ['set-status', 'Set this lane\'s status (waiting / done / free text)'],
677
+ ['cleanup-sessions', 'Drop session records for lanes that no longer exist'],
678
+ ],
679
+ flags: [
680
+ ['--json', 'Machine-readable result'],
681
+ ['--target <path>', 'Act on another repo instead of the current directory'],
682
+ ['--session <id>', 'Address one agent session'],
683
+ ['--branch <agent/...>', 'Address one agent branch'],
684
+ ['--dry-run', 'Print actions without applying them'],
685
+ ['--cleanup-only', 'start: run only the cleanup bot (no token-spending review bot)'],
686
+ ],
687
+ examples: ['gx agents status --json', 'gx agents start --cleanup-only', 'gx agents files --branch agent/claude/my-lane'],
688
+ },
689
+
690
+ 'pr-review': {
691
+ usage: 'gx pr-review [options]',
692
+ summary: 'Run a local Codex/Claude review of a pull request; post inline GitHub comments, '
693
+ + 'write an artifact, or apply the fixes.',
694
+ flags: [
695
+ ['--pr <number>', 'Review this PR instead of the current branch\'s'],
696
+ ['--provider <name>', 'Pin codex or claude (default: Codex, with Claude if Codex cannot launch)'],
697
+ ['--pr-lens', 'Validate/render local PR Lens diagrams alongside findings (optional CLI)'],
698
+ ['--no-pr-lens', 'Disable diagrams even when GUARDEX_REVIEW_PR_LENS=1'],
699
+ ['--pr-lens-publish <url>', 'With --post, publish/update an existing GitHub Actions artifact link only; no review run'],
700
+ ['--post', 'Post the findings as inline GitHub comments'],
701
+ ['--no-post', 'Do not post anything (the default when writing an artifact)'],
702
+ ['--artifact <path>', 'Write the findings to a file'],
703
+ ['--output <path>', 'Exact alias for --artifact; both write the findings file'],
704
+ ['--fix', 'Let the provider apply and commit the fixes'],
705
+ ['--agent-quiet', 'Suppress verbose provider transcripts; keep results and errors'],
706
+ ['--timeout-ms <n>', 'Give up on the provider after this long'],
707
+ ['--target <path>', 'Act on another repo instead of the current directory'],
708
+ ],
709
+ examples: ['gx pr-review --pr 785 --post', 'gx pr-review --pr 785 --artifact review.md --no-post'],
710
+ notes: [
711
+ 'Exits 0 even when it finds something — read the printed findings, not the exit code.',
712
+ 'To watch a PR with the review bot instead, that is `gx review --only-pr <n> --once`.',
713
+ 'PR Lens: install @coldtea/pr-lens-cli@0.6.1 (Node >=20.11); GUARDEX_PR_LENS_BIN overrides its path.',
714
+ 'GUARDEX_REVIEW_PR_LENS=1 enables diagrams for review gates too. Diagrams stay local even with --post.',
715
+ ],
716
+ },
717
+
718
+ cockpit: {
719
+ usage: 'gx cockpit [options]',
720
+ summary: 'Create or attach to this repo\'s tmux/kitty cockpit session.',
721
+ flags: [
722
+ ['--backend <auto|kitty|tmux>', 'Force a terminal backend'],
723
+ ['--target <path>', 'Act on another repo instead of the current directory'],
724
+ ],
725
+ examples: ['gx cockpit', 'gx cockpit --backend tmux'],
726
+ notes: ['Interactive; needs a TTY. `gx` with no arguments opens it automatically on a TTY.'],
727
+ },
728
+
729
+ 'install-agent-skills': {
730
+ usage: 'gx install-agent-skills [options]',
731
+ summary: 'Install the Guardex Codex/Claude skills into the user home.',
732
+ flags: [
733
+ ['--force', 'Overwrite skills that are already installed'],
734
+ ['--dry-run', 'Print what would be written'],
735
+ ],
736
+ examples: ['gx install-agent-skills'],
737
+ },
738
+
739
+ report: {
740
+ usage: 'gx report <scorecard|session-severity> [options]',
741
+ summary: 'Security and safety reports.',
742
+ subcommands: [
743
+ ['scorecard', 'OpenSSF scorecard for the repo'],
744
+ ['session-severity', 'Severity summary for an agent session'],
745
+ ],
746
+ flags: [
747
+ ['--repo <github.com/owner/repo>', 'Report on this repo'],
748
+ ['--scorecard-json <path>', 'Read a scorecard JSON already on disk'],
749
+ ['--output-dir <path>', 'Write the report here'],
750
+ ['--json', 'Machine-readable result'],
751
+ ['--target <path>', 'Act on another repo instead of the current directory'],
752
+ ],
753
+ examples: ['gx report scorecard --repo github.com/opencue/gitguardex'],
754
+ },
755
+
756
+ release: {
757
+ usage: 'gx release [options]',
758
+ summary: 'Create or update the current GitHub release with README-generated notes.',
759
+ flags: [
760
+ ['--title <text>', 'Release title'],
761
+ ['--notes <path>', 'Use these notes instead of the generated ones'],
762
+ ['--repo <owner/name>', 'Act on this repo'],
763
+ ['--target <path>', 'Act on another repo instead of the current directory'],
764
+ ],
765
+ examples: ['gx release', 'gx release --title "v7.1.0"'],
766
+ },
767
+
768
+ help: {
769
+ usage: 'gx help [command]',
770
+ summary: 'List every command, or explain one.',
771
+ flags: [
772
+ ['--json', 'Emit the whole command catalog as JSON (with `gx --help --json`)'],
773
+ ],
774
+ examples: ['gx --help', 'gx --help --json', 'gx help finish', 'gx finish --help'],
775
+ },
776
+
777
+ version: {
778
+ usage: 'gx version',
779
+ summary: 'Print the GitGuardex version.',
780
+ examples: ['gx version', 'gx --version'],
781
+ },
782
+ };
453
783
  const CLI_COMMAND_DESCRIPTIONS = CLI_COMMAND_GROUPS.flatMap((group) => group.commands);
454
784
  const CLI_QUICKSTART_STEPS = [
455
785
  'gx setup',
@@ -948,6 +1278,8 @@ module.exports = {
948
1278
  LEGACY_NAMES,
949
1279
  GLOBAL_INSTALL_COMMAND,
950
1280
  OPENSPEC_PACKAGE,
1281
+ CODEGRAPH_PACKAGE,
1282
+ OPENSRC_PACKAGE,
951
1283
  OMC_PACKAGE,
952
1284
  OMC_REPO_URL,
953
1285
  COLONY_PACKAGE,
@@ -957,11 +1289,34 @@ module.exports = {
957
1289
  GLOBAL_TOOLCHAIN_PACKAGES,
958
1290
  OPTIONAL_LOCAL_COMPANION_TOOLS,
959
1291
  resolveGithubCliBin,
960
- GH_BIN,
961
- REQUIRED_SYSTEM_TOOLS,
1292
+ get GH_BIN() {
1293
+ if (_ghBin === undefined) _ghBin = resolveGithubCliBin();
1294
+ return _ghBin;
1295
+ },
1296
+ get REQUIRED_SYSTEM_TOOLS() {
1297
+ if (!_requiredSystemTools) {
1298
+ const ghBin = module.exports.GH_BIN;
1299
+ _requiredSystemTools = [
1300
+ {
1301
+ name: 'gh',
1302
+ displayName: ghBin === 'ghx' ? 'GitHub (ghx proxy)' : 'GitHub (gh)',
1303
+ command: ghBin,
1304
+ installHint: 'https://cli.github.com/',
1305
+ },
1306
+ {
1307
+ name: 'rtk',
1308
+ displayName: 'RTK (rtk)',
1309
+ command: RTK_BIN,
1310
+ installHint: 'Install RTK and ensure `rtk` is on PATH.',
1311
+ },
1312
+ ];
1313
+ }
1314
+ return _requiredSystemTools;
1315
+ },
962
1316
  MAINTAINER_RELEASE_REPO,
963
1317
  NPM_BIN,
964
1318
  OPENSPEC_BIN,
1319
+ CODEGRAPH_BIN,
965
1320
  SCORECARD_BIN,
966
1321
  GIT_PROTECTED_BRANCHES_KEY,
967
1322
  GIT_BASE_BRANCH_KEY,
@@ -1009,6 +1364,7 @@ module.exports = {
1009
1364
  TARGETED_FORCEABLE_MANAGED_PATHS,
1010
1365
  COMMAND_TYPO_ALIASES,
1011
1366
  SUGGESTIBLE_COMMANDS,
1367
+ CLI_COMMAND_HELP,
1012
1368
  CLI_COMMAND_DESCRIPTIONS,
1013
1369
  CLI_COMMAND_GROUPS,
1014
1370
  CLI_QUICKSTART_STEPS,