@imdeadpool/guardex 8.4.25 → 8.4.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imdeadpool/guardex",
3
- "version": "8.4.25",
3
+ "version": "8.4.26",
4
4
  "description": "Guardian T-Rex for your multi-agent repo. Isolated worktrees, file locks, and PR-only merges stop parallel Codex & Claude agents from overwriting each other's work. Auto-wires Oh My Codex, Oh My Claude, OpenSpec, and Caveman.",
5
5
  "license": "MIT",
6
6
  "preferGlobal": true,
@@ -65,5 +65,5 @@
65
65
  "prepublishOnly": "node scripts/prepublish-bump-version.js",
66
66
  "postinstall": "node -e \"require('./src/heavy').installReport()\""
67
67
  },
68
- "gitHead": "13d45cbde94a8cf9ccc3cdde0049d62c4d0baa11"
68
+ "gitHead": "bf90aca41cc24d8b6dd8ec9e3706522196e664f0"
69
69
  }
@@ -353,7 +353,8 @@ function branch(rawArgs) {
353
353
  autoCommitWorktree ? 'checking worktree and pending changes' : 'resolving branch and finish policy',
354
354
  );
355
355
  const commitState = autoCommitWorktree
356
- ? autoCommitWorktreeForFinish(repoRoot, autoCommitWorktree, finishBranch, { noAutoCommit, commitMessage })
356
+ ? progress.trackFailure(() =>
357
+ autoCommitWorktreeForFinish(repoRoot, autoCommitWorktree, finishBranch, { noAutoCommit, commitMessage }))
357
358
  : { changed: false, committed: false };
