claude-code-session-manager 0.137.0 → 0.139.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 (101) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +339 -82
  3. package/dist/assets/{AppSettings-l7NTc0yu.js → AppSettings-CUfWY9vN.js} +2 -2
  4. package/dist/assets/History-DDnqaLyw.js +2 -0
  5. package/dist/assets/HomeClaudeConfig-CGD2Onjv.js +3 -0
  6. package/dist/assets/{Panel-BuInRmA0.js → Panel-Csyd9HbD.js} +1 -1
  7. package/dist/assets/ProjectClaudeConfig-C-jlYpC_.js +26 -0
  8. package/dist/assets/{Scheduler-B7sn2mUw.js → Scheduler-NLs08fx7.js} +9 -9
  9. package/dist/assets/{SkillReferenceGraph-DwV0Ueyc.js → SkillReferenceGraph-DcscPXAG.js} +1 -1
  10. package/dist/assets/Skills-BpGRKOcY.js +67 -0
  11. package/dist/assets/{TiptapBody-Bl8hDhhS.js → TiptapBody-DSU3769X.js} +60 -54
  12. package/dist/assets/ViewTabs-C0PRZx4_.js +1 -0
  13. package/dist/assets/{VoiceButton-DJx-jY4r.js → VoiceButton-D2rMurNg.js} +1 -1
  14. package/dist/assets/{historyTotals-Cgjm5q24.js → historyTotals-TcIQs2sh.js} +1 -1
  15. package/dist/assets/{index-62tyjEQB.css → index-BCySPdtU.css} +1 -1
  16. package/dist/assets/index-C-d0DCre.js +3124 -0
  17. package/dist/index.html +2 -2
  18. package/dist-web/app.css +1 -1
  19. package/dist-web/app.js +471 -452
  20. package/package.json +13 -5
  21. package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
  22. package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
  23. package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
  24. package/plugins/session-manager-dev/skills/develop/SKILL.md +12 -5
  25. package/scripts/README.md +1 -0
  26. package/scripts/scheduler-mcp-server.cjs +161 -18
  27. package/src/main/build-info.json +4 -4
  28. package/src/main/chatRunner.cjs +53 -2
  29. package/src/main/exchanges.cjs +70 -5
  30. package/src/main/historyAggregator.cjs +84 -58
  31. package/src/main/historyDashboard.cjs +18 -13
  32. package/src/main/index.cjs +35 -9
  33. package/src/main/ipcSchemas.cjs +133 -5
  34. package/src/main/lib/claude/effectiveModelInfo.cjs +2 -2
  35. package/src/main/lib/claude/modelPricing.cjs +148 -0
  36. package/src/main/lib/demo-video-kit/checks.cjs +16 -0
  37. package/src/main/lib/epic/epicAdminRoutes.cjs +101 -0
  38. package/src/main/lib/epic/epicAttachments.cjs +143 -0
  39. package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
  40. package/src/main/lib/epic/epicMint.cjs +4 -0
  41. package/src/main/lib/epic/epicOutsideRead.cjs +306 -0
  42. package/src/main/lib/epic/epicOutsideState.cjs +233 -0
  43. package/src/main/lib/epic/epicSettle.cjs +1 -1
  44. package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
  45. package/src/main/lib/epic/externalRef.cjs +37 -0
  46. package/src/main/lib/epic/externalRefIndex.cjs +136 -0
  47. package/src/main/lib/epic/restorableSessions.cjs +151 -17
  48. package/src/main/lib/epic/transcriptUsage.cjs +197 -0
  49. package/src/main/lib/externalContract.cjs +111 -0
  50. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +121 -4
  51. package/src/main/lib/feedback-remote/crossProjectReply.cjs +83 -1
  52. package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
  53. package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
  54. package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
  55. package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
  56. package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
  57. package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
  58. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +287 -1
  59. package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
  60. package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
  61. package/src/main/lib/feedback-remote/needsYouStore.cjs +281 -0
  62. package/src/main/lib/feedback-remote/remoteFrameAssembler.cjs +113 -0
  63. package/src/main/lib/historyRollup.cjs +32 -5
  64. package/src/main/lib/mcpToolCatalog.cjs +111 -14
  65. package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
  66. package/src/main/lib/persona-macro/macroLibrary.cjs +7 -0
  67. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
  68. package/src/main/lib/process/bootStdioGuard.cjs +32 -0
  69. package/src/main/lib/process/stdioGuard.cjs +115 -0
  70. package/src/main/lib/promptSessionSchema.cjs +4 -0
  71. package/src/main/lib/remoteTranscriptTail.cjs +32 -1
  72. package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
  73. package/src/main/lib/telemetry/auditEvents.cjs +176 -0
  74. package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
  75. package/src/main/loopEfficiencyHandlers.cjs +1 -1
  76. package/src/main/scheduler.cjs +29 -0
  77. package/src/main/templates/PRD_AUTHORING.md +1 -0
  78. package/src/main/transcripts.cjs +62 -7
  79. package/src/main/webRemote.cjs +122 -18
  80. package/src/preload/api.d.ts +98 -9
  81. package/src/preload/apiSurface.cjs +7 -0
  82. package/src/preload/apiSurface.json +415 -83
  83. package/src/preload/index.cjs +17 -3
  84. package/src/seed/agents/demo-video-builder.md +10 -7
  85. package/dist/assets/AgentLibrary-DV0DTZDC.js +0 -2
  86. package/dist/assets/Button-Cmfkgjfa.js +0 -1
  87. package/dist/assets/DocumentEditorPane-MTljV-Uw.js +0 -1
  88. package/dist/assets/Extensions-Cc1Q_8id.js +0 -2
  89. package/dist/assets/History-CFo-1DHo.js +0 -2
  90. package/dist/assets/Library-C_ibFiOx.js +0 -32
  91. package/dist/assets/ListDetail-ByULG209.js +0 -1
  92. package/dist/assets/ProjectClaudeConfig-yqqVtHY7.js +0 -25
  93. package/dist/assets/ProvenanceBadge-CJvnQReI.js +0 -1
  94. package/dist/assets/Settings-DRRSJksU.js +0 -2
  95. package/dist/assets/Skills-DVYHA9gV.js +0 -29
  96. package/dist/assets/SourceChip-DfJ5_5rV.js +0 -1
  97. package/dist/assets/SystemPrompt-f11wGllK.js +0 -1
  98. package/dist/assets/Toggle-DaxeFDFp.js +0 -1
  99. package/dist/assets/ViewTabs-DRtgFKRw.js +0 -1
  100. package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
  101. package/dist/assets/index-iQ6pdyuS.js +0 -3116
