claude-code-session-manager 0.135.0 → 0.136.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 (88) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/assets/{AgentLibrary-DRlcF1YD.js → AgentLibrary-BFztz90B.js} +1 -1
  3. package/dist/assets/{AppSettings-CBhYHKGI.js → AppSettings-6_dqi9Ti.js} +1 -1
  4. package/dist/assets/{Button-DtBUGvGI.js → Button-5wbUTtD5.js} +1 -1
  5. package/dist/assets/{DocumentEditorPane-C82c7Qtl.js → DocumentEditorPane-CRgJFjka.js} +1 -1
  6. package/dist/assets/{Extensions-Kn-oUD2_.js → Extensions-ZXSJbnK7.js} +2 -2
  7. package/dist/assets/{History-B4c3Uz9u.js → History-CmSTZeiu.js} +1 -1
  8. package/dist/assets/{Library-1RpLT-aH.js → Library-DcTnW9kq.js} +1 -1
  9. package/dist/assets/{ListDetail-xr0oxNkv.js → ListDetail-BGsdNFiK.js} +1 -1
  10. package/dist/assets/{Panel-O8XPrpJu.js → Panel-BR2PeMf6.js} +1 -1
  11. package/dist/assets/{ProjectClaudeConfig-DBGhhzg2.js → ProjectClaudeConfig-DJYcUU1G.js} +1 -1
  12. package/dist/assets/{ProvenanceBadge-DSaizfZL.js → ProvenanceBadge-B_TDAI3k.js} +1 -1
  13. package/dist/assets/{Scheduler-D2_5NyiR.js → Scheduler-DqocyumD.js} +1 -1
  14. package/dist/assets/{Settings-Clgqb3Lq.js → Settings-BzPe2TH6.js} +1 -1
  15. package/dist/assets/{SkillReferenceGraph-D80RA7kR.js → SkillReferenceGraph-DfdO0Q_N.js} +1 -1
  16. package/dist/assets/{Skills-DNG7tHSf.js → Skills-CGPJxKhR.js} +1 -1
  17. package/dist/assets/{SourceChip-D-Imzszd.js → SourceChip-CI8xpHRi.js} +1 -1
  18. package/dist/assets/{SystemPrompt-CGlOpUQA.js → SystemPrompt-BbzGIHoz.js} +1 -1
  19. package/dist/assets/{TiptapBody-CJFGfBdz.js → TiptapBody-CTmjUhAI.js} +1 -1
  20. package/dist/assets/{Toggle-0Ff0bPa_.js → Toggle-CWx9Rq6E.js} +1 -1
  21. package/dist/assets/{ViewTabs-BCMYQwo_.js → ViewTabs-BnjD0Crp.js} +1 -1
  22. package/dist/assets/{VoiceButton-JzyC6DAB.js → VoiceButton-C-iQGCL1.js} +1 -1
  23. package/dist/assets/{historyTotals-B01WPBwh.js → historyTotals-BaxAMu7r.js} +1 -1
  24. package/dist/assets/{index-CjQ_p5y7.css → index-62tyjEQB.css} +1 -1
  25. package/dist/assets/index-Cob2iZhR.js +3116 -0
  26. package/dist/index.html +2 -2
  27. package/dist-web/app.css +1 -1
  28. package/dist-web/app.js +412 -412
  29. package/package.json +1 -1
  30. package/plugins/CLAUDE.md +9 -8
  31. package/plugins/packs/apple-design/.claude-plugin/plugin.json +6 -0
  32. package/plugins/packs/apple-design/laws.md +14 -0
  33. package/plugins/packs/apple-design/skills/hig-layout-and-accessibility/SKILL.md +152 -0
  34. package/plugins/packs/apple-design/skills/liquid-glass-adoption/SKILL.md +132 -0
  35. package/plugins/packs/apple-design/sm-pack.json +5 -0
  36. package/plugins/packs/apple-swift-core/.claude-plugin/plugin.json +12 -0
  37. package/plugins/packs/apple-swift-core/laws.md +13 -0
  38. package/plugins/packs/apple-swift-core/skills/swift-concurrency/SKILL.md +160 -0
  39. package/plugins/packs/apple-swift-core/skills/swiftui-state-and-navigation/SKILL.md +165 -0
  40. package/plugins/packs/apple-swift-core/sm-pack.json +5 -0
  41. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  42. package/plugins/session-manager-dev/skills/builder/SKILL.md +136 -91
  43. package/plugins/session-manager-dev/skills/builder/manual.md +80 -0
  44. package/plugins/session-manager-dev/skills/develop/SKILL.md +29 -56
  45. package/plugins/session-manager-dev/skills/develop/standards.md +11 -19
  46. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +9 -0
  47. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +5 -2
  48. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +100 -5
  49. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +65 -21
  50. package/scripts/scheduler-mcp-server.cjs +65 -5
  51. package/src/main/build-info.json +4 -4
  52. package/src/main/chatRunner.cjs +26 -2
  53. package/src/main/index.cjs +4 -0
  54. package/src/main/ipcSchemas.cjs +13 -0
  55. package/src/main/lib/CLAUDE.md +2 -0
  56. package/src/main/lib/claude/agentModelResolve.cjs +23 -0
  57. package/src/main/lib/epic/epicMint.cjs +12 -6
  58. package/src/main/lib/epic/epicTranscriptPath.cjs +5 -4
  59. package/src/main/lib/epic/promptSessionsCreateEpic.cjs +8 -4
  60. package/src/main/lib/epic/restorableSessions.cjs +16 -8
  61. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +201 -8
  62. package/src/main/lib/feedback-remote/crossProjectReply.cjs +375 -0
  63. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
  64. package/src/main/lib/mcpToolCatalog.cjs +38 -4
  65. package/src/main/lib/mdNetworkScan.cjs +61 -11
  66. package/src/main/lib/mdReviewRecord.cjs +287 -0
  67. package/src/main/lib/packs/packCatalog.cjs +120 -0
  68. package/src/main/lib/packs/packSpawnArgs.cjs +59 -0
  69. package/src/main/lib/packs/packsIpc.cjs +76 -0
  70. package/src/main/lib/persona-macro/builtinMacros.cjs +3 -2
  71. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +34 -0
  72. package/src/main/lib/prd/prdCreate.cjs +2 -2
  73. package/src/main/lib/promptSessionSchema.cjs +8 -0
  74. package/src/main/projectPages.cjs +19 -0
  75. package/src/main/promptSessionEvents.cjs +8 -1
  76. package/src/main/scheduler.cjs +23 -2
  77. package/src/preload/api.d.ts +71 -0
  78. package/src/preload/apiSurface.json +21 -0
  79. package/src/preload/index.cjs +7 -0
  80. package/src/seed/agents/demo-video-builder.md +28 -33
  81. package/src/seed/agents/dev-lead.md +3 -3
  82. package/dist/assets/index-rt7pTODX.js +0 -3116
  83. package/plugins/session-manager-dev/skills/builder/0-diff/SKILL.md +0 -44
  84. package/plugins/session-manager-dev/skills/builder/1-classify-and-bump/SKILL.md +0 -37
  85. package/plugins/session-manager-dev/skills/builder/2-gate/SKILL.md +0 -37
  86. package/plugins/session-manager-dev/skills/builder/3-publish/SKILL.md +0 -137
  87. package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +0 -124
  88. package/plugins/session-manager-dev/skills/builder/5-report/SKILL.md +0 -35
