claude-code-session-manager 0.127.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.
Files changed (76) hide show
  1. package/dist/assets/{AgentLibrary-DKQznr7o.js → AgentLibrary-cNQU5YWy.js} +1 -1
  2. package/dist/assets/{Button-CZXqmIiM.js → Button-9dIPAOBg.js} +1 -1
  3. package/dist/assets/{DataModel-piyV33To.js → DataModel-DrDJ6ysw.js} +1 -1
  4. package/dist/assets/{History-BxwtrKF2.js → History-4rrDdWNP.js} +1 -1
  5. package/dist/assets/{Hooks-DogeSPII.js → Hooks-Bj_jF5Pa.js} +1 -1
  6. package/dist/assets/{Library-BDt6EeQQ.js → Library-D-Wsxrh7.js} +1 -1
  7. package/dist/assets/{ListDetail-CwS-LKar.js → ListDetail-D7Om0H8j.js} +1 -1
  8. package/dist/assets/{McpServers-D2HVljgS.js → McpServers-CbIbSd5o.js} +1 -1
  9. package/dist/assets/{Memory-hNzuOGn8.js → Memory-DgQlvQrO.js} +1 -1
  10. package/dist/assets/{Panel-BLDrsUeq.js → Panel-DZHiD8Ar.js} +1 -1
  11. package/dist/assets/{Permissions-DzZ5vaJW.js → Permissions-CfzduF4B.js} +1 -1
  12. package/dist/assets/{Plugins-Cz9yaxzG.js → Plugins-D-AG5nAo.js} +2 -2
  13. package/dist/assets/{ProvenanceBadge-CCgLO4m9.js → ProvenanceBadge-B9JSEjll.js} +1 -1
  14. package/dist/assets/{SaveBar-Shmn699J.js → SaveBar-mVKig6hL.js} +1 -1
  15. package/dist/assets/{Scheduler-Bqr0WHNd.js → Scheduler-DFTCnh60.js} +1 -1
  16. package/dist/assets/{ScopeSwitcher-CBx1fB5g.js → ScopeSwitcher-s8J-yr7Z.js} +1 -1
  17. package/dist/assets/{Settings-Ci8in-yF.js → Settings-BTmxRMaP.js} +1 -1
  18. package/dist/assets/{SkillReferenceGraph-BWwljba8.js → SkillReferenceGraph-C5lKqf5y.js} +1 -1
  19. package/dist/assets/{Skills-BON6o-c4.js → Skills-CxOacq0k.js} +1 -1
  20. package/dist/assets/{SystemPrompt-D5epIYYs.js → SystemPrompt-BCWg5FAz.js} +1 -1
  21. package/dist/assets/{TagLibrary-C2qDZROJ.js → TagLibrary-BnF0_PkG.js} +1 -1
  22. package/dist/assets/{TiptapBody-SZhI3-bW.js → TiptapBody-C2Iu6rZd.js} +1 -1
  23. package/dist/assets/{Toggle-C_qFDG0g.js → Toggle-C-oD66BG.js} +1 -1
  24. package/dist/assets/{ViewTabs-C9q5WCEd.js → ViewTabs-Cs4v7vLY.js} +1 -1
  25. package/dist/assets/{historyTotals-BCl7IOhY.js → historyTotals-CbRSLD8f.js} +1 -1
  26. package/dist/assets/{index-BnKaYERU.css → index-DtdWBGrI.css} +1 -1
  27. package/dist/assets/index-DzY_GXYY.js +3081 -0
  28. package/dist/assets/{settingsSchema-BBrRBrBr.js → settingsSchema-bSBfHuan.js} +1 -1
  29. package/dist/assets/{skillFrontmatter-B01qJk6N.js → skillFrontmatter-BEseWm8r.js} +1 -1
  30. package/dist/assets/{useAgentsDirWatch-CuR3GSjS.js → useAgentsDirWatch-CdyHxKCI.js} +1 -1
  31. package/dist/index.html +2 -2
  32. package/dist-web/app.css +1 -1
  33. package/dist-web/app.js +343 -341
  34. package/package.json +1 -1
  35. package/scripts/scheduler-mcp-server.cjs +170 -6
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/index.cjs +14 -0
  38. package/src/main/ipcSchemas.cjs +107 -0
  39. package/src/main/lib/claude/agentModelResolve.cjs +26 -7
  40. package/src/main/lib/claude/personaToolScope.cjs +40 -2
  41. package/src/main/lib/demo-video-kit/capture.cjs +113 -0
  42. package/src/main/lib/demo-video-kit/character.cjs +97 -0
  43. package/src/main/lib/demo-video-kit/checks.cjs +150 -0
  44. package/src/main/lib/demo-video-kit/frames.cjs +200 -0
  45. package/src/main/lib/demo-video-kit/seedKit.cjs +52 -0
  46. package/src/main/lib/demo-video-kit/sound.cjs +312 -0
  47. package/src/main/lib/epic/epicValidationHook.cjs +17 -1
  48. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +185 -34
  49. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +15 -0
  50. package/src/main/lib/mcpToolCatalog.cjs +71 -11
  51. package/src/main/lib/opsOwnership.cjs +9 -5
  52. package/src/main/lib/persona-macro/builtinMacros.cjs +19 -5
  53. package/src/main/lib/persona-macro/macroJobDispatch.cjs +116 -0
  54. package/src/main/lib/persona-macro/macroJobIpc.cjs +50 -0
  55. package/src/main/lib/persona-macro/macroJobStatus.cjs +112 -0
  56. package/src/main/lib/persona-macro/macroLibrary.cjs +16 -0
  57. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +89 -0
  58. package/src/main/lib/prd/prdCreate.cjs +12 -1
  59. package/src/main/lib/prd/prdFrontmatter.cjs +7 -2
  60. package/src/main/lib/project-pages/pagesLibrary.cjs +171 -0
  61. package/src/main/lib/project-pages/playerBridge.cjs +129 -0
  62. package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
  63. package/src/main/lib/smfileHeaders.cjs +11 -3
  64. package/src/main/projectPages.cjs +107 -30
  65. package/src/main/promptSessionsIpc.cjs +131 -0
  66. package/src/main/scheduler/prdParser.cjs +2 -0
  67. package/src/main/scheduler.cjs +26 -9
  68. package/src/main/seedSchedulerMcp.cjs +10 -1
  69. package/src/main/transcripts.cjs +8 -0
  70. package/src/main/webRemote.cjs +3 -1
  71. package/src/preload/api.d.ts +101 -5
  72. package/src/preload/apiSurface.json +70 -0
  73. package/src/preload/index.cjs +13 -0
  74. package/src/seed/agents/demo-video-builder.md +86 -36
  75. package/src/seed/agents/project-home-builder.md +26 -13
  76. package/dist/assets/index-CMIYLbPb.js +0 -3079
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Read-tier IPC for the Sessions (Epics) list/detail path. The renderer used to
5
+ * read active-index.json, per-Epic archives and the Claude session JSONL via
6
+ * config:readJson/listDir/readText — all `deny` for a remote (web) browser, so
7
+ * the remote UI could never list or open a Session. These channels are the
8
+ * dedicated, fenced replacement: every handler reads ONLY under
9
+ * `<cwd>/session-manager-operations/prompt-sessions` (via opsPath()) — except
10
+ * read-session-transcript, which resolves the project's own Claude JSONL via
11
+ * transcripts.cjs — and refuses a cwd that is not a registered project root.
12
+ * Reads only: the single-writer law (opsOwnership.cjs) is untouched.
13
+ */
14
+
15
+ const fs = require('node:fs');
16
+ const path = require('node:path');
17
+
18
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
19
+ const MAX_TRANSCRIPT_BYTES = 64 * 1024 * 1024;
20
+
21
+ function norm(p) {
22
+ return path.resolve(String(p)).replace(/[\\/]+$/, '');
23
+ }
24
+
25
+ /** Default registered-project source: persisted tabs plus every project Claude has seen. */
26
+ function defaultProjectRoots() {
27
+ const roots = [];
28
+ try {
29
+ const sessionsStore = require('./sessionsStore.cjs');
30
+ const data = JSON.parse(fs.readFileSync(sessionsStore.storePath(), 'utf8'));
31
+ for (const t of data.tabs || []) if (t && typeof t.cwd === 'string' && t.cwd) roots.push(t.cwd);
32
+ } catch { /* none */ }
33
+ try {
34
+ for (const c of require('./lib/activeSessions.cjs').allProjectCwds()) roots.push(c);
35
+ } catch { /* none */ }
36
+ return roots;
37
+ }
38
+
39
+ function assertRegistered(cwd, projectRoots) {
40
+ if (typeof cwd !== 'string' || !cwd || !path.isAbsolute(cwd)) throw new Error('cwd must be an absolute project path');
41
+ const { projectRootOf } = require('./lib/activeSessions.cjs');
42
+ const want = norm(projectRootOf(cwd) || cwd);
43
+ for (const r of projectRoots() || []) {
44
+ if (typeof r !== 'string' || !r) continue;
45
+ if (norm(r) === want || norm(projectRootOf(r) || r) === want) return;
46
+ }
47
+ throw new Error('cwd is not a registered project root');
48
+ }
49
+
50
+ function promptSessionsDir(cwd) {
51
+ return require('./lib/opsOwnership.cjs').opsPath(cwd, 'prompt-sessions');
52
+ }
53
+
54
+ function loadActiveIndex(cwd, { projectRoots = defaultProjectRoots } = {}) {
55
+ assertRegistered(cwd, projectRoots);
56
+ const file = path.join(promptSessionsDir(cwd), 'active-index.json');
57
+ try {
58
+ return { exists: true, data: JSON.parse(fs.readFileSync(file, 'utf8')) };
59
+ } catch (err) {
60
+ if (err && err.code === 'ENOENT') return { exists: false, data: null };
61
+ return { exists: false, data: null, error: String(err && err.message ? err.message : err) };
62
+ }
63
+ }
64
+
65
+ function listArchived(cwd, { projectRoots = defaultProjectRoots } = {}) {
66
+ assertRegistered(cwd, projectRoots);
67
+ try {
68
+ const ids = fs.readdirSync(promptSessionsDir(cwd), { withFileTypes: true })
69
+ .filter((e) => e.isFile() && e.name.endsWith('.json') && e.name !== 'active-index.json')
70
+ .map((e) => e.name.slice(0, -'.json'.length))
71
+ .filter((id) => ID_RE.test(id));
72
+ return { ok: true, ids };
73
+ } catch (err) {
74
+ return { ok: false, ids: [], error: String(err && err.message ? err.message : err) };
75
+ }
76
+ }
77
+
78
+ function readArchived(cwd, epicId, { projectRoots = defaultProjectRoots } = {}) {
79
+ assertRegistered(cwd, projectRoots);
80
+ if (typeof epicId !== 'string' || !ID_RE.test(epicId) || epicId === 'active-index') throw new Error('invalid epicId');
81
+ try {
82
+ return { exists: true, data: JSON.parse(fs.readFileSync(path.join(promptSessionsDir(cwd), `${epicId}.json`), 'utf8')) };
83
+ } catch (err) {
84
+ if (err && err.code === 'ENOENT') return { exists: false, data: null };
85
+ return { exists: false, data: null, error: String(err && err.message ? err.message : err) };
86
+ }
87
+ }
88
+
89
+ function readSessionTranscript(cwd, sessionId, { projectRoots = defaultProjectRoots, resolvePath } = {}) {
90
+ assertRegistered(cwd, projectRoots);
91
+ if (typeof sessionId !== 'string' || !ID_RE.test(sessionId)) throw new Error('invalid sessionId');
92
+ const file = (resolvePath || ((c, s) => require('./transcripts.cjs').transcriptPath(c, s)))(cwd, sessionId);
93
+ try {
94
+ if (fs.statSync(file).size > MAX_TRANSCRIPT_BYTES) return { exists: true, text: '', error: 'transcript too large' };
95
+ return { exists: true, text: fs.readFileSync(file, 'utf8') };
96
+ } catch (err) {
97
+ if (err && err.code === 'ENOENT') return { exists: false, text: '' };
98
+ return { exists: false, text: '', error: String(err && err.message ? err.message : err) };
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Write one completed Epic's archive (<cwd>/…/prompt-sessions/<id>.json).
104
+ * Path is built here from opsPath(); the writer id is hardcoded 'epics'
105
+ * (single-writer law). Refuses a non-registered cwd and an archive whose
106
+ * session.id does not match the named epicId.
107
+ */
108
+ async function writeArchive(cwd, epicId, archive, { projectRoots = defaultProjectRoots, writeJson } = {}) {
109
+ assertRegistered(cwd, projectRoots);
110
+ if (typeof epicId !== 'string' || !ID_RE.test(epicId) || epicId === 'active-index') throw new Error('invalid epicId');
111
+ if (!archive || typeof archive !== 'object' || !archive.session || archive.session.id !== epicId) {
112
+ throw new Error('archive.session.id must match epicId');
113
+ }
114
+ const config = require('./config.cjs');
115
+ config.addAllowedRoot(norm(cwd));
116
+ const file = path.join(promptSessionsDir(cwd), `${epicId}.json`);
117
+ await (writeJson || config.writeJson)(file, archive, { writer: 'epics' });
118
+ return { ok: true };
119
+ }
120
+
121
+ function registerPromptSessionsReadHandlers() {
122
+ const { ipcMain } = require('electron');
123
+ const { schemas: s, validated: v } = require('./ipcSchemas.cjs');
124
+ ipcMain.handle('promptSessions:load-active-index', v(s.promptSessionsCwd, ({ cwd }) => loadActiveIndex(cwd)));
125
+ ipcMain.handle('promptSessions:list-archived', v(s.promptSessionsCwd, ({ cwd }) => listArchived(cwd)));
126
+ ipcMain.handle('promptSessions:read-archived', v(s.promptSessionsReadArchived, ({ cwd, epicId }) => readArchived(cwd, epicId)));
127
+ ipcMain.handle('promptSessions:write-archive', v(s.promptSessionsWriteArchive, ({ cwd, epicId, archive }) => writeArchive(cwd, epicId, archive)));
128
+ ipcMain.handle('promptSessions:read-session-transcript', v(s.promptSessionsReadSessionTranscript, ({ cwd, sessionId }) => readSessionTranscript(cwd, sessionId)));
129
+ }
130
+
131
+ module.exports = { loadActiveIndex, listArchived, readArchived, readSessionTranscript, writeArchive, registerPromptSessionsReadHandlers };
@@ -131,6 +131,8 @@ async function parsePrdRaw(filePath) {
131
131
  disposition: (fm.disposition === 'append' || fm.disposition === 'new-head') ? fm.disposition : null,
132
132
  // Durable wave identity (createPrd-stamped); malformed values read as absent.
133
133
  planId: (typeof fm.planId === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(fm.planId)) ? fm.planId : null,
134
+ // Macro press that minted this PRD (prdFrontmatter.cjs MACRO_ID_RE); malformed reads as absent.
135
+ macroId: (typeof fm.macroId === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(fm.macroId.trim())) ? fm.macroId.trim() : null,
134
136
  // Opt-in exclusive-lease flag (PRD 1107, quietMachineLease.cjs +
135
137
  // schedulerBatch.cjs's pickNextBatch). Only a literal `true` opts in —
136
138
  // matches prdFrontmatter.cjs's applyKey semantics for this field.
@@ -154,7 +154,7 @@ const queueOps = require('./queueOps.cjs');
154
154
  const { listEpicPrdDirs, listArchivedPrdDirs, deriveProjectCwdFromPrdPath } = require('./lib/prd/prdLocations.cjs');
155
155
  const { ensureEpic, appendPrdCreatedEvent, readActiveIndex } = require('./lib/epic/epicMint.cjs');
156
156
  const agentModelResolve = require('./lib/claude/agentModelResolve.cjs');
157
- const { buildPersonaToolScope, personaToolScopeArgs } = require('./lib/claude/personaToolScope.cjs');
157
+ const { buildPersonaToolScope, personaToolScopeArgs, personaToolScopeEnv } = require('./lib/claude/personaToolScope.cjs');
158
158
  const { resolveEpicEffort, effortArgs } = require('./lib/claude/agentEffortResolve.cjs');
159
159
  const { transitionJob, STATUS_HISTORY_CAP, LEGAL_TRANSITIONS } = require('./lib/scheduler/scheduleJobTransitions.cjs');
160
160
  const { buildContextDigest, composeExecutorPrompt } = require('./lib/epic/epicContextDigest.cjs');
@@ -1802,6 +1802,7 @@ async function reconcilePass(state) {
1802
1802
  ?? resolveOriginSessionId(refreshedCwd, p.epicId ?? reconcileSourcePromptId(job, p.sourcePromptId)),
1803
1803
  bodyPreview: p.body.split('\n').slice(0, 6).join('\n'),
1804
1804
  agentType: p.agentType ?? job.agentType ?? null,
1805
+ macroId: p.macroId ?? job.macroId ?? null,
1805
1806
  };
1806
1807
  // Adopt path: a row parked 'quarantined' (no createdVia provenance when
1807
1808
  // discovered) whose PRD file now carries a stamp — written via the
@@ -1925,6 +1926,7 @@ async function reconcilePass(state) {
1925
1926
  originSessionId: inv.row?.originSessionId ?? resolveOriginSessionId(repairedCwd, p.epicId ?? p.sourcePromptId),
1926
1927
  bodyPreview: p.body.split('\n').slice(0, 6).join('\n'),
1927
1928
  agentType: p.agentType ?? inv.row?.agentType ?? null,
1929
+ macroId: p.macroId ?? inv.row?.macroId ?? null,
1928
1930
  };
1929
1931
  const reason = `reconcile: repaired invalid status ${JSON.stringify(oldStatus)}`;
1930
1932
  // A repair is not a lifecycle transition — the corrupted `status` was
@@ -2076,6 +2078,7 @@ async function reconcilePass(state) {
2076
2078
  originSessionId: resolveOriginSessionId(discoveredCwd, p.epicId ?? p.sourcePromptId),
2077
2079
  bodyPreview: p.body.split('\n').slice(0, 6).join('\n'),
2078
2080
  agentType: p.agentType ?? null,
2081
+ macroId: p.macroId ?? null,
2079
2082
  status: 'pending',
2080
2083
  // Enqueue time (PRD 1086/1087): the cross-project fairness tiebreak and
2081
2084
  // the starvation escalation both need a provable age for a pending row;
@@ -4498,13 +4501,20 @@ const HEADLESS_DISALLOWED_TOOLS = Object.freeze([
4498
4501
  * and a large prompt failed with spawn E2BIG before the job started (the
4499
4502
  * 2026-10-26 incident). `claude -p` with no positional prompt reads stdin.
4500
4503
  */
4504
+ // MCP servers whose definition the scheduler knows. Lazy require: avoids a
4505
+ // load-order cycle with seedSchedulerMcp.cjs.
4506
+ function knownMcpServers() {
4507
+ const seed = require('./seedSchedulerMcp.cjs');
4508
+ return { [seed.SERVER_NAME]: seed.schedulerServerEntry() };
4509
+ }
4510
+
4501
4511
  function buildClaudeSpawnArgs({ model, effort, sessionId, resume, systemPrompt, toolScope }) {
4502
4512
  return [
4503
4513
  '-p',
4504
4514
  '--model', model,
4505
4515
  ...effortArgs(effort),
4506
4516
  ...(systemPrompt ? ['--append-system-prompt', systemPrompt] : []),
4507
- ...personaToolScopeArgs(toolScope),
4517
+ ...personaToolScopeArgs(toolScope, { mcpServers: knownMcpServers() }),
4508
4518
  '--dangerously-skip-permissions',
4509
4519
  ...headlessPermissionArgs(),
4510
4520
  '--disallowedTools', HEADLESS_DISALLOWED_TOOLS.join(','),
@@ -4851,6 +4861,8 @@ async function executeJob(job, runDir, defaultCwd, onPid, execCwd, resumeTarget
4851
4861
  // scheduler-mcp-server.cjs can refuse scheduler_create_prd from inside a
4852
4862
  // run (issue #11 list C1 — the PRD 460 self-queue incident). Only a
4853
4863
  // persona whose whole job is decomposition may still queue.
4864
+ // SM_SCHEDULER_JOB_MCP_TOOLS tells scheduler-mcp-server.cjs which of its tools this job's
4865
+ // persona admits (see personaToolScope.cjs).
4854
4866
  // `launchEnv` is the launch circuit breaker's degraded-mode env (e.g.
4855
4867
  // MAX_THINKING_TOKENS=0 while an outdated CLI's thinking parameter is
4856
4868
  // being rejected — lib/scheduler/launchFailure.cjs); applied last so it wins.
@@ -4859,6 +4871,7 @@ async function executeJob(job, runDir, defaultCwd, onPid, execCwd, resumeTarget
4859
4871
  SM_PROJECT_ROOT: cwd,
4860
4872
  SM_SCHEDULER_JOB_SLUG: job.slug,
4861
4873
  SM_SCHEDULER_JOB_MAY_QUEUE: job.agentType === 'architect' ? '1' : '0',
4874
+ ...personaToolScopeEnv(personaToolScope),
4862
4875
  BASH_DEFAULT_TIMEOUT_MS: String(BASH_DEFAULT_TIMEOUT_MS),
4863
4876
  BASH_MAX_TIMEOUT_MS: String(BASH_MAX_TIMEOUT_MS),
4864
4877
  ...(launchEnv && typeof launchEnv === 'object' ? launchEnv : {}),
@@ -6257,8 +6270,10 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6257
6270
  // branch below has this run's OWN start time — the freshness check
6258
6271
  // (isCooldownSuppressed) needs to know whether this specific dispatch
6259
6272
  // started after the manual clear, not whatever startedAt this row
6260
- // carried from a prior run.
6273
+ // carried from a prior run. The same stamped start (ISO form, below)
6274
+ // also feeds verifyRun's queueEntry so artifact-only PRDs get a real window.
6261
6275
  let dispatchStartedAtMs = null;
6276
+ let dispatchStartedAt = null;
6262
6277
  let dispatchSkippedAlreadyCompleted = false;
6263
6278
  await mutate((s) => {
6264
6279
  const idx = s.jobs.findIndex((x) => x.slug === job.slug);
@@ -6341,6 +6356,7 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6341
6356
  s.jobs[idx].dispatchPhase = 'running-stamped';
6342
6357
  s.jobs[idx].dispatchPhaseAt = s.jobs[idx].startedAt;
6343
6358
  dispatchStartedAtMs = Date.parse(s.jobs[idx].startedAt);
6359
+ dispatchStartedAt = s.jobs[idx].startedAt;
6344
6360
  if (job.quietMachine === true) {
6345
6361
  s.jobs[idx].quietMachine = true;
6346
6362
  s.jobs[idx].quietLeaseDegraded = job.quietLeaseDegraded === true;
@@ -6735,7 +6751,7 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6735
6751
  guardCwd,
6736
6752
  guardHeadBefore,
6737
6753
  headAtExit,
6738
- job.startedAt,
6754
+ dispatchStartedAt,
6739
6755
  new Date().toISOString(),
6740
6756
  );
6741
6757
  let rangeCommits = [];
@@ -6745,7 +6761,7 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6745
6761
  rangeCommits = await gitTreeGuard.gitRangeCommits(guardCwd, guardHeadBefore, headAtExit);
6746
6762
  transcriptCommitShas = parseLog(path.join(runDir, `${job.slug}.log`)).transcriptCommitShas || [];
6747
6763
  const overlapState = await readQueue().catch(() => ({ jobs: [] }));
6748
- const myStart = Date.parse(job.startedAt) || 0;
6764
+ const myStart = Date.parse(dispatchStartedAt) || 0;
6749
6765
  const myEnd = Date.now();
6750
6766
  siblingOverlap = (overlapState.jobs || []).some((j) => {
6751
6767
  if (j.slug === job.slug || (j.cwd || defaultCwd) !== guardCwd) return false;
@@ -6789,7 +6805,7 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6789
6805
  verifyResult = await verifyRun({
6790
6806
  runDir,
6791
6807
  prdPath,
6792
- queueEntry: job,
6808
+ queueEntry: { ...job, startedAt: dispatchStartedAt, finishedAt: null },
6793
6809
  allJobs: stateForDeps.jobs,
6794
6810
  committedDuringRun,
6795
6811
  priorLandedCommit,
@@ -6952,11 +6968,11 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6952
6968
  guardCwd,
6953
6969
  guardHeadBefore,
6954
6970
  guardHeadAtSigterm,
6955
- job.startedAt,
6971
+ dispatchStartedAt,
6956
6972
  new Date().toISOString(),
6957
6973
  );
6958
6974
  if (guardHeadBefore && guardHeadAtSigterm && guardHeadAtSigterm !== guardHeadBefore) {
6959
- const verified = await resolveLandedCommitEvidence(guardCwd, guardHeadAtSigterm, job.startedAt);
6975
+ const verified = await resolveLandedCommitEvidence(guardCwd, guardHeadAtSigterm, dispatchStartedAt);
6960
6976
  if (verified) sigtermLandedCommitEvidence = guardHeadAtSigterm;
6961
6977
  }
6962
6978
  }
@@ -6996,7 +7012,7 @@ async function spawnJob(job, runId, runDir, defaultCwd, resumeTarget = null, sib
6996
7012
  if (res.exitCode !== 0 && res.exitCode !== 143 && !res.rateLimited) {
6997
7013
  const headAtPlainExit = await gitTreeGuard.gitHead(guardCwd);
6998
7014
  if (guardHeadBefore && headAtPlainExit && headAtPlainExit !== guardHeadBefore) {
6999
- const verified = await resolveLandedCommitEvidence(guardCwd, headAtPlainExit, job.startedAt);
7015
+ const verified = await resolveLandedCommitEvidence(guardCwd, headAtPlainExit, dispatchStartedAt);
7000
7016
  if (verified) plainExitLandedCommitEvidence = headAtPlainExit;
7001
7017
  }
7002
7018
  }
@@ -11153,6 +11169,7 @@ async function listPrdsInternal({ cwd: rawCwd } = {}) {
11153
11169
  epicId: parsed.epicId ?? null,
11154
11170
  dependsOn: parsed.dependsOn ?? null,
11155
11171
  agentType: parsed.agentType ?? null,
11172
+ macroId: parsed.macroId ?? null,
11156
11173
  disposition: parsed.disposition ?? null,
11157
11174
  planId: parsed.planId ?? null,
11158
11175
  mtimeMs: stat.mtimeMs,
@@ -111,6 +111,15 @@ function mcpAddArgv(serverPath) {
111
111
  return ['mcp', 'add', SERVER_NAME, '--scope', 'user', ...envFlags, '--', spec.command, ...spec.args];
112
112
  }
113
113
 
114
+ /** The server definition (`{command,args,env?}`) shared by the seed and by
115
+ * scheduler job spawns (--mcp-config). Same nodeSpawnSpec as mcpAddArgv. */
116
+ function schedulerServerEntry(serverPath = serverScriptPath()) {
117
+ const spec = nodeSpawnSpec(serverPath);
118
+ const entry = { command: spec.command, args: [...spec.args] };
119
+ if (Object.keys(spec.env).length) entry.env = { ...spec.env };
120
+ return entry;
121
+ }
122
+
114
123
  /** Run `claude mcp add session-manager-scheduler --scope user -- node <serverPath>`.
115
124
  * No shell:true — argv array passed directly to spawn. */
116
125
  function runClaudeMcpAdd(serverPath) {
@@ -209,4 +218,4 @@ async function seedSchedulerMcp({ logger = console, addFn = runClaudeMcpAdd, rem
209
218
  }
210
219
  }
211
220
 
212
- module.exports = { seedSchedulerMcp, writeMarker, runClaudeMcpAdd, runClaudeMcpRemove, mcpAddArgv, markerPath, MAX_ATTEMPTS, serverScriptPath, SERVER_NAME };
221
+ module.exports = { seedSchedulerMcp, writeMarker, runClaudeMcpAdd, runClaudeMcpRemove, mcpAddArgv, markerPath, MAX_ATTEMPTS, serverScriptPath, SERVER_NAME, schedulerServerEntry };
@@ -57,6 +57,12 @@ function transcriptPath(cwd, sessionUuid) {
57
57
  return resolveTranscript(cwd, sessionUuid).filePath;
58
58
  }
59
59
 
60
+ /** True when the session's JSONL exists on disk (project or Epic-worktree encoding). */
61
+ function transcriptExists(cwd, sessionUuid) {
62
+ const { filePath, existsAnywhere } = resolveTranscript(cwd, sessionUuid);
63
+ return existsAnywhere || fs.existsSync(filePath);
64
+ }
65
+
60
66
  // Cap bytes read per readDelta pass. Bounds memory on first attach to a very
61
67
  // large transcript (hundreds of MB) — see readDelta's seek-to-tail branch.
62
68
  const MAX_DELTA_BYTES = 8 * 1024 * 1024;
@@ -577,12 +583,14 @@ function registerTranscriptHandlers() {
577
583
  }));
578
584
  ipcMain.handle('transcript:buffer', v(s.transcriptTabId, ({ tabId }) => getBuffer(tabId)));
579
585
  ipcMain.handle('transcript:path', v(s.transcriptPath, ({ cwd, sessionUuid }) => transcriptPath(cwd, sessionUuid)));
586
+ ipcMain.handle('transcript:exists', v(s.transcriptPath, ({ cwd, sessionUuid }) => transcriptExists(cwd, sessionUuid)));
580
587
  ipcMain.handle('transcript:usageFor', v(s.transcriptUsageFor, ({ cwd, sessionIds }) => usageFor(cwd, sessionIds)));
581
588
  ipcMain.handle('transcript:page', v(s.transcriptPage, ({ tabId, startLine, endLine }) => pageEvents(tabId, startLine, endLine)));
582
589
  ipcMain.handle('transcript:readRef', v(s.transcriptReadRef, (ref) => readRef(ref)));
583
590
  }
584
591
 
585
592
  module.exports = {
593
+ transcriptExists,
586
594
  attachWindow,
587
595
  registerTranscriptHandlers,
588
596
  closeAll,
@@ -923,7 +923,9 @@ function sendIpcResult(callId, frame, client) {
923
923
  try {
924
924
  const inner = { type: 'ipc:result', id: callId, seq: frame.seq, total: frame.total, data: frame.data, ts: Date.now() };
925
925
  const { nonce, ciphertext } = encryptBox(JSON.stringify(inner), client.e2e.sessionKey);
926
- const out = { type: 'e2e:box', id: callId, payload: { nonce, ciphertext }, ts: Date.now() };
926
+ // The relay's envelope schema requires a UUID `id` and DROPS anything else (invalid_envelope), so the
927
+ // outer id is always a fresh UUID. Batched replies are keyed `<uuid>.<n>`; that key rides inside the box.
928
+ const out = { type: 'e2e:box', id: crypto.randomUUID(), payload: { nonce, ciphertext }, ts: Date.now() };
927
929
  if (client.key !== LEGACY_CLIENT_KEY) out.toConn = client.key;
928
930
  _ws.send(JSON.stringify(out));
929
931
  } catch (e) {
@@ -286,6 +286,36 @@ export interface MacroInput {
286
286
  options?: string[];
287
287
  }
288
288
 
289
+ /** Background-build descriptor on a built-in macro. */
290
+ export interface MacroJob {
291
+ estimateMinutes: number;
292
+ artifactPaths: string[];
293
+ }
294
+
295
+ export interface MacroJobDispatchInput {
296
+ cwd: string;
297
+ macroId: string;
298
+ epicId: string;
299
+ extraInstructions?: string;
300
+ }
301
+
302
+ export type MacroJobDispatchResult =
303
+ | { ok: true; slug: string; epicId: string }
304
+ | { ok: false; error: string; activeSlug?: string };
305
+
306
+ export type MacroJobState = 'queued' | 'running' | 'done' | 'failed';
307
+
308
+ export interface MacroJobStatus {
309
+ macroId: string;
310
+ epicId: string | null;
311
+ slug: string;
312
+ state: MacroJobState;
313
+ status: string;
314
+ reason: string | null;
315
+ startedAt: string | null;
316
+ finishedAt: string | null;
317
+ }
318
+
289
319
  /** One user-defined sidebar HOT KEYS macro (macroLibrary.cjs). `projects` = absolute cwds or `'*'` (every project). */
290
320
  export interface Macro {
291
321
  id: string;
@@ -305,6 +335,8 @@ export interface Macro {
305
335
  inputs?: MacroInput[];
306
336
  /** Projects ('*' or absolute cwds) this macro's session may start work in without approval. */
307
337
  autoStartTargets?: string[];
338
+ /** Set only on built-ins whose press builds in the background. */
339
+ job?: MacroJob;
308
340
  }
309
341
 
310
342
  /** Omit `id` to create; set it to update an existing macro. */
@@ -667,6 +699,7 @@ export interface ScheduleJobRuntime {
667
699
  }
668
700
 
669
701
  export interface ScheduleJob {
702
+ macroId?: string | null;
670
703
  slug: string;
671
704
  title: string;
672
705
  cwd: string | null;
@@ -1488,12 +1521,57 @@ export type ProjectBriefUpdateResult =
1488
1521
  | { ok: false; error: string };
1489
1522
 
1490
1523
  // ────────────────────────────────────────────── Project Pages (single home.html)
1524
+ export interface ProjectPageMeta {
1525
+ id: string;
1526
+ title: string;
1527
+ topic: string;
1528
+ createdAt: string;
1529
+ model: string;
1530
+ }
1531
+
1532
+ export interface ProjectVideoMeta {
1533
+ id: string;
1534
+ title: string;
1535
+ kind: 'project-demo' | 'blog-post' | 'feature';
1536
+ style: string;
1537
+ lengthS: number;
1538
+ createdAt: string;
1539
+ character: string | null;
1540
+ sources: { claim: string; source: string; ref: string }[];
1541
+ report: {
1542
+ lufs: number | null;
1543
+ truePeakDb: number | null;
1544
+ speechS: number | null;
1545
+ readingGrade: number | null;
1546
+ checks: { id: string; ok: boolean; detail: string }[];
1547
+ bytes: number;
1548
+ };
1549
+ macroVersion: number;
1550
+ seedVersion: number;
1551
+ model: string;
1552
+ effort: string;
1553
+ }
1554
+
1555
+ /** One library folder (knowledge/<id>/ or videos/<id>/); `meta` is null when meta.json is missing/invalid (see `error`). */
1556
+ export interface ProjectLibraryEntry<M> {
1557
+ id: string;
1558
+ /** Absolute path of the entry's index.html — load via smfile://. */
1559
+ path: string;
1560
+ mtimeMs: number;
1561
+ meta: M | null;
1562
+ error: string | null;
1563
+ }
1564
+
1491
1565
  export interface ProjectPagesGetResult {
1492
- /** Contents of session-manager-operations/project-pages/home.html, or null when it has not been generated. */
1566
+ /** Knowledge pages, newest first. */
1567
+ knowledge: ProjectLibraryEntry<ProjectPageMeta>[];
1568
+ /** Videos, newest first. */
1569
+ videos: ProjectLibraryEntry<ProjectVideoMeta>[];
1570
+ /** Contents of the `overview` knowledge page, or null when there is none. */
1493
1571
  html: string | null;
1494
- /** home.html's mtime, or null when `html` is null. */
1572
+ /** The overview page's mtime, or null when `html` is null. */
1495
1573
  mtimeMs: number | null;
1496
- /** project-pages/demo-video/index.html's absolute path + mtime, or null when it does not exist. Load it via smfile:// — never pass its HTML across IPC. */
1574
+ /** The newest video's absolute path + mtime, or null when there is none. Load it via smfile:// — never pass its HTML across IPC. */
1497
1575
  demoVideo: { path: string; mtimeMs: number } | null;
1498
1576
  }
1499
1577
 
@@ -1800,6 +1878,8 @@ export interface SessionManagerAPI {
1800
1878
  /** Full untruncated single-line read via a classifier byte reference (expand-to-full path). */
1801
1879
  readRef: (ref: TranscriptEventRef) => Promise<{ ok: boolean; text?: string; error?: string }>;
1802
1880
  pathFor: (cwd: string, sessionUuid: string) => Promise<string>;
1881
+ /** Does the claude JSONL transcript for this session exist? Remote-readable. */
1882
+ exists: (cwd: string, sessionUuid: string) => Promise<boolean>;
1803
1883
  /** Batched token-usage totals, one map entry per requested sessionId. A
1804
1884
  * session with no transcript file yet (or one over the main-process size
1805
1885
  * cap) maps to null. */
@@ -1878,6 +1958,10 @@ export interface SessionManagerAPI {
1878
1958
  delete: (payload: { id: string }) => Promise<{ ok: boolean }>;
1879
1959
  /** Add/remove one project cwd. A macro shown in every project (`'*'`) cannot be narrowed: `{ ok: false, error: 'macro is shown in every project' }`. */
1880
1960
  setProject: (payload: { id: string; cwd: string; enabled: boolean }) => Promise<{ ok: true; macro: Macro } | { ok: false; error: string }>;
1961
+ /** Dispatch a built-in macro's background build as a scheduler job. */
1962
+ dispatchJob: (payload: MacroJobDispatchInput) => Promise<MacroJobDispatchResult>;
1963
+ /** Status of this project's macro background builds. */
1964
+ jobStatus: (payload: { cwd: string }) => Promise<MacroJobStatus[]>;
1881
1965
  /** Fires after any save/delete/setProject — re-fetch list(). */
1882
1966
  onChanged: (handler: () => void) => () => void;
1883
1967
  };
@@ -2178,13 +2262,17 @@ export interface SessionManagerAPI {
2178
2262
  update: (cwd: string, patch: ProjectBriefPatch) => Promise<ProjectBriefUpdateResult>;
2179
2263
  };
2180
2264
  projectPages: {
2181
- /** Read project-pages/home.html (`{html: null, mtimeMs: null}` if it does not exist yet). Never fires an LLM call. */
2265
+ /** Read the project-pages library (knowledge/<id>/ pages and videos/<id>/ videos, each with its meta) as a `ProjectPagesGetResult`; empty lists if nothing exists yet. Never fires an LLM call. */
2182
2266
  get: (cwd: string) => Promise<ProjectPagesGetResult>;
2183
2267
  /** Start pushing `onChanged` events for this cwd's output dir. Refcounted per cwd; `ok:false` (reason 'ephemeral'|'invalid-cwd') means no live updates are possible, not an error. */
2184
2268
  watch: (cwd: string) => Promise<{ ok: boolean; reason?: 'ephemeral' | 'invalid-cwd' }>;
2185
2269
  /** Stop pushing `onChanged` events for this cwd — must be paired 1:1 with a prior `watch` call. */
2186
2270
  unwatch: (cwd: string) => Promise<{ ok: boolean }>;
2187
- /** Fires whenever a watched cwd's home.html is added/changed/removed, carrying the freshly read result. */
2271
+ /** Rewrite one library entry's meta.json title. Rejects on a bad id, missing entry or invalid meta. */
2272
+ rename: (cwd: string, kind: 'knowledge' | 'video', id: string, title: string) => Promise<{ ok: true; title: string }>;
2273
+ /** Remove exactly one library entry folder. Rejects on a bad id or missing entry. */
2274
+ delete: (cwd: string, kind: 'knowledge' | 'video', id: string) => Promise<{ ok: true }>;
2275
+ /** Fires whenever a watched cwd's knowledge/videos library is added/changed/removed, carrying the freshly read library result. */
2188
2276
  onChanged: (handler: (payload: { cwd: string } & ProjectPagesGetResult) => void) => () => void;
2189
2277
  };
2190
2278
  promptSessionTranscript: {
@@ -2312,6 +2400,14 @@ export interface SessionManagerAPI {
2312
2400
  * (lib/epic/activeIndexMerge.cjs) — persistActiveIndex sends only its own
2313
2401
  * in-memory contribution for the cwd; disk stays main's truth, merged
2314
2402
  * inside the same lock epicMint.cjs's ensureEpic serializes through. */
2403
+ /** Read-tier (remote-safe) Sessions reads, fenced to a registered project's
2404
+ * prompt-sessions ops dir (main/promptSessionsIpc.cjs). Reject on a cwd
2405
+ * that is not a registered project root. */
2406
+ loadActiveIndex: (payload: { cwd: string }) => Promise<{ exists: boolean; data: unknown; error?: string }>;
2407
+ listArchived: (payload: { cwd: string }) => Promise<{ ok: boolean; ids: string[]; error?: string }>;
2408
+ readArchived: (payload: { cwd: string; epicId: string }) => Promise<{ exists: boolean; data: unknown; error?: string }>;
2409
+ readSessionTranscript: (payload: { cwd: string; sessionId: string }) => Promise<{ exists: boolean; text: string; error?: string }>;
2410
+ writeArchive: (payload: { cwd: string; epicId: string; archive: Record<string, unknown> }) => Promise<{ ok: true }>;
2315
2411
  mergeActiveIndex: (payload: PromptSessionsMergeActiveIndexPayload) => Promise<PromptSessionsMergeActiveIndexResult>;
2316
2412
  /** Mints a brand-new 'proposed' Epic through main's own ensureEpic()
2317
2413
  * (lib/epic/promptSessionsCreateEpic.cjs) instead of the renderer
@@ -279,6 +279,13 @@
279
279
  "kind": "invoke",
280
280
  "remote": "read"
281
281
  },
282
+ {
283
+ "ns": "transcripts",
284
+ "method": "exists",
285
+ "channel": "transcript:exists",
286
+ "kind": "invoke",
287
+ "remote": "read"
288
+ },
282
289
  {
283
290
  "ns": "transcripts",
284
291
  "method": "usageFor",
@@ -433,6 +440,20 @@
433
440
  "kind": "invoke",
434
441
  "remote": "mutate"
435
442
  },
443
+ {
444
+ "ns": "macros",
445
+ "method": "dispatchJob",
446
+ "channel": "macros:dispatch-job",
447
+ "kind": "invoke",
448
+ "remote": "mutate"
449
+ },
450
+ {
451
+ "ns": "macros",
452
+ "method": "jobStatus",
453
+ "channel": "macros:job-status",
454
+ "kind": "invoke",
455
+ "remote": "read"
456
+ },
436
457
  {
437
458
  "ns": "macros",
438
459
  "method": "onChanged",
@@ -1301,6 +1322,20 @@
1301
1322
  "kind": "invoke",
1302
1323
  "remote": "mutate"
1303
1324
  },
1325
+ {
1326
+ "ns": "projectPages",
1327
+ "method": "rename",
1328
+ "channel": "project-pages:rename",
1329
+ "kind": "invoke",
1330
+ "remote": "mutate"
1331
+ },
1332
+ {
1333
+ "ns": "projectPages",
1334
+ "method": "delete",
1335
+ "channel": "project-pages:delete",
1336
+ "kind": "invoke",
1337
+ "remote": "mutate"
1338
+ },
1304
1339
  {
1305
1340
  "ns": "projectPages",
1306
1341
  "method": "onChanged",
@@ -1651,6 +1686,41 @@
1651
1686
  "kind": "invoke",
1652
1687
  "remote": "mutate"
1653
1688
  },
1689
+ {
1690
+ "ns": "promptSessions",
1691
+ "method": "loadActiveIndex",
1692
+ "channel": "promptSessions:load-active-index",
1693
+ "kind": "invoke",
1694
+ "remote": "read"
1695
+ },
1696
+ {
1697
+ "ns": "promptSessions",
1698
+ "method": "listArchived",
1699
+ "channel": "promptSessions:list-archived",
1700
+ "kind": "invoke",
1701
+ "remote": "read"
1702
+ },
1703
+ {
1704
+ "ns": "promptSessions",
1705
+ "method": "readArchived",
1706
+ "channel": "promptSessions:read-archived",
1707
+ "kind": "invoke",
1708
+ "remote": "read"
1709
+ },
1710
+ {
1711
+ "ns": "promptSessions",
1712
+ "method": "readSessionTranscript",
1713
+ "channel": "promptSessions:read-session-transcript",
1714
+ "kind": "invoke",
1715
+ "remote": "read"
1716
+ },
1717
+ {
1718
+ "ns": "promptSessions",
1719
+ "method": "writeArchive",
1720
+ "channel": "promptSessions:write-archive",
1721
+ "kind": "invoke",
1722
+ "remote": "mutate"
1723
+ },
1654
1724
  {
1655
1725
  "ns": "promptSessions",
1656
1726
  "method": "createWorktree",
@@ -85,6 +85,8 @@ contextBridge.exposeInMainWorld('api', {
85
85
  readRef: (ref) => ipcRenderer.invoke('transcript:readRef', ref),
86
86
  pathFor: (cwd, sessionUuid) =>
87
87
  ipcRenderer.invoke('transcript:path', { cwd, sessionUuid }),
88
+ exists: (cwd, sessionUuid) =>
89
+ ipcRenderer.invoke('transcript:exists', { cwd, sessionUuid }),
88
90
  usageFor: (cwd, sessionIds) =>
89
91
  ipcRenderer.invoke('transcript:usageFor', { cwd, sessionIds }),
90
92
  // Main sends one batch (array) per flush — see transcripts.cjs's doFlush —
@@ -135,6 +137,8 @@ contextBridge.exposeInMainWorld('api', {
135
137
  save: (payload) => ipcRenderer.invoke('macros:save', payload),
136
138
  delete: (payload) => ipcRenderer.invoke('macros:delete', payload),
137
139
  setProject: (payload) => ipcRenderer.invoke('macros:set-project', payload),
140
+ dispatchJob: (payload) => ipcRenderer.invoke('macros:dispatch-job', payload),
141
+ jobStatus: (payload) => ipcRenderer.invoke('macros:job-status', payload),
138
142
  // Fired after any save/delete/set-project so every subscriber re-fetches list().
139
143
  onChanged: (handler) => {
140
144
  const listener = () => handler();
@@ -378,6 +382,8 @@ contextBridge.exposeInMainWorld('api', {
378
382
  get: (cwd) => ipcRenderer.invoke('project-pages:get', { cwd }),
379
383
  watch: (cwd) => ipcRenderer.invoke('project-pages:watch', { cwd }),
380
384
  unwatch: (cwd) => ipcRenderer.invoke('project-pages:unwatch', { cwd }),
385
+ rename: (cwd, kind, id, title) => ipcRenderer.invoke('project-pages:rename', { cwd, kind, id, title }),
386
+ delete: (cwd, kind, id) => ipcRenderer.invoke('project-pages:delete', { cwd, kind, id }),
381
387
  onChanged: (handler) => {
382
388
  const listener = (_e, payload) => handler(payload);
383
389
  ipcRenderer.on('project-pages:changed', listener);
@@ -584,5 +590,12 @@ contextBridge.exposeInMainWorld('api', {
584
590
  archiveTranscript: (payload) => ipcRenderer.invoke('promptSessions:archiveTranscript', payload),
585
591
  /** Reopens a completed Epic in place (same id + claudeSessionId); never mints an Epic. */
586
592
  reopen: (payload) => ipcRenderer.invoke('promptSessions:reopen', payload),
593
+ /** Read-tier (remote-safe) Sessions reads — see main/promptSessionsIpc.cjs. */
594
+ loadActiveIndex: (payload) => ipcRenderer.invoke('promptSessions:load-active-index', payload),
595
+ listArchived: (payload) => ipcRenderer.invoke('promptSessions:list-archived', payload),
596
+ readArchived: (payload) => ipcRenderer.invoke('promptSessions:read-archived', payload),
597
+ readSessionTranscript: (payload) => ipcRenderer.invoke('promptSessions:read-session-transcript', payload),
598
+ /** Mutate-tier archive write for markCompleted (main builds the path; single-writer 'epics'). */
599
+ writeArchive: (payload) => ipcRenderer.invoke('promptSessions:write-archive', payload),
587
600
  },
588
601
  });