claude-code-session-manager 0.130.3 → 0.132.0
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/dist/assets/{AgentLibrary-BmrXNwK8.js → AgentLibrary-C09MlPFx.js} +2 -2
- package/dist/assets/AppSettings-DvDKsCnD.js +2 -0
- package/dist/assets/{Button-UUr5giu8.js → Button-BzG_KdBC.js} +1 -1
- package/dist/assets/{DocumentEditorPane-C46Hj0lz.js → DocumentEditorPane-fm6zsnLM.js} +1 -1
- package/dist/assets/Extensions-DgxKT_OZ.js +2 -0
- package/dist/assets/{History-Bndupj87.js → History-Nd3bKjBq.js} +2 -2
- package/dist/assets/{Library-DFn0YPIW.js → Library-R71t6VAB.js} +12 -12
- package/dist/assets/{ListDetail-DjMn8a_3.js → ListDetail-CG50Ul7c.js} +1 -1
- package/dist/assets/{Panel-CIvb-XXN.js → Panel-C7EFG4eU.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BQQRtMdK.js → ProjectClaudeConfig-J92iNEGC.js} +7 -7
- package/dist/assets/{ProvenanceBadge-ej8W2ZIK.js → ProvenanceBadge-C3KB3ILO.js} +1 -1
- package/dist/assets/Scheduler-DeYBA7uc.js +16 -0
- package/dist/assets/{Settings-DqxUna06.js → Settings-B6r7N4v-.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-BEMTdxdD.js → SkillReferenceGraph-D7bt3fyB.js} +1 -1
- package/dist/assets/Skills-GpxtUrFP.js +29 -0
- package/dist/assets/{SourceChip-BrPci8FX.js → SourceChip-uyVMCZc7.js} +1 -1
- package/dist/assets/{SystemPrompt-B43hNP0X.js → SystemPrompt-Cv25uFSM.js} +1 -1
- package/dist/assets/{TiptapBody-B-R2Bpda.js → TiptapBody-uP8fJkbM.js} +1 -1
- package/dist/assets/{Toggle-DKb4x1BP.js → Toggle-DRs80cX-.js} +1 -1
- package/dist/assets/{ViewTabs-CcJdFZgv.js → ViewTabs-BDkvvzJ8.js} +1 -1
- package/dist/assets/{VoiceButton-BSH0UI3u.js → VoiceButton-Cmtz2sQt.js} +1 -1
- package/dist/assets/{historyTotals-5oUEu_fe.js → historyTotals-DHwAXunq.js} +1 -1
- package/dist/assets/index-CBCdyHbZ.js +3097 -0
- package/dist/assets/{index-CMCcT2yg.css → index-oXqzajWV.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +414 -390
- package/package.json +1 -1
- package/scripts/scheduler-mcp-server.cjs +83 -4
- package/src/main/build-info.json +4 -4
- package/src/main/index.cjs +11 -0
- package/src/main/ipcSchemas.cjs +28 -1
- package/src/main/lib/epic/epicMint.cjs +61 -6
- package/src/main/lib/epic/epicWorktreeMint.cjs +45 -4
- package/src/main/lib/epic/promptSessionsCreateEpic.cjs +32 -5
- package/src/main/lib/epic/restorableSessions.cjs +749 -0
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +36 -13
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +61 -0
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
- package/src/main/lib/git/branchSweep.cjs +9 -3
- package/src/main/lib/git/gitExec.cjs +8 -1
- package/src/main/lib/git/gitWorktree.cjs +564 -62
- package/src/main/lib/git/jobWorktree.cjs +3 -0
- package/src/main/lib/git/jobWorktreeBootLive.cjs +14 -2
- package/src/main/lib/mcpToolCatalog.cjs +43 -6
- package/src/main/lib/mcpToolsProbe.cjs +831 -0
- package/src/main/lib/persona-macro/builtinMacros.cjs +33 -0
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +8 -0
- package/src/main/lib/persona-macro/macroJobIpc.cjs +57 -11
- package/src/main/lib/persona-macro/macroLibrary.cjs +40 -10
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +38 -0
- package/src/main/lib/project-pages/competitiveMatrix.cjs +258 -0
- package/src/main/lib/project-pages/matrixHtml.cjs +239 -0
- package/src/main/lib/project-pages/matrixStore.cjs +112 -0
- package/src/main/lib/promptSessionSchema.cjs +5 -0
- package/src/main/lib/scheduler/fixPlanSlug.cjs +15 -1
- package/src/main/lib/scheduler/reaperHelpers.cjs +35 -0
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
- package/src/main/lib/scheduler/scheduleJobTransitions.cjs +8 -7
- package/src/main/projectPages.cjs +25 -2
- package/src/main/promptSessionEvents.cjs +10 -6
- package/src/main/runVerify.cjs +8 -3
- package/src/main/scheduler/budget.cjs +146 -7
- package/src/main/scheduler/gitTreeGuard.cjs +10 -11
- package/src/main/scheduler/reviewLadder.cjs +60 -0
- package/src/main/scheduler.cjs +461 -48
- package/src/main/seedAgentPersonas.cjs +1 -1
- package/src/preload/api.d.ts +162 -2
- package/src/preload/apiSurface.json +21 -0
- package/src/preload/index.cjs +5 -0
- package/src/seed/agents/competitive-analyst.md +69 -0
- package/src/seed/agents/competitive-researcher.md +75 -0
- package/src/seed/agents/validator.md +2 -2
- package/dist/assets/AppSettings-Cs4POznd.js +0 -2
- package/dist/assets/Extensions-B9QdiNOV.js +0 -2
- package/dist/assets/Scheduler-DSVBWqRK.js +0 -16
- package/dist/assets/Skills-DTXehVS7.js +0 -12
- package/dist/assets/index-C9w-dVzo.js +0 -3090
|
@@ -195,7 +195,7 @@ function computeJobBudgetMs(estimateMinutes, { factor, floorMs, ceilingMs } = {}
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
|
-
* classifyBudgetKill(res, landedCommitEvidence) → { status, reason, landedCommit } | null
|
|
198
|
+
* classifyBudgetKill(res, landedCommitEvidence, context?) → { status, reason, landedCommit } | null
|
|
199
199
|
*
|
|
200
200
|
* Pure. `res` is executeJob's resolved outcome — only fires when
|
|
201
201
|
* `res.killedByWatchdog === 'budget'` (stamped by the budget watchdog inside
|
|
@@ -212,14 +212,151 @@ function computeJobBudgetMs(estimateMinutes, { factor, floorMs, ceilingMs } = {}
|
|
|
212
212
|
* commit-guard evidence check the plain sigterm/exit paths already use, is
|
|
213
213
|
* threaded onto the row as `landedCommit` so a job that HAD already
|
|
214
214
|
* committed before overrunning is still adjudicated on its git evidence.
|
|
215
|
+
*
|
|
216
|
+
* `context` (optional) is describeBudgetKillContext's output plus an optional
|
|
217
|
+
* `commits` list ({ sha, subject }[], the run's own commits, read by the
|
|
218
|
+
* caller). Only when `context.inFinishReview` is true does the reason change:
|
|
219
|
+
* it names the review call the kill landed in, what had already landed, and
|
|
220
|
+
* which push/publish side effects had already run. Otherwise the reason is
|
|
221
|
+
* byte-identical to the context-less one.
|
|
222
|
+
*
|
|
223
|
+
* @param {any} res
|
|
224
|
+
* @param {string|null|undefined} landedCommitEvidence
|
|
225
|
+
* @param {{ inFinishReview?: boolean, reviewSkill?: string|null, sideEffects?: string[], commits?: Array<{ sha: string, subject: string }>|null }|null} [context]
|
|
215
226
|
*/
|
|
216
|
-
function classifyBudgetKill(res, landedCommitEvidence) {
|
|
227
|
+
function classifyBudgetKill(res, landedCommitEvidence, context) {
|
|
217
228
|
if (!res || res.killedByWatchdog !== 'budget') return null;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
229
|
+
const baseReason = res.budgetKillReason || `wall-clock budget exceeded (exit ${res.exitCode})`;
|
|
230
|
+
const landedCommit = landedCommitEvidence || null;
|
|
231
|
+
if (!context || context.inFinishReview !== true) {
|
|
232
|
+
return { status: 'needs_review', reason: baseReason, landedCommit };
|
|
233
|
+
}
|
|
234
|
+
// Keep the ran/budget/estimate figures: everything after the generic prefix.
|
|
235
|
+
const figures = baseReason.replace(/^wall-clock budget exceeded:?\s*/, '');
|
|
236
|
+
const skillLabel = String(context.reviewSkill || 'code-review');
|
|
237
|
+
const skillShown = skillLabel.length > REVIEW_SKILL_MAX_CHARS ? `${skillLabel.slice(0, REVIEW_SKILL_MAX_CHARS)}…` : skillLabel;
|
|
238
|
+
let reason = `wall-clock budget exceeded inside the finish-protocol review (/${skillShown} never returned)`;
|
|
239
|
+
if (figures) reason += `: ${figures}`;
|
|
240
|
+
const commits = Array.isArray(context.commits) ? context.commits.slice(0, 5) : [];
|
|
241
|
+
if (commits.length > 0) {
|
|
242
|
+
reason += `; work already landed: ${commits.map((c) => `${String(c.sha).slice(0, 7)} ${c.subject}`.trim()).join(', ')}`;
|
|
243
|
+
} else if (landedCommit) {
|
|
244
|
+
reason += `; work already landed: ${String(landedCommit).slice(0, 7)}`;
|
|
245
|
+
} else {
|
|
246
|
+
reason += '; no commit landed on the job branch';
|
|
247
|
+
}
|
|
248
|
+
const sideEffects = Array.isArray(context.sideEffects) ? context.sideEffects : [];
|
|
249
|
+
if (sideEffects.length > 0) reason += `; side effects already run: ${sideEffects.join(' | ')}`;
|
|
250
|
+
return { status: 'needs_review', reason, landedCommit };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const REVIEW_SKILL_PREFIXES = ['code-review', 'security-review'];
|
|
254
|
+
const SIDE_EFFECT_MAX = 5;
|
|
255
|
+
const SIDE_EFFECT_MAX_CHARS = 120;
|
|
256
|
+
const REVIEW_SKILL_MAX_CHARS = 80;
|
|
257
|
+
const SIDE_EFFECT_PATTERNS = ['git push', 'npm publish'];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* sideEffectSegments(command) → string[]
|
|
261
|
+
*
|
|
262
|
+
* Pure. Splits a Bash command on &&, ||, ;, | and newlines (no shell parser —
|
|
263
|
+
* a split inside a quoted string is acceptable), trims each segment and keeps
|
|
264
|
+
* the ones naming `git push` / `npm publish`, each cut to 120 chars. So a real
|
|
265
|
+
* executor's `cd /tmp/x && git add a && git commit -m y && git push origin
|
|
266
|
+
* HEAD:main` is labelled by its push, not by its leading `cd`.
|
|
267
|
+
*
|
|
268
|
+
* @param {string} command
|
|
269
|
+
* @returns {string[]}
|
|
270
|
+
*/
|
|
271
|
+
function sideEffectSegments(command) {
|
|
272
|
+
return String(command)
|
|
273
|
+
.split(/&&|\|\||;|\||\n/)
|
|
274
|
+
.map((seg) => seg.trim())
|
|
275
|
+
.filter((seg) => SIDE_EFFECT_PATTERNS.some((p) => seg.includes(p)))
|
|
276
|
+
.map((seg) => seg.slice(0, SIDE_EFFECT_MAX_CHARS));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* describeBudgetKillContext(logText) → { inFinishReview, reviewSkill, sideEffects }
|
|
281
|
+
*
|
|
282
|
+
* Pure, never throws. Parses a `claude -p --output-format stream-json` run log
|
|
283
|
+
* (or its tail — a torn first line is just skipped) and answers: was the
|
|
284
|
+
* executor's LAST top-level tool call a review Skill (/code-review,
|
|
285
|
+
* /security-review) that never got its tool_result — i.e. did the budget kill
|
|
286
|
+
* land inside the finish-protocol review? `sideEffects` lists the `git push` /
|
|
287
|
+
* `npm publish` command segments (see sideEffectSegments) of Bash calls that had already succeeded (a matching
|
|
288
|
+
* tool_result with is_error !== true), deduped, at most 5, each ≤ 120 chars.
|
|
289
|
+
* Subagent events (non-null parent_tool_use_id) never count as the last
|
|
290
|
+
* top-level tool_use.
|
|
291
|
+
*
|
|
292
|
+
* @param {string} logText
|
|
293
|
+
* @returns {{ inFinishReview: boolean, reviewSkill: string|null, sideEffects: string[] }}
|
|
294
|
+
*/
|
|
295
|
+
function describeBudgetKillContext(logText) {
|
|
296
|
+
const empty = { inFinishReview: false, reviewSkill: null, sideEffects: [] };
|
|
297
|
+
try {
|
|
298
|
+
if (typeof logText !== 'string' || !logText) return empty;
|
|
299
|
+
/** @type {any} */
|
|
300
|
+
let lastTopToolUse = null;
|
|
301
|
+
/** @type {Map<string, boolean>} tool_use_id → is_error */
|
|
302
|
+
const results = new Map();
|
|
303
|
+
// true once a tool_result answers the current lastTopToolUse
|
|
304
|
+
let answeredAfterLast = false;
|
|
305
|
+
/** @type {Array<{ id: string, command: string }>} */
|
|
306
|
+
const bashCalls = [];
|
|
307
|
+
for (const raw of logText.split('\n')) {
|
|
308
|
+
const line = raw.trim();
|
|
309
|
+
if (!line || line[0] !== '{') continue;
|
|
310
|
+
let ev;
|
|
311
|
+
try { ev = JSON.parse(line); } catch { continue; }
|
|
312
|
+
if (!ev || typeof ev !== 'object') continue;
|
|
313
|
+
const content = ev.message && Array.isArray(ev.message.content) ? ev.message.content : null;
|
|
314
|
+
if (!content) continue;
|
|
315
|
+
const topLevel = ev.parent_tool_use_id == null;
|
|
316
|
+
if (ev.type === 'assistant') {
|
|
317
|
+
for (const block of content) {
|
|
318
|
+
if (!block || block.type !== 'tool_use') continue;
|
|
319
|
+
if (block.name === 'Bash' && block.input && typeof block.input.command === 'string' && typeof block.id === 'string') {
|
|
320
|
+
bashCalls.push({ id: block.id, command: block.input.command });
|
|
321
|
+
}
|
|
322
|
+
if (topLevel) {
|
|
323
|
+
lastTopToolUse = block;
|
|
324
|
+
answeredAfterLast = false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
} else if (ev.type === 'user') {
|
|
328
|
+
for (const block of content) {
|
|
329
|
+
if (!block || block.type !== 'tool_result' || typeof block.tool_use_id !== 'string') continue;
|
|
330
|
+
results.set(block.tool_use_id, block.is_error === true);
|
|
331
|
+
if (lastTopToolUse && block.tool_use_id === lastTopToolUse.id) answeredAfterLast = true;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
let inFinishReview = false;
|
|
336
|
+
let reviewSkill = null;
|
|
337
|
+
if (lastTopToolUse && lastTopToolUse.name === 'Skill' && !answeredAfterLast) {
|
|
338
|
+
const input = lastTopToolUse.input || {};
|
|
339
|
+
const skill = typeof input.skill === 'string' ? input.skill.trim() : '';
|
|
340
|
+
if (REVIEW_SKILL_PREFIXES.some((p) => skill.startsWith(p))) {
|
|
341
|
+
inFinishReview = true;
|
|
342
|
+
const args = typeof input.args === 'string' ? input.args.trim() : '';
|
|
343
|
+
reviewSkill = args ? `${skill} ${args}` : skill;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** @type {string[]} */
|
|
347
|
+
const sideEffects = [];
|
|
348
|
+
for (const call of bashCalls) {
|
|
349
|
+
if (sideEffects.length >= SIDE_EFFECT_MAX) break;
|
|
350
|
+
if (!results.has(call.id) || results.get(call.id) === true) continue;
|
|
351
|
+
for (const seg of module.exports.sideEffectSegments(call.command)) {
|
|
352
|
+
if (sideEffects.length >= SIDE_EFFECT_MAX) break;
|
|
353
|
+
if (!sideEffects.includes(seg)) sideEffects.push(seg);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return { inFinishReview, reviewSkill, sideEffects };
|
|
357
|
+
} catch {
|
|
358
|
+
return empty;
|
|
359
|
+
}
|
|
223
360
|
}
|
|
224
361
|
|
|
225
362
|
/**
|
|
@@ -598,6 +735,8 @@ module.exports = {
|
|
|
598
735
|
findOverrunningJobs,
|
|
599
736
|
computeJobBudgetMs,
|
|
600
737
|
classifyBudgetKill,
|
|
738
|
+
describeBudgetKillContext,
|
|
739
|
+
sideEffectSegments,
|
|
601
740
|
isJobBudgetExempt,
|
|
602
741
|
shouldKillForBudget,
|
|
603
742
|
resolveBudgetKillOutcome,
|
|
@@ -518,20 +518,19 @@ function gitRangeCommits(cwd, before, after) {
|
|
|
518
518
|
* 1. Ancestry: the branch tip is an ancestor of (or equal to) HEAD, the
|
|
519
519
|
* same `mergeBase === branchHead` test as integrateBranch()'s no-op
|
|
520
520
|
* detection.
|
|
521
|
-
* 2. Content: `gitWorktree.isBranchContentLanded({ cwd, base: 'HEAD', branch })`.
|
|
521
|
+
* 2. Content: `gitWorktree.isBranchContentLanded({ cwd, base: 'HEAD', branch, sinceSha: forkSha })`.
|
|
522
522
|
* Linear landing (PRDs 2743, 2825) replays the branch onto the base, so a
|
|
523
523
|
* landed branch's own commits never become ancestors of HEAD. Proof 1
|
|
524
524
|
* alone made the reaper park a landed job as "still holds unintegrated
|
|
525
525
|
* work — never merged" (validator finding I-2). The helper also accepts
|
|
526
526
|
* patch-equivalent commits on HEAD, or a merge that would change nothing.
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
* conservative failure direction here is needs_review, never a silent merge.
|
|
527
|
+
* `forkSha` (the branch's fork point) is passed as `sinceSha`, bounding
|
|
528
|
+
* the proof to the job's own commits — a base rebased after the fork
|
|
529
|
+
* never makes the base's rewritten commits read as unlanded job work.
|
|
530
|
+
* This check itself never calls integrateBranch: it is read-only proof.
|
|
531
|
+
* The landing decision belongs to reapDeadRunningJobs, which integrates a
|
|
532
|
+
* `false` branch only when the run printed its own SCHEDULER_VERDICT: PASS
|
|
533
|
+
* line; any other outcome parks needs_review, never a silent merge.
|
|
535
534
|
*
|
|
536
535
|
* Returns:
|
|
537
536
|
* - true — branch exists and its content is already in HEAD (integrated by
|
|
@@ -543,7 +542,7 @@ function gitRangeCommits(cwd, before, after) {
|
|
|
543
542
|
* in-place run, or SM_JOB_WORKTREE_DISABLE), or `rev-parse` errored.
|
|
544
543
|
* Never throws.
|
|
545
544
|
*/
|
|
546
|
-
function isBranchAlreadyIntegrated(cwd, branch) {
|
|
545
|
+
function isBranchAlreadyIntegrated(cwd, branch, forkSha = null) {
|
|
547
546
|
return new Promise((resolve) => {
|
|
548
547
|
if (!cwd || !branch) { resolve(null); return; }
|
|
549
548
|
execFile(
|
|
@@ -558,7 +557,7 @@ function isBranchAlreadyIntegrated(cwd, branch) {
|
|
|
558
557
|
(mbErr, mbOut) => {
|
|
559
558
|
const mergeBase = mbErr ? '' : String(mbOut || '').trim();
|
|
560
559
|
if (mergeBase !== '' && mergeBase === branchHead) { resolve(true); return; }
|
|
561
|
-
gitWorktree.isBranchContentLanded({ cwd, base: 'HEAD', branch })
|
|
560
|
+
gitWorktree.isBranchContentLanded({ cwd, base: 'HEAD', branch, sinceSha: forkSha || undefined })
|
|
562
561
|
.then((landed) => resolve(landed === true), () => resolve(false));
|
|
563
562
|
},
|
|
564
563
|
);
|
|
@@ -122,6 +122,7 @@ function selectMechanicalRecoveryTarget(job, currentHeadSha = null) {
|
|
|
122
122
|
branch: jobWorktree.branchNameFor(job.slug),
|
|
123
123
|
carriedPaths: job.carriedPaths || [],
|
|
124
124
|
baseBranch: job.worktreeBaseBranch || null,
|
|
125
|
+
forkSha: job.worktreeForkSha || null,
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
|
|
@@ -187,9 +188,59 @@ const RESCAN_EXCLUDED_VERDICTS = new Set([
|
|
|
187
188
|
// Its damage IS a commit stranded on an unmerged sm-job branch — a landedCommit restates it; selectMechanicalRecoveryTarget owns the real re-merge.
|
|
188
189
|
'worktree_integration_failed',
|
|
189
190
|
// The run overran its own time/cost estimate; no transcript or git evidence can un-overrun it (selectAutoFixTargets excludes it too).
|
|
191
|
+
// Carve-out (isFinishReviewKillHealEligible): a kill inside the finish-protocol review AFTER the commit
|
|
192
|
+
// integrated left only the review + verdict undone, so a green re-run of the PRD's own gate is the proof.
|
|
190
193
|
'budget_exceeded',
|
|
191
194
|
]);
|
|
192
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Finish-review budget-kill heal (one attempt). The ONLY budget_exceeded rows
|
|
198
|
+
* any self-heal rung may touch: the kill hit inside the finish-protocol review
|
|
199
|
+
* (budgetKillPhase 'finish-review', stamped at finalize) after the run landed
|
|
200
|
+
* a commit. Everything else budget_exceeded stays excluded (above).
|
|
201
|
+
*
|
|
202
|
+
* Pure. Integration into the main checkout is only partly provable here: a
|
|
203
|
+
* row carrying an integrationFailureKind (stampIntegrationFailure — commit
|
|
204
|
+
* stranded on an unmerged sm-job branch) is refused outright; the rung in
|
|
205
|
+
* scheduler.cjs additionally requires landedCommit to be an ancestor of the
|
|
206
|
+
* main checkout's HEAD before it runs the gate.
|
|
207
|
+
*
|
|
208
|
+
* Bounded to one attempt by finishReviewHealAttemptedAt, stamped by the rung
|
|
209
|
+
* whatever the outcome (red, unrunnable, not integrated) — so a red gate never
|
|
210
|
+
* loops. Kill-switch: SM_FINISH_REVIEW_HEAL_DISABLE=1.
|
|
211
|
+
*/
|
|
212
|
+
function isFinishReviewKillHealEligible(job) {
|
|
213
|
+
if (process.env.SM_FINISH_REVIEW_HEAL_DISABLE === '1') return false;
|
|
214
|
+
if (!job || job.status !== 'needs_review') return false;
|
|
215
|
+
if (job.verifierVerdict !== 'budget_exceeded') return false;
|
|
216
|
+
if (job.budgetKillPhase !== 'finish-review') return false;
|
|
217
|
+
if (typeof job.landedCommit !== 'string' || job.landedCommit.length === 0) return false;
|
|
218
|
+
if (job.finishReviewHealAttemptedAt) return false;
|
|
219
|
+
if (job.integrationFailureKind) return false;
|
|
220
|
+
if (isCancelledJob(job) || isRefireCapped(job)) return false;
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Pure decision for the finish-review heal, from ground truth the rung
|
|
226
|
+
* computed: evidenceOk (landedCommit is git-verified evidence from THIS
|
|
227
|
+
* dispatch), integratedOk (landedCommit is an ancestor of the main
|
|
228
|
+
* checkout's HEAD), setupOk (scratch worktree's declared setup settled), the
|
|
229
|
+
* resolved gate, and runGateSequence's outcome. First failed check names the
|
|
230
|
+
* reason. Mirrors decideGateAuthority's trusted-gate rule ('ac-line-guess'
|
|
231
|
+
* never counts).
|
|
232
|
+
*/
|
|
233
|
+
function decideFinishReviewKillHeal({ evidenceOk, integratedOk, gate, setupOk, outcome } = {}) {
|
|
234
|
+
if (evidenceOk !== true) return { complete: false, reason: 'commit-not-from-this-run' };
|
|
235
|
+
if (integratedOk !== true) return { complete: false, reason: 'commit-not-integrated' };
|
|
236
|
+
const hasGate = (gate?.source === 'explicit' || gate?.source === 'ac-line')
|
|
237
|
+
&& Array.isArray(gate?.sequence) && gate.sequence.length > 0;
|
|
238
|
+
if (!hasGate) return { complete: false, reason: 'no-gate' };
|
|
239
|
+
if (setupOk !== true) return { complete: false, reason: 'setup-not-settled' };
|
|
240
|
+
if (outcome?.status !== 'green') return { complete: false, reason: outcome?.status === 'red' ? 'gate-red' : 'gate-not-runnable' };
|
|
241
|
+
return { complete: true, reason: 'gate-green' };
|
|
242
|
+
}
|
|
243
|
+
|
|
193
244
|
// Per-pass / per-row bounds on the evidence-only rung (the widened candidate
|
|
194
245
|
// set). Each scan costs one computeLooksDone: a per-cwd-deduped `git fetch`
|
|
195
246
|
// (<=~20s) + a git log. Unbounded, a backlog of N parked rows would pay N of
|
|
@@ -879,6 +930,8 @@ function selectAutoFixTargets(jobs, { fixSlugExists, resolveJobRunId = resolveRu
|
|
|
879
930
|
// auto-fix investigation or auto-retry — the run didn't fail, it simply
|
|
880
931
|
// overran its own estimate; there's no code defect to diagnose (Out of
|
|
881
932
|
// scope: "retrying or auto-resuming a budget-killed job" for this PRD).
|
|
933
|
+
// The finish-review carve-out (isFinishReviewKillHealEligible) heals via a gate
|
|
934
|
+
// re-run, never via auto-fix — so this exclusion holds for every budget_exceeded row.
|
|
882
935
|
if (job.verifierVerdict === 'budget_exceeded') return false;
|
|
883
936
|
// A stale re-run whose work already shipped (rcaReport's 'already-shipped'
|
|
884
937
|
// class) must never buy a fix-plan PRD — there is nothing to fix, and the
|
|
@@ -970,6 +1023,11 @@ function selectGateShadowTarget(jobs, headByCwd, { authorityDisabled = false, ba
|
|
|
970
1023
|
return typeof head === 'string' && head.length > 0;
|
|
971
1024
|
});
|
|
972
1025
|
|
|
1026
|
+
// Tier 0: a finish-review budget kill's one-shot heal (bounded by its own
|
|
1027
|
+
// attempt stamp, so it can win the pick at most once per row).
|
|
1028
|
+
const finishReviewHeal = eligible.find((j) => isFinishReviewKillHealEligible(j));
|
|
1029
|
+
if (finishReviewHeal) return finishReviewHeal;
|
|
1030
|
+
|
|
973
1031
|
const isStale = (j) => {
|
|
974
1032
|
const head = headByCwd.get(j.cwd);
|
|
975
1033
|
return !j.gateShadow || j.gateShadow.head !== head || j.gateShadow.definitive !== true;
|
|
@@ -1074,4 +1132,6 @@ module.exports = {
|
|
|
1074
1132
|
selectAutoFixTargets,
|
|
1075
1133
|
isEligibleForImmediateAutoFix,
|
|
1076
1134
|
selectGateShadowTarget,
|
|
1135
|
+
isFinishReviewKillHealEligible,
|
|
1136
|
+
decideFinishReviewKillHeal,
|
|
1077
1137
|
};
|