@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
@@ -2,7 +2,11 @@
2
2
  import * as dns from "node:dns/promises";
3
3
  import * as net from "node:net";
4
4
  function isPrivateIPv4(addr) {
5
- const parts = addr.split(".").map((p) => Number.parseInt(p, 10));
5
+ const parts = addr.split(".").map((p) => {
6
+ if (!/^\d+$/.test(p)) return Number.NaN;
7
+ if (p.length > 1 && p.startsWith("0")) return Number.NaN;
8
+ return Number.parseInt(p, 10);
9
+ });
6
10
  if (parts.length !== 4 || parts.some((n) => Number.isNaN(n) || n < 0 || n > 255)) {
7
11
  return true;
8
12
  }
@@ -122,4 +126,4 @@ export {
122
126
  expandIPv6,
123
127
  assertNotPrivateHost
124
128
  };
125
- //# sourceMappingURL=chunk-GFJOMSHG.js.map
129
+ //# sourceMappingURL=chunk-LA7CLDRW.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-PFZO3C6H.js";
4
4
 
5
5
  // src/utils/message-invariants.ts
6
- function repairToolUseAdjacency(messages) {
6
+ function repairToolUseAdjacency(messages, opts = {}) {
7
7
  const removedToolUses = [];
8
8
  const removedToolResults = [];
9
9
  let removedMessages = 0;
@@ -17,7 +17,8 @@ function repairToolUseAdjacency(messages) {
17
17
  const filtered = mapContent(msg, (blocks) => {
18
18
  const next = [];
19
19
  for (const block of blocks) {
20
- if (block.type === "tool_use" && !nextIds.has(block.id)) {
20
+ const preserveTrailing = opts.preserveTrailingToolUse === true && i === messages.length - 1 && block.type === "tool_use";
21
+ if (block.type === "tool_use" && !nextIds.has(block.id) && !preserveTrailing) {
21
22
  removedToolUses.push(block.id);
22
23
  changed = true;
23
24
  continue;
@@ -90,8 +91,11 @@ function mapContent(msg, fn) {
90
91
  return { ...msg, content: next };
91
92
  }
92
93
  function hasMeaningfulContent(content) {
94
+ if (!content) return false;
93
95
  if (typeof content === "string") return content.trim().length > 0;
96
+ if (!Array.isArray(content)) return false;
94
97
  for (const block of content) {
98
+ if (!block || typeof block !== "object") continue;
95
99
  if (block.type === "text") {
96
100
  if (block.text.trim().length > 0) return true;
97
101
  continue;
@@ -112,4 +116,4 @@ export {
112
116
  repairToolUseAdjacency,
113
117
  hasMeaningfulContent
114
118
  };
115
- //# sourceMappingURL=chunk-M2WF6AXG.js.map
119
+ //# sourceMappingURL=chunk-LSMMOS2Z.js.map
@@ -11,10 +11,10 @@ import {
11
11
  encodeChronicleProjectServerMessage,
12
12
  importLegacyChronicleJournal,
13
13
  resolveChronicleRuntimeLocation
14
- } from "./chunk-AT4V4XGI.js";
14
+ } from "./chunk-4BMVPOHO.js";
15
15
  import {
16
16
  resolveWstackPaths
17
- } from "./chunk-YNCVSFGF.js";
17
+ } from "./chunk-SAFHACFA.js";
18
18
 
19
19
  // src/chronicle/project-server-client.ts
20
20
  import { spawn } from "node:child_process";
@@ -786,4 +786,4 @@ export {
786
786
  createChronicleProjectAccess,
787
787
  createChronicleEventJournal
788
788
  };
789
- //# sourceMappingURL=chunk-ASX6AW36.js.map
789
+ //# sourceMappingURL=chunk-LXWCMQNJ.js.map
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-XEBHSJLT.js";
4
4
  import {
5
5
  buildChildEnv
6
- } from "./chunk-VB3H5WWB.js";
6
+ } from "./chunk-6NWEVFEL.js";
7
7
  import {
8
8
  hasMeaningfulContent,
9
9
  repairToolUseAdjacency
10
- } from "./chunk-M2WF6AXG.js";
10
+ } from "./chunk-LSMMOS2Z.js";
11
11
  import {
12
12
  color
13
13
  } from "./chunk-4VWO3ZXL.js";
@@ -17,19 +17,19 @@ import {
17
17
  buildConversationContinuityBlock,
18
18
  markAssistantReferencedEvidence,
19
19
  resolveEventSessionId
20
- } from "./chunk-EFEHDQGY.js";
20
+ } from "./chunk-ZHZ2Y2DH.js";
21
+ import {
22
+ stripFrontmatter
23
+ } from "./chunk-FC2ZGRF3.js";
21
24
  import {
22
25
  RUNTIME_CAPABILITY_MANIFEST,
23
26
  missingRequiredRuntimeTools,
24
27
  missingRuntimeCapabilities,
25
28
  runtimeToolReferencesFromText
26
- } from "./chunk-AWNQ6ED6.js";
27
- import {
28
- stripFrontmatter
29
- } from "./chunk-WEBMSQP2.js";
29
+ } from "./chunk-THEGTRAG.js";
30
30
  import {
31
31
  flattenSystemPromptRegions
32
- } from "./chunk-CB2HFKTP.js";
32
+ } from "./chunk-VVBP6KGT.js";
33
33
  import {
34
34
  resolveTokenSavingTier
35
35
  } from "./chunk-KJ2ZTQSL.js";
@@ -1256,7 +1256,8 @@ var DefaultSystemPromptBuilder = class {
1256
1256
  * join, leave, or change status.
1257
1257
  */
1258
1258
  _toolsUsageCache;
1259
- _instructionBundle;
1259
+ /** Instruction bundle per identity variant — see `instructions()`. */
1260
+ _instructionBundles = /* @__PURE__ */ new Map();
1260
1261
  /**
1261
1262
  * Cached rendered identity layer. Keyed the same way as `_toolsUsageCache`:
1262
1263
  * the ToolRegistry snapshot keeps the array reference stable until a registry
@@ -1344,7 +1345,7 @@ var DefaultSystemPromptBuilder = class {
1344
1345
  } else {
1345
1346
  this.skillCache = "";
1346
1347
  }
1347
- const instructions = await this.instructions();
1348
+ const instructions = await this.instructions(ctx.systemVariant);
1348
1349
  const tplCtx = this.templateContext(ctx);
1349
1350
  const layer1 = this.buildIdentity(instructions, tplCtx, ctx);
1350
1351
  const layer2 = await this.buildToolUsage(ctx.tools, ctx, tplCtx);
@@ -1497,13 +1498,27 @@ ${peers}
1497
1498
  };
1498
1499
  return text;
1499
1500
  }
1500
- async instructions() {
1501
- if (!this._instructionBundle) {
1502
- this._instructionBundle = loadInstructionBundle(this.opts.instructionPaths).then(
1503
- (bundle) => this.opts.instructionBundle ? mergeInstructionBundle(bundle, this.opts.instructionBundle) : bundle
1504
- );
1505
- }
1506
- return this._instructionBundle;
1501
+ /**
1502
+ * The instruction bundle for one identity variant.
1503
+ *
1504
+ * Cached per variant rather than once for the builder: four conversations
1505
+ * share this instance and each picks its own identity, so a single memoised
1506
+ * bundle handed whichever variant loaded first to all of them. At most three
1507
+ * entries exist ('default' | 'lite' | 'pro').
1508
+ */
1509
+ async instructions(variant) {
1510
+ const paths = this.opts.instructionPaths;
1511
+ const effective = variant ?? paths?.systemVariant;
1512
+ const key = effective ?? "default";
1513
+ const cached = this._instructionBundles.get(key);
1514
+ if (cached) return cached;
1515
+ const loading = loadInstructionBundle(
1516
+ paths ? { ...paths, ...effective ? { systemVariant: effective } : {} } : paths
1517
+ ).then(
1518
+ (bundle) => this.opts.instructionBundle ? mergeInstructionBundle(bundle, this.opts.instructionBundle) : bundle
1519
+ );
1520
+ this._instructionBundles.set(key, loading);
1521
+ return loading;
1507
1522
  }
1508
1523
  /**
1509
1524
  * Cached plan content keyed by (planPath, mtimeMs). The plan is read
@@ -1530,7 +1545,7 @@ ${peers}
1530
1545
  }
1531
1546
  async buildToolUsage(tools, ctx, tplCtx) {
1532
1547
  if (tools.length === 0) return "## Tool usage\n\nNo tools registered.";
1533
- const instructions = await this.instructions();
1548
+ const instructions = await this.instructions(ctx.systemVariant);
1534
1549
  const tpl = tplCtx ?? this.templateContext(ctx);
1535
1550
  const section = (key, vars = {}) => instructionSection(instructions, key, vars, tpl);
1536
1551
  const tier = this.tier;
@@ -1633,6 +1648,12 @@ ${hint.trim()}`);
1633
1648
  if (mailbox) lines.push(mailbox);
1634
1649
  }
1635
1650
  }
1651
+ if (tools.some((t) => t.name === "session_note")) {
1652
+ const sessionNote = section(
1653
+ this.tier === "off" ? "tool.session.note.full" : "tool.session.note.compact"
1654
+ );
1655
+ if (sessionNote) lines.push(sessionNote);
1656
+ }
1636
1657
  const hasGitTool = tools.some((t) => t.name === "git");
1637
1658
  if (hasGitTool && this.tier !== "minimal" && this.tier !== "light" && this.tier !== "aggressive") {
1638
1659
  const commitHygiene = section("tool.commit.hygiene");
@@ -2425,12 +2446,27 @@ function sizeSignals(toolName, content) {
2425
2446
  return { outputBytes, outputTokens, outputLines };
2426
2447
  }
2427
2448
 
2449
+ // src/core/request-conversation-binding.ts
2450
+ var requestConversations = /* @__PURE__ */ new WeakMap();
2451
+ function bindRequestConversation(request, conversation) {
2452
+ requestConversations.set(request, conversation);
2453
+ }
2454
+ function conversationBoundToRequest(request) {
2455
+ return requestConversations.get(request);
2456
+ }
2457
+ function inheritRequestConversation(from, to) {
2458
+ if (from === to) return;
2459
+ const conversation = requestConversations.get(from);
2460
+ if (conversation) requestConversations.set(to, conversation);
2461
+ }
2462
+
2428
2463
  // src/core/agent-response.ts
2429
2464
  var MAX_TODO_SNAPSHOT_ITEMS = 10;
2430
2465
  var MAX_TODO_SNAPSHOT_CONTENT = 180;
2431
2466
  function buildLiveNextStepsGateBlock(ctx) {
2432
2467
  if (ctx.agentId !== "leader") return void 0;
2433
- const openTodos = ctx.todos.filter(
2468
+ const todos = Array.isArray(ctx.todos) ? ctx.todos : [];
2469
+ const openTodos = todos.filter(
2434
2470
  (todo) => todo.status === "pending" || todo.status === "in_progress"
2435
2471
  );
2436
2472
  if (openTodos.length === 0) {
@@ -2615,7 +2651,10 @@ function createAgentResponseHandler(a) {
2615
2651
  ...repaired.report
2616
2652
  });
2617
2653
  a.logger.warn(
2618
- `Repaired context tool adjacency: removed ${repaired.report.removedToolUses.length} tool_use block(s), ${repaired.report.removedToolResults.length} tool_result block(s), ${repaired.report.removedMessages} empty message(s)` + formatAdjacencyRepairIds(repaired.report.removedToolUses, repaired.report.removedToolResults)
2654
+ `Repaired context tool adjacency: removed ${repaired.report.removedToolUses.length} tool_use block(s), ${repaired.report.removedToolResults.length} tool_result block(s), ${repaired.report.removedMessages} empty message(s)` + formatAdjacencyRepairIds(
2655
+ repaired.report.removedToolUses,
2656
+ repaired.report.removedToolResults
2657
+ )
2619
2658
  );
2620
2659
  }
2621
2660
  }
@@ -2662,7 +2701,10 @@ function createAgentResponseHandler(a) {
2662
2701
  // partition when the actual prefix bytes did not change.
2663
2702
  cache: { key: deriveCachePrefixKey(stableSystem) }
2664
2703
  };
2704
+ bindRequestConversation(baseReq, a.ctx);
2705
+ bindRequestProvider(baseReq, provider);
2665
2706
  const request = await a.pipelines.request.run(baseReq);
2707
+ bindRequestConversation(request, a.ctx);
2666
2708
  bindRequestProvider(request, provider);
2667
2709
  return { request, provider };
2668
2710
  }
@@ -2685,7 +2727,13 @@ function createAgentResponseHandler(a) {
2685
2727
  ts: (/* @__PURE__ */ new Date()).toISOString(),
2686
2728
  content: res.content,
2687
2729
  stopReason: res.stopReason,
2688
- usage: res.usage
2730
+ usage: res.usage,
2731
+ // Stamp the routed identity alongside the usage it produced. Both are
2732
+ // already resolved here (they are what tokenCounter.account was just
2733
+ // handed), and without them the journal's only token record is
2734
+ // unattributable — see the `model`/`provider` docs on SessionEvent.
2735
+ model: req.model,
2736
+ provider: requestProvider.id
2689
2737
  });
2690
2738
  a.ctx.state.appendMessage({ role: "assistant", content: res.content });
2691
2739
  if (!a.ctx.toolAdjacencyDirty) {
@@ -2761,6 +2809,8 @@ export {
2761
2809
  hasNextStepsTag,
2762
2810
  renderNextStepsBlock,
2763
2811
  maybeAppendPendingNextSteps,
2812
+ conversationBoundToRequest,
2813
+ inheritRequestConversation,
2764
2814
  renderInstructionLayer,
2765
2815
  SYSTEM_BLOCK_SOURCE,
2766
2816
  buildLiveNextStepsGateBlock,
@@ -2776,4 +2826,4 @@ export {
2776
2826
  truncateForEvent,
2777
2827
  sizeSignals
2778
2828
  };
2779
- //# sourceMappingURL=chunk-WZO23AWO.js.map
2829
+ //# sourceMappingURL=chunk-M27LIEKV.js.map
@@ -1,39 +1,39 @@
1
1
  import {
2
2
  DefaultConfigLoader
3
- } from "./chunk-IQ35HMQL.js";
3
+ } from "./chunk-5YPSXQXM.js";
4
4
  import {
5
5
  DefaultSecretVault,
6
6
  migratePlaintextSecrets
7
- } from "./chunk-6AKOTGLM.js";
7
+ } from "./chunk-CU546ESW.js";
8
8
  import {
9
9
  DefaultLogger,
10
10
  noOpLogger
11
11
  } from "./chunk-WBPVKEEE.js";
12
- import {
13
- promptCacheHitRatio
14
- } from "./chunk-NFAYHPRH.js";
15
12
  import {
16
13
  activateProjectStateGuard
17
- } from "./chunk-CQQL4ZOQ.js";
14
+ } from "./chunk-ZT7JNIGX.js";
18
15
  import {
19
16
  safeParse
20
- } from "./chunk-RPOA7IAE.js";
17
+ } from "./chunk-W5VITDM2.js";
18
+ import {
19
+ writeErr
20
+ } from "./chunk-4VWO3ZXL.js";
21
21
  import {
22
22
  ensureProjectGitignore,
23
23
  ensureProjectIdentity,
24
24
  readProjectIdentity
25
- } from "./chunk-4XV6IR37.js";
26
- import {
27
- writeErr
28
- } from "./chunk-4VWO3ZXL.js";
25
+ } from "./chunk-HI3JGZR2.js";
29
26
  import {
30
27
  atomicWrite
31
- } from "./chunk-7ZHZE5EO.js";
28
+ } from "./chunk-OSGLYW5J.js";
32
29
  import {
33
30
  canonicalProjectRoot,
34
31
  resolveWstackPaths,
35
32
  safeProfileName
36
- } from "./chunk-YNCVSFGF.js";
33
+ } from "./chunk-SAFHACFA.js";
34
+ import {
35
+ promptCacheHitRatio
36
+ } from "./chunk-3ECENVHL.js";
37
37
  import {
38
38
  normalizeTokenSavingTier
39
39
  } from "./chunk-KJ2ZTQSL.js";
