claude-code-session-manager 0.139.0 → 0.141.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -4
- package/dist/assets/AppSettings-DExeJhqQ.js +2 -0
- package/dist/assets/History-DJMiuXyK.js +2 -0
- package/dist/assets/{HomeClaudeConfig-CGD2Onjv.js → HomeClaudeConfig-CTp2tkZ4.js} +2 -2
- package/dist/assets/{Panel-Csyd9HbD.js → Panel-Bf1Cf8UL.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-C-jlYpC_.js → ProjectClaudeConfig-BWPpypf9.js} +1 -1
- package/dist/assets/Scheduler-cyr61UAC.js +16 -0
- package/dist/assets/{SkillReferenceGraph-DcscPXAG.js → SkillReferenceGraph-Ba4TkX2C.js} +1 -1
- package/dist/assets/{Skills-BpGRKOcY.js → Skills-C1v91GEO.js} +26 -26
- package/dist/assets/{TiptapBody-DSU3769X.js → TiptapBody-BrcWVpiW.js} +1 -1
- package/dist/assets/{ViewTabs-C0PRZx4_.js → ViewTabs-DXhOWFG0.js} +1 -1
- package/dist/assets/{VoiceButton-D2rMurNg.js → VoiceButton-qivnDV6K.js} +1 -1
- package/dist/assets/{historyTotals-TcIQs2sh.js → historyTotals-CMCPTKqC.js} +1 -1
- package/dist/assets/index-B2TQz3nd.js +3121 -0
- package/dist/assets/{index-BCySPdtU.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +423 -426
- package/package.json +5 -2
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/skills/builder/SKILL.md +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +29 -19
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
- package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
- package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
- package/scripts/README.md +1 -0
- package/scripts/hooks/guard-tool-risk.cjs +91 -0
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
- package/scripts/ops-sweep.cjs +53 -23
- package/scripts/scheduler-mcp-server.cjs +205 -18
- package/src/main/build-info.json +4 -4
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +88 -5
- package/src/main/historyDashboard.cjs +69 -4
- package/src/main/index.cjs +56 -2
- package/src/main/ipcSchemas.cjs +122 -16
- package/src/main/lib/AGENTS.md +54 -0
- package/src/main/lib/CLAUDE.md +1 -54
- package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
- package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
- package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
- package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
- package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
- package/src/main/lib/claude/effectiveModelInfo.cjs +90 -20
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
- package/src/main/lib/claude/personaToolScope.cjs +12 -6
- package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
- package/src/main/lib/claude/runClaudeP.cjs +6 -1
- package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
- package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
- package/src/main/lib/ephemeralCwd.cjs +37 -2
- package/src/main/lib/epic/delegationReadiness.cjs +42 -9
- package/src/main/lib/epic/epicAdminRoutes.cjs +25 -5
- package/src/main/lib/epic/epicOutsideRead.cjs +118 -1
- package/src/main/lib/epic/epicOutsideState.cjs +2 -2
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/externalContract.cjs +31 -5
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +55 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +106 -11
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +47 -19
- package/src/main/lib/feedback-remote/needsYouStore.cjs +6 -2
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
- package/src/main/lib/git/branchSweep.cjs +209 -4
- package/src/main/lib/git/gitWorktree.cjs +41 -5
- package/src/main/lib/guardShims.cjs +1 -1
- package/src/main/lib/historyRollup.cjs +26 -0
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +132 -13
- package/src/main/lib/mdDocCensus.cjs +59 -78
- package/src/main/lib/mdDocRefs.cjs +71 -93
- package/src/main/lib/mdNetworkScan.cjs +245 -250
- package/src/main/lib/mdReviewRecord.cjs +22 -9
- package/src/main/lib/memoryMdNetwork.cjs +5 -12
- package/src/main/lib/opsOwnership.cjs +18 -2
- package/src/main/lib/opsRetentionSettings.cjs +28 -4
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
- package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
- package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
- package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
- package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/depSlugResolve.cjs +104 -4
- package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
- package/src/main/lib/prd/prdCreate.cjs +377 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +121 -3
- package/src/main/lib/process/loginItem.cjs +171 -0
- package/src/main/lib/process/loginItemPlan.cjs +193 -0
- package/src/main/lib/project-pages/playerBridge.cjs +4 -0
- package/src/main/lib/project-pages/videoReview.cjs +268 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
- package/src/main/lib/scheduler/cpuSample.cjs +131 -4
- package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
- package/src/main/lib/scheduler/loadGate.cjs +24 -6
- package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
- package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
- package/src/main/lib/scheduler/preflightCheck.cjs +97 -0
- package/src/main/lib/scheduler/queueStore.cjs +7 -0
- package/src/main/lib/scheduler/rcaReport.cjs +21 -1
- package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
- package/src/main/lib/scheduler/reviewNotice.cjs +39 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
- package/src/main/lib/scheduler/schedulerPaths.cjs +3 -0
- package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
- package/src/main/lib/scheduler/validationQuality.cjs +282 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
- package/src/main/lib/tasks/taskIpc.cjs +80 -0
- package/src/main/lib/tasks/taskLedger.cjs +502 -0
- package/src/main/lib/tasks/taskRun.cjs +313 -0
- package/src/main/lib/tasks/taskSwitch.cjs +120 -0
- package/src/main/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +10 -1
- package/src/main/projectPages.cjs +6 -15
- package/src/main/promptSessionEvents.cjs +9 -1
- package/src/main/queueOps.cjs +260 -3
- package/src/main/runVerify.cjs +53 -25
- package/src/main/scheduler/AGENTS.md +26 -0
- package/src/main/scheduler/CLAUDE.md +1 -26
- package/src/main/scheduler/budget.cjs +239 -9
- package/src/main/scheduler/cancelDependents.cjs +154 -0
- package/src/main/scheduler/prdParser.cjs +19 -1
- package/src/main/scheduler/reviewLadder.cjs +36 -3
- package/src/main/scheduler/starvation.cjs +89 -18
- package/src/main/scheduler.cjs +1080 -89
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +14 -1
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +10 -2
- package/src/preload/api.d.ts +364 -21
- package/src/preload/apiSurface.json +89 -10
- package/src/preload/index.cjs +23 -2
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AppSettings-CUfWY9vN.js +0 -2
- package/dist/assets/History-DDnqaLyw.js +0 -2
- package/dist/assets/Scheduler-NLs08fx7.js +0 -16
- package/dist/assets/index-C-d0DCre.js +0 -3124
|
@@ -950,6 +950,38 @@ function fallbackReasonText(reason) {
|
|
|
950
950
|
return r;
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
+
/**
|
|
954
|
+
* findOpenReplyFallback(toCwd, { toEpicId, fromCwd, fromEpicId }) → { epicId, status } | null
|
|
955
|
+
*
|
|
956
|
+
* The OPEN (proposed/active) reply-fallback Epic already minted in toCwd for
|
|
957
|
+
* this thread — the (asking Epic toEpicId, replier fromCwd/fromEpicId) pair —
|
|
958
|
+
* or null. Completed or archived (removed from the active index) Epics never
|
|
959
|
+
* match. Tolerates rows with missing/partial `source`. Never throws.
|
|
960
|
+
*/
|
|
961
|
+
function findOpenReplyFallback(toCwd, { toEpicId, fromCwd, fromEpicId } = {}) {
|
|
962
|
+
const sameCwd = (x, y) => typeof x === 'string' && typeof y === 'string' && x && y
|
|
963
|
+
&& path.resolve(x) === path.resolve(y);
|
|
964
|
+
let sessions;
|
|
965
|
+
try {
|
|
966
|
+
sessions = readActiveIndex(toCwd).sessions;
|
|
967
|
+
} catch {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
970
|
+
const wantFromEpicId = fromEpicId || null;
|
|
971
|
+
for (const [id, row] of Object.entries(sessions || {})) {
|
|
972
|
+
if (!row || typeof row !== 'object') continue;
|
|
973
|
+
if (row.status !== 'proposed' && row.status !== 'active') continue;
|
|
974
|
+
const src = row.source && typeof row.source === 'object' ? row.source : null;
|
|
975
|
+
if (!src || src.producer !== 'cross-project-feedback') continue;
|
|
976
|
+
const replyOf = src.replyOf && typeof src.replyOf === 'object' ? src.replyOf : null;
|
|
977
|
+
if (!replyOf || replyOf.epicId !== toEpicId || !sameCwd(replyOf.cwd, toCwd)) continue;
|
|
978
|
+
if (!sameCwd(src.fromCwd, fromCwd)) continue;
|
|
979
|
+
if ((src.fromEpicId || null) !== wantFromEpicId) continue;
|
|
980
|
+
return { epicId: row.id || id, status: row.status };
|
|
981
|
+
}
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
|
|
953
985
|
/**
|
|
954
986
|
* openReplyFallbackSession(input, deps?) → { ok, epicId, toCwd, ... } | { ok: false, status, error }
|
|
955
987
|
*
|
|
@@ -985,6 +1017,28 @@ async function openReplyFallbackSession(input = {}, deps = {}) {
|
|
|
985
1017
|
if (!isSessionManagerProject(toCwd)) return bad(400, `${toCwd} is not a Session Manager project`);
|
|
986
1018
|
if (toCwd === fromCwd) return bad(400, 'the reply fallback must land in a DIFFERENT project');
|
|
987
1019
|
|
|
1020
|
+
// Idempotent per thread: at most one OPEN fallback Epic per (asking Epic,
|
|
1021
|
+
// replier Epic). A second reply on the same thread joins the open one
|
|
1022
|
+
// instead of minting a duplicate (2026-11-21: two Epics, plan queued twice).
|
|
1023
|
+
const replyOf = { cwd: toCwd, epicId: toEpicId };
|
|
1024
|
+
const existing = findOpenReplyFallback(toCwd, { toEpicId, fromCwd, fromEpicId });
|
|
1025
|
+
if (existing) {
|
|
1026
|
+
const outcome = singleLine(input.outcome) || 'unknown';
|
|
1027
|
+
const reason = singleLine(input.reason) || 'unknown';
|
|
1028
|
+
try {
|
|
1029
|
+
audit('epic_cross_project_reply_fallback_reused', {
|
|
1030
|
+
cwd: toCwd,
|
|
1031
|
+
epicId: existing.epicId,
|
|
1032
|
+
replyOf,
|
|
1033
|
+
fromCwd,
|
|
1034
|
+
fromEpicId,
|
|
1035
|
+
outcome,
|
|
1036
|
+
reason,
|
|
1037
|
+
});
|
|
1038
|
+
} catch { /* audit is best-effort */ }
|
|
1039
|
+
return { ok: true, epicId: existing.epicId, reused: true, status: existing.status, toCwd, fromCwd, replyOf, reason };
|
|
1040
|
+
}
|
|
1041
|
+
|
|
988
1042
|
const original = input.original && typeof input.original === 'object' ? input.original : {};
|
|
989
1043
|
const proposal = original.proposal && typeof original.proposal === 'object' ? original.proposal : {};
|
|
990
1044
|
const originalTitle = singleLine(original.title) || '(untitled request)';
|
|
@@ -1020,7 +1074,6 @@ async function openReplyFallbackSession(input = {}, deps = {}) {
|
|
|
1020
1074
|
acceptanceCriteria,
|
|
1021
1075
|
});
|
|
1022
1076
|
|
|
1023
|
-
const replyOf = { cwd: toCwd, epicId: toEpicId };
|
|
1024
1077
|
let minted;
|
|
1025
1078
|
try {
|
|
1026
1079
|
minted = await mint(toCwd, {
|
|
@@ -1217,6 +1270,7 @@ module.exports = {
|
|
|
1217
1270
|
openFeedbackSession,
|
|
1218
1271
|
recordExternalRefWithRetry,
|
|
1219
1272
|
readEpicGoal,
|
|
1273
|
+
findOpenReplyFallback,
|
|
1220
1274
|
openReplyFallbackSession,
|
|
1221
1275
|
listFeedbackTargets,
|
|
1222
1276
|
registerAdminRoute,
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* active-index.json delegation). Reads use epicMint.cjs's readActiveIndex.
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
+
const crypto = require('node:crypto');
|
|
36
37
|
const fs = require('node:fs');
|
|
37
38
|
const path = require('node:path');
|
|
38
39
|
|
|
@@ -176,9 +177,37 @@ function receiptFields(appendResult) {
|
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
|
|
180
|
+
/** The thread's receipts on Y — the cap count and the latest one (for the
|
|
181
|
+
* identical-retry check) come from the same read. */
|
|
182
|
+
function readReceipts(cwd, epicId) {
|
|
180
183
|
const events = readActiveIndex(cwd).events[epicId];
|
|
181
|
-
return Array.isArray(events) ? events.filter((e) => e && e.notice === RECEIPT_NOTICE)
|
|
184
|
+
return Array.isArray(events) ? events.filter((e) => e && e.notice === RECEIPT_NOTICE) : [];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** reply.hash on every receipt: an identical retry (same outcome + message)
|
|
188
|
+
* of the thread's latest reply is the same reply, not a new one. */
|
|
189
|
+
function replyHash(outcome, message) {
|
|
190
|
+
return crypto.createHash('sha256').update(`${outcome}\n${message}`).digest('hex');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The delivery fields an earlier receipt recorded, returned to an identical
|
|
194
|
+
* retry instead of delivering again. */
|
|
195
|
+
function earlierDelivery(receipt, { targetCwd, rt, threadField, sent }) {
|
|
196
|
+
const r = receipt.reply || {};
|
|
197
|
+
return {
|
|
198
|
+
ok: true,
|
|
199
|
+
alreadyDelivered: true,
|
|
200
|
+
delivery: r.delivery || 'delivered',
|
|
201
|
+
toCwd: targetCwd,
|
|
202
|
+
toEpicId: r.toEpicId || rt.epicId || null,
|
|
203
|
+
...(r.fallbackEpicId ? { fallbackEpicId: r.fallbackEpicId } : {}),
|
|
204
|
+
...(r.reused ? { reused: true } : {}),
|
|
205
|
+
...(r.reason ? { reason: r.reason } : {}),
|
|
206
|
+
...threadField,
|
|
207
|
+
receiptOnReplyingEpic: true,
|
|
208
|
+
repliesUsed: sent,
|
|
209
|
+
repliesLeft: Math.max(0, MAX_REPLIES_PER_THREAD - sent),
|
|
210
|
+
};
|
|
182
211
|
}
|
|
183
212
|
|
|
184
213
|
/**
|
|
@@ -243,8 +272,14 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
243
272
|
}
|
|
244
273
|
|
|
245
274
|
return withThreadLock(`${realOr(replierCwd)}\u0000${yId}`, async () => {
|
|
246
|
-
// 4.
|
|
247
|
-
const
|
|
275
|
+
// 4. Identical retry, then cap.
|
|
276
|
+
const receipts = readReceipts(replierCwd, yId);
|
|
277
|
+
const sent = receipts.length;
|
|
278
|
+
const hash = replyHash(outcome, message);
|
|
279
|
+
const latest = receipts[sent - 1];
|
|
280
|
+
if (latest && latest.reply && latest.reply.hash === hash) {
|
|
281
|
+
return earlierDelivery(latest, { targetCwd, rt, threadField, sent });
|
|
282
|
+
}
|
|
248
283
|
if (sent >= MAX_REPLIES_PER_THREAD) {
|
|
249
284
|
return bad(429, `reply limit of ${MAX_REPLIES_PER_THREAD} reached for this thread`);
|
|
250
285
|
}
|
|
@@ -252,7 +287,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
252
287
|
if (eventMode) {
|
|
253
288
|
return replyAsEvent({
|
|
254
289
|
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y,
|
|
255
|
-
message, outcome, referencePaths,
|
|
290
|
+
message, outcome, referencePaths, hash,
|
|
256
291
|
});
|
|
257
292
|
}
|
|
258
293
|
|
|
@@ -280,13 +315,29 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
280
315
|
});
|
|
281
316
|
if (!opened || !opened.ok || typeof opened.epicId !== 'string') return opened;
|
|
282
317
|
const project = path.basename(targetCwd);
|
|
318
|
+
const reused = opened.reused === true;
|
|
319
|
+
// A reused fallback Epic already carries the first reply in its opening
|
|
320
|
+
// prompt; this one must land in it too, or its text is lost.
|
|
321
|
+
let landedInFallback = null;
|
|
322
|
+
if (reused) {
|
|
323
|
+
landedInFallback = await deliverIntoReusedFallback({
|
|
324
|
+
sendPrompt, appendEvent, targetCwd, epicId: opened.epicId,
|
|
325
|
+
replierCwd, yId, y, outcome, message, referencePaths,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
283
328
|
// Receipt on Y — counts toward the per-thread cap like a delivered reply.
|
|
284
329
|
const receipt = await appendEvent(replierCwd, yId,
|
|
285
|
-
|
|
330
|
+
reused
|
|
331
|
+
? `Reply to ${rt.epicId} in ${project} fell back into the open session ${opened.epicId} in ${project} (${reason}).`
|
|
332
|
+
: `Reply to ${rt.epicId} in ${project} fell back to a new proposed session ${opened.epicId} in ${project} (${reason}).`,
|
|
286
333
|
{
|
|
287
334
|
notice: RECEIPT_NOTICE,
|
|
288
335
|
allowInactive: true,
|
|
289
|
-
reply: {
|
|
336
|
+
reply: {
|
|
337
|
+
fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
|
|
338
|
+
delivery: 'fallback', toEpicId: rt.epicId, fallbackEpicId: opened.epicId, reason,
|
|
339
|
+
...(reused ? { reused: true } : {}),
|
|
340
|
+
},
|
|
290
341
|
});
|
|
291
342
|
// Best-effort receipt on X, only while X is still in A's active index.
|
|
292
343
|
let receiptOnAskingEpic = false;
|
|
@@ -294,7 +345,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
294
345
|
if (readActiveIndex(targetCwd).sessions[rt.epicId]) {
|
|
295
346
|
const r = await appendEvent(targetCwd, rt.epicId,
|
|
296
347
|
`A reply from ${path.basename(replierCwd)} (${outcome}) could not be delivered here (${reason}); `
|
|
297
|
-
+ `it opened as a new proposed session ${opened.epicId}
|
|
348
|
+
+ (reused ? `it was added to the open session ${opened.epicId}.` : `it opened as a new proposed session ${opened.epicId}.`),
|
|
298
349
|
{ notice: FALLBACK_NOTICE, allowInactive: true, reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, fallbackEpicId: opened.epicId } });
|
|
299
350
|
receiptOnAskingEpic = !!(r && r.ok);
|
|
300
351
|
}
|
|
@@ -306,6 +357,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
306
357
|
toCwd: targetCwd,
|
|
307
358
|
toEpicId: rt.epicId,
|
|
308
359
|
fallbackEpicId: opened.epicId,
|
|
360
|
+
...(reused ? { reused: true, landedInFallback } : {}),
|
|
309
361
|
receiptOnAskingEpic,
|
|
310
362
|
...threadField,
|
|
311
363
|
...receiptFields(receipt),
|
|
@@ -353,7 +405,11 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
353
405
|
{
|
|
354
406
|
notice: RECEIPT_NOTICE,
|
|
355
407
|
allowInactive: true,
|
|
356
|
-
reply: {
|
|
408
|
+
reply: {
|
|
409
|
+
fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
|
|
410
|
+
delivery, toEpicId: x.id,
|
|
411
|
+
...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
|
|
412
|
+
},
|
|
357
413
|
});
|
|
358
414
|
|
|
359
415
|
// 7. Audit.
|
|
@@ -389,7 +445,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
389
445
|
* audit row. Never prompts a chat, never opens a fallback session.
|
|
390
446
|
*/
|
|
391
447
|
async function replyAsEvent({
|
|
392
|
-
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y, message, outcome, referencePaths,
|
|
448
|
+
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y, message, outcome, referencePaths, hash,
|
|
393
449
|
}) {
|
|
394
450
|
const replyMeta = { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths };
|
|
395
451
|
let eventOnAskingEpic = false;
|
|
@@ -407,7 +463,14 @@ async function replyAsEvent({
|
|
|
407
463
|
const project = path.basename(targetCwd);
|
|
408
464
|
const receipt = await appendEvent(replierCwd, yId,
|
|
409
465
|
`Reply recorded as an event for ${rt.epicId ? `${rt.epicId} in ` : ''}${project} (${outcome}, event-only).`,
|
|
410
|
-
{
|
|
466
|
+
{
|
|
467
|
+
notice: RECEIPT_NOTICE,
|
|
468
|
+
allowInactive: true,
|
|
469
|
+
reply: {
|
|
470
|
+
...replyMeta, hash, delivery: 'event-only', reason: EVENT_MODE_REASON,
|
|
471
|
+
...(rt.epicId ? { toEpicId: rt.epicId } : {}),
|
|
472
|
+
},
|
|
473
|
+
});
|
|
411
474
|
|
|
412
475
|
const externalRef = y.source && y.source.externalRef;
|
|
413
476
|
audit('epic_cross_project_reply', {
|
|
@@ -438,6 +501,38 @@ async function replyAsEvent({
|
|
|
438
501
|
|
|
439
502
|
const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
|
|
440
503
|
|
|
504
|
+
/**
|
|
505
|
+
* deliverIntoReusedFallback(ctx) → Promise<'delivered'|'event-only'|'event-failed'>
|
|
506
|
+
* A later reply on a thread whose open fallback Epic F was reused: an ACTIVE
|
|
507
|
+
* F gets the same event + prompt as a delivered reply; a PROPOSED F (no chat
|
|
508
|
+
* running yet) gets the reply as an event on its chain (allowInactive).
|
|
509
|
+
*/
|
|
510
|
+
async function deliverIntoReusedFallback({
|
|
511
|
+
sendPrompt, appendEvent, targetCwd, epicId, replierCwd, yId, y, outcome, message, referencePaths,
|
|
512
|
+
}) {
|
|
513
|
+
const f = readActiveIndex(targetCwd).sessions[epicId] || {};
|
|
514
|
+
const active = f.status === 'active';
|
|
515
|
+
const prompt = composeReplyPrompt({
|
|
516
|
+
fromCwd: replierCwd, fromEpicId: yId, fromGoalText: y.goalText, outcome, message, referencePaths,
|
|
517
|
+
});
|
|
518
|
+
let appended;
|
|
519
|
+
try {
|
|
520
|
+
appended = await appendEvent(targetCwd, epicId, prompt, {
|
|
521
|
+
notice: REPLY_NOTICE,
|
|
522
|
+
...(active ? {} : { allowInactive: true }),
|
|
523
|
+
reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths },
|
|
524
|
+
});
|
|
525
|
+
} catch { appended = null; }
|
|
526
|
+
if (!appended || !appended.ok) return 'event-failed';
|
|
527
|
+
if (!active) return 'event-only';
|
|
528
|
+
let sendResult;
|
|
529
|
+
try {
|
|
530
|
+
sendResult = await sendPrompt(epicId, prompt, { sessionId: f.claudeSessionId, cwd: f.cwd || targetCwd });
|
|
531
|
+
} catch { sendResult = null; }
|
|
532
|
+
const d = sendResult && sendResult.disposition;
|
|
533
|
+
return d === 'sent' || d === 'queued' ? 'delivered' : 'event-only';
|
|
534
|
+
}
|
|
535
|
+
|
|
441
536
|
/**
|
|
442
537
|
* resolveThread(src) — pure. The thread a replying Epic's `source` names:
|
|
443
538
|
* { ok: true, thread: { cwd, epicId, claudeSessionId }, legacy } or { ok: false, error }.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the scheduler MCP) can list, create/update and delete a HOT KEYS macro
|
|
4
4
|
* for its own project, through the existing macroLibrary.cjs store:
|
|
5
5
|
* GET /admin/macros?cwd=… -> { ok, macros }
|
|
6
|
-
* POST /admin/macros/save {cwd, id?, label, agentName, tag, prompt, inputs?}
|
|
6
|
+
* POST /admin/macros/save {cwd, id?, label, agentName, tag, prompt, inputs?, surface?, job?}
|
|
7
7
|
* POST /admin/macros/delete {cwd, id, originClaudeSessionId?}
|
|
8
8
|
* -> { ok, deleted, macro }
|
|
9
9
|
* delete removes the macro from THIS project through
|
|
@@ -29,6 +29,17 @@
|
|
|
29
29
|
* human typed into body.originClaudeSessionId (humanPromptLedger) AND name
|
|
30
30
|
* every/all projects (or, for a 'project-home' macro, Project Home). Otherwise 400, no write, no onChanged, no audit.
|
|
31
31
|
*
|
|
32
|
+
* A save whose resulting surface is 'project-video' (one project's own Video
|
|
33
|
+
* tool, Project Home ▸ Video) may carry `job` (forwarded to saveMacro), always
|
|
34
|
+
* needs the same verified quote as a 'project-home' save, and ignores a
|
|
35
|
+
* caller's `projects`: a create stores [resolvedCwd], an update keeps the
|
|
36
|
+
* stored projects, so the library refuses a '*' or multi-project macro.
|
|
37
|
+
*
|
|
38
|
+
* Before the write, a save whose resulting macro is surface 'project-video'
|
|
39
|
+
* with a job (the sent job, or the stored one an update keeps) runs
|
|
40
|
+
* projectVideoToolCheck's checkProjectVideoToolRunnable (deps-injectable) for
|
|
41
|
+
* the resolved cwd and persona; a refusal is a 400 with the helper's error.
|
|
42
|
+
*
|
|
32
43
|
* Every successful save appends one `admin_macro_save` audit event and calls
|
|
33
44
|
* `onChanged()` exactly once so the Sessions HOT KEYS strip updates live,
|
|
34
45
|
* matching the IPC handlers in index.cjs.
|
|
@@ -79,20 +90,23 @@ function quoteNamesProjectHome(quote) {
|
|
|
79
90
|
return PROJECT_HOME_RE.test(q);
|
|
80
91
|
}
|
|
81
92
|
|
|
93
|
+
const PROJECT_VIDEO_HINT =
|
|
94
|
+
"a Project Video tool (Project Home ▸ Video, this project only) needs humanRequestQuote (the human's words naming Project Home); the human can add one from Project Home ▸ Video";
|
|
82
95
|
const HUMAN_HINT = "the human can set 'Show in every project' in the macro editor";
|
|
83
96
|
const PROJECT_HOME_HINT =
|
|
84
97
|
"a Project Home tool is shown in every project's Project Home, so it needs humanRequestQuote (the human's words asking for a Project Home tool); the human can add one from Project Home ▸ Tools ▸ Add a tool";
|
|
85
98
|
|
|
86
|
-
/** Fail-closed check that a human asked for an all-projects macro (or a Project Home tool). */
|
|
87
|
-
function verifyAllProjectsRequest(body, { projectHome = false } = {}) {
|
|
88
|
-
const hint = projectHome ? PROJECT_HOME_HINT : HUMAN_HINT;
|
|
99
|
+
/** Fail-closed check that a human asked for an all-projects macro (or a Project Home / Project Video tool). */
|
|
100
|
+
function verifyAllProjectsRequest(body, { projectHome = false, projectVideo = false } = {}) {
|
|
101
|
+
const hint = projectVideo ? PROJECT_VIDEO_HINT : projectHome ? PROJECT_HOME_HINT : HUMAN_HINT;
|
|
102
|
+
const what = projectVideo ? 'a Project Video tool' : 'a macro shown in every project';
|
|
89
103
|
const quote = body.humanRequestQuote;
|
|
90
104
|
if (typeof quote !== 'string' || !quote.trim()) {
|
|
91
|
-
return { ok: false, reason:
|
|
105
|
+
return { ok: false, reason: `${what} needs humanRequestQuote (a verbatim human request); ${hint}` };
|
|
92
106
|
}
|
|
93
107
|
const origin = body.originClaudeSessionId;
|
|
94
108
|
if (typeof origin !== 'string' || origin.length < 1 || origin.length > 128) {
|
|
95
|
-
return { ok: false, reason:
|
|
109
|
+
return { ok: false, reason: `${what} needs originClaudeSessionId (1-128 chars); ${hint}` };
|
|
96
110
|
}
|
|
97
111
|
if (!findHumanPromptContaining(origin, quote)) {
|
|
98
112
|
return { ok: false, reason: `humanRequestQuote was not found in a prompt the human typed in this session; ${hint}` };
|
|
@@ -142,7 +156,7 @@ function listHandler(onChanged, libOpts) {
|
|
|
142
156
|
};
|
|
143
157
|
}
|
|
144
158
|
|
|
145
|
-
function saveHandler(onChanged, libOpts) {
|
|
159
|
+
function saveHandler(onChanged, libOpts, deps = {}) {
|
|
146
160
|
return async (req, res) => {
|
|
147
161
|
const body = await readJsonBody(req, res);
|
|
148
162
|
if (!body) return;
|
|
@@ -155,12 +169,6 @@ function saveHandler(onChanged, libOpts) {
|
|
|
155
169
|
sendJson(res, 400, { ok: false, error: 'built-in macros cannot be edited through this route' });
|
|
156
170
|
return;
|
|
157
171
|
}
|
|
158
|
-
const p = body.projects;
|
|
159
|
-
if (p !== undefined && !(Array.isArray(p) && p.length === 1 && p[0] === macroLibrary.ALL_PROJECTS)) {
|
|
160
|
-
sendJson(res, 400, { ok: false, error: 'projects: only ["*"] is accepted; omit it to use the current project' });
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const wantsAll = p !== undefined;
|
|
164
172
|
let input;
|
|
165
173
|
try {
|
|
166
174
|
input = macroLibrary.MacroSaveSchema.parse({
|
|
@@ -171,6 +179,7 @@ function saveHandler(onChanged, libOpts) {
|
|
|
171
179
|
prompt: body.prompt,
|
|
172
180
|
inputs: body.inputs,
|
|
173
181
|
surface: body.surface,
|
|
182
|
+
job: body.job,
|
|
174
183
|
});
|
|
175
184
|
} catch (e) {
|
|
176
185
|
sendJson(res, 400, { ok: false, error: e?.issues?.[0]?.message ?? e?.message ?? 'invalid payload' });
|
|
@@ -191,10 +200,18 @@ function saveHandler(onChanged, libOpts) {
|
|
|
191
200
|
}
|
|
192
201
|
const resultSurface = input.surface ?? existing?.surface ?? 'sessions';
|
|
193
202
|
const projectHome = resultSurface === 'project-home';
|
|
203
|
+
// A Project Video tool belongs to the resolved project only: a caller's `projects` is ignored.
|
|
204
|
+
const projectVideo = resultSurface === 'project-video';
|
|
205
|
+
const p = projectVideo ? undefined : body.projects;
|
|
206
|
+
if (p !== undefined && !(Array.isArray(p) && p.length === 1 && p[0] === macroLibrary.ALL_PROJECTS)) {
|
|
207
|
+
sendJson(res, 400, { ok: false, error: 'projects: only ["*"] is accepted; omit it to use the current project' });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const wantsAll = p !== undefined;
|
|
194
211
|
const allProjects = Boolean(existing?.projects.includes(macroLibrary.ALL_PROJECTS)) || wantsAll || projectHome;
|
|
195
212
|
let quote = null;
|
|
196
|
-
if (allProjects) {
|
|
197
|
-
const v = verifyAllProjectsRequest(body, { projectHome });
|
|
213
|
+
if (allProjects || projectVideo) {
|
|
214
|
+
const v = verifyAllProjectsRequest(body, { projectHome: projectHome || projectVideo, projectVideo });
|
|
198
215
|
if (!v.ok) {
|
|
199
216
|
sendJson(res, 400, { ok: false, error: v.reason });
|
|
200
217
|
return;
|
|
@@ -204,12 +221,22 @@ function saveHandler(onChanged, libOpts) {
|
|
|
204
221
|
if (!input.id) {
|
|
205
222
|
input = {
|
|
206
223
|
...input,
|
|
207
|
-
projects: wantsAll || projectHome ? [macroLibrary.ALL_PROJECTS] : [resolved.cwd],
|
|
224
|
+
projects: (wantsAll || projectHome) && !projectVideo ? [macroLibrary.ALL_PROJECTS] : [resolved.cwd],
|
|
208
225
|
surface: input.surface ?? 'sessions',
|
|
209
226
|
};
|
|
210
|
-
} else if (wantsAll || projectHome) {
|
|
227
|
+
} else if ((wantsAll || projectHome) && !projectVideo) {
|
|
211
228
|
input = { ...input, projects: [macroLibrary.ALL_PROJECTS] };
|
|
212
229
|
}
|
|
230
|
+
const resultJob = input.job !== undefined ? input.job : existing?.job;
|
|
231
|
+
if (projectVideo && resultJob && typeof resultJob === 'object') {
|
|
232
|
+
const check = deps.checkProjectVideoToolRunnable
|
|
233
|
+
|| require('../persona-macro/projectVideoToolCheck.cjs').checkProjectVideoToolRunnable;
|
|
234
|
+
const verdict = await check({ cwd: resolved.cwd, agentName: input.agentName ?? existing?.agentName, job: resultJob });
|
|
235
|
+
if (!verdict || verdict.ok === false) {
|
|
236
|
+
sendJson(res, 400, { ok: false, error: verdict?.error ?? 'project-video tool check failed' });
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
213
240
|
let macro;
|
|
214
241
|
try {
|
|
215
242
|
macro = await macroLibrary.saveMacro(input, libOpts);
|
|
@@ -530,13 +557,14 @@ async function runWithExternalRef({ deps, res, cwd, macro, prompt, effort, exter
|
|
|
530
557
|
|
|
531
558
|
/**
|
|
532
559
|
* @param {{ onChanged?: () => void, startExternalNewSession?: (p: object) => Promise<any>,
|
|
533
|
-
* isTabBusy?: (tabId: string) => boolean, listPersonas?: () => Promise<Array<{name: string}
|
|
560
|
+
* isTabBusy?: (tabId: string) => boolean, listPersonas?: () => Promise<Array<{name: string}>>,
|
|
561
|
+
* checkProjectVideoToolRunnable?: (i: { cwd: string, agentName: string, job: object }) => Promise<{ ok: boolean, error?: string }> }} deps
|
|
534
562
|
*/
|
|
535
563
|
function registerAdminRoute(adminHttp, deps = {}, opts = {}) {
|
|
536
564
|
const { onChanged } = deps;
|
|
537
565
|
const libOpts = opts.filePath ? { filePath: opts.filePath } : undefined;
|
|
538
566
|
adminHttp.registerRoute('GET', '/admin/macros', listHandler(onChanged, libOpts));
|
|
539
|
-
adminHttp.registerRoute('POST', '/admin/macros/save', saveHandler(onChanged, libOpts));
|
|
567
|
+
adminHttp.registerRoute('POST', '/admin/macros/save', saveHandler(onChanged, libOpts, deps));
|
|
540
568
|
adminHttp.registerRoute('POST', '/admin/macros/delete', deleteHandler(onChanged, libOpts));
|
|
541
569
|
if (typeof deps.startExternalNewSession === 'function') {
|
|
542
570
|
adminHttp.registerRoute('POST', '/admin/macros/run', runHandler(deps, libOpts));
|
|
@@ -26,9 +26,13 @@ const STATUSES = /** @type {const} */ (['open', 'answered', 'withdrawn']);
|
|
|
26
26
|
|
|
27
27
|
const AppSchema = z.string().regex(/^[A-Za-z0-9._-]{1,40}$/, 'app must be 1 to 40 letters, digits, . _ or -');
|
|
28
28
|
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Runs a value through normalizeExternalRef; `required` refuses absent values.
|
|
31
|
+
* The input is `.optional()` so zod 4 lets a missing key reach the transform
|
|
32
|
+
* (a bare z.unknown().transform() rejects it as "expected nonoptional").
|
|
33
|
+
*/
|
|
30
34
|
function refSchema(label, required) {
|
|
31
|
-
return z.unknown().transform((v, ctx) => {
|
|
35
|
+
return z.unknown().optional().transform((v, ctx) => {
|
|
32
36
|
if (required && (v === undefined || v === null)) {
|
|
33
37
|
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `${label} is required.` });
|
|
34
38
|
return z.NEVER;
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* POST /admin/project-home/demo-video/write alias: {cwd, html} -> a new videos/vid-<id>/ project-demo entry
|
|
7
7
|
* POST /admin/project-home/matrix/read {cwd} -> project-pages/matrix/matrix.json (+ its JSON Schema)
|
|
8
8
|
* POST /admin/project-home/matrix/write {cwd, matrix, model?} -> matrixStore.writeMatrix
|
|
9
|
+
* POST /admin/project-home/videos/review/write {cwd, videoId, text, images:[{base64}]} -> videoReview.writeMaterial
|
|
10
|
+
* (review material only; there is deliberately no route that decides, approves or retries —
|
|
11
|
+
* only the human buttons in the app record a decision)
|
|
9
12
|
* all owned by writer 'project-home' (see opsOwnership.cjs). Registered
|
|
10
13
|
* against the same injected localAdminHttp.cjs transport as
|
|
11
14
|
* prdAdminRoutes.cjs.
|
|
@@ -36,9 +39,14 @@ const { checkHtmlLimits } = require('../demo-video-kit/checks.cjs');
|
|
|
36
39
|
const { injectPlayerBridge } = require('../project-pages/playerBridge.cjs');
|
|
37
40
|
const { readMatrix, matrixJsonSchema, MAX_MATRIX_BYTES } = require('../project-pages/competitiveMatrix.cjs');
|
|
38
41
|
const { writeMatrix } = require('../project-pages/matrixStore.cjs');
|
|
42
|
+
const videoReview = require('../project-pages/videoReview.cjs');
|
|
39
43
|
|
|
40
44
|
const MAX_HTML_BYTES = 1024 * 1024;
|
|
41
45
|
const MAX_DEMO_VIDEO_BYTES = 2 * 1024 * 1024;
|
|
46
|
+
/** Review write body cap: 6 base64 images of 2 MiB (16 MiB) + a 32000-char text and JSON overhead. */
|
|
47
|
+
const REVIEW_WRITE_BODY_MAX = 18 * 1024 * 1024;
|
|
48
|
+
const REVIEW_DECISION_KEYS = Object.freeze(['decision', 'status', 'approved', 'approvedAt']);
|
|
49
|
+
const REVIEW_DECISION_REFUSAL = 'review decisions are made only by a human in the app';
|
|
42
50
|
|
|
43
51
|
// Each detector is a linear regex scan; the input is capped first.
|
|
44
52
|
const REMOTE_REFERENCE_CHECKS = [
|
|
@@ -79,6 +87,23 @@ const NETWORK_CHECKS = [
|
|
|
79
87
|
{ re: /<a\b[^>]*\bhref\s*=\s*["']?\s*(?:https?:|\/\/|javascript:)/i, message: '<a href="http(s):|//|javascript:…"> is not allowed' },
|
|
80
88
|
];
|
|
81
89
|
|
|
90
|
+
// <meta name="sm-demo-aspect" content="..."> in any attribute order, either quote style.
|
|
91
|
+
const META_TAG_RE = /<meta\b[^>]*>/gi;
|
|
92
|
+
const ASPECT_NAME_RE = /\bname\s*=\s*(["'])\s*sm-demo-aspect\s*\1/i;
|
|
93
|
+
const CONTENT_ATTR_RE = /\bcontent\s*=\s*(["'])(.*?)\1/i;
|
|
94
|
+
const VIDEO_ASPECTS = ['16:9', '9:16'];
|
|
95
|
+
|
|
96
|
+
/** The document's declared aspect: '16:9' when no tag, an error for any other value. */
|
|
97
|
+
function readAspect(html) {
|
|
98
|
+
for (const tag of html.match(META_TAG_RE) ?? []) {
|
|
99
|
+
if (!ASPECT_NAME_RE.test(tag)) continue;
|
|
100
|
+
const content = (tag.match(CONTENT_ATTR_RE)?.[2] ?? '').trim();
|
|
101
|
+
if (VIDEO_ASPECTS.includes(content)) return { aspect: content };
|
|
102
|
+
return { error: `sm-demo-aspect content must be '16:9' or '9:16' (got '${content.slice(0, 40)}')` };
|
|
103
|
+
}
|
|
104
|
+
return { aspect: '16:9' };
|
|
105
|
+
}
|
|
106
|
+
|
|
82
107
|
const DURATION_META_RE = /<meta\b[^>]*\bname\s*=\s*["']sm-demo-duration["'][^>]*\bcontent\s*=\s*["'](\d+)["'][^>]*>/i;
|
|
83
108
|
const MIN_DEMO_DURATION_S = 5;
|
|
84
109
|
const MAX_DEMO_DURATION_S = 60;
|
|
@@ -220,7 +245,7 @@ function makeWriteHandler({ schema, bodyLimit, build }) {
|
|
|
220
245
|
const abs = path.join(dir, 'index.html');
|
|
221
246
|
await config.writeTextAtomic(abs, built.html, { writer: 'project-home' });
|
|
222
247
|
await config.writeTextAtomic(path.join(dir, 'meta.json'), JSON.stringify(built.meta, null, 2) + '\n', { writer: 'project-home' });
|
|
223
|
-
sendJson(res, 200, { ok: true, path: abs, bytes: Buffer.byteLength(built.html, 'utf8'), id: built.meta.id });
|
|
248
|
+
sendJson(res, 200, { ok: true, path: abs, bytes: Buffer.byteLength(built.html, 'utf8'), id: built.meta.id, meta: built.meta });
|
|
224
249
|
} catch (e) {
|
|
225
250
|
sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
|
|
226
251
|
}
|
|
@@ -257,6 +282,9 @@ function buildVideo(input, { videoId, title, kind, lengthS, meta }) {
|
|
|
257
282
|
if (rejection) return { error: rejection };
|
|
258
283
|
const declared = Number(input.html.match(DURATION_META_RE)[1]);
|
|
259
284
|
if (declared !== lengthS) return { error: `sm-demo-duration (${declared}) must equal lengthS (${lengthS})` };
|
|
285
|
+
// The document's tag is the one source; a caller-supplied meta.aspect is ignored.
|
|
286
|
+
const declaredAspect = readAspect(input.html);
|
|
287
|
+
if (declaredAspect.error) return { error: declaredAspect.error };
|
|
260
288
|
const html = injectPlayerBridge(injectCsp(input.html));
|
|
261
289
|
const bytes = Buffer.byteLength(html, 'utf8');
|
|
262
290
|
return {
|
|
@@ -268,6 +296,7 @@ function buildVideo(input, { videoId, title, kind, lengthS, meta }) {
|
|
|
268
296
|
title,
|
|
269
297
|
kind,
|
|
270
298
|
lengthS,
|
|
299
|
+
aspect: declaredAspect.aspect,
|
|
271
300
|
createdAt: new Date().toISOString(),
|
|
272
301
|
report: { ...meta.report, bytes },
|
|
273
302
|
}),
|
|
@@ -338,6 +367,9 @@ function registerAdminRoute(adminHttp) {
|
|
|
338
367
|
},
|
|
339
368
|
}));
|
|
340
369
|
|
|
370
|
+
// POST /admin/project-home/videos/review/write {cwd, videoId, text, images:[{base64}]} -> review/material.json
|
|
371
|
+
adminHttp.registerRoute('POST', '/admin/project-home/videos/review/write', reviewWriteHandler);
|
|
372
|
+
|
|
341
373
|
// POST /admin/project-home/character/write {cwd, json, js, replace?} -> videos/_character/
|
|
342
374
|
adminHttp.registerRoute('POST', '/admin/project-home/character/write', characterWriteHandler);
|
|
343
375
|
|
|
@@ -393,6 +425,70 @@ function makeMatrixHandler(run) {
|
|
|
393
425
|
};
|
|
394
426
|
}
|
|
395
427
|
|
|
428
|
+
/**
|
|
429
|
+
* Saves review material for one review-stage video entry. Never records a
|
|
430
|
+
* decision: a body carrying any decision-shaped key is refused outright.
|
|
431
|
+
*/
|
|
432
|
+
async function reviewWriteHandler(req, res) {
|
|
433
|
+
let raw;
|
|
434
|
+
try {
|
|
435
|
+
raw = await readBody(req, REVIEW_WRITE_BODY_MAX);
|
|
436
|
+
} catch (e) {
|
|
437
|
+
sendJson(res, 413, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (limit is ${REVIEW_WRITE_BODY_MAX} bytes)` });
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
let body;
|
|
441
|
+
try {
|
|
442
|
+
body = raw ? JSON.parse(raw) : {};
|
|
443
|
+
} catch {
|
|
444
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
448
|
+
sendJson(res, 400, { ok: false, error: 'invalid payload' });
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (REVIEW_DECISION_KEYS.some((k) => Object.prototype.hasOwnProperty.call(body, k))) {
|
|
452
|
+
sendJson(res, 400, { ok: false, error: REVIEW_DECISION_REFUSAL });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const { videoId, text, images } = body;
|
|
456
|
+
if (typeof videoId !== 'string' || !ENTRY_ID_RE.test(videoId)) {
|
|
457
|
+
sendJson(res, 400, { ok: false, error: 'invalid videoId' });
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (!Array.isArray(images)) {
|
|
461
|
+
sendJson(res, 400, { ok: false, error: 'images must be an array of { base64 }' });
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const decoded = [];
|
|
465
|
+
for (let i = 0; i < images.length; i++) {
|
|
466
|
+
const b64 = images[i] && images[i].base64;
|
|
467
|
+
if (typeof b64 !== 'string' || !b64) {
|
|
468
|
+
sendJson(res, 400, { ok: false, error: `image ${i + 1}: base64 must be a non-empty string` });
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
decoded.push({ bytes: Buffer.from(b64, 'base64') });
|
|
472
|
+
}
|
|
473
|
+
const resolved = resolveCwd(body.cwd);
|
|
474
|
+
if (!resolved.ok) {
|
|
475
|
+
sendJson(res, resolved.status, { ok: false, error: resolved.error });
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
config.addAllowedRoot(resolved.cwd);
|
|
479
|
+
try {
|
|
480
|
+
const r = await videoReview.writeMaterial(resolved.cwd, videoId, { text, images: decoded });
|
|
481
|
+
if (!r.ok) {
|
|
482
|
+
sendJson(res, 400, { ok: false, error: r.error });
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
const review = await videoReview.readReview(resolved.cwd, videoId);
|
|
486
|
+
sendJson(res, 200, { ok: true, entryId: videoId, status: review ? review.status : 'waiting' });
|
|
487
|
+
} catch (e) {
|
|
488
|
+
sendJson(res, 500, { ok: false, error: e?.message ?? 'review write failed' });
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
396
492
|
async function characterWriteHandler(req, res) {
|
|
397
493
|
let raw;
|
|
398
494
|
try {
|
|
@@ -455,5 +551,6 @@ module.exports = {
|
|
|
455
551
|
DEMO_VIDEO_CSP,
|
|
456
552
|
MAX_HTML_BYTES,
|
|
457
553
|
MAX_DEMO_VIDEO_BYTES,
|
|
554
|
+
REVIEW_WRITE_BODY_MAX,
|
|
458
555
|
resolveCwd,
|
|
459
556
|
};
|
|
@@ -68,6 +68,11 @@ const PATH_FENCED_CHANNELS = Object.freeze({
|
|
|
68
68
|
'project-pages:matrix': { field: 'cwd', mode: 'root' },
|
|
69
69
|
// Epic Changes view (main/lib/epic/epicChanges.cjs): diffs a repo, so cwd must sit inside a registered root.
|
|
70
70
|
'epicChanges:get': { field: 'cwd', mode: 'root' },
|
|
71
|
+
// Scheduler Tasks section reads (main/lib/tasks/taskIpc.cjs): cwd inside a registered root.
|
|
72
|
+
// tasks:set-switch is not here — its apiSurface row is 'deny', so it never reaches the relay.
|
|
73
|
+
'tasks:list': { field: 'cwd', mode: 'root' },
|
|
74
|
+
'tasks:get': { field: 'cwd', mode: 'root' },
|
|
75
|
+
'tasks:get-switch': { field: 'cwd', mode: 'root' },
|
|
71
76
|
})
|
|
72
77
|
|
|
73
78
|
const SECRET_DIRS = new Set(['.ssh', '.gnupg', '.aws', '.kube', '.docker', '.password-store', '.azure', '.terraform.d'])
|