@@ -25,7 +25,12 @@
25
25
  * macro_delete({ id }) -> POST /admin/macros/delete
26
26
  * customer_feedback_list({ pull?, includeHidden? }) -> GET /admin/customer-feedback/inbox
27
27
  * customer_feedback_set_status({ id, status, note? }) -> POST /admin/customer-feedback/status
28
- * customer_feedback_submit({ title, body, tag }) -> POST /admin/customer-feedback/submit
28
+ * customer_feedback_submit({ goal, description, tag, imagePaths? }) -> POST /admin/customer-feedback/submit
29
+ *
30
+ * epic_list({ cwd, state?, limit?, offset? }) -> GET /admin/epics?cwd=<encoded>&...
31
+ * epic_get({ cwd, id? | externalRef?, receipt? }) -> GET /admin/epic?cwd=<encoded>&(id|externalRef)=...[&receipt=1]
32
+ *
33
+ * agent_list({ cwd? }) -> GET /admin/agents[?cwd=<encoded>]
29
34
  *
30
35
  * This is a separate process from the Electron app — it only ever reaches
31
36
  * it over the token-authed loopback HTTP API in admin-api.json, never by
@@ -46,6 +51,7 @@ const fsp = require('node:fs/promises');
46
51
  const { createStdioServer } = require('../src/main/lib/mcpStdioServer.cjs');
47
52
  const { PRD_WORK_TYPES } = require('../src/main/lib/prd/workTypeLibrary.cjs');
48
53
  const { MCP_TOOL_CATALOG, MCP_RECIPES, composeDescription } = require('../src/main/lib/mcpToolCatalog.cjs');
54
+ const { EPIC_OUTSIDE_STATES } = require('../src/main/lib/epic/epicOutsideState.cjs');
49
55
 