@@ -242,7 +242,7 @@ async function bootConfig(options = {}) {
242
242
  }
243
243
  const logger = new DefaultLogger({ level: config.log?.level ?? "info", file: wpaths.logFile });
244
244
  try {
245
- const { getProjectSessionRegistry } = await import("./registry-R23UBE7H.js");
245
+ const { getProjectSessionRegistry } = await import("./registry-7N4O3E7W.js");
246
246
  getProjectSessionRegistry(wpaths.globalRoot);
247
247
  } catch {
248
248
  }
@@ -660,4 +660,4 @@ export {
660
660
  assertProjectRootOutsideStateDir,
661
661
  ProviderCacheLedger
662
662
  };
663
- //# sourceMappingURL=chunk-JTHKOYWU.js.map
663
+ //# sourceMappingURL=chunk-MJPHJRAL.js.map
@@ -1,10 +1,10 @@
1
- import {
2
- ERROR_CODES,
3
- WrongStackError
4
- } from "./chunk-WOEZV3Q4.js";
5
1
  import {
6
2
  expectDefined
7
3
  } from "./chunk-PFZO3C6H.js";
4
+ import {
5
+ ERROR_CODES,
6
+ WrongStackError
7
+ } from "./chunk-25LSLC3G.js";
8
8
 
