claude-code-session-manager 0.135.1 → 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 (75) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/assets/{AgentLibrary-BBY7E1ag.js → AgentLibrary-BFztz90B.js} +1 -1
  3. package/dist/assets/{AppSettings-vMiIi0xn.js → AppSettings-6_dqi9Ti.js} +1 -1
  4. package/dist/assets/{Button-C0Z090Ui.js → Button-5wbUTtD5.js} +1 -1
  5. package/dist/assets/{DocumentEditorPane-Ds10W8SZ.js → DocumentEditorPane-CRgJFjka.js} +1 -1
  6. package/dist/assets/{Extensions-CjPiz2I5.js → Extensions-ZXSJbnK7.js} +2 -2
  7. package/dist/assets/{History-Bm3KXXs1.js → History-CmSTZeiu.js} +1 -1
  8. package/dist/assets/{Library-D-khizDg.js → Library-DcTnW9kq.js} +1 -1
  9. package/dist/assets/{ListDetail-CJYpp8fW.js → ListDetail-BGsdNFiK.js} +1 -1
  10. package/dist/assets/{Panel-BHFGylfy.js → Panel-BR2PeMf6.js} +1 -1
  11. package/dist/assets/{ProjectClaudeConfig-DIzNAala.js → ProjectClaudeConfig-DJYcUU1G.js} +1 -1
  12. package/dist/assets/{ProvenanceBadge-CYryeTYF.js → ProvenanceBadge-B_TDAI3k.js} +1 -1
  13. package/dist/assets/{Scheduler-BS82wfRP.js → Scheduler-DqocyumD.js} +1 -1
  14. package/dist/assets/{Settings-DWPHJ94d.js → Settings-BzPe2TH6.js} +1 -1
  15. package/dist/assets/{SkillReferenceGraph-Cf2M7YNq.js → SkillReferenceGraph-DfdO0Q_N.js} +1 -1
  16. package/dist/assets/{Skills-DLq55Odf.js → Skills-CGPJxKhR.js} +1 -1
  17. package/dist/assets/{SourceChip-CHxAzRlD.js → SourceChip-CI8xpHRi.js} +1 -1
  18. package/dist/assets/{SystemPrompt-BYtKMAr3.js → SystemPrompt-BbzGIHoz.js} +1 -1
  19. package/dist/assets/{TiptapBody-O_Gfq0Ha.js → TiptapBody-CTmjUhAI.js} +1 -1
  20. package/dist/assets/{Toggle-BJOUI5NY.js → Toggle-CWx9Rq6E.js} +1 -1
  21. package/dist/assets/{ViewTabs-kkvNGu-S.js → ViewTabs-BnjD0Crp.js} +1 -1
  22. package/dist/assets/{VoiceButton-3i-6ju2L.js → VoiceButton-C-iQGCL1.js} +1 -1
  23. package/dist/assets/{historyTotals-CHrIptK1.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 +2 -0
  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 +23 -0
  43. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +9 -0
  44. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +5 -2
  45. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +100 -5
  46. package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +52 -3
  47. package/scripts/scheduler-mcp-server.cjs +65 -5
  48. package/src/main/build-info.json +4 -4
  49. package/src/main/chatRunner.cjs +26 -2
  50. package/src/main/index.cjs +4 -0
  51. package/src/main/ipcSchemas.cjs +13 -0
  52. package/src/main/lib/claude/agentModelResolve.cjs +23 -0
  53. package/src/main/lib/epic/epicMint.cjs +12 -6
  54. package/src/main/lib/epic/promptSessionsCreateEpic.cjs +8 -4
  55. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +201 -8
  56. package/src/main/lib/feedback-remote/crossProjectReply.cjs +375 -0
  57. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
  58. package/src/main/lib/mcpToolCatalog.cjs +38 -4
  59. package/src/main/lib/mdNetworkScan.cjs +61 -11
  60. package/src/main/lib/mdReviewRecord.cjs +287 -0
  61. package/src/main/lib/packs/packCatalog.cjs +120 -0
  62. package/src/main/lib/packs/packSpawnArgs.cjs +59 -0
  63. package/src/main/lib/packs/packsIpc.cjs +76 -0
  64. package/src/main/lib/persona-macro/builtinMacros.cjs +3 -2
  65. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  66. package/src/main/lib/prd/prdCreate.cjs +2 -2
  67. package/src/main/lib/promptSessionSchema.cjs +8 -0
  68. package/src/main/projectPages.cjs +19 -0
  69. package/src/main/promptSessionEvents.cjs +8 -1
  70. package/src/main/scheduler.cjs +23 -2
  71. package/src/preload/api.d.ts +71 -0
  72. package/src/preload/apiSurface.json +21 -0
  73. package/src/preload/index.cjs +7 -0
  74. package/src/seed/agents/demo-video-builder.md +5 -3
  75. package/dist/assets/index-D9qgN9_V.js +0 -3116
@@ -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
 
@@ -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',
@@ -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
  };