@wrongstack/core 0.313.1 → 0.316.2

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 (290) hide show
  1. package/dist/chronicle/index.js +31 -31
  2. package/dist/chronicle/legacy-journal-import.d.ts +0 -6
  3. package/dist/chronicle/metrics-ingest.d.ts +14 -0
  4. package/dist/chronicle/metrics-schema.d.ts +10 -1
  5. package/dist/chronicle/metrics-store.d.ts +20 -2
  6. package/dist/chronicle/project-server.js +39 -31
  7. package/dist/chronicle/sink.d.ts +13 -0
  8. package/dist/chronicle/sqlite-journal.d.ts +20 -2
  9. package/dist/{chunk-WOEZV3Q4.js → chunk-25LSLC3G.js} +2 -1
  10. package/dist/{chunk-AI4LLQ2U.js → chunk-27QIURLN.js} +229 -12
  11. package/dist/{chunk-I45KAW2N.js → chunk-3AGWVSS7.js} +38 -450
  12. package/dist/chunk-3BDV7RL3.js +211 -0
  13. package/dist/{chunk-NFAYHPRH.js → chunk-3ECENVHL.js} +10 -8
  14. package/dist/{chunk-FW5LDDMJ.js → chunk-45WI72ZB.js} +1576 -1156
  15. package/dist/{chunk-AT4V4XGI.js → chunk-4BMVPOHO.js} +539 -313
  16. package/dist/{chunk-YBUJCZ57.js → chunk-4I7HGVVA.js} +17 -5
  17. package/dist/{chunk-JVGPR3TS.js → chunk-4LCZVJVF.js} +7 -55
  18. package/dist/{chunk-4ZHTKJHM.js → chunk-4SJNS7OB.js} +36 -2
  19. package/dist/{chunk-AD7ZFZCS.js → chunk-5BMIE7QG.js} +3 -3
  20. package/dist/{chunk-IQ35HMQL.js → chunk-5YPSXQXM.js} +71 -24
  21. package/dist/chunk-6FHWXLPT.js +10 -0
  22. package/dist/{chunk-FIV4IJL7.js → chunk-6H5GEOET.js} +163 -20
  23. package/dist/{chunk-VB3H5WWB.js → chunk-6NWEVFEL.js} +2 -2
  24. package/dist/{chunk-E6I5RXVK.js → chunk-AYW5YINX.js} +2 -2
  25. package/dist/{chunk-DEIQMBD2.js → chunk-B7F4WVP4.js} +2 -2
  26. package/dist/{chunk-XQ2XGIBF.js → chunk-BPBKKBUK.js} +6 -7
  27. package/dist/{chunk-K4YUNKU7.js → chunk-BYD345OX.js} +2 -2
  28. package/dist/{chunk-LZDDLNCZ.js → chunk-C27KDLOX.js} +4 -4
  29. package/dist/{chunk-6AKOTGLM.js → chunk-CU546ESW.js} +7 -7
  30. package/dist/{chunk-ZZ4V3WIZ.js → chunk-DLHHXUAM.js} +10 -1
  31. package/dist/{chunk-BAKVJLEV.js → chunk-DOTHQSJ2.js} +28 -16
  32. package/dist/{chunk-KBZGE6LN.js → chunk-DYLPMV4Q.js} +4 -3
  33. package/dist/{chunk-52RTVH4M.js → chunk-F3JWNST7.js} +2 -2
  34. package/dist/{chunk-WEBMSQP2.js → chunk-FC2ZGRF3.js} +21 -4
  35. package/dist/{chunk-FHAMQS7Q.js → chunk-FCBTO76Z.js} +76 -146
  36. package/dist/{chunk-4LJJYBAU.js → chunk-FHZVFYSL.js} +9 -1
  37. package/dist/{chunk-W4A6QA3D.js → chunk-FWNLEZYG.js} +4 -3
  38. package/dist/{chunk-OJZEX73F.js → chunk-GDQ7CZRQ.js} +5 -1
  39. package/dist/{chunk-QVOVMXJR.js → chunk-GJJGJB2R.js} +32 -9
  40. package/dist/{chunk-4XV6IR37.js → chunk-HI3JGZR2.js} +7 -6
  41. package/dist/{chunk-FSWCWSTS.js → chunk-HMLIGAU7.js} +26 -26
  42. package/dist/{chunk-PFXFQQRT.js → chunk-HXKZ7OBQ.js} +7 -43
  43. package/dist/{chunk-2FQL4PDC.js → chunk-I7DALG7J.js} +5 -5
  44. package/dist/{chunk-GM54GJBU.js → chunk-IRUTEHCE.js} +3 -3
  45. package/dist/{chunk-TYW2GI5I.js → chunk-J2WRWR37.js} +40 -13
  46. package/dist/{chunk-ZEHUCJHY.js → chunk-JFPJ6LLQ.js} +2 -2
  47. package/dist/chunk-JMULFFLN.js +9 -0
  48. package/dist/{chunk-RD6DEE36.js → chunk-JO4MGB6Z.js} +94 -8
  49. package/dist/{chunk-5DSMEVA4.js → chunk-K6BXGITA.js} +7 -7
  50. package/dist/{chunk-O74MJHXU.js → chunk-KZMSZV32.js} +2 -2
  51. package/dist/{chunk-GFJOMSHG.js → chunk-LA7CLDRW.js} +6 -2
  52. package/dist/{chunk-M2WF6AXG.js → chunk-LSMMOS2Z.js} +7 -3
  53. package/dist/{chunk-ASX6AW36.js → chunk-LXWCMQNJ.js} +3 -3
  54. package/dist/{chunk-WZO23AWO.js → chunk-M27LIEKV.js} +72 -22
  55. package/dist/{chunk-JTHKOYWU.js → chunk-MJPHJRAL.js} +15 -15
  56. package/dist/{chunk-G5AAKEEZ.js → chunk-MTL4O5YR.js} +5 -5
  57. package/dist/chunk-NHJ75HXY.js +1 -0
  58. package/dist/{chunk-ZYU2YOJ6.js → chunk-NIOAGFPB.js} +29 -15
  59. package/dist/{chunk-Y2GE5TSI.js → chunk-NS52ISWS.js} +2 -2
  60. package/dist/{chunk-UIWONWVG.js → chunk-NSOFPKGT.js} +541 -148
  61. package/dist/{chunk-RCQYT2I4.js → chunk-NVIZG63R.js} +2 -2
  62. package/dist/{chunk-EPC3GZD4.js → chunk-OOYZPOXM.js} +2 -2
  63. package/dist/{chunk-7ZHZE5EO.js → chunk-OSGLYW5J.js} +2 -2
  64. package/dist/{chunk-CE4ZOCOI.js → chunk-PFCMSSUF.js} +9 -9
  65. package/dist/{chunk-GFXZTHNI.js → chunk-PGRVXIMY.js} +5 -5
  66. package/dist/{chunk-JJPMWPB6.js → chunk-PISBFBJN.js} +6 -6
  67. package/dist/chunk-POOOIWE5.js +9 -0
  68. package/dist/{chunk-5RP3QTRL.js → chunk-PQNS3U7Z.js} +20 -3
  69. package/dist/{chunk-3E244UDA.js → chunk-QSTSJOCK.js} +52 -6
  70. package/dist/{chunk-YUPMXOGP.js → chunk-RFQMOKWK.js} +3 -3
  71. package/dist/chunk-RTOTNK3P.js +484 -0
  72. package/dist/{chunk-SN2DQRL6.js → chunk-RXKSDUAU.js} +7 -7
  73. package/dist/{chunk-T3KGZBU5.js → chunk-S45JPKQN.js} +189 -43
  74. package/dist/{chunk-YNCVSFGF.js → chunk-SAFHACFA.js} +4 -1
  75. package/dist/{chunk-KI4L2DUL.js → chunk-TCCHINEF.js} +114 -19
  76. package/dist/{chunk-AWNQ6ED6.js → chunk-THEGTRAG.js} +7 -2
  77. package/dist/{chunk-2KKODIQU.js → chunk-TR4LQE7L.js} +15 -15
  78. package/dist/{chunk-GPQ3NJPR.js → chunk-TWJMGXCI.js} +3 -3
  79. package/dist/{chunk-H72H4XDU.js → chunk-U45AXT5D.js} +9 -9
  80. package/dist/{chunk-62V2AFVG.js → chunk-U4FWBSO3.js} +160 -73
  81. package/dist/{chunk-A455ATZB.js → chunk-UBGDX6FI.js} +8 -1
  82. package/dist/chunk-UJILKYES.js +75 -0
  83. package/dist/{chunk-KSJ5UTP7.js → chunk-ULMAQV3T.js} +84 -4
  84. package/dist/{chunk-CB2HFKTP.js → chunk-VVBP6KGT.js} +1 -1
  85. package/dist/{chunk-RPOA7IAE.js → chunk-W5VITDM2.js} +43 -25
  86. package/dist/{chunk-QRTG4XTI.js → chunk-WAHQVNWT.js} +7 -1
  87. package/dist/{chunk-SQP64RCS.js → chunk-WGGYRBXH.js} +3019 -2976
  88. package/dist/{chunk-K3G6JBUC.js → chunk-WLYKU45P.js} +679 -141
  89. package/dist/chunk-WP7BVANJ.js +53 -0
  90. package/dist/{chunk-GAZEWQEZ.js → chunk-XF4VUMKW.js} +2 -2
  91. package/dist/{chunk-PAAWLLZX.js → chunk-Y5YXDM7D.js} +2 -2
  92. package/dist/{chunk-65RDIOR2.js → chunk-YOPAUVU4.js} +162 -44
  93. package/dist/{chunk-FFSX2QDQ.js → chunk-YPT4A46F.js} +3 -3
  94. package/dist/chunk-YWXT3JNM.js +425 -0
  95. package/dist/{chunk-EFEHDQGY.js → chunk-ZHZ2Y2DH.js} +64 -10
  96. package/dist/{chunk-CQQL4ZOQ.js → chunk-ZT7JNIGX.js} +4 -3
  97. package/dist/coordination/agent-monitor.d.ts +9 -1
  98. package/dist/coordination/agent-subagent-runner.d.ts +1 -1
  99. package/dist/coordination/agents/agent-prompts.d.ts +8 -0
  100. package/dist/coordination/agents/index.d.ts +33 -1
  101. package/dist/coordination/agents/index.js +52 -22
  102. package/dist/coordination/agents/phase3-wave1-platform.d.ts +1 -3
  103. package/dist/coordination/agents/phase3-wave2-meta.d.ts +1 -3
  104. package/dist/coordination/agents/phase8-wave3-products.d.ts +1 -3
  105. package/dist/coordination/agents/phase9-wave4-platform-meta.d.ts +1 -3
  106. package/dist/coordination/agents/project-agent-identity.d.ts +11 -11
  107. package/dist/coordination/agents/types.d.ts +13 -2
  108. package/dist/coordination/brain-monitor.d.ts +30 -7
  109. package/dist/coordination/collab-debug.d.ts +1 -1
  110. package/dist/coordination/collab-pause.d.ts +1 -1
  111. package/dist/coordination/delegate-tool.d.ts +7 -5
  112. package/dist/coordination/director-kanban-queue-helpers.d.ts +1 -0
  113. package/dist/coordination/director-options.d.ts +7 -0
  114. package/dist/coordination/director-spawn-model.d.ts +17 -0
  115. package/dist/coordination/director-tools.d.ts +2 -2
  116. package/dist/coordination/director.d.ts +12 -0
  117. package/dist/coordination/dispatcher.d.ts +8 -0
  118. package/dist/coordination/fleet-bus.d.ts +35 -4
  119. package/dist/coordination/fleet-supervisor.d.ts +10 -2
  120. package/dist/coordination/fleet.d.ts +16 -7
  121. package/dist/coordination/index.d.ts +4 -0
  122. package/dist/coordination/index.js +86 -49
  123. package/dist/coordination/kanban-dispatch-port.d.ts +2 -2
  124. package/dist/coordination/mailbox-http-router.d.ts +4 -3
  125. package/dist/coordination/mailbox-http-validation.d.ts +1 -1
  126. package/dist/coordination/mailbox-project-server.js +15 -15
  127. package/dist/coordination/mailbox-types.d.ts +24 -6
  128. package/dist/coordination/model-tier-leader.d.ts +122 -0
  129. package/dist/coordination/model-tier.d.ts +122 -0
  130. package/dist/coordination/multi-agent-coordinator.d.ts +24 -0
  131. package/dist/coordination/origin-session.d.ts +16 -0
  132. package/dist/coordination/provider-status-tracker.d.ts +37 -5
  133. package/dist/coordination/session-note-hub.d.ts +44 -0
  134. package/dist/coordination/session-note-tool.d.ts +10 -0
  135. package/dist/core/agent.d.ts +1 -1
  136. package/dist/core/context.d.ts +22 -3
  137. package/dist/core/index.d.ts +2 -0
  138. package/dist/core/index.js +130 -38
  139. package/dist/core/request-conversation-binding.d.ts +37 -0
  140. package/dist/core/session-notes.d.ts +25 -0
  141. package/dist/core/system-prompt-builder.d.ts +11 -2
  142. package/dist/core/system-prompt-variants.d.ts +78 -0
  143. package/dist/design/index.js +3 -3
  144. package/dist/execution/auto-compaction-middleware.d.ts +11 -0
  145. package/dist/execution/autonomy-brain.d.ts +2 -1
  146. package/dist/execution/autonomy-prompt-contributor.d.ts +7 -2
  147. package/dist/execution/compaction-core.d.ts +4 -4
  148. package/dist/execution/eternal-autonomy.d.ts +1 -1
  149. package/dist/execution/index.js +138 -129
  150. package/dist/execution/model-runtime.d.ts +0 -7
  151. package/dist/execution/parallel-eternal-engine.d.ts +7 -7
  152. package/dist/extension/index.js +3 -3
  153. package/dist/goal/index.js +6 -6
  154. package/dist/hooks/index.js +3 -3
  155. package/dist/hq/index.js +14 -12
  156. package/dist/hq/persistence/event-log.d.ts +0 -1
  157. package/dist/hq/persistence.d.ts +4 -4
  158. package/dist/hq/publisher.d.ts +2 -0
  159. package/dist/index.d.ts +14 -11
  160. package/dist/index.js +728 -635
  161. package/dist/infrastructure/index.d.ts +4 -4
  162. package/dist/infrastructure/index.js +281 -260
  163. package/dist/infrastructure/token-counter.d.ts +9 -0
  164. package/dist/kernel/events/agent-events.d.ts +77 -3
  165. package/dist/kernel/events/brain-events.d.ts +12 -0
  166. package/dist/kernel/events/provider-events.d.ts +7 -1
  167. package/dist/kernel/events/session-events.d.ts +14 -0
  168. package/dist/kernel/events/tool-events.d.ts +13 -0
  169. package/dist/kernel/index.js +4 -4
  170. package/dist/mailbox-attach.d.ts +1 -1
  171. package/dist/models/index.js +10 -9
  172. package/dist/observability/event-bridge.d.ts +25 -5
  173. package/dist/observability/index.d.ts +9 -8
  174. package/dist/observability/index.js +459 -351
  175. package/dist/observability/tool-usage-source.d.ts +65 -0
  176. package/dist/plugin/index.d.ts +5 -0
  177. package/dist/plugin/index.js +66 -50
  178. package/dist/plugins/auto-review-plugin.d.ts +3 -2
  179. package/dist/plugins/review-finding-commands.d.ts +0 -8
  180. package/dist/{review-finding-store-DKAV3AS6.js → plugins/review-finding-store.js} +7 -6
  181. package/dist/plugins/review-finding-types.js +19 -0
  182. package/dist/plugins/review-report-integration.js +21 -0
  183. package/dist/{review-report-store-OWY3EC3N.js → plugins/review-report-store.js} +7 -6
  184. package/dist/plugins/review-report-types.js +13 -0
  185. package/dist/prompts/index.js +5 -5
  186. package/dist/registry/index.js +3 -3
  187. package/dist/registry/tool-registry.d.ts +59 -9
  188. package/dist/{registry-R23UBE7H.js → registry-7N4O3E7W.js} +5 -5
  189. package/dist/security/capabilities.d.ts +6 -0
  190. package/dist/security/file-permissions.d.ts +1 -1
  191. package/dist/security/index.js +47 -33
  192. package/dist/security/permission-policy.d.ts +12 -1
  193. package/dist/security/secret-scrubber.d.ts +15 -0
  194. package/dist/session-catalog/index.d.ts +1 -0
  195. package/dist/session-catalog/index.js +19 -14
  196. package/dist/session-catalog/project-server.js +30 -13
  197. package/dist/session-catalog/protocol.d.ts +32 -1
  198. package/dist/session-catalog/registry.d.ts +17 -1
  199. package/dist/session-catalog/session-agents.d.ts +56 -0
  200. package/dist/session-catalog/store-rebuild.d.ts +14 -0
  201. package/dist/session-catalog/store-schema.d.ts +26 -0
  202. package/dist/session-catalog/store.d.ts +27 -1
  203. package/dist/session-note-attach.d.ts +9 -0
  204. package/dist/skills/index.js +5 -5
  205. package/dist/statusline/index.d.ts +43 -0
  206. package/dist/statusline/index.js +102 -0
  207. package/dist/storage/board-store-port.d.ts +2 -2
  208. package/dist/storage/config-loader/in-project-policy.d.ts +29 -0
  209. package/dist/storage/config-loader.d.ts +3 -2
  210. package/dist/storage/file-session-writer.d.ts +4 -2
  211. package/dist/storage/goal-coordination.d.ts +6 -1
  212. package/dist/storage/goal-kanban.d.ts +4 -1
  213. package/dist/storage/index.d.ts +12 -4
  214. package/dist/storage/index.js +76 -61
  215. package/dist/storage/input-history-store.d.ts +2 -4
  216. package/dist/storage/memory-curator.d.ts +133 -0
  217. package/dist/storage/session-agent-attribution.d.ts +39 -0
  218. package/dist/storage/session-doctor.d.ts +109 -0
  219. package/dist/storage/session-event-bridge.d.ts +5 -7
  220. package/dist/storage/session-outcome.d.ts +42 -0
  221. package/dist/storage/session-recovery.d.ts +55 -0
  222. package/dist/storage/session-store/load-session-data.d.ts +11 -0
  223. package/dist/storage/session-store/prune-helpers.d.ts +1 -1
  224. package/dist/storage/session-store/resume-session.d.ts +0 -2
  225. package/dist/storage/session-store/types.d.ts +8 -0
  226. package/dist/storage/session-store.d.ts +3 -3
  227. package/dist/storage/session-summary-tracker.d.ts +8 -1
  228. package/dist/storage/session-write-buffer.d.ts +18 -0
  229. package/dist/storage/session-writer-truncate.d.ts +2 -0
  230. package/dist/tasking/index.js +2 -2
  231. package/dist/tools/fallback-manage-tools.d.ts +6 -4
  232. package/dist/tools/index.js +21 -21
  233. package/dist/tools/model-tier-set-tool.d.ts +66 -0
  234. package/dist/types/agent-bridge.d.ts +2 -1
  235. package/dist/types/config/mcp-features.d.ts +7 -0
  236. package/dist/types/config/model-tiers.d.ts +148 -0
  237. package/dist/types/config/root.d.ts +9 -0
  238. package/dist/types/config/tools.d.ts +73 -0
  239. package/dist/types/config.d.ts +1 -0
  240. package/dist/types/context.d.ts +2 -0
  241. package/dist/types/default-config.d.ts +6 -0
  242. package/dist/types/errors.d.ts +2 -1
  243. package/dist/types/index.d.ts +11 -9
  244. package/dist/types/index.js +25 -15
  245. package/dist/types/multi-agent.d.ts +43 -0
  246. package/dist/types/plugin.d.ts +1 -1
  247. package/dist/types/provider.d.ts +15 -0
  248. package/dist/types/runtime-capability-manifest.d.ts +1 -1
  249. package/dist/types/secret-scrubber.d.ts +15 -0
  250. package/dist/types/session-markers.d.ts +37 -10
  251. package/dist/types/session-markers.js +1 -1
  252. package/dist/types/session-timeline.d.ts +197 -0
  253. package/dist/types/session-timeline.js +12 -0
  254. package/dist/types/session.d.ts +172 -11
  255. package/dist/types/system-prompt.d.ts +27 -0
  256. package/dist/utils/config-backup.d.ts +9 -1
  257. package/dist/utils/heap-watchdog.js +2 -2
  258. package/dist/utils/index.js +50 -48
  259. package/dist/utils/message-invariants.d.ts +4 -1
  260. package/dist/utils/regex-guard.d.ts +1 -1
  261. package/dist/utils/socket-path.d.ts +1 -1
  262. package/dist/utils/token-estimate.d.ts +6 -2
  263. package/dist/utils/wstack-paths.d.ts +2 -0
  264. package/dist/wiring/proxy-rewrite.d.ts +28 -0
  265. package/dist/wiring/proxy-rewrite.js +7 -1
  266. package/dist/worktree/index.js +2 -2
  267. package/instructions/agents/explore-companion.md +45 -18
  268. package/instructions/agents/memory-curator.md +34 -22
  269. package/instructions/coordination/director-preamble.md +12 -7
  270. package/instructions/coordination/subagent-baseline.md +26 -5
  271. package/instructions/leader-after-task.md +4 -1
  272. package/instructions/llm/chimera-review.md +30 -9
  273. package/instructions/llm/memory-curator.md +31 -0
  274. package/instructions/sections/tool/delegation-compact.md +2 -0
  275. package/instructions/sections/tool/delegation-full.md +5 -1
  276. package/instructions/sections/tool/mailbox-compact.md +5 -1
  277. package/instructions/sections/tool/mailbox-full.md +3 -0
  278. package/instructions/sections/tool/session-note-compact.md +3 -0
  279. package/instructions/sections/tool/session-note-full.md +15 -0
  280. package/instructions/system-lite.md +9 -4
  281. package/instructions/system-pro.md +66 -143
  282. package/instructions/system.md +73 -175
  283. package/package.json +33 -5
  284. package/dist/chunk-2BUUIMQB.js +0 -225
  285. package/dist/chunk-FAYRX2AD.js +0 -13
  286. package/dist/chunk-H5E77KUJ.js +0 -15
  287. package/dist/chunk-M7BS2K6U.js +0 -1
  288. package/dist/coordination/agents.d.ts +0 -8
  289. package/dist/coordination/transport.d.ts +0 -2
  290. package/dist/storage/session-writer/session-writer-summary-tracker.d.ts +0 -28