@@ -247,6 +247,9 @@ const promptSessionsCreateEpic = z.object({
247
247
  agentCli: z.enum(['claude', 'codex', 'gemini', 'antigravity', 'cursor', 'opencode']).optional(),
248
248
  // Model passed to a non-Claude CLI; absent = that CLI's own default.
249
249
  agentCliModel: z.string().min(1).max(128).optional(),
250
+ // Selected context pack ids (same bounds as PromptSessionSchema.packs); absent = none.
251
+ // ensureEpic dedupes them and drops them for a non-Claude agentCli.
252
+ packs: z.array(z.string().min(1).max(64)).max(16).optional(),
250
253
  });
251
254
 
252
255
  // Renderer entry point for the "Restore a session" picker: this project's CLI
@@ -932,6 +935,14 @@ const projectPagesMdNetwork = z.object({
932
935
  docFolders: mdNetworkFolderList.optional(),
933
936
  }).strict();
934
937
 
938
+ // project-pages:md-review — cwd plus optional Review MD network Epic ids whose
939
+ // reviews/validation/<id>/ folders to list. Ids are joined onto the fs, so the
940
+ // slug regex (same as lib/mdReviewRecord.cjs EPIC_ID_RE) is load-bearing.
941
+ const projectPagesMdReview = z.object({
942
+ cwd: z.string().min(1).max(4096),
943
+ epicIds: z.array(z.string().regex(/^[a-z0-9][a-z0-9-]{0,127}$/)).max(50).optional(),
944
+ }).strict();
945
+
935
946
  // ──────────────────────────────────────────── Project Home admin route
936
947
  // Real path validation is projectRootResolve.cjs + config.cjs's validatePath;
937
948
  // html content limits live in projectHomeAdminRoutes.cjs's validateHomeHtml.