9
9
  // src/extension/registry.ts
10
10
  var ExtensionRegistry = class {
@@ -225,4 +225,4 @@ var ExtensionRegistry = class {
225
225
  export {
226
226
  ExtensionRegistry
227
227
  };
228
- //# sourceMappingURL=chunk-G5AAKEEZ.js.map
228
+ //# sourceMappingURL=chunk-MTL4O5YR.js.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-NHJ75HXY.js.map
@@ -6,26 +6,26 @@ import {
6
6
  } from "./chunk-Z2IJUO45.js";
7
7
  import {
8
8
  SESSION_RECIPIENT_PREFIX
9
- } from "./chunk-W4A6QA3D.js";
9
+ } from "./chunk-FWNLEZYG.js";
10
+ import {
11
+ DefaultSecretScrubber
12
+ } from "./chunk-QSTSJOCK.js";
10
13
  import {
11
14
  SECRET_FILE_MODE,
12
15
  restrictFilePermissions
13
- } from "./chunk-H5E77KUJ.js";
14
- import {
15
- DefaultSecretScrubber
16
- } from "./chunk-3E244UDA.js";
16
+ } from "./chunk-6FHWXLPT.js";
17
17
  import {
18
18
  readProjectIdentitySync
19
- } from "./chunk-4XV6IR37.js";
19
+ } from "./chunk-HI3JGZR2.js";
20
20
  import {
21
21
  isPidAlive
22
22
  } from "./chunk-TRT2HRWZ.js";
