claude-code-session-manager 0.141.0 → 0.143.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/.claude-plugin/marketplace.json +1 -1
- package/README.md +76 -153
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
- package/dist/assets/Scheduler-CNLjn90m.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/Toggle-CYajnSdx.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/index-CdTppjKR.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 +6 -4
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- 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 +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +2 -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 +1032 -112
- package/src/main/adminRouteRegistry.cjs +69 -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 +336 -23
- package/src/main/config.cjs +35 -1
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +129 -2
- package/src/main/index.cjs +110 -52
- package/src/main/ipcSchemas.cjs +172 -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 +52 -0
- package/src/main/lib/demo-video-kit/character.cjs +778 -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 +103 -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/projectSounds.cjs +191 -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/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- 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/activeIndexMerge.cjs +5 -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 +356 -0
- package/src/main/lib/epic/artifactStore.cjs +435 -0
- package/src/main/lib/epic/delegationReadiness.cjs +83 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +258 -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/epicStateEmitter.cjs +248 -0
- 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 +94 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +48 -4
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
- 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 +32 -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 +207 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- 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/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +182 -4
- package/src/main/lib/mcpToolCatalog.cjs +399 -29
- package/src/main/lib/opsOwnership.cjs +141 -28
- 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 +309 -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 +387 -228
- package/src/main/lib/prd/prdCriteria.cjs +228 -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/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- 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 +313 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -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 +9 -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 +251 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
- package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
- package/src/main/lib/tasks/mitigationReview.cjs +314 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
- 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 +204 -6
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- 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/atomicFs.cjs +2 -2
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +21 -1
- package/src/main/pty.cjs +77 -0
- package/src/main/queueOps.cjs +33 -14
- 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 +191 -0
- package/src/main/scheduler.cjs +1932 -213
- package/src/main/templates/PRD_AUTHORING.md +11 -3
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +576 -39
- package/src/preload/apiSurface.json +223 -7
- package/src/preload/index.cjs +48 -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 +98 -87
- 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 +23 -23
- 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,312 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Demo-video kit voice library: the ONE resolver for library voices.
|
|
3
|
+
// Three scopes, highest first (like agents):
|
|
4
|
+
// project <projectRoot>/.claude/voices/<id>.json
|
|
5
|
+
// machine <voicesHome>/library/<id>.json
|
|
6
|
+
// builtin every voice in the installed Kokoro model (voices-v1.0.bin zip),
|
|
7
|
+
// or KOKORO_V1_VOICES (installed:false) when the model is absent.
|
|
8
|
+
// A higher scope shadows a lower one with the same id. Approvals live in
|
|
9
|
+
// <voicesHome>/approvals.json; this module only READS them. An approved voice
|
|
10
|
+
// whose pin no longer matches, or whose file is gone, is refused — never used,
|
|
11
|
+
// never replaced by a lower scope.
|
|
12
|
+
// Kit files are seeded to ~/.claude/session-manager/demo-video-kit/ and must
|
|
13
|
+
// load standalone: node built-ins and this folder only.
|
|
14
|
+
const fs = require('node:fs');
|
|
15
|
+
const os = require('node:os');
|
|
16
|
+
const path = require('node:path');
|
|
17
|
+
const crypto = require('node:crypto');
|
|
18
|
+
const { validateCharacterJson } = require('./character.cjs');
|
|
19
|
+
|
|
20
|
+
/** The one library voice id pattern; every other copy points here. */
|
|
21
|
+
const VOICE_ID_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
22
|
+
const MAX_ENTRY_BYTES = 16 * 1024;
|
|
23
|
+
const LABEL_MAX = 80;
|
|
24
|
+
const SAMPLE_MAX = 300;
|
|
25
|
+
const LICENCE_MAX = 120;
|
|
26
|
+
const PIN_FILES_MAX = 8;
|
|
27
|
+
const DEFAULT_SAMPLE = 'Hello! This is how I sound when I tell your project story.';
|
|
28
|
+
const BUILTIN_LICENCE = 'Apache-2.0 (Kokoro-82M)';
|
|
29
|
+
const SCOPE_ORDER = Object.freeze({ project: 0, machine: 1, builtin: 2 });
|
|
30
|
+
|
|
31
|
+
const KOKORO_V1_VOICES = Object.freeze([
|
|
32
|
+
'af_alloy', 'af_aoede', 'af_bella', 'af_heart', 'af_jessica', 'af_kore', 'af_nicole', 'af_nova', 'af_river', 'af_sarah', 'af_sky',
|
|
33
|
+
'am_adam', 'am_echo', 'am_eric', 'am_fenrir', 'am_liam', 'am_michael', 'am_onyx', 'am_puck', 'am_santa',
|
|
34
|
+
'bf_alice', 'bf_emma', 'bf_isabella', 'bf_lily', 'bm_daniel', 'bm_fable', 'bm_george', 'bm_lewis',
|
|
35
|
+
'ef_dora', 'em_alex', 'em_santa', 'ff_siwis', 'hf_alpha', 'hf_beta', 'hm_omega', 'hm_psi',
|
|
36
|
+
'if_sara', 'im_nicola', 'jf_alpha', 'jf_gongitsune', 'jf_nezumi', 'jf_tebukuro', 'jm_kumo',
|
|
37
|
+
'pf_dora', 'pm_alex', 'pm_santa', 'zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi',
|
|
38
|
+
'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang',
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const KOKORO_LANGS = Object.freeze({
|
|
42
|
+
a: 'US', b: 'UK', e: 'Spanish', f: 'French', h: 'Hindi', i: 'Italian', j: 'Japanese', p: 'Brazilian Portuguese', z: 'Mandarin',
|
|
43
|
+
});
|
|
44
|
+
const KOKORO_GENDERS = Object.freeze({ f: 'female', m: 'male' });
|
|
45
|
+
|
|
46
|
+
function voicesHome() {
|
|
47
|
+
return process.env.SM_VOICES_HOME || path.join(os.homedir(), '.claude', 'session-manager', 'voices');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function kokoroModelDir() {
|
|
51
|
+
return process.env.KOKORO_MODEL_DIR || path.join(os.homedir(), '.cache', 'kokoro-onnx');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function projectVoicesDir(projectRoot) {
|
|
55
|
+
return projectRoot ? path.join(path.resolve(projectRoot), '.claude', 'voices') : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function machineVoicesDir() {
|
|
59
|
+
return path.join(voicesHome(), 'library');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 'af_heart' -> 'Heart (US female)'. */
|
|
63
|
+
function builtinLabel(id) {
|
|
64
|
+
const m = /^([a-z])([a-z])_(.+)$/.exec(id);
|
|
65
|
+
if (!m) return id;
|
|
66
|
+
const name = m[3].charAt(0).toUpperCase() + m[3].slice(1);
|
|
67
|
+
const lang = KOKORO_LANGS[m[1]];
|
|
68
|
+
const gender = KOKORO_GENDERS[m[2]];
|
|
69
|
+
const tags = [lang, gender].filter(Boolean).join(' ');
|
|
70
|
+
return tags ? `${name} (${tags})` : name;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Entry names in a zip's central directory; throws on a non-zip. Reads only the tail + directory. */
|
|
74
|
+
function zipEntryNames(file) {
|
|
75
|
+
const fd = fs.openSync(file, 'r');
|
|
76
|
+
try {
|
|
77
|
+
const size = fs.fstatSync(fd).size;
|
|
78
|
+
const tailLen = Math.min(size, 65536 + 22);
|
|
79
|
+
const tail = Buffer.alloc(tailLen);
|
|
80
|
+
fs.readSync(fd, tail, 0, tailLen, size - tailLen);
|
|
81
|
+
let eocd = -1;
|
|
82
|
+
for (let i = tailLen - 22; i >= 0; i--) {
|
|
83
|
+
if (tail.readUInt32LE(i) === 0x06054b50) { eocd = i; break; }
|
|
84
|
+
}
|
|
85
|
+
if (eocd === -1) throw new Error('no zip end-of-central-directory record');
|
|
86
|
+
const count = tail.readUInt16LE(eocd + 10);
|
|
87
|
+
const cdSize = tail.readUInt32LE(eocd + 12);
|
|
88
|
+
const cdOffset = tail.readUInt32LE(eocd + 16);
|
|
89
|
+
if (cdOffset + cdSize > size) throw new Error('zip central directory out of range');
|
|
90
|
+
const cd = Buffer.alloc(cdSize);
|
|
91
|
+
fs.readSync(fd, cd, 0, cdSize, cdOffset);
|
|
92
|
+
const names = [];
|
|
93
|
+
let p = 0;
|
|
94
|
+
for (let n = 0; n < count; n++) {
|
|
95
|
+
if (p + 46 > cd.length || cd.readUInt32LE(p) !== 0x02014b50) throw new Error('bad zip central directory entry');
|
|
96
|
+
const nameLen = cd.readUInt16LE(p + 28);
|
|
97
|
+
const extraLen = cd.readUInt16LE(p + 30);
|
|
98
|
+
const commentLen = cd.readUInt16LE(p + 32);
|
|
99
|
+
names.push(cd.toString('utf8', p + 46, p + 46 + nameLen));
|
|
100
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
101
|
+
}
|
|
102
|
+
return names;
|
|
103
|
+
} finally {
|
|
104
|
+
fs.closeSync(fd);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function builtinEntry(id, installed) {
|
|
109
|
+
return {
|
|
110
|
+
id,
|
|
111
|
+
label: builtinLabel(id),
|
|
112
|
+
voice: { engine: 'kokoro', id },
|
|
113
|
+
engine: 'kokoro',
|
|
114
|
+
sampleText: DEFAULT_SAMPLE,
|
|
115
|
+
licence: BUILTIN_LICENCE,
|
|
116
|
+
heavy: false,
|
|
117
|
+
scope: 'builtin',
|
|
118
|
+
installed,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function builtinVoices() {
|
|
123
|
+
let ids = null;
|
|
124
|
+
try {
|
|
125
|
+
const names = zipEntryNames(path.join(kokoroModelDir(), 'voices-v1.0.bin'));
|
|
126
|
+
ids = names.filter((n) => n.endsWith('.npy')).map((n) => path.posix.basename(n).slice(0, -4)).filter(Boolean);
|
|
127
|
+
if (ids.length === 0) ids = null;
|
|
128
|
+
} catch { /* missing or unreadable: fall back */ }
|
|
129
|
+
if (ids) return [...new Set(ids)].map((id) => builtinEntry(id, true));
|
|
130
|
+
return KOKORO_V1_VOICES.map((id) => builtinEntry(id, false));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** -> null when `json` is a valid voice entry for file stem `stem`, else a reason string. */
|
|
134
|
+
function validateVoiceEntry(json, stem) {
|
|
135
|
+
if (typeof stem !== 'string' || !VOICE_ID_RE.test(stem)) return `file name '${stem}' must match ${VOICE_ID_RE}`;
|
|
136
|
+
if (!json || typeof json !== 'object' || Array.isArray(json)) return 'voice entry must be an object';
|
|
137
|
+
if ('id' in json && json.id !== stem) return `id '${json.id}' must equal the file name '${stem}'`;
|
|
138
|
+
if ('label' in json && (typeof json.label !== 'string' || json.label.length < 1 || json.label.length > LABEL_MAX)) {
|
|
139
|
+
return `label must be a 1-${LABEL_MAX} char string`;
|
|
140
|
+
}
|
|
141
|
+
const v = json.voice;
|
|
142
|
+
if (!v || typeof v !== 'object' || Array.isArray(v)) return 'voice is required';
|
|
143
|
+
if ('voiceId' in v) return 'voice must be an inline voice, not a {voiceId} reference (no chains)';
|
|
144
|
+
const vErr = validateCharacterJson({ name: 'x', palette: ['x'], voice: v });
|
|
145
|
+
if (vErr) return vErr;
|
|
146
|
+
if ('sampleText' in json && (typeof json.sampleText !== 'string' || json.sampleText.length > SAMPLE_MAX)) {
|
|
147
|
+
return `sampleText must be a string of at most ${SAMPLE_MAX} chars`;
|
|
148
|
+
}
|
|
149
|
+
if ('licence' in json && (typeof json.licence !== 'string' || json.licence.length > LICENCE_MAX)) {
|
|
150
|
+
return `licence must be a string of at most ${LICENCE_MAX} chars`;
|
|
151
|
+
}
|
|
152
|
+
if ('heavy' in json && typeof json.heavy !== 'boolean') return 'heavy must be a boolean';
|
|
153
|
+
if ('pinFiles' in json) {
|
|
154
|
+
const pf = json.pinFiles;
|
|
155
|
+
if (!Array.isArray(pf) || pf.length > PIN_FILES_MAX) return `pinFiles must be an array of at most ${PIN_FILES_MAX} paths`;
|
|
156
|
+
for (const f of pf) {
|
|
157
|
+
if (typeof f !== 'string' || !f) return 'pinFiles items must be non-empty strings';
|
|
158
|
+
if (path.isAbsolute(f) || path.posix.isAbsolute(f) || path.win32.isAbsolute(f)) return `pinFiles '${f}' must be project-relative, not absolute`;
|
|
159
|
+
if (f.split(/[\\/]/).includes('..')) return `pinFiles '${f}' must not contain '..'`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** -> { entry } | { error } | null (no file). */
|
|
166
|
+
function readEntryFile(file, scope) {
|
|
167
|
+
if (!fs.existsSync(file)) return null;
|
|
168
|
+
const stem = path.basename(file, '.json');
|
|
169
|
+
let json;
|
|
170
|
+
try {
|
|
171
|
+
const raw = fs.readFileSync(file, 'utf8');
|
|
172
|
+
if (Buffer.byteLength(raw, 'utf8') > MAX_ENTRY_BYTES) return { error: `exceeds the ${MAX_ENTRY_BYTES}-byte limit` };
|
|
173
|
+
json = JSON.parse(raw);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
return { error: `not valid JSON: ${e.message}` };
|
|
176
|
+
}
|
|
177
|
+
const reason = validateVoiceEntry(json, stem);
|
|
178
|
+
if (reason) return { error: reason };
|
|
179
|
+
return {
|
|
180
|
+
entry: {
|
|
181
|
+
id: stem,
|
|
182
|
+
label: json.label || stem,
|
|
183
|
+
voice: json.voice,
|
|
184
|
+
engine: json.voice.engine,
|
|
185
|
+
sampleText: json.sampleText ?? DEFAULT_SAMPLE,
|
|
186
|
+
licence: json.licence ?? 'unknown',
|
|
187
|
+
heavy: json.heavy === true,
|
|
188
|
+
...(json.pinFiles ? { pinFiles: [...json.pinFiles] } : {}),
|
|
189
|
+
scope,
|
|
190
|
+
file,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function listDir(dir) {
|
|
196
|
+
if (!dir) return [];
|
|
197
|
+
try {
|
|
198
|
+
return fs.readdirSync(dir).filter((f) => f.endsWith('.json')).sort().map((f) => path.join(dir, f));
|
|
199
|
+
} catch {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function emptyApprovals() {
|
|
205
|
+
return { version: 1, approvals: {} };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** <voicesHome>/approvals.json; never throws (missing/corrupt = empty). */
|
|
209
|
+
function readApprovals() {
|
|
210
|
+
try {
|
|
211
|
+
const j = JSON.parse(fs.readFileSync(path.join(voicesHome(), 'approvals.json'), 'utf8'));
|
|
212
|
+
if (!j || typeof j !== 'object' || !j.approvals || typeof j.approvals !== 'object' || Array.isArray(j.approvals)) return emptyApprovals();
|
|
213
|
+
return { version: 1, approvals: j.approvals };
|
|
214
|
+
} catch {
|
|
215
|
+
return emptyApprovals();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** approvals.json key: '<scope>|<resolved projectRoot, project scope only>|<id>'. The ONE copy — voicesIpc.cjs (the writer) imports it. */
|
|
220
|
+
function approvalKey(scope, projectRoot, id) {
|
|
221
|
+
return `${scope}|${scope === 'project' && projectRoot ? path.resolve(projectRoot) : ''}|${id}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Key-sorted JSON (undefined keys dropped) — the stable bytes pinOf hashes. */
|
|
225
|
+
function canonical(v) {
|
|
226
|
+
if (Array.isArray(v)) return `[${v.map(canonical).join(',')}]`;
|
|
227
|
+
if (v && typeof v === 'object') {
|
|
228
|
+
return `{${Object.keys(v).sort().filter((k) => v[k] !== undefined).map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(',')}}`;
|
|
229
|
+
}
|
|
230
|
+
return JSON.stringify(v === undefined ? null : v);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const sha256 = (b) => crypto.createHash('sha256').update(b).digest('hex');
|
|
234
|
+
|
|
235
|
+
/** sha256 of canonical {id, voice, pinFiles} + per pinFile sha256 of its bytes (or 'missing'). */
|
|
236
|
+
function pinOf(entry, projectRoot) {
|
|
237
|
+
const pinFiles = Array.isArray(entry.pinFiles) ? entry.pinFiles : [];
|
|
238
|
+
const h = crypto.createHash('sha256');
|
|
239
|
+
h.update(canonical({ id: entry.id, voice: entry.voice, pinFiles }));
|
|
240
|
+
for (const f of pinFiles) {
|
|
241
|
+
let part = 'missing';
|
|
242
|
+
try {
|
|
243
|
+
if (projectRoot) part = sha256(fs.readFileSync(path.join(path.resolve(projectRoot), f)));
|
|
244
|
+
} catch { /* missing */ }
|
|
245
|
+
h.update(part);
|
|
246
|
+
}
|
|
247
|
+
return h.digest('hex');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function withApproval(entry, projectRoot, approvals) {
|
|
251
|
+
const a = approvals.approvals[approvalKey(entry.scope, projectRoot, entry.id)];
|
|
252
|
+
const approved = !!(a && typeof a === 'object');
|
|
253
|
+
const pinOk = approved ? a.pin === pinOf(entry, projectRoot) : true;
|
|
254
|
+
return { ...entry, approved, pinOk };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** -> { voices, errors }: every library voice, highest scope wins per id. */
|
|
258
|
+
function listVoices(projectRoot) {
|
|
259
|
+
const approvals = readApprovals();
|
|
260
|
+
const errors = [];
|
|
261
|
+
const byId = new Map();
|
|
262
|
+
const add = (entry) => { if (!byId.has(entry.id)) byId.set(entry.id, entry); };
|
|
263
|
+
for (const [scope, dir] of [['project', projectVoicesDir(projectRoot)], ['machine', machineVoicesDir()]]) {
|
|
264
|
+
for (const file of listDir(dir)) {
|
|
265
|
+
const r = readEntryFile(file, scope);
|
|
266
|
+
if (!r) continue;
|
|
267
|
+
if (r.error) errors.push({ file, error: r.error });
|
|
268
|
+
else add(r.entry);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (const b of builtinVoices()) add(b);
|
|
272
|
+
const voices = [...byId.values()]
|
|
273
|
+
.map((e) => withApproval(e, projectRoot, approvals))
|
|
274
|
+
.sort((a, b) => (SCOPE_ORDER[a.scope] - SCOPE_ORDER[b.scope]) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
275
|
+
return { voices, errors };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** -> { ok:true, entry, voice, scope, approved } | { ok:false, error }. */
|
|
279
|
+
function resolveVoiceId(projectRoot, id) {
|
|
280
|
+
if (typeof id !== 'string' || !VOICE_ID_RE.test(id)) return { ok: false, error: `unknown voice '${id}'` };
|
|
281
|
+
const approvals = readApprovals();
|
|
282
|
+
let entry = null;
|
|
283
|
+
for (const [scope, dir] of [['project', projectVoicesDir(projectRoot)], ['machine', machineVoicesDir()]]) {
|
|
284
|
+
if (!dir) continue;
|
|
285
|
+
const r = readEntryFile(path.join(dir, `${id}.json`), scope);
|
|
286
|
+
if (r && r.error) return { ok: false, error: `voice '${id}' is invalid (${path.join(dir, `${id}.json`)}): ${r.error}` };
|
|
287
|
+
if (r) { entry = r.entry; break; }
|
|
288
|
+
if (approvals.approvals[approvalKey(scope, projectRoot, id)]) {
|
|
289
|
+
return { ok: false, error: `approved voice '${id}' was removed outside the Voices screen` };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!entry) entry = builtinVoices().find((b) => b.id === id) || null;
|
|
293
|
+
if (!entry) return { ok: false, error: `unknown voice '${id}'` };
|
|
294
|
+
const e = withApproval(entry, projectRoot, approvals);
|
|
295
|
+
if (e.approved && !e.pinOk) {
|
|
296
|
+
return { ok: false, error: `approved voice '${id}' changed since a human approved it; re-approve it in Project Home > Video > Voices` };
|
|
297
|
+
}
|
|
298
|
+
return { ok: true, entry: e, voice: e.voice, scope: e.scope, approved: e.approved };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
module.exports = {
|
|
302
|
+
voicesHome,
|
|
303
|
+
listVoices,
|
|
304
|
+
resolveVoiceId,
|
|
305
|
+
pinOf,
|
|
306
|
+
approvalKey,
|
|
307
|
+
canonical,
|
|
308
|
+
readApprovals,
|
|
309
|
+
validateVoiceEntry,
|
|
310
|
+
KOKORO_V1_VOICES,
|
|
311
|
+
VOICE_ID_RE,
|
|
312
|
+
};
|
|
@@ -181,6 +181,11 @@ async function mergeActiveIndex(cwd, { sessions: rawMemorySessions = {}, events:
|
|
|
181
181
|
Promise.resolve()
|
|
182
182
|
.then(() => stopPreview(id))
|
|
183
183
|
.catch((e) => console.warn(`[activeIndexMerge] app preview stop failed for ${id}`, e));
|
|
184
|
+
// Outside-state poke: a deleted open Epic leaves the index here and
|
|
185
|
+
// writes no event-log kind the emitter listens for, so it yields 'gone'.
|
|
186
|
+
Promise.resolve()
|
|
187
|
+
.then(() => require('./epicStateEmitter.cjs').pokeEpicState(cwd, id))
|
|
188
|
+
.catch((e) => console.warn(`[activeIndexMerge] epic state poke failed for ${id}`, e));
|
|
184
189
|
}
|
|
185
190
|
// Status mirror (epicStatusMirror.cjs) — this IPC handler is the
|
|
186
191
|
// renderer-driven persist path (persistActiveIndex), the write site for
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* artifactAdminRoutes.cjs — loopback admin HTTP routes in front of the per-project
|
|
4
|
+
* Artifacts store (artifactStore.cjs, the ONE writer of `artifacts/`). The artifact
|
|
5
|
+
* MCP tool and other local callers reach the store only through here:
|
|
6
|
+
* POST /admin/artifacts/publish { path, title?, kind?, cwd?, originClaudeSessionId?, sourcePromptId? }
|
|
7
|
+
* -> { ok, storedPath, revealPath, entry }
|
|
8
|
+
* GET /admin/artifacts?cwd= -> { ok, projectRoot, artifacts }
|
|
9
|
+
*
|
|
10
|
+
* The bearer-token check is the transport's (localAdminHttp.cjs handleRequest), shared
|
|
11
|
+
* by every admin route. The calling project + Epic come from resolveProjectContext
|
|
12
|
+
* (projectRootResolve.cjs), so a caller inside an Epic worktree, or one that only knows
|
|
13
|
+
* its claude session id, still lands on the main project and its Epic. A relative
|
|
14
|
+
* `path` resolves against that Epic's worktree when known, else the project root.
|
|
15
|
+
* Allowed source roots: project root, the Epic worktree, the artifact staging base,
|
|
16
|
+
* os.tmpdir().
|
|
17
|
+
*
|
|
18
|
+
* Refusals are 4xx `{ ok:false, error, message }` where `error` names the reason:
|
|
19
|
+
* bad_request, no_project, no_epic, not_found, outside_root, not_a_file, too_large,
|
|
20
|
+
* refused. Deliberately NO route that mints an Epic (SINGLE-CREATOR LAW, epicMint.cjs).
|
|
21
|
+
*/
|
|
22
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
const os = require('node:os');
|
|
25
|
+
const path = require('node:path');
|
|
26
|
+
const { readBody, sendJson } = require('../feedback-remote/localAdminHttp.cjs');
|
|
27
|
+
|
|
28
|
+
const MAX_PATH = 4096;
|
|
29
|
+
const MAX_TITLE = 500;
|
|
30
|
+
const MAX_ID = 200;
|
|
31
|
+
|
|
32
|
+
class RouteError extends Error {
|
|
33
|
+
/** @param {number} status @param {string} code @param {string} message */
|
|
34
|
+
constructor(status, code, message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.status = status;
|
|
37
|
+
this.code = code;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @param {string} message */
|
|
42
|
+
const bad = (message) => new RouteError(400, 'bad_request', message);
|
|
43
|
+
|
|
44
|
+
/** @param {any} req @returns {Promise<Record<string, unknown>>} */
|
|
45
|
+
async function readJsonBody(req) {
|
|
46
|
+
let raw;
|
|
47
|
+
try {
|
|
48
|
+
raw = await readBody(req);
|
|
49
|
+
} catch (/** @type {any} */ e) {
|
|
50
|
+
throw bad(`request body rejected: ${e?.message ?? 'unreadable'}`);
|
|
51
|
+
}
|
|
52
|
+
/** @type {any} */
|
|
53
|
+
let body;
|
|
54
|
+
try {
|
|
55
|
+
body = raw ? JSON.parse(raw) : {};
|
|
56
|
+
} catch {
|
|
57
|
+
throw bad('invalid JSON body');
|
|
58
|
+
}
|
|
59
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) throw bad('body must be a JSON object');
|
|
60
|
+
return body;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @param {unknown} v @param {string} name @param {number} max @returns {string | undefined} */
|
|
64
|
+
function optString(v, name, max) {
|
|
65
|
+
if (v === undefined || v === null || v === '') return undefined;
|
|
66
|
+
if (typeof v !== 'string' || v.length > max) throw bad(`${name} must be a string of at most ${max} characters`);
|
|
67
|
+
return v;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @param {unknown} v @returns {string | undefined} */
|
|
71
|
+
function optAbsCwd(v) {
|
|
72
|
+
const s = optString(v, 'cwd', MAX_PATH);
|
|
73
|
+
if (s !== undefined && !path.isAbsolute(s)) throw bad('cwd must be an absolute path');
|
|
74
|
+
return s;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Map an artifactStore refusal string to a status + reason code.
|
|
79
|
+
* @param {string} error
|
|
80
|
+
* @returns {RouteError}
|
|
81
|
+
*/
|
|
82
|
+
function storeRefusal(error) {
|
|
83
|
+
const msg = String(error || 'publish refused');
|
|
84
|
+
if (/outside every allowed root|already inside the artifacts store/.test(msg)) return new RouteError(400, 'outside_root', msg);
|
|
85
|
+
if (/not a regular file|is a symlink/.test(msg)) return new RouteError(400, 'not_a_file', msg);
|
|
86
|
+
if (/oversize/.test(msg)) return new RouteError(413, 'too_large', msg);
|
|
87
|
+
if (/source unreadable|source unresolvable/.test(msg)) {
|
|
88
|
+
return /ENOENT/.test(msg) ? new RouteError(404, 'not_found', msg) : new RouteError(400, 'not_a_file', msg);
|
|
89
|
+
}
|
|
90
|
+
if (/kind must be|absolute path|unsafe epicId|exactly one of/.test(msg)) return new RouteError(400, 'bad_request', msg);
|
|
91
|
+
if (/copy failed|ledger write failed|publish failed/.test(msg)) return new RouteError(500, 'internal', msg);
|
|
92
|
+
return new RouteError(400, 'refused', msg);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The artifact staging base (<worktreeBase>/artifact-staging), or null when unresolvable. */
|
|
96
|
+
function defaultStagingBase() {
|
|
97
|
+
try {
|
|
98
|
+
const { worktreeBase } = require('../scheduler/schedulerPaths.cjs');
|
|
99
|
+
return path.join(worktreeBase(), 'artifact-staging');
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The Epic's own worktree dir from its PromptSession (`worktree.dir`), or null.
|
|
107
|
+
* @param {(cwd: string) => { sessions: Record<string, any> }} readActiveIndexFn
|
|
108
|
+
* @param {string} projectCwd
|
|
109
|
+
* @param {string} epicId
|
|
110
|
+
* @returns {string | null}
|
|
111
|
+
*/
|
|
112
|
+
function epicWorktreeDir(readActiveIndexFn, projectCwd, epicId) {
|
|
113
|
+
try {
|
|
114
|
+
const { sessions } = readActiveIndexFn(projectCwd);
|
|
115
|
+
const dir = sessions && sessions[epicId] && sessions[epicId].worktree && sessions[epicId].worktree.dir;
|
|
116
|
+
return typeof dir === 'string' && path.isAbsolute(dir) ? dir : null;
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {(req: any, query: URLSearchParams) => Promise<Record<string, unknown>>} fn
|
|
124
|
+
*/
|
|
125
|
+
function route(fn) {
|
|
126
|
+
return async (/** @type {any} */ req, /** @type {any} */ res, /** @type {URLSearchParams} */ query) => {
|
|
127
|
+
try {
|
|
128
|
+
sendJson(res, 200, await fn(req, query || new URLSearchParams()));
|
|
129
|
+
} catch (e) {
|
|
130
|
+
if (e instanceof RouteError) {
|
|
131
|
+
sendJson(res, e.status, { ok: false, error: e.code, message: e.message });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
sendJson(res, 500, { ok: false, error: 'internal', message: e instanceof Error ? e.message : 'request failed' });
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @typedef {{
|
|
141
|
+
* store?: { publishArtifact: Function, listArtifacts: Function },
|
|
142
|
+
* resolveProjectContext?: Function,
|
|
143
|
+
* readActiveIndex?: (cwd: string) => { sessions: Record<string, any> },
|
|
144
|
+
* stagingBase?: () => string | null,
|
|
145
|
+
* tmpdir?: () => string,
|
|
146
|
+
* postArtifactReadyNotice?: Function,
|
|
147
|
+
* }} ArtifactRouteDeps
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {any} adminHttp
|
|
152
|
+
* @param {ArtifactRouteDeps} [deps] test seams
|
|
153
|
+
*/
|
|
154
|
+
function registerAdminRoute(adminHttp, deps = {}) {
|
|
155
|
+
const store = () => deps.store || require('./artifactStore.cjs');
|
|
156
|
+
const resolveCtx = (/** @type {any} */ args) => (
|
|
157
|
+
deps.resolveProjectContext || require('../projectRootResolve.cjs').resolveProjectContext
|
|
158
|
+
)(args);
|
|
159
|
+
const readIndex = (/** @type {string} */ cwd) => (deps.readActiveIndex || require('./epicMint.cjs').readActiveIndex)(cwd);
|
|
160
|
+
const stagingBase = deps.stagingBase || defaultStagingBase;
|
|
161
|
+
const tmpdir = deps.tmpdir || os.tmpdir;
|
|
162
|
+
const postNotice = deps.postArtifactReadyNotice || require('./artifactNotice.cjs').postArtifactReadyNotice;
|
|
163
|
+
|
|
164
|
+
adminHttp.registerRoute('POST', '/admin/artifacts/publish', route(async (req) => {
|
|
165
|
+
const b = await readJsonBody(req);
|
|
166
|
+
const rawPath = optString(b.path, 'path', MAX_PATH);
|
|
167
|
+
if (!rawPath) throw bad('path is required');
|
|
168
|
+
const title = optString(b.title, 'title', MAX_TITLE);
|
|
169
|
+
const kind = optString(b.kind, 'kind', 20);
|
|
170
|
+
const cwd = optAbsCwd(b.cwd);
|
|
171
|
+
const originClaudeSessionId = optString(b.originClaudeSessionId, 'originClaudeSessionId', MAX_ID);
|
|
172
|
+
const sourcePromptId = optString(b.sourcePromptId, 'sourcePromptId', MAX_ID);
|
|
173
|
+
|
|
174
|
+
const ctx = resolveCtx({ cwd, originClaudeSessionId, epicId: sourcePromptId }) || {};
|
|
175
|
+
const projectRoot = typeof ctx.cwd === 'string' && ctx.cwd ? ctx.cwd : null;
|
|
176
|
+
if (!projectRoot) throw new RouteError(400, 'no_project', 'could not resolve the calling project: give cwd, originClaudeSessionId or sourcePromptId');
|
|
177
|
+
const epicId = typeof ctx.epicId === 'string' && ctx.epicId ? ctx.epicId : null;
|
|
178
|
+
if (!epicId) throw new RouteError(400, 'no_epic', 'no Epic resolved for this caller: give originClaudeSessionId or sourcePromptId of an Epic in this project');
|
|
179
|
+
|
|
180
|
+
const worktreeDir = epicWorktreeDir(readIndex, ctx.epicCwd || projectRoot, epicId);
|
|
181
|
+
const srcPath = path.isAbsolute(rawPath) ? path.resolve(rawPath) : path.resolve(worktreeDir || projectRoot, rawPath);
|
|
182
|
+
const allowedRoots = [projectRoot, worktreeDir, stagingBase(), tmpdir()]
|
|
183
|
+
.filter((r) => typeof r === 'string' && path.isAbsolute(r));
|
|
184
|
+
|
|
185
|
+
const result = await store().publishArtifact({
|
|
186
|
+
projectRoot,
|
|
187
|
+
epicId,
|
|
188
|
+
srcPath,
|
|
189
|
+
title,
|
|
190
|
+
kind,
|
|
191
|
+
producer: { epicId, sessionId: originClaudeSessionId || null },
|
|
192
|
+
allowedRoots,
|
|
193
|
+
});
|
|
194
|
+
if (!result || !result.ok) throw storeRefusal(result && result.error);
|
|
195
|
+
// One 'artifact-ready' notice per publish call, in the owning Epic's chat (never throws).
|
|
196
|
+
await postNotice({ cwd: projectRoot, epicId, entries: [{ storedPath: result.storedPath, entry: result.entry }] });
|
|
197
|
+
const revealPath = path.relative(projectRoot, result.storedPath).split(path.sep).join('/');
|
|
198
|
+
return { ok: true, storedPath: result.storedPath, revealPath, entry: result.entry };
|
|
199
|
+
}));
|
|
200
|
+
|
|
201
|
+
adminHttp.registerRoute('GET', '/admin/artifacts', route(async (_req, q) => {
|
|
202
|
+
const cwd = optAbsCwd(q.get('cwd'));
|
|
203
|
+
if (!cwd) throw bad('cwd is required (absolute path)');
|
|
204
|
+
const ctx = resolveCtx({ cwd }) || {};
|
|
205
|
+
const projectRoot = typeof ctx.cwd === 'string' && ctx.cwd ? ctx.cwd : null;
|
|
206
|
+
if (!projectRoot) throw new RouteError(400, 'no_project', `could not resolve a project for ${cwd}`);
|
|
207
|
+
return { ok: true, projectRoot, artifacts: store().listArtifacts(projectRoot) };
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = { registerAdminRoute };
|