50
56
  const CATALOG_BY_NAME = new Map(MCP_TOOL_CATALOG.map((entry) => [entry.name, entry]));
51
57
 
@@ -168,12 +174,34 @@ function resolveCwdArg(args) {
168
174
  return process.env.SM_PROJECT_ROOT || process.cwd();
169
175
  }
170
176
 
171
- // This server is registered from a checkout that can be newer than the
172
- // running app; its version goes into the version-skew message below.
177
+ // This server's package.json version. When it runs from a source checkout
178
+ // that number does not identify the code (the checkout can be far past the
179
+ // release it names), so the unknown-route message below never treats it as
180
+ // proof that a restart helps.
173
181
  const MCP_SERVER_VERSION = (() => {
174
182
  try { return require('../package.json').version; } catch { return 'unknown'; }
175
183
  })();
176
184
 
185
+ // True when the package root holding this script has a .git entry (a folder
186
+ // in a clone, a file in a git worktree). Existence check only; no git spawn.
187
+ const MCP_SERVER_FROM_CHECKOUT = (() => {
188
+ try { return require('node:fs').existsSync(path.join(__dirname, '..', '.git')); } catch { return false; }
189
+ })();
190
+
191
+ // Numeric compare of dotted versions; anything after a hyphen is ignored.
192
+ // Returns <0, 0 or >0, or NaN when either side has no usable number.
193
+ function compareVersions(a, b) {
194
+ const parse = (v) => String(v).split('-')[0].split('.').map((n) => Number(n));
195
+ const pa = parse(a);
196
+ const pb = parse(b);
197
+ if (pa.some(Number.isNaN) || pb.some(Number.isNaN)) return NaN;
198
+ for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
199
+ const d = (pa[i] || 0) - (pb[i] || 0);
200
+ if (d !== 0) return d;
201
+ }
202
+ return 0;
203
+ }
204
+
177
205
  // The transport's own unknown-route 404 (localAdminHttp handleRequest). Apps
178
206
  // up to v0.136.2 send exactly { ok:false, error:'not found' }; newer ones add
179
207
  // unknownRoute. Route handlers' own 'not found' replies use HTTP 200
@@ -185,15 +213,31 @@ function isUnknownRouteReply(status, body) {
185
213
  return Object.keys(body).length === 2 && body.error === 'not found';
186
214
  }
187
215
 
216
+ // Pure: states only what is known, and picks the advice from evidence.
217
+ function unknownRouteMessage({ method, pathname, appVersion, serverVersion, fromCheckout }) {
218
+ const appLabel = appVersion ? `v${appVersion}` : 'version not reported';
219
+ const head = `the running Session Manager app (${appLabel}) has no route ${method} ${pathname}. `
220
+ + `This MCP server is v${serverVersion}.`;
221
+ if (fromCheckout) {
222
+ return `${head} This MCP server runs from a source checkout, so its version number does not say which code it has. `
223
+ + 'The route may not be in any published release yet. '
224
+ + 'Restarting the app helps only once a release containing this route is installed.';
225
+ }
226
+ const cmp = appVersion ? compareVersions(appVersion, serverVersion) : -1;
227
+ if (!appVersion || cmp < 0) {
228
+ return `${head} The app is older than this MCP server. `
229
+ + "Restart Session Manager (Command Palette: 'Reboot app (drain first)') and call again.";
230
+ }
231
+ return `${head} A restart alone will not help. `
232
+ + 'Session Manager must be updated to a build that has this route.';
233
+ }
234
+
188
235
  function unknownRouteError(method, urlPath, body) {
189
236
  const pathname = String(urlPath).split('?')[0];
190
- const appVersion = body && typeof body.appVersion === 'string' && body.appVersion
191
- ? ` (running app: v${body.appVersion})` : '';
192
- const err = new Error(
193
- `the running Session Manager app has no route ${method} ${pathname}: the app${appVersion} is older than `
194
- + `this MCP server (v${MCP_SERVER_VERSION}). Restart Session Manager (Command Palette: 'Reboot app (drain first)') `
195
- + 'and call again.',
196
- );
237
+ const appVersion = body && typeof body.appVersion === 'string' && body.appVersion ? body.appVersion : null;
238
+ const err = new Error(unknownRouteMessage({
239
+ method, pathname, appVersion, serverVersion: MCP_SERVER_VERSION, fromCheckout: MCP_SERVER_FROM_CHECKOUT,
240
+ }));
197
241
  // Tagged so callers can add a tool-specific hint (feedback_reply does).
198
242
  err.code = 'SM_UNKNOWN_ROUTE';
199
243
  return err;
@@ -392,6 +436,44 @@ const TOOLS = [
392
436
  },
393
437
  },
