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
|
@@ -34,10 +34,25 @@ const { isFixPlanSlug } = require('../scheduler/fixPlanSlug.cjs');
|
|
|
34
34
|
const { isIncomplete, resolveChainTerminals, isValidPlanId, mintPlanId, resolveInheritedPlanId } = require('./prdDisposition.cjs');
|
|
35
35
|
const { splitFrontmatter, PRD_EFFORT_LEVELS, formatQuotedInlineList } = require('./prdFrontmatter.cjs');
|
|
36
36
|
const { parseRule: parseToolRiskRule } = require('../claude/toolRiskMarks.cjs');
|
|
37
|
+
const { normalizePreflight } = require('../scheduler/preflightCheck.cjs');
|
|
37
38
|
|
|
38
39
|
// Cap on riskTools entries — mirrors ipcSchemas.cjs RiskToolsSchema.
|
|
39
40
|
const RISK_TOOLS_MAX = 20;
|
|
40
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Validate + normalize a `preflight` value — wraps preflightCheck's
|
|
44
|
+
* normalizePreflight (which throws) into the { ok, value | error } shape the
|
|
45
|
+
* other field checks return, so createPrd and the update path share one check.
|
|
46
|
+
* value is null when the input is empty/absent (no frontmatter key).
|
|
47
|
+
*/
|
|
48
|
+
function normalizePreflightField(value) {
|
|
49
|
+
try {
|
|
50
|
+
return { ok: true, value: normalizePreflight(value) };
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return { ok: false, error: e && e.message ? e.message : String(e) };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
41
56
|
/**
|
|
42
57
|
* Validate + normalize a `riskTools` value — the ONE check shared by
|
|
43
58
|
* createPrd and scheduler.cjs's updatePrd so create and update can never
|
|
@@ -66,7 +81,8 @@ const telemetryCounters = require('../telemetry/telemetryCounters.cjs');
|
|
|
66
81
|
const { execGit } = require('../git/gitExec.cjs');
|
|
67
82
|
const { extractRepoPathCandidates, worktreeReachWarnings } = require('./prdWorktreeReach.cjs');
|
|
68
83
|
const { isSweepValidatorSlug } = require('../epic/epicSweepValidator.cjs');
|
|
69
|
-
const { validateGate, validateFiles, renderFilesSection, renderGateSection, parseFilesSection } = require('./prdGateFiles.cjs');
|
|
84
|
+
const { NONE_GATE_WARNING, validateGate, validateFiles, renderFilesSection, renderGateSection, parseFilesSection } = require('./prdGateFiles.cjs');
|
|
85
|
+
const { normalizeCriteria, validateCriteria, serializeCriteria, renderCriteriaLines } = require('./prdCriteria.cjs');
|
|
70
86
|
const { filesOverlap } = require('../scheduler/schedulerBatch.cjs');
|
|
71
87
|
const { resolveGate, parseChain, isNoneGate } = require('../scheduler/definitionOfDone.cjs');
|
|
72
88
|
const { MISS_KINDS } = require('../scheduler/validatorVerdictSchema.cjs');
|
|
@@ -112,6 +128,8 @@ function deriveSlugFromTitle(title) {
|
|
|
112
128
|
* Engineering standards, in order.
|
|
113
129
|
*/
|
|
114
130
|
const MACRO_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
131
|
+
// Voice-library id pattern: the one owner is voiceLibrary.cjs.
|
|
132
|
+
const { VOICE_ID_RE } = require('../demo-video-kit/voiceLibrary.cjs');
|
|
115
133
|
function isValidMacroId(id) {
|
|
116
134
|
return typeof id === 'string' && MACRO_ID_RE.test(id);
|
|
117
135
|
}
|
|
@@ -119,9 +137,13 @@ function isValidMacroId(id) {
|
|
|
119
137
|
function buildPrdBody(input) {
|
|
120
138
|
const {
|
|
121
139
|
title, cwd, estimateMinutes, goal, acceptanceCriteria,
|
|
122
|
-
implementationNotes, outOfScope, sourcePromptId, sourceTabId, tag, agentType, dependsOn, quietMachine, disposition, deliverable, artifactPaths, planId, macroId, effort, riskTools,
|
|
140
|
+
implementationNotes, outOfScope, sourcePromptId, sourceTabId, tag, agentType, dependsOn, quietMachine, disposition, deliverable, artifactPaths, planId, macroId, effort, voiceId, riskTools, preflight,
|
|
123
141
|
gate, files, budgetExempt, fixes,
|
|
124
142
|
} = input;
|
|
143
|
+
// Structured criteria (prdCriteria.cjs): createPrd() normalizes once and
|
|
144
|
+
// passes `criteria`; a direct caller with only string criteria gets the
|
|
145
|
+
// same normalization here, so every PRD carries ids.
|
|
146
|
+
const criteria = Array.isArray(input.criteria) ? input.criteria : normalizeCriteria(acceptanceCriteria);
|
|
125
147
|
|
|
126
148
|
// No `parallelGroup` frontmatter key (PRD_AUTHORING.md §5) — the NN-
|
|
127
149
|
// filename prefix is the single source of truth for grouping; adding a
|
|
@@ -178,15 +200,21 @@ function buildPrdBody(input) {
|
|
|
178
200
|
// prdFrontmatter.cjs's applyKey for the matching "only true opts in" parse.
|
|
179
201
|
if (isValidMacroId(macroId)) fmLines.push(`macroId: ${macroId}`);
|
|
180
202
|
if (PRD_EFFORT_LEVELS.includes(effort)) fmLines.push(`effort: ${effort}`);
|
|
203
|
+
if (typeof voiceId === 'string' && VOICE_ID_RE.test(voiceId)) fmLines.push(`voiceId: ${voiceId}`);
|
|
181
204
|
// Risky tools this PRD is cleared to call — validated + de-duplicated by createPrd().
|
|
182
205
|
if (Array.isArray(riskTools) && riskTools.length) fmLines.push(`riskTools: ${formatQuotedInlineList(riskTools)}`);
|
|
206
|
+
// Precondition command — validated by createPrd() via normalizePreflightField.
|
|
207
|
+
// JSON-string form, matching prdFrontmatter.cjs's serializer.
|
|
208
|
+
if (typeof preflight === 'string' && preflight) fmLines.push(`preflight: ${JSON.stringify(preflight)}`);
|
|
183
209
|
if (quietMachine === true) fmLines.push('quietMachine: true');
|
|
184
210
|
// Budget exemption is for a sweep validator that cannot be split further;
|
|
185
211
|
// every other caller's budgetExempt is ignored.
|
|
186
212
|
if (budgetExempt === true && agentType === 'validator' && isSweepValidatorSlug(input.slug)) fmLines.push('budgetExempt: true');
|
|
213
|
+
// Normalized criteria as one-line JSON — [{ id, statement, check: { kind, spec? } }].
|
|
214
|
+
fmLines.push(`criteria: ${serializeCriteria(criteria)}`);
|
|
187
215
|
fmLines.push('---', '');
|
|
188
216
|
|
|
189
|
-
const acLines =
|
|
217
|
+
const acLines = renderCriteriaLines(criteria).join('\n');
|
|
190
218
|
const oosSource = outOfScope && outOfScope.length ? outOfScope : ['(none)'];
|
|
191
219
|
const oosLines = oosSource.map((line) => `- ${line}`).join('\n');
|
|
192
220
|
|
|
@@ -652,6 +680,11 @@ async function createPrdInner(input, remote, ctl, opts = {}) {
|
|
|
652
680
|
if (input.effort != null && !PRD_EFFORT_LEVELS.includes(input.effort)) {
|
|
653
681
|
return { ok: false, applied: false, status: 400, error: 'effort must be one of low, medium, high, xhigh, max when given' };
|
|
654
682
|
}
|
|
683
|
+
// voiceId (in-process callers only, like effort — the schedulerCreatePrd
|
|
684
|
+
// schema has no voiceId, so the HTTP/MCP path strips a caller-supplied one).
|
|
685
|
+
if (input.voiceId != null && !(typeof input.voiceId === 'string' && VOICE_ID_RE.test(input.voiceId))) {
|
|
686
|
+
return { ok: false, applied: false, status: 400, error: `voiceId must match /${VOICE_ID_RE.source}/ when given` };
|
|
687
|
+
}
|
|
655
688
|
// riskTools: tool-risk rule strings (toolRiskMarks.parseRule grammar) this PRD
|
|
656
689
|
// is cleared to call. Refused before NN allocation; de-duplicated in order.
|
|
657
690
|
if (input.riskTools != null) {
|
|
@@ -659,6 +692,23 @@ async function createPrdInner(input, remote, ctl, opts = {}) {
|
|
|
659
692
|
if (!rt.ok) return { ok: false, applied: false, status: 400, error: rt.error };
|
|
660
693
|
input = { ...input, riskTools: rt.value };
|
|
661
694
|
}
|
|
695
|
+
// preflight: one-line precondition command (preflightCheck.normalizePreflight).
|
|
696
|
+
// Refused before NN allocation; an empty value writes no key.
|
|
697
|
+
if (input.preflight !== undefined) {
|
|
698
|
+
const pf = normalizePreflightField(input.preflight);
|
|
699
|
+
if (!pf.ok) return { ok: false, applied: false, status: 400, error: pf.error };
|
|
700
|
+
input = { ...input, preflight: pf.value || undefined };
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Structured criteria (prdCriteria.cjs): strings become manual ac-<n>
|
|
704
|
+
// criteria; objects are checked per kind. Refused before NN allocation.
|
|
705
|
+
// acceptanceCriteria is rewritten to the plain statements so every
|
|
706
|
+
// string-only consumer below (heading guard, sizing, worktree reach) works.
|
|
707
|
+
{
|
|
708
|
+
const cv = validateCriteria(input.acceptanceCriteria);
|
|
709
|
+
if (!cv.ok) return { ok: false, applied: false, status: 400, error: `acceptance ${cv.error}` };
|
|
710
|
+
input = { ...input, criteria: cv.criteria, acceptanceCriteria: cv.criteria.map((c) => c.statement) };
|
|
711
|
+
}
|
|
662
712
|
|
|
663
713
|
// Fake-heading guard (gate-and-files-in-PRD-body unit): a caller-supplied
|
|
664
714
|
// free-text field that itself contains a "# Gate" or "# Files" heading line
|
|
@@ -706,7 +756,11 @@ async function createPrdInner(input, remote, ctl, opts = {}) {
|
|
|
706
756
|
return { ok: false, applied: false, status: 400, error: gateValidation.error };
|
|
707
757
|
}
|
|
708
758
|
gateCommands = gateValidation.commands;
|
|
709
|
-
|
|
759
|
+
// A validator PRD's gate is always none (it re-runs the plan's gates itself),
|
|
760
|
+
// so the none-gate warning is expected noise for it — drop only that one.
|
|
761
|
+
extraWarnings.push(...gateValidation.warnings.filter(
|
|
762
|
+
(w) => !(input.agentType === 'validator' && w === NONE_GATE_WARNING),
|
|
763
|
+
));
|
|
710
764
|
} else {
|
|
711
765
|
extraWarnings.push('No gate: the scheduler cannot re-check this PRD.');
|
|
712
766
|
}
|
|
@@ -1076,6 +1130,9 @@ async function createPrdInner(input, remote, ctl, opts = {}) {
|
|
|
1076
1130
|
commands: gateCommands || [],
|
|
1077
1131
|
},
|
|
1078
1132
|
files: filesList || [],
|
|
1133
|
+
// The preflight actually written (null = no key) — the MCP server checks
|
|
1134
|
+
// it against what the caller sent, so a dropped key is never silent.
|
|
1135
|
+
preflight: input.preflight || null,
|
|
1079
1136
|
// Advisory only (PRD 1403 sizing warnings + gate-and-files-in-PRD-body
|
|
1080
1137
|
// absent/none-gate warnings) — never blocks the write. See prdSizing.cjs
|
|
1081
1138
|
// and prdGateFiles.cjs.
|
|
@@ -1190,10 +1247,13 @@ async function createPrdBatch(inputs, remote, opts = {}) {
|
|
|
1190
1247
|
nn = nns[i];
|
|
1191
1248
|
filenameSlug = `${nn}-${p.slug}`;
|
|
1192
1249
|
const body = buildPrdBody({ ...p.input, dependsOn: fullDeps(p.input.dependsOn), planId, gate: p.gateCommands, files: p.filesList });
|
|
1250
|
+
// A validated preflight must reach the file (PRD 3805 ran unheld when one
|
|
1251
|
+
// was lost); a body without the line rolls the whole batch back.
|
|
1252
|
+
if (p.input.preflight && !/^preflight: /m.test(body)) throw new Error('preflight was not written to the PRD frontmatter');
|
|
1193
1253
|
const w = await remote.writePrd(filenameSlug, body, p.input.cwd);
|
|
1194
1254
|
if (!w?.ok) throw new Error(w?.error ?? 'write failed');
|
|
1195
1255
|
written.push({ filenameSlug, path: w.path ?? null, cwd: p.input.cwd });
|
|
1196
|
-
results.push({ slug: p.slug, nn, filename: `${filenameSlug}.md`, warnings: p.warnings });
|
|
1256
|
+
results.push({ slug: p.slug, nn, filename: `${filenameSlug}.md`, preflight: p.input.preflight || null, warnings: p.warnings });
|
|
1197
1257
|
} catch (e) {
|
|
1198
1258
|
await rollback();
|
|
1199
1259
|
return fail([{ index: i, slug: p.slug, error: `write failed (batch rolled back): ${e?.message ?? e}` }]);
|
|
@@ -1276,6 +1336,7 @@ function registerAdminRoute(adminHttp, remote) {
|
|
|
1276
1336
|
note: result.note,
|
|
1277
1337
|
gate: result.gate,
|
|
1278
1338
|
files: result.files,
|
|
1339
|
+
preflight: result.preflight ?? null,
|
|
1279
1340
|
warnings: result.warnings,
|
|
1280
1341
|
});
|
|
1281
1342
|
});
|
|
@@ -1317,6 +1378,7 @@ module.exports = {
|
|
|
1317
1378
|
createPrd,
|
|
1318
1379
|
createPrdBatch,
|
|
1319
1380
|
normalizeRiskTools,
|
|
1381
|
+
normalizePreflightField,
|
|
1320
1382
|
RISK_TOOLS_MAX,
|
|
1321
1383
|
findCrossEpicDuplicates,
|
|
1322
1384
|
validateFixesShape,
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structured PRD acceptance criteria (Managed Agents C-series primitive).
|
|
5
|
+
*
|
|
6
|
+
* A criterion is either a plain string (a `manual` criterion with a generated
|
|
7
|
+
* id `ac-<n>`) or an object `{ id?, statement, check?: { kind, spec } }` so a
|
|
8
|
+
* criterion can be checked mechanically:
|
|
9
|
+
* - command: spec is one gate command; must pass prdGateFiles.validateGate.
|
|
10
|
+
* - file: spec is a repo-relative path string, or { path, contains? }.
|
|
11
|
+
* - http: spec is a loopback URL string, or { url, status? } (status defaults to 200).
|
|
12
|
+
* - manual: spec is optional one-line guidance for the human/validator.
|
|
13
|
+
*
|
|
14
|
+
* Pure, no I/O. normalizeCriteria throws a CriteriaError naming the 1-based
|
|
15
|
+
* criterion index on any refusal; validateCriteria wraps it as a result object.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const { validateGate, validateFiles } = require('./prdGateFiles.cjs');
|
|
19
|
+
|
|
20
|
+
const CRITERIA_MAX = 100;
|
|
21
|
+
const STATEMENT_MAX_CHARS = 2000;
|
|
22
|
+
const ID_MAX_CHARS = 60;
|
|
23
|
+
const CONTAINS_MAX_CHARS = 500;
|
|
24
|
+
const MANUAL_SPEC_MAX_CHARS = 2000;
|
|
25
|
+
const ID_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
26
|
+
const CHECK_KINDS = ['command', 'file', 'http', 'manual'];
|
|
27
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
|
|
28
|
+
|
|
29
|
+
class CriteriaError extends Error {
|
|
30
|
+
/** @param {number} index 1-based criterion index (0 = the list itself) @param {string} message */
|
|
31
|
+
constructor(index, message) {
|
|
32
|
+
super(index > 0 ? `criteria entry ${index}: ${message}` : message);
|
|
33
|
+
this.name = 'CriteriaError';
|
|
34
|
+
this.index = index;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function oneLine(value, max, what, idx) {
|
|
39
|
+
if (typeof value !== 'string' || value.trim() === '') throw new CriteriaError(idx, `${what} must be a non-empty string.`);
|
|
40
|
+
const s = value.trim();
|
|
41
|
+
if (/[\r\n]/.test(s)) throw new CriteriaError(idx, `${what} must not contain a newline.`);
|
|
42
|
+
if (s.length > max) throw new CriteriaError(idx, `${what} must be at most ${max} chars.`);
|
|
43
|
+
return s;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeCommand(spec, idx) {
|
|
47
|
+
const cmd = oneLine(spec, 1000, 'command check spec', idx);
|
|
48
|
+
const v = validateGate([cmd]);
|
|
49
|
+
if (!v.ok) throw new CriteriaError(idx, `command check spec is not a valid gate command: ${v.error}`);
|
|
50
|
+
if (v.commands.length === 1 && v.commands[0] === 'none') {
|
|
51
|
+
throw new CriteriaError(idx, 'command check spec must be a runnable command, not "none" (use a manual check).');
|
|
52
|
+
}
|
|
53
|
+
return v.commands[0];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function normalizeFile(spec, idx) {
|
|
57
|
+
const obj = typeof spec === 'string' ? { path: spec } : spec;
|
|
58
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
59
|
+
throw new CriteriaError(idx, 'file check spec must be a repo-relative path or { path, contains? }.');
|
|
60
|
+
}
|
|
61
|
+
const extra = Object.keys(obj).filter((k) => k !== 'path' && k !== 'contains');
|
|
62
|
+
if (extra.length) throw new CriteriaError(idx, `file check spec has unknown key(s): ${extra.join(', ')}.`);
|
|
63
|
+
const p = oneLine(obj.path, 1000, 'file check path', idx);
|
|
64
|
+
const v = validateFiles([p]);
|
|
65
|
+
if (!v.ok) throw new CriteriaError(idx, `file check path is not a repo-relative path: ${v.error}`);
|
|
66
|
+
const out = { path: v.files[0] };
|
|
67
|
+
if (obj.contains !== undefined) out.contains = oneLine(obj.contains, CONTAINS_MAX_CHARS, 'file check contains', idx);
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function normalizeHttp(spec, idx) {
|
|
72
|
+
const obj = typeof spec === 'string' ? { url: spec } : spec;
|
|
73
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
74
|
+
throw new CriteriaError(idx, 'http check spec must be a loopback URL or { url, status? }.');
|
|
75
|
+
}
|
|
76
|
+
const extra = Object.keys(obj).filter((k) => k !== 'url' && k !== 'status');
|
|
77
|
+
if (extra.length) throw new CriteriaError(idx, `http check spec has unknown key(s): ${extra.join(', ')}.`);
|
|
78
|
+
const raw = oneLine(obj.url, 2000, 'http check url', idx);
|
|
79
|
+
let url;
|
|
80
|
+
try {
|
|
81
|
+
url = new URL(raw);
|
|
82
|
+
} catch {
|
|
83
|
+
throw new CriteriaError(idx, 'http check url is not a valid URL.');
|
|
84
|
+
}
|
|
85
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
86
|
+
throw new CriteriaError(idx, 'http check url must use http or https.');
|
|
87
|
+
}
|
|
88
|
+
if (url.username || url.password) throw new CriteriaError(idx, 'http check url must not carry credentials.');
|
|
89
|
+
if (!LOOPBACK_HOSTS.has(url.hostname)) {
|
|
90
|
+
throw new CriteriaError(idx, `http check url must be loopback only (localhost, 127.0.0.1 or [::1]); got host "${url.hostname}".`);
|
|
91
|
+
}
|
|
92
|
+
const status = obj.status === undefined ? 200 : obj.status;
|
|
93
|
+
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
94
|
+
throw new CriteriaError(idx, 'http check status must be an integer from 100 to 599.');
|
|
95
|
+
}
|
|
96
|
+
return { url: url.href, status };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function normalizeCheck(check, idx) {
|
|
100
|
+
if (check === undefined || check === null) return { kind: 'manual' };
|
|
101
|
+
if (typeof check !== 'object' || Array.isArray(check)) throw new CriteriaError(idx, 'check must be an object { kind, spec }.');
|
|
102
|
+
const extra = Object.keys(check).filter((k) => k !== 'kind' && k !== 'spec');
|
|
103
|
+
if (extra.length) throw new CriteriaError(idx, `check has unknown key(s): ${extra.join(', ')}.`);
|
|
104
|
+
const { kind, spec } = check;
|
|
105
|
+
if (!CHECK_KINDS.includes(kind)) {
|
|
106
|
+
throw new CriteriaError(idx, `check kind must be one of ${CHECK_KINDS.join(', ')} (got ${JSON.stringify(kind)}).`);
|
|
107
|
+
}
|
|
108
|
+
if (kind === 'manual') {
|
|
109
|
+
if (spec === undefined || spec === null) return { kind };
|
|
110
|
+
return { kind, spec: oneLine(spec, MANUAL_SPEC_MAX_CHARS, 'manual check spec', idx) };
|
|
111
|
+
}
|
|
112
|
+
if (spec === undefined || spec === null) throw new CriteriaError(idx, `${kind} check needs a spec.`);
|
|
113
|
+
if (kind === 'command') return { kind, spec: normalizeCommand(spec, idx) };
|
|
114
|
+
if (kind === 'file') return { kind, spec: normalizeFile(spec, idx) };
|
|
115
|
+
return { kind, spec: normalizeHttp(spec, idx) };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {unknown} input array of string | { id?, statement, check? }
|
|
120
|
+
* @param {{ previous?: unknown }} [opts] previous: the PRD's current normalized
|
|
121
|
+
* criteria (update path). An entry with no explicit id whose statement
|
|
122
|
+
* matches a previous criterion keeps that criterion's id, so re-sending the
|
|
123
|
+
* same lines in a new order or with one line added never renumbers the rest.
|
|
124
|
+
* A generated id that is already taken moves to the next free ac-<n>.
|
|
125
|
+
* @returns {Array<{id: string, statement: string, check: {kind: string, spec?: unknown}}>}
|
|
126
|
+
*/
|
|
127
|
+
function normalizeCriteria(input, opts = {}) {
|
|
128
|
+
const previousIds = new Map();
|
|
129
|
+
if (Array.isArray(opts.previous)) {
|
|
130
|
+
for (const p of opts.previous) {
|
|
131
|
+
if (p && typeof p.id === 'string' && typeof p.statement === 'string' && !previousIds.has(p.statement)) {
|
|
132
|
+
previousIds.set(p.statement, p.id);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!Array.isArray(input) || input.length === 0 || input.length > CRITERIA_MAX) {
|
|
137
|
+
throw new CriteriaError(0, `criteria must be an array of 1 to ${CRITERIA_MAX} entries.`);
|
|
138
|
+
}
|
|
139
|
+
const out = [];
|
|
140
|
+
const seen = new Map();
|
|
141
|
+
for (let i = 0; i < input.length; i++) {
|
|
142
|
+
const idx = i + 1;
|
|
143
|
+
const entry = input[i];
|
|
144
|
+
let crit;
|
|
145
|
+
if (typeof entry === 'string') {
|
|
146
|
+
crit = { id: null, statement: oneLine(entry, STATEMENT_MAX_CHARS, 'statement', idx), check: { kind: 'manual' } };
|
|
147
|
+
} else if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
|
|
148
|
+
const extra = Object.keys(entry).filter((k) => k !== 'id' && k !== 'statement' && k !== 'check');
|
|
149
|
+
if (extra.length) throw new CriteriaError(idx, `unknown key(s): ${extra.join(', ')}.`);
|
|
150
|
+
let id = null;
|
|
151
|
+
if (entry.id !== undefined) {
|
|
152
|
+
if (typeof entry.id !== 'string' || !ID_RE.test(entry.id) || entry.id.length > ID_MAX_CHARS) {
|
|
153
|
+
throw new CriteriaError(idx, `id must be a kebab-case id (a-z, 0-9, single dashes, at most ${ID_MAX_CHARS} chars).`);
|
|
154
|
+
}
|
|
155
|
+
id = entry.id;
|
|
156
|
+
}
|
|
157
|
+
crit = {
|
|
158
|
+
id,
|
|
159
|
+
statement: oneLine(entry.statement, STATEMENT_MAX_CHARS, 'statement', idx),
|
|
160
|
+
check: normalizeCheck(entry.check, idx),
|
|
161
|
+
};
|
|
162
|
+
} else {
|
|
163
|
+
throw new CriteriaError(idx, 'must be a string or an object { id?, statement, check? }.');
|
|
164
|
+
}
|
|
165
|
+
if (crit.id === null) {
|
|
166
|
+
const reused = previousIds.get(crit.statement);
|
|
167
|
+
if (reused && !seen.has(reused)) {
|
|
168
|
+
crit.id = reused;
|
|
169
|
+
} else {
|
|
170
|
+
let n = idx;
|
|
171
|
+
while (previousIds.size && (seen.has(`ac-${n}`) || reservedByPrevious(previousIds, `ac-${n}`, input, i))) n++;
|
|
172
|
+
crit.id = `ac-${n}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (seen.has(crit.id)) {
|
|
176
|
+
throw new CriteriaError(idx, `duplicate id "${crit.id}" (already used by entry ${seen.get(crit.id)}).`);
|
|
177
|
+
}
|
|
178
|
+
seen.set(crit.id, idx);
|
|
179
|
+
out.push(crit);
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* True when `id` belongs to a previous criterion whose statement appears
|
|
186
|
+
* later in `input` (that later entry will reclaim it), so a generated id
|
|
187
|
+
* must not take it first.
|
|
188
|
+
*/
|
|
189
|
+
function reservedByPrevious(previousIds, id, input, fromIndex) {
|
|
190
|
+
for (let j = fromIndex + 1; j < input.length; j++) {
|
|
191
|
+
const e = input[j];
|
|
192
|
+
const stmt = typeof e === 'string' ? e.trim() : (e && typeof e === 'object' && e.id === undefined && typeof e.statement === 'string' ? e.statement.trim() : null);
|
|
193
|
+
if (stmt !== null && previousIds.get(stmt) === id) return true;
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Result-object wrapper for callers that accumulate errors (createPrd). */
|
|
199
|
+
function validateCriteria(input, opts) {
|
|
200
|
+
try {
|
|
201
|
+
return { ok: true, criteria: normalizeCriteria(input, opts) };
|
|
202
|
+
} catch (e) {
|
|
203
|
+
if (e instanceof CriteriaError) return { ok: false, error: e.message, index: e.index };
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** One-line JSON for the PRD frontmatter `criteria:` key. */
|
|
209
|
+
function serializeCriteria(criteria) {
|
|
210
|
+
return JSON.stringify(criteria);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** `- [ ] <id>: <statement>` checklist lines for # Acceptance criteria. */
|
|
214
|
+
function renderCriteriaLines(criteria) {
|
|
215
|
+
return criteria.map((c) => `- [ ] ${c.id}: ${c.statement}`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
module.exports = {
|
|
219
|
+
normalizeCriteria,
|
|
220
|
+
validateCriteria,
|
|
221
|
+
serializeCriteria,
|
|
222
|
+
renderCriteriaLines,
|
|
223
|
+
CriteriaError,
|
|
224
|
+
CHECK_KINDS,
|
|
225
|
+
};
|
|
@@ -78,13 +78,18 @@ function splitFrontmatter(raw) {
|
|
|
78
78
|
*
|
|
79
79
|
* `fixes` (the earlier PRDs this one repairs) is a one-line JSON array of
|
|
80
80
|
* { prd, missKind, reason } — see parseFixes.
|
|
81
|
+
*
|
|
82
|
+
* `criteria` (structured acceptance criteria, prdCriteria.cjs) is a one-line
|
|
83
|
+
* JSON array of { id, statement, check: { kind, spec? } } — see parseCriteria.
|
|
81
84
|
*/
|
|
82
85
|
|
|
83
|
-
const RECOGNIZED_KEYS = new Set(['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'riskTools']);
|
|
84
|
-
const EMIT_ORDER = ['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'riskTools'];
|
|
86
|
+
const RECOGNIZED_KEYS = new Set(['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'voiceId', 'riskTools', 'preflight', 'criteria']);
|
|
87
|
+
const EMIT_ORDER = ['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'voiceId', 'riskTools', 'preflight', 'criteria'];
|
|
85
88
|
// Mirrors modelCatalog.cjs CATALOG_FLOOR.effortLevels. A closed set so the
|
|
86
89
|
// value is always safe as a frontmatter line and as a --effort argv token.
|
|
87
90
|
const PRD_EFFORT_LEVELS = Object.freeze(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
91
|
+
// Voice-library id (in-process only, like effort); the one owner is voiceLibrary.cjs.
|
|
92
|
+
const { VOICE_ID_RE } = require('../demo-video-kit/voiceLibrary.cjs');
|
|
88
93
|
const MACRO_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
89
94
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
90
95
|
|
|
@@ -211,6 +216,26 @@ function parseFixes(raw) {
|
|
|
211
216
|
return out;
|
|
212
217
|
}
|
|
213
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Parse the `criteria` value — a one-line JSON array of { id, statement,
|
|
221
|
+
* check: { kind, spec? } } (the sole form prdCreate.cjs writes; shape rules
|
|
222
|
+
* live in prdCriteria.cjs, not required here because definitionOfDone.cjs ->
|
|
223
|
+
* this file would cycle). Returns null for anything malformed.
|
|
224
|
+
*/
|
|
225
|
+
function parseCriteria(raw) {
|
|
226
|
+
const v = String(raw ?? '').trim();
|
|
227
|
+
if (!v.startsWith('[')) return null;
|
|
228
|
+
let arr;
|
|
229
|
+
try { arr = JSON.parse(v); } catch { return null; }
|
|
230
|
+
if (!Array.isArray(arr)) return null;
|
|
231
|
+
for (const e of arr) {
|
|
232
|
+
if (e == null || typeof e !== 'object' || Array.isArray(e)) return null;
|
|
233
|
+
if (typeof e.id !== 'string' || typeof e.statement !== 'string') return null;
|
|
234
|
+
if (e.check == null || typeof e.check !== 'object' || typeof e.check.kind !== 'string') return null;
|
|
235
|
+
}
|
|
236
|
+
return arr;
|
|
237
|
+
}
|
|
238
|
+
|
|
214
239
|
function arraysEqual(a, b) {
|
|
215
240
|
if (!Array.isArray(a) || !Array.isArray(b)) return false;
|
|
216
241
|
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
@@ -267,6 +292,11 @@ function applyKey(fm, key, after) {
|
|
|
267
292
|
if (list && list.length) fm.fixes = list;
|
|
268
293
|
return;
|
|
269
294
|
}
|
|
295
|
+
case 'criteria': {
|
|
296
|
+
const list = parseCriteria(after);
|
|
297
|
+
if (list && list.length) fm.criteria = list;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
270
300
|
case 'quietMachine':
|
|
271
301
|
// Opt-in exclusive-lease flag (PRD 1107) — only a literal `true`
|
|
272
302
|
// frontmatter value opts in; anything else (including an explicit
|
|
@@ -297,6 +327,10 @@ function applyKey(fm, key, after) {
|
|
|
297
327
|
// In-process-only per-PRD effort override; anything outside PRD_EFFORT_LEVELS is dropped.
|
|
298
328
|
if (typeof v === 'string' && PRD_EFFORT_LEVELS.includes(v.trim())) fm.effort = v.trim();
|
|
299
329
|
return;
|
|
330
|
+
case 'voiceId':
|
|
331
|
+
// In-process-only per-PRD library voice; anything off VOICE_ID_RE is dropped.
|
|
332
|
+
if (typeof v === 'string' && VOICE_ID_RE.test(v.trim())) fm.voiceId = v.trim();
|
|
333
|
+
return;
|
|
300
334
|
case 'artifactPaths': {
|
|
301
335
|
// Inline `[a, b]` list, same shape as dependsOn.
|
|
302
336
|
const list = parseInlineList(after);
|
|
@@ -309,9 +343,29 @@ function applyKey(fm, key, after) {
|
|
|
309
343
|
if (list) fm.riskTools = list;
|
|
310
344
|
return;
|
|
311
345
|
}
|
|
346
|
+
case 'preflight': {
|
|
347
|
+
// One-line precondition command (preflightCheck.cjs). Written as a JSON
|
|
348
|
+
// string so quotes/`#` inside a command survive; a bare hand-written
|
|
349
|
+
// value is read as-is.
|
|
350
|
+
const s = parsePreflightValue(after);
|
|
351
|
+
if (s) fm.preflight = s;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
312
354
|
}
|
|
313
355
|
}
|
|
314
356
|
|
|
357
|
+
function parsePreflightValue(raw) {
|
|
358
|
+
const t = String(raw ?? '').trim();
|
|
359
|
+
if (t.startsWith('"')) {
|
|
360
|
+
try {
|
|
361
|
+
const j = JSON.parse(t);
|
|
362
|
+
if (typeof j === 'string') return j.trim() || null;
|
|
363
|
+
} catch { /* fall through to the bare form */ }
|
|
364
|
+
}
|
|
365
|
+
const s = t.length >= 2 && t.startsWith("'") && t.endsWith("'") ? t.slice(1, -1) : t;
|
|
366
|
+
return s.trim() || null;
|
|
367
|
+
}
|
|
368
|
+
|
|
315
369
|
/** Parse a full PRD file into { frontmatter, body }, same shape as the TS module. */
|
|
316
370
|
function parsePrdFile(text) {
|
|
317
371
|
const m = text.match(FRONTMATTER_RE);
|
|
@@ -344,7 +398,7 @@ function parsePrdFile(text) {
|
|
|
344
398
|
|
|
345
399
|
if (RECOGNIZED_KEYS.has(key)) {
|
|
346
400
|
applyKey(fm, key, after);
|
|
347
|
-
if (key === 'dependsOn' || key === 'artifactPaths' || key === 'fixes' || key === 'riskTools') {
|
|
401
|
+
if (key === 'dependsOn' || key === 'artifactPaths' || key === 'fixes' || key === 'riskTools' || key === 'preflight' || key === 'criteria') {
|
|
348
402
|
if (fm[key]) {
|
|
349
403
|
if (!fm._raw) fm._raw = {};
|
|
350
404
|
fm._raw[key] = { line, parsed: fm[key] };
|
|
@@ -393,6 +447,11 @@ function serializePrdFile(fm, body) {
|
|
|
393
447
|
// dependency — never emitted, same as an absent key.
|
|
394
448
|
if (Array.isArray(v) && v.length === 0) continue;
|
|
395
449
|
const cached = fm._raw?.[key];
|
|
450
|
+
if (key === 'criteria') {
|
|
451
|
+
const line = `criteria: ${JSON.stringify(v)}`;
|
|
452
|
+
out.push(cached && cached.line.trim() === line ? cached.line : line);
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
396
455
|
if (key === 'fixes') {
|
|
397
456
|
const line = `fixes: ${JSON.stringify(v.map((f) => ({ prd: f.prd, missKind: f.missKind, reason: f.reason })))}`;
|
|
398
457
|
out.push(cached && cached.line.trim() === line ? cached.line : line);
|
|
@@ -410,6 +469,10 @@ function serializePrdFile(fm, body) {
|
|
|
410
469
|
out.push(`${key}: ${formatQuotedInlineList(v)}`);
|
|
411
470
|
continue;
|
|
412
471
|
}
|
|
472
|
+
if (key === 'preflight') {
|
|
473
|
+
out.push(`${key}: ${JSON.stringify(String(v))}`);
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
413
476
|
if (Array.isArray(v)) {
|
|
414
477
|
out.push(`${key}: [${v.join(', ')}]`);
|
|
415
478
|
continue;
|
|
@@ -430,12 +493,14 @@ function serializePrdFile(fm, body) {
|
|
|
430
493
|
|
|
431
494
|
module.exports = {
|
|
432
495
|
splitFrontmatter,
|
|
496
|
+
parsePreflightValue,
|
|
433
497
|
parsePrdFile,
|
|
434
498
|
serializePrdFile,
|
|
435
499
|
parseInlineList,
|
|
436
500
|
parseQuotedInlineList,
|
|
437
501
|
formatQuotedInlineList,
|
|
438
502
|
parseFixes,
|
|
503
|
+
parseCriteria,
|
|
439
504
|
isArtifactOnlyDeclaration,
|
|
440
505
|
RECOGNIZED_KEYS,
|
|
441
506
|
PRD_EFFORT_LEVELS,
|