23
23
  import {
24
24
  atomicWrite
25
- } from "./chunk-7ZHZE5EO.js";
25
+ } from "./chunk-OSGLYW5J.js";
26
26
  import {
27
27
  wstackGlobalRoot
28
- } from "./chunk-YNCVSFGF.js";
28
+ } from "./chunk-SAFHACFA.js";
29
29
 
30
30
  // src/hq/auth-audit.ts
31
31
  import { appendFileSync, readFileSync, mkdirSync } from "node:fs";
@@ -774,7 +774,10 @@ var DEFAULT_MAX_QUEUED_BYTES = Math.min(
774
774
  var DEFAULT_COMMAND_POLL_INTERVAL_MS = 500;
775
775
  var DEFAULT_COMMAND_POLL_LIMIT = 25;
776
776
  var DEFAULT_HEARTBEAT_INTERVAL_MS = 25e3;
777
- var lastConnectWarningAtMs = 0;
777
+ var warnedEndpoints = /* @__PURE__ */ new Set();
778
+ function resetHqPublisherWarningStateForTests() {
779
+ warnedEndpoints.clear();
780
+ }
778
781
  function queuedFrameCoalesceKey(frame) {
779
782
  if (frame.type !== "client.event" || !frame.event.type.endsWith(".snapshot")) {
780
783
  return void 0;
@@ -901,6 +904,13 @@ var HqPublisher = class {
901
904
  this.socket = socket;
902
905
  const onOpen = () => {
903
906
  this.reconnectAttempt = 0;
907
+ this.connectWarningEmitted = false;
908
+ if (this.lastAttempt?.url) {
909
+ warnedEndpoints.delete(this.lastAttempt.url);
910
+ }
911
+ if (this.options.url) {
912
+ warnedEndpoints.delete(this.options.url);
913
+ }
904
914
  this.sendHelloNow();
905
915
  this.flushQueue();
906
916
  this.startHeartbeat();
@@ -1261,7 +1271,8 @@ var HqPublisher = class {
1261
1271
  const delay = Math.min(this.reconnectMaxMs, this.reconnectBaseMs * 2 ** this.reconnectAttempt);
1262
1272
  this.reconnectAttempt += 1;
1263
1273
  if (!this.connectWarningEmitted && this.reconnectAttempt >= this.connectWarnAfterFailures) {
1264
- if (this.emitConnectWarning()) this.connectWarningEmitted = true;
1274
+ this.connectWarningEmitted = true;
1275
+ this.emitConnectWarning();
1265
1276
  }
1266
1277
  this.reconnectTimer = setTimeout(() => {
1267
1278
  this.reconnectTimer = null;
@@ -1270,11 +1281,13 @@ var HqPublisher = class {
1270
1281
  this.reconnectTimer.unref?.();
1271
1282
  }
1272
1283
  emitConnectWarning() {
1273
- const nowMs = Date.now();
1274
- if (nowMs - lastConnectWarningAtMs < this.connectWarnCooldownMs) {
1275
- return false;
1284
+ const targetUrl = this.lastAttempt?.url ?? this.options.url;
1285
+ if (this.connectWarnCooldownMs > 0) {
1286
+ if (warnedEndpoints.has(targetUrl)) {
1287
+ return false;
1288
+ }
1289
+ warnedEndpoints.add(targetUrl);
1276
1290
  }
1277
- lastConnectWarningAtMs = nowMs;
1278
1291
  const attempt = this.lastAttempt;
1279
1292
  const message = `WrongStack HQ publisher: ${this.reconnectAttempt} consecutive connection failures${attempt !== null ? ` to ${attempt.url} (client token ${attempt.hadToken ? "present" : "absent"})` : ""}. Either the HQ server is unreachable or it rejected the token (401). If HQ runs in client-token mode, verify WRONGSTACK_HQ_TOKEN / auth.json. Retries continue with backoff.`;
1280
1293
  if (this.logger) {
@@ -1486,6 +1499,7 @@ export {
1486
1499
  createMailboxSnapshotPayload,
1487
1500
  createMailboxSnapshotPayloadFromMailbox,
1488
1501
  createMailboxEventPayload,
1502
+ resetHqPublisherWarningStateForTests,
1489
1503
  HqPublisher,
1490
1504
  discoverLocalHqEndpoint,
1491
1505
  resolveHqConfigFromEnv,
@@ -1493,4 +1507,4 @@ export {
1493
1507
  deriveHqProjectId,
1494
1508
  createHqPublisherFromEnv
1495
1509
  };
1496
- //# sourceMappingURL=chunk-ZYU2YOJ6.js.map
1510
+ //# sourceMappingURL=chunk-NIOAGFPB.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ERROR_CODES,
3
3
  WrongStackError
4
- } from "./chunk-WOEZV3Q4.js";
4
+ } from "./chunk-25LSLC3G.js";
5
5
  import {
6
6
  toErrorMessage
7
7
  } from "./chunk-TBRL2RCC.js";
@@ -352,4 +352,4 @@ export {
352
352
  TOKENS,
353
353
  Pipeline
354
354
  };
355
- //# sourceMappingURL=chunk-Y2GE5TSI.js.map
355
+ //# sourceMappingURL=chunk-NS52ISWS.js.map