394
438
  },
439
+ {
440
+ name: 'epic_list',
441
+ description: descriptionFor('epic_list'),
442
+ inputSchema: {
443
+ type: 'object',
444
+ properties: {
445
+ cwd: { type: 'string', description: 'Absolute path of the project whose open Epics to list' },
446
+ state: { type: 'string', enum: [...EPIC_OUTSIDE_STATES], description: 'Optional: only Epics in this outside-facing state' },
447
+ limit: { type: 'number', description: 'Optional: page size, default 50, max 200' },
448
+ offset: { type: 'number', description: 'Optional: page offset, default 0' },
449
+ },
450
+ required: ['cwd'],
451
+ },
452
+ },
453
+ {
454
+ name: 'agent_list',
455
+ description: descriptionFor('agent_list'),
456
+ inputSchema: {
457
+ type: 'object',
458
+ properties: {
459
+ cwd: { type: 'string', description: "Optional: absolute project path; when given, each agent also carries the model and effort it resolves to there" },
460
+ },
461
+ },
462
+ },
463
+ {
464
+ name: 'epic_get',
465
+ description: descriptionFor('epic_get'),
466
+ inputSchema: {
467
+ type: 'object',
468
+ properties: {
469
+ cwd: { type: 'string', description: 'Absolute path of the project the Epic belongs to' },
470
+ id: { type: 'string', description: 'The Epic id. Give exactly one of id / externalRef.' },
471
+ externalRef: { type: 'string', description: 'The external reference the Epic was opened with. Give exactly one of id / externalRef.' },
472
+ receipt: { type: 'boolean', description: 'Optional: when true, the answer also carries epic.receipt, what the Epic cost in jobs and chat.' },
473
+ },
474
+ required: ['cwd'],
475
+ },
476
+ },
395
477
  {
396
478
  name: 'scheduler_get_prd',
397
479
  description: descriptionFor('scheduler_get_prd'),
@@ -569,6 +651,15 @@ const TOOLS = [
569
651
  type: 'string',
570
652
  description: "Required with autoStart. Copy VERBATIM from the human's own message in this conversation; the quoted words themselves must name the target project. Do not paraphrase or write it yourself.",
571
653
  },
654
+ externalRef: {
655
+ type: 'string',
656
+ description: 'Optional: your own id for this handoff, 1 to 200 characters of letters, digits or . _ : / @ - (trimmed). It is stored on the new session and returned. Repeating a call with the same toCwd, fromCwd and externalRef opens nothing new and returns the session that already exists (status "existing", existing: true); the same externalRef already used by a different sender is refused with 409.',
657
+ },
658
+ replyMode: {
659
+ type: 'string',
660
+ enum: ['prompt', 'event'],
661
+ description: "Optional: how a reply comes back — 'prompt' (default) wakes your chat session, 'event' records it as data in the audit log for a caller with no chat.",
662
+ },
572
663
  },
573
664
  required: ['toCwd', 'fromCwd', 'title', 'motivation', 'acceptanceCriteria', 'body'],
574
665
  },
@@ -781,11 +872,17 @@ const TOOLS = [
781
872
  inputSchema: {
782
873
  type: 'object',
783
874
  properties: {
784
- title: { type: 'string', description: 'Short title, max 120 chars. Show it to the human before calling.' },
785
- body: { type: 'string', description: 'Feedback text, max 4000 chars. No secrets, tokens, customer data or private file contents.' },
875
+ goal: { type: 'string', description: 'One line, max 120 chars: what the human wants or what went wrong. Show it to the human before calling.' },
876
+ description: { type: 'string', description: 'Details, max 4000 chars: what happened, what was expected, steps. No secrets, tokens, customer data or private file contents.' },
786
877
  tag: { type: 'string', enum: ['bug', 'feature', 'discussion'], description: 'Kind of feedback.' },
878
+ imagePaths: {
879
+ type: 'array',
880
+ items: { type: 'string' },
881
+ maxItems: 5,
882
+ description: 'Optional: absolute paths of up to 5 PNG, JPEG, WebP or GIF images the human asked to include — for example the Attached: <path> lines of images pasted into this chat. Images are sent as-is; large PNG/JPEG are downscaled; anything that is not an image is refused.',
883
+ },
787
884
  },
788
- required: ['title', 'body', 'tag'],
885
+ required: ['goal', 'description', 'tag'],
789
886
  },
790
887
  },