@@ -967,6 +978,7 @@ const projectVideoMeta = z.object({
967
978
  id: entryId,
968
979
  title: z.string().min(1).max(120),
969
980
  kind: z.enum(['project-demo', 'blog-post', 'feature']),
981
+ target: z.string().max(300).optional(),
970
982
  style: z.string().max(40),
971
983
  lengthS: z.number().int().min(5).max(60),
972
984
  createdAt: z.string().datetime(),
@@ -1567,6 +1579,7 @@ module.exports = {
1567
1579
  projectBriefCwd,
1568
1580
  projectPagesCwd,
1569
1581
  projectPagesMdNetwork,
1582
+ projectPagesMdReview,
1570
1583
  projectPagesRename,
1571
1584
  projectPagesDelete,
1572
1585
  projectHomeAdminWriteBody,
@@ -7,12 +7,14 @@ Shared main-process helpers (CommonJS `.cjs`). Layout source of truth: `scripts/
7
7
  - `agent-cli/` — other agent CLIs: registry, adapters, session store, turn planner, IPC.
8
8
  - `app-preview/` — Epic dev-server preview processes (spawn, URL detect, stop, orphan sweep).
9
9
  - `claude/` — claude CLI binary, caps, model/effort resolution.
10
+ - `demo-video-kit/` — demo-video build tools (capture, sound, frames, checks), seeded to `~/.claude/session-manager/demo-video-kit/`.
10
11
  - `epic/` — Epic mint, worktrees, active index, spawn plan/cwd, transcripts.
11
12
  - `feedback-remote/` — cross-project and customer feedback conduits.
12
13
  - `git/` — git exec, worktrees, branch sweeps, job worktrees.
13
14
  - `persona-macro/` — agent persona schema/merge, macro library, builtin macros.
14
15
  - `prd/` — PRD parsing helpers, admin routes, dep-slug resolution, plan validation.
15
16
  - `process/` — child processes, kill tree, env cleaning, pid liveness, instance lock.
17
+ - `project-pages/` — Project Home pages library, competitor matrix store/HTML, player bridge.
16
18
  - `scheduler/` — dispatch loop, session slots, gates, supervisors, queue helpers.
17
19
  - `telemetry/` — audit/ops error logs, crash and OTLP telemetry.
18
20
  - `util/` — generic pure helpers (atomic fs, kebab, home/cwd encoding, JSON extract, tail).
@@ -85,6 +85,28 @@ function findEpicByClaudeSessionId(cwd, claudeSessionId, deps = {}) {
85
85
  return null;
86
86
  }
87
87
 
88
+ /**
89
+ * Looks up an Epic (PromptSession) row by its own Epic id — the key of the
90
+ * active index, or a row whose `id` matches. Same reader as
91
+ * findEpicByClaudeSessionId. Returns the row or null; never throws.
92
+ */
93
+ function findEpicById(cwd, epicId, deps = {}) {
94
+ if (!cwd || !epicId) return null;
95
+ try {
96
+ const load = deps.readActiveIndex || readActiveIndex;
97
+ const { sessions } = load(cwd);
98
+ if (!sessions || typeof sessions !== 'object') return null;
99
+ const direct = Object.prototype.hasOwnProperty.call(sessions, epicId) ? sessions[epicId] : null;
100
+ if (direct && typeof direct === 'object') return direct;
101
+ for (const session of Object.values(sessions)) {
102
+ if (session && session.id === epicId) return session;
103
+ }
104
+ return null;
105
+ } catch {
106
+ return null;
107
+ }
108
+ }
109
+
88
110
  function findAgentTypeByClaudeSessionId(cwd, claudeSessionId, deps = {}) {
89
111
  return findEpicByClaudeSessionId(cwd, claudeSessionId, deps)?.agentType || null;
90
112
  }
@@ -265,6 +287,7 @@ module.exports = {
265
287
  resolveEpicModel,
266
288
  findAgentTypeByClaudeSessionId,
267
289
  findEpicByClaudeSessionId,
290
+ findEpicById,
268
291
  epicOverrideValue,
269
292
  readOverlayAwarePersonaModel,
270
293
  readOverlayAwarePersona,
@@ -48,14 +48,19 @@ const promptSessionSchema = require('../promptSessionSchema.cjs');
48
48
  const { isAgentCliId, isNonClaudeAgentCli, AGENT_CLI_MODEL_RE } = require('../agent-cli/agentCliEvents.cjs');
49
49
 
50
50
  /**
51
- * agentCliMintFields(agentCli, agentCliModel, restoreSessionId) — validate the
51
+ * agentCliMintFields(agentCli, agentCliModel, restoreSessionId, packs) — validate the
52
52
  * Epic's agent-CLI options and return the record keys they add ({} for a
53
53
  * Claude Code Epic, so its on-disk shape is unchanged). Throws on any bad
54
54
  * combination. The develop loop (dev plugin, /develop, PRD API) and Restore a
55
55
  * session only work with Claude Code, so a non-Claude Epic is always
56
56
  * developLoop:false and can never adopt a CLI session.
57
+ *
58
+ * `packs` (selected context pack ids) are Claude Code only too: a non-empty
59
+ * array on a Claude Epic adds `packs` (deduplicated, order kept); a non-Claude
60
+ * Epic, or an absent/empty array, adds no `packs` key. Ids are not checked
61
+ * against the pack catalog here — PromptSessionSchema bounds them.
57
62
  */
58
- function agentCliMintFields(agentCli, agentCliModel, restoreSessionId) {
63
+ function agentCliMintFields(agentCli, agentCliModel, restoreSessionId, packs = null) {
59
64
  const absent = agentCli === undefined || agentCli === null || agentCli === 'claude';
60
65
  if (!absent && !isAgentCliId(agentCli)) {
61
66
  throw new Error(`ensureEpic: unknown agentCli '${String(agentCli)}' — expected one of claude, codex, gemini, antigravity, cursor, opencode`);
@@ -63,7 +68,8 @@ function agentCliMintFields(agentCli, agentCliModel, restoreSessionId) {
63
68
  const modelGiven = agentCliModel !== undefined && agentCliModel !== null;
64
69
  if (absent || !isNonClaudeAgentCli(agentCli)) {
65
70
  if (modelGiven) throw new Error('ensureEpic: agentCliModel requires a non-Claude agentCli');
66
- return {};
71
+ const unique = Array.isArray(packs) ? [...new Set(packs)] : [];
72
+ return unique.length > 0 ? { packs: unique } : {};
67
73
  }
68
74
  if (restoreSessionId !== null && restoreSessionId !== undefined) {
69
75
  throw new Error(`ensureEpic: Restore a session is Claude Code only — cannot restore into a '${agentCli}' Epic`);
@@ -301,7 +307,7 @@ function restoreRefusal(cwd, index, restoreSessionId, mintAuthority, deps) {
301
307
  * The Epic's id doubles as its directory name under scheduler/epics/, so the
302
308
  * PromptSession ↔ on-disk Epic mapping is 1:1 with no lookup table.
303
309
  */
304
- function ensureEpic(cwd, { goalText, tag, epicId: explicitEpicId, status = 'proposed', openingPrompt = null, sections = null, source = null, agentType = null, model = null, effort = null, developLoop = null, mintAuthority = null, restoreSessionId = null, agentCli = null, agentCliModel = null } = {}, deps = {}) {
310
+ function ensureEpic(cwd, { goalText, tag, epicId: explicitEpicId, status = 'proposed', openingPrompt = null, sections = null, source = null, agentType = null, model = null, effort = null, developLoop = null, mintAuthority = null, restoreSessionId = null, agentCli = null, agentCliModel = null, packs = null } = {}, deps = {}) {
305
311
  if (!cwd || typeof cwd !== 'string') throw new Error('ensureEpic: cwd is required');
306
312
  // A relative cwd (e.g. a caller passing '.') would otherwise get stored
307
313
  // verbatim on the minted Epic's `cwd` field — the renderer's EpicsWorkspace
@@ -312,7 +318,7 @@ function ensureEpic(cwd, { goalText, tag, epicId: explicitEpicId, status = 'prop
312
318
  return withPathLock(activeIndexPath(cwd), () => {
313
319
  // Agent-CLI rules run first — a bad id or combination throws before
314
320
  // anything (index, mirror, audit, PRD dir) is written.
315
- const cliFields = agentCliMintFields(agentCli, agentCliModel, restoreSessionId);
321
+ const cliFields = agentCliMintFields(agentCli, agentCliModel, restoreSessionId, packs);
316
322
  if (cliFields.agentCli) developLoop = false;
317
323
  const index = readActiveIndex(cwd);
318
324
 
@@ -433,7 +439,7 @@ function ensureEpic(cwd, { goalText, tag, epicId: explicitEpicId, status = 'prop
433
439
  ...(typeof effort === 'string' && effort ? { effort } : {}),
434
440
  // Only false is persisted: absent = develop loop on (byte-identical legacy shape).
435
441
  ...(developLoop === false ? { developLoop: false } : {}),
436
- // Non-Claude agent CLI only (absent = Claude Code, legacy shape).
442
+ // Agent-CLI fields: agentCli/agentCliModel (non-Claude only) or packs (Claude only); absent = legacy shape.
437
443
  ...cliFields,
438
444
  };
439
445
 
@@ -15,7 +15,8 @@
15
15
  *
16
16
  * Bounded: never enumerates ~/.claude/projects, only stats its candidate list.
17
17
  * The active-index.json read and the archive scan are memoised per cwd on
18
- * mtimeMs + size (same shape as transcripts.cjs's usageCache) because
18
+ * restorableSessions.cjs's keyOf (dev:ino:ctimeMs:mtimeMs:size; mtimeMs:size
19
+ * alone misses a same-size, same-mtime rewrite — see keyOf) because
19
20
  * usageFor() can call this for up to 500 ids in one IPC.
20
21
  *
21
22
  * Ops-root hazard (see epicSpawnCwd.cjs): `cwd` here is the PROJECT cwd used
@@ -29,7 +30,7 @@ const { encodeCwd } = require('../util/encodeCwd.cjs');
29
30
  const { readActiveIndex } = require('./epicMint.cjs');
30
31
  const { resolveEpicSpawnCwd } = require('./epicSpawnCwd.cjs');
31
32
 
32
- /** Map<cwd, { key, sessions }> — active-index.json parse, keyed on mtime+size. */
33
+ /** Map<cwd, { key, sessions }> — active-index.json parse, keyed on keyOf(stat). */
33
34
  const indexCache = new Map();
34
35
  /** Map<cwd, { dirKey, files: Map<name,{key,sid,dir}>, byId: Map<sid,string[]> }> */
35
36
  const archiveCache = new Map();
@@ -45,8 +46,8 @@ function emptyResult() {
45
46
 
46
47
  function statKey(statSync, p) {
47
48
  try {
48
- const s = statSync(p);
49
- return `${s.mtimeMs}:${s.size}`;
49
+ // Lazy: restorableSessions.cjs is heavier than this module needs at load.
50
+ return require('./restorableSessions.cjs').keyOf(statSync(p));
50
51
  } catch {
51
52
  return 'missing';
52
53
  }
@@ -23,7 +23,7 @@ const { listRestorableSessions, listRecentRestorableSessions } = require('./rest
23
23
  const { validatePath } = require('../../config.cjs');
24
24
 
25
25
  /**
26
- * createEpicViaIpc(cwd, { goalText, tag?, agentType?, source?, restoreSessionId?, agentCli?, agentCliModel? }) → Promise<{ epicId, session }>
26
+ * createEpicViaIpc(cwd, { goalText, tag?, agentType?, source?, restoreSessionId?, agentCli?, agentCliModel?, packs? }) → Promise<{ epicId, session }>
27
27
  *
28
28
  * THE one Epic-creation path (epicMint.cjs's SINGLE-CREATOR LAW): this handler
29
29
  * holds `MINT_AUTHORITY_NEW_EPIC_UI`, the token that unlocks ensureEpic's mint
@@ -53,8 +53,11 @@ const { validatePath } = require('../../config.cjs');
53
53
  *
54
54
  * `agentCli` / `agentCliModel` (absent = Claude Code) pick the agent CLI. ensureEpic
55
55
  * owns the Claude-only rules; a broken rule throws, so the call rejects and nothing is minted.
56
+ *
57
+ * `packs` (absent = none) are the selected context pack ids; ensureEpic dedupes them
58
+ * and drops them for a non-Claude agentCli.
56
59
  */
57
- async function createEpicViaIpc(cwd, { goalText, tag, agentType, model, effort, developLoop, source, openingPrompt, sections, restoreSessionId, agentCli, agentCliModel } = {}) {
60
+ async function createEpicViaIpc(cwd, { goalText, tag, agentType, model, effort, developLoop, source, openingPrompt, sections, restoreSessionId, agentCli, agentCliModel, packs } = {}) {
58
61
  validatePath(cwd);
59
62
  const { epicId } = await ensureEpic(cwd, {
60
63
  goalText,
@@ -69,6 +72,7 @@ async function createEpicViaIpc(cwd, { goalText, tag, agentType, model, effort,
69
72
  restoreSessionId,
70
73
  agentCli,
71
74
  agentCliModel,
75
+ packs,
72
76
  mintAuthority: MINT_AUTHORITY_NEW_EPIC_UI,
73
77
  status: 'proposed',
74
78
  });
@@ -117,8 +121,8 @@ function registerPromptSessionsCreateEpicHandlers(deps = {}) {
117
121
  const { schemas: s, validated: v } = require('../../ipcSchemas.cjs');
118
122
  ipcMain.handle(
119
123
  'promptSessions:create-epic',
120
- v(s.promptSessionsCreateEpic, ({ cwd, goalText, tag, agentType, model, effort, developLoop, source, openingPrompt, sections, restoreSessionId, agentCli, agentCliModel }) =>
121
- createEpicViaIpc(cwd, { goalText, tag, agentType, model, effort, developLoop, source, openingPrompt, sections, restoreSessionId, agentCli, agentCliModel })),
124
+ v(s.promptSessionsCreateEpic, ({ cwd, goalText, tag, agentType, model, effort, developLoop, source, openingPrompt, sections, restoreSessionId, agentCli, agentCliModel, packs }) =>
125
+ createEpicViaIpc(cwd, { goalText, tag, agentType, model, effort, developLoop, source, openingPrompt, sections, restoreSessionId, agentCli, agentCliModel, packs })),
122
126
  );
123
127
  ipcMain.handle(
124
128
  'promptSessions:list-restorable',
@@ -29,7 +29,7 @@
29
29
  * row never takes an interactive row's place. Per-kind budgets exist because
30
30
  * a project with claude -p automation has ~98% headless transcripts: one
31
31
  * shared budget listed 48 headless + 2 interactive rows on this repo;
32
- * - memoises the claimed-id scan per cwd on each ops file's mtimeMs:size, so
32
+ * - memoises the claimed-id scan per cwd on each ops file's stat key (keyOf), so
33
33
  * an unchanged Epic file is never re-read (epicTranscriptPath.cjs's shape).
34
34
  * The list path scans through fs.promises (claimedClaudeSessionIdsAsync): a
35
35
  * cold scan reads every archived Epic file, which blocked 191 ms when sync.
@@ -131,16 +131,23 @@ function __resetCacheForTests() {
131
131
  /**
132
132
  * The memo key. One formatter for both stat paths, so each reader can reuse
133
133
  * the records the other wrote.
134
+ *
135
+ * mtimeMs:size alone served stale ids: a rewrite that swaps one claudeSessionId
136
+ * for another is always the same size (UUIDs are fixed-length), and it keeps
137
+ * its mtime when it lands within one timestamp tick (coarse-mtime filesystems)
138
+ * or has its mtime restored. dev:ino changes on every tmp+rename write (how
139
+ * atomicFs writes Epic files), and ctime moves on every write and can't be
140
+ * set back from user space.
134
141
  * @param {import('node:fs').Stats} s
135
- * @returns {string} `mtimeMs:size`
142
+ * @returns {string} `dev:ino:ctimeMs:mtimeMs:size`
136
143
  */
137
144
  function keyOf(s) {
138
- return `${s.mtimeMs}:${s.size}`;
145
+ return `${s.dev}:${s.ino}:${s.ctimeMs}:${s.mtimeMs}:${s.size}`;
139
146
  }
140
147
 
141
148
  /**
142
149
  * @param {string} file
143
- * @returns {string} `mtimeMs:size`, or 'missing'
150
+ * @returns {string} keyOf(stat), or 'missing'
144
151
  */
145
152
  function statKey(file) {
146
153
  try {
@@ -153,7 +160,7 @@ function statKey(file) {
153
160
  /**
154
161
  * statKey through fs.promises.
155
162
  * @param {string} file
156
- * @returns {Promise<string>} `mtimeMs:size`, or 'missing'
163
+ * @returns {Promise<string>} keyOf(stat), or 'missing'
157
164
  */
158
165
  async function statKeyAsync(file) {
159
166
  try {
@@ -257,7 +264,7 @@ function isArchiveName(name) {
257
264
 
258
265
  /**
259
266
  * First half of the per-file archive-record update both readers share: the
260
- * memo's record while the file's mtimeMs:size is unchanged, else null.
267
+ * memo's record while the file's stat key is unchanged, else null.
261
268
  * @param {Map<string, ArchiveRec>} prevFiles
262
269
  * @param {string} name
263
270
  * @param {string} key
@@ -296,7 +303,7 @@ function commitClaimed(cwd, entry) {
296
303
  /**
297
304
  * Every claudeSessionId an Epic of this project owns: active-index.json plus
298
305
  * each archived prompt-sessions/<id>.json. Memoised per cwd on each file's
299
- * mtimeMs:size, so an unchanged file is never re-read (one statSync per file per
306
+ * stat key (keyOf), so an unchanged file is never re-read (one statSync per file per
300
307
  * call); the memo is shared with claimedClaudeSessionIdsAsync. A cwd with no ops
301
308
  * root (relative, tmpdir or linked worktree) cannot hold Epics, so it owns
302
309
  * nothing. Sync, for the mint gate (checkRestorableSessionSync).
@@ -333,7 +340,7 @@ function claimedClaudeSessionIds(cwd, deps) {
333
340
  * claimedClaudeSessionIds through fs.promises (readdir, stat and readFile, at
334
341
  * most 16 files in flight), for the list path. A cold scan reads every archived
335
342
  * Epic file; done sync it blocked the main loop for 191 ms. Same memo as the
336
- * sync reader, so either one re-reads only the files whose mtimeMs:size changed
343
+ * sync reader, so either one re-reads only the files whose stat key changed
337
344
  * since the last scan by either. active-index.json stays a readActiveIndex read,
338
345
  * memoised on its own key as in the sync reader.
339
346
  * @param {string} cwd Project cwd (mapped to its ops root by opsPath).
@@ -828,6 +835,7 @@ function checkRestorableSessionSync(cwd, sessionId, deps) {
828
835
 
829
836
  module.exports = {
830
837
  SESSION_ID_RE,
838
+ keyOf,
831
839
  claimedClaudeSessionIds,
832
840
  claimedClaudeSessionIdsAsync,
833
841
  listRestorableSessions,
@@ -86,7 +86,8 @@ const {
86
86
  MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK,
87
87
  } = require('../epic/epicMint.cjs');
88
88
  const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
89
- const { OPS_ROOT_DIR } = require('../opsOwnership.cjs');
89
+ const { OPS_ROOT_DIR, opsPath } = require('../opsOwnership.cjs');
90
+ const { readJsonOrSync } = require('../util/atomicFs.cjs');
90
91
  const { resolveProjectContext } = require('../projectRootResolve.cjs');
91
92
  const { isEphemeralCwd } = require('../ephemeralCwd.cjs');
92
93
 
@@ -177,6 +178,34 @@ function resolveOriginAsk(fromCwd, fromEpicId) {
177
178
  }
178
179
  }
179
180
 
181
+ /**
182
+ * resolveReplyTo(fromCwd, fromEpicId) → { cwd, epicId, claudeSessionId } | null
183
+ *
184
+ * The thread back to the sending Epic, stamped on the receiving Epic as
185
+ * source.replyTo. Null when the sender is unresolved (e.g. a scheduler job
186
+ * with no chat session id) or its Epic carries no claudeSessionId — a reply
187
+ * needs a live session to land in. Never throws.
188
+ */
189
+ function resolveReplyTo(fromCwd, fromEpicId) {
190
+ if (typeof fromCwd !== 'string' || !fromCwd || typeof fromEpicId !== 'string' || !fromEpicId) return null;
191
+ let claudeSessionId = null;
192
+ try {
193
+ const epic = readActiveIndex(fromCwd).sessions[fromEpicId];
194
+ claudeSessionId = epic && typeof epic.claudeSessionId === 'string' ? epic.claudeSessionId : null;
195
+ } catch {
196
+ claudeSessionId = null;
197
+ }
198
+ if (!claudeSessionId) return null;
199
+ return { cwd: fromCwd, epicId: fromEpicId, claudeSessionId };
200
+ }
201
+
202
+ function replyNote(replyTo) {
203
+ return replyTo
204
+ ? `The receiving session can answer into this session (${replyTo.epicId}) with feedback_reply.`
205
+ : 'No reply path exists because the sending session could not be identified, so the receiving session '
206
+ + 'cannot answer back. If you need an answer, ask the human to follow up.';
207
+ }
208
+
180
209
  function seriesLine(series) {
181
210
  return series ? `Part ${series.index} of ${series.total} — ${singleLine(series.title)}` : '';
182
211
  }
@@ -217,6 +246,7 @@ function composeFeedbackIntake({
217
246
  acceptanceCriteria = [],
218
247
  outOfScope = [],
219
248
  series = null,
249
+ replyTo = null,
220
250
  } = {}) {
221
251
  const trimmedTitle = singleLine(title);
222
252
  const trimmedBody = String(body ?? '').trim();
@@ -246,7 +276,12 @@ function composeFeedbackIntake({
246
276
  `This session is INBOUND FEEDBACK from another project: ${origin}.${askClause} `
247
277
  + 'Nobody in this project wrote the report below — an agent working in that project did, and it '
248
278
  + 'may be wrong about this codebase. Verify the claim against the code here before acting on it, '
249
- + 'and if it does not hold, say so and close the session rather than building against it.',
279
+ + 'and if it does not hold, say so and close the session rather than building against it.'
280
+ + (replyTo
281
+ ? ' When the work is done, blocked, or needs an answer, call feedback_reply from this session '
282
+ + '(not from a PRD, and never a new feedback_open_session); the answer lands in the asking session '
283
+ + `${singleLine(replyTo.epicId)} in ${path.basename(singleLine(replyTo.cwd)) || singleLine(replyTo.cwd)}.`
284
+ : ''),
250
285
  source: fromCwd,
251
286
  });
252
287
 
@@ -625,6 +660,7 @@ async function openFeedbackSession(input, deps = {}) {
625
660
  }
626
661
 
627
662
  const originAsk = resolveOriginAsk(v.fromCwd, v.fromEpicId);
663
+ const replyTo = resolveReplyTo(v.fromCwd, v.fromEpicId);
628
664
 
629
665
  const { goalText, openingPrompt, sections } = composeFeedbackIntake({
630
666
  fromCwd: v.fromCwd,
@@ -640,6 +676,7 @@ async function openFeedbackSession(input, deps = {}) {
640
676
  acceptanceCriteria: v.acceptanceCriteria,
641
677
  outOfScope: v.outOfScope,
642
678
  series: v.series,
679
+ replyTo,
643
680
  });
644
681
 
645
682
  // The Epic's stored identity is the one-line title, not the whole report —
@@ -658,6 +695,7 @@ async function openFeedbackSession(input, deps = {}) {
658
695
  producer: 'cross-project-feedback',
659
696
  fromCwd: v.fromCwd,
660
697
  ...(v.fromEpicId ? { fromEpicId: v.fromEpicId } : {}),
698
+ ...(replyTo ? { replyTo } : {}),
661
699
  ...(auto.granted
662
700
  ? {
663
701
  autoApprove: macroGranted
@@ -744,21 +782,173 @@ async function openFeedbackSession(input, deps = {}) {
744
782
  receiptOnOriginEpic,
745
783
  // Say plainly what did NOT happen, same posture as create-prd's
746
784
  // `enqueued: false` — never let a caller report this as "work started".
747
- note: macroGranted
785
+ note: (macroGranted
748
786
  ? `Auto-approved by the "${auto.macroLabel}" macro (${auto.macroId}), which the human launched this session `
749
787
  + 'from and which allows auto-start in this project: the session is starting in the receiving project. '
750
- + 'There is no callback: if you need an answer, ask the human to follow up.'
751
788
  : auto.granted
752
789
  ? 'Auto-approved at the human\'s explicit request (verified against their chat prompt): the session '
753
- + 'is starting in the receiving project. There is no callback: if you need an answer, ask the human '
754
- + 'to follow up.'
790
+ + 'is starting in the receiving project. '
755
791
  : 'Delivered as a PROPOSED session in the receiving project\'s Sessions queue. Nothing runs and no '
756
- + 'tokens are spent until a human in that project presses Approve & start. There is no callback: '
757
- + 'if you need an answer, ask the human to follow up.',
792
+ + 'tokens are spent until a human in that project presses Approve & start. ')
793
+ + replyNote(replyTo),
758
794
  goalText,
759
795
  };
760
796
  }
761
797
 
798
+ /**
799
+ * readEpicGoal(cwd, epicId) → string | null
800
+ *
801
+ * An Epic's goalText from the active index, or — for an archived Epic no
802
+ * longer in the index — from its `prompt-sessions/<epicId>.json` file
803
+ * (archived shape `.session.goalText`; flat mirror shape `.goalText`).
804
+ * Read-only; never throws.
805
+ */
806
+ function readEpicGoal(cwd, epicId) {
807
+ if (typeof cwd !== 'string' || !cwd || typeof epicId !== 'string' || !epicId) return null;
808
+ try {
809
+ const row = readActiveIndex(cwd).sessions[epicId];
810
+ const goal = row && typeof row.goalText === 'string' ? singleLine(row.goalText) : '';
811
+ if (goal) return goal;
812
+ } catch { /* fall through to the per-Epic file */ }
813
+ let file;
814
+ try {
815
+ file = opsPath(cwd, 'prompt-sessions', `${epicId}.json`);
816
+ } catch {
817
+ return null;
818
+ }
819
+ const doc = readJsonOrSync(file, null);
820
+ if (!doc || typeof doc !== 'object') return null;
821
+ const raw = doc.session && typeof doc.session === 'object' && typeof doc.session.goalText === 'string'
822
+ ? doc.session.goalText
823
+ : (typeof doc.goalText === 'string' ? doc.goalText : '');
824
+ return singleLine(raw) || null;
825
+ }
826
+
827
+ function fallbackReasonText(reason) {
828
+ const r = String(reason || 'unknown');
829
+ if (r === 'missing') return 'missing: the asking session is no longer in its project\'s active Sessions (archived or removed)';
830
+ if (r === 'not-active') return 'not-active: the asking session is not active (completed or not yet started)';
831
+ if (r === 'session-mismatch') return 'session-mismatch: the asking session now runs a different Claude session';
832
+ if (r.startsWith('send-refused')) return `${r}: the app refused to send the reply into the asking session`;
833
+ return r;
834
+ }
835
+
836
+ /**
837
+ * openReplyFallbackSession(input, deps?) → { ok, epicId, toCwd, ... } | { ok: false, status, error }
838
+ *
839
+ * The fallback leg of feedback_reply (crossProjectReply.cjs): when the asking
840
+ * Epic X in project A cannot take the reply, this mints a NEW `proposed`
841
+ * Epic in A that links X (source.replyOf) and carries X's goal, the original
842
+ * request and both sets of reference paths. It is minted here — through this
843
+ * module's MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK — because the SINGLE-CREATOR
844
+ * LAW allows no third mint authority. Never auto-approved.
845
+ *
846
+ * input: { reason, toCwd, toEpicId, fromCwd, fromEpicId, message, outcome,
847
+ * referencePaths, original: { title, proposal, referencePaths } }
848
+ * deps: { ensureEpic, appendAudit }
849
+ */
850
+ async function openReplyFallbackSession(input = {}, deps = {}) {
851
+ const mint = deps.ensureEpic || ensureEpic;
852
+ const audit = deps.appendAudit || appendAuditEvent;
853
+ const bad = (status, error) => ({ ok: false, status, error });
854
+
855
+ const message = typeof input.message === 'string' ? input.message.trim() : '';
856
+ if (!message) return bad(400, 'message is required');
857
+ const toEpicId = typeof input.toEpicId === 'string' ? input.toEpicId : '';
858
+ if (!toEpicId) return bad(400, 'toEpicId (the asking Epic) is required');
859
+ const fromEpicId = typeof input.fromEpicId === 'string' && input.fromEpicId ? input.fromEpicId : null;
860
+ let toCwd;
861
+ let fromCwd;
862
+ try {
863
+ toCwd = config.validatePath(path.resolve(String(input.toCwd || '')));
864
+ fromCwd = config.validatePath(path.resolve(String(input.fromCwd || '')));
865
+ } catch (e) {
866
+ return bad(400, `cwd rejected: ${e.message}`);
867
+ }
868
+ if (!isSessionManagerProject(toCwd)) return bad(400, `${toCwd} is not a Session Manager project`);
869
+ if (toCwd === fromCwd) return bad(400, 'the reply fallback must land in a DIFFERENT project');
870
+
871
+ const original = input.original && typeof input.original === 'object' ? input.original : {};
872
+ const proposal = original.proposal && typeof original.proposal === 'object' ? original.proposal : {};
873
+ const originalTitle = singleLine(original.title) || '(untitled request)';
874
+ const motivation = typeof proposal.motivation === 'string' ? proposal.motivation.trim() : '';
875
+ const strList = (xs) => (Array.isArray(xs) ? xs.filter((x) => typeof x === 'string' && x.trim()).map((x) => x.trim()) : []);
876
+ const acceptanceCriteria = strList(proposal.acceptanceCriteria).slice(0, MAX_LIST_ITEMS);
877
+ const referencePaths = [...new Set([...strList(original.referencePaths), ...strList(input.referencePaths)])]
878
+ .slice(0, MAX_REFERENCES);
879
+ const outcome = singleLine(input.outcome) || 'unknown';
880
+ const reason = singleLine(input.reason) || 'unknown';
881
+ const xGoal = readEpicGoal(toCwd, toEpicId);
882
+ const replierName = path.basename(fromCwd) || fromCwd;
883
+
884
+ const title = `Reply from ${replierName}: ${originalTitle}`.slice(0, MAX_TITLE_CHARS);
885
+ const body = [
886
+ `This reply could not be delivered into the asking session ${toEpicId}, so it opened as a new proposed `
887
+ + `session instead. Why it fell back: ${fallbackReasonText(reason)}.`,
888
+ `Asking session: ${toEpicId}${xGoal ? ` — goal: "${xGoal.slice(0, MAX_ORIGIN_ASK_CHARS)}"` : ' — goal unknown'}.`,
889
+ `Original request (sent from this project to ${replierName}): ${originalTitle}`,
890
+ `## Reply (outcome: ${outcome})\n${message}`,
891
+ ].join('\n\n');
892
+
893
+ const originAsk = xGoal ? xGoal.slice(0, MAX_ORIGIN_ASK_CHARS) : null;
894
+ const { openingPrompt, sections } = composeFeedbackIntake({
895
+ fromCwd,
896
+ fromEpicId,
897
+ title,
898
+ body,
899
+ agentName: DEFAULT_FEEDBACK_AGENT,
900
+ referencePaths,
901
+ originAsk,
902
+ motivation,
903
+ acceptanceCriteria,
904
+ });
905
+
906
+ const replyOf = { cwd: toCwd, epicId: toEpicId };
907
+ let minted;
908
+ try {
909
+ minted = await mint(toCwd, {
910
+ goalText: title,
911
+ tag: DEFAULT_FEEDBACK_TAG,
912
+ agentType: DEFAULT_FEEDBACK_AGENT,
913
+ status: 'proposed',
914
+ openingPrompt,
915
+ sections,
916
+ source: {
917
+ producer: 'cross-project-feedback',
918
+ fromCwd,
919
+ ...(fromEpicId ? { fromEpicId } : {}),
920
+ replyOf,
921
+ proposal: {
922
+ motivation,
923
+ originAsk,
924
+ plan: strList(proposal.plan).slice(0, MAX_LIST_ITEMS),
925
+ acceptanceCriteria,
926
+ outOfScope: strList(proposal.outOfScope).slice(0, MAX_LIST_ITEMS),
927
+ series: null,
928
+ },
929
+ },
930
+ mintAuthority: MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK,
931
+ });
932
+ } catch (e) {
933
+ return bad(500, `could not open the reply fallback session: ${e.message}`);
934
+ }
935
+
936
+ try {
937
+ audit('epic_cross_project_reply_fallback', {
938
+ cwd: toCwd,
939
+ epicId: minted.epicId,
940
+ replyOf,
941
+ fromCwd,
942
+ fromEpicId,
943
+ outcome,
944
+ reason,
945
+ title,
946
+ });
947
+ } catch { /* audit is best-effort */ }
948
+
949
+ return { ok: true, epicId: minted.epicId, toCwd, fromCwd, replyOf, reason, title, status: 'proposed' };
950
+ }
951
+
762
952
  /**
763
953
  * listFeedbackTargets() → { projects: [{ cwd, lastActivity }], scanned, truncated }
764
954
  *
@@ -903,8 +1093,11 @@ module.exports = {
903
1093
  isSessionManagerProject,
904
1094
  composeFeedbackIntake,
905
1095
  resolveOriginAsk,
1096
+ resolveReplyTo,
906
1097
  validateFeedbackInput,
907
1098
  openFeedbackSession,
1099
+ readEpicGoal,
1100
+ openReplyFallbackSession,
908
1101
  listFeedbackTargets,
909
1102
  registerAdminRoute,
910
1103
  };