claude-code-session-manager 0.139.0 → 0.141.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/README.md +20 -4
- package/dist/assets/AppSettings-DExeJhqQ.js +2 -0
- package/dist/assets/History-DJMiuXyK.js +2 -0
- package/dist/assets/{HomeClaudeConfig-CGD2Onjv.js → HomeClaudeConfig-CTp2tkZ4.js} +2 -2
- package/dist/assets/{Panel-Csyd9HbD.js → Panel-Bf1Cf8UL.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-C-jlYpC_.js → ProjectClaudeConfig-BWPpypf9.js} +1 -1
- package/dist/assets/Scheduler-cyr61UAC.js +16 -0
- package/dist/assets/{SkillReferenceGraph-DcscPXAG.js → SkillReferenceGraph-Ba4TkX2C.js} +1 -1
- package/dist/assets/{Skills-BpGRKOcY.js → Skills-C1v91GEO.js} +26 -26
- package/dist/assets/{TiptapBody-DSU3769X.js → TiptapBody-BrcWVpiW.js} +1 -1
- package/dist/assets/{ViewTabs-C0PRZx4_.js → ViewTabs-DXhOWFG0.js} +1 -1
- package/dist/assets/{VoiceButton-D2rMurNg.js → VoiceButton-qivnDV6K.js} +1 -1
- package/dist/assets/{historyTotals-TcIQs2sh.js → historyTotals-CMCPTKqC.js} +1 -1
- package/dist/assets/index-B2TQz3nd.js +3121 -0
- package/dist/assets/{index-BCySPdtU.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +423 -426
- package/package.json +5 -2
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/skills/builder/SKILL.md +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +29 -19
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
- package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
- package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
- package/scripts/README.md +1 -0
- package/scripts/hooks/guard-tool-risk.cjs +91 -0
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
- package/scripts/ops-sweep.cjs +53 -23
- package/scripts/scheduler-mcp-server.cjs +205 -18
- package/src/main/build-info.json +4 -4
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +88 -5
- package/src/main/historyDashboard.cjs +69 -4
- package/src/main/index.cjs +56 -2
- package/src/main/ipcSchemas.cjs +122 -16
- package/src/main/lib/AGENTS.md +54 -0
- package/src/main/lib/CLAUDE.md +1 -54
- package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
- package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
- package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
- package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
- package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
- package/src/main/lib/claude/effectiveModelInfo.cjs +90 -20
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
- package/src/main/lib/claude/personaToolScope.cjs +12 -6
- package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
- package/src/main/lib/claude/runClaudeP.cjs +6 -1
- package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
- package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
- package/src/main/lib/ephemeralCwd.cjs +37 -2
- package/src/main/lib/epic/delegationReadiness.cjs +42 -9
- package/src/main/lib/epic/epicAdminRoutes.cjs +25 -5
- package/src/main/lib/epic/epicOutsideRead.cjs +118 -1
- package/src/main/lib/epic/epicOutsideState.cjs +2 -2
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/externalContract.cjs +31 -5
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +55 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +106 -11
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +47 -19
- package/src/main/lib/feedback-remote/needsYouStore.cjs +6 -2
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
- package/src/main/lib/git/branchSweep.cjs +209 -4
- package/src/main/lib/git/gitWorktree.cjs +41 -5
- package/src/main/lib/guardShims.cjs +1 -1
- package/src/main/lib/historyRollup.cjs +26 -0
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +132 -13
- package/src/main/lib/mdDocCensus.cjs +59 -78
- package/src/main/lib/mdDocRefs.cjs +71 -93
- package/src/main/lib/mdNetworkScan.cjs +245 -250
- package/src/main/lib/mdReviewRecord.cjs +22 -9
- package/src/main/lib/memoryMdNetwork.cjs +5 -12
- package/src/main/lib/opsOwnership.cjs +18 -2
- package/src/main/lib/opsRetentionSettings.cjs +28 -4
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
- package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
- package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
- package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
- package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/depSlugResolve.cjs +104 -4
- package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
- package/src/main/lib/prd/prdCreate.cjs +377 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +121 -3
- package/src/main/lib/process/loginItem.cjs +171 -0
- package/src/main/lib/process/loginItemPlan.cjs +193 -0
- package/src/main/lib/project-pages/playerBridge.cjs +4 -0
- package/src/main/lib/project-pages/videoReview.cjs +268 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
- package/src/main/lib/scheduler/cpuSample.cjs +131 -4
- package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
- package/src/main/lib/scheduler/loadGate.cjs +24 -6
- package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
- package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
- package/src/main/lib/scheduler/preflightCheck.cjs +97 -0
- package/src/main/lib/scheduler/queueStore.cjs +7 -0
- package/src/main/lib/scheduler/rcaReport.cjs +21 -1
- package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
- package/src/main/lib/scheduler/reviewNotice.cjs +39 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
- package/src/main/lib/scheduler/schedulerPaths.cjs +3 -0
- package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
- package/src/main/lib/scheduler/validationQuality.cjs +282 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
- package/src/main/lib/tasks/taskIpc.cjs +80 -0
- package/src/main/lib/tasks/taskLedger.cjs +502 -0
- package/src/main/lib/tasks/taskRun.cjs +313 -0
- package/src/main/lib/tasks/taskSwitch.cjs +120 -0
- package/src/main/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +10 -1
- package/src/main/projectPages.cjs +6 -15
- package/src/main/promptSessionEvents.cjs +9 -1
- package/src/main/queueOps.cjs +260 -3
- package/src/main/runVerify.cjs +53 -25
- package/src/main/scheduler/AGENTS.md +26 -0
- package/src/main/scheduler/CLAUDE.md +1 -26
- package/src/main/scheduler/budget.cjs +239 -9
- package/src/main/scheduler/cancelDependents.cjs +154 -0
- package/src/main/scheduler/prdParser.cjs +19 -1
- package/src/main/scheduler/reviewLadder.cjs +36 -3
- package/src/main/scheduler/starvation.cjs +89 -18
- package/src/main/scheduler.cjs +1080 -89
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +14 -1
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +10 -2
- package/src/preload/api.d.ts +364 -21
- package/src/preload/apiSurface.json +89 -10
- package/src/preload/index.cjs +23 -2
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AppSettings-CUfWY9vN.js +0 -2
- package/dist/assets/History-DDnqaLyw.js +0 -2
- package/dist/assets/Scheduler-NLs08fx7.js +0 -16
- package/dist/assets/index-C-d0DCre.js +0 -3124
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
const gitWorktree = require('./gitWorktree.cjs');
|
|
23
23
|
const { execGit: sharedExecGit } = require('./gitExec.cjs');
|
|
24
|
+
const { readJsonOr, writeJsonAtomic } = require('../util/atomicFs.cjs');
|
|
24
25
|
|
|
25
26
|
// Thin re-shape over the shared gitExec.execGit — kept so call sites below
|
|
26
27
|
// (positional `timeout`, no `-C` prefix needed) don't all need touching.
|
|
@@ -52,6 +53,152 @@ async function listCheckedOutBranches(cwd) {
|
|
|
52
53
|
|
|
53
54
|
const TERMINAL_JOB_STATUSES = new Set(['completed', 'failed', 'skipped']);
|
|
54
55
|
|
|
56
|
+
// ─── Persisted per-(cwd, branch) failure backoff (PRD 3494) ────────────────
|
|
57
|
+
//
|
|
58
|
+
// The in-memory attempted set resets on every restart, so a permanently
|
|
59
|
+
// conflicting branch was re-attempted (and re-reported as
|
|
60
|
+
// branch_sweep_conflict) at every boot forever — 17 rows across 9 projects on
|
|
61
|
+
// the 2026-11-22 reboot. The backoff state below survives restarts: each
|
|
62
|
+
// failed attempt bumps a count and pushes the next attempt out exponentially;
|
|
63
|
+
// at BRANCH_SWEEP_MAX_FAILURES (or once the owning PRD is skipped/superseded)
|
|
64
|
+
// the branch is given up on for good — never retried, never deleted, reported
|
|
65
|
+
// exactly once.
|
|
66
|
+
|
|
67
|
+
const BRANCH_SWEEP_MAX_FAILURES = 3;
|
|
68
|
+
const BRANCH_SWEEP_BACKOFF_BASE_MS = 60 * 60 * 1000; // 1 h, doubled per failure
|
|
69
|
+
// Row statuses that mean "this PRD will never run again" — a branch they own
|
|
70
|
+
// has nothing left to recover into.
|
|
71
|
+
const GIVE_UP_ROW_STATUSES = new Set(['skipped', 'cancelled', 'superseded']);
|
|
72
|
+
|
|
73
|
+
/** Empty backoff state: `{ version, branches: { [branch]: entry } }`. */
|
|
74
|
+
function emptyBackoffState() {
|
|
75
|
+
return { version: 1, branches: {} };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Coerce anything read off disk into a well-formed backoff state. */
|
|
79
|
+
function normalizeBackoffState(raw) {
|
|
80
|
+
const out = emptyBackoffState();
|
|
81
|
+
if (!raw || typeof raw !== 'object' || !raw.branches || typeof raw.branches !== 'object') return out;
|
|
82
|
+
for (const [branch, e] of Object.entries(raw.branches)) {
|
|
83
|
+
if (!e || typeof e !== 'object') continue;
|
|
84
|
+
out.branches[branch] = {
|
|
85
|
+
failures: Number.isFinite(e.failures) && e.failures > 0 ? Math.floor(e.failures) : 0,
|
|
86
|
+
lastFailureAt: Number.isFinite(e.lastFailureAt) ? e.lastFailureAt : null,
|
|
87
|
+
nextAttemptAt: Number.isFinite(e.nextAttemptAt) ? e.nextAttemptAt : null,
|
|
88
|
+
lastReason: typeof e.lastReason === 'string' ? e.lastReason : null,
|
|
89
|
+
gaveUp: e.gaveUp === true,
|
|
90
|
+
gaveUpAt: Number.isFinite(e.gaveUpAt) ? e.gaveUpAt : null,
|
|
91
|
+
gaveUpReason: typeof e.gaveUpReason === 'string' ? e.gaveUpReason : null,
|
|
92
|
+
slug: typeof e.slug === 'string' ? e.slug : null,
|
|
93
|
+
reported: e.reported === true,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Read a backoff state file; a missing/garbled file is an empty state. */
|
|
100
|
+
async function loadBranchSweepBackoff(file) {
|
|
101
|
+
return normalizeBackoffState(await readJsonOr(file, null));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Persist a backoff state file atomically. Caller owns the ops-write check. */
|
|
105
|
+
async function saveBranchSweepBackoff(file, state) {
|
|
106
|
+
await writeJsonAtomic(file, normalizeBackoffState(state));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* prdGiveUpReason(row) → 'prd-skipped' | 'prd-superseded' | null. A row whose
|
|
111
|
+
* PRD was skipped, cancelled or superseded will never run again, so its
|
|
112
|
+
* stranded branch is given up on without another merge attempt.
|
|
113
|
+
*/
|
|
114
|
+
function prdGiveUpReason(row) {
|
|
115
|
+
if (!row || typeof row !== 'object') return null;
|
|
116
|
+
if (row.supersededBy) return 'prd-superseded';
|
|
117
|
+
if (!GIVE_UP_ROW_STATUSES.has(row.status)) return null;
|
|
118
|
+
return row.status === 'skipped' ? 'prd-skipped' : 'prd-superseded';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* decideBranchRetry({ entry, row, now }) → { action, reason } — the pure
|
|
123
|
+
* give-up decision. action is one of:
|
|
124
|
+
* 'given-up' — already given up in an earlier pass (never retried)
|
|
125
|
+
* 'give-up' — give up now without attempting (reason = prd-skipped/superseded,
|
|
126
|
+
* or max-failures for a legacy entry already at the cap)
|
|
127
|
+
* 'backoff' — failed before; next attempt not yet due
|
|
128
|
+
* 'attempt' — try one bounded integration
|
|
129
|
+
*/
|
|
130
|
+
function decideBranchRetry({ entry, row, now }) {
|
|
131
|
+
if (entry && entry.gaveUp) return { action: 'given-up', reason: entry.gaveUpReason || null };
|
|
132
|
+
const prdReason = prdGiveUpReason(row);
|
|
133
|
+
if (prdReason) return { action: 'give-up', reason: prdReason };
|
|
134
|
+
if (entry && entry.failures >= BRANCH_SWEEP_MAX_FAILURES) return { action: 'give-up', reason: 'max-failures' };
|
|
135
|
+
if (entry && Number.isFinite(entry.nextAttemptAt) && now < entry.nextAttemptAt) {
|
|
136
|
+
return { action: 'backoff', reason: null };
|
|
137
|
+
}
|
|
138
|
+
return { action: 'attempt', reason: null };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* recordBranchFailure(entry, { now, reason, slug }) → new entry with the
|
|
143
|
+
* failure counted, the next attempt pushed out by base·2^(failures-1), and
|
|
144
|
+
* gaveUp set once the count reaches BRANCH_SWEEP_MAX_FAILURES.
|
|
145
|
+
*/
|
|
146
|
+
function recordBranchFailure(entry, { now, reason = null, slug = null } = {}) {
|
|
147
|
+
const failures = ((entry && entry.failures) || 0) + 1;
|
|
148
|
+
const gaveUp = failures >= BRANCH_SWEEP_MAX_FAILURES;
|
|
149
|
+
return {
|
|
150
|
+
...emptyEntry(),
|
|
151
|
+
...(entry || {}),
|
|
152
|
+
failures,
|
|
153
|
+
lastFailureAt: now,
|
|
154
|
+
lastReason: reason,
|
|
155
|
+
nextAttemptAt: gaveUp ? null : now + BRANCH_SWEEP_BACKOFF_BASE_MS * 2 ** (failures - 1),
|
|
156
|
+
slug: slug || (entry && entry.slug) || null,
|
|
157
|
+
gaveUp,
|
|
158
|
+
gaveUpAt: gaveUp ? now : null,
|
|
159
|
+
gaveUpReason: gaveUp ? 'max-failures' : null,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function emptyEntry() {
|
|
164
|
+
return {
|
|
165
|
+
failures: 0, lastFailureAt: null, nextAttemptAt: null, lastReason: null,
|
|
166
|
+
gaveUp: false, gaveUpAt: null, gaveUpReason: null, slug: null, reported: false,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Mark an entry given up (without counting a failure). */
|
|
171
|
+
function markGaveUp(entry, { now, reason, slug = null }) {
|
|
172
|
+
return {
|
|
173
|
+
...emptyEntry(), ...(entry || {}),
|
|
174
|
+
nextAttemptAt: null, gaveUp: true, gaveUpAt: now, gaveUpReason: reason,
|
|
175
|
+
slug: slug || (entry && entry.slug) || null,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* takeUnreportedGiveUps(state) → [{ branch, slug, reason, failures }] for every
|
|
181
|
+
* given-up branch not yet reported, flipping `reported` so the same branch is
|
|
182
|
+
* never reported again (across boots, once the state is saved).
|
|
183
|
+
*/
|
|
184
|
+
function takeUnreportedGiveUps(state) {
|
|
185
|
+
const out = [];
|
|
186
|
+
for (const [branch, e] of Object.entries((state && state.branches) || {})) {
|
|
187
|
+
if (!e || !e.gaveUp || e.reported) continue;
|
|
188
|
+
e.reported = true;
|
|
189
|
+
out.push({ branch, slug: e.slug || null, reason: e.gaveUpReason || null, failures: e.failures || 0 });
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** listGivenUpBranches(state) → every given-up branch (reported or not), sorted. */
|
|
195
|
+
function listGivenUpBranches(state) {
|
|
196
|
+
return Object.entries((state && state.branches) || {})
|
|
197
|
+
.filter(([, e]) => e && e.gaveUp)
|
|
198
|
+
.map(([branch, e]) => ({ branch, slug: e.slug || null, reason: e.gaveUpReason || null, failures: e.failures || 0 }))
|
|
199
|
+
.sort((a, b) => a.branch.localeCompare(b.branch));
|
|
200
|
+
}
|
|
201
|
+
|
|
55
202
|
/**
|
|
56
203
|
* sweepStrandedJobBranches({ cwd, jobs, attemptedBranches }) → { results }
|
|
57
204
|
*
|
|
@@ -70,16 +217,32 @@ const TERMINAL_JOB_STATUSES = new Set(['completed', 'failed', 'skipped']);
|
|
|
70
217
|
* 'integrated' — merged into HEAD this pass (`integration` attached)
|
|
71
218
|
* 'conflict' — one bounded integrateBranch attempt failed (`integration` attached)
|
|
72
219
|
*
|
|
220
|
+
* 'skip-backoff' — failed before; its next attempt is not due yet (backoff only)
|
|
221
|
+
* 'skip-gave-up' — given up in an earlier pass; never retried (backoff only)
|
|
222
|
+
* 'gave-up' — given up this pass without an attempt: PRD skipped/superseded (backoff only)
|
|
223
|
+
*
|
|
224
|
+
* `backoff` (optional) = `{ state, now }`: a mutable persisted backoff state
|
|
225
|
+
* (see loadBranchSweepBackoff). When given, the sweep consults
|
|
226
|
+
* decideBranchRetry before each attempt and records each conflict into it
|
|
227
|
+
* (`gaveUp: true` on the conflict result that hits the cap); a success clears
|
|
228
|
+
* the branch's entry. `changed` in the return value says whether the caller
|
|
229
|
+
* must persist the state. Branches are never deleted either way.
|
|
230
|
+
*
|
|
73
231
|
* SM_BRANCH_SWEEP_DISABLE=1 restores today's behaviour exactly (no-op),
|
|
74
232
|
* mirroring SM_RESUME_RECOVERY_DISABLE.
|
|
75
233
|
*/
|
|
76
|
-
async function sweepStrandedJobBranches({ cwd, jobs, attemptedBranches }) {
|
|
234
|
+
async function sweepStrandedJobBranches({ cwd, jobs, attemptedBranches, backoff }) {
|
|
77
235
|
if (process.env.SM_BRANCH_SWEEP_DISABLE === '1') return { results: [] };
|
|
78
236
|
if (!cwd || !(await gitWorktree.isGitRepo(cwd))) return { results: [] };
|
|
79
237
|
|
|
80
238
|
const attempted = attemptedBranches instanceof Set ? attemptedBranches : new Set();
|
|
239
|
+
const bo = backoff && backoff.state && typeof backoff.state === 'object'
|
|
240
|
+
? { state: backoff.state, now: Number.isFinite(backoff.now) ? backoff.now : Date.now() }
|
|
241
|
+
: null;
|
|
242
|
+
if (bo && (!bo.state.branches || typeof bo.state.branches !== 'object')) bo.state.branches = {};
|
|
243
|
+
let changed = false;
|
|
81
244
|
const branches = await listSmJobBranches(cwd);
|
|
82
|
-
if (!branches.length) return { results: [] };
|
|
245
|
+
if (!branches.length) return { results: [], changed: false };
|
|
83
246
|
const checkedOut = new Set(await listCheckedOutBranches(cwd));
|
|
84
247
|
const jobsBySlug = new Map((Array.isArray(jobs) ? jobs : []).map((j) => [j.slug, j]));
|
|
85
248
|
|
|
@@ -112,6 +275,23 @@ async function sweepStrandedJobBranches({ cwd, jobs, attemptedBranches }) {
|
|
|
112
275
|
results.push({ branch, slug, action: 'skip-already-attempted' });
|
|
113
276
|
continue;
|
|
114
277
|
}
|
|
278
|
+
if (bo) {
|
|
279
|
+
const decision = decideBranchRetry({ entry: bo.state.branches[branch], row, now: bo.now });
|
|
280
|
+
if (decision.action === 'given-up') {
|
|
281
|
+
results.push({ branch, slug, action: 'skip-gave-up', reason: decision.reason });
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (decision.action === 'give-up') {
|
|
285
|
+
bo.state.branches[branch] = markGaveUp(bo.state.branches[branch], { now: bo.now, reason: decision.reason, slug });
|
|
286
|
+
changed = true;
|
|
287
|
+
results.push({ branch, slug, action: 'gave-up', reason: decision.reason });
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (decision.action === 'backoff') {
|
|
291
|
+
results.push({ branch, slug, action: 'skip-backoff', nextAttemptAt: bo.state.branches[branch].nextAttemptAt });
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
115
295
|
attempted.add(attemptKey);
|
|
116
296
|
// baseBranch: read off the job row when one still exists (the crash-between-
|
|
117
297
|
// commit-and-integrate case this sweep exists for) so integration targets the
|
|
@@ -122,12 +302,37 @@ async function sweepStrandedJobBranches({ cwd, jobs, attemptedBranches }) {
|
|
|
122
302
|
const integration = await gitWorktree.integrateJobBranch({
|
|
123
303
|
cwd, branch, slug: slug || branch, baseBranch: (row && row.worktreeBaseBranch) || null, forkSha,
|
|
124
304
|
});
|
|
125
|
-
|
|
305
|
+
if (!integration.ok) {
|
|
306
|
+
if (bo) {
|
|
307
|
+
const entry = recordBranchFailure(bo.state.branches[branch], { now: bo.now, reason: integration.reason || null, slug });
|
|
308
|
+
bo.state.branches[branch] = entry;
|
|
309
|
+
changed = true;
|
|
310
|
+
results.push({ branch, slug, action: 'conflict', integration, failures: entry.failures, gaveUp: entry.gaveUp });
|
|
311
|
+
} else {
|
|
312
|
+
results.push({ branch, slug, action: 'conflict', integration });
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (bo && bo.state.branches[branch]) {
|
|
317
|
+
delete bo.state.branches[branch];
|
|
318
|
+
changed = true;
|
|
319
|
+
}
|
|
320
|
+
results.push({ branch, slug, action: 'integrated', integration });
|
|
126
321
|
}
|
|
127
|
-
return { results };
|
|
322
|
+
return { results, changed };
|
|
128
323
|
}
|
|
129
324
|
|
|
130
325
|
module.exports = {
|
|
326
|
+
BRANCH_SWEEP_MAX_FAILURES,
|
|
327
|
+
BRANCH_SWEEP_BACKOFF_BASE_MS,
|
|
328
|
+
emptyBackoffState,
|
|
329
|
+
loadBranchSweepBackoff,
|
|
330
|
+
saveBranchSweepBackoff,
|
|
331
|
+
prdGiveUpReason,
|
|
332
|
+
decideBranchRetry,
|
|
333
|
+
recordBranchFailure,
|
|
334
|
+
takeUnreportedGiveUps,
|
|
335
|
+
listGivenUpBranches,
|
|
131
336
|
listSmJobBranches,
|
|
132
337
|
listCheckedOutBranches,
|
|
133
338
|
sweepStrandedJobBranches,
|
|
@@ -1085,6 +1085,20 @@ async function pathsIdenticalToBranch({ cwd, branch, paths }) {
|
|
|
1085
1085
|
return true;
|
|
1086
1086
|
}
|
|
1087
1087
|
|
|
1088
|
+
/**
|
|
1089
|
+
* Drops namespace READMEs whose on-disk bytes equal the branch blob — deleting
|
|
1090
|
+
* and re-checking-out identical bytes loses nothing (handled by the
|
|
1091
|
+
* identical-duplicates retry). Anything else is kept (fail closed).
|
|
1092
|
+
*/
|
|
1093
|
+
async function dropIdenticalNamespaceReadmes({ cwd, branch, paths }) {
|
|
1094
|
+
const keep = [];
|
|
1095
|
+
for (const p of paths) {
|
|
1096
|
+
if (isNamespaceReadme(p) && (await pathsIdenticalToBranch({ cwd, branch, paths: [p] }))) continue;
|
|
1097
|
+
keep.push(p);
|
|
1098
|
+
}
|
|
1099
|
+
return keep;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1088
1102
|
/**
|
|
1089
1103
|
* Returns the entries of `paths` whose bytes in `dir` still equal the bytes in
|
|
1090
1104
|
* `cwd` (carried-but-untouched), plus entries absent from both (a carried
|
|
@@ -1797,7 +1811,7 @@ async function integrateBranchInCheckout({ cwd, branch, carriedPaths, forkSha, m
|
|
|
1797
1811
|
return { ok: false, reason: `linear landing failed: ${ffText}`, failureKind: 'other', baseHeadSha: headSha };
|
|
1798
1812
|
}
|
|
1799
1813
|
const allPaths = [...blocking.tracked, ...blocking.untracked];
|
|
1800
|
-
const ignoredBlock = await filterIgnoredPaths({ cwd, paths: allPaths });
|
|
1814
|
+
const ignoredBlock = await dropIdenticalNamespaceReadmes({ cwd, branch: r.tipSha, paths: await filterIgnoredPaths({ cwd, paths: allPaths }) });
|
|
1801
1815
|
if (ignoredBlock.length) {
|
|
1802
1816
|
return {
|
|
1803
1817
|
ok: false,
|
|
@@ -1852,7 +1866,7 @@ async function integrateBranchInCheckout({ cwd, branch, carriedPaths, forkSha, m
|
|
|
1852
1866
|
const blocking = parseBlockingMergePaths(stderrText);
|
|
1853
1867
|
if (blocking) {
|
|
1854
1868
|
const allPaths = [...blocking.tracked, ...blocking.untracked];
|
|
1855
|
-
const ignoredBlock = await filterIgnoredPaths({ cwd, paths: allPaths });
|
|
1869
|
+
const ignoredBlock = await dropIdenticalNamespaceReadmes({ cwd, branch, paths: await filterIgnoredPaths({ cwd, paths: allPaths }) });
|
|
1856
1870
|
if (ignoredBlock.length) {
|
|
1857
1871
|
return {
|
|
1858
1872
|
ok: false,
|
|
@@ -1946,6 +1960,16 @@ async function filterIgnoredPaths({ cwd, paths }) {
|
|
|
1946
1960
|
}
|
|
1947
1961
|
}
|
|
1948
1962
|
|
|
1963
|
+
/**
|
|
1964
|
+
* True exactly for `${OPS_ROOT_DIR}/<ns>/README.md` with ns in RUNTIME_NAMESPACES
|
|
1965
|
+
* (top level only) — the tracked storage-layout contract of a runtime folder,
|
|
1966
|
+
* never runtime state. Mirrors lib/git/runtimeStateUntrack.cjs.
|
|
1967
|
+
* @param {string} p repo-relative posix path
|
|
1968
|
+
*/
|
|
1969
|
+
function isNamespaceReadme(p) {
|
|
1970
|
+
return RUNTIME_NAMESPACES.some((ns) => p === `${OPS_ROOT_DIR}/${ns}/README.md`);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1949
1973
|
/**
|
|
1950
1974
|
* Paths the branch changed since the merge base that are git-ignored AND
|
|
1951
1975
|
* present on disk in `cwd` — the live files a merge would overwrite (git's
|
|
@@ -1964,7 +1988,18 @@ async function findIgnoredLivePaths({ cwd, branch, mergeBase }) {
|
|
|
1964
1988
|
const ignored = await filterIgnoredPaths({ cwd, paths: changed });
|
|
1965
1989
|
const live = [];
|
|
1966
1990
|
for (const p of ignored) {
|
|
1967
|
-
try { await fsp.lstat(path.join(cwd, p));
|
|
1991
|
+
try { await fsp.lstat(path.join(cwd, p)); } catch { continue; /* absent — safe */ }
|
|
1992
|
+
if (isNamespaceReadme(p)) {
|
|
1993
|
+
// Overwriting with identical bytes loses nothing; any doubt keeps it (fail closed).
|
|
1994
|
+
try {
|
|
1995
|
+
const [onDisk, inBranch] = await Promise.all([
|
|
1996
|
+
execGit(['hash-object', '--', path.join(cwd, p)], { cwd, timeout: 15_000 }),
|
|
1997
|
+
execGit(['rev-parse', `${branch}:${p}`], { cwd, timeout: 15_000 }),
|
|
1998
|
+
]);
|
|
1999
|
+
if (onDisk.trim() && onDisk.trim() === inBranch.trim()) continue;
|
|
2000
|
+
} catch { /* keep */ }
|
|
2001
|
+
}
|
|
2002
|
+
live.push(p);
|
|
1968
2003
|
}
|
|
1969
2004
|
return live;
|
|
1970
2005
|
}
|
|
@@ -1974,7 +2009,8 @@ async function findIgnoredLivePaths({ cwd, branch, mergeBase }) {
|
|
|
1974
2009
|
* (`session-manager-operations/<ns>/`, ns from RUNTIME_NAMESPACES — state
|
|
1975
2010
|
* that must never be committed) AND that are git-ignored in `cwd`, i.e. a
|
|
1976
2011
|
* force-added runtime file. Modified/deleted paths and deliberately
|
|
1977
|
-
* un-ignored ones are never returned
|
|
2012
|
+
* un-ignored ones are never returned; neither is a top-level namespace
|
|
2013
|
+
* README.md — the tracked layout contract (see runtimeStateUntrack.cjs). A diff error returns [].
|
|
1978
2014
|
* @param {{cwd: string, branch: string, mergeBase: string}} a
|
|
1979
2015
|
* @returns {Promise<string[]>}
|
|
1980
2016
|
*/
|
|
@@ -1986,7 +2022,7 @@ async function findRuntimeStateAdds({ cwd, branch, mergeBase }) {
|
|
|
1986
2022
|
['diff', '--name-only', '-z', '--diff-filter=A', `${mergeBase || 'HEAD'}..${branch}`, '--', ...pathspecs],
|
|
1987
2023
|
{ cwd, timeout: 15_000 },
|
|
1988
2024
|
);
|
|
1989
|
-
added = out.split('\0').filter(Boolean);
|
|
2025
|
+
added = out.split('\0').filter(Boolean).filter((p) => !isNamespaceReadme(p));
|
|
1990
2026
|
} catch {
|
|
1991
2027
|
return [];
|
|
1992
2028
|
}
|
|
@@ -42,7 +42,7 @@ const { writeJson, writeTextAtomic, addAllowedRoot } = require('../config.cjs');
|
|
|
42
42
|
// delegationReadiness.cjs's *_GUARD_SCRIPT constants use.
|
|
43
43
|
const APP_ROOT = path.resolve(__dirname, '..', '..', '..');
|
|
44
44
|
|
|
45
|
-
const GUARD_NAMES = ['guard-prd-writes.cjs', 'guard-destructive-git.cjs', 'guard-inline-implementation.cjs', 'guard-self-schedule.cjs'];
|
|
45
|
+
const GUARD_NAMES = ['guard-prd-writes.cjs', 'guard-destructive-git.cjs', 'guard-inline-implementation.cjs', 'guard-self-schedule.cjs', 'guard-tool-risk.cjs'];
|
|
46
46
|
|
|
47
47
|
function hooksDir(homeDir = os.homedir()) {
|
|
48
48
|
return path.join(homeDir, '.claude', 'session-manager', 'hooks');
|
|
@@ -122,6 +122,30 @@ function legacyFinalizedDates(mergedMap) {
|
|
|
122
122
|
return dates.sort();
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Newest `cycleStartedAt` among finalized markers written at ROLLUP_VERSION
|
|
127
|
+
* (older-version markers and markers without the field are ignored), or null.
|
|
128
|
+
* finalizeClosedDays() derives its "skip unchanged folders" threshold from it,
|
|
129
|
+
* so null — first run, missing rollup, version change — means a full pass.
|
|
130
|
+
*/
|
|
131
|
+
function newestFinalizedCycleStart(mergedMap) {
|
|
132
|
+
let newest = null;
|
|
133
|
+
for (const bucket of mergedMap.values()) {
|
|
134
|
+
if (bucket.projectDir !== FINALIZED_PROJECT_ID || bucket.modelId !== FINALIZED_MODEL_ID) continue;
|
|
135
|
+
if (!bucket.finalizedAt || (bucket.v ?? 1) !== ROLLUP_VERSION) continue;
|
|
136
|
+
if (typeof bucket.cycleStartedAt !== 'number' || !Number.isFinite(bucket.cycleStartedAt)) continue;
|
|
137
|
+
if (newest === null || bucket.cycleStartedAt > newest) newest = bucket.cycleStartedAt;
|
|
138
|
+
}
|
|
139
|
+
return newest;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** newestFinalizedCycleStart() over the whole rollup file on disk. */
|
|
143
|
+
async function readNewestFinalizedCycleStart() {
|
|
144
|
+
const { exists, text } = await config.readText(historyRollupPath());
|
|
145
|
+
if (!exists || !text) return null;
|
|
146
|
+
return newestFinalizedCycleStart(mergeRollupLines(text.split('\n')));
|
|
147
|
+
}
|
|
148
|
+
|
|
125
149
|
/**
|
|
126
150
|
* Append bucket entries (append-only) to the rollup file, then compact
|
|
127
151
|
* (dedupe + rewrite) if the file has grown past COMPACT_THRESHOLD_BYTES.
|
|
@@ -169,6 +193,8 @@ module.exports = {
|
|
|
169
193
|
readRollup,
|
|
170
194
|
isDateFinalized,
|
|
171
195
|
legacyFinalizedDates,
|
|
196
|
+
newestFinalizedCycleStart,
|
|
197
|
+
readNewestFinalizedCycleStart,
|
|
172
198
|
appendRollupDays,
|
|
173
199
|
compact,
|
|
174
200
|
};
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* the target and the home directory are resolved via realpath, and the
|
|
6
6
|
* boundary is either exact equality or a path-separator boundary.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Containment exports, two policies (plus assertNotSensitiveWrite, the
|
|
9
|
+
* write-side denylist):
|
|
9
10
|
* assertInsideHome(p) → { realPath } — throws on failure
|
|
10
11
|
* checkInsideHome(p) → { ok, realPath } | { ok, error } — never throws
|
|
11
12
|
*
|
|
@@ -170,7 +171,32 @@ function assertInsideHomeOrRoots(p, roots = [], deps = {}) {
|
|
|
170
171
|
return { realPath: r.realPath };
|
|
171
172
|
}
|
|
172
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Write-side denylist — the ONE copy of the rule (files:* mutations and
|
|
176
|
+
* config:write-text both call it). Pure path logic; no fs touched. Pass an
|
|
177
|
+
* already-resolved real path. Throws on a denied path, returns undefined
|
|
178
|
+
* otherwise.
|
|
179
|
+
*
|
|
180
|
+
* Defense-in-depth: a renderer compromise could otherwise write credential or
|
|
181
|
+
* code-execution-persistence material. Shell rc files are deliberately NOT
|
|
182
|
+
* blocked; developers legitimately edit those.
|
|
183
|
+
*/
|
|
184
|
+
function assertNotSensitiveWrite(realAbs, home = os.homedir()) {
|
|
185
|
+
if (path.basename(realAbs) === '.credentials.json') {
|
|
186
|
+
throw new Error('Write to .credentials.json denied');
|
|
187
|
+
}
|
|
188
|
+
const rel = path.relative(home, realAbs);
|
|
189
|
+
if (rel === '.ssh' || rel.startsWith('.ssh' + path.sep)) {
|
|
190
|
+
throw new Error('Write inside ~/.ssh denied');
|
|
191
|
+
}
|
|
192
|
+
if (rel.startsWith(path.join('.config', 'autostart') + path.sep)) {
|
|
193
|
+
throw new Error('Write to ~/.config/autostart denied');
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
173
198
|
module.exports = {
|
|
199
|
+
assertNotSensitiveWrite,
|
|
174
200
|
assertInsideHome,
|
|
175
201
|
checkInsideHome,
|
|
176
202
|
assertInsideHomeOrRoots,
|