791
888
  {
@@ -851,7 +948,7 @@ function macroDeleteRefusal() {
851
948
  function customerFeedbackSubmitRefusal() {
852
949
  return humanSessionRefusal(
853
950
  'refused: customer_feedback_submit runs only in a Session Manager chat or terminal session, because feedback is sent only when a human asks. '
854
- + 'Say in your final result what the feedback is; the human can send it from the {F} feedback panel.',
951
+ + 'Say in your final result what the feedback is; the human can send it from the Feedback panel.',
855
952
  );
856
953
  }
857
954
 
@@ -937,6 +1034,41 @@ async function handleCallTool(request) {
937
1034
  }
938
1035
  return { content: [{ type: 'text', text: JSON.stringify(result) }] };
939
1036
  }
1037
+ if (name === 'epic_list') {
1038
+ const qs = new URLSearchParams();
1039
+ if (args?.cwd) qs.set('cwd', args.cwd);
1040
+ if (args?.state) qs.set('state', args.state);
1041
+ if (args?.limit !== undefined) qs.set('limit', String(args.limit));
1042
+ if (args?.offset !== undefined) qs.set('offset', String(args.offset));
1043
+ const result = await adminRequest('GET', `/admin/epics?${qs.toString()}`);
1044
+ // Same partial-page guard as scheduler_list_prds: never let a page pass
1045
+ // for the full list.
1046
+ if (result?.ok && result.hasMore) {
1047
+ result.note = `partial list: returned ${result.epics.length} of ${result.total} Epics (offset ${result.offset}, limit ${result.limit}) — pass a higher offset to see more`;
1048
+ }
1049
+ return { content: [{ type: 'text', text: JSON.stringify(result) }] };
1050
+ }
1051
+ if (name === 'agent_list') {
1052
+ const qs = new URLSearchParams();
1053
+ if (args?.cwd) qs.set('cwd', args.cwd);
1054
+ const suffix = qs.toString() ? `?${qs.toString()}` : '';
1055
+ const result = await adminRequest('GET', `/admin/agents${suffix}`);
1056
+ return { content: [{ type: 'text', text: JSON.stringify(result) }] };
1057
+ }
1058
+ if (name === 'epic_get') {
1059
+ const hasId = typeof args?.id === 'string' && args.id !== '';
1060
+ const hasRef = typeof args?.externalRef === 'string' && args.externalRef !== '';
1061
+ if (hasId === hasRef) {
1062
+ return errorResult('provide exactly one of id or externalRef');
1063
+ }
1064
+ const qs = new URLSearchParams();
1065
+ if (args?.cwd) qs.set('cwd', args.cwd);
1066
+ if (hasId) qs.set('id', args.id);
1067
+ else qs.set('externalRef', args.externalRef);
1068
+ if (args?.receipt === true) qs.set('receipt', '1');
1069
+ const result = await adminRequest('GET', `/admin/epic?${qs.toString()}`);
1070
+ return { content: [{ type: 'text', text: JSON.stringify(result) }] };
1071
+ }
940
1072
  if (name === 'scheduler_get_prd') {
941
1073
  const slug = args && typeof args.slug === 'string' ? args.slug : null;
942
1074
  if (!slug) {
@@ -1139,6 +1271,8 @@ async function handleCallTool(request) {
1139
1271
  if (result?.ok !== false) {
1140
1272
  if (result?.delivery === 'delivered') {
1141
1273
  note = ' — delivered into the asking session; it has not acted on it yet.';
1274
+ } else if (result?.delivery === 'event-only' && result?.reason === 'asker-requested-event') {
1275
+ note = ' — the answer was recorded as an event for the asking app, as it requested; no chat was prompted.';
1142
1276
  } else if (result?.delivery === 'event-only') {
1143
1277
  note = " — delivered as an event only on the asking Epic; its session was not prompted"
1144
1278
  + `${result.reason ? ` (${result.reason})` : ''}.`;
@@ -1319,10 +1453,17 @@ async function handleCallTool(request) {
1319
1453
  if (name === 'customer_feedback_submit') {
1320
1454
  const refusal = customerFeedbackSubmitRefusal();
1321
1455
  if (refusal) return refusal;
1322
- if (!args || typeof args.title !== 'string' || typeof args.body !== 'string' || typeof args.tag !== 'string') {
1323
- return errorResult('missing or invalid required argument(s): title, body, tag');
1456
+ if (!args || typeof args.goal !== 'string' || typeof args.description !== 'string' || typeof args.tag !== 'string') {
1457
+ return errorResult('missing or invalid required argument(s): goal, description, tag');
1458
+ }
1459
+ const imagePaths = args.imagePaths;
1460
+ if (imagePaths !== undefined
1461
+ && (!Array.isArray(imagePaths) || imagePaths.length > 5 || !imagePaths.every((p) => typeof p === 'string'))) {
1462
+ return errorResult('invalid argument: imagePaths must be an array of at most 5 absolute file path strings');
1324
1463
  }
1325
- const result = await adminRequest('POST', '/admin/customer-feedback/submit', { title: args.title, body: args.body, tag: args.tag });
1464
+ const payload = { title: args.goal, body: args.description, tag: args.tag };
1465
+ if (imagePaths && imagePaths.length > 0) payload.imagePaths = imagePaths;
1466
+ const result = await adminRequest('POST', '/admin/customer-feedback/submit', payload);
1326
1467
  if (result?.ok === false) return errorResult(result.error ?? 'customer_feedback_submit failed');
1327
1468
  return { content: [{ type: 'text', text: JSON.stringify(result) }] };
1328
1469
  }
@@ -1388,4 +1529,6 @@ if (require.main === module) {
1388
1529
  });
1389
1530
  }
1390
1531
 
1391
- module.exports = { TOOLS, handleCallTool, HELP_POINTER, NOT_RUNNING_ERROR, busyError };
1532
+ module.exports = {
1533
+ TOOLS, handleCallTool, HELP_POINTER, NOT_RUNNING_ERROR, busyError, unknownRouteMessage, compareVersions,
1534
+ };
@@ -1,8 +1,8 @@
1
1
  {
2
- "version": "0.137.0",
3
- "gitSha": "2ec9176d21aa5c815cbf59feeb935924dcb3342e",
4
- "gitShortSha": "2ec9176d",
2
+ "version": "0.139.0",
3
+ "gitSha": "ca86eb20ac810d686da85bf23356b2e8a9ae86a8",
4
+ "gitShortSha": "ca86eb20",
5
5
  "gitBranch": "HEAD",
6
- "builtAt": "2026-11-19T18:18:31.246Z",
6
+ "builtAt": "2026-11-22T16:17:18.856Z",
7
7
  "dirty": false
8
8
  }
@@ -40,7 +40,7 @@ const { spawn } = require('node:child_process');
40
40
  const { ipcMain } = require('electron');
41
41
  const { resolveClaudeBin, claudeSpawnTarget } = require('./lib/claude/claudeBin.cjs');
42
42
  const { cleanChildEnv, pathWithUserBins } = require('./lib/process/cleanEnv.cjs');
43
- const { recordExchange } = require('./exchanges.cjs');
43
+ const { recordExchange, formatAskedResult } = require('./exchanges.cjs');
44
44
  const { classifyToolUse } = require('./lib/toolUseClassify.cjs');
45
45
  const { extractJson } = require('./lib/util/extractJson.cjs');
46
46
  const { classifyPromptTicket } = require('./lib/classifyPromptTicket.cjs');
@@ -939,7 +939,7 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
939
939
  sessionId,
940
940
  cwd,
941
941
  prompt,
942
- result: `${signal.answerBody}\n\n[asked: ${signal.questions.join(' | ')}]`,
942
+ result: formatAskedResult(signal.answerBody, signal.questions),
943
943
  promptId,
944
944
  }).catch((err) => {
945
945
  console.error('[chatRunner] recordExchange failed:', err?.message ?? err);
@@ -1219,6 +1219,49 @@ function requestExternalNewSession(payload) {
1219
1219
  broadcast('chat:external-new-session', payload);
1220
1220
  }
1221
1221
 
1222
+ // Awaited sibling of requestExternalNewSession for the admin route
1223
+ // (POST /admin/macros/run): tags the payload with a requestId and resolves
1224
+ // once the renderer reports which Epic it minted. Never rejects.
1225
+ const EXTERNAL_NEW_SESSION_TIMEOUT_MS = 30000;
1226
+ const pendingExternalNewSessions = new Map(); // requestId -> { resolve, timer }
1227
+
1228
+ /**
1229
+ * @returns {Promise<{ ok: true, epicId: string } | { ok: false, reason: 'no-window'|'timeout'|'launch-failed', error: string }>}
1230
+ */
1231
+ function startExternalNewSession(payload) {
1232
+ if (!hasLiveWindow()) {
1233
+ return Promise.resolve({ ok: false, reason: 'no-window', error: 'Session Manager window is not open' });
1234
+ }
1235
+ const requestId = require('node:crypto').randomUUID();
1236
+ return new Promise((resolve) => {
1237
+ const timer = setTimeout(() => {
1238
+ pendingExternalNewSessions.delete(requestId);
1239
+ resolve({ ok: false, reason: 'timeout', error: 'renderer did not report the new session in time' });
1240
+ }, EXTERNAL_NEW_SESSION_TIMEOUT_MS);
1241
+ timer.unref?.();
1242
+ pendingExternalNewSessions.set(requestId, { resolve, timer });
1243
+ broadcast('chat:external-new-session', { ...payload, requestId });
1244
+ });
1245
+ }
1246
+
1247
+ function settleExternalNewSession({ requestId, ok, epicId, error }) {
1248
+ const entry = pendingExternalNewSessions.get(requestId);
1249
+ if (!entry) return;
1250
+ clearTimeout(entry.timer);
1251
+ pendingExternalNewSessions.delete(requestId);
1252
+ if (ok && epicId) entry.resolve({ ok: true, epicId });
1253
+ else entry.resolve({ ok: false, reason: 'launch-failed', error: error || 'renderer could not start the session' });
1254
+ }
1255
+
1256
+ // Read-only: is a chat turn for this tab running, being dispatched, parked
1257
+ // behind a worktree mint, or queued?
1258
+ function isTabBusy(tabId) {
1259
+ return inFlight.has(tabId)
1260
+ || dispatching.has(tabId)
1261
+ || pendingStart.has(tabId)
1262
+ || waiting.some((w) => w.tabId === tabId);
1263
+ }
1264
+
1222
1265
  /**
1223
1266
  * Registers the admin-HTTP entry point for enqueueExternalPrompt, mirroring
1224
1267
  * prdCreate.cjs's registerAdminRoute pattern (auth is the injected transport's
@@ -1294,6 +1337,10 @@ function registerChatHandlers() {
1294
1337
  settleExternalSend(payload);
1295
1338
  }));
1296
1339
 
1340
+ ipcMain.handle('chat:external-new-session-result', validated(schemas.chatExternalNewSessionResult, async (payload) => {
1341
+ settleExternalNewSession(payload);
1342
+ }));
1343
+
1297
1344
  ipcMain.handle('chat:cancel', async (_e, payload) => {
1298
1345
  let tabId;
1299
1346
  try { tabId = schemas.chatCancel.parse(payload).tabId; } catch { return; }
@@ -1332,5 +1379,9 @@ module.exports = {
1332
1379
  settleExternalSend,
1333
1380
  EXTERNAL_SEND_ACK_TIMEOUT_MS,
1334
1381
  requestExternalNewSession,
1382
+ startExternalNewSession,
1383
+ settleExternalNewSession,
1384
+ isTabBusy,
1385
+ EXTERNAL_NEW_SESSION_TIMEOUT_MS,
1335
1386
  registerAdminRoute,
1336
1387
  };
@@ -78,13 +78,13 @@ const MAX_TAIL_BYTES = 8 * 1024 * 1024;
78
78
  const DEFAULT_LIMIT = 100;
79
79
 
80
80
  /**
81
- * Read exchanges for a project, newest-first. Bounded to MAX_TAIL_BYTES from
82
- * the end of the file so large logs never block the main thread.
81
+ * Parse the last MAX_TAIL_BYTES of the project's exchanges.jsonl into records,
82
+ * oldest-first. Missing/unreadable file → []. Malformed lines are skipped.
83
83
  *
84
- * @param {{ cwd: string, sessionId?: string, limit?: number, offset?: number }}
84
+ * @param {string} cwd
85
85
  * @returns {Promise<object[]>}
86
86
  */
87
- async function listExchanges({ cwd, sessionId, limit = DEFAULT_LIMIT, offset = 0 }) {
87
+ async function readTailRecords(cwd) {
88
88
  const filePath = exchangesFilePath(cwd);
89
89
 
90
90
  let stat;
@@ -122,6 +122,18 @@ async function listExchanges({ cwd, sessionId, limit = DEFAULT_LIMIT, offset = 0
122
122
  if (rec && typeof rec.ts === 'string') records.push(rec);
123
123
  } catch { /* skip malformed */ }
124
124
  }
125
+ return records;
126
+ }
127
+
128
+ /**
129
+ * Read exchanges for a project, newest-first. Bounded to MAX_TAIL_BYTES from
130
+ * the end of the file so large logs never block the main thread.
131
+ *
132
+ * @param {{ cwd: string, sessionId?: string, limit?: number, offset?: number }}
133
+ * @returns {Promise<object[]>}
134
+ */
135
+ async function listExchanges({ cwd, sessionId, limit = DEFAULT_LIMIT, offset = 0 }) {
136
+ const records = await readTailRecords(cwd);
125
137
 
126
138
  // Newest-first
127
139
  records.reverse();
@@ -133,4 +145,57 @@ async function listExchanges({ cwd, sessionId, limit = DEFAULT_LIMIT, offset = 0
133
145
  return filtered.slice(offset, offset + limit);
134
146
  }
135
147
 
136
- module.exports = { recordExchange, listExchanges };
148
+ // The needs-input marker. chatRunner.cjs records a turn that ended by asking
149
+ // the human questions as `<answerBody>\n\n[asked: q1 | q2]`; this is its one home.
150
+ const ASKED_PREFIX = '\n\n[asked: ';
151
+ const ASKED_SEPARATOR = ' | ';
152
+
153
+ /**
154
+ * Build the `result` string recorded for a needs-input turn.
155
+ *
156
+ * @param {string} answerBody
157
+ * @param {string[]} questions
158
+ * @returns {string}
159
+ */
160
+ function formatAskedResult(answerBody, questions) {
161
+ return `${answerBody}${ASKED_PREFIX}${questions.join(ASKED_SEPARATOR)}]`;
162
+ }
163
+
164
+ /**
165
+ * True only for a string that ends with the `[asked: ...]` marker block.
166
+ *
167
+ * @param {unknown} result
168
+ * @returns {boolean}
169
+ */
170
+ function resultAwaitsInput(result) {
171
+ if (typeof result !== 'string' || !result.endsWith(']')) return false;
172
+ const at = result.lastIndexOf(ASKED_PREFIX);
173
+ if (at === -1) return false;
174
+ // The marker block is a single line — nothing after it may start a new one.
175
+ return !result.slice(at + ASKED_PREFIX.length).includes('\n');
176
+ }
177
+
178
+ /**
179
+ * Sessions (Claude session ids) whose newest exchange in this project is still
180
+ * waiting for the human's answer. Reads at most MAX_TAIL_BYTES of the log.
181
+ *
182
+ * @param {string} cwd
183
+ * @returns {Promise<Set<string>>}
184
+ */
185
+ async function awaitingInputSessions(cwd) {
186
+ const waiting = new Set();
187
+ for (const rec of await readTailRecords(cwd)) {
188
+ if (typeof rec.sessionId !== 'string' || !rec.sessionId) continue;
189
+ if (resultAwaitsInput(rec.result)) waiting.add(rec.sessionId);
190
+ else waiting.delete(rec.sessionId);
191
+ }
192
+ return waiting;
193
+ }
194
+
195
+ module.exports = {
196
+ recordExchange,
197
+ listExchanges,
198
+ formatAskedResult,
199
+ resultAwaitsInput,
200
+ awaitingInputSessions,
201
+ };