claude-code-session-manager 0.143.0 → 0.145.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 +3 -1
- package/dist/assets/AppSettings-BR5b6oof.js +2 -0
- package/dist/assets/{History-DTttbvPb.js → History-B4U0mCdK.js} +2 -2
- package/dist/assets/HomeClaudeConfig-DQqG7lFE.js +5 -0
- package/dist/assets/{Panel-B_D4Bg7L.js → Panel-CwsOJ0nI.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-BzRowu8x.js +26 -0
- package/dist/assets/Scheduler-dr7CNOcL.js +16 -0
- package/dist/assets/{SkillReferenceGraph-D1b2aiol.js → SkillReferenceGraph-CroBPY4C.js} +1 -1
- package/dist/assets/{Skills-cfV7sgk6.js → Skills-BiW2lCnD.js} +23 -23
- package/dist/assets/{TiptapBody-DVXtEIVy.js → TiptapBody-CYTkQiva.js} +27 -27
- package/dist/assets/{Toggle-CYajnSdx.js → Toggle-WFBYo8JI.js} +1 -1
- package/dist/assets/{VoiceButton-DJ4gGRuE.js → VoiceButton-DZu8dTpO.js} +1 -1
- package/dist/assets/{historyTotals-D3MoHY2U.js → historyTotals-B7KeXLSE.js} +1 -1
- package/dist/assets/{index-DVHIHoJf.css → index-BJ5TJvmz.css} +1 -1
- package/dist/assets/{index-CdTppjKR.js → index-hXRNm0UJ.js} +698 -697
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +442 -439
- package/package.json +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +25 -19
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +16 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/weekly-consolidation.md +91 -0
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +9 -6
- package/scripts/README.md +1 -1
- package/scripts/scheduler-mcp-server.cjs +77 -0
- package/src/main/adminRouteRegistry.cjs +6 -0
- package/src/main/agentLibrary.cjs +60 -11
- package/src/main/agentsIpc.cjs +19 -0
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +139 -0
- package/src/main/config.cjs +12 -0
- package/src/main/health.cjs +59 -17
- package/src/main/index.cjs +6 -2
- package/src/main/ipcSchemas.cjs +55 -1
- package/src/main/lib/claude/agentArmory.cjs +128 -0
- package/src/main/lib/claude/agentModelResolve.cjs +3 -2
- package/src/main/lib/claude/agentSnapshot.cjs +24 -3
- package/src/main/lib/claude/builtinTools.cjs +110 -0
- package/src/main/lib/claude/environmentProfiles.cjs +1 -1
- package/src/main/lib/claude/headlessMcpServers.cjs +138 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +8 -2
- package/src/main/lib/claude/personaToolScope.cjs +100 -14
- package/src/main/lib/demo-video-kit/resumableRun.cjs +21 -14
- package/src/main/lib/demo-video-kit/seedKit.cjs +2 -2
- package/src/main/lib/epic/epicDepsSync.cjs +66 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +74 -2
- package/src/main/lib/epic/epicSettle.cjs +48 -4
- package/src/main/lib/epic/epicSpawnPlan.cjs +3 -1
- package/src/main/lib/epic/epicValidationHook.cjs +9 -1
- package/src/main/lib/epic/planReviewInput.cjs +125 -0
- package/src/main/lib/epic/restorableSessions.cjs +1 -0
- package/src/main/lib/epic/scriptStartedBy.cjs +86 -0
- package/src/main/lib/externalContract.cjs +12 -0
- package/src/main/lib/feedback-remote/createdProjects.cjs +291 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +108 -14
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +5 -1
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +24 -3
- package/src/main/lib/feedback-remote/pendingReplies.cjs +8 -4
- package/src/main/lib/feedback-remote/projectCreate.cjs +415 -0
- package/src/main/lib/feedback-remote/replyClaims.cjs +15 -6
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +35 -4
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +43 -2
- package/src/main/lib/feedback-remote/servicePairLocalRoutes.cjs +91 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +95 -7
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +104 -1
- package/src/main/lib/git/gitWorktree.cjs +1 -1
- package/src/main/lib/git/worktreeDeps.cjs +9 -3
- package/src/main/lib/mcpToolCatalog.cjs +47 -7
- package/src/main/lib/mcpToolsProbe.cjs +19 -2
- package/src/main/lib/opsOwnership.cjs +2 -0
- package/src/main/lib/packs/packCatalog.cjs +98 -5
- package/src/main/lib/persona-macro/agentPersonaSchema.cjs +6 -0
- package/src/main/lib/persona-macro/builtinMacros.cjs +6 -4
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +9 -0
- package/src/main/lib/persona-macro/personaLoadout.cjs +58 -0
- package/src/main/lib/persona-macro/personaMerge.cjs +11 -3
- package/src/main/lib/persona-macro/personaUpgrade.cjs +96 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +1 -1
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +94 -0
- package/src/main/lib/prd/prdCreate.cjs +49 -5
- package/src/main/lib/prd/prdFrontmatter.cjs +5 -2
- package/src/main/lib/prd/prdMcpReachWarnings.cjs +46 -0
- package/src/main/lib/prd/prdSandboxWarnings.cjs +49 -0
- package/src/main/lib/process/peerChatSession.cjs +165 -0
- package/src/main/lib/project-pages/videoScriptPress.cjs +6 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +24 -4
- package/src/main/lib/promptSessionSchema.cjs +2 -0
- package/src/main/lib/scheduler/baselineGate.cjs +31 -2
- package/src/main/lib/scheduler/planRecordHarvest.cjs +104 -12
- package/src/main/lib/scheduler/planReleaseRoute.cjs +110 -0
- package/src/main/lib/scheduler/planReviewSchema.cjs +182 -0
- package/src/main/lib/scheduler/planReviewStats.cjs +63 -0
- package/src/main/lib/scheduler/planReviewStore.cjs +150 -0
- package/src/main/lib/scheduler/reviewNotice.cjs +3 -1
- package/src/main/lib/scheduler/sandboxEnvironmentLimit.cjs +141 -0
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
- package/src/main/lib/scheduler/upgradeDrain.cjs +32 -5
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +12 -2
- package/src/main/lib/tasks/memoryConsolidation.cjs +118 -37
- package/src/main/lib/tasks/taskAdminRoutes.cjs +26 -14
- package/src/main/lib/tasks/taskRun.cjs +3 -1
- package/src/main/lib/tasks/weeklyConsolidationInputs.cjs +298 -0
- package/src/main/projectPages.cjs +22 -14
- package/src/main/pty.cjs +3 -0
- package/src/main/runVerify.cjs +80 -5
- package/src/main/scheduler/gitTreeGuard.cjs +6 -0
- package/src/main/scheduler/planReviewHold.cjs +146 -0
- package/src/main/scheduler/prdParser.cjs +1 -0
- package/src/main/scheduler/prdPaths.cjs +10 -1
- package/src/main/scheduler/reviewLadder.cjs +2 -0
- package/src/main/scheduler/utilizationHold.cjs +7 -2
- package/src/main/scheduler.cjs +692 -86
- package/src/main/seedAgentPersonas.cjs +11 -6
- package/src/main/seedStatus.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +17 -2
- package/src/main/webRemote.cjs +69 -7
- package/src/preload/api.d.ts +79 -1
- package/src/preload/apiSurface.json +39 -0
- package/src/preload/index.cjs +11 -0
- package/src/seed/agents/architect.md +28 -43
- package/src/seed/agents/dev-lead.md +3 -1
- package/src/seed/agents/md-network-curator.md +27 -0
- package/src/seed/agents/plan-reviewer.md +47 -0
- package/src/seed/agents/validator.md +2 -1
- package/dist/assets/AppSettings-BO4jDVGO.js +0 -2
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +0 -3
- package/dist/assets/ProjectClaudeConfig-DPnDJKcr.js +0 -26
- package/dist/assets/Scheduler-CNLjn90m.js +0 -16
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* planReviewStore.cjs — read/write `plan-records/<epic>/<validate-slug>.plan-review.json`:
|
|
5
|
+
* the independent plan review(s), the round count, and the release record.
|
|
6
|
+
* Writes go through opsPath + writeJsonAtomic as the plan-records namespace's
|
|
7
|
+
* owner ('scheduler'). Unsafe ids/slugs are refused before any path is built.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const { opsPath, assertOpsWrite } = require('../opsOwnership.cjs');
|
|
12
|
+
const { writeJsonAtomic } = require('../util/atomicFs.cjs');
|
|
13
|
+
const { EPIC_ID_RE } = require('./planRecordHarvest.cjs');
|
|
14
|
+
|
|
15
|
+
const NAMESPACE = 'plan-records';
|
|
16
|
+
const WRITER = 'scheduler';
|
|
17
|
+
const SUFFIX = '.plan-review.json';
|
|
18
|
+
const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
19
|
+
const RELEASE_BY = ['planner', 'auto', 'timeout'];
|
|
20
|
+
|
|
21
|
+
function safeIds(epicId, validateSlug) {
|
|
22
|
+
return typeof epicId === 'string' && EPIC_ID_RE.test(epicId)
|
|
23
|
+
&& typeof validateSlug === 'string' && SLUG_RE.test(validateSlug)
|
|
24
|
+
&& !validateSlug.includes('..');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function assertSafe(epicId, validateSlug) {
|
|
28
|
+
if (!safeIds(epicId, validateSlug)) {
|
|
29
|
+
throw new Error('planReviewStore: unsafe epicId or validateSlug');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Absolute record path; throws on an unsafe epicId/slug. */
|
|
34
|
+
function planReviewPath(cwd, epicId, validateSlug) {
|
|
35
|
+
assertSafe(epicId, validateSlug);
|
|
36
|
+
return opsPath(cwd, NAMESPACE, epicId, `${validateSlug}${SUFFIX}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readFile(file) {
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
42
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The record, or null when missing, malformed, or the ids are unsafe. */
|
|
49
|
+
function readPlanReview(cwd, epicId, validateSlug) {
|
|
50
|
+
if (!safeIds(epicId, validateSlug)) return null;
|
|
51
|
+
return readFile(planReviewPath(cwd, epicId, validateSlug));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function writeRecord(cwd, record) {
|
|
55
|
+
const file = planReviewPath(cwd, record.epicId, record.validateSlug);
|
|
56
|
+
assertOpsWrite(file, WRITER);
|
|
57
|
+
await writeJsonAtomic(file, record);
|
|
58
|
+
return file;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Append one review round; the record's `round` becomes the saved round. */
|
|
62
|
+
async function savePlanReviewResult({
|
|
63
|
+
cwd, epicId, validateSlug, round, reviewer, runId, model, review,
|
|
64
|
+
} = {}) {
|
|
65
|
+
assertSafe(epicId, validateSlug);
|
|
66
|
+
const prior = readPlanReview(cwd, epicId, validateSlug);
|
|
67
|
+
const reviews = prior && Array.isArray(prior.reviews) ? prior.reviews.slice() : [];
|
|
68
|
+
const n = Number.isFinite(round) ? round : reviews.length + 1;
|
|
69
|
+
reviews.push({ round: n, at: new Date().toISOString(), reviewer, runId, model, review });
|
|
70
|
+
const record = {
|
|
71
|
+
...(prior || {}),
|
|
72
|
+
validateSlug,
|
|
73
|
+
epicId,
|
|
74
|
+
round: n,
|
|
75
|
+
reviews,
|
|
76
|
+
release: prior && prior.release ? prior.release : null,
|
|
77
|
+
};
|
|
78
|
+
if (n === 2) record.rereviewRequested = false;
|
|
79
|
+
await writeRecord(cwd, record);
|
|
80
|
+
return record;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Record the release once. An already-released record is left untouched. */
|
|
84
|
+
async function recordPlanRelease({
|
|
85
|
+
cwd, epicId, validateSlug, by, rejected = [], accepted = 0,
|
|
86
|
+
} = {}) {
|
|
87
|
+
assertSafe(epicId, validateSlug);
|
|
88
|
+
if (!RELEASE_BY.includes(by)) throw new Error(`planReviewStore: bad release actor '${by}'`);
|
|
89
|
+
const prior = readPlanReview(cwd, epicId, validateSlug);
|
|
90
|
+
if (prior && prior.release) return { alreadyReleased: true };
|
|
91
|
+
const record = {
|
|
92
|
+
...(prior || {}),
|
|
93
|
+
validateSlug,
|
|
94
|
+
epicId,
|
|
95
|
+
round: prior && Number.isFinite(prior.round) ? prior.round : 0,
|
|
96
|
+
reviews: prior && Array.isArray(prior.reviews) ? prior.reviews : [],
|
|
97
|
+
release: {
|
|
98
|
+
at: new Date().toISOString(),
|
|
99
|
+
by,
|
|
100
|
+
rejected: (Array.isArray(rejected) ? rejected : []).map((r) => ({
|
|
101
|
+
finding: String(r && r.finding != null ? r.finding : ''),
|
|
102
|
+
reason: String(r && r.reason != null ? r.reason : ''),
|
|
103
|
+
})),
|
|
104
|
+
accepted: Number.isFinite(accepted) ? accepted : 0,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
await writeRecord(cwd, record);
|
|
108
|
+
return record;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Mark that the review-PRD create was refused (and audited) for `round`.
|
|
113
|
+
* Merge-preserving. Returns true the first time per round, false after.
|
|
114
|
+
*/
|
|
115
|
+
async function markCreateRefused(cwd, epicId, validateSlug, round) {
|
|
116
|
+
assertSafe(epicId, validateSlug);
|
|
117
|
+
const prior = readPlanReview(cwd, epicId, validateSlug);
|
|
118
|
+
const logged = prior && Array.isArray(prior.createRefusedLogged) ? prior.createRefusedLogged : [];
|
|
119
|
+
if (logged.includes(round)) return false;
|
|
120
|
+
await writeRecord(cwd, {
|
|
121
|
+
...(prior || {}),
|
|
122
|
+
validateSlug,
|
|
123
|
+
epicId,
|
|
124
|
+
round: prior && Number.isFinite(prior.round) ? prior.round : 0,
|
|
125
|
+
reviews: prior && Array.isArray(prior.reviews) ? prior.reviews : [],
|
|
126
|
+
release: prior && prior.release ? prior.release : null,
|
|
127
|
+
createRefusedLogged: [...logged, round],
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Every readable record in an Epic's folder; [] for unsafe id/missing folder. */
|
|
133
|
+
function readPlanReviewFiles(cwd, epicId) {
|
|
134
|
+
if (typeof epicId !== 'string' || !EPIC_ID_RE.test(epicId)) return [];
|
|
135
|
+
const dir = opsPath(cwd, NAMESPACE, epicId);
|
|
136
|
+
let names;
|
|
137
|
+
try { names = fs.readdirSync(dir); } catch { return []; }
|
|
138
|
+
const out = [];
|
|
139
|
+
for (const name of names.sort()) {
|
|
140
|
+
if (!name.endsWith(SUFFIX)) continue;
|
|
141
|
+
const rec = readFile(`${dir}/${name}`);
|
|
142
|
+
// markCreateRefused stubs (no review, no release) are not plan reviews; readPlanReview still returns them.
|
|
143
|
+
if (rec && !((!Array.isArray(rec.reviews) || rec.reviews.length === 0) && !rec.release)) out.push(rec);
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
planReviewPath, readPlanReview, savePlanReviewResult, recordPlanRelease, readPlanReviewFiles, markCreateRefused,
|
|
150
|
+
};
|
|
@@ -86,7 +86,9 @@ function blockingPathsOf(job) {
|
|
|
86
86
|
* `undefined` and this falls to the same `now` default.
|
|
87
87
|
*/
|
|
88
88
|
function buildReviewNotice({ job, report, epicId, now, prior } = {}) {
|
|
89
|
-
const cause =
|
|
89
|
+
const cause = !job?.verifierVerdict && job?.environmentLimit?.kind
|
|
90
|
+
? `environment_limit:${job.environmentLimit.kind}`
|
|
91
|
+
: `${job?.verifierVerdict || 'unknown'}${job?.integrationFailureKind ? `:${job.integrationFailureKind}` : ''}`;
|
|
90
92
|
const filed = Boolean(report && report.filed);
|
|
91
93
|
const summary = filed ? report.summary : `${job?.slug ?? 'unknown job'} stopped (${cause})`;
|
|
92
94
|
const reportPath = filed ? (report.path ?? null) : null;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pure classifier: did the OS job sandbox itself refuse something the job
|
|
5
|
+
* tried? Such a failure is an environment limit, not a code defect — an
|
|
6
|
+
* auto-fix investigation runs in the same sandbox and hits the same wall
|
|
7
|
+
* (Self 1313 -> 1313-fix). Deliberately narrow: each pattern needs the
|
|
8
|
+
* sandbox-specific symptom AND its object on one line, so an ordinary EACCES
|
|
9
|
+
* in user code or the bare word "sandbox" never matches.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const PATTERNS = [
|
|
13
|
+
['claude-dir-write', /^(?=[^\n]*(?:denied|EPERM|EACCES|read-only|not permitted|\bblocked\b|\bblocks\b))[^\n]*?(?:sandbox[^\n]{0,80}\.claude\/|\.claude\/[^\n]{0,80}sandbox)|(?:Operation not permitted|Permission denied|Errno 30|Read-only file system|read-only filesystem)[^\n]{0,160}\.claude\/|\.claude\/[^\n]{0,160}(?:Operation not permitted|Permission denied|Errno 30|Read-only file system|read-only filesystem)/im],
|
|
14
|
+
['unix-socket', /(?:Operation not permitted)[^\n]{0,80}AF_UNIX|AF_UNIX[^\n]{0,80}Operation not permitted/i],
|
|
15
|
+
['readonly-tmp', /(?:Errno 30|Read-only file system)[^\n]{0,80}\/tmp|\/tmp[^\n]{0,80}(?:Errno 30|Read-only file system)/i],
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const MAX_BLOCK_LINES = 60;
|
|
19
|
+
const TRACEBACK_START = /^Traceback \(most recent call last\):/;
|
|
20
|
+
const ERROR_LINE = /(?:Operation not permitted|Errno 30|Read-only file system)/i;
|
|
21
|
+
|
|
22
|
+
const ENVIRONMENT_LIMIT_MESSAGE =
|
|
23
|
+
'environment limit (job sandbox), not a code bug — see PRD_AUTHORING.md#job-sandbox-limits';
|
|
24
|
+
|
|
25
|
+
/** @returns {null | { kind: 'claude-dir-write'|'unix-socket'|'readonly-tmp', evidence: string }} */
|
|
26
|
+
function detectSandboxEnvironmentLimit(text) {
|
|
27
|
+
if (typeof text !== 'string' || !text) return null;
|
|
28
|
+
for (const [kind, re] of PATTERNS) {
|
|
29
|
+
const m = re.exec(text);
|
|
30
|
+
if (m) return { kind, evidence: m[0].slice(0, 200) };
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Plain per-line detection (single-line matches only). */
|
|
36
|
+
function detectPerLine(text) {
|
|
37
|
+
if (typeof text !== 'string' || !text) return null;
|
|
38
|
+
for (const line of text.split(/\r?\n/)) {
|
|
39
|
+
const hit = detectSandboxEnvironmentLimit(line);
|
|
40
|
+
if (hit) return hit;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Bash tool_result bodies only: per-line detection, then a traceback-block
|
|
47
|
+
* scan. Anchor on an error line, look back to the nearest
|
|
48
|
+
* "Traceback (most recent call last):" (at most MAX_BLOCK_LINES lines) and
|
|
49
|
+
* classify unix-socket if AF_UNIX is in that block, readonly-tmp if /tmp is.
|
|
50
|
+
* A block ends at its exception line (the first non-indented line after the
|
|
51
|
+
* header), so a later unrelated line never joins it; each new header opens a
|
|
52
|
+
* fresh block (chained tracebacks work). Linear: one pass tracking the block start.
|
|
53
|
+
*/
|
|
54
|
+
function detectBashBody(text) {
|
|
55
|
+
if (typeof text !== 'string' || !text) return null;
|
|
56
|
+
const lines = text.split(/\r?\n/);
|
|
57
|
+
const direct = detectPerLine(text);
|
|
58
|
+
if (direct) return direct;
|
|
59
|
+
let start = -1;
|
|
60
|
+
for (let i = 0; i < lines.length; i++) {
|
|
61
|
+
if (TRACEBACK_START.test(lines[i])) { start = i; continue; }
|
|
62
|
+
if (start < 0 || lines[i].trim() === '' || /^\s/.test(lines[i])) continue;
|
|
63
|
+
// First non-indented line after the header is the exception line: the block ends here.
|
|
64
|
+
const blockStart = start;
|
|
65
|
+
start = -1;
|
|
66
|
+
if (!ERROR_LINE.test(lines[i]) || i - blockStart > MAX_BLOCK_LINES) continue;
|
|
67
|
+
const block = lines.slice(blockStart, i + 1).join('\n');
|
|
68
|
+
if (/Operation not permitted/i.test(lines[i]) && block.includes('AF_UNIX')) {
|
|
69
|
+
return { kind: 'unix-socket', evidence: lines[i].slice(0, 200) };
|
|
70
|
+
}
|
|
71
|
+
if (/Errno 30|Read-only file system/i.test(lines[i]) && block.includes('/tmp')) {
|
|
72
|
+
return { kind: 'readonly-tmp', evidence: lines[i].slice(0, 200) };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Detect a sandbox refusal in a stream-json log tail. Only text the sandbox
|
|
80
|
+
* itself produced is considered: decoded Bash tool_result content, and the
|
|
81
|
+
* executor's `SCHEDULER_VERDICT: FAIL <reason>` from the final result text.
|
|
82
|
+
* Text a job merely read (Read tool_result) or quoted (assistant text) is ignored.
|
|
83
|
+
* @param {string} text
|
|
84
|
+
* @returns {null | { kind: 'claude-dir-write'|'unix-socket'|'readonly-tmp', evidence: string }}
|
|
85
|
+
*/
|
|
86
|
+
function sandboxLimitFromStreamJson(text) {
|
|
87
|
+
if (typeof text !== 'string' || !text) return null;
|
|
88
|
+
const bashIds = new Set();
|
|
89
|
+
let hit = null;
|
|
90
|
+
let resultText = null;
|
|
91
|
+
let structuredOutput;
|
|
92
|
+
for (const raw of text.split('\n')) {
|
|
93
|
+
const line = raw.trim();
|
|
94
|
+
if (!line || line[0] !== '{') continue;
|
|
95
|
+
let ev;
|
|
96
|
+
try { ev = JSON.parse(line); } catch { continue; }
|
|
97
|
+
if (!ev || typeof ev !== 'object') continue;
|
|
98
|
+
if (ev.type === 'result' && typeof ev.result === 'string') {
|
|
99
|
+
resultText = ev.result;
|
|
100
|
+
const so = ev.structured_output ?? ev.structuredOutput;
|
|
101
|
+
if (so && typeof so === 'object' && !Array.isArray(so)) structuredOutput = so;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const content = ev.message && Array.isArray(ev.message.content) ? ev.message.content : null;
|
|
105
|
+
if (!content) continue;
|
|
106
|
+
for (const item of content) {
|
|
107
|
+
if (!item || typeof item !== 'object') continue;
|
|
108
|
+
if (ev.type === 'assistant' && item.type === 'tool_use' && item.name === 'Bash' && item.id) {
|
|
109
|
+
bashIds.add(item.id);
|
|
110
|
+
} else if (ev.type === 'user' && item.type === 'tool_result' && bashIds.has(item.tool_use_id)) {
|
|
111
|
+
if (hit || item.is_error !== true) continue;
|
|
112
|
+
const body = typeof item.content === 'string'
|
|
113
|
+
? item.content
|
|
114
|
+
: Array.isArray(item.content)
|
|
115
|
+
? item.content.filter((b) => b && b.type === 'text').map((b) => b.text ?? '').join('')
|
|
116
|
+
: '';
|
|
117
|
+
hit = detectBashBody(body);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (hit) return hit;
|
|
122
|
+
if (resultText || structuredOutput) {
|
|
123
|
+
// Lazy require: runVerify.cjs is large.
|
|
124
|
+
const { scanSentinelReason } = require('../../runVerify.cjs');
|
|
125
|
+
return detectPerLine(scanSentinelReason({ resultText, ...(structuredOutput ? { structuredOutput } : {}) }, []));
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Finalize stamp/clear decision for a job row.
|
|
132
|
+
* @returns {{ environmentLimit: object|null, error: string|null }}
|
|
133
|
+
*/
|
|
134
|
+
function environmentLimitStamp(sandboxLimit, status) {
|
|
135
|
+
if (sandboxLimit && (status === 'failed' || status === 'needs_review')) {
|
|
136
|
+
return { environmentLimit: sandboxLimit, error: ENVIRONMENT_LIMIT_MESSAGE };
|
|
137
|
+
}
|
|
138
|
+
return { environmentLimit: null, error: null };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
module.exports = { detectSandboxEnvironmentLimit, sandboxLimitFromStreamJson, environmentLimitStamp, ENVIRONMENT_LIMIT_MESSAGE };
|
|
@@ -115,6 +115,8 @@ const ScheduleJobSchema = z
|
|
|
115
115
|
// quietMachineWaitMs without the machine going quiet — tells a reader the
|
|
116
116
|
// job's measurements ran under contention, not on a quiet machine.
|
|
117
117
|
quietLeaseDegraded: z.boolean().optional(),
|
|
118
|
+
// Set when the job sandbox itself refused the run (sandboxEnvironmentLimit.cjs); auto-fix skips such rows.
|
|
119
|
+
environmentLimit: z.object({ kind: z.string(), evidence: z.string() }).optional(),
|
|
118
120
|
// Salvaged uncommitted diff patch path (PRD 1098).
|
|
119
121
|
salvagePatch: z.string().nullable().optional(),
|
|
120
122
|
// Artifact evidence captured before the job worktree was removed, bound
|
|
@@ -74,6 +74,16 @@ function retireRestartRequest(file = schedulerPaths.restartRequestPath()) {
|
|
|
74
74
|
try { fs.unlinkSync(file); } catch (e) { if (e?.code !== 'ENOENT') throw e; }
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** Never throws: { ok: true } or { ok: false, error } (for the forced-reboot path). */
|
|
78
|
+
function retireRestartRequestBestEffort(file = schedulerPaths.restartRequestPath()) {
|
|
79
|
+
try {
|
|
80
|
+
retireRestartRequest(file);
|
|
81
|
+
return { ok: true };
|
|
82
|
+
} catch (e) {
|
|
83
|
+
return { ok: false, error: e?.code || e?.message || String(e) };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
// ---------- pure state machine ----------
|
|
78
88
|
|
|
79
89
|
/**
|
|
@@ -88,20 +98,31 @@ function queueBusyCount(jobs, extraInFlight = 0) {
|
|
|
88
98
|
return n + (Number.isFinite(extraInFlight) ? extraInFlight : 0);
|
|
89
99
|
}
|
|
90
100
|
|
|
101
|
+
/** True when a request's requestedAt is earlier than bootedAt; unparsable/missing either → false. Pure. */
|
|
102
|
+
function requestPredatesBoot(request, bootedAt) {
|
|
103
|
+
const requestedMs = Date.parse(request?.requestedAt ?? '');
|
|
104
|
+
const bootedMs = typeof bootedAt === 'string' ? Date.parse(bootedAt) : NaN;
|
|
105
|
+
return Number.isFinite(requestedMs) && Number.isFinite(bootedMs) && requestedMs < bootedMs;
|
|
106
|
+
}
|
|
107
|
+
|
|
91
108
|
/**
|
|
92
|
-
* evaluateDrain({request, queueSnapshot, drainState, now, deadlineMs}) → {action, reason}
|
|
109
|
+
* evaluateDrain({request, queueSnapshot, drainState, now, deadlineMs, bootedAt}) → {action, reason}
|
|
93
110
|
*
|
|
94
111
|
* queueSnapshot: { running, investigating } counts (in-memory investigations
|
|
95
112
|
* already folded in by the caller). drainState: the machine `drain` field
|
|
96
|
-
* (null / {active}).
|
|
113
|
+
* (null / {active}). bootedAt: this process's boot time (ISO); a missing or
|
|
114
|
+
* unparsable value skips the predates-boot rule. Pure — no IO, no clock.
|
|
97
115
|
*
|
|
98
116
|
* no request, or request already completed → none (abort if a stale drain is still active)
|
|
117
|
+
* pending request written before bootedAt → abort (the restart it asked for already
|
|
118
|
+
* happened: force reboot, manual
|
|
119
|
+
* relaunch, or a crash before the stamp)
|
|
99
120
|
* deadline passed → abort
|
|
100
121
|
* request pending, drain not yet active → pause (engage drain)
|
|
101
122
|
* drain active, anything running/investigating → wait
|
|
102
123
|
* drain active, zero busy → restart
|
|
103
124
|
*/
|
|
104
|
-
function evaluateDrain({ request, queueSnapshot, drainState, now, deadlineMs = DEFAULT_DRAIN_DEADLINE_MS } = {}) {
|
|
125
|
+
function evaluateDrain({ request, queueSnapshot, drainState, now, deadlineMs = DEFAULT_DRAIN_DEADLINE_MS, bootedAt } = {}) {
|
|
105
126
|
const active = Boolean(drainState && drainState.active);
|
|
106
127
|
if (!request || request.drainCompletedAt) {
|
|
107
128
|
return active && !request
|
|
@@ -109,6 +130,9 @@ function evaluateDrain({ request, queueSnapshot, drainState, now, deadlineMs = D
|
|
|
109
130
|
: { action: 'none', reason: request ? 'request-complete' : 'no-request' };
|
|
110
131
|
}
|
|
111
132
|
const requestedMs = Date.parse(request.requestedAt ?? '');
|
|
133
|
+
if (requestPredatesBoot(request, bootedAt)) {
|
|
134
|
+
return { action: 'abort', reason: 'request-predates-boot' };
|
|
135
|
+
}
|
|
112
136
|
if (Number.isFinite(requestedMs) && now - requestedMs >= deadlineMs) {
|
|
113
137
|
return { action: 'abort', reason: 'deadline' };
|
|
114
138
|
}
|
|
@@ -118,12 +142,13 @@ function evaluateDrain({ request, queueSnapshot, drainState, now, deadlineMs = D
|
|
|
118
142
|
}
|
|
119
143
|
|
|
120
144
|
/**
|
|
121
|
-
* bootDrainAction({drainState, request}) → 'clear' | 'keep' | 'none'.
|
|
145
|
+
* bootDrainAction({drainState, request, bootedAt}) → 'clear' | 'keep' | 'none'.
|
|
122
146
|
* A drain whose request is complete (the restart happened) or gone is stale.
|
|
123
147
|
*/
|
|
124
|
-
function bootDrainAction({ drainState, request } = {}) {
|
|
148
|
+
function bootDrainAction({ drainState, request, bootedAt } = {}) {
|
|
125
149
|
if (!drainState || !drainState.active) return 'none';
|
|
126
150
|
if (!request || request.drainCompletedAt) return 'clear';
|
|
151
|
+
if (requestPredatesBoot(request, bootedAt)) return 'clear';
|
|
127
152
|
return 'keep';
|
|
128
153
|
}
|
|
129
154
|
|
|
@@ -168,9 +193,11 @@ module.exports = {
|
|
|
168
193
|
requestRestart,
|
|
169
194
|
stampDrainCompleted,
|
|
170
195
|
retireRestartRequest,
|
|
196
|
+
retireRestartRequestBestEffort,
|
|
171
197
|
queueBusyCount,
|
|
172
198
|
evaluateDrain,
|
|
173
199
|
bootDrainAction,
|
|
200
|
+
requestPredatesBoot,
|
|
174
201
|
effectivePaused,
|
|
175
202
|
installedBuildDiffers,
|
|
176
203
|
markRestarting,
|
|
@@ -26,7 +26,7 @@ const { HTTP_RETRY_ATTEMPTS, HTTP_RETRY_DELAY_MS } = require('./criteriaChecks.c
|
|
|
26
26
|
/** @typedef {{ id: string, met: boolean, evidence: string, missKind?: MissKind }} Criterion */
|
|
27
27
|
/** @typedef {{ severity: Severity, text: string, file?: string, missKind?: MissKind }} Finding */
|
|
28
28
|
/** @typedef {{ prd: string, verdict: 'VERIFIED'|'REFUTED', reason: string, criteria: Criterion[], findings: Finding[] }} VerdictEntry */
|
|
29
|
-
/** @typedef {{ schedulerVerdict: 'PASS'|'FAIL', failReason?: string, verdicts: VerdictEntry[] }} ValidatorVerdict */
|
|
29
|
+
/** @typedef {{ schedulerVerdict: 'PASS'|'FAIL', failReason?: string, lessons?: string[], verdicts: VerdictEntry[] }} ValidatorVerdict */
|
|
30
30
|
/** @typedef {{ slug: string, verdict: 'verified'|'refuted', reason: string, missKinds: MissKind[] }} VerdictRow */
|
|
31
31
|
/** @typedef {{ ids: string[], failedIds?: string[] }} ExpectedCriteria */
|
|
32
32
|
/** @typedef {Record<string, ExpectedCriteria> | Map<string, ExpectedCriteria>} ExpectedMap */
|
|
@@ -68,6 +68,12 @@ const VALIDATOR_VERDICT_SCHEMA = {
|
|
|
68
68
|
description: 'PASS when the validator run itself completed; FAIL when it could not judge the plan.',
|
|
69
69
|
},
|
|
70
70
|
failReason: { type: 'string', description: 'Why the run is FAIL.' },
|
|
71
|
+
lessons: {
|
|
72
|
+
type: 'array',
|
|
73
|
+
maxItems: 3,
|
|
74
|
+
description: 'Optional: at most 3 lessons a future run would need; usually omitted.',
|
|
75
|
+
items: { type: 'string', maxLength: 200 },
|
|
76
|
+
},
|
|
71
77
|
verdicts: {
|
|
72
78
|
type: 'array',
|
|
73
79
|
items: {
|
|
@@ -261,7 +267,7 @@ function checkExpectedCriteria(entry, exp, where) {
|
|
|
261
267
|
function parseValidatorVerdict(value, opts = {}) {
|
|
262
268
|
try {
|
|
263
269
|
if (!isPlainObject(value)) return { ok: false, error: 'verdict: not an object' };
|
|
264
|
-
const keyErr = checkKeys(value, ['schedulerVerdict', 'verdicts'], ['schedulerVerdict', 'failReason', 'verdicts'], 'verdict');
|
|
270
|
+
const keyErr = checkKeys(value, ['schedulerVerdict', 'verdicts'], ['schedulerVerdict', 'failReason', 'lessons', 'verdicts'], 'verdict');
|
|
265
271
|
if (keyErr) return { ok: false, error: keyErr };
|
|
266
272
|
if (value.schedulerVerdict !== 'PASS' && value.schedulerVerdict !== 'FAIL') {
|
|
267
273
|
return { ok: false, error: 'schedulerVerdict: not PASS or FAIL' };
|
|
@@ -269,6 +275,10 @@ function parseValidatorVerdict(value, opts = {}) {
|
|
|
269
275
|
if (value.failReason !== undefined && typeof value.failReason !== 'string') {
|
|
270
276
|
return { ok: false, error: 'failReason: not a string' };
|
|
271
277
|
}
|
|
278
|
+
if (value.lessons !== undefined) {
|
|
279
|
+
if (!Array.isArray(value.lessons) || value.lessons.length > 3) return { ok: false, error: 'lessons: not an array of at most 3' };
|
|
280
|
+
if (value.lessons.some((l) => typeof l !== 'string' || l.length > 200)) return { ok: false, error: 'lessons: each must be a string of at most 200 chars' };
|
|
281
|
+
}
|
|
272
282
|
if (!Array.isArray(value.verdicts)) return { ok: false, error: 'verdicts: not an array' };
|
|
273
283
|
const expected = opts && (opts.expected instanceof Map || isPlainObject(opts.expected)) ? opts.expected : null;
|
|
274
284
|
/** @type {Set<string>} */
|