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
@@ -585,11 +585,61 @@ const adminListPrdsQuery = z.object({
585
585
  fields: z.enum(['compact', 'full']).optional().default('compact'),
586
586
  });
587
587
 
588
+ // GET /admin/events (lib/telemetry/eventsAdminRoutes.cjs) — cursor read over the
589
+ // audit log. `after` is checked by readEventsAfter itself (the route maps its
590
+ // rejection to the same 400); `kinds` is a comma-separated list, each entry one
591
+ // of auditEvents.cjs's OUTSIDE_EVENT_KINDS; `limit` 1..500 (default applied by
592
+ // readEventsAfter when absent).
593
+ const OUTSIDE_EVENT_KIND_ENUM = z.enum(/** @type {[string, ...string[]]} */ ([...require('./lib/telemetry/auditEvents.cjs').OUTSIDE_EVENT_KINDS]));
594
+ const adminListEventsQuery = z.object({
595
+ after: z.string().max(200).optional(),
596
+ kinds: z.string().min(1).max(1000)
597
+ .transform((v) => v.split(',').map((k) => k.trim()))
598
+ .pipe(z.array(OUTSIDE_EVENT_KIND_ENUM).min(1))
599
+ .optional(),
600
+ limit: z.coerce.number().int().min(1).max(500).optional(),
601
+ });
602
+
588
603
  const adminGetPrdQuery = z.object({
589
604
  slug: z.string().regex(SCHEDULE_SLUG_RE),
590
605
  cwd: z.string().min(1).max(4096).optional(),
591
606
  });
592
607
 
608
+ // GET /admin/epics + /admin/epic (lib/epic/epicAdminRoutes.cjs) — read-only
609
+ // outside-facing Epic records (lib/epic/epicOutsideRead.cjs). Query strings
610
+ // arrive as text, so limit/offset coerce before the int/range checks.
611
+ const EPIC_OUTSIDE_STATE_ENUM = z.enum(/** @type {[string, ...string[]]} */ ([...require('./lib/epic/epicOutsideState.cjs').EPIC_OUTSIDE_STATES]));
612
+ const adminListEpicsQuery = z.object({
613
+ cwd: z.string().min(1).max(4096),
614
+ state: EPIC_OUTSIDE_STATE_ENUM.optional(),
615
+ limit: z.coerce.number().int().min(1).max(200).optional().default(50),
616
+ offset: z.coerce.number().int().min(0).optional().default(0),
617
+ });
618
+
619
+ // GET /admin/agents (lib/persona-macro/agentAdminRoutes.cjs) — read-only
620
+ // persona roster; an optional cwd adds each persona's effective model/effort.
621
+ const adminListAgentsQuery = z.object({
622
+ cwd: z.string().min(1).max(4096).optional(),
623
+ });
624
+
625
+ const adminGetEpicQuery = z.object({
626
+ cwd: z.string().min(1).max(4096),
627
+ id: z.string().min(1).max(200).optional(),
628
+ externalRef: z.string().max(1000).optional().transform((v, ctx) => {
629
+ if (v === undefined) return undefined;
630
+ const r = require('./lib/epic/externalRef.cjs').normalizeExternalRef(v);
631
+ if (!r.ok) {
632
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: r.error });
633
+ return z.NEVER;
634
+ }
635
+ return r.value;
636
+ }),
637
+ // Opt-in cost receipt: only the query values '1' and 'true' turn it on.
638
+ receipt: z.string().max(10).optional().transform((v) => v === '1' || v === 'true'),
639
+ }).refine((v) => (v.id === undefined) !== (v.externalRef === undefined), {
640
+ message: 'exactly one of id or externalRef is required',
641
+ });
642
+
593
643
  // Partial frontmatter patch for update-prd — same recognized-key set as
594
644
  // prdFrontmatter.cjs's parsePrdFile/serializePrdFile round-trip pair. Every
595
645
  // field optional; the route refuses an empty patch+no-body request via the
@@ -761,6 +811,14 @@ const macrosDispatchJob = z.object({
761
811
  effort: z.enum(/** @type {[string, ...string[]]} */ ([...PRD_EFFORT_LEVELS])).optional(),
762
812
  });
