claude-code-session-manager 0.126.0 → 0.128.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/bin/cli.cjs +71 -9
- package/bin/supervise.cjs +84 -0
- package/dist/assets/{AgentLibrary-bzeuZN4F.js → AgentLibrary-cNQU5YWy.js} +1 -1
- package/dist/assets/{Button-8dWfDDuQ.js → Button-9dIPAOBg.js} +1 -1
- package/dist/assets/{DataModel-D4ybBPZN.js → DataModel-DrDJ6ysw.js} +1 -1
- package/dist/assets/{History-hsztE6yh.js → History-4rrDdWNP.js} +1 -1
- package/dist/assets/{Hooks-CRmZMQaW.js → Hooks-Bj_jF5Pa.js} +1 -1
- package/dist/assets/{Library-Czt3Bojd.js → Library-D-Wsxrh7.js} +1 -1
- package/dist/assets/{ListDetail-Cr6Ct_WX.js → ListDetail-D7Om0H8j.js} +1 -1
- package/dist/assets/{McpServers-CeXJ2bng.js → McpServers-CbIbSd5o.js} +1 -1
- package/dist/assets/{Memory-caujO8O3.js → Memory-DgQlvQrO.js} +1 -1
- package/dist/assets/{Panel-D64i9tGz.js → Panel-DZHiD8Ar.js} +1 -1
- package/dist/assets/{Permissions-DpWOIrvr.js → Permissions-CfzduF4B.js} +1 -1
- package/dist/assets/{Plugins-Bd1ekP5P.js → Plugins-D-AG5nAo.js} +2 -2
- package/dist/assets/{ProvenanceBadge-B96A_uZf.js → ProvenanceBadge-B9JSEjll.js} +1 -1
- package/dist/assets/{SaveBar-D0Y2t-Ao.js → SaveBar-mVKig6hL.js} +1 -1
- package/dist/assets/{Scheduler-Y5_YbNrC.js → Scheduler-DFTCnh60.js} +1 -1
- package/dist/assets/{ScopeSwitcher-BmWA_dP9.js → ScopeSwitcher-s8J-yr7Z.js} +1 -1
- package/dist/assets/{Settings-Bcf65bpL.js → Settings-BTmxRMaP.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-BeSNXloA.js → SkillReferenceGraph-C5lKqf5y.js} +1 -1
- package/dist/assets/{Skills-DwnQKJVc.js → Skills-CxOacq0k.js} +1 -1
- package/dist/assets/{SystemPrompt-Dih6SCmL.js → SystemPrompt-BCWg5FAz.js} +1 -1
- package/dist/assets/{TagLibrary-BZ-Kp10P.js → TagLibrary-BnF0_PkG.js} +1 -1
- package/dist/assets/{TiptapBody-C2nEUmF7.js → TiptapBody-C2Iu6rZd.js} +1 -1
- package/dist/assets/{Toggle-Dw8-zNQo.js → Toggle-C-oD66BG.js} +1 -1
- package/dist/assets/{ViewTabs-CoYPKGN-.js → ViewTabs-Cs4v7vLY.js} +1 -1
- package/dist/assets/{historyTotals-BbKcNpV7.js → historyTotals-CbRSLD8f.js} +1 -1
- package/dist/assets/{index-BnKaYERU.css → index-DtdWBGrI.css} +1 -1
- package/dist/assets/index-DzY_GXYY.js +3081 -0
- package/dist/assets/{settingsSchema-6doG_61l.js → settingsSchema-bSBfHuan.js} +1 -1
- package/dist/assets/{skillFrontmatter-BYMYWDfb.js → skillFrontmatter-BEseWm8r.js} +1 -1
- package/dist/assets/{useAgentsDirWatch-Cqabjieh.js → useAgentsDirWatch-CdyHxKCI.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +343 -341
- package/package.json +1 -1
- package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -2
- package/scripts/scheduler-mcp-server.cjs +209 -7
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +37 -4
- package/src/main/crashDiagnostics.cjs +83 -8
- package/src/main/health.cjs +16 -5
- package/src/main/index.cjs +46 -0
- package/src/main/ipcSchemas.cjs +107 -0
- package/src/main/lib/chatBootRecovery.cjs +136 -0
- package/src/main/lib/chatInflight.cjs +88 -0
- package/src/main/lib/claude/agentModelResolve.cjs +26 -7
- package/src/main/lib/claude/personaToolScope.cjs +40 -2
- package/src/main/lib/demo-video-kit/capture.cjs +113 -0
- package/src/main/lib/demo-video-kit/character.cjs +97 -0
- package/src/main/lib/demo-video-kit/checks.cjs +150 -0
- package/src/main/lib/demo-video-kit/frames.cjs +200 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +52 -0
- package/src/main/lib/demo-video-kit/sound.cjs +312 -0
- package/src/main/lib/epic/epicDelegationStats.cjs +1 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +60 -6
- package/src/main/lib/epic/epicValidationHook.cjs +31 -3
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +71 -15
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +185 -34
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +15 -0
- package/src/main/lib/mcpToolCatalog.cjs +93 -14
- package/src/main/lib/opsOwnership.cjs +9 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +30 -5
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +116 -0
- package/src/main/lib/persona-macro/macroJobIpc.cjs +50 -0
- package/src/main/lib/persona-macro/macroJobStatus.cjs +112 -0
- package/src/main/lib/persona-macro/macroLibrary.cjs +73 -3
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +100 -0
- package/src/main/lib/prd/prdCreate.cjs +17 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +7 -2
- package/src/main/lib/process/childWithLog.cjs +38 -95
- package/src/main/lib/process/memoryScope.cjs +140 -0
- package/src/main/lib/process/ozonePlatform.cjs +15 -0
- package/src/main/lib/process/procIdentity.cjs +10 -3
- package/src/main/lib/process/scopeOomPolicy.cjs +69 -0
- package/src/main/lib/project-pages/pagesLibrary.cjs +171 -0
- package/src/main/lib/project-pages/playerBridge.cjs +129 -0
- package/src/main/lib/scheduler/cpuSample.cjs +147 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +40 -0
- package/src/main/lib/scheduler/jobLeftovers.cjs +204 -0
- package/src/main/lib/scheduler/jobSupervisorRecord.cjs +2 -1
- package/src/main/lib/scheduler/loadGate.cjs +116 -45
- package/src/main/lib/scheduler/queueStore.cjs +5 -2
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +10 -3
- package/src/main/lib/scheduler/schedulerConfig.cjs +7 -2
- package/src/main/lib/smfileHeaders.cjs +11 -3
- package/src/main/lib/telemetry/crashTelemetry.cjs +8 -4
- package/src/main/projectPages.cjs +107 -30
- package/src/main/promptSessionsIpc.cjs +131 -0
- package/src/main/scheduler/budget.cjs +31 -0
- package/src/main/scheduler/prdParser.cjs +2 -0
- package/src/main/scheduler/prdPaths.cjs +54 -0
- package/src/main/scheduler/reviewLadder.cjs +17 -0
- package/src/main/scheduler/starvation.cjs +22 -0
- package/src/main/scheduler.cjs +548 -77
- package/src/main/seedSchedulerMcp.cjs +10 -1
- package/src/main/templates/PRD_AUTHORING.md +5 -2
- package/src/main/transcripts.cjs +8 -0
- package/src/main/usage.cjs +4 -2
- package/src/main/webRemote.cjs +3 -1
- package/src/preload/api.d.ts +113 -7
- package/src/preload/apiSurface.json +70 -0
- package/src/preload/index.cjs +13 -0
- package/src/seed/agents/demo-video-builder.md +141 -43
- package/src/seed/agents/project-home-builder.md +26 -13
- package/dist/assets/index-DgPUERhe.js +0 -3079
package/src/main/health.cjs
CHANGED
|
@@ -88,6 +88,13 @@ function readFreshHeartbeat(heartbeatPath) {
|
|
|
88
88
|
return entry;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// Last tick's reason + detail from a heartbeat's dispatch block; both null
|
|
92
|
+
// when the heartbeat or its dispatch is missing.
|
|
93
|
+
function lastTickFromHeartbeat(heartbeat) {
|
|
94
|
+
const d = heartbeat?.dispatch;
|
|
95
|
+
return { lastTickReason: d?.lastTickReason ?? null, lastTickDetail: d?.lastTickDetail ?? null };
|
|
96
|
+
}
|
|
97
|
+
|
|
91
98
|
// Evaluates whether the scheduler tick looks stalled: pending work exists,
|
|
92
99
|
// there's free capacity to run it, and nothing about the queue's own state
|
|
93
100
|
// explains why it hasn't. Kept as a pure function of (queueState, heartbeat,
|
|
@@ -762,8 +769,8 @@ function evaluateCredentialHealth({ credState, now = Date.now() } = {}) {
|
|
|
762
769
|
* latestStarveEscalationReasons); a cwd with no recorded reason yet reports
|
|
763
770
|
* 'unknown' rather than failing.
|
|
764
771
|
*/
|
|
765
|
-
function evaluateStarveEscalationHealth(jobs, now, thresholdMs, escalationReasons = {}) {
|
|
766
|
-
const starved = findStarvedProjects(jobs, now, thresholdMs);
|
|
772
|
+
function evaluateStarveEscalationHealth(jobs, now, thresholdMs, escalationReasons = {}, lastDispatchAtByCwd = {}) {
|
|
773
|
+
const starved = findStarvedProjects(jobs, now, thresholdMs, lastDispatchAtByCwd);
|
|
767
774
|
if (starved.length === 0) return { ok: true };
|
|
768
775
|
const projects = starved.map((sp) => ({
|
|
769
776
|
cwd: sp.cwd,
|
|
@@ -988,9 +995,11 @@ async function check(opts = {}) {
|
|
|
988
995
|
machineStateRecovered: queueState.machineStateRecovered ?? false,
|
|
989
996
|
quarantinedCwds: (queueState.unreadableCwds ?? []).map((u) => u.cwd),
|
|
990
997
|
machineStateRecoveryMode: queueState.machineStateRecoveryMode ?? null,
|
|
991
|
-
|
|
992
|
-
//
|
|
993
|
-
//
|
|
998
|
+
...lastTickFromHeartbeat(heartbeat),
|
|
999
|
+
// Informational only (PRD 1085): the RAW 1-min loadavg per core vs the
|
|
1000
|
+
// launch-gate threshold, with no CPU sample behind it (the gate also
|
|
1001
|
+
// checks a CPU sample, so a ratio over threshold is not a hold). Read it
|
|
1002
|
+
// beside lastTickReason / lastTickDetail above.
|
|
994
1003
|
loadRatio: (() => {
|
|
995
1004
|
const cores = (os.cpus() || []).length;
|
|
996
1005
|
const l1 = os.loadavg()[0];
|
|
@@ -1066,6 +1075,7 @@ async function check(opts = {}) {
|
|
|
1066
1075
|
// the exact condition the 2026-09-12 19h Bilko starve went unreported by.
|
|
1067
1076
|
status.components.project_starve_escalation = evaluateStarveEscalationHealth(
|
|
1068
1077
|
queueState.jobs, now, STARVE_ESCALATION_MS, latestStarveEscalationReasons(auditLogPath()),
|
|
1078
|
+
queueState.lastDispatchAtByCwd,
|
|
1069
1079
|
);
|
|
1070
1080
|
if (!status.components.project_starve_escalation.ok) {
|
|
1071
1081
|
status.issues.push(status.components.project_starve_escalation.message);
|
|
@@ -1414,6 +1424,7 @@ module.exports = {
|
|
|
1414
1424
|
check,
|
|
1415
1425
|
evaluateTickLiveness,
|
|
1416
1426
|
readFreshHeartbeat,
|
|
1427
|
+
lastTickFromHeartbeat,
|
|
1417
1428
|
evaluatePrdMigrationHealth,
|
|
1418
1429
|
evaluateDelegationChainHealth,
|
|
1419
1430
|
evaluateCredentialHealth,
|
package/src/main/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ const { createProjectFolder } = require('./lib/projectFolder.cjs');
|
|
|
29
29
|
const { cleanChildEnv } = require('./lib/process/cleanEnv.cjs');
|
|
30
30
|
const { applyLoginShellPath } = require('./lib/process/loginShellPath.cjs');
|
|
31
31
|
const { terminateLosingInstance } = require('./lib/process/singleInstanceGuard.cjs');
|
|
32
|
+
const { ensureScopeOomPolicy } = require('./lib/process/scopeOomPolicy.cjs');
|
|
32
33
|
const { acquireSchedulerOwnership, releaseSchedulerOwnership } = require('./lib/process/instanceLock.cjs');
|
|
33
34
|
const { manager: ptyManager, registerPtyHandlers } = require('./pty.cjs');
|
|
34
35
|
const configMgr = require('./config.cjs');
|
|
@@ -102,6 +103,7 @@ const queueOps = require('./queueOps.cjs');
|
|
|
102
103
|
const pluginInstall = require('./pluginInstall.cjs');
|
|
103
104
|
const { seedDevPlugin } = require('./seedDevPlugin.cjs');
|
|
104
105
|
const { seedAgentPersonas } = require('./seedAgentPersonas.cjs');
|
|
106
|
+
const { seedDemoVideoKit } = require('./lib/demo-video-kit/seedKit.cjs');
|
|
105
107
|
const { seedSchedulerMcp } = require('./seedSchedulerMcp.cjs');
|
|
106
108
|
const { runSeedersSerially } = require('./lib/runSeeders.cjs');
|
|
107
109
|
const { getSeedStatus } = require('./seedStatus.cjs');
|
|
@@ -605,6 +607,16 @@ function broadcastMacrosChanged() {
|
|
|
605
607
|
sendIfAlive(mainWindow, 'macros:changed', {});
|
|
606
608
|
}
|
|
607
609
|
ipcMain.handle('macros:list', () => macroLibrary.listMacros());
|
|
610
|
+
// Background macro jobs: dispatch a built-in macro as a scheduler PRD inside an existing Epic.
|
|
611
|
+
// createPrd is wired exactly as chat:create-prd (below) so its own reconcile request queues the row.
|
|
612
|
+
require('./lib/persona-macro/macroJobIpc.cjs').registerMacroJobIpc(ipcMain, {
|
|
613
|
+
schemas,
|
|
614
|
+
validatePath: require('./config.cjs').validatePath,
|
|
615
|
+
readActiveIndex: require('./lib/epic/epicMint.cjs').readActiveIndex,
|
|
616
|
+
createPrd: (input) => prdCreate.createPrd(input, scheduler.remote),
|
|
617
|
+
loadJobs: async () => (await require('./lib/scheduler/queueStore.cjs').readMerged()).jobs || [],
|
|
618
|
+
archivePrd: (slug, cwd) => queueOps.archiveMany([slug], cwd),
|
|
619
|
+
});
|
|
608
620
|
ipcMain.handle('macros:save', validated(schemas.macrosSave, async (payload) => {
|
|
609
621
|
const macro = await macroLibrary.saveMacro(payload);
|
|
610
622
|
broadcastMacrosChanged();
|
|
@@ -1041,6 +1053,7 @@ registerLoopEfficiencyHandlers();
|
|
|
1041
1053
|
pluginInstall.registerPluginInstallHandlers();
|
|
1042
1054
|
memoryTool.registerMemoryHandlers();
|
|
1043
1055
|
activeIndexMerge.registerActiveIndexMergeHandlers();
|
|
1056
|
+
require('./promptSessionsIpc.cjs').registerPromptSessionsReadHandlers();
|
|
1044
1057
|
promptSessionsCreateEpic.registerPromptSessionsCreateEpicHandlers();
|
|
1045
1058
|
require('./lib/epic/archivedTranscript.cjs').registerIpc(ipcMain);
|
|
1046
1059
|
customerFeedbackIpc.registerCustomerFeedbackHandlers();
|
|
@@ -1086,6 +1099,29 @@ try {
|
|
|
1086
1099
|
logs.writeLine({ scope: 'main', level: 'error', message: 'ops retention IPC registration failed', meta: { error: e?.message } });
|
|
1087
1100
|
}
|
|
1088
1101
|
chatRunner.registerChatHandlers();
|
|
1102
|
+
// Boot recovery of chat turns that were in flight when the app last died (once, after handlers).
|
|
1103
|
+
try {
|
|
1104
|
+
const chatInflight = require('./lib/chatInflight.cjs');
|
|
1105
|
+
const { identity } = require('./lib/process/procIdentity.cjs');
|
|
1106
|
+
require('./lib/chatBootRecovery.cjs').recoverInflightTurns({
|
|
1107
|
+
ledger: chatInflight,
|
|
1108
|
+
run: (o) => chatRunner.run(o),
|
|
1109
|
+
holdOrphan: chatRunner.holdOrphanSession,
|
|
1110
|
+
releaseOrphan: chatRunner.releaseOrphanSession,
|
|
1111
|
+
identityOf: identity,
|
|
1112
|
+
sessionTurnState: async (entry) => {
|
|
1113
|
+
try {
|
|
1114
|
+
const { resolveEpicTranscriptPath } = require('./lib/epic/epicTranscriptPath.cjs');
|
|
1115
|
+
const { readTranscriptTail } = require('./lib/epic/epicDelegationStats.cjs');
|
|
1116
|
+
const filePath = resolveEpicTranscriptPath({ cwd: entry.cwd, claudeSessionId: entry.sessionId }).path;
|
|
1117
|
+
if (!filePath) return 'missing';
|
|
1118
|
+
return require('./lib/chatBootRecovery.cjs').classifyTurnTail(readTranscriptTail(filePath));
|
|
1119
|
+
} catch { return 'missing'; }
|
|
1120
|
+
},
|
|
1121
|
+
}).catch((e) => logs.writeLine({ scope: 'main', level: 'error', message: 'chat boot recovery failed', meta: { error: e?.message } }));
|
|
1122
|
+
} catch (e) {
|
|
1123
|
+
logs.writeLine({ scope: 'main', level: 'error', message: 'chat boot recovery wiring failed', meta: { error: e?.message } });
|
|
1124
|
+
}
|
|
1089
1125
|
|
|
1090
1126
|
// Direct in-process PRD authoring for a queued PromptTicket classified
|
|
1091
1127
|
// 'develop' (PRD 749 follow-up) — calls the same createPrd() the admin HTTP
|
|
@@ -1223,6 +1259,7 @@ app.on('web-contents-created', (_e, wc) => {
|
|
|
1223
1259
|
app.whenReady().then(async () => {
|
|
1224
1260
|
logs.pruneOld();
|
|
1225
1261
|
logs.writeLine({ scope: 'main', level: 'info', message: 'app start', meta: { version: app.getVersion(), platform: process.platform } });
|
|
1262
|
+
logs.writeLine({ scope: 'main', level: 'info', message: 'ozone platform', meta: { ozonePlatform: app.commandLine.getSwitchValue('ozone-platform') || 'default', override: process.env.SM_OZONE_PLATFORM || null } });
|
|
1226
1263
|
|
|
1227
1264
|
// Crash/OOM diagnostics: logs a postmortem if the PREVIOUS run died
|
|
1228
1265
|
// uncleanly (the silent OOM-kill we've been chasing), then starts the memory
|
|
@@ -1456,6 +1493,13 @@ app.whenReady().then(async () => {
|
|
|
1456
1493
|
// owner's running job and overwrote admin-api.json. Losing instances run
|
|
1457
1494
|
// scheduler-PASSIVE: read IPC still works (handlers registered above),
|
|
1458
1495
|
// nothing mutates.
|
|
1496
|
+
// Child OOM-kill must not stop the whole app scope (OOMPolicy=continue drop-in).
|
|
1497
|
+
try {
|
|
1498
|
+
const oom = ensureScopeOomPolicy({ log: (m) => logs.writeLine({ scope: 'main', level: 'warn', message: m }) });
|
|
1499
|
+
logs.writeLine({ scope: 'main', level: 'info', message: 'scope OOM policy', meta: oom });
|
|
1500
|
+
} catch (e) {
|
|
1501
|
+
logs.writeLine({ scope: 'main', level: 'warn', message: 'scope OOM policy failed', meta: { error: e?.message } });
|
|
1502
|
+
}
|
|
1459
1503
|
const ownership = acquireSchedulerOwnership();
|
|
1460
1504
|
if (ownership.owner) {
|
|
1461
1505
|
scheduler.init().catch((e) => {
|
|
@@ -1490,6 +1534,8 @@ app.whenReady().then(async () => {
|
|
|
1490
1534
|
bootSeedingPromise = runSeedersSerially([
|
|
1491
1535
|
{ name: 'dev-plugin', run: () => seedDevPlugin({ logger: console, writeLog: logs.writeLine }) },
|
|
1492
1536
|
{ name: 'agent-personas', run: () => seedAgentPersonas({ logger: console, writeLog: logs.writeLine }) },
|
|
1537
|
+
// Demo-video kit -> ~/.claude/session-manager/demo-video-kit/ (stamp-gated). SM_SEED_DEMO_VIDEO_KIT_DISABLE=1 to opt out.
|
|
1538
|
+
{ name: 'demo-video-kit', run: () => seedDemoVideoKit({ logger: console, writeLog: logs.writeLine }) },
|
|
1493
1539
|
{ name: 'scheduler-mcp', run: () => seedSchedulerMcp({ logger: console, writeLog: logs.writeLine }) },
|
|
1494
1540
|
]).catch((e) => {
|
|
1495
1541
|
logs.writeLine({ scope: 'seed', level: 'error', message: 'seed chain failed', meta: { error: e?.message } });
|
package/src/main/ipcSchemas.cjs
CHANGED
|
@@ -209,6 +209,15 @@ const promptSessionsMergeActiveIndex = z.object({
|
|
|
209
209
|
// routes state/promptSessions.ts's createPromptSession through it. `tag`/
|
|
210
210
|
// `source` reuse promptSessionSchema.cjs's own enums rather than retyping
|
|
211
211
|
// the value lists a third time.
|
|
212
|
+
// Archive write for markCompleted — main resolves the path via opsPath() and
|
|
213
|
+
// writes as the 'epics' owner, so the renderer (and a remote browser) never
|
|
214
|
+
// hands over a path. `archive` is opaque here; the handler checks its shape.
|
|
215
|
+
const promptSessionsWriteArchive = z.object({
|
|
216
|
+
cwd: z.string().min(1).max(4096),
|
|
217
|
+
epicId: z.string().regex(PROMPT_SESSION_ID_RE),
|
|
218
|
+
archive: z.record(z.string(), z.unknown()),
|
|
219
|
+
}).strict();
|
|
220
|
+
|
|
212
221
|
const promptSessionsCreateEpic = z.object({
|
|
213
222
|
cwd: z.string().min(1).max(4096),
|
|
214
223
|
goalText: z.string().min(1).max(20000),
|
|
@@ -233,6 +242,9 @@ const promptSessionsCreateWorktree = z.object({
|
|
|
233
242
|
});
|
|
234
243
|
|
|
235
244
|
// Renderer entry point for reopening a completed Epic in place (lib/epic/epicReopen.cjs).
|
|
245
|
+
const promptSessionsCwd = z.object({ cwd: z.string().min(1).max(4096) }).strict();
|
|
246
|
+
const promptSessionsReadArchived = z.object({ cwd: z.string().min(1).max(4096), epicId: z.string().regex(PROMPT_SESSION_ID_RE) }).strict();
|
|
247
|
+
const promptSessionsReadSessionTranscript = z.object({ cwd: z.string().min(1).max(4096), sessionId: z.string().min(1).max(128) }).strict();
|
|
236
248
|
const promptSessionsReopen = z.object({ cwd: z.string().min(1).max(4096), epicId: z.string().regex(PROMPT_SESSION_ID_RE) }).strict();
|
|
237
249
|
|
|
238
250
|
// Renderer entry point for folding an Epic's isolated git worktree branch
|
|
@@ -651,6 +663,14 @@ const agentsSavePersona = AgentPersonaSaveSchema;
|
|
|
651
663
|
const macrosSave = MacroSaveSchema;
|
|
652
664
|
const macrosDelete = MacroDeleteSchema;
|
|
653
665
|
const macrosSetProject = MacroSetProjectSchema;
|
|
666
|
+
// Background macro job (macroJobIpc.cjs): press a built-in macro as a scheduler PRD inside an existing Epic.
|
|
667
|
+
const macrosDispatchJob = z.object({
|
|
668
|
+
cwd: z.string().min(1).max(4096),
|
|
669
|
+
macroId: z.string().min(1).max(128),
|
|
670
|
+
epicId: z.string().min(1).max(200),
|
|
671
|
+
extraInstructions: z.string().max(4000).optional(),
|
|
672
|
+
});
|
|
673
|
+
const macrosJobStatus = z.object({ cwd: z.string().min(1).max(4096) });
|
|
654
674
|
|
|
655
675
|
// ──────────────────────────────────────────── Memory tool (Bundle C, cycle 3)
|
|
656
676
|
// Workspace-scoped markdown store at ~/.claude/projects/<ws>/memory/.
|
|
@@ -826,6 +846,80 @@ const projectDemoVideoAdminWriteBody = z.object({
|
|
|
826
846
|
html: z.string(),
|
|
827
847
|
}).strict();
|
|
828
848
|
|
|
849
|
+
// ──────────────────────────────────────────── Project Home library entries
|
|
850
|
+
// One id rule for every library entry; '_character' starts with '_' so it can
|
|
851
|
+
// never match.
|
|
852
|
+
const ENTRY_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
853
|
+
const entryId = z.string().regex(ENTRY_ID_RE);
|
|
854
|
+
const projectVideoReportFields = {
|
|
855
|
+
lufs: z.number().nullable(),
|
|
856
|
+
truePeakDb: z.number().nullable(),
|
|
857
|
+
speechS: z.number().nullable(),
|
|
858
|
+
readingGrade: z.number().nullable(),
|
|
859
|
+
checks: z.array(z.object({
|
|
860
|
+
id: z.string().max(60),
|
|
861
|
+
ok: z.boolean(),
|
|
862
|
+
detail: z.string().max(300),
|
|
863
|
+
}).strict()).max(60),
|
|
864
|
+
};
|
|
865
|
+
const projectVideoMeta = z.object({
|
|
866
|
+
id: entryId,
|
|
867
|
+
title: z.string().min(1).max(120),
|
|
868
|
+
kind: z.enum(['project-demo', 'blog-post', 'feature']),
|
|
869
|
+
style: z.string().max(40),
|
|
870
|
+
lengthS: z.number().int().min(5).max(60),
|
|
871
|
+
createdAt: z.string().datetime(),
|
|
872
|
+
character: z.string().max(80).nullable(),
|
|
873
|
+
sources: z.array(z.object({
|
|
874
|
+
claim: z.string().max(300),
|
|
875
|
+
source: z.string().max(600),
|
|
876
|
+
ref: z.string().max(300),
|
|
877
|
+
}).strict()).max(40),
|
|
878
|
+
report: z.object({ ...projectVideoReportFields, bytes: z.number().int() }).strict(),
|
|
879
|
+
macroVersion: z.number().int().min(0),
|
|
880
|
+
seedVersion: z.number().int().min(0),
|
|
881
|
+
model: z.string().max(60),
|
|
882
|
+
effort: z.string().max(60),
|
|
883
|
+
}).strict();
|
|
884
|
+
const projectPagesEntryKind = z.enum(['knowledge', 'video']);
|
|
885
|
+
const projectPagesRename = z.object({
|
|
886
|
+
cwd: z.string().min(1).max(4096),
|
|
887
|
+
kind: projectPagesEntryKind,
|
|
888
|
+
id: entryId,
|
|
889
|
+
title: z.string().min(1).max(120),
|
|
890
|
+
}).strict();
|
|
891
|
+
const projectPagesDelete = z.object({
|
|
892
|
+
cwd: z.string().min(1).max(4096),
|
|
893
|
+
kind: projectPagesEntryKind,
|
|
894
|
+
id: entryId,
|
|
895
|
+
}).strict();
|
|
896
|
+
const projectPageMeta = z.object({
|
|
897
|
+
id: entryId,
|
|
898
|
+
title: z.string().min(1).max(120),
|
|
899
|
+
topic: z.string().max(120),
|
|
900
|
+
createdAt: z.string().datetime(),
|
|
901
|
+
model: z.string().max(60),
|
|
902
|
+
}).strict();
|
|
903
|
+
const projectPageAdminWriteBody = z.object({
|
|
904
|
+
cwd: z.string().min(1).max(4096).optional(),
|
|
905
|
+
pageId: entryId,
|
|
906
|
+
title: z.string().min(1).max(120),
|
|
907
|
+
topic: z.string().max(120).optional(),
|
|
908
|
+
html: z.string(),
|
|
909
|
+
}).strict();
|
|
910
|
+
// Server stamps id, createdAt and report.bytes.
|
|
911
|
+
const projectVideoAdminWriteBody = z.object({
|
|
912
|
+
cwd: z.string().min(1).max(4096).optional(),
|
|
913
|
+
videoId: entryId,
|
|
914
|
+
title: z.string().min(1).max(120),
|
|
915
|
+
kind: z.enum(['project-demo', 'blog-post', 'feature']),
|
|
916
|
+
lengthS: z.number().int().min(5).max(60),
|
|
917
|
+
html: z.string(),
|
|
918
|
+
meta: projectVideoMeta.omit({ id: true, createdAt: true }).extend({
|
|
919
|
+
report: z.object(projectVideoReportFields).strict(),
|
|
920
|
+
}),
|
|
921
|
+
}).strict();
|
|
922
|
+
|
|
829
923
|
const projectBriefSetPin = z.object({
|
|
830
924
|
cwd: z.string().min(1).max(4096),
|
|
831
925
|
block: PROJECT_BRIEF_BLOCK,
|
|
@@ -1275,6 +1369,7 @@ module.exports = {
|
|
|
1275
1369
|
SCHEDULE_SLUG_RE,
|
|
1276
1370
|
SCHEDULE_RUN_ID_RE,
|
|
1277
1371
|
PRD_CREATE_SLUG_RE,
|
|
1372
|
+
ENTRY_ID_RE,
|
|
1278
1373
|
READ_COMMANDS,
|
|
1279
1374
|
SAS_GATED_READS,
|
|
1280
1375
|
MUTATE_COMMANDS,
|
|
@@ -1353,17 +1448,27 @@ module.exports = {
|
|
|
1353
1448
|
memoryProposeFix,
|
|
1354
1449
|
projectBriefCwd,
|
|
1355
1450
|
projectPagesCwd,
|
|
1451
|
+
projectPagesRename,
|
|
1452
|
+
projectPagesDelete,
|
|
1356
1453
|
projectHomeAdminWriteBody,
|
|
1357
1454
|
projectDemoVideoAdminWriteBody,
|
|
1455
|
+
projectVideoMeta,
|
|
1456
|
+
projectPageMeta,
|
|
1457
|
+
projectPageAdminWriteBody,
|
|
1458
|
+
projectVideoAdminWriteBody,
|
|
1358
1459
|
projectBriefSetPin,
|
|
1359
1460
|
projectBriefUpdate,
|
|
1360
1461
|
promptSessionTranscriptAppend,
|
|
1361
1462
|
promptSessionTranscriptRead,
|
|
1362
1463
|
epicDelegationStatsGet,
|
|
1363
1464
|
promptSessionsMergeActiveIndex,
|
|
1465
|
+
promptSessionsWriteArchive,
|
|
1364
1466
|
promptSessionsCreateEpic,
|
|
1365
1467
|
promptSessionsCreateWorktree,
|
|
1366
1468
|
promptSessionsReopen,
|
|
1469
|
+
promptSessionsCwd,
|
|
1470
|
+
promptSessionsReadArchived,
|
|
1471
|
+
promptSessionsReadSessionTranscript,
|
|
1367
1472
|
promptSessionsMergeToMain,
|
|
1368
1473
|
promptSessionsGetWorktreeDisabled,
|
|
1369
1474
|
promptSessionsSetWorktreeDisabled,
|
|
@@ -1390,6 +1495,8 @@ module.exports = {
|
|
|
1390
1495
|
macrosSave,
|
|
1391
1496
|
macrosDelete,
|
|
1392
1497
|
macrosSetProject,
|
|
1498
|
+
macrosDispatchJob,
|
|
1499
|
+
macrosJobStatus,
|
|
1393
1500
|
agentsGetPersonaBody,
|
|
1394
1501
|
agentsResolveModelInfo,
|
|
1395
1502
|
modelsCatalog,
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Boot recovery for chat turns that were in flight when the app died
|
|
5
|
+
* (ledger: lib/chatInflight.cjs). Per ledger entry:
|
|
6
|
+
* - pid alive AND it is an sm-claude-chat process for that sessionId → orphan: hold the
|
|
7
|
+
* session in chatRunner so run() queues instead of spawning a second writer, poll until
|
|
8
|
+
* it exits, then treat it as dead;
|
|
9
|
+
* - dead (or recycled pid) → Claude's own session JSONL decides (classifyTurnTail): finished or
|
|
10
|
+
* missing, or a silent entry → just clear the entry; unfinished → re-run ONCE through
|
|
11
|
+
* chatRunner.run() with the same sessionId and a fixed continue prompt, at most once per
|
|
12
|
+
* session per 24 h.
|
|
13
|
+
* Touches only the session's own turn: never mints an Epic or edits its title/objective/status.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
17
|
+
const ORPHAN_POLL_MS = 5000;
|
|
18
|
+
|
|
19
|
+
const CONTINUE_PROMPT = 'The Session Manager app restarted while your previous turn was running. '
|
|
20
|
+
+ 'Check what already landed (files, git status, commits, tool results) before repeating any step, '
|
|
21
|
+
+ 'then continue the interrupted work from where it stopped.';
|
|
22
|
+
|
|
23
|
+
function defaultPidAlive(pid) {
|
|
24
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
25
|
+
try { process.kill(pid, 0); return true; } catch (e) { return !!(e && e.code === 'EPERM'); }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isChatProcessFor(identity, sessionId) {
|
|
29
|
+
const cmd = identity && typeof identity.cmdline === 'string' ? identity.cmdline : '';
|
|
30
|
+
return cmd.includes('sm-claude-chat') && cmd.includes(sessionId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Classify the tail of a Claude session JSONL.
|
|
35
|
+
* @param {string} text
|
|
36
|
+
* @returns {'finished'|'unfinished'|'missing'}
|
|
37
|
+
*/
|
|
38
|
+
function classifyTurnTail(text) {
|
|
39
|
+
if (typeof text !== 'string' || !text) return 'missing';
|
|
40
|
+
const lines = text.split('\n');
|
|
41
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
42
|
+
const t = lines[i].trim();
|
|
43
|
+
if (!t) continue;
|
|
44
|
+
let obj;
|
|
45
|
+
try { obj = JSON.parse(t); } catch { continue; }
|
|
46
|
+
if (!obj || typeof obj !== 'object') continue;
|
|
47
|
+
if (obj.type === 'user') return 'unfinished';
|
|
48
|
+
if (obj.type === 'assistant') {
|
|
49
|
+
const sr = obj.message && obj.message.stop_reason;
|
|
50
|
+
return sr != null && sr !== 'tool_use' ? 'finished' : 'unfinished';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return 'missing';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {object} deps
|
|
58
|
+
* ledger {list,end,markRecovered,recoveredMap}, run(opts), holdOrphan(sid), releaseOrphan(sid),
|
|
59
|
+
* pidAlive(pid), identityOf(pid), sessionTurnState(entry) → 'finished'|'unfinished'|'missing',
|
|
60
|
+
* now(), pollMs, setTimer/clearTimer (tests)
|
|
61
|
+
* @returns {Promise<{ pending: Promise<void>, results: object[] }>} resolves after the first pass;
|
|
62
|
+
* `pending` settles once every orphan has exited and been handled.
|
|
63
|
+
*/
|
|
64
|
+
async function recoverInflightTurns(deps) {
|
|
65
|
+
const {
|
|
66
|
+
ledger, run, holdOrphan = () => {}, releaseOrphan = () => {},
|
|
67
|
+
pidAlive = defaultPidAlive, identityOf = () => null,
|
|
68
|
+
sessionTurnState = async () => 'missing',
|
|
69
|
+
now = Date.now, pollMs = ORPHAN_POLL_MS,
|
|
70
|
+
setTimer = setTimeout,
|
|
71
|
+
} = deps;
|
|
72
|
+
const results = [];
|
|
73
|
+
const waits = [];
|
|
74
|
+
let entries = [];
|
|
75
|
+
try { entries = await ledger.list(); } catch { entries = []; }
|
|
76
|
+
|
|
77
|
+
async function settleDead(entry) {
|
|
78
|
+
const { sessionId, tabId, cwd } = entry;
|
|
79
|
+
let state = 'missing';
|
|
80
|
+
if (!entry.silent) {
|
|
81
|
+
try { state = await sessionTurnState(entry); } catch { state = 'missing'; }
|
|
82
|
+
}
|
|
83
|
+
if (entry.silent || state !== 'unfinished') {
|
|
84
|
+
await ledger.end(sessionId);
|
|
85
|
+
return { sessionId, outcome: 'finished' };
|
|
86
|
+
}
|
|
87
|
+
let recovered = {};
|
|
88
|
+
try { recovered = await ledger.recoveredMap(); } catch { recovered = {}; }
|
|
89
|
+
const prev = Number(recovered[sessionId]);
|
|
90
|
+
if (Number.isFinite(prev) && now() - prev < DAY_MS) {
|
|
91
|
+
await ledger.end(sessionId);
|
|
92
|
+
return { sessionId, outcome: 'guarded' };
|
|
93
|
+
}
|
|
94
|
+
await ledger.markRecovered(sessionId, now());
|
|
95
|
+
await ledger.end(sessionId);
|
|
96
|
+
run({
|
|
97
|
+
tabId, sessionId, cwd, prompt: CONTINUE_PROMPT, resume: true,
|
|
98
|
+
...(entry.promptId ? { promptId: entry.promptId } : {}),
|
|
99
|
+
...(entry.origin ? { origin: entry.origin } : {}),
|
|
100
|
+
...(entry.worktreeDirHint ? { worktreeDirHint: entry.worktreeDirHint } : {}),
|
|
101
|
+
});
|
|
102
|
+
return { sessionId, outcome: 'rerun' };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function isOrphan(entry) {
|
|
106
|
+
if (!pidAlive(entry.pid)) return false;
|
|
107
|
+
try { return isChatProcessFor(identityOf(entry.pid), entry.sessionId); } catch { return false; }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
if (!entry || !entry.sessionId) continue;
|
|
112
|
+
if (isOrphan(entry)) {
|
|
113
|
+
holdOrphan(entry.sessionId);
|
|
114
|
+
waits.push(new Promise((resolve) => {
|
|
115
|
+
const tick = () => {
|
|
116
|
+
if (isOrphan(entry)) {
|
|
117
|
+
const t = setTimer(tick, pollMs);
|
|
118
|
+
if (t && typeof t.unref === 'function') t.unref();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
settleDead(entry)
|
|
122
|
+
.catch(() => ({ sessionId: entry.sessionId, outcome: 'error' }))
|
|
123
|
+
.then((r) => { results.push(r); releaseOrphan(entry.sessionId); resolve(); });
|
|
124
|
+
};
|
|
125
|
+
const t = setTimer(tick, pollMs);
|
|
126
|
+
if (t && typeof t.unref === 'function') t.unref();
|
|
127
|
+
}));
|
|
128
|
+
results.push({ sessionId: entry.sessionId, outcome: 'orphan' });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
try { results.push(await settleDead(entry)); } catch { results.push({ sessionId: entry.sessionId, outcome: 'error' }); }
|
|
132
|
+
}
|
|
133
|
+
return { results, pending: Promise.all(waits).then(() => undefined) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = { recoverInflightTurns, classifyTurnTail, CONTINUE_PROMPT, DAY_MS };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Durable ledger of in-flight chat turns (~/.claude/session-manager/chat-inflight.json).
|
|
5
|
+
* begin() after a successful spawn, end() when the turn settles; list() lets the next
|
|
6
|
+
* boot see what was running. Carries NO prompt text and nothing from childEnv.
|
|
7
|
+
* Never throws into a turn: a missing/corrupt ledger reads as empty.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const { readJsonOr, writeJsonAtomic } = require('./util/atomicFs.cjs');
|
|
12
|
+
const { schedulerHome } = require('./scheduler/schedulerPaths.cjs');
|
|
13
|
+
|
|
14
|
+
function ledgerPath() {
|
|
15
|
+
return process.env.SM_CHAT_INFLIGHT_PATH || path.join(schedulerHome(), 'chat-inflight.json');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// One in-process chain serializes every read-modify-write.
|
|
19
|
+
let chain = Promise.resolve();
|
|
20
|
+
|
|
21
|
+
async function readAll() {
|
|
22
|
+
try {
|
|
23
|
+
const data = await readJsonOr(ledgerPath(), {});
|
|
24
|
+
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
25
|
+
} catch { return {}; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function enqueue(mutate) {
|
|
29
|
+
const next = chain.then(async () => {
|
|
30
|
+
try {
|
|
31
|
+
const all = await readAll();
|
|
32
|
+
mutate(all);
|
|
33
|
+
await writeJsonAtomic(ledgerPath(), all);
|
|
34
|
+
} catch { /* ledger is best-effort */ }
|
|
35
|
+
});
|
|
36
|
+
chain = next;
|
|
37
|
+
return next;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Fields of a run() payload that may be persisted (never prompt / env). */
|
|
41
|
+
function sanitize(sessionId, entry) {
|
|
42
|
+
const e = entry || {};
|
|
43
|
+
const out = { sessionId, startedAt: Date.now() };
|
|
44
|
+
for (const k of ['tabId', 'cwd', 'pid', 'startedAt', 'resume', 'silent', 'promptId', 'origin', 'worktreeDirHint']) {
|
|
45
|
+
if (e[k] !== undefined && typeof e[k] !== 'function') out[k] = e[k];
|
|
46
|
+
}
|
|
47
|
+
out.sessionId = sessionId;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function begin(sessionId, entry) {
|
|
52
|
+
if (!sessionId) return Promise.resolve();
|
|
53
|
+
return enqueue((all) => { all[sessionId] = sanitize(sessionId, entry); });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function end(sessionId) {
|
|
57
|
+
if (!sessionId) return Promise.resolve();
|
|
58
|
+
return enqueue((all) => { delete all[sessionId]; });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const RECOVERED_KEY = '__recovered';
|
|
62
|
+
|
|
63
|
+
/** @returns {Promise<object[]>} */
|
|
64
|
+
async function list() {
|
|
65
|
+
await chain;
|
|
66
|
+
const all = await readAll();
|
|
67
|
+
return Object.entries(all).filter(([k]) => k !== RECOVERED_KEY).map(([, v]) => v);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Stamp a session as boot-recovered now (separate key, survives begin/end). */
|
|
71
|
+
function markRecovered(sessionId, at = Date.now()) {
|
|
72
|
+
if (!sessionId) return Promise.resolve();
|
|
73
|
+
return enqueue((all) => {
|
|
74
|
+
const m = all[RECOVERED_KEY] && typeof all[RECOVERED_KEY] === 'object' ? all[RECOVERED_KEY] : {};
|
|
75
|
+
for (const [k, v] of Object.entries(m)) if (at - Number(v) > 7 * 86400000) delete m[k];
|
|
76
|
+
m[sessionId] = at;
|
|
77
|
+
all[RECOVERED_KEY] = m;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @returns {Promise<Record<string, number>>} sessionId → last recovery ms */
|
|
82
|
+
async function recoveredMap() {
|
|
83
|
+
await chain;
|
|
84
|
+
const m = (await readAll())[RECOVERED_KEY];
|
|
85
|
+
return m && typeof m === 'object' ? m : {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { begin, end, list, ledgerPath, markRecovered, recoveredMap };
|
|
@@ -28,11 +28,13 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
const path = require('node:path');
|
|
31
|
+
const crypto = require('node:crypto');
|
|
31
32
|
const os = require('node:os');
|
|
32
33
|
const { splitFrontmatter } = require('../prd/prdFrontmatter.cjs');
|
|
33
34
|
const { readActiveIndex, resolvePersonaPaths } = require('../epic/epicMint.cjs');
|
|
34
35
|
const { resolveMergedPersona, PERSONA_NAME_RE } = require('../persona-macro/personaMerge.cjs');
|
|
35
36
|
const configMgr = require('../../config.cjs');
|
|
37
|
+
const { SHIPPED_PERSONA_SEEDS } = require('../persona-macro/shippedPersonaSeeds.cjs');
|
|
36
38
|
|
|
37
39
|
/** The hardcoded floor every branch of resolveEpicModel falls back to — --model must never be omitted (CLAUDE.md "Automation model pinning"). */
|
|
38
40
|
const FALLBACK_MODEL = 'sonnet';
|
|
@@ -180,17 +182,31 @@ function resolveEpicModel({ cwd, claudeSessionId, fallbackModel = FALLBACK_MODEL
|
|
|
180
182
|
/** Mirrors epicIntake.ts's AGENT_BODY_CHAR_CAP — a runaway persona file must
|
|
181
183
|
* not be able to dominate a spawned job's system prompt either. Duplicated
|
|
182
184
|
* rather than imported: epicIntake.ts is a renderer module (no ES modules
|
|
183
|
-
* in main).
|
|
185
|
+
* in main).
|
|
186
|
+
*
|
|
187
|
+
* EXEMPTION: a body whose digest matches a version the app itself shipped
|
|
188
|
+
* (SHIPPED_PERSONA_SEEDS) is passed whole — an unedited app-shipped body
|
|
189
|
+
* cannot be a runaway file, and demo-video-builder's style and palette rules
|
|
190
|
+
* sit past 6000 chars, so capping it silently drops them. Every other body
|
|
191
|
+
* (edited, overlay-changed, no manifest entry) stays capped. */
|
|
184
192
|
const AGENT_BODY_CHAR_CAP = 6000;
|
|
185
193
|
|
|
194
|
+
/** sha256 hex of a body (newlines normalized, trimmed). MUST stay the same
|
|
195
|
+
* digest as seedAgentPersonas.cjs's personaBodyHash (not required here: it
|
|
196
|
+
* pulls the seeding writers); the unit test enforces the equality. */
|
|
197
|
+
function shippedBodyHash(body) {
|
|
198
|
+
const normalized = String(body || '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
199
|
+
return crypto.createHash('sha256').update(normalized.trim()).digest('hex');
|
|
200
|
+
}
|
|
201
|
+
|
|
186
202
|
/** Trims a persona's frontmatter-stripped body and caps it at
|
|
187
|
-
* AGENT_BODY_CHAR_CAP, appending a truncation notice
|
|
188
|
-
* — same shape as epicIntake.ts's buildPersonaBodyText.
|
|
189
|
-
* empty body. */
|
|
190
|
-
function buildPersonaBodyText(rawBody, personaPath) {
|
|
203
|
+
* AGENT_BODY_CHAR_CAP (unless `uncapped`), appending a truncation notice
|
|
204
|
+
* naming `personaPath` — same shape as epicIntake.ts's buildPersonaBodyText.
|
|
205
|
+
* Returns null for an empty body. */
|
|
206
|
+
function buildPersonaBodyText(rawBody, personaPath, { uncapped = false } = {}) {
|
|
191
207
|
const body = (rawBody || '').trim();
|
|
192
208
|
if (!body) return null;
|
|
193
|
-
if (body.length <= AGENT_BODY_CHAR_CAP) return body;
|
|
209
|
+
if (uncapped || body.length <= AGENT_BODY_CHAR_CAP) return body;
|
|
194
210
|
const truncated = body.slice(0, AGENT_BODY_CHAR_CAP);
|
|
195
211
|
const pathLabel = personaPath || 'the persona file';
|
|
196
212
|
return `${truncated}\n\n[Truncated — ${pathLabel} exceeds ${AGENT_BODY_CHAR_CAP} characters; see the file for the full body.]`;
|
|
@@ -229,7 +245,9 @@ async function resolvePrdPersonaForSpawn({ cwd, agentType, fallbackModel = FALLB
|
|
|
229
245
|
// (older injected reader) is parsed here.
|
|
230
246
|
const { fm, body } = persona.fm ? persona : splitFrontmatter(persona.text);
|
|
231
247
|
const model = fm.model && fm.model !== 'inherit' ? fm.model : fallbackModel;
|
|
232
|
-
const
|
|
248
|
+
const digest = shippedBodyHash(body);
|
|
249
|
+
const uncapped = (SHIPPED_PERSONA_SEEDS[agentType] || []).some((e) => e.bodySha256 === digest);
|
|
250
|
+
const systemPrompt = buildPersonaBodyText(body, persona.path, { uncapped });
|
|
233
251
|
const parseTools = deps.parseTools || require('../../agentLibrary.cjs').parseTools;
|
|
234
252
|
const list = parseTools(typeof fm.tools === 'string' ? fm.tools : '');
|
|
235
253
|
return { model, systemPrompt, personaPath: persona.path, tools: list.length ? list : null };
|
|
@@ -241,6 +259,7 @@ async function resolvePrdPersonaForSpawn({ cwd, agentType, fallbackModel = FALLB
|
|
|
241
259
|
module.exports = {
|
|
242
260
|
FALLBACK_MODEL,
|
|
243
261
|
AGENT_BODY_CHAR_CAP,
|
|
262
|
+
shippedBodyHash,
|
|
244
263
|
resolveEpicModel,
|
|
245
264
|
findAgentTypeByClaudeSessionId,
|
|
246
265
|
findEpicByClaudeSessionId,
|