claude-code-session-manager 0.141.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-DJMiuXyK.js → History-DpZuJXi1.js} +1 -1
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-BjdJjhqt.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
- package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-vv0noNVI.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-CXi8Pvut.js} +1 -1
- package/dist/assets/Toggle-CiYCWLjh.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-4NKKd1sC.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.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/develop/SKILL.md +52 -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 +732 -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 +161 -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 +304 -28
- 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 +41 -5
- package/src/main/lib/prd/prdCriteria.cjs +225 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +43 -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/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 +46 -13
- package/src/main/scheduler/reviewLadder.cjs +9 -25
- package/src/main/scheduler/utilizationHold.cjs +101 -0
- package/src/main/scheduler.cjs +1414 -189
- package/src/main/templates/PRD_AUTHORING.md +5 -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-DExeJhqQ.js +0 -2
- package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
- package/dist/assets/Scheduler-cyr61UAC.js +0 -16
- package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
- package/dist/assets/index-B2TQz3nd.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
|
@@ -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', 'preflight']);
|
|
84
|
-
const EMIT_ORDER = ['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'riskTools', 'preflight'];
|
|
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);
|
|
@@ -364,7 +398,7 @@ function parsePrdFile(text) {
|
|
|
364
398
|
|
|
365
399
|
if (RECOGNIZED_KEYS.has(key)) {
|
|
366
400
|
applyKey(fm, key, after);
|
|
367
|
-
if (key === 'dependsOn' || key === 'artifactPaths' || key === 'fixes' || key === 'riskTools' || key === 'preflight') {
|
|
401
|
+
if (key === 'dependsOn' || key === 'artifactPaths' || key === 'fixes' || key === 'riskTools' || key === 'preflight' || key === 'criteria') {
|
|
368
402
|
if (fm[key]) {
|
|
369
403
|
if (!fm._raw) fm._raw = {};
|
|
370
404
|
fm._raw[key] = { line, parsed: fm[key] };
|
|
@@ -413,6 +447,11 @@ function serializePrdFile(fm, body) {
|
|
|
413
447
|
// dependency — never emitted, same as an absent key.
|
|
414
448
|
if (Array.isArray(v) && v.length === 0) continue;
|
|
415
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
|
+
}
|
|
416
455
|
if (key === 'fixes') {
|
|
417
456
|
const line = `fixes: ${JSON.stringify(v.map((f) => ({ prd: f.prd, missKind: f.missKind, reason: f.reason })))}`;
|
|
418
457
|
out.push(cached && cached.line.trim() === line ? cached.line : line);
|
|
@@ -461,6 +500,7 @@ module.exports = {
|
|
|
461
500
|
parseQuotedInlineList,
|
|
462
501
|
formatQuotedInlineList,
|
|
463
502
|
parseFixes,
|
|
503
|
+
parseCriteria,
|
|
464
504
|
isArtifactOnlyDeclaration,
|
|
465
505
|
RECOGNIZED_KEYS,
|
|
466
506
|
PRD_EFFORT_LEVELS,
|
|
@@ -145,6 +145,40 @@ function validateGate(gate) {
|
|
|
145
145
|
return { ok: true, commands: trimmed, warnings };
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
* The one per-entry `files` rule set, shared by validateFiles (create time)
|
|
150
|
+
* and parseFilesSection (read back from any PRD body, including ones written
|
|
151
|
+
* raw outside the API). `entry` must already be trimmed and non-empty.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} entry
|
|
154
|
+
* @returns {{ok:true, path:string}|{ok:false, reason:string}}
|
|
155
|
+
* path has every leading `./` stripped.
|
|
156
|
+
*/
|
|
157
|
+
function isValidFilesEntry(entry) {
|
|
158
|
+
if (typeof entry !== 'string' || entry.length === 0) return { ok: false, reason: 'must not be empty.' };
|
|
159
|
+
if (entry.length > FILES_ENTRY_MAX_CHARS) return { ok: false, reason: `must be at most ${FILES_ENTRY_MAX_CHARS} chars.` };
|
|
160
|
+
if (/[\r\n]/.test(entry)) return { ok: false, reason: 'must not contain a newline.' };
|
|
161
|
+
if (FILES_FOREIGN_WHITESPACE_RE.test(entry)) {
|
|
162
|
+
return { ok: false, reason: 'has a character that is not a plain space (for example a tab, a no-break space, or a line break). Retype it.' };
|
|
163
|
+
}
|
|
164
|
+
if (entry.includes('\\')) return { ok: false, reason: 'use "/" between folders, not "\\".' };
|
|
165
|
+
if (entry.includes('`')) return { ok: false, reason: 'must not contain a backtick.' };
|
|
166
|
+
if (entry.startsWith('-')) return { ok: false, reason: 'must not start with "-".' };
|
|
167
|
+
if (entry.startsWith('/') || entry.startsWith('~') || /^[A-Za-z]:/.test(entry)) {
|
|
168
|
+
return { ok: false, reason: 'must be repo-relative — absolute paths are not allowed.' };
|
|
169
|
+
}
|
|
170
|
+
if (entry.includes('*') || entry.includes('?')) return { ok: false, reason: 'must not contain "*" or "?" (no globs).' };
|
|
171
|
+
|
|
172
|
+
let normalized = entry;
|
|
173
|
+
while (normalized.startsWith('./')) normalized = normalized.slice(2);
|
|
174
|
+
if (normalized.length === 0) return { ok: false, reason: 'is empty after removing "./".' };
|
|
175
|
+
const segments = normalized.split('/');
|
|
176
|
+
if (segments.includes('..')) return { ok: false, reason: 'must not contain a ".." path segment.' };
|
|
177
|
+
if (segments.includes('.')) return { ok: false, reason: 'must not contain a "." path segment.' };
|
|
178
|
+
if (normalized.includes('//')) return { ok: false, reason: 'must not contain an empty path segment ("//").' };
|
|
179
|
+
return { ok: true, path: normalized };
|
|
180
|
+
}
|
|
181
|
+
|
|
148
182
|
/**
|
|
149
183
|
* Validate a PRD's `files` field.
|
|
150
184
|
*
|
|
@@ -173,50 +207,11 @@ function validateFiles(files) {
|
|
|
173
207
|
if (entry.length === 0) {
|
|
174
208
|
return { ok: false, error: `files entry ${idx}: must not be empty.` };
|
|
175
209
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (/[\r\n]/.test(entry)) {
|
|
180
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a newline.') };
|
|
181
|
-
}
|
|
182
|
-
if (FILES_FOREIGN_WHITESPACE_RE.test(entry)) {
|
|
183
|
-
return {
|
|
184
|
-
ok: false,
|
|
185
|
-
error: entryError('files', idx, entry, 'has a character that is not a plain space (for example a tab, a no-break space, or a line break). Retype it.'),
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
if (entry.includes('\\')) {
|
|
189
|
-
return { ok: false, error: entryError('files', idx, entry, 'use "/" between folders, not "\\".') };
|
|
190
|
-
}
|
|
191
|
-
if (entry.includes('`')) {
|
|
192
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a backtick.') };
|
|
193
|
-
}
|
|
194
|
-
if (entry.startsWith('-')) {
|
|
195
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not start with "-".') };
|
|
196
|
-
}
|
|
197
|
-
if (entry.startsWith('/') || entry.startsWith('~') || /^[A-Za-z]:/.test(entry)) {
|
|
198
|
-
return { ok: false, error: entryError('files', idx, entry, 'must be repo-relative — absolute paths are not allowed.') };
|
|
199
|
-
}
|
|
200
|
-
if (entry.includes('*') || entry.includes('?')) {
|
|
201
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain "*" or "?" (no globs).') };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
let normalized = entry;
|
|
205
|
-
while (normalized.startsWith('./')) normalized = normalized.slice(2);
|
|
206
|
-
if (normalized.length === 0) {
|
|
207
|
-
return { ok: false, error: entryError('files', idx, entry, 'is empty after removing "./".') };
|
|
208
|
-
}
|
|
209
|
-
const segments = normalized.split('/');
|
|
210
|
-
if (segments.includes('..')) {
|
|
211
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a ".." path segment.') };
|
|
210
|
+
const checked = isValidFilesEntry(entry);
|
|
211
|
+
if (!checked.ok) {
|
|
212
|
+
return { ok: false, error: entryError('files', idx, entry, checked.reason) };
|
|
212
213
|
}
|
|
213
|
-
|
|
214
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain a "." path segment.') };
|
|
215
|
-
}
|
|
216
|
-
if (normalized.includes('//')) {
|
|
217
|
-
return { ok: false, error: entryError('files', idx, entry, 'must not contain an empty path segment ("//").') };
|
|
218
|
-
}
|
|
219
|
-
|
|
214
|
+
const normalized = checked.path;
|
|
220
215
|
if (!seen.has(normalized)) {
|
|
221
216
|
seen.add(normalized);
|
|
222
217
|
out.push(normalized);
|
|
@@ -247,8 +242,10 @@ function renderFilesSection(files) {
|
|
|
247
242
|
/**
|
|
248
243
|
* Inverse of renderFilesSection: read the bullet entries under the `# Files`
|
|
249
244
|
* heading (up to the next top-level heading) back out of a PRD body. Returns
|
|
250
|
-
* [] when there is no such section
|
|
251
|
-
*
|
|
245
|
+
* [] when there is no such section; never throws. Each bullet keeps only the
|
|
246
|
+
* paths that pass isValidFilesEntry (see parseFilesEntry) — a trailing note
|
|
247
|
+
* is cut off, a ", " list is split, prose and invalid bullets are dropped,
|
|
248
|
+
* duplicates removed.
|
|
252
249
|
*
|
|
253
250
|
* @param {string} body
|
|
254
251
|
* @returns {string[]}
|
|
@@ -266,14 +263,92 @@ function parseFilesSection(body) {
|
|
|
266
263
|
if (!inFence && /^#\s/.test(line)) break;
|
|
267
264
|
const m = line.match(/^[-*]\s+(.+?)\s*$/);
|
|
268
265
|
if (!m) continue;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (entry && !out.includes(entry)) out.push(entry);
|
|
266
|
+
for (const entry of parseFilesEntry(m[1])) {
|
|
267
|
+
if (!out.includes(entry)) out.push(entry);
|
|
268
|
+
}
|
|
273
269
|
}
|
|
274
270
|
return out;
|
|
275
271
|
}
|
|
276
272
|
|
|
273
|
+
const unwrapTicks = (s) => { const t = s.match(/^`([^`]+)`$/); return (t ? t[1] : s).trim(); };
|
|
274
|
+
|
|
275
|
+
// Separators a `# Files` bullet uses between a path and a note (or, for
|
|
276
|
+
// ", ", between two paths). Matched only when what comes before is a path.
|
|
277
|
+
const FILES_NOTE_SEPARATORS = [' (', ' - ', ' — ', ': ', ', '];
|
|
278
|
+
|
|
279
|
+
/** The validated path when `s` is a valid entry ending in a file extension or "/", else null. */
|
|
280
|
+
function pathLikePrefix(s) {
|
|
281
|
+
const lead = unwrapTicks(s);
|
|
282
|
+
if (!lead) return null;
|
|
283
|
+
const checked = isValidFilesEntry(lead);
|
|
284
|
+
if (!checked.ok) return null;
|
|
285
|
+
return /\.[A-Za-z0-9]+$/.test(checked.path) || checked.path.endsWith('/') ? checked.path : null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Note separators (", " excluded — it lists paths, never a note).
|
|
289
|
+
const FILES_WHOLE_TIEBREAK_SEPARATORS = FILES_NOTE_SEPARATORS.filter((sep) => sep !== ', ');
|
|
290
|
+
|
|
291
|
+
/** True when `text` has no note separator, or the text after its earliest one is a single whitespace-free token. */
|
|
292
|
+
function isSingleTokenRemainder(text) {
|
|
293
|
+
let earliest = null;
|
|
294
|
+
for (const sep of FILES_WHOLE_TIEBREAK_SEPARATORS) {
|
|
295
|
+
const at = text.indexOf(sep);
|
|
296
|
+
if (at > 0 && (earliest === null || at < earliest.at)) earliest = { at, sep };
|
|
297
|
+
}
|
|
298
|
+
if (earliest === null) return true;
|
|
299
|
+
const rest = text.slice(earliest.at + earliest.sep.length);
|
|
300
|
+
return rest.length > 0 && !/\s/.test(rest);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* One `# Files` bullet's text -> the paths it names ([] when none). An
|
|
305
|
+
* entry with no ", " that is itself a path (valid, ending in a file
|
|
306
|
+
* extension or "/") is kept whole first, but only when the text after its
|
|
307
|
+
* earliest note separator (" (", " - ", " — ", ": ") is one whitespace-free
|
|
308
|
+
* token — more than one word there is a note. Otherwise walks
|
|
309
|
+
* every separator occurrence (" (", " - ", " — ", ": ", ", ") left to right
|
|
310
|
+
* and splits at the first whose prefix is a path (valid entry ending in a
|
|
311
|
+
* file extension or "/"): after ", " the rest is parsed again as more
|
|
312
|
+
* entries; after any other separator the rest is a note and dropped. With no
|
|
313
|
+
* such split, the whole (unwrapped) entry is kept when it passes
|
|
314
|
+
* isValidFilesEntry — so a spaced path like "docs/A - B.md" round-trips. A
|
|
315
|
+
* whole entry with a space must still look like a path (contain "/", not end
|
|
316
|
+
* in sentence punctuation) — the API allows spaced paths, but a spaced entry
|
|
317
|
+
* with neither is prose.
|
|
318
|
+
*
|
|
319
|
+
* @param {string} raw
|
|
320
|
+
* @returns {string[]}
|
|
321
|
+
*/
|
|
322
|
+
function parseFilesEntry(raw) {
|
|
323
|
+
const text = unwrapTicks(String(raw).trim());
|
|
324
|
+
if (!text) return [];
|
|
325
|
+
// A whole entry that is itself a path wins over a note split only when the
|
|
326
|
+
// text after its earliest note separator is one whitespace-free token, so
|
|
327
|
+
// "docs/v1.2 - notes.md" is not cut to "docs/v1.2" but "src/a.cjs -
|
|
328
|
+
// renamed from old.cjs" is a note. A ", " list still splits:
|
|
329
|
+
// "src/a.cjs, src/b.cjs" is two paths, not one spaced name.
|
|
330
|
+
if (!text.includes(', ')) {
|
|
331
|
+
const whole = pathLikePrefix(text);
|
|
332
|
+
if (whole && isSingleTokenRemainder(text)) return [whole];
|
|
333
|
+
}
|
|
334
|
+
/** @type {{at:number, sep:string}[]} */
|
|
335
|
+
const hits = [];
|
|
336
|
+
for (const sep of FILES_NOTE_SEPARATORS) {
|
|
337
|
+
for (let at = text.indexOf(sep); at > 0; at = text.indexOf(sep, at + 1)) hits.push({ at, sep });
|
|
338
|
+
}
|
|
339
|
+
hits.sort((a, b) => a.at - b.at);
|
|
340
|
+
for (const { at, sep } of hits) {
|
|
341
|
+
const lead = pathLikePrefix(text.slice(0, at));
|
|
342
|
+
if (!lead) continue;
|
|
343
|
+
if (sep !== ', ') return [lead];
|
|
344
|
+
return [lead, ...parseFilesEntry(text.slice(at + sep.length))];
|
|
345
|
+
}
|
|
346
|
+
const checked = isValidFilesEntry(text);
|
|
347
|
+
if (!checked.ok) return [];
|
|
348
|
+
if (/\s/.test(checked.path) && (!checked.path.includes('/') || /[.,:;!?)]$/.test(checked.path))) return [];
|
|
349
|
+
return [checked.path];
|
|
350
|
+
}
|
|
351
|
+
|
|
277
352
|
/**
|
|
278
353
|
* Render the `# Gate` body section as an array of lines. `commandsOrNone`
|
|
279
354
|
* must already be validated (validateGate's `commands` output) — either
|
|
@@ -307,6 +382,7 @@ function renderGateSection(commandsOrNone) {
|
|
|
307
382
|
}
|
|
308
383
|
|
|
309
384
|
module.exports = {
|
|
385
|
+
NONE_GATE_WARNING,
|
|
310
386
|
validateGate,
|
|
311
387
|
validateFiles,
|
|
312
388
|
renderFilesSection,
|
|
@@ -35,7 +35,9 @@ function sizingWarnings(input) {
|
|
|
35
35
|
|
|
36
36
|
const warnings = [];
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
// A validator PRD's criteria list one check per PRD in its plan, so a long
|
|
39
|
+
// list is expected; every other sizing rule still applies to it.
|
|
40
|
+
if (input?.agentType !== 'validator' && acceptanceCriteria.length > SIZING_LIMITS.acLines) {
|
|
39
41
|
warnings.push(
|
|
40
42
|
`acceptanceCriteria has ${acceptanceCriteria.length} lines, exceeding the ${SIZING_LIMITS.acLines}-line sizing limit — split into smaller, single-purpose PRDs.`,
|
|
41
43
|
);
|
|
@@ -102,4 +102,55 @@ function cleanChildEnv(extra = {}) {
|
|
|
102
102
|
return env;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
/**
|
|
106
|
+
* The ONLY spawn sites allowed to hand a headless child an env that still
|
|
107
|
+
* carries secret-shaped keys. Both are internal one-shot `claude -p` helpers
|
|
108
|
+
* that deliberately inherit process.env verbatim (withProcRole, not
|
|
109
|
+
* cleanChildEnv). Adding an entry is a deliberate security decision.
|
|
110
|
+
*/
|
|
111
|
+
const CREDENTIAL_EXCEPTIONS = Object.freeze([
|
|
112
|
+
Object.freeze({ site: 'runClaudeP', reason: 'internal one-shot aux claude -p (no tools beyond its sandbox, --strict-mcp-config); inherits process.env so the CLI auth env it was launched with keeps working' }),
|
|
113
|
+
Object.freeze({ site: 'docEdit', reason: 'internal one-shot aux claude -p that rewrites a doc the user asked to edit; inherits process.env for the same CLI-auth reason as runClaudeP' }),
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
/** Spawn sites that must pass a credential-free env. */
|
|
117
|
+
const CREDENTIAL_CHECKED_SITES = Object.freeze(['scheduler-job', 'task', 'chat', 'chat-agent']);
|
|
118
|
+
|
|
119
|
+
/** Secret-shaped keys (SECRET_KEY_RE) present in env with a non-empty value. */
|
|
120
|
+
function credentialKeys(env) {
|
|
121
|
+
return Object.keys(env || {}).filter((k) => SECRET_KEY_RE.test(k) && env[k] !== undefined && env[k] !== null && env[k] !== '');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Spawn-time assertion: throw if `env` carries any key matching
|
|
126
|
+
* SECRET_KEY_RE. The error names each offending key, never its value.
|
|
127
|
+
* `site` must be a known spawn site: an exception site passes unchecked, a
|
|
128
|
+
* checked site is scanned, and an unknown site is refused outright.
|
|
129
|
+
* @param {Record<string, any>} env
|
|
130
|
+
* @param {{ site: string }} opts
|
|
131
|
+
*/
|
|
132
|
+
function assertNoCredentials(env, opts) {
|
|
133
|
+
const site = opts && typeof opts.site === 'string' ? opts.site : '';
|
|
134
|
+
if (CREDENTIAL_EXCEPTIONS.some((e) => e.site === site)) return;
|
|
135
|
+
if (!CREDENTIAL_CHECKED_SITES.includes(site)) {
|
|
136
|
+
const err = /** @type {Error & { code?: string }} */ (new Error(`assertNoCredentials: unknown spawn site ${JSON.stringify(site)} — refused`));
|
|
137
|
+
err.code = 'credential_site_unknown';
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
const keys = credentialKeys(env);
|
|
141
|
+
if (keys.length) {
|
|
142
|
+
const err = /** @type {Error & { code?: string, keys?: string[] }} */ (new Error(`assertNoCredentials: ${site} env carries credential keys: ${keys.join(', ')} — refused`));
|
|
143
|
+
err.code = 'credentials_in_env';
|
|
144
|
+
err.keys = keys;
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Copy of env with every SECRET_KEY_RE key removed. */
|
|
150
|
+
function stripCredentials(env) {
|
|
151
|
+
const out = { ...(env || {}) };
|
|
152
|
+
for (const k of Object.keys(out)) if (SECRET_KEY_RE.test(k)) delete out[k];
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = { cleanChildEnv, assertNoCredentials, stripCredentials, CREDENTIAL_EXCEPTIONS, CREDENTIAL_CHECKED_SITES, SECRET_KEY_RE, withProcRole, inferProcRole, PROC_ROLE_ENV, userBinDirs, pathWithUserBins };
|