763
813
  const macrosJobStatus = z.object({ cwd: z.string().min(1).max(4096) });
814
+ // Dashboard "Needs you" (lib/feedback-remote/needsYouIpc.cjs): list takes no payload; answer
815
+ // names one item + the chosen option. needsYouStore.cjs re-validates app/id and the option.
816
+ const needsYouList = z.object({}).strict().optional();
817
+ const needsYouAnswer = z.object({
818
+ app: z.string().min(1).max(40),
819
+ id: z.string().min(1).max(200),
820
+ answer: z.string().min(1).max(80),
821
+ }).strict();
764
822
 
765
823
  // ──────────────────────────────────────────── Memory tool (Bundle C, cycle 3)
766
824
  // Workspace-scoped markdown store at ~/.claude/projects/<ws>/memory/.
@@ -824,7 +882,7 @@ const memoryStale = z.object({
824
882
  agent: MEMORY_AGENT,
825
883
  }).strict();
826
884
 
827
- // memory:verify/archive/restore/listArchived/ask/proposeFix — Memory Explorer actions.
885
+ // memory:verify/archive/restore/listArchived — Memory Explorer actions (ask/proposeFix wrap memoryNamed below).
828
886
  const memoryNamed = z.object({
829
887
  workspace: z.string().regex(MEMORY_WORKSPACE_RE).optional(),
830
888
  name: z.string().regex(MEMORY_SLUG_RE),
@@ -834,15 +892,38 @@ const memoryNamed = z.object({
834
892
  const memoryVerify = memoryNamed;
835
893
  const memoryArchive = memoryNamed;
836
894
  const memoryRestore = memoryNamed;
837
- const memoryProposeFix = memoryNamed;
838
895
  const memoryListArchived = memoryList;
839
- const memoryAsk = z.object({
896
+
897
+ // memory:ask / memory:proposeFix receive the renderer's raw single object
898
+ // ({ question|name, target, contextName? }) from BOTH the Electron preload and
899
+ // the relay remote (remoteApi.ts forwards positionally). Flatten `target`'s
900
+ // truthy addressing keys onto the top level (target wins) and drop a falsy
901
+ // contextName, so askMemory/proposeFix see the same flat payload as before.
902
+ // A target carrying any other key (or a non-object target) is left in place
903
+ // so the inner .strict() schema rejects it.
904
+ const MEMORY_TARGET_KEYS = ['workspace', 'cwd', 'agent'];
905
+ /** @param {unknown} input */
906
+ function flattenMemoryTarget(input) {
907
+ if (!input || typeof input !== 'object' || Array.isArray(input)) return input;
908
+ const { target, ...rest } = /** @type {Record<string, unknown>} */ (input);
909
+ if (!rest.contextName) delete rest.contextName;
910
+ if (target === undefined || target === null) return rest;
911
+ if (typeof target !== 'object' || Array.isArray(target)
912
+ || Object.keys(target).some((k) => !MEMORY_TARGET_KEYS.includes(k))) {
913
+ return { ...rest, target };
914
+ }
915
+ const t = /** @type {Record<string, unknown>} */ (target);
916
+ for (const k of MEMORY_TARGET_KEYS) if (t[k]) rest[k] = t[k];
917
+ return rest;
918
+ }
919
+ const memoryProposeFix = z.preprocess(flattenMemoryTarget, memoryNamed);
920
+ const memoryAsk = z.preprocess(flattenMemoryTarget, z.object({
840
921
  workspace: z.string().regex(MEMORY_WORKSPACE_RE).optional(),
841
922
  question: z.string().min(1).max(4000),
842
923
  contextName: z.string().regex(MEMORY_SLUG_RE).optional(),
843
924
  cwd: MEMORY_CWD,
844
925
  agent: MEMORY_AGENT,
845
- }).strict();
926
+ }).strict());
846
927
 
847
928
  const memoryAgents = z.object({
848
929
  cwd: MEMORY_CWD,
@@ -1086,7 +1167,7 @@ const epicDelegationStatsGet = z.object({
1086
1167
 
1087
1168
  // ──────────────────────────────────────────── Audit log (renderer Epic
1088
1169
  // lifecycle trace, PRD 940). Kind allowlist is enforced HERE, main-side — the
1089
- // renderer cannot write arbitrary kinds through this channel, only the six
1170
+ // renderer cannot write arbitrary kinds through this channel, only the
1090
1171
  // Epic lifecycle transitions it emits from promptSessions.ts.
1091
1172
  const AUDIT_LOG_KIND = z.enum([
1092
1173
  'epic_create',
@@ -1096,12 +1177,15 @@ const AUDIT_LOG_KIND = z.enum([
1096
1177
  'epic_resume',
1097
1178
  'epic_duplicate',
1098
1179
  'epic_draft_update',
1180
+ 'epic_continue',
1099
1181
  ]);
1100
1182
  const auditLogAppend = z.object({
1101
1183
  kind: AUDIT_LOG_KIND,
1102
1184
  cwd: z.string().min(1).max(4096),
1103
1185
  epicId: z.string().min(1).max(256),
1104
1186
  source: z.string().min(1).max(256),
1187
+ /** epic_continue only: the Epic the new session continues from. */
1188
+ fromEpicId: z.string().min(1).max(256).optional(),
1105
1189
  }).strict();
1106
1190
 
1107
1191
  // ──────────────────────────────────────────── Exchanges (PRD 324 read path)
@@ -1195,6 +1279,28 @@ const chatExternalSend = z.object({
1195
1279
  ),
1196
1280
  });
1197
1281
 
1282
+ // Phone remote's cmd:chat:send — chatExternalSend plus up to 6 images (saved
1283
+ // as Epic attachments by epicAttachments.cjs). Prompt may be empty when at
1284
+ // least one image is sent. Deep validation (magic bytes, decoded size) is
1285
+ // saveChatImages' job; this bounds the wire shape.
1286
+ const remoteChatImage = z.object({
1287
+ name: z.string().min(1).max(128),
1288
+ mime: z.enum(['image/png', 'image/jpeg', 'image/gif', 'image/webp']),
1289
+ data: z.string().min(1).max(4200000),
1290
+ });
1291
+
1292
+ const remoteChatSend = z.object({
1293
+ tabId: z.string().min(1).max(128),
1294
+ prompt: z.string().refine(
1295
+ (s) => Buffer.byteLength(s, 'utf8') <= CHAT_PROMPT_MAX_BYTES,
1296
+ `prompt must be ≤ ${CHAT_PROMPT_MAX_BYTES} bytes`,
1297
+ ),
1298
+ images: z.array(remoteChatImage).max(6).optional(),
1299
+ }).refine(
1300
+ (v) => v.prompt.trim().length > 0 || (Array.isArray(v.images) && v.images.length > 0),
1301
+ { message: 'prompt or at least one image is required', path: ['prompt'] },
1302
+ );
1303
+
1198
1304
  // Renderer's report of what it did with a `chat:external-send` (mirrors
1199
1305
  // ChatExternalSendResult in preload/api.d.ts).
1200
1306
  const chatExternalSendResult = z.object({
@@ -1203,6 +1309,16 @@ const chatExternalSendResult = z.object({
1203
1309
  reason: z.enum(['terminal-attached', 'completed', 'unknown-target', 'empty-prompt']).optional(),
1204
1310
  });
1205
1311
 
1312
+ // Renderer's report of what it did with a chat:external-new-session that
1313
+ // carried a requestId (POST /admin/macros/run). Mirrors
1314
+ // ChatExternalNewSessionResult in preload/api.d.ts.
1315
+ const chatExternalNewSessionResult = z.object({
1316
+ requestId: z.string().min(1).max(64),
1317
+ ok: z.boolean(),
1318
+ epicId: z.string().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9_.-]*$/).optional(),
1319
+ error: z.string().max(500).optional(),
1320
+ }).strict();
1321
+
1206
1322
  // Phone drill-down reads. cwd is re-checked against the open tabs in
1207
1323
  // webRemote.cjs; sessionKey becomes a transcript filename lookup so it is
1208
1324
  // restricted to a session-id charset (no '/', so no traversal).
@@ -1397,6 +1513,8 @@ const customerFeedbackSubmit = z.object({
1397
1513
  title: z.string().max(120),
1398
1514
  body: z.string().max(4000),
1399
1515
  tag: z.enum(['bug', 'feature', 'discussion']),
1516
+ images: z.array(z.object({ dataUrl: z.string().max(35_000_000) })).max(5).optional(),
1517
+ imagePaths: z.array(z.string().max(4096)).max(5).optional(),
1400
1518
  });
1401
1519
  const customerFeedbackMarkSeen = z.object({ ids: z.array(z.string().max(200)).max(500).optional() });
1402
1520
  const customerFeedbackInboxList = z.object({ includeHidden: z.boolean().optional() });
@@ -1406,6 +1524,7 @@ const customerFeedbackInboxSetStatus = z.object({
1406
1524
  note: z.string().max(500).optional(),
1407
1525
  });
1408
1526
  const customerFeedbackInboxLinkEpic = z.object({ id: z.string().max(200), epicId: z.string().max(200) });
1527
+ const customerFeedbackInboxImage = z.object({ id: z.string().min(1).max(200), index: z.number().int().min(0).max(4) }).strict();
1409
1528
 
1410
1529
  /**
1411
1530
  * Wrap an IPC handler with schema validation. Returns a new handler that
@@ -1539,7 +1658,11 @@ module.exports = {
1539
1658
  scheduleArchivePrd,
1540
1659
  scheduleRetagPrd,
1541
1660
  adminListPrdsQuery,
1661
+ adminListEventsQuery,
1542
1662
  adminGetPrdQuery,
1663
+ adminListEpicsQuery,
1664
+ adminGetEpicQuery,
1665
+ adminListAgentsQuery,
1543
1666
  adminUpdatePrd,
1544
1667
  adminCancelJob,
1545
1668
  setConfigSchema,
@@ -1620,7 +1743,9 @@ module.exports = {
1620
1743
  chatCancel,
1621
1744
  chatClassifyTicket,
1622
1745
  chatExternalSend,
1746
+ remoteChatSend,
1623
1747
  chatExternalSendResult,
1748
+ chatExternalNewSessionResult,
1624
1749
  remoteSessionCreate,
1625
1750
  remoteProjectSessions,
1626
1751
  remoteSessionTranscript,
@@ -1638,6 +1763,8 @@ module.exports = {
1638
1763
  macrosRemoveFromProject,
1639
1764
  macrosDispatchJob,
1640
1765
  macrosJobStatus,
1766
+ needsYouList,
1767
+ needsYouAnswer,
1641
1768
  agentsGetPersonaBody,
1642
1769
  agentsResolveModelInfo,
1643
1770
  modelsCatalog,
@@ -1651,6 +1778,7 @@ module.exports = {
1651
1778
  customerFeedbackInboxList,
1652
1779
  customerFeedbackInboxSetStatus,
1653
1780
  customerFeedbackInboxLinkEpic,
1781
+ customerFeedbackInboxImage,
1654
1782
  },
1655
1783
  validated,
1656
1784
  };
@@ -309,8 +309,8 @@ async function resolveEffectiveModelInfo({ cwd, agentType, deps = {} } = {}) {
309
309
  // Agentless: no per-agent evidence to look up (it would match every agentless job).
310
310
  if (!agentType) return result;
311
311
 
312
- // Evidence is never derived via historyAggregator.cjs's resolvePricingKey
313
- // (which buckets any unknown id to 'sonnet' with estimated:true) —
312
+ // Evidence is never derived via lib/claude/modelPricing.cjs's priceForModel
313
+ // (which prices any unknown id at a family fallback with estimated:true) —
314
314
  // deliberately: that is a pricing heuristic, and borrowing it here would
315
315
  // turn "we don't know" into a confident wrong answer.
316
316
  const schedulerHit = findLatestSchedulerModel(normalizedCwd, agentType, deps);
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * modelPricing.cjs — the current price of each Claude model id, and the dollar cost of one
5
+ * usage bucket. Pure: no I/O, no imports, never throws.
6
+ *
7
+ * Source: the `claude-api` skill's model and prompt-caching reference, cached 2026-11-03,
8
+ * read on 2026-11-21. Prices are dollars per million tokens.
9
+ *
10
+ * Cache writes cost CACHE_WRITE_5M_MULTIPLIER × input for the 5-minute cache and
11
+ * CACHE_WRITE_1H_MULTIPLIER × input for the 1-hour cache, on every model. Cache writes whose split
12
+ * is unknown (cacheCreationUnknownTokens, or all of them when cacheCreation1hTokens is absent) are
13
+ * charged at the 1-hour rate and the result is marked estimated: on 2026-11-21 this machine's last 48 hours of transcripts had 93.5% of
14
+ * cache-write tokens as 1-hour writes.
15
+ *
16
+ * Known limits, deliberately NOT modeled (on 2026-11-21 the last 48 hours of transcripts had no
17
+ * such call):
18
+ * 1. Claude Haiku 5.5 prompts over 100K tokens cost 0.50 / 2.50 (input / output), not the base rate.
19
+ * 2. Fast mode costs more than the rates below.
20
+ */
21
+
22
+ /** @typedef {{ input: number, output: number, cacheRead: number }} ModelPrice */
23
+
24
+ const row = (input, output, cacheRead) => Object.freeze({ input, output, cacheRead });
25
+
26
+ // cacheRead is stated outright by the reference for Fable 5.2, Fable 5.1, Fable 5, Opus 5.5 and
27
+ // Sonnet 5.5 (and their Mythos twins). Every other row's cacheRead is derived from the general
28
+ // rule, 0.1 × input: opus-5, opus-4-8, opus-4-7, opus-4-6, sonnet-5, sonnet-4-6, haiku-5-5, haiku-4-5.
29
+ const MODEL_PRICES = Object.freeze({
30
+ 'claude-fable-5-2': row(8, 40, 0.20),
31
+ 'claude-mythos-5-2': row(8, 40, 0.20),
32
+ 'claude-fable-5-1': row(10, 50, 0.25),
33
+ 'claude-mythos-5-1': row(10, 50, 0.25),
34
+ 'claude-fable-5': row(10, 50, 1.00),
35
+ 'claude-mythos-5': row(10, 50, 1.00),
36
+ 'claude-opus-5-5': row(4, 20, 0.20),
37
+ 'claude-opus-5': row(5, 25, 0.50),
38
+ 'claude-opus-4-8': row(5, 25, 0.50),
39
+ 'claude-opus-4-7': row(5, 25, 0.50),
40
+ 'claude-opus-4-6': row(5, 25, 0.50),
41
+ 'claude-sonnet-5-5': row(2, 10, 0.10),
42
+ 'claude-sonnet-5': row(2, 10, 0.20),
43
+ 'claude-sonnet-4-6': row(3, 15, 0.30),
44
+ 'claude-haiku-5-5': row(0.10, 0.50, 0.01),
45
+ 'claude-haiku-4-5': row(1, 5, 0.10),
46
+ });
47
+
48
+ const CACHE_WRITE_5M_MULTIPLIER = 1.25;
49
+ const CACHE_WRITE_1H_MULTIPLIER = 2;
50
+
51
+ // Newest row per family, used to price an id that matches no row. Order matters only in that the
52
+ // first family word found wins.
53
+ const FAMILY_FALLBACK = Object.freeze([
54
+ ['fable', 'claude-fable-5-2'],
55
+ ['mythos', 'claude-mythos-5-2'],
56
+ ['opus', 'claude-opus-5-5'],
57
+ ['sonnet', 'claude-sonnet-5-5'],
58
+ ['haiku', 'claude-haiku-5-5'],
59
+ ]);
60
+ const DEFAULT_ID = 'claude-sonnet-5-5';
61
+
62
+ // Bedrock-style provider prefixes: `anthropic.`, `us.anthropic.`, `global.anthropic.`, …
63
+ const PROVIDER_PREFIX_RE = /^(?:[a-z0-9-]+\.)*anthropic\./;
64
+ // What may follow a row id: a -YYYYMMDD date, a `[1m]`-style context tag, or a Vertex `@` version.
65
+ const ROW_CONTINUATION_RE = /^(?:-\d{8}(?!\d)|\[|@)/;
66
+
67
+ /**
68
+ * @param {string} rowId
69
+ * @param {boolean} estimated
70
+ */
71
+ function priced(rowId, estimated) {
72
+ const p = MODEL_PRICES[/** @type {keyof typeof MODEL_PRICES} */ (rowId)];
73
+ return { id: rowId, input: p.input, output: p.output, cacheRead: p.cacheRead, estimated };
74
+ }
75
+
76
+ /**
77
+ * @param {unknown} modelId
78
+ * @returns {{ id: string, input: number, output: number, cacheRead: number, estimated: boolean }}
79
+ */
80
+ function priceForModel(modelId) {
81
+ const id = typeof modelId === 'string' ? modelId.toLowerCase().replace(PROVIDER_PREFIX_RE, '') : '';
82
+ if (id) {
83
+ for (const rowId of Object.keys(MODEL_PRICES)) {
84
+ if (id === rowId) return priced(rowId, false);
85
+ if (id.startsWith(rowId) && ROW_CONTINUATION_RE.test(id.slice(rowId.length))) return priced(rowId, false);
86
+ }
87
+ for (const [family, rowId] of FAMILY_FALLBACK) {
88
+ if (id.includes(family)) return priced(rowId, true);
89
+ }
90
+ }
91
+ return priced(DEFAULT_ID, true);
92
+ }
93
+
94
+ /** @param {unknown} v */
95
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
96
+
97
+ /**
98
+ * Cache writes split three ways:
99
+ * - cacheCreationUnknownTokens: cache-write tokens whose 5-minute / 1-hour split was not
100
+ * recorded. Clamped to [0, cacheCreationTokens], charged at the 1-hour rate, and they mark
101
+ * the result estimated when above zero. It is a plain number so buckets that mix lines with
102
+ * and without a recorded split still sum correctly.
103
+ * - cacheCreation1hTokens: recorded 1-hour writes, clamped to what is left after the unknown part.
104
+ * - the rest is 5-minute writes.
105
+ * When cacheCreation1hTokens is not a number at all, every cache write counts as unknown.
106
+ *
107
+ * @param {unknown} modelId
108
+ * @param {unknown} bucket { inputTokens, outputTokens, cacheReadTokens, cacheCreationTokens, cacheCreation1hTokens?, cacheCreationUnknownTokens? }
109
+ * @returns {{ costUsd: number, cacheSavingsUsd: number, estimated: boolean }}
110
+ */
111
+ function costOfUsage(modelId, bucket) {
112
+ const price = priceForModel(modelId);
113
+ /** @type {Record<string, unknown>} */
114
+ const b = bucket && typeof bucket === 'object' ? /** @type {Record<string, unknown>} */ (bucket) : {};
115
+ const input = num(b.inputTokens);
116
+ const output = num(b.outputTokens);
117
+ const cacheRead = num(b.cacheReadTokens);
118
+ const cacheWrite = Math.max(0, num(b.cacheCreationTokens));
119
+ let estimated = price.estimated;
120
+ let writeUnknown;
121
+ let write1h;
122
+ if (typeof b.cacheCreation1hTokens === 'number' && Number.isFinite(b.cacheCreation1hTokens)) {
123
+ writeUnknown = Math.min(Math.max(0, num(b.cacheCreationUnknownTokens)), cacheWrite);
124
+ write1h = Math.min(Math.max(0, b.cacheCreation1hTokens), cacheWrite - writeUnknown);
125
+ } else {
126
+ writeUnknown = cacheWrite;
127
+ write1h = 0;
128
+ }
129
+ if (writeUnknown > 0) estimated = true;
130
+ const write5m = cacheWrite - writeUnknown - write1h;
131
+ const costUsd = (
132
+ input * price.input +
133
+ output * price.output +
134
+ cacheRead * price.cacheRead +
135
+ write5m * price.input * CACHE_WRITE_5M_MULTIPLIER +
136
+ (writeUnknown + write1h) * price.input * CACHE_WRITE_1H_MULTIPLIER
137
+ ) / 1e6;
138
+ const cacheSavingsUsd = cacheRead * (price.input - price.cacheRead) / 1e6;
139
+ return { costUsd, cacheSavingsUsd, estimated };
140
+ }
141
+
142
+ module.exports = {
143
+ MODEL_PRICES,
144
+ CACHE_WRITE_5M_MULTIPLIER,
145
+ CACHE_WRITE_1H_MULTIPLIER,
146
+ priceForModel,
147
+ costOfUsage,
148
+ };
@@ -111,6 +111,20 @@ function checkBlankFrames(frames, threshold = DEFAULT_BLANK_STDDEV) {
111
111
  bad.length ? `blank frame(s) at ${bad.map((f) => `${f.t}s`).join(', ')}` : `${list.length} frame(s) non-blank`);
112
112
  }
113
113
 
114
+ // Project Home's VideoPlayer draws the only control bar; a video that draws its own
115
+ // shows a second one under it. The injected player bridge script is not the video's.
116
+ const PLAYER_BRIDGE_BLOCK_RE = /<script\b[^>]*\bdata-sm-player-bridge\b[^>]*>[\s\S]*?<\/script\s*>/gi;
117
+ const CONTROL_PATTERNS = [
118
+ ['button', /<button\b/i],
119
+ ['input', /<input\b/i],
120
+ ['audio controls', /<audio\b[^>]*\scontrols\b/i],
121
+ ['video controls', /<video\b[^>]*\scontrols\b/i],
122
+ ];
123
+ function ownPlaybackControls(html) {
124
+ const h = String(html || '').replace(PLAYER_BRIDGE_BLOCK_RE, '');
125
+ return CONTROL_PATTERNS.filter(([, re]) => re.test(h)).map(([what]) => what);
126
+ }
127
+
114
128
  function checkHtmlLimits({ html, bytes, lengthS } = {}) {
115
129
  const h = String(html || '');
116
130
  const size = Number.isFinite(bytes) ? bytes : Buffer.byteLength(h);
@@ -122,6 +136,8 @@ function checkHtmlLimits({ html, bytes, lengthS } = {}) {
122
136
  if (!dur) problems.push('sm-demo-duration meta missing');
123
137
  else if (Number(dur[1]) !== Number(lengthS)) problems.push(`sm-demo-duration ${dur[1]} != ${lengthS}`);
124
138
  if (!/window\.smDemo\s*=/.test(h) || !/scenes\s*:/.test(h)) problems.push('window.smDemo with scenes missing');
139
+ const controls = ownPlaybackControls(h);
140
+ if (controls.length) problems.push(`own playback controls: ${controls.join(', ')}`);
125
141
  return result('htmlLimits', problems.length === 0, problems.length ? problems.join('; ') : `${size} bytes within cap ${cap}`);
126
142
  }
127
143
 
@@ -0,0 +1,101 @@
1
+ /**
2
+ * epicAdminRoutes.cjs — read-only admin HTTP routes over epicOutsideRead.cjs,
3
+ * so a script or another project can read an Epic's state without touching
4
+ * Session Manager's files.
5
+ *
6
+ * GET /admin/epics?cwd=<abs>&state=<state>&limit=<1..200>&offset=<0..>
7
+ * → 200 { ok: true, epics, total, limit, offset, hasMore }
8
+ * GET /admin/epic?cwd=<abs>&(id=<epicId> | externalRef=<ref>)[&receipt=1|true]
9
+ * → 200 { ok: true, epic } (epic.receipt = { jobs, chat } only when receipt was asked for) | 404 { ok: false, error: 'not found' }
10
+ *
11
+ * A query the schema rejects → 400 { ok: false, error: 'invalid query', details }.
12
+ * A cwd that is not absolute or has no session-manager-operations folder →
13
+ * 400 { ok: false, error: <reason> }.
14
+ *
15
+ * Writes no file and no audit row. Auth/loopback binding are the injected
16
+ * localAdminHttp.cjs transport's job (see index.cjs).
17
+ */
18
+ 'use strict';
19
+
20
+ const fs = require('node:fs');
21
+ const path = require('node:path');
22
+ const { schemas } = require('../../ipcSchemas.cjs');
23
+ const { sendJson } = require('../feedback-remote/localAdminHttp.cjs');
24
+ const { opsPath } = require('../opsOwnership.cjs');
25
+ const { listOpenEpicRecords, getEpicRecord } = require('./epicOutsideRead.cjs');
26
+
27
+ /** @param {unknown} cwd @returns {string | null} the reason this cwd is not a project, or null. */
28
+ function projectProblem(cwd) {
29
+ if (typeof cwd !== 'string' || !path.isAbsolute(cwd)) return 'cwd must be an absolute path';
30
+ let dir;
31
+ try {
32
+ dir = opsPath(cwd);
33
+ } catch (e) {
34
+ return e instanceof Error ? e.message : String(e);
35
+ }
36
+ try {
37
+ if (!fs.statSync(dir).isDirectory()) return 'cwd has no session-manager-operations folder';
38
+ } catch {
39
+ return 'cwd has no session-manager-operations folder';
40
+ }
41
+ return null;
42
+ }
43
+
44
+ /**
45
+ * @param {{ registerRoute: Function }} adminHttp
46
+ * @param {{ isTabBusy?: (epicId: string) => boolean | Promise<boolean>, listJobs?: () => any, projectRoots?: () => string[] }} [deps]
47
+ */
48
+ function registerAdminRoute(adminHttp, deps = {}) {
49
+ /** @type {Record<string, unknown>} */
50
+ const readOpts = {};
51
+ if (typeof deps.isTabBusy === 'function') readOpts.isTabBusy = deps.isTabBusy;
52
+ if (typeof deps.listJobs === 'function') readOpts.listJobs = deps.listJobs;
53
+ if (typeof deps.projectRoots === 'function') readOpts.projectRoots = deps.projectRoots;
54
+
55
+ /** @param {any} schema @param {any} query @param {any} res */
56
+ function parseQuery(schema, query, res) {
57
+ let input;
58
+ try {
59
+ input = schema.parse(Object.fromEntries(query ?? []));
60
+ } catch (e) {
61
+ sendJson(res, 400, { ok: false, error: 'invalid query', details: e?.issues ?? e?.message });
62
+ return null;
63
+ }
64
+ const problem = projectProblem(input.cwd);
65
+ if (problem) {
66
+ sendJson(res, 400, { ok: false, error: problem });
67
+ return null;
68
+ }
69
+ return input;
70
+ }
71
+
72
+ adminHttp.registerRoute('GET', '/admin/epics', async (/** @type {any} */ req, /** @type {any} */ res, /** @type {any} */ query) => {
73
+ const input = parseQuery(schemas.adminListEpicsQuery, query, res);
74
+ if (!input) return;
75
+ const { epics, total, limit, offset, hasMore } = await listOpenEpicRecords(input.cwd, {
76
+ ...readOpts,
77
+ state: input.state,
78
+ limit: input.limit,
79
+ offset: input.offset,
80
+ });
81
+ sendJson(res, 200, { ok: true, epics, total, limit, offset, hasMore });
82
+ });
83
+
84
+ adminHttp.registerRoute('GET', '/admin/epic', async (/** @type {any} */ req, /** @type {any} */ res, /** @type {any} */ query) => {
85
+ const input = parseQuery(schemas.adminGetEpicQuery, query, res);
86
+ if (!input) return;
87
+ const epic = await getEpicRecord(input.cwd, {
88
+ ...readOpts,
89
+ id: input.id,
90
+ externalRef: input.externalRef,
91
+ receipt: input.receipt === true,
92
+ });
93
+ if (!epic) {
94
+ sendJson(res, 404, { ok: false, error: 'not found' });
95
+ return;
96
+ }
97
+ sendJson(res, 200, { ok: true, epic });
98
+ });
99
+ }
100
+
101
+ module.exports = { registerAdminRoute };