@@ -0,0 +1,484 @@
1
+ import {
2
+ AGENTS_BY_PHASE,
3
+ AGENT_CATALOG
4
+ } from "./chunk-FCBTO76Z.js";
5
+ import {
6
+ fallbackProfileChain
7
+ } from "./chunk-U45AXT5D.js";
8
+ import {
9
+ parseModelRef
10
+ } from "./chunk-RJIZEJ42.js";
11
+
12
+ // src/coordination/model-matrix.ts
13
+ var MATRIX_PHASE_KEYS = Object.keys(AGENTS_BY_PHASE);
14
+ var ROLE_TO_PHASE = (() => {
15
+ const map = {};
16
+ for (const [phase, defs] of Object.entries(AGENTS_BY_PHASE)) {
17
+ for (const def of defs) {
18
+ const role = def.config.role;
19
+ if (role) map[role] = phase;
20
+ }
21
+ }
22
+ return map;
23
+ })();
24
+ function phaseForRole(role) {
25
+ return role ? ROLE_TO_PHASE[role] : void 0;
26
+ }
27
+ function resolveModelMatrixResolution(matrix, role) {
28
+ if (!matrix) return void 0;
29
+ if (role && matrix[role]) return { entry: matrix[role], source: "role", key: role };
30
+ const phase = phaseForRole(role);
31
+ if (phase && matrix[phase]) return { entry: matrix[phase], source: "phase", key: phase };
32
+ if (matrix["*"]) return { entry: matrix["*"], source: "default", key: "*" };
33
+ return void 0;
34
+ }
35
+ function resolveModelMatrix(matrix, role) {
36
+ return resolveModelMatrixResolution(matrix, role)?.entry;
37
+ }
38
+ function resolveModelTargetFromEntry(config, entry) {
39
+ if (!entry) return void 0;
40
+ if (entry.model) {
41
+ return {
42
+ provider: entry.provider,
43
+ model: entry.model,
44
+ modelRuntime: entry.modelRuntime,
45
+ fallbackProfile: entry.fallbackProfile,
46
+ fallbackModels: fallbackProfileChain(config, entry.fallbackProfile)
47
+ };
48
+ }
49
+ const chain = fallbackProfileChain(config, entry.fallbackProfile);
50
+ const first = chain[0];
51
+ if (!first) {
52
+ return entry.modelRuntime ? { modelRuntime: entry.modelRuntime } : void 0;
53
+ }
54
+ const parsed = parseModelRef(first);
55
+ return {
56
+ provider: parsed.provider,
57
+ model: parsed.model,
58
+ modelRuntime: entry.modelRuntime,
59
+ fallbackProfile: entry.fallbackProfile,
60
+ fallbackModels: chain.slice(1)
61
+ };
62
+ }
63
+ function roleNeedsIndependentReviewModel(role) {
64
+ if (!role) return false;
65
+ return role === "reviewer" || phaseForRole(role) === "review";
66
+ }
67
+ function resolveSubagentModelTarget(config, role, opts = {}) {
68
+ const resolution = resolveModelMatrixResolution(config.modelMatrix, role);
69
+ const matrixTarget = resolveModelTargetFromEntry(config, resolution?.entry);
70
+ const implementationTarget = opts.implementationTarget ?? resolveImplementationModelTarget(config);
71
+ const isAvailable = (providerId, model) => {
72
+ if (!opts.statusTracker) return true;
73
+ if (!providerId || !model) return true;
74
+ return opts.statusTracker.isAvailable(providerId, model);
75
+ };
76
+ const matrixEffective = materializeTarget(config, matrixTarget);
77
+ const matrixIsAvailable = !matrixEffective || isAvailable(matrixEffective.provider, matrixEffective.model);
78
+ if (!roleNeedsIndependentReviewModel(role)) {
79
+ if (!matrixTarget) return void 0;
80
+ if (!matrixIsAvailable) return void 0;
81
+ return {
82
+ ...matrixTarget,
83
+ source: "matrix",
84
+ matrixSource: resolution?.source
85
+ };
86
+ }
87
+ const matrixRef = materializeTarget(config, matrixTarget);
88
+ if (resolution?.source === "role" || resolution?.source === "phase") {
89
+ if (!matrixTarget) return void 0;
90
+ if (!matrixIsAvailable) return void 0;
91
+ return {
92
+ ...matrixTarget,
93
+ source: "matrix",
94
+ matrixSource: resolution.source
95
+ };
96
+ }
97
+ if (matrixRef && !sameModelReference(matrixRef, implementationTarget)) {
98
+ if (!matrixIsAvailable) return void 0;
99
+ return {
100
+ ...matrixTarget ?? {},
101
+ source: "matrix",
102
+ matrixSource: resolution?.source
103
+ };
104
+ }
105
+ const diverse = chooseDiverseModelTargetWithTracker(
106
+ config,
107
+ implementationTarget,
108
+ opts.statusTracker
109
+ );
110
+ if (diverse) {
111
+ return {
112
+ provider: diverse.provider,
113
+ model: diverse.model,
114
+ modelRuntime: matrixTarget?.modelRuntime,
115
+ fallbackModels: matrixTarget?.fallbackModels,
116
+ fallbackProfile: matrixTarget?.fallbackProfile,
117
+ source: "diversity",
118
+ matrixSource: resolution?.source,
119
+ diversified: true
120
+ };
121
+ }
122
+ if (!matrixTarget) return void 0;
123
+ if (!matrixIsAvailable) return void 0;
124
+ return {
125
+ ...matrixTarget,
126
+ source: "matrix",
127
+ matrixSource: resolution?.source
128
+ };
129
+ }
130
+ function resolveImplementationModelTarget(config) {
131
+ const target = resolveModelTargetFromEntry(
132
+ config,
133
+ resolveModelMatrix(config.modelMatrix, "executor")
134
+ );
135
+ return materializeTarget(config, target) ?? {
136
+ provider: config.provider,
137
+ model: config.model
138
+ };
139
+ }
140
+ function sameModelReference(a, b) {
141
+ if (!a?.model || !b?.model) return false;
142
+ const providerA = a.provider ?? "";
143
+ const providerB = b.provider ?? "";
144
+ return providerA === providerB && a.model === b.model;
145
+ }
146
+ function materializeTarget(config, target) {
147
+ if (!target?.model) return void 0;
148
+ return {
149
+ provider: target.provider ?? config.provider,
150
+ model: target.model
151
+ };
152
+ }
153
+ function chooseDiverseModelTarget(config, avoid) {
154
+ const candidates = collectConfiguredModelTargets(config).filter(
155
+ (candidate) => !sameModelReference(candidate, avoid)
156
+ );
157
+ candidates.sort((a, b) => modelDiversityScore(b, avoid) - modelDiversityScore(a, avoid));
158
+ return candidates[0];
159
+ }
160
+ function chooseDiverseModelTargetWithTracker(config, avoid, tracker) {
161
+ if (!tracker) return chooseDiverseModelTarget(config, avoid);
162
+ const ranked = collectConfiguredModelTargets(config).filter((candidate) => !sameModelReference(candidate, avoid)).sort((a, b) => modelDiversityScore(b, avoid) - modelDiversityScore(a, avoid));
163
+ for (const candidate of ranked) {
164
+ if (tracker.isAvailable(candidate.provider, candidate.model)) return candidate;
165
+ }
166
+ return void 0;
167
+ }
168
+ function collectConfiguredModelTargets(config) {
169
+ const seen = /* @__PURE__ */ new Set();
170
+ const out = [];
171
+ const add = (provider, model) => {
172
+ if (!provider || !model) return;
173
+ const key = `${provider}\0${model}`;
174
+ if (seen.has(key)) return;
175
+ seen.add(key);
176
+ out.push({ provider, model });
177
+ };
178
+ add(config.provider, config.model);
179
+ for (const [providerId, provider] of Object.entries(config.providers ?? {})) {
180
+ if (!isProviderAvailable(providerId, provider, config.provider)) continue;
181
+ for (const model of provider.models ?? []) add(providerId, model);
182
+ for (const model of Object.keys(provider.customModels ?? {})) add(providerId, model);
183
+ }
184
+ for (const model of Object.keys(config.models ?? {})) add(config.provider, model);
185
+ return out;
186
+ }
187
+ function isProviderAvailable(providerId, provider, leaderProvider) {
188
+ if (providerId === leaderProvider) return true;
189
+ if (typeof provider.apiKey === "string" && provider.apiKey.length > 0) return true;
190
+ if (Array.isArray(provider.apiKeys) && provider.apiKeys.some((key) => key?.apiKey)) return true;
191
+ if (typeof provider.baseUrl === "string" && provider.baseUrl.length > 0) return true;
192
+ return false;
193
+ }
194
+ function modelDiversityScore(candidate, avoid) {
195
+ let score = 0;
196
+ if (candidate.provider !== avoid.provider) score += 100;
197
+ if (candidate.model !== avoid.model) score += 20;
198
+ if (/opus|gpt-5|o3|o4|gemini.*pro|deepseek-r1/i.test(candidate.model)) score += 10;
199
+ if (/mini|haiku|flash/i.test(candidate.model)) score -= 5;
200
+ return score;
201
+ }
202
+ function matrixKeyKind(key) {
203
+ if (key === "*") return "default";
204
+ if (key in AGENT_CATALOG) return "role";
205
+ if (MATRIX_PHASE_KEYS.includes(key)) return "phase";
206
+ return "unknown";
207
+ }
208
+ function isValidMatrixKey(key) {
209
+ return matrixKeyKind(key) !== "unknown";
210
+ }
211
+
212
+ // src/coordination/model-tier.ts
213
+ var DEFAULT_TIER_ID = "standard";
214
+ function activeTierConfig(config) {
215
+ const tiers = config.modelTiers;
216
+ if (tiers?.enabled !== true) return void 0;
217
+ return tiers;
218
+ }
219
+ function listTierIds(config) {
220
+ const tiers = activeTierConfig(config);
221
+ return Object.keys(tiers?.levels ?? {});
222
+ }
223
+ function tierLevel(config, tier) {
224
+ if (!tier) return void 0;
225
+ const tiers = activeTierConfig(config);
226
+ return tiers?.levels?.[tier];
227
+ }
228
+ function isConfiguredTier(config, tier) {
229
+ return tierLevel(config, tier) !== void 0;
230
+ }
231
+ function classifyTier(config, input = {}) {
232
+ const tiers = activeTierConfig(config);
233
+ if (!tiers) return void 0;
234
+ if (input.tier) {
235
+ return {
236
+ tier: input.tier,
237
+ source: "explicit",
238
+ configured: isConfiguredTier(config, input.tier)
239
+ };
240
+ }
241
+ const routing = tiers.routing ?? {};
242
+ const role = input.role;
243
+ const roleTier = role ? routing[role] : void 0;
244
+ if (roleTier) {
245
+ return {
246
+ tier: roleTier,
247
+ source: "role",
248
+ key: role,
249
+ configured: isConfiguredTier(config, roleTier)
250
+ };
251
+ }
252
+ const phase = phaseForRole(role);
253
+ const phaseTier = phase ? routing[phase] : void 0;
254
+ if (phaseTier) {
255
+ return {
256
+ tier: phaseTier,
257
+ source: "phase",
258
+ key: phase,
259
+ configured: isConfiguredTier(config, phaseTier)
260
+ };
261
+ }
262
+ const starTier = routing["*"];
263
+ if (starTier) {
264
+ return {
265
+ tier: starTier,
266
+ source: "default",
267
+ key: "*",
268
+ configured: isConfiguredTier(config, starTier)
269
+ };
270
+ }
271
+ const fallbackTier = tiers.default ?? DEFAULT_TIER_ID;
272
+ return {
273
+ tier: fallbackTier,
274
+ source: "config-default",
275
+ configured: isConfiguredTier(config, fallbackTier)
276
+ };
277
+ }
278
+ function tierBudget(level) {
279
+ if (!level) return {};
280
+ return {
281
+ ...level.maxCostUsd !== void 0 ? { maxCostUsd: level.maxCostUsd } : {},
282
+ ...level.maxIterations !== void 0 ? { maxIterations: level.maxIterations } : {},
283
+ ...level.maxToolCalls !== void 0 ? { maxToolCalls: level.maxToolCalls } : {},
284
+ ...level.maxTokens !== void 0 ? { maxTokens: level.maxTokens } : {},
285
+ ...level.timeoutMs !== void 0 ? { timeoutMs: level.timeoutMs } : {}
286
+ };
287
+ }
288
+ function tierModelTarget(config, level) {
289
+ if (!level) return void 0;
290
+ const entry = {
291
+ ...level.provider !== void 0 ? { provider: level.provider } : {},
292
+ ...level.model !== void 0 ? { model: level.model } : {},
293
+ ...level.modelRuntime !== void 0 ? { modelRuntime: level.modelRuntime } : {},
294
+ ...level.fallbackProfile !== void 0 ? { fallbackProfile: level.fallbackProfile } : {}
295
+ };
296
+ return resolveModelTargetFromEntry(config, entry);
297
+ }
298
+ function resolveTier(config, input = {}) {
299
+ const decision = classifyTier(config, input);
300
+ if (!decision) return void 0;
301
+ const level = tierLevel(config, decision.tier);
302
+ if (!level) return void 0;
303
+ const target = tierModelTarget(config, level);
304
+ return {
305
+ ...target ?? {},
306
+ tier: decision.tier,
307
+ source: decision.source,
308
+ budget: tierBudget(level)
309
+ };
310
+ }
311
+ var TIGHTENABLE_BUDGETS = ["maxCostUsd", "maxIterations", "maxToolCalls", "maxTokens"];
312
+ function applyTierToSubagentConfig(cfg, resolved) {
313
+ if (!resolved) return;
314
+ if (!cfg.model && resolved.model) cfg.model = resolved.model;
315
+ if (!cfg.provider && resolved.provider) cfg.provider = resolved.provider;
316
+ if (!cfg.fallbackProfile && resolved.fallbackProfile) {
317
+ cfg.fallbackProfile = resolved.fallbackProfile;
318
+ }
319
+ if (!cfg.fallbackModels?.length && resolved.fallbackModels?.length) {
320
+ cfg.fallbackModels = [...resolved.fallbackModels];
321
+ }
322
+ if (!cfg.modelRuntime && resolved.modelRuntime) cfg.modelRuntime = resolved.modelRuntime;
323
+ const budget = resolved.budget;
324
+ const pinned = new Set(cfg.budgetPins ?? []);
325
+ for (const field of TIGHTENABLE_BUDGETS) {
326
+ const tierValue = budget[field];
327
+ if (tierValue === void 0 || pinned.has(field)) continue;
328
+ const current = cfg[field];
329
+ cfg[field] = current === void 0 ? tierValue : Math.min(current, tierValue);
330
+ }
331
+ if (cfg.timeoutMs === void 0 && budget.timeoutMs !== void 0 && !pinned.has("timeoutMs")) {
332
+ cfg.timeoutMs = budget.timeoutMs;
333
+ }
334
+ }
335
+
336
+ // src/coordination/model-tier-leader.ts
337
+ var DEFAULTS = {
338
+ mode: "propose",
339
+ dwellTurns: 6,
340
+ minSavingsUsd: 0.1,
341
+ maxContextFillForSwitch: 0.8
342
+ };
343
+ function leaderTierPolicy(config) {
344
+ const leader = config.modelTiers?.leader ?? {};
345
+ return {
346
+ mode: leader.mode ?? DEFAULTS.mode,
347
+ dwellTurns: leader.dwellTurns ?? DEFAULTS.dwellTurns,
348
+ minSavingsUsd: leader.minSavingsUsd ?? DEFAULTS.minSavingsUsd,
349
+ maxContextFillForSwitch: leader.maxContextFillForSwitch ?? DEFAULTS.maxContextFillForSwitch,
350
+ ...leader.maxTier !== void 0 ? { maxTier: leader.maxTier } : {}
351
+ };
352
+ }
353
+ function tierRank(config, tier) {
354
+ if (!tier) return -1;
355
+ return listTierIds(config).indexOf(tier);
356
+ }
357
+ function evaluateSwitchEconomics(request, projectedTurns) {
358
+ const mtok = request.contextTokens / 1e6;
359
+ const { from, to } = request.economics;
360
+ const fromInput = from.inputPerMTok ?? 0;
361
+ const toInput = to.inputPerMTok ?? 0;
362
+ const stayPerTurn = mtok * (from.cacheReadPerMTok ?? fromInput);
363
+ const switchPerTurn = mtok * (to.cacheReadPerMTok ?? toInput);
364
+ const reWarm = mtok * (to.cacheWritePerMTok ?? toInput);
365
+ return {
366
+ reWarmCostUsd: reWarm,
367
+ stayCostPerTurnUsd: stayPerTurn,
368
+ switchCostPerTurnUsd: switchPerTurn,
369
+ projectedSavingsUsd: (stayPerTurn - switchPerTurn) * projectedTurns - reWarm,
370
+ isDowngrade: toInput < fromInput
371
+ };
372
+ }
373
+ function evaluateLeaderTierSwitch(config, request) {
374
+ const tiers = activeTierConfig(config);
375
+ if (!tiers) {
376
+ return { allowed: false, code: "disabled", reason: "The model-tier layer is not enabled." };
377
+ }
378
+ const policy = leaderTierPolicy(config);
379
+ if (policy.mode === "off") {
380
+ return {
381
+ allowed: false,
382
+ code: "disabled",
383
+ reason: 'Leader tier switching is off (modelTiers.leader.mode = "off").'
384
+ };
385
+ }
386
+ if (request.toTier === request.fromTier) {
387
+ return {
388
+ allowed: false,
389
+ code: "same-tier",
390
+ reason: `Already running at tier "${request.toTier}".`
391
+ };
392
+ }
393
+ const targetRank = tierRank(config, request.toTier);
394
+ if (targetRank < 0) {
395
+ const available = listTierIds(config);
396
+ return {
397
+ allowed: false,
398
+ code: "unknown-tier",
399
+ reason: `"${request.toTier}" is not a configured tier${available.length ? ` (available: ${available.join(", ")})` : ""}.`
400
+ };
401
+ }
402
+ if (policy.maxTier !== void 0) {
403
+ const ceiling = tierRank(config, policy.maxTier);
404
+ if (ceiling >= 0 && targetRank > ceiling) {
405
+ return {
406
+ allowed: false,
407
+ code: "ceiling",
408
+ reason: `Tier "${request.toTier}" is above the configured ceiling "${policy.maxTier}". Raising spend past the ceiling is the user\u2019s call, not the leader\u2019s.`
409
+ };
410
+ }
411
+ }
412
+ if (request.turnsSinceSwitch < policy.dwellTurns) {
413
+ return {
414
+ allowed: false,
415
+ code: "dwell",
416
+ reason: `Only ${request.turnsSinceSwitch} turn(s) since the last tier switch; ${policy.dwellTurns} required. Switching more often than this busts the prompt cache faster than a new tier can pay for itself.`
417
+ };
418
+ }
419
+ const targetWindow = request.economics.to.maxContext;
420
+ if (targetWindow && targetWindow > 0) {
421
+ const fill = request.contextTokens / targetWindow;
422
+ if (fill > policy.maxContextFillForSwitch) {
423
+ return {
424
+ allowed: false,
425
+ code: "context-window",
426
+ reason: `Context is ${Math.round(fill * 100)}% of the target model's ${targetWindow}-token window (limit ${Math.round(policy.maxContextFillForSwitch * 100)}%). Compact first, then retry the switch.`
427
+ };
428
+ }
429
+ }
430
+ const projectedTurns = request.projectedTurns ?? policy.dwellTurns;
431
+ const economics = evaluateSwitchEconomics(request, projectedTurns);
432
+ const pricingKnown = request.economics.from.inputPerMTok !== void 0 || request.economics.to.inputPerMTok !== void 0;
433
+ if (pricingKnown && economics.isDowngrade && economics.projectedSavingsUsd < policy.minSavingsUsd) {
434
+ return {
435
+ allowed: false,
436
+ code: "not-worth-it",
437
+ economics,
438
+ reason: `Projected saving $${economics.projectedSavingsUsd.toFixed(4)} over ${projectedTurns} turn(s) is below the $${policy.minSavingsUsd.toFixed(4)} floor once the $${economics.reWarmCostUsd.toFixed(4)} cache re-warm is paid for.`
439
+ };
440
+ }
441
+ if (!pricingKnown) {
442
+ return {
443
+ allowed: true,
444
+ mode: policy.mode === "auto" ? "auto" : "propose",
445
+ economics,
446
+ reason: `No published pricing for either model, so the switch to "${request.toTier}" was judged on the structural guards alone (dwell, context window, ceiling).`
447
+ };
448
+ }
449
+ return {
450
+ allowed: true,
451
+ mode: policy.mode === "auto" ? "auto" : "propose",
452
+ economics,
453
+ reason: economics.isDowngrade ? `Downgrade to "${request.toTier}" saves about $${economics.projectedSavingsUsd.toFixed(4)} over ${projectedTurns} turn(s) after a $${economics.reWarmCostUsd.toFixed(4)} re-warm.` : `Upgrade to "${request.toTier}" costs about $${(-economics.projectedSavingsUsd).toFixed(4)} over ${projectedTurns} turn(s), including a $${economics.reWarmCostUsd.toFixed(4)} re-warm.`
454
+ };
455
+ }
456
+
457
+ export {
458
+ MATRIX_PHASE_KEYS,
459
+ phaseForRole,
460
+ resolveModelMatrixResolution,
461
+ resolveModelMatrix,
462
+ resolveModelTargetFromEntry,
463
+ roleNeedsIndependentReviewModel,
464
+ resolveSubagentModelTarget,
465
+ resolveImplementationModelTarget,
466
+ sameModelReference,
467
+ matrixKeyKind,
468
+ isValidMatrixKey,
469
+ DEFAULT_TIER_ID,
470
+ activeTierConfig,
471
+ listTierIds,
472
+ tierLevel,
473
+ isConfiguredTier,
474
+ classifyTier,
475
+ tierBudget,
476
+ tierModelTarget,
477
+ resolveTier,
478
+ applyTierToSubagentConfig,
479
+ leaderTierPolicy,
480
+ tierRank,
481
+ evaluateSwitchEconomics,
482
+ evaluateLeaderTierSwitch
483
+ };
484
+ //# sourceMappingURL=chunk-RTOTNK3P.js.map
@@ -6,25 +6,25 @@ import {
6
6
  } from "./chunk-XEBHSJLT.js";