358
359
  if (commitState.committed && !agentQuiet) {
359
360
  console.log(`[${TOOL_NAME}] Auto-committed '${finishBranch}' before finish.`);
@@ -367,7 +368,7 @@ function branch(rawArgs) {
367
368
  // the merge never happens.
368
369
  let gateResult;
369
370
  if (gateReview) {
370
- gateResult = runReviewGate({
371
+ gateResult = progress.trackFailure(() => runReviewGate({
371
372
  repoRoot,
372
373
  branch: finishBranch,
373
374
  // Must match how the shell resolves --base when it is omitted, which
@@ -390,7 +391,7 @@ function branch(rawArgs) {
390
391
  },
391
392
  progress,
392
393
  preflight: branchPreflightDuringCi(repoRoot, scriptArgs, { activeCwd, agentQuiet, progress }),
393
- });
394
+ }));
394
395
  } else {
395
396
  progress.skip('review', 'review gate disabled');
396
397
  progress.skip('autofix', 'review gate disabled');
@@ -128,6 +128,7 @@ function startHeartbeat({
128
128
  runId: String(event.runId || ''),
129
129
  branch: String(event.branch || ''),
130
130
  baseBranch: String(event.baseBranch || ''),
131
+ ...(event.recovery ? { recovery: event.recovery } : {}),
131
132
  };
132
133
  stdio.push(eventDescriptor);
133
134
  }
@@ -569,7 +569,7 @@ function finish(rawArgs, defaults = {}) {
569
569
  progress.start('prepare', worktreePath ? 'checking worktree and pending changes' : 'checking branch');
570
570
  let commitState = { changed: false, committed: false };
571
571
  if (worktreePath) {
572
- commitState = autoCommitWorktreeForFinish(repoRoot, worktreePath, branch, options);
572
+ commitState = progress.trackFailure(() => autoCommitWorktreeForFinish(repoRoot, worktreePath, branch, options));
573
573
  }
574
574
 
575
575
  if (terse) {
@@ -694,12 +694,12 @@ function finish(rawArgs, defaults = {}) {
694
694
  finishArgs.push('--no-preflight');
695
695
  }
696
696
  if (options.mergeMode === 'pr' && options.gateReview) {
697
- gateResult = runReviewGate({
697
+ gateResult = progress.trackFailure(() => runReviewGate({
698
698
  repoRoot, worktreePath, branch, baseBranch, options, progress,
699
699
  preflight: branchPreflightDuringCi(repoRoot, finishArgs, {
700
700
  activeCwd, agentQuiet: options.agentQuiet, progress,
701
701
  }),
702
- });
702
+ }));
703
703
  } else {
704
704
  progress.skip('review', 'review gate disabled');
705
705
  progress.skip('autofix', 'review gate disabled');
@@ -20,6 +20,28 @@ const SYMBOLS = {
20
20
 
21
21
  const TIMED_STAGES = new Set(['review', 'autofix']);
22
22
 
23
+ const RECOVERY_ACTIONS = {
24
+ prepare: 'Inspect the worktree and pending changes before retrying finish.',
25
+ preflight: 'Inspect the local check output and correct the failure before retrying finish.',
26
+ pr: 'Check whether the branch was pushed and the PR already exists before retrying finish.',
27
+ review: 'Check the current PR head and base and the posted review before retrying gated finish.',
28
+ autofix: 'Check the repair commit and whether it was pushed before applying another fix.',
29
+ ci: 'Refresh checks and required approvals on the current PR head before retrying gated finish.',
30
+ merge: 'Check whether GitHub already merged the PR before retrying gated finish.',
31
+ cleanup: 'Confirm the PR merged and the worktree is safe to remove before retrying cleanup.',
32
+ };
33
+
34
+ function recoveryFields(stage, state, detail) {
35
+ if (state !== 'running' && state !== 'failed') return {};
36
+ return {
37
+ recovery: {
38
+ outcome: state === 'failed' ? 'failed' : 'unconfirmed',
39
+ reason: state === 'failed' ? (detail || 'Stage failed') : 'No completed outcome recorded yet',
40
+ nextAction: RECOVERY_ACTIONS[stage],
41
+ },
42
+ };
43
+ }
44
+
23
45
  function createRunId(branch) {
24
46
  const digest = crypto.createHash('sha256').update(String(branch || '')).digest('hex').slice(0, 8);
25
47
  return `finish-${Date.now().toString(36)}-${process.pid}-${digest}`;
@@ -148,6 +170,8 @@ function createFinishProgress({
148
170
  const stageStartedAt = new Map();
149
171
  let activeTimedStage = '';
150
172
  let stopActiveHeartbeat = null;
173
+ let lastPrimaryStage = 'prepare';
174
+ let failures = 0;
151
175
 
152
176
  output(`[gx:finish] ╭─ 🚀 GX FINISH · ${branch || 'current branch'} → ${baseBranch || 'configured base'}`);
153
177
  if (eventStream) {
@@ -189,6 +213,10 @@ function createFinishProgress({
189
213
  if (stage.state === state && stage.detail === normalizedDetail) return false;
190
214
  stage.state = state;
191
215
  stage.detail = normalizedDetail;
216
+ // Skips do not advance the gate. Preflight can overlap CI and reports
217
+ // its own failures; it must not inherit a subsequent gate exception.
218
+ if (state !== 'skipped' && id !== 'preflight') lastPrimaryStage = id;
219
+ if (state === 'failed') failures += 1;
192
220
  const connector = id === 'cleanup' && state !== 'running' ? '╰─' : '├─';
193
221
  output(
194
222
  `[gx:finish] ${connector} ${SYMBOLS[state]} ${stage.index}/${STAGES.length} ${stage.label}`
@@ -202,6 +230,7 @@ function createFinishProgress({
202
230
  total: STAGES.length,
203
231
  label: stage.label,
204
232
  detail: normalizedDetail,
233
+ ...recoveryFields(id, state, normalizedDetail),
205
234
  });
206
235
  }
207
236
  return true;
@@ -231,7 +260,7 @@ function createFinishProgress({
231
260
  startAt,
232
261
  ...(eventStream ? {
233
262
  eventDescriptor: eventStream.descriptor,
234
- event: eventStream.event,
263
+ event: { ...eventStream.event, ...recoveryFields(id, 'running', normalizedDetail) },
235
264
  } : {}),
236
265
  });
237
266
  } catch (_error) {
@@ -249,8 +278,36 @@ function createFinishProgress({
249
278
  update(id, state, detail, displaySuffix);
250
279
  }
251
280
 
281
+ // Gate checks may throw after a stage reports success (e.g. the base moves).
282
+ // Preserve the error without replacing a more specific phase failure.
283
+ function trackFailure(operation) {
284
+ const previousFailures = failures;
285
+ try {
286
+ return operation();
287
+ } catch (error) {
288
+ if (failures === previousFailures) {
289
+ const reason = String(error?.message || 'Finish stopped').split('\n', 1)[0].slice(0, 500);
290
+ const stage = stageMap.get(lastPrimaryStage);
291
+ if (stage.state === 'complete') {
292
+ // A later guard can stop finish without undoing a completed check.
293
+ eventStream?.write({
294
+ ...stage,
295
+ stage: lastPrimaryStage,
296
+ total: STAGES.length,
297
+ kind: 'guard-failure',
298
+ ...recoveryFields(lastPrimaryStage, 'failed', reason),
299
+ });
300
+ } else {
301
+ settle(lastPrimaryStage, 'failed', reason);
302
+ }
303
+ }
304
+ throw error;
305
+ }
306
+ }
307
+
252
308
  return {
253
309
  start,
310
+ trackFailure,
254
311
  complete: (id, detail) => settle(id, 'complete', detail),
255
312
  skip: (id, detail) => settle(id, 'skipped', detail),
256
313
  fail: (id, detail) => settle(id, 'failed', detail),
@@ -107,9 +107,27 @@ finish_event() {
107
107
  local label="${4:-}"
108
108
  local detail="${5:-}"
109
109
  local timestamp=""
110
+ local recovery="" outcome="" reason="" next_action=""
110
111
  [[ -n "$FINISH_EVENT_FILE" && -n "$FINISH_RUN_ID" ]] || return 0
112
+ if [[ "$state" == "running" || "$state" == "failed" ]]; then
113
+ case "$stage" in
114
+ preflight) next_action="Inspect the local check output and correct the failure before retrying finish." ;;
115
+ pr) next_action="Check whether the branch was pushed and the PR already exists before retrying finish." ;;
116
+ merge) next_action="Check whether GitHub already merged the PR before retrying gated finish." ;;
117
+ cleanup) next_action="Confirm the PR merged and the worktree is safe to remove before retrying cleanup." ;;
118
+ esac
119
+ if [[ "$state" == "failed" ]]; then
120
+ outcome="failed"
121
+ reason="${detail:-Stage failed}"
122
+ else
123
+ outcome="unconfirmed"
124
+ reason="No completed outcome recorded yet"
125
+ fi
126
+ recovery="$(printf ',"recovery":{"outcome":"%s","reason":"%s","nextAction":"%s"}' \
127
+ "$outcome" "$(finish_json_escape "$reason")" "$(finish_json_escape "$next_action")")"
128
+ fi
111
129
  timestamp="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
112
- printf '{"schemaVersion":1,"runId":"%s","timestamp":"%s","branch":"%s","baseBranch":"%s","stage":"%s","state":"%s","index":%s,"total":8,"label":"%s","detail":"%s"}\n' \
130
+ printf '{"schemaVersion":1,"runId":"%s","timestamp":"%s","branch":"%s","baseBranch":"%s","stage":"%s","state":"%s","index":%s,"total":8,"label":"%s","detail":"%s"%s}\n' \
113
131
  "$(finish_json_escape "$FINISH_RUN_ID")" \
114
132
  "$timestamp" \
115
133
  "$(finish_json_escape "$FINISH_EVENT_BRANCH")" \
@@ -119,6 +137,7 @@ finish_event() {
119
137
  "$number" \
120
138
  "$(finish_json_escape "$label")" \
121
139
  "$(finish_json_escape "$detail")" \
140
+ "$recovery" \
122
141
  >> "$FINISH_EVENT_FILE" 2>/dev/null || true
123
142
  }
124
143
 
@@ -350,7 +369,7 @@ run_preflight() {
350
369
  echo "[agent-branch-finish] Pre-flight passed." >&2
351
370
  return 0
352
371
  fi
353
- finish_progress failed preflight "failed"
372
+ finish_progress failed preflight "preflight exited with status ${preflight_status}"
354
373
  echo "[agent-branch-finish] Pre-flight FAILED; refusing push. Override with --no-preflight if you really mean it." >&2
355
374
  return 1
356
375
  }