claude-code-session-manager 0.140.0 → 0.142.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 +80 -70
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
- package/dist/assets/{History--JwsFnbn.js → History-DpZuJXi1.js} +1 -1
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
- package/dist/assets/{Panel-CALyU0pe.js → Panel-BjdJjhqt.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-sdlA-fUb.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
- package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
- package/dist/assets/{SkillReferenceGraph-CxAuwhNN.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
- package/dist/assets/{Skills-DtRzghn5.js → Skills-vv0noNVI.js} +5 -5
- package/dist/assets/{TiptapBody-DApeu7x8.js → TiptapBody-CXi8Pvut.js} +1 -1
- package/dist/assets/Toggle-CiYCWLjh.js +1 -0
- package/dist/assets/{VoiceButton-DtStfv1H.js → VoiceButton-4NKKd1sC.js} +1 -1
- package/dist/assets/{historyTotals-ydfnwepc.js → historyTotals-DDunb8Ch.js} +1 -1
- package/dist/assets/index-Cn5E9958.js +3133 -0
- package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +496 -484
- package/package.json +4 -2
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/hooks/hooks.json +15 -0
- package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
- package/plugins/session-manager-dev/skills/builder/SKILL.md +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +55 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +1 -0
- package/scripts/hooks/guard-tool-risk.cjs +5 -1
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
- package/scripts/scheduler-mcp-server.cjs +737 -110
- package/src/main/adminRouteRegistry.cjs +59 -0
- package/src/main/agentLibrary.cjs +72 -4
- package/src/main/agentsIpc.cjs +3 -2
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +231 -16
- package/src/main/config.cjs +30 -0
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +91 -0
- package/src/main/index.cjs +98 -48
- package/src/main/ipcSchemas.cjs +171 -8
- package/src/main/lib/AGENTS.md +1 -1
- package/src/main/lib/chatBootRecovery.cjs +2 -0
- package/src/main/lib/claude/agentModelResolve.cjs +51 -25
- package/src/main/lib/claude/agentSnapshot.cjs +186 -0
- package/src/main/lib/claude/environmentProfiles.cjs +242 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
- package/src/main/lib/claude/personaToolScope.cjs +82 -31
- package/src/main/lib/claude/runClaudeP.cjs +4 -2
- package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
- package/src/main/lib/claude/usageCircuit.cjs +49 -21
- package/src/main/lib/claude/vaultRefs.cjs +277 -0
- package/src/main/lib/demo-video-kit/capture.cjs +282 -12
- package/src/main/lib/demo-video-kit/cast.md +43 -0
- package/src/main/lib/demo-video-kit/character.cjs +722 -30
- package/src/main/lib/demo-video-kit/checks.cjs +120 -1
- package/src/main/lib/demo-video-kit/export.cjs +218 -0
- package/src/main/lib/demo-video-kit/frames.cjs +104 -9
- package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
- package/src/main/lib/demo-video-kit/kind-tiktok.md +99 -0
- package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
- package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
- package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
- package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
- package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
- package/src/main/lib/epic/artifactIpc.cjs +153 -0
- package/src/main/lib/epic/artifactNotice.cjs +72 -0
- package/src/main/lib/epic/artifactRetention.cjs +310 -0
- package/src/main/lib/epic/artifactStore.cjs +392 -0
- package/src/main/lib/epic/delegationReadiness.cjs +76 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +214 -0
- package/src/main/lib/epic/epicMint.cjs +43 -1
- package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
- package/src/main/lib/epic/epicOutsideState.cjs +18 -4
- package/src/main/lib/epic/epicPurge.cjs +347 -0
- package/src/main/lib/epic/epicReopen.cjs +5 -2
- package/src/main/lib/epic/epicSettle.cjs +4 -13
- package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
- package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +81 -2
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +37 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
- package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
- package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
- package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
- package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
- package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
- package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +2 -1
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
- package/src/main/lib/feedback-remote/pendingReplies.cjs +189 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
- package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
- package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
- package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
- package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
- package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
- package/src/main/lib/git/worktreeDeps.cjs +77 -2
- package/src/main/lib/mcpToolCatalog.cjs +315 -30
- package/src/main/lib/opsOwnership.cjs +29 -1
- package/src/main/lib/opsRetentionSettings.cjs +27 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
- package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
- package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +263 -0
- package/src/main/lib/phaseProjection.cjs +103 -0
- package/src/main/lib/prd/depSlugResolve.cjs +4 -13
- package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
- package/src/main/lib/prd/prdCreate.cjs +67 -5
- package/src/main/lib/prd/prdCriteria.cjs +225 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +68 -3
- package/src/main/lib/prd/prdGateFiles.cjs +125 -49
- package/src/main/lib/prd/prdSizing.cjs +3 -1
- package/src/main/lib/process/cleanEnv.cjs +52 -1
- package/src/main/lib/process/leftoverRenice.cjs +178 -0
- package/src/main/lib/process/memoryScope.cjs +31 -3
- package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
- package/src/main/lib/project-pages/voicePreview.cjs +196 -0
- package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
- package/src/main/lib/promptSessionSchema.cjs +6 -0
- package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
- package/src/main/lib/scheduler/cpuSample.cjs +133 -42
- package/src/main/lib/scheduler/criteriaChecks.cjs +169 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
- package/src/main/lib/scheduler/preflightCheck.cjs +97 -0
- package/src/main/lib/scheduler/reviewNotice.cjs +39 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -0
- package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
- package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +0 -3
- package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
- package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
- package/src/main/lib/scheduler/slotsRoute.cjs +237 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
- package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
- package/src/main/lib/tasks/mitigationReview.cjs +294 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
- package/src/main/lib/tasks/taskIpc.cjs +22 -18
- package/src/main/lib/tasks/taskLedger.cjs +147 -25
- package/src/main/lib/tasks/taskRun.cjs +186 -17
- package/src/main/lib/tasks/taskSwitch.cjs +85 -12
- package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
- package/src/main/lib/telemetry/auditEvents.cjs +207 -6
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
- package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
- package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
- package/src/main/lib/toolUseClassify.cjs +181 -0
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +5 -0
- package/src/main/pty.cjs +68 -0
- package/src/main/queueOps.cjs +32 -13
- package/src/main/runVerify.cjs +74 -9
- package/src/main/scheduler/AGENTS.md +1 -0
- package/src/main/scheduler/budget.cjs +6 -5
- package/src/main/scheduler/prdParser.cjs +62 -14
- package/src/main/scheduler/reviewLadder.cjs +45 -28
- package/src/main/scheduler/starvation.cjs +69 -0
- package/src/main/scheduler/utilizationHold.cjs +101 -0
- package/src/main/scheduler.cjs +1745 -210
- package/src/main/templates/PRD_AUTHORING.md +13 -2
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +529 -38
- package/src/preload/apiSurface.json +209 -7
- package/src/preload/index.cjs +46 -1
- package/src/seed/agents/architect.md +6 -1
- package/src/seed/agents/blender-artist.md +2 -1
- package/src/seed/agents/competitive-analyst.md +3 -1
- package/src/seed/agents/competitive-researcher.md +2 -1
- package/src/seed/agents/demo-video-builder.md +87 -83
- package/src/seed/agents/dev-lead.md +3 -3
- package/src/seed/agents/project-home-builder.md +9 -31
- package/src/seed/agents/validator.md +9 -10
- package/dist/assets/AppSettings-CMFEM68R.js +0 -2
- package/dist/assets/HomeClaudeConfig-ijEXs--3.js +0 -3
- package/dist/assets/Scheduler-YT3j8SUa.js +0 -16
- package/dist/assets/ViewTabs-B7qLXRAH.js +0 -1
- package/dist/assets/index-CtxruO1L.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* epicTransitions.cjs — the ONE place an Epic's `status` changes after mint.
|
|
5
|
+
* Mint (birth as `proposed`) stays in epicMint.cjs; every later edge
|
|
6
|
+
* (complete, discard, reopen) goes through `transitionEpic` here.
|
|
7
|
+
*
|
|
8
|
+
* The status law itself lives in
|
|
9
|
+
* session-manager-operations/prompt-sessions/README.md#lifecycle — link it,
|
|
10
|
+
* never restate it. This module only encodes its edges as a table.
|
|
11
|
+
*
|
|
12
|
+
* Semantics copy lib/scheduler/scheduleJobTransitions.cjs's transitionJob:
|
|
13
|
+
* - identity (status unchanged) is a no-op success, nothing recorded;
|
|
14
|
+
* - a legal edge mutates `epic.status`, writes an `epic_transition` audit
|
|
15
|
+
* record and appends `epic.status_changed` to the Epic's event log
|
|
16
|
+
* (fire-and-forget — a log failure never blocks the transition);
|
|
17
|
+
* - an illegal edge is refused: the Epic is left untouched, an
|
|
18
|
+
* `epic_transition_refused` audit record is written, and false is
|
|
19
|
+
* returned. Under test (NODE_ENV=test or VITEST set) it throws instead, so
|
|
20
|
+
* a call site asking for an illegal edge fails its own test loudly.
|
|
21
|
+
*
|
|
22
|
+
* Plain Node module (no Electron deps), like epicMint.cjs.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const auditLog = require('../telemetry/auditLog.cjs');
|
|
26
|
+
// Module objects (not destructured) so tests can stub the audit + event emits.
|
|
27
|
+
const epicEventLog = require('./epicEventLog.cjs');
|
|
28
|
+
const opsErrorLog = require('../telemetry/opsErrorLog.cjs');
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Explicit from->to edges (see the README link above for what each means).
|
|
32
|
+
* proposed->completed is Discard on a proposal, which the lifecycle law lists
|
|
33
|
+
* as entering `completed` alongside markCompleted.
|
|
34
|
+
* @type {Readonly<Record<string, readonly string[]>>}
|
|
35
|
+
*/
|
|
36
|
+
const EPIC_LEGAL_TRANSITIONS = Object.freeze({
|
|
37
|
+
proposed: Object.freeze(['active', 'completed']),
|
|
38
|
+
active: Object.freeze(['completed']),
|
|
39
|
+
completed: Object.freeze(['active']),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let refusedTransitionCount = 0;
|
|
43
|
+
|
|
44
|
+
function isTestEnv() {
|
|
45
|
+
return process.env.NODE_ENV === 'test' || !!process.env.VITEST;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string|null|undefined} from
|
|
50
|
+
* @param {string|null|undefined} to
|
|
51
|
+
*/
|
|
52
|
+
function isLegalEpicTransition(from, to) {
|
|
53
|
+
if (from === to && typeof from === 'string' && from in EPIC_LEGAL_TRANSITIONS) return true;
|
|
54
|
+
if (typeof from !== 'string' || typeof to !== 'string') return false;
|
|
55
|
+
const edges = EPIC_LEGAL_TRANSITIONS[from];
|
|
56
|
+
return Array.isArray(edges) && edges.includes(to);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} cwd
|
|
61
|
+
* @param {string} epicId
|
|
62
|
+
* @param {Record<string, unknown>} event
|
|
63
|
+
*/
|
|
64
|
+
function emitEpicEvent(cwd, epicId, event) {
|
|
65
|
+
/** @param {unknown} err */
|
|
66
|
+
const onError = (err) => {
|
|
67
|
+
try {
|
|
68
|
+
opsErrorLog.appendError({
|
|
69
|
+
cwd,
|
|
70
|
+
scope: 'epic',
|
|
71
|
+
level: 'error',
|
|
72
|
+
epicId,
|
|
73
|
+
message: `epic event append failed (${String(event.kind)}): ${err instanceof Error ? err.message : String(err)}`,
|
|
74
|
+
meta: { kind: event.kind ?? null },
|
|
75
|
+
});
|
|
76
|
+
} catch { /* logging must never be the thing that fails */ }
|
|
77
|
+
};
|
|
78
|
+
try {
|
|
79
|
+
const p = epicEventLog.appendEpicEvent(cwd, epicId, event);
|
|
80
|
+
if (p && typeof p.catch === 'function') p.catch(onError);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
onError(err);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* transitionEpic(epic, to, { reason, source, allowAnyFrom }) → boolean.
|
|
88
|
+
* Mutates `epic.status` in place on success. `epic.id` and `epic.cwd` name
|
|
89
|
+
* the event log the transition is appended to (skipped when either is
|
|
90
|
+
* missing). `allowAnyFrom` is the same narrow data-repair hatch transitionJob
|
|
91
|
+
* has: a record with no readable prior status still goes through this
|
|
92
|
+
* chokepoint (mutation, audit, event) without consulting the table.
|
|
93
|
+
*
|
|
94
|
+
* @param {{ id?: string, cwd?: string, status?: string|null } & Record<string, unknown>} epic
|
|
95
|
+
* @param {string} to
|
|
96
|
+
* @param {{ reason?: string|null, source?: string|null, allowAnyFrom?: boolean }} [opts]
|
|
97
|
+
*/
|
|
98
|
+
function transitionEpic(epic, to, { reason = null, source = null, allowAnyFrom = false } = {}) {
|
|
99
|
+
if (!epic || typeof epic !== 'object') return false;
|
|
100
|
+
const from = epic.status ?? null;
|
|
101
|
+
const epicId = typeof epic.id === 'string' ? epic.id : null;
|
|
102
|
+
const cwd = typeof epic.cwd === 'string' ? epic.cwd : null;
|
|
103
|
+
|
|
104
|
+
const toKnown = typeof to === 'string' && to in EPIC_LEGAL_TRANSITIONS;
|
|
105
|
+
if (!toKnown || (!allowAnyFrom && !isLegalEpicTransition(from, to))) {
|
|
106
|
+
refusedTransitionCount += 1;
|
|
107
|
+
const msg = `[epicTransitions] illegal transition refused: epicId=${epicId ?? '(unknown)'} `
|
|
108
|
+
+ `from=${from ?? '(none)'} to=${to ?? '(none)'} reason=${reason ?? '(none)'} source=${source ?? '(none)'}`;
|
|
109
|
+
console.error(msg);
|
|
110
|
+
auditLog.appendAuditEvent('epic_transition_refused', { epicId, cwd, from, to: to ?? null, reason, source });
|
|
111
|
+
if (isTestEnv()) throw new Error(msg);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (from === to) return true; // identity — nothing changed, nothing to record
|
|
116
|
+
|
|
117
|
+
epic.status = to;
|
|
118
|
+
auditLog.appendAuditEvent('epic_transition', { epicId, cwd, from, to, reason, source });
|
|
119
|
+
if (epicId && cwd) {
|
|
120
|
+
emitEpicEvent(cwd, epicId, { kind: 'epic.status_changed', from, to, reason, source });
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function getRefusedEpicTransitionCount() {
|
|
126
|
+
return refusedTransitionCount;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function _resetRefusedEpicTransitionCountForTests() {
|
|
130
|
+
refusedTransitionCount = 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = {
|
|
134
|
+
EPIC_LEGAL_TRANSITIONS,
|
|
135
|
+
isLegalEpicTransition,
|
|
136
|
+
transitionEpic,
|
|
137
|
+
getRefusedEpicTransitionCount,
|
|
138
|
+
_resetRefusedEpicTransitionCountForTests,
|
|
139
|
+
};
|
|
@@ -68,7 +68,74 @@ function recordFolderLines(cwd, epicId) {
|
|
|
68
68
|
* (plan-records/<epicId>/, never committed), so the digest names that
|
|
69
69
|
* absolute folder plus the legacy reviews/validation/<epicId>/ one.
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
const SEVERITY_ORDER = ['Critical', 'Important', 'Minor'];
|
|
72
|
+
const MAX_FINDING_LINES = 50;
|
|
73
|
+
|
|
74
|
+
function severityRank(sev) {
|
|
75
|
+
const i = SEVERITY_ORDER.indexOf(String(sev || ''));
|
|
76
|
+
return i === -1 ? SEVERITY_ORDER.length : i;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Collapse every whitespace run (newlines, tabs) to one space and trim. */
|
|
80
|
+
function oneLine(x) {
|
|
81
|
+
return String(x ?? '').replace(/\s+/g, ' ').trim();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Findings section lines: every finding gets an outcome in the same turn —
|
|
86
|
+
* Minor ones are the ones that get dropped when only verdict slugs are listed.
|
|
87
|
+
* Critical first, then Important, then Minor (stable within a severity).
|
|
88
|
+
*/
|
|
89
|
+
function findingLines(findings) {
|
|
90
|
+
const list = (Array.isArray(findings) ? findings : []).filter((f) => f && typeof f === 'object');
|
|
91
|
+
if (!list.length) return [];
|
|
92
|
+
const sorted = list
|
|
93
|
+
.map((f, i) => ({ f, i }))
|
|
94
|
+
.sort((a, b) => (severityRank(a.f.severity) - severityRank(b.f.severity)) || (a.i - b.i))
|
|
95
|
+
.map((x) => x.f);
|
|
96
|
+
const shown = sorted.slice(0, MAX_FINDING_LINES);
|
|
97
|
+
const out = [
|
|
98
|
+
'', `Findings (${list.length}) — give each one an outcome in this turn: a fix PRD or a one-line close reason:`,
|
|
99
|
+
...shown.map((f) => {
|
|
100
|
+
const text = oneLine(f.text);
|
|
101
|
+
const file = oneLine(f.file);
|
|
102
|
+
return `- [${oneLine(f.severity)}] ${oneLine(f.prd)}:${text ? ` ${text}` : ''}${file ? ` (${file})` : ''}`;
|
|
103
|
+
}),
|
|
104
|
+
];
|
|
105
|
+
if (sorted.length > shown.length) out.push(`- …and ${sorted.length - shown.length} more in the records`);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Flatten verdict records ({ prd, at, findings[] }) to digest findings, keeping
|
|
111
|
+
* only verdicts saved after `sinceMs` (null = keep all). A verdict with no
|
|
112
|
+
* parseable `at` is kept only when there is no previous digest.
|
|
113
|
+
*/
|
|
114
|
+
function collectFindings(verdicts, sinceMs) {
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const v of Array.isArray(verdicts) ? verdicts : []) {
|
|
117
|
+
if (!v || !Array.isArray(v.findings) || !v.findings.length) continue;
|
|
118
|
+
if (sinceMs != null) {
|
|
119
|
+
const t = typeof v.at === 'string' ? Date.parse(v.at) : NaN;
|
|
120
|
+
if (!Number.isFinite(t) || t <= sinceMs) continue;
|
|
121
|
+
}
|
|
122
|
+
for (const f of v.findings) {
|
|
123
|
+
if (!f || typeof f !== 'object') continue;
|
|
124
|
+
out.push({ prd: v.prd, severity: f.severity, text: f.text, file: f.file });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function defaultReadVerdictFiles(cwd, epicId) {
|
|
131
|
+
try {
|
|
132
|
+
return require('./epicOutsideRead.cjs').readVerdictFiles(cwd, epicId);
|
|
133
|
+
} catch {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function buildSettledDigest(settle, { epicId, notValidatedReason, cwd, findings } = {}) {
|
|
72
139
|
const s = settle || {};
|
|
73
140
|
const verified = s.verified || [];
|
|
74
141
|
const refuted = s.refuted || [];
|
|
@@ -99,6 +166,7 @@ function buildSettledDigest(settle, { epicId, notValidatedReason, cwd } = {}) {
|
|
|
99
166
|
...cancelled.map((c) => `- ${c}`),
|
|
100
167
|
);
|
|
101
168
|
}
|
|
169
|
+
lines.push(...findingLines(findings));
|
|
102
170
|
if (notValidated.length) {
|
|
103
171
|
lines.push(
|
|
104
172
|
'', `Not validated (${notValidated.length}) — ${notValidatedReason || 'no validator checked them'}:`,
|
|
@@ -134,6 +202,7 @@ async function runEpicSettle({ cwd, epicId } = {}, deps = {}) {
|
|
|
134
202
|
jobBudget,
|
|
135
203
|
sendPrompt,
|
|
136
204
|
appendResponseEvent,
|
|
205
|
+
readVerdictFiles = defaultReadVerdictFiles,
|
|
137
206
|
now = Date.now,
|
|
138
207
|
log = console,
|
|
139
208
|
} = deps;
|
|
@@ -220,7 +289,17 @@ async function runEpicSettle({ cwd, epicId } = {}, deps = {}) {
|
|
|
220
289
|
}
|
|
221
290
|
}
|
|
222
291
|
|
|
223
|
-
|
|
292
|
+
let findings = [];
|
|
293
|
+
try {
|
|
294
|
+
const sinceMs = newestDigest ? Date.parse(newestDigest.at) : null;
|
|
295
|
+
findings = collectFindings(
|
|
296
|
+
(await readVerdictFiles(cwd, epicId)) || [],
|
|
297
|
+
sinceMs != null && Number.isFinite(sinceMs) ? sinceMs : null,
|
|
298
|
+
);
|
|
299
|
+
} catch (e) {
|
|
300
|
+
try { (log || console).error('[epicValidationHook] readVerdictFiles failed', epicId, e); } catch { /* noop */ }
|
|
301
|
+
}
|
|
302
|
+
const prompt = buildSettledDigest(digestSettle, { epicId, notValidatedReason, cwd, findings });
|
|
224
303
|
sendPrompt(epicId, prompt, { origin: 'scheduler' });
|
|
225
304
|
await appendResponseEvent(
|
|
226
305
|
cwd, epicId,
|
|
@@ -73,8 +73,9 @@ async function writeGuardSpawnSettingsFile({ spawnCwd, homeDir = os.homedir(), d
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/** Every tool class guard-tool-risk.cjs can mark
|
|
77
|
-
|
|
76
|
+
/** Every tool class guard-tool-risk.cjs can mark (Bash rules, file writes, MCP calls), plus
|
|
77
|
+
* WebFetch/WebSearch, which it only observes for environment would-block reports. */
|
|
78
|
+
const TOOL_RISK_MATCHER = 'Bash|Write|Edit|NotebookEdit|WebFetch|WebSearch|mcp__.*';
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
81
|
* Settings carrying ONLY the guard-tool-risk PreToolUse hook, for headless
|
|
@@ -25,6 +25,21 @@ function contractInfo() {
|
|
|
25
25
|
return { contractVersion: CONTRACT_VERSION, appVersion: APP_VERSION };
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The health route's answer: contractInfo() plus the Task request keys, so an
|
|
30
|
+
* outside caller can tell which optional keys this app accepts (additive keys
|
|
31
|
+
* never bump contractVersion, and the strict Task schemas 400 an unknown key).
|
|
32
|
+
* @returns {{ contractVersion: number, appVersion: string | null, taskBodyKeys: string[], taskRuntimeKeys: string[], taskGetKeys: string[] }}
|
|
33
|
+
*/
|
|
34
|
+
function healthInfo() {
|
|
35
|
+
return {
|
|
36
|
+
...contractInfo(),
|
|
37
|
+
taskBodyKeys: [...CONTRACT.taskBodyKeys],
|
|
38
|
+
taskRuntimeKeys: [...CONTRACT.taskRuntimeKeys],
|
|
39
|
+
taskGetKeys: [...CONTRACT.taskGetKeys],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
/** Recursively freeze a plain object/array literal. */
|
|
29
44
|
function deepFreeze(v) {
|
|
30
45
|
if (v && typeof v === 'object') {
|
|
@@ -47,6 +62,8 @@ const CONTRACT = deepFreeze({
|
|
|
47
62
|
{ method: 'POST', path: '/admin/macros/run' },
|
|
48
63
|
{ method: 'GET', path: '/admin/epics' },
|
|
49
64
|
{ method: 'GET', path: '/admin/epic' },
|
|
65
|
+
// GET /admin/events: no epicId → audit-log rows { events, next, more, gap } (eventKinds below);
|
|
66
|
+
// ?epicId=<id>[&cwd][&after=<seq>][&kinds][&limit≤500] → that Epic's event-log replay { events, cursor, hasMore }.
|
|
50
67
|
{ method: 'GET', path: '/admin/events' },
|
|
51
68
|
{ method: 'GET', path: '/admin/agents' },
|
|
52
69
|
{ method: 'POST', path: '/admin/needs-you' },
|
|
@@ -56,6 +73,7 @@ const CONTRACT = deepFreeze({
|
|
|
56
73
|
{ method: 'GET', path: '/admin/tasks' },
|
|
57
74
|
{ method: 'GET', path: '/admin/task' },
|
|
58
75
|
{ method: 'POST', path: '/admin/tasks/import' },
|
|
76
|
+
{ method: 'POST', path: '/admin/tasks/switch' },
|
|
59
77
|
{ method: 'GET', path: '/admin/validation-quality' },
|
|
60
78
|
],
|
|
61
79
|
tools: {
|
|
@@ -69,7 +87,7 @@ const CONTRACT = deepFreeze({
|
|
|
69
87
|
},
|
|
70
88
|
epicStates: ['closed', 'awaiting_approval', 'needs_input', 'blocked', 'working', 'in_review', 'verified', 'open'],
|
|
71
89
|
epicRecordFields: [
|
|
72
|
-
'epicId', 'cwd', 'title', 'goal', 'tag', 'agentType', 'status', 'state', 'blocked', 'prds',
|
|
90
|
+
'epicId', 'cwd', 'title', 'goal', 'tag', 'agentType', 'status', 'state', 'phase', 'blocked', 'prds',
|
|
73
91
|
'verified', 'refuted', 'unvalidated', 'externalRef', 'source', 'createdAt', 'completedAt', 'verdicts',
|
|
74
92
|
],
|
|
75
93
|
receiptFields: ['jobs', 'chat'],
|
|
@@ -96,8 +114,17 @@ const CONTRACT = deepFreeze({
|
|
|
96
114
|
'taskId', 'source', 'importId', 'importedAt', 'agent', 'missionId', 'model', 'effort', 'priority', 'caller',
|
|
97
115
|
'outputFormat', 'timeoutSec', 'slotWaitSec', 'sessionId', 'persisted', 'startedAt', 'endedAt', 'status',
|
|
98
116
|
'exitCode', 'signal', 'durationMs', 'slotWaitMs', 'usage', 'costUsd', 'cliCostUsd', 'numTurns', 'quota',
|
|
99
|
-
'promptBytes', 'promptSha256', 'outputBytes', 'outputSha256',
|
|
117
|
+
'promptBytes', 'promptSha256', 'outputBytes', 'outputSha256', 'phase',
|
|
118
|
+
],
|
|
119
|
+
// Keys POST /admin/tasks accepts at the top level / under runtime, and GET /admin/task query keys
|
|
120
|
+
// (tasks/taskAdminRoutes.cjs TASK_BODY_KEYS / TASK_RUNTIME_KEYS / TASK_GET_KEYS; the schemas are strict, so an unknown key is a 400).
|
|
121
|
+
taskBodyKeys: ['cwd', 'agent', 'missionId', 'prompt', 'timeoutSec', 'slotWaitSec', 'priority', 'caller', 'runtime', 'stream'],
|
|
122
|
+
taskRuntimeKeys: [
|
|
123
|
+
'outputFormat', 'settingSources', 'mcpConfig', 'strictMcpConfig', 'allowedTools', 'tools', 'maxTurns', 'systemPrompt',
|
|
124
|
+
'appendSystemPrompt', 'disallowedTools', 'skipPermissions', 'disableAutoMemory', 'sessionId', 'resume', 'persistSession',
|
|
125
|
+
'cwd',
|
|
100
126
|
],
|
|
127
|
+
taskGetKeys: ['cwd', 'id', 'after'],
|
|
101
128
|
eventKinds: ['epic_state_changed', 'job_transition', 'epic_cross_project_reply', 'needs_you_answered'],
|
|
102
129
|
adminApiFields: ['port', 'token', 'appVersion', 'contractVersion'],
|
|
103
130
|
});
|
|
@@ -126,12 +153,18 @@ function contractFingerprint() {
|
|
|
126
153
|
const CONTRACT_FINGERPRINTS = Object.freeze({
|
|
127
154
|
// v1 was unreleased when the manifest was completed (at/kind, epic_get requiredOneOf, then epic_cross_project_reply + feedback_reply + replyEventFields, then GET /admin/agents + agent_list + agentFields, then the Needs you routes + needsYouItemFields + needsYouAnsweredFields + needs_you_answered, then POST /admin/tasks, then GET /admin/tasks + GET /admin/task + POST /admin/tasks/import + taskFields, then task_list + task_get), so its first fingerprint was replaced, not appended.
|
|
128
155
|
// Additive since: epicRecordFields + 'verdicts' (checked validator verdicts from plan-records/*.verdicts.json),
|
|
129
|
-
// then GET /admin/validation-quality (validationQualityHandlers.cjs)
|
|
156
|
+
// then GET /admin/validation-quality (validationQualityHandlers.cjs),
|
|
157
|
+
// then 'phase' on epicRecordFields + taskFields (phaseProjection.cjs),
|
|
158
|
+
// then POST /admin/tasks/switch (tasks/taskSwitchRoute.cjs),
|
|
159
|
+
// then taskBodyKeys + taskRuntimeKeys + taskGetKeys (advertised on GET /__admin/health via healthInfo()).
|
|
130
160
|
1: Object.freeze([
|
|
131
161
|
'5a56abbb70184ff4a34346a5c6da4c5e6edbd756b54573c199b812d3f5a04101',
|
|
132
162
|
'7383ff32c80561b1b2c505a78a1e8313ae2851bdc6e8fce6c6a88e1ab119bf5a',
|
|
133
163
|
'b8af6788f3c5022346278194a8113455c47f3ab7a565e51d47c5e79c7f36fbd7',
|
|
164
|
+
'2ddfa9e96382e6d2d8db6849361aeb89a62d86c237ad99d149ccb01c6b57db6a',
|
|
165
|
+
'a5be9b9b073639b4622574c842ed9a41ebb39c24c0919d699b18d2e197a8eb67',
|
|
166
|
+
'ffb97327f0bd2da7d3f29693171ee7ee53982d8347d20d009e5aa5baf2bc15d1',
|
|
134
167
|
]),
|
|
135
168
|
});
|
|
136
169
|
|
|
137
|
-
module.exports = { CONTRACT_VERSION, contractInfo, CONTRACT, contractFingerprint, CONTRACT_FINGERPRINTS };
|
|
170
|
+
module.exports = { CONTRACT_VERSION, contractInfo, healthInfo, CONTRACT, contractFingerprint, CONTRACT_FINGERPRINTS };
|