@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
package/src/pr.js CHANGED
@@ -7,7 +7,7 @@
7
7
  // these helpers expose the same primitives to the JS CLI so `gx pr ...` can be
8
8
  // driven without invoking the shell flow.
9
9
 
10
- const { GH_BIN } = require('./context');
10
+ const _ctx = require('./context');
11
11
  const { run } = require('./core/runtime');
12
12
  const {
13
13
  resolveRepoRoot,
@@ -33,12 +33,12 @@ class PrError extends Error {
33
33
  }
34
34
 
35
35
  function ghAvailable() {
36
- const result = run(GH_BIN, ['--version'], { allowFailure: true });
36
+ const result = run(_ctx.GH_BIN, ['--version'], { allowFailure: true });
37
37
  return result.status === 0;
38
38
  }
39
39
 
40
40
  function ghAuthStatus() {
41
- const result = run(GH_BIN, ['auth', 'status'], { allowFailure: true });
41
+ const result = run(_ctx.GH_BIN, ['auth', 'status'], { allowFailure: true });
42
42
  return {
43
43
  authenticated: result.status === 0,
44
44
  output: ((result.stdout || '') + (result.stderr || '')).trim(),
@@ -46,7 +46,7 @@ function ghAuthStatus() {
46
46
  }
47
47
 
48
48
  function ghJson(repoRoot, args) {
49
- const result = run(GH_BIN, args, { cwd: repoRoot, allowFailure: true });
49
+ const result = run(_ctx.GH_BIN, args, { cwd: repoRoot, allowFailure: true });
50
50
  if (result.status !== 0) {
51
51
  return { ok: false, error: (result.stderr || result.stdout || '').trim(), data: null };
52
52
  }
@@ -59,6 +59,28 @@ function ghJson(repoRoot, args) {
59
59
  }
60
60
  }
61
61
 
62
+ function githubActionsWorkflowsDisabled(repoRoot, runner = run) {
63
+ const result = runner(_ctx.GH_BIN, [
64
+ 'api',
65
+ repoApiPath(repoRoot, 'actions/workflows?per_page=100', runner),
66
+ '--paginate',
67
+ '--slurp',
68
+ ], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
69
+ if (result.status !== 0) return false;
70
+
71
+ try {
72
+ const pages = JSON.parse(String(result.stdout || ''));
73
+ if (!Array.isArray(pages) || !pages.length || !pages.every((page) => Array.isArray(page?.workflows))) return false;
74
+ const workflows = pages.flatMap((page) => page.workflows);
75
+ return workflows.length > 0
76
+ && pages.every((page) => page.total_count === workflows.length)
77
+ && workflows.every((workflow) => Number.isSafeInteger(workflow?.id) && workflow.state === 'disabled_manually')
78
+ && new Set(workflows.map((workflow) => workflow.id)).size === workflows.length;
79
+ } catch (_error) {
80
+ return false;
81
+ }
82
+ }
83
+
62
84
  function githubActionsJobId(check) {
63
85
  if (String(check?.__typename || '') !== 'CheckRun') return '';
64
86
  if (!String(check?.name || '').trim()) return '';
@@ -92,7 +114,7 @@ function commitCheckRuns(repoRoot, headSha, runner = run) {
92
114
  const sha = String(headSha || '').trim();
93
115
  if (!/^[0-9a-f]{7,64}$/i.test(sha)) return [];
94
116
 
95
- const result = runner(GH_BIN, [
117
+ const result = runner(_ctx.GH_BIN, [
96
118
  'api',
97
119
  repoApiPath(repoRoot, `commits/${sha}/check-runs?per_page=100`, runner),
98
120
  ], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
@@ -122,7 +144,7 @@ function isBillingBlockedCheckRun(repoRoot, check, expectedCheckRunId, runner =
122
144
  const jobId = githubActionsJobId(check);
123
145
  if (!jobId || !expectedCheckRunId) return false;
124
146
 
125
- const jobResult = runner(GH_BIN, [
147
+ const jobResult = runner(_ctx.GH_BIN, [
126
148
  'api',
127
149
  repoApiPath(repoRoot, `actions/jobs/${jobId}`, runner),
128
150
  ], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
@@ -144,7 +166,7 @@ function isBillingBlockedCheckRun(repoRoot, check, expectedCheckRunId, runner =
144
166
  const annotationsPath = githubCheckRunAnnotationsPath(job, expectedCheckRunId);
145
167
  if (!annotationsPath) return false;
146
168
 
147
- const result = runner(GH_BIN, [
169
+ const result = runner(_ctx.GH_BIN, [
148
170
  'api',
149
171
  repoApiPath(repoRoot, annotationsPath, runner),
150
172
  ], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
@@ -334,7 +356,7 @@ function openPullRequest(options) {
334
356
  ];
335
357
  if (options.draft !== false) args.push('--draft');
336
358
 
337
- const result = run(GH_BIN, args, { cwd: repoRoot, allowFailure: true });
359
+ const result = run(_ctx.GH_BIN, args, { cwd: repoRoot, allowFailure: true });
338
360
  if (result.status !== 0) {
339
361
  throw new PrError(
340
362
  `gh pr create failed:\n${(result.stderr || result.stdout || '').trim()}`,
@@ -342,6 +364,22 @@ function openPullRequest(options) {
342
364
  );
343
365
  }
344
366
 
367
+ // gh pr create prints the PR URL as its last (or only) non-empty line.
368
+ // Parse it to avoid a second list-API round-trip on the happy path.
369
+ const createStdout = (result.stdout || '').trim();
370
+ const urlMatch = createStdout.match(/https:\/\/github\.com\/[^\s]+\/pull\/\d+/);
371
+ if (urlMatch) {
372
+ const prUrl = urlMatch[0];
373
+ const viewResult = ghJson(repoRoot, [
374
+ 'pr', 'view', prUrl,
375
+ '--json', 'number,url,state,isDraft,mergeable,mergeStateStatus,reviewDecision,headRefName,headRefOid,baseRefName,title,statusCheckRollup',
376
+ ]);
377
+ if (viewResult.ok && viewResult.data) {
378
+ return { created: true, pr: viewResult.data };
379
+ }
380
+ }
381
+
382
+ // Fall back to a list lookup when the stdout URL is absent or the view call failed.
345
383
  const created = findOpenPrForBranch(repoRoot, branch);
346
384
  if (!created) {
347
385
  throw new PrError('PR appears to have been created but could not be located on origin', {
@@ -391,6 +429,25 @@ function getPullRequestStatus(repoRoot, branch) {
391
429
  };
392
430
  }
393
431
 
432
+ /**
433
+ * Lightweight poll: fetch only the open PR's headRefOid for `branch`.
434
+ * Used when only the head SHA is needed (e.g. waiting for a push to propagate)
435
+ * and fetching the full statusCheckRollup would be wasteful.
436
+ *
437
+ * Returns `{ headSha }` when an open PR exists, or `null` otherwise.
438
+ */
439
+ function getPrHeadOid(repoRoot, branch) {
440
+ const result = ghJson(repoRoot, [
441
+ 'pr', 'list',
442
+ '--head', branch,
443
+ '--state', 'open',
444
+ '--json', 'headRefOid',
445
+ '--limit', '1',
446
+ ]);
447
+ if (!result.ok || !Array.isArray(result.data) || !result.data.length) return null;
448
+ return { headSha: result.data[0].headRefOid || '' };
449
+ }
450
+
394
451
  /**
395
452
  * Check outcomes recorded against `ref` (a branch name or SHA).
396
453
  *
@@ -419,13 +476,13 @@ function checkOutcomes(repoRoot, ref, runner = run) {
419
476
  }
420
477
  };
421
478
 
422
- collect(runner(GH_BIN, [
479
+ collect(runner(_ctx.GH_BIN, [
423
480
  'api', '--paginate',
424
481
  repoApiPath(repoRoot, `commits/${ref}/check-runs?per_page=100`, runner),
425
482
  '-q', '.check_runs[] | select(.status == "completed") | "\\(.conclusion)\\t\\(.name)"',
426
483
  ], { cwd: repoRoot, timeout: 60_000, allowFailure: true }));
427
484
 
428
- collect(runner(GH_BIN, [
485
+ collect(runner(_ctx.GH_BIN, [
429
486
  'api',
430
487
  repoApiPath(repoRoot, `commits/${ref}/status`, runner),
431
488
  '-q', '.statuses[] | "\\(.state)\\t\\(.context)"',
@@ -436,7 +493,7 @@ function checkOutcomes(repoRoot, ref, runner = run) {
436
493
 
437
494
  /** Head SHA of the most recently merged PR into `baseBranch`, or ''. */
438
495
  function lastMergedPrHead(repoRoot, baseBranch, runner = run) {
439
- const result = runner(GH_BIN, [
496
+ const result = runner(_ctx.GH_BIN, [
440
497
  'api',
441
498
  // GitHub cannot sort by merge time; `updated` desc correlates with it far
442
499
  // better than the `created` desc default, which would rank a long-lived PR
@@ -502,7 +559,7 @@ function enableAutoMerge(repoRoot, prNumber, { strategy = 'squash' } = {}) {
502
559
  const flag = strategy === 'merge'
503
560
  ? '--merge'
504
561
  : strategy === 'rebase' ? '--rebase' : '--squash';
505
- const result = run(GH_BIN, [
562
+ const result = run(_ctx.GH_BIN, [
506
563
  'pr', 'merge', String(prNumber),
507
564
  '--auto', flag, '--delete-branch',
508
565
  ], { cwd: repoRoot, allowFailure: true });
@@ -513,7 +570,7 @@ function enableAutoMerge(repoRoot, prNumber, { strategy = 'squash' } = {}) {
513
570
  }
514
571
 
515
572
  function markPullRequestReady(repoRoot, prNumber) {
516
- const result = run(GH_BIN, ['pr', 'ready', String(prNumber)], {
573
+ const result = run(_ctx.GH_BIN, ['pr', 'ready', String(prNumber)], {
517
574
  cwd: repoRoot, allowFailure: true,
518
575
  });
519
576
  return {
@@ -523,7 +580,7 @@ function markPullRequestReady(repoRoot, prNumber) {
523
580
  }
524
581
 
525
582
  function markPullRequestDraft(repoRoot, prNumber) {
526
- const result = run(GH_BIN, ['pr', 'ready', '--undo', String(prNumber)], {
583
+ const result = run(_ctx.GH_BIN, ['pr', 'ready', '--undo', String(prNumber)], {
527
584
  cwd: repoRoot, allowFailure: true,
528
585
  });
529
586
  return {
@@ -610,6 +667,8 @@ module.exports = {
610
667
  pushBranch,
611
668
  openPullRequest,
612
669
  getPullRequestStatus,
670
+ getPrHeadOid,
671
+ githubActionsWorkflowsDisabled,
613
672
  githubActionsJobId,
614
673
  isBillingBlockedCheckRun,
615
674
  checkOutcomes,
@@ -92,10 +92,31 @@ function resolveProviderBin(provider, env = process.env) {
92
92
  return findRealProviderBin(normalized, env) || normalized;
93
93
  }
94
94
 
95
+ function withProviderStderr(agentQuiet, execute) {
96
+ if (!agentQuiet) return execute('inherit');
97
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gitguardex-provider-'));
98
+ let fd;
99
+ try {
100
+ // Don't pipe stderr: verbose diagnostics must not consume the stdout
101
+ // buffer budget or cause spawnSync to terminate a successful provider.
102
+ fd = fs.openSync(path.join(dir, 'stderr'), 'wx+', 0o600);
103
+ const result = execute(fd);
104
+ if (result.status === 0) return result;
105
+ const size = fs.fstatSync(fd).size;
106
+ const tail = Buffer.alloc(Math.min(size, 2000));
107
+ const read = fs.readSync(fd, tail, 0, tail.length, size - tail.length);
108
+ return { ...result, stderr: tail.toString('utf8', 0, read) };
109
+ } finally {
110
+ if (fd !== undefined) fs.closeSync(fd);
111
+ fs.rmSync(dir, { recursive: true, force: true });
112
+ }
113
+ }
114
+
95
115
  module.exports = {
96
116
  codexReviewEffort,
97
117
  cueShimDir,
98
118
  findRealProviderBin,
99
119
  isCueAgentShim,
100
120
  resolveProviderBin,
121
+ withProviderStderr,
101
122
  };
@@ -0,0 +1,90 @@
1
+ const MIN_LOCK_DIFF_LENGTH = 8_192;
2
+ const LOCK_HEADER = /^diff --git a\/((?:[\w.@-]+\/)*package-lock\.json) b\/\1$/;
3
+ const FILE_INDEX = /^index [0-9a-f]+\.\.[0-9a-f]+ 100644$/;
4
+ const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: .*)?$/;
5
+ const PACKAGE_ENTRY = /^[ +\-] {4}"node_modules\/[^"\\]+": {$/;
6
+ const GENERATED_METADATA =
7
+ /^ {7}"(?:(?:dev|optional|peer|devOptional)": (?:true|false)|(?:version|license)": "[^"\\\r\n]{1,80}"|integrity": "sha(?:1|256|384|512)-[A-Za-z0-9+/=]+"|resolved": "https:\/\/registry\.npmjs\.org\/[^\s"\\]+"),?$/;
8
+
9
+ function isOmittable(lines, index) {
10
+ // Preserve package labels, structure, custom registry URLs, script metadata,
11
+ // and the immediate context on either side of a changed line.
12
+ return (
13
+ GENERATED_METADATA.test(lines[index] || '') &&
14
+ !/^[+-]/.test(lines[index - 1] || '') &&
15
+ !/^[+-]/.test(lines[index + 1] || '')
16
+ );
17
+ }
18
+
19
+ function compactHunk(lines) {
20
+ const header = HUNK.exec(lines[0]);
21
+ if (!header) return null;
22
+ let oldLine = Number(header[1]);
23
+ let newLine = Number(header[3]);
24
+ const oldEnd = oldLine + Number(header[2] ?? 1);
25
+ const newEnd = newLine + Number(header[4] ?? 1);
26
+ if (!Number.isSafeInteger(oldEnd) || !Number.isSafeInteger(newEnd)) return null;
27
+ const result = [lines[0]];
28
+ for (let i = 1; i < lines.length; ) {
29
+ const line = lines[i];
30
+ const prefix = line[0];
31
+ if (prefix !== ' ' && prefix !== '+' && prefix !== '-') return null;
32
+ if (isOmittable(lines, i)) {
33
+ let end = i + 1;
34
+ while (isOmittable(lines, end)) end += 1;
35
+ const count = end - i;
36
+ const oldRange = count === 1 ? oldLine : `${oldLine}-${oldLine + count - 1}`;
37
+ const newRange = count === 1 ? newLine : `${newLine}-${newLine + count - 1}`;
38
+ const marker = ` [unchanged lockfile context: old ${oldRange}, new ${newRange}]`;
39
+ const original = lines.slice(i, end).join('\n');
40
+ result.push(marker.length < original.length ? marker : original);
41
+ oldLine += count;
42
+ newLine += count;
43
+ i = end;
44
+ continue;
45
+ }
46
+ if (prefix !== '+') oldLine += 1;
47
+ if (prefix !== '-') newLine += 1;
48
+ result.push(line);
49
+ i += 1;
50
+ }
51
+ return oldLine === oldEnd && newLine === newEnd ? result.join('\n') : null;
52
+ }
53
+
54
+ function compactSection(section) {
55
+ if (section.length < MIN_LOCK_DIFF_LENGTH) return section;
56
+ const lines = section.split('\n');
57
+ const path = LOCK_HEADER.exec(lines[0])?.[1];
58
+ if (
59
+ !path ||
60
+ !FILE_INDEX.test(lines[1]) ||
61
+ lines[2] !== `--- a/${path}` ||
62
+ lines[3] !== `+++ b/${path}` ||
63
+ !lines.some((line) => PACKAGE_ENTRY.test(line))
64
+ ) {
65
+ return section;
66
+ }
67
+ const trailingNewline = lines.at(-1) === '' ? lines.pop() : null;
68
+ const compacted = lines.slice(0, 4);
69
+ for (let start = 4; start < lines.length; ) {
70
+ let end = start + 1;
71
+ while (end < lines.length && !lines[end].startsWith('@@ ')) end += 1;
72
+ const hunk = compactHunk(lines.slice(start, end));
73
+ if (hunk === null) return section;
74
+ compacted.push(hunk);
75
+ start = end;
76
+ }
77
+ if (trailingNewline !== null) compacted.push(trailingNewline);
78
+ return compacted.join('\n');
79
+ }
80
+
81
+ /** Provider prompt only: keep the original diff for all validation and anchoring. */
82
+ function compactGeneratedReviewDiff(diff) {
83
+ if (diff.length < MIN_LOCK_DIFF_LENGTH || !diff.includes('/package-lock.json')) return diff;
84
+ return diff
85
+ .split(/(?<=\n)(?=diff --git )/)
86
+ .map(compactSection)
87
+ .join('');
88
+ }
89
+
90
+ module.exports = { compactGeneratedReviewDiff };
package/src/review-fix.js CHANGED
@@ -14,13 +14,14 @@
14
14
 
15
15
  const { run } = require('./core/runtime');
16
16
  const { gitRun, currentBranchName, readProtectedBranches } = require('./git');
17
- const { codexReviewEffort, resolveProviderBin } = require('./provider-binary');
17
+ const { codexReviewEffort, resolveProviderBin, withProviderStderr } = require('./provider-binary');
18
18
 
19
19
  const DEFAULT_FIX_TIMEOUT_MS = 15 * 60 * 1000;
20
20
  const TOOL_PREFIX = '[gitguardex]';
21
21
  const CODEX_AUTOMATION_ARGS = ['--ephemeral', '--ignore-user-config', '--ignore-rules'];
22
22
 
23
23
  function resolveFixModel(model, env = process.env) {
24
+ if (model === null) return ''; // Don't pass the primary model to a fallback provider.
24
25
  const explicit = String(model || '').trim();
25
26
  if (explicit) return explicit;
26
27
  return String(env.GUARDEX_REVIEW_MODEL || '').trim();
@@ -37,12 +38,12 @@ function commandForFix(provider, prompt, settings = {}) {
37
38
  const model = String(settings.model || '').trim();
38
39
  if (provider === 'claude') {
39
40
  // Print mode defaults to asking for permission; acceptEdits lets it write.
40
- return {
41
- cmd,
42
- args: model
43
- ? ['--safe-mode', '--model', model, '-p', '--permission-mode', 'acceptEdits', prompt]
44
- : ['--safe-mode', '-p', '--permission-mode', 'acceptEdits', prompt],
45
- };
41
+ // Deliver the prompt via stdin (same as the review path) so it never
42
+ // appears in the process listing and cannot exceed ARG_MAX.
43
+ const args = ['--safe-mode', '--permission-mode', 'acceptEdits'];
44
+ if (model) args.push('--model', model);
45
+ args.push('-p');
46
+ return { cmd, args, input: prompt };
46
47
  }
47
48
  // `codex exec` sandboxes to read-only by default; workspace-write allows edits
48
49
  // inside the worktree and nowhere else.
@@ -56,8 +57,9 @@ function commandForFix(provider, prompt, settings = {}) {
56
57
  args: [
57
58
  'exec', ...automationArgs, ...effortArgs,
58
59
  ...(model ? ['-m', model] : []),
59
- '--sandbox', 'workspace-write', prompt,
60
+ '--sandbox', 'workspace-write', '-',
60
61
  ],
62
+ input: prompt,
61
63
  };
62
64
  }
63
65
 
@@ -140,6 +142,7 @@ function runReviewFix({
140
142
  timeoutMs = DEFAULT_FIX_TIMEOUT_MS,
141
143
  expectBranch = '',
142
144
  model = '',
145
+ agentQuiet = false,
143
146
  }, deps = {}) {
144
147
  const runner = deps.run || run;
145
148
  if (findings.length === 0) {
@@ -186,17 +189,20 @@ function runReviewFix({
186
189
  const startedAt = Date.now();
187
190
  console.log(
188
191
  `${TOOL_PREFIX} code-assist ${provider} auto-fix started for ${findings.length} finding(s)`
189
- + `${selectedModel ? ` with model ${selectedModel}` : ''}; provider progress follows`,
192
+ + `${selectedModel ? ` with model ${selectedModel}` : ''}${agentQuiet ? '' : '; provider progress follows'}`,
193
+ );
194
+ const result = withProviderStderr(agentQuiet, (stderr) =>
195
+ runner(command.cmd, command.args, {
196
+ cwd: repoRoot,
197
+ timeout: timeoutMs,
198
+ input: command.input,
199
+ // No provider output is parsed in fix mode.
200
+ stdio: ['pipe', agentQuiet ? 'ignore' : 'inherit', stderr],
201
+ })
190
202
  );
191
- const result = runner(command.cmd, command.args, {
192
- cwd: repoRoot,
193
- timeout: timeoutMs,
194
- // No provider output is parsed in fix mode. Inherit both streams so edits,
195
- // tool calls, and progress remain visible to the parent Codex session.
196
- stdio: ['ignore', 'inherit', 'inherit'],
197
- });
198
203
  if (result.status !== 0) {
199
- throw new Error(`${provider} fix run failed${result.stderr ? `\n${result.stderr.trim()}` : ''}`);
204
+ const detail = String(result.stderr || '').trim();
205
+ throw new Error(`${provider} fix run failed${detail ? `\n${detail}` : ''}`);
200
206
  }
201
207
  console.log(
202
208
  `${TOOL_PREFIX} code-assist ${provider} auto-fix completed in ${Math.round((Date.now() - startedAt) / 1000)}s`,
@@ -20,7 +20,7 @@
20
20
  const fs = require('fs');
21
21
  const path = require('path');
22
22
  const { spawnSync } = require('child_process');
23
- const { provisionFromConfig } = require('./provision-config');
23
+ const { provisionFromConfig, provisioningMode } = require('./provision-config');
24
24
 
25
25
  const ENV_FILE_CANDIDATES = [
26
26
  '.env',
@@ -28,7 +28,7 @@ const ENV_FILE_CANDIDATES = [
28
28
  '.env.development',
29
29
  '.env.development.local',
30
30
  '.env.production',
31
- '.env.production.local',
31
+ '.env.production.local'
32
32
  ];
33
33
 
34
34
  // Port pool by detected app role. Storefronts get the Vite/Next range,
@@ -36,7 +36,7 @@ const ENV_FILE_CANDIDATES = [
36
36
  const PORT_POOLS = {
37
37
  storefront: 5174,
38
38
  backend: 9101,
39
- default: 8100,
39
+ default: 8100
40
40
  };
41
41
 
42
42
  function detectAppPackages(repoRoot) {
@@ -77,7 +77,7 @@ function isPortFree(port) {
77
77
  // CI image); the dev server will fail loudly if it isn't.
78
78
  const probe = spawnSync('lsof', ['-iTCP:' + port, '-sTCP:LISTEN', '-t'], {
79
79
  stdio: ['ignore', 'pipe', 'pipe'],
80
- timeout: 2000,
80
+ timeout: 2000
81
81
  });
82
82
  if (probe.error) return true;
83
83
  const out = (probe.stdout && probe.stdout.toString().trim()) || '';
@@ -114,7 +114,7 @@ function symlinkAppEnvFiles(repoRoot, worktreePath, appName) {
114
114
  operations.push({
115
115
  status: 'unchanged',
116
116
  file: `apps/${appName}/${candidate}`,
117
- note: 'already present in worktree',
117
+ note: 'already present in worktree'
118
118
  });
119
119
  continue;
120
120
  }
@@ -123,13 +123,13 @@ function symlinkAppEnvFiles(repoRoot, worktreePath, appName) {
123
123
  operations.push({
124
124
  status: 'linked',
125
125
  file: `apps/${appName}/${candidate}`,
126
- note: `→ ${path.relative(worktreePath, rootEnv)}`,
126
+ note: `→ ${path.relative(worktreePath, rootEnv)}`
127
127
  });
128
128
  } catch (err) {
129
129
  operations.push({
130
130
  status: 'failed',
131
131
  file: `apps/${appName}/${candidate}`,
132
- note: `symlink failed: ${err.message}`,
132
+ note: `symlink failed: ${err.message}`
133
133
  });
134
134
  }
135
135
  }
@@ -152,7 +152,7 @@ function assignAgentPort(repoRoot, worktreePath, appName, takenPorts) {
152
152
  return {
153
153
  status: 'failed',
154
154
  file: `apps/${appName}/.env.local`,
155
- note: 'no free port found in pool',
155
+ note: 'no free port found in pool'
156
156
  };
157
157
  }
158
158
  takenPorts.add(port);
@@ -183,11 +183,12 @@ function assignAgentPort(repoRoot, worktreePath, appName, takenPorts) {
183
183
  return {
184
184
  status: 'wrote',
185
185
  file: `apps/${appName}/.env.local`,
186
- note: `PORT=${port} (${role} pool)`,
186
+ note: `PORT=${port} (${role} pool)`
187
187
  };
188
188
  }
189
189
 
190
- function prepareAgentWorktree(repoRoot, worktreePath) {
190
+ function prepareAgentWorktree(repoRoot, worktreePath, deps = {}) {
191
+ const mode = provisioningMode(deps);
191
192
  if (!repoRoot || !worktreePath) return [];
192
193
  if (repoRoot === worktreePath) return [];
193
194
  if (!fs.existsSync(worktreePath)) return [];
@@ -196,7 +197,8 @@ function prepareAgentWorktree(repoRoot, worktreePath) {
196
197
 
197
198
  // Declarative `.guardex.json` provisioning runs for ANY repo (monorepo or
198
199
  // not) — copy/symlink gitignored files and run post_create hooks.
199
- operations.push(...provisionFromConfig(repoRoot, worktreePath));
200
+ operations.push(...provisionFromConfig(repoRoot, worktreePath, deps));
201
+ if (mode !== 'full') return operations;
200
202
 
201
203
  // Built-in apps/* monorepo convenience: env-file symlinks + a free dev port
202
204
  // per app. Stays as the zero-config default for monorepos.
@@ -216,5 +218,5 @@ module.exports = {
216
218
  pickFreePort,
217
219
  symlinkAppEnvFiles,
218
220
  assignAgentPort,
219
- prepareAgentWorktree,
221
+ prepareAgentWorktree
220
222
  };