7
7
  import {
8
8
  atomicWrite
9
- } from "./chunk-7ZHZE5EO.js";
9
+ } from "./chunk-OSGLYW5J.js";
10
10
  import {
11
11
  isValidSkillNameFormat,
12
12
  parseSkillFrontmatter,
13
13
  validateSkillName
14
- } from "./chunk-WEBMSQP2.js";
14
+ } from "./chunk-FC2ZGRF3.js";
15
+ import {
16
+ expectDefined
17
+ } from "./chunk-PFZO3C6H.js";
15
18
  import {
16
19
  ERROR_CODES,
17
20
  FetchError,
18
21
  FsError,
19
22
  ParseError,
20
23
  WrongStackError
21
- } from "./chunk-WOEZV3Q4.js";
24
+ } from "./chunk-25LSLC3G.js";
22
25
  import {
23
26
  toErrorMessage
24
27
  } from "./chunk-TBRL2RCC.js";
25
- import {
26
- expectDefined
27
- } from "./chunk-PFZO3C6H.js";
28
28
 
29
29
  // src/skills/registry/github-direct-adapter.ts
30
30
  var githubDirectAdapter = {
@@ -1169,4 +1169,4 @@ export {
1169
1169
  SkillManifestStore,
1170
1170
  SkillInstaller
1171
1171
  };
1172
- //# sourceMappingURL=chunk-SN2DQRL6.js.map
1172
+ //# sourceMappingURL=chunk-RXKSDUAU.js.map