@iowarp/clio-coder 0.3.2 → 0.3.4

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 (259) hide show
  1. package/CHANGELOG.md +269 -458
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +3 -3
  4. package/dist/{acp-BIYHVZIM.js → acp-S5R4RR5B.js} +7 -6
  5. package/dist/{agents-YT6SSRIT.js → agents-P6DMMVZY.js} +24 -21
  6. package/dist/assets/codewiki.json +1 -1
  7. package/dist/{auth-5TWEIYDN.js → auth-2XCZLPKS.js} +12 -8
  8. package/dist/{chunk-GGXXDWE4.js → chunk-22NAGB7X.js} +2 -2
  9. package/dist/{chunk-WMSVI4G2.js → chunk-2LZI5CAG.js} +133 -13
  10. package/dist/{chunk-OAO4GE4M.js → chunk-2TZWSW76.js} +2 -2
  11. package/dist/{chunk-OOJYHWRB.js → chunk-34475P3I.js} +2 -2
  12. package/dist/{chunk-WVO7V2QY.js → chunk-35MKKU5R.js} +4 -4
  13. package/dist/{chunk-LBNRH5WM.js → chunk-3HZ5RWN2.js} +5 -5
  14. package/dist/{chunk-AGYYIBLL.js → chunk-3JLKSKD7.js} +2 -2
  15. package/dist/{chunk-MBS4V7ZP.js → chunk-4JUF2NNX.js} +7 -7
  16. package/dist/{chunk-ZDOOVTXZ.js → chunk-4OC57DA6.js} +27 -4
  17. package/dist/chunk-5M54SPOL.js +926 -0
  18. package/dist/{chunk-STBPMHSX.js → chunk-7RXG6QRZ.js} +51 -11
  19. package/dist/{chunk-77VKQEHF.js → chunk-A2GZF7DC.js} +5 -5
  20. package/dist/{chunk-A3CYT5EX.js → chunk-AD2SYQYC.js} +55 -2
  21. package/dist/chunk-AOCYTWAV.js +449 -0
  22. package/dist/chunk-BEY543CS.js +258 -0
  23. package/dist/{chunk-6N5PTWMY.js → chunk-BP4OYD6A.js} +32 -13
  24. package/dist/chunk-BPGS2WCQ.js +612 -0
  25. package/dist/{chunk-J5HN4RYU.js → chunk-BRXQQJFP.js} +8 -8
  26. package/dist/chunk-CFGTUFWB.js +67 -0
  27. package/dist/{chunk-CBCAPZAA.js → chunk-E25LMLRW.js} +2 -2
  28. package/dist/{chunk-G2DE3C7R.js → chunk-EDRHSCIE.js} +4 -4
  29. package/dist/{chunk-4KLWL3UC.js → chunk-EFADSJET.js} +2 -2
  30. package/dist/{chunk-M6SHUN7Q.js → chunk-FO5ZOVUY.js} +2 -2
  31. package/dist/chunk-FYYLNIL5.js +313 -0
  32. package/dist/{chunk-EPVUXGXG.js → chunk-HV5X7OR2.js} +14 -12
  33. package/dist/{chunk-TZTZS7QK.js → chunk-HXG4IURW.js} +5 -3
  34. package/dist/{chunk-IGLFWIYI.js → chunk-K6WL7QZT.js} +3 -3
  35. package/dist/chunk-K7VKOLQQ.js +15 -0
  36. package/dist/{chunk-BMEMKKIT.js → chunk-KOHPCX4K.js} +2 -2
  37. package/dist/{chunk-V4RXGQ5Q.js → chunk-KRPY7NTG.js} +10 -7
  38. package/dist/chunk-LL4KHSZI.js +22 -0
  39. package/dist/{chunk-KJ5LWLOE.js → chunk-MEQ45TQ4.js} +15 -9
  40. package/dist/{chunk-5UUP6MWO.js → chunk-MV3K5QF2.js} +5 -436
  41. package/dist/{chunk-AO4RKG4M.js → chunk-N4CZJQRK.js} +5 -5
  42. package/dist/{chunk-ARBGF5F7.js → chunk-NILBFAPG.js} +14 -8
  43. package/dist/chunk-OZNBF4L3.js +23 -0
  44. package/dist/{verify-G6V4D2G7.js → chunk-PCZJO5TI.js} +127 -42
  45. package/dist/chunk-QQK64KLB.js +1360 -0
  46. package/dist/{chunk-6EJV5X2W.js → chunk-QQL5RT5M.js} +979 -1619
  47. package/dist/{chunk-LZSJBIVT.js → chunk-QWU7ZBO7.js} +70 -720
  48. package/dist/{chunk-2EHAIA3X.js → chunk-RD5U66HV.js} +3 -3
  49. package/dist/{chunk-OKGUZO2U.js → chunk-SPULKLCF.js} +4 -3
  50. package/dist/{chunk-OQ33BKR3.js → chunk-TTNYS3EA.js} +3 -60
  51. package/dist/chunk-TW3WDMVS.js +677 -0
  52. package/dist/chunk-TZSKNMZG.js +434 -0
  53. package/dist/{chunk-7MNJORFF.js → chunk-UL3WSD3F.js} +6 -1
  54. package/dist/{chunk-7EYHLWU7.js → chunk-UZHIZC5S.js} +7 -7
  55. package/dist/{chunk-QTYWRVRA.js → chunk-VAWWTKDP.js} +8 -8
  56. package/dist/{chunk-X75S7HFS.js → chunk-VEZEGCGW.js} +214 -20
  57. package/dist/{chunk-OHHN2SO4.js → chunk-VMNQ6OZA.js} +98 -202
  58. package/dist/chunk-VSNATDE6.js +122 -0
  59. package/dist/chunk-W6GROXXM.js +69 -0
  60. package/dist/chunk-WPQLXFOZ.js +375 -0
  61. package/dist/{chunk-ORBHGJC5.js → chunk-WR67VIZY.js} +3 -3
  62. package/dist/{chunk-3ZXDFGR5.js → chunk-X6COSD2O.js} +5 -5
  63. package/dist/chunk-ZGVHUX3M.js +66 -0
  64. package/dist/{chunk-MAW544W2.js → chunk-ZWMF7253.js} +4 -4
  65. package/dist/{chunk-MQSRRFWA.js → chunk-ZYKPLLNQ.js} +563 -546
  66. package/dist/cli/index.js +27 -23
  67. package/dist/{clio-4LY5K2AC.js → clio-J5JIOIDS.js} +7 -6
  68. package/dist/{code-nav-7AX6FYE6.js → code-nav-AXCXSBHX.js} +5 -3
  69. package/dist/{config-GTLUW2PR.js → config-OEBMIN2U.js} +37 -27
  70. package/dist/{configure-R6A64DHX.js → configure-PUQOSIXQ.js} +16 -13
  71. package/dist/{context-5VKGUVJJ.js → context-EKDCKUUZ.js} +82 -7
  72. package/dist/{context-RW5HC47S.js → context-MGSE4Z2T.js} +33 -23
  73. package/dist/{context-JFZEJ7W5.js → context-URSXPBCK.js} +17 -9
  74. package/dist/{context-clear-6ZHBAZZT.js → context-clear-KDAJRNUK.js} +33 -23
  75. package/dist/context-working-set-SBKMPPI2.js +1552 -0
  76. package/dist/{dispatch-runner-VKBRCWQC.js → dispatch-runner-MSWN72NK.js} +43 -29
  77. package/dist/{doctor-KI767GSN.js → doctor-7BSE27PJ.js} +10 -10
  78. package/dist/{eval-XSSNATB4.js → eval-IZGDOO4H.js} +9 -8
  79. package/dist/{evidence-UA6AWDQQ.js → evidence-SR7WXB5B.js} +51 -23
  80. package/dist/{evolve-QNTFGV6Z.js → evolve-K7VE2CBX.js} +30 -20
  81. package/dist/{fleet-Q7UOMUSG.js → fleet-7XMJNQNF.js} +48 -38
  82. package/dist/{fleet-preflight-DDN536IT.js → fleet-preflight-AQNAH644.js} +3 -3
  83. package/dist/{init-WBB65ZHQ.js → init-JGNPAYXT.js} +41 -31
  84. package/dist/{memory-MD3O64RI.js → memory-4ALKDJ4Q.js} +32 -22
  85. package/dist/{models-BZU34YWD.js → models-ZMMLFJNN.js} +22 -19
  86. package/dist/{monitor-MEQA5C3I.js → monitor-2F3T5KHP.js} +55 -43
  87. package/dist/{orchestrator-CGFKEP27.js → orchestrator-ORHT43JB.js} +2507 -1896
  88. package/dist/{reset-L2FQEE3E.js → reset-NXGTYNUO.js} +4 -3
  89. package/dist/{run-IV4Q6RLN.js → run-RF4WJGMT.js} +51 -41
  90. package/dist/{share-S5BZQC5I.js → share-UT3W6E4M.js} +5 -4
  91. package/dist/{skills-LQEKRDTN.js → skills-PSACKC5Q.js} +2 -2
  92. package/dist/{skills-eval-3DC4HEWS.js → skills-eval-WJSI55RZ.js} +34 -24
  93. package/dist/{targets-C4SSGQOB.js → targets-PIIRAOYS.js} +23 -20
  94. package/dist/{terminal-lease-IT5JW2NR.js → terminal-lease-ULWXWNVY.js} +5 -4
  95. package/dist/{upgrade-7TT7SQ3G.js → upgrade-346TZ6AV.js} +18 -17
  96. package/dist/{usage-GV4PKT3M.js → usage-6KKXR32N.js} +34 -24
  97. package/dist/verifiers-4UUM6TEE.js +1214 -0
  98. package/dist/verify-X5HDROLA.js +25 -0
  99. package/dist/{wiki-generate-DQF6Z66B.js → wiki-generate-7STOCIFZ.js} +42 -31
  100. package/dist/worker/entry.js +33 -24
  101. package/docs/README.md +8 -7
  102. package/docs/acp.md +1 -1
  103. package/docs/alcf-provider.md +1 -1
  104. package/docs/architecture.md +2 -2
  105. package/docs/artifact-versions.md +1 -1
  106. package/docs/built-in-agents.md +1 -1
  107. package/docs/capacity-and-scheduling.md +1 -1
  108. package/docs/commands-and-modes.md +53 -21
  109. package/docs/config-knobs-audit.md +1 -2
  110. package/docs/configuration-and-targets.md +15 -1
  111. package/docs/context-engine.md +64 -12
  112. package/docs/context-working-set.md +194 -0
  113. package/docs/development-pipeline.md +1 -1
  114. package/docs/documentation-coverage.md +5 -5
  115. package/docs/documentation-guide.md +6 -5
  116. package/docs/environment-variables.md +2 -1
  117. package/docs/eval-runner.md +1 -1
  118. package/docs/evals-internal.md +14 -1
  119. package/docs/evidence-and-memory.md +74 -2
  120. package/docs/evolution.md +1 -1
  121. package/docs/exit-codes-and-output.md +1 -1
  122. package/docs/extensions-and-sharing.md +2 -2
  123. package/docs/fleet-dispatch.md +22 -7
  124. package/docs/glossary.md +21 -1
  125. package/docs/installation-and-lifecycle.md +6 -6
  126. package/docs/middleware-and-components.md +1 -1
  127. package/docs/model-catalog.md +7 -9
  128. package/docs/observability.md +4 -4
  129. package/docs/performance-methodology.md +2 -2
  130. package/docs/proactive-memory.md +1 -1
  131. package/docs/prompt-envelope-and-tools.md +4 -4
  132. package/docs/provider-adapter-cookbook.md +1 -1
  133. package/docs/release-cut-checklist.md +35 -35
  134. package/docs/safety-model.md +23 -4
  135. package/docs/scientific-validation.md +21 -3
  136. package/docs/session-lifecycle.md +3 -3
  137. package/docs/skills-marketplace.md +1 -1
  138. package/docs/tool-usage.md +79 -12
  139. package/docs/trace-store.md +1 -1
  140. package/docs/troubleshooting.md +1 -1
  141. package/docs/tui-design.md +2 -2
  142. package/docs/worker-dispatch-mechanics.md +11 -1
  143. package/package.json +8 -11
  144. package/skills/meta/clio-test/SKILL.md +20 -17
  145. package/skills/meta/clio-test/evals.md +3 -3
  146. package/skills/meta/clio-test/references/harness.md +35 -6
  147. package/skills/meta/clio-test/references/test-map.md +20 -10
  148. package/skills/registry.yaml +2 -2
  149. package/skills/skill-marketplace.json +1 -1
  150. package/src/cli/context-working-set.ts +513 -0
  151. package/src/cli/context.ts +8 -0
  152. package/src/cli/evidence.ts +20 -2
  153. package/src/cli/index.ts +4 -0
  154. package/src/cli/verifiers.ts +325 -0
  155. package/src/core/bash-exec.ts +39 -14
  156. package/src/core/bus-events.ts +19 -4
  157. package/src/core/config.ts +54 -0
  158. package/src/core/defaults.ts +50 -3
  159. package/src/core/git-commit-attribution.ts +46 -21
  160. package/src/core/verification-scripts.ts +6 -0
  161. package/src/domains/agents/builtins/verifier.md +3 -0
  162. package/src/domains/config/classify.ts +1 -0
  163. package/src/domains/config/keybindings.ts +3 -3
  164. package/src/domains/context/working-set/contract.ts +161 -0
  165. package/src/domains/context/working-set/defaults.ts +28 -0
  166. package/src/domains/context/working-set/engine.ts +203 -0
  167. package/src/domains/context/working-set/fold.ts +62 -0
  168. package/src/domains/context/working-set/horizon.ts +38 -0
  169. package/src/domains/context/working-set/marker.ts +103 -0
  170. package/src/domains/context/working-set/path-index.ts +436 -0
  171. package/src/domains/context/working-set/payload.ts +152 -0
  172. package/src/domains/context/working-set/policies/age-horizon.ts +55 -0
  173. package/src/domains/context/working-set/policies/index.ts +21 -0
  174. package/src/domains/context/working-set/policies/structural.ts +160 -0
  175. package/src/domains/context/working-set/project.ts +132 -0
  176. package/src/domains/context/working-set/protect.ts +109 -0
  177. package/src/domains/context/working-set/recall.ts +177 -0
  178. package/src/domains/context/working-set/replay/controls.ts +112 -0
  179. package/src/domains/context/working-set/replay/load-clio.ts +199 -0
  180. package/src/domains/context/working-set/replay/metrics.ts +185 -0
  181. package/src/domains/context/working-set/replay/reference-graph.ts +79 -0
  182. package/src/domains/context/working-set/replay/report.ts +139 -0
  183. package/src/domains/context/working-set/replay/runner.ts +325 -0
  184. package/src/domains/context/working-set/replay/synthetic.ts +422 -0
  185. package/src/domains/context/working-set/replay/trace.ts +21 -0
  186. package/src/domains/context/working-set/visible.ts +54 -0
  187. package/src/domains/evidence/build.ts +112 -45
  188. package/src/domains/evidence/eval.ts +24 -7
  189. package/src/domains/evidence/index.ts +53 -0
  190. package/src/domains/evidence/ordering.ts +12 -0
  191. package/src/domains/evidence/run-trust.ts +221 -0
  192. package/src/domains/evidence/store.ts +46 -6
  193. package/src/domains/evidence/trust-status.ts +854 -0
  194. package/src/domains/evidence/types.ts +26 -0
  195. package/src/domains/middleware/memory-intervention.ts +3 -0
  196. package/src/domains/middleware/stalled-turn.ts +165 -4
  197. package/src/domains/safety/autonomy.ts +1 -1
  198. package/src/domains/safety/default-path-policy.ts +8 -0
  199. package/src/domains/safety/finish-contract.ts +4 -3
  200. package/src/domains/safety/policy-engine.ts +48 -6
  201. package/src/domains/session/compaction/compact.ts +23 -1
  202. package/src/domains/session/compaction/cut-point.ts +2 -0
  203. package/src/domains/session/compaction/tokens.ts +16 -1
  204. package/src/domains/session/context-ledger.ts +2 -0
  205. package/src/domains/session/entries.ts +107 -1
  206. package/src/domains/session/manager.ts +9 -2
  207. package/src/domains/session/migrations/index.ts +22 -3
  208. package/src/engine/acp/server.ts +3 -0
  209. package/src/engine/agent.ts +18 -1
  210. package/src/engine/session.ts +9 -3
  211. package/src/entry/orchestrator.ts +16 -4
  212. package/src/interactive/chat-loop-messages.ts +18 -6
  213. package/src/interactive/chat-panel.ts +571 -244
  214. package/src/interactive/chat-renderer.ts +79 -39
  215. package/src/interactive/context-meter.ts +10 -0
  216. package/src/interactive/context-overlay.ts +81 -6
  217. package/src/interactive/context-recall-command.ts +110 -0
  218. package/src/interactive/editor-submit.ts +26 -1
  219. package/src/interactive/footer/widgets.ts +22 -20
  220. package/src/interactive/footer-panel.ts +6 -1
  221. package/src/interactive/interactive-application.ts +2 -0
  222. package/src/interactive/interactive-event-projection.ts +12 -0
  223. package/src/interactive/interactive-slash-runtime.ts +49 -8
  224. package/src/interactive/model-session-replay.ts +21 -0
  225. package/src/interactive/overlay-general-openers.ts +6 -0
  226. package/src/interactive/overlay-session-lifecycle.ts +8 -4
  227. package/src/interactive/overlays/ask-user.ts +146 -24
  228. package/src/interactive/renderers/tool-execution.ts +167 -56
  229. package/src/interactive/session-transcript.ts +2 -2
  230. package/src/interactive/slash-commands.ts +29 -2
  231. package/src/interactive/status/index.ts +12 -1
  232. package/src/interactive/status/reasoning.ts +87 -0
  233. package/src/interactive/status/summary.ts +13 -2
  234. package/src/interactive/transcript-detail.ts +120 -0
  235. package/src/interactive/turn-context.ts +238 -88
  236. package/src/interactive/turn-middleware.ts +6 -6
  237. package/src/tools/agent-tools.ts +11 -4
  238. package/src/tools/bash.ts +144 -82
  239. package/src/tools/builtin-tool-catalog.ts +18 -6
  240. package/src/tools/context/index.ts +105 -3
  241. package/src/tools/context/surface.ts +3 -2
  242. package/src/tools/core-bootstrap.ts +21 -0
  243. package/src/tools/dispatch-runner.ts +9 -7
  244. package/src/tools/monitor.ts +28 -20
  245. package/src/tools/presentation.ts +107 -0
  246. package/src/tools/registry.ts +65 -7
  247. package/src/tools/result-disposition.ts +550 -0
  248. package/src/tools/result-shaping.ts +262 -19
  249. package/src/tools/safe-exec.ts +2 -0
  250. package/src/tools/verify/authoring.ts +1119 -0
  251. package/src/tools/verify/catalog.ts +346 -0
  252. package/src/tools/verify/index.ts +13 -3
  253. package/src/tools/verify/scripts.ts +135 -37
  254. package/src/tools/verify/surface.ts +9 -5
  255. package/src/tools/worker-evidence.ts +35 -12
  256. package/dist/chunk-MNA4JGU4.js +0 -255
  257. package/dist/chunk-SRF2PJNW.js +0 -184
  258. package/dist/chunk-T6YILFSB.js +0 -80
  259. package/dist/chunk-VAKQQHWR.js +0 -434
@@ -1,27 +1,27 @@
1
1
  import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
2
  import {
3
- BASH_HARD_CAP_BYTES,
4
- HEADLESS_PERMISSION_DENIED_MARKER,
5
- combineBashOutput,
6
- runBashCommand
7
- } from "./chunk-MNA4JGU4.js";
3
+ HEADLESS_PERMISSION_DENIED_MARKER
4
+ } from "./chunk-K7VKOLQQ.js";
8
5
  import {
9
6
  hashToolCall
10
7
  } from "./chunk-UOV2BYIW.js";
11
8
  import {
12
9
  describeDispatchPlan
13
- } from "./chunk-G2DE3C7R.js";
10
+ } from "./chunk-EDRHSCIE.js";
14
11
  import {
15
12
  RESPONSE_SCHEMA_RUNTIME_ID,
16
13
  applyToolProfile,
14
+ bashTool,
17
15
  builtin,
18
- createTaskBoardStore,
19
16
  networkToolsDisabled,
20
17
  readMaxBytes,
21
18
  readTool,
22
- renderAgentLedger,
19
+ renderAgentLedger
20
+ } from "./chunk-ZYKPLLNQ.js";
21
+ import {
22
+ createTaskBoardStore,
23
23
  taskBoardCounts
24
- } from "./chunk-MQSRRFWA.js";
24
+ } from "./chunk-WPQLXFOZ.js";
25
25
  import {
26
26
  DEFAULT_AUTONOMY_EXPOSURE,
27
27
  DEFAULT_AUTONOMY_LEVEL,
@@ -29,15 +29,17 @@ import {
29
29
  autonomyDenyRejection,
30
30
  formatModelRejection,
31
31
  mapAutonomy
32
- } from "./chunk-STBPMHSX.js";
32
+ } from "./chunk-7RXG6QRZ.js";
33
+ import {
34
+ classify
35
+ } from "./chunk-AOCYTWAV.js";
33
36
  import {
34
37
  CLIO_ARTIFACT_DIR,
35
38
  artifactDefaultPath,
36
- classify,
37
39
  detectValidationCommand,
38
40
  protectArtifact,
39
41
  protectedArtifactMutationBlockReason
40
- } from "./chunk-5UUP6MWO.js";
42
+ } from "./chunk-MV3K5QF2.js";
41
43
  import {
42
44
  parseAgentLedgerBody
43
45
  } from "./chunk-CMZWFGD2.js";
@@ -47,7 +49,7 @@ import {
47
49
  import {
48
50
  gitTool,
49
51
  verifyToolSurface
50
- } from "./chunk-ARBGF5F7.js";
52
+ } from "./chunk-NILBFAPG.js";
51
53
  import {
52
54
  codeNavToolSurface
53
55
  } from "./chunk-XN3L4EYL.js";
@@ -59,35 +61,35 @@ import {
59
61
  rgIgnoreArgs
60
62
  } from "./chunk-VG7TBQIY.js";
61
63
  import {
62
- expandPath,
63
64
  resolveReadPath,
64
65
  resolveToCwd,
65
66
  toPosixPath
66
67
  } from "./chunk-OQE5J4C6.js";
67
68
  import {
68
69
  contextToolSurface
69
- } from "./chunk-OKGUZO2U.js";
70
+ } from "./chunk-SPULKLCF.js";
70
71
  import {
71
72
  evaluateSkillToolSurface,
72
73
  skillActivationFromToolDetails
73
- } from "./chunk-T6YILFSB.js";
74
+ } from "./chunk-BEY543CS.js";
74
75
  import {
75
- DEFAULT_MAX_LINES,
76
- GREP_MAX_LINE_LENGTH,
76
+ DEFAULT_TOOL_RESULT_MAX_BYTES,
77
77
  OBSERVATION_POLICY_SLACK_BYTES,
78
78
  OBSERVE_SELF_CAPS,
79
79
  commitObservationReservation,
80
80
  finalizeObservation,
81
- formatSize,
81
+ isDispositionedToolResultError,
82
82
  observationBudgetExhausted,
83
83
  releaseObservation,
84
84
  reserveObservation,
85
85
  shapeToolResult,
86
- truncateHead,
87
- truncateLine,
88
- truncateTail,
89
- writeToolOffload
90
- } from "./chunk-VAKQQHWR.js";
86
+ toolResultContextText,
87
+ truncateHead
88
+ } from "./chunk-5M54SPOL.js";
89
+ import {
90
+ GREP_MAX_LINE_LENGTH,
91
+ truncateLine
92
+ } from "./chunk-OZNBF4L3.js";
91
93
  import {
92
94
  truncateUtf8
93
95
  } from "./chunk-6XLNIQDB.js";
@@ -102,9 +104,8 @@ import {
102
104
  incompleteInstallationAdvice
103
105
  } from "./chunk-65DEGPJ6.js";
104
106
  import {
105
- buildSafeToolEnv,
106
- resolveSafeCwd
107
- } from "./chunk-SRF2PJNW.js";
107
+ buildSafeToolEnv
108
+ } from "./chunk-VEZEGCGW.js";
108
109
  import {
109
110
  GUARDRAIL_DEFAULTS,
110
111
  isWorkerToolCallCapExceededReason,
@@ -123,7 +124,7 @@ import {
123
124
  } from "./chunk-BNAZZHFG.js";
124
125
  import {
125
126
  BusChannels
126
- } from "./chunk-OQ33BKR3.js";
127
+ } from "./chunk-TTNYS3EA.js";
127
128
  import {
128
129
  init_esm_shims
129
130
  } from "./chunk-3R73A4XB.js";
@@ -1269,6 +1270,7 @@ function createRegistry(deps) {
1269
1270
  let approvalRequestCounter = 0;
1270
1271
  const approvalRequestToken = randomBytes(4).toString("hex");
1271
1272
  const runSpec = async (spec, call, decision, options) => {
1273
+ let resultDisposition = spec.metadata?.resultDisposition;
1272
1274
  try {
1273
1275
  const beforeEffects = runToolHook("before_tool", spec, call, decision, options);
1274
1276
  const block = firstBlockToolEffect(beforeEffects);
@@ -1282,17 +1284,18 @@ function createRegistry(deps) {
1282
1284
  }
1283
1285
  try {
1284
1286
  const preparedArgs = prepareToolArgs(spec, call.args ?? {});
1285
- const result = shapeToolResult(spec, await spec.run(preparedArgs, options), options);
1287
+ resultDisposition = resolveToolResultDisposition(spec, preparedArgs);
1288
+ const result = await spec.run(preparedArgs, options);
1286
1289
  const afterEffects = runToolHook("after_tool", spec, call, decision, options, result);
1287
- const finalResult = shapeToolResult(spec, applyToolResultEffects(result, afterEffects), options);
1290
+ const finalResult = shapeToolResult(spec, applyToolResultEffects(result, afterEffects), options, resultDisposition);
1288
1291
  return { kind: "ok", result: finalResult, decision };
1289
1292
  } catch (err) {
1290
1293
  const message = err instanceof Error ? err.message : String(err);
1291
- const result = shapeToolResult(spec, { kind: "error", message }, options);
1294
+ const result = { kind: "error", message };
1292
1295
  const afterEffects = runToolHook("after_tool", spec, call, decision, options, result);
1293
1296
  return {
1294
1297
  kind: "ok",
1295
- result: shapeToolResult(spec, applyToolResultEffects(result, afterEffects), options),
1298
+ result: shapeToolResult(spec, applyToolResultEffects(result, afterEffects), options, resultDisposition),
1296
1299
  decision
1297
1300
  };
1298
1301
  }
@@ -1609,6 +1612,23 @@ function prepareToolArgs(spec, args) {
1609
1612
  return args;
1610
1613
  }
1611
1614
  }
1615
+ function resolveToolResultDisposition(spec, args) {
1616
+ const declared = spec.metadata?.resultDisposition;
1617
+ if (!spec.resolveResultDisposition) return declared;
1618
+ try {
1619
+ return spec.resolveResultDisposition(args, declared);
1620
+ } catch (error) {
1621
+ const maxBytes = declared !== void 0 && declared.context.maxBytes !== void 0 ? declared.context.maxBytes : DEFAULT_TOOL_RESULT_MAX_BYTES;
1622
+ return {
1623
+ presentation: declared?.presentation ?? { foldDefault: "folded", showDiffWhenFolded: false, failureExcerpt: true },
1624
+ context: { mode: "metadata-only", maxBytes },
1625
+ // The narrowing is recorded with the result, so a resolver bug shows up
1626
+ // on the transcript row and in the model's header instead of reading as
1627
+ // a deliberate metadata-only request.
1628
+ fallback: { reason: "resolver-error", message: error instanceof Error ? error.message : String(error) }
1629
+ };
1630
+ }
1631
+ }
1612
1632
  function disposeAdmissionArgs(spec, args) {
1613
1633
  try {
1614
1634
  spec?.disposeAdmissionArguments?.(args);
@@ -1780,12 +1800,14 @@ function applyToolResultEffects(result, effects) {
1780
1800
 
1781
1801
  ${annotations.join("\n")}`;
1782
1802
  if (result.kind === "ok") {
1783
- const annotated = { kind: "ok", output: `${result.output}${suffix}` };
1784
- if (result.details !== void 0) annotated.details = result.details;
1785
- if (result.terminate === true) annotated.terminate = true;
1786
- return annotated;
1803
+ const annotated2 = { kind: "ok", output: `${result.output}${suffix}` };
1804
+ if (result.details !== void 0) annotated2.details = result.details;
1805
+ if (result.terminate === true) annotated2.terminate = true;
1806
+ return annotated2;
1787
1807
  }
1788
- return { kind: "error", message: `${result.message}${suffix}` };
1808
+ const annotated = { kind: "error", message: `${result.message}${suffix}` };
1809
+ if (result.details !== void 0) annotated.details = result.details;
1810
+ return annotated;
1789
1811
  }
1790
1812
  function annotationMessages(effects) {
1791
1813
  const messages = [];
@@ -1800,8 +1822,20 @@ function annotationMessages(effects) {
1800
1822
  // src/engine/agent.ts
1801
1823
  init_esm_shims();
1802
1824
  import { Agent } from "@earendil-works/pi-agent-core";
1825
+ function dispositionAwareAfterToolCall(delegate) {
1826
+ return async (context, signal) => {
1827
+ const override = await delegate?.(context, signal);
1828
+ const effectiveResult = override?.details === void 0 ? context.result : { ...context.result, details: override.details };
1829
+ if (isDispositionedToolResultError(effectiveResult)) return { ...override, isError: true };
1830
+ return override;
1831
+ };
1832
+ }
1803
1833
  function createEngineAgent(options = {}) {
1804
- const agent = new Agent({ streamFn: engineStreamSimple, ...options });
1834
+ const agent = new Agent({
1835
+ streamFn: engineStreamSimple,
1836
+ ...options,
1837
+ afterToolCall: dispositionAwareAfterToolCall(options.afterToolCall)
1838
+ });
1805
1839
  return {
1806
1840
  agent,
1807
1841
  state: () => agent.state
@@ -1814,10 +1848,10 @@ import { performance as performance2 } from "node:perf_hooks";
1814
1848
  function projectToolResult(result) {
1815
1849
  const details = { ...result.details ?? {}, kind: result.kind };
1816
1850
  if (result.kind === "error") {
1817
- return { content: [{ type: "text", text: result.message }], details };
1851
+ return { content: [{ type: "text", text: toolResultContextText(result) }], details };
1818
1852
  }
1819
1853
  return {
1820
- content: [{ type: "text", text: result.output }],
1854
+ content: [{ type: "text", text: toolResultContextText(result) }],
1821
1855
  details,
1822
1856
  ...result.terminate === true ? { terminate: true } : {}
1823
1857
  };
@@ -1872,12 +1906,15 @@ async function runValidatedToolCall(input) {
1872
1906
  reason: verdict.result.message,
1873
1907
  decision: verdict.decision
1874
1908
  });
1875
- throw new Error(verdict.result.message);
1909
+ if (input.returnDispositionedErrors === true && isDispositionedToolResultError(verdict.result)) {
1910
+ return projectToolResult(verdict.result);
1911
+ }
1912
+ throw new Error(toolResultContextText(verdict.result));
1876
1913
  }
1877
1914
  const toolDetails = isRecord2(verdict.result.details) ? verdict.result.details : {};
1878
1915
  const skillActivation = spec.name === ToolNames.Context ? skillActivationFromToolDetails(toolDetails, input.invokeOptions?.turnId) : null;
1879
1916
  const result = {
1880
- content: [{ type: "text", text: verdict.result.output }],
1917
+ content: [{ type: "text", text: toolResultContextText(verdict.result) }],
1881
1918
  details: { ...toolDetails, kind: "ok" }
1882
1919
  };
1883
1920
  if (verdict.result.terminate === true) {
@@ -1941,7 +1978,8 @@ function toAgentTool(spec, registry, telemetry, invokeOptions) {
1941
1978
  const callInput = {
1942
1979
  spec,
1943
1980
  args: params,
1944
- registry
1981
+ registry,
1982
+ returnDispositionedErrors: true
1945
1983
  };
1946
1984
  if (signal) callInput.signal = signal;
1947
1985
  if (telemetry) callInput.telemetry = telemetry;
@@ -2345,161 +2383,6 @@ function createArtifactTool(deps = {}) {
2345
2383
  };
2346
2384
  }
2347
2385
 
2348
- // src/tools/bash.ts
2349
- init_esm_shims();
2350
- var BASH_DISPLAY_MAX_BYTES = 16 * 1024;
2351
- var BASH_TAIL_NOTE_RESERVE = 512;
2352
- function shapeBashProgress(rawOutput) {
2353
- const truncation = truncateTail(rawOutput, {
2354
- maxLines: DEFAULT_MAX_LINES,
2355
- maxBytes: BASH_DISPLAY_MAX_BYTES - BASH_TAIL_NOTE_RESERVE
2356
- });
2357
- const bytes = Buffer.byteLength(rawOutput, "utf8");
2358
- return {
2359
- kind: "ok",
2360
- output: truncation.content,
2361
- details: {
2362
- resultSize: {
2363
- bytes,
2364
- shownBytes: truncation.outputBytes,
2365
- maxBytes: BASH_DISPLAY_MAX_BYTES,
2366
- truncated: truncation.truncated,
2367
- policy: "tail"
2368
- }
2369
- }
2370
- };
2371
- }
2372
- function shapeBashOutput(rawOutput, context) {
2373
- const truncation = truncateTail(rawOutput, {
2374
- maxLines: DEFAULT_MAX_LINES,
2375
- maxBytes: BASH_DISPLAY_MAX_BYTES - BASH_TAIL_NOTE_RESERVE
2376
- });
2377
- if (!truncation.truncated) return { text: rawOutput };
2378
- const totalBytes = Buffer.byteLength(rawOutput, "utf8");
2379
- const offloadPath = writeToolOffload(rawOutput, context, BASH_HARD_CAP_BYTES);
2380
- const startLine = truncation.totalLines - truncation.outputLines + 1;
2381
- const scope = truncation.lastLinePartial ? `last ${formatSize(truncation.outputBytes)} of line ${truncation.totalLines} (line is large)` : `lines ${startLine}-${truncation.totalLines} of ${truncation.totalLines}`;
2382
- const location = offloadPath !== null ? ` Full output saved to ${offloadPath}; read it with offset/limit.` : "";
2383
- const note = `[Output tail-truncated: showing ${scope} (${formatSize(BASH_DISPLAY_MAX_BYTES)} display limit).${location}]`;
2384
- const details = {
2385
- resultSize: {
2386
- bytes: totalBytes,
2387
- shownBytes: truncation.outputBytes,
2388
- maxBytes: BASH_DISPLAY_MAX_BYTES,
2389
- truncated: true,
2390
- policy: "tail",
2391
- followUpHint: "Read the full-output offload file with offset/limit, or re-run a narrower command.",
2392
- ...offloadPath !== null ? { offloadPath } : {}
2393
- }
2394
- };
2395
- return { text: `${truncation.content}
2396
-
2397
- ${note}`, details };
2398
- }
2399
- function withDetails(base, details) {
2400
- if (details === void 0) return base;
2401
- if (base.kind === "ok") return { ...base, details };
2402
- return { ...base, details };
2403
- }
2404
- var OBSERVE_COMMAND_PATTERN = /^\s*(?:cat|head|tail|ls|grep|rg|find)\b/;
2405
- var OBSERVE_NUDGE_SESSION_LIMIT = 64;
2406
- var observeNudgeSeenSessions = /* @__PURE__ */ new Set();
2407
- function observeToolsNudge(command, sessionId) {
2408
- if (!OBSERVE_COMMAND_PATTERN.test(command)) return "";
2409
- const key = sessionId ?? "no-session";
2410
- if (observeNudgeSeenSessions.has(key)) return "";
2411
- if (observeNudgeSeenSessions.size >= OBSERVE_NUDGE_SESSION_LIMIT) {
2412
- const oldest = observeNudgeSeenSessions.values().next().value;
2413
- if (oldest !== void 0) observeNudgeSeenSessions.delete(oldest);
2414
- }
2415
- observeNudgeSeenSessions.add(key);
2416
- return "\n\n[note: prefer the structured observe tools over shell file inspection: read pages files with offset/limit, ls lists directories, grep and find search, code_nav maps symbols. Their results are capped and continuable; keep bash for builds, git, and scripts.]";
2417
- }
2418
- var bashTool = {
2419
- name: ToolNames.Bash,
2420
- description: "Execute a bash command and return stdout and stderr. Runs inside the session workspace. Default timeout 300000 ms.",
2421
- parameters: typebox_exports.Object({
2422
- command: typebox_exports.String({ description: "Bash command to execute." }),
2423
- cwd: typebox_exports.Optional(
2424
- typebox_exports.String({
2425
- description: "Omit this. The command already runs at the session workspace root. Set it only to run in a subdirectory of that root, as a relative path; an absolute path outside the root is blocked."
2426
- })
2427
- ),
2428
- timeout_ms: typebox_exports.Optional(typebox_exports.Number({ description: "Timeout in milliseconds." }))
2429
- }),
2430
- baseActionClass: "execute",
2431
- executionMode: "sequential",
2432
- async run(args, options) {
2433
- if (typeof args.command !== "string" || args.command.length === 0) {
2434
- return { kind: "error", message: "bash: missing command argument" };
2435
- }
2436
- const cwdArg = typeof args.cwd === "string" && args.cwd.length > 0 ? args.cwd : void 0;
2437
- let cwd;
2438
- try {
2439
- cwd = resolveSafeCwd(cwdArg === void 0 ? void 0 : expandPath(cwdArg), process.cwd());
2440
- } catch {
2441
- return {
2442
- kind: "error",
2443
- message: `bash: cwd '${cwdArg}' escapes workspace root '${process.cwd()}'; use a typed tool or a project policy entry with explicit cwd`
2444
- };
2445
- }
2446
- const timeout = typeof args.timeout_ms === "number" && args.timeout_ms > 0 ? args.timeout_ms : 3e5;
2447
- try {
2448
- const runOptions = {
2449
- cwd,
2450
- timeoutMs: timeout,
2451
- ...options?.signal === void 0 ? {} : { signal: options.signal }
2452
- };
2453
- if (options?.onUpdate !== void 0) {
2454
- runOptions.onUpdate = (progress) => {
2455
- options.onUpdate?.(shapeBashProgress(combineBashOutput(progress)));
2456
- };
2457
- }
2458
- const result = await runBashCommand(args.command, runOptions);
2459
- const { error, aborted, timedOut, outputCapped } = result;
2460
- if (aborted) {
2461
- return { kind: "error", message: "bash: command aborted" };
2462
- }
2463
- const shaped = shapeBashOutput(combineBashOutput(result), options);
2464
- const output = shaped.text.trim();
2465
- if (timedOut) {
2466
- const status = `bash: command timed out after ${timeout}ms`;
2467
- return withDetails(
2468
- { kind: "error", message: output.length > 0 ? `${output}
2469
-
2470
- ${status}` : status },
2471
- shaped.details
2472
- );
2473
- }
2474
- if (outputCapped) {
2475
- const status = `bash: command output exceeded ${BASH_HARD_CAP_BYTES} bytes and was stopped`;
2476
- return withDetails(
2477
- { kind: "error", message: output.length > 0 ? `${output}
2478
-
2479
- ${status}` : status },
2480
- shaped.details
2481
- );
2482
- }
2483
- if (error) {
2484
- const code = typeof error.code === "number" ? error.code : error.code;
2485
- const status = `bash: command failed (exit ${code ?? "?"})`;
2486
- const message = output.length > 0 ? `${output}
2487
-
2488
- ${status}` : `${status}: ${error.message}`;
2489
- return withDetails({ kind: "error", message }, shaped.details);
2490
- }
2491
- const body = shaped.text.length > 0 ? shaped.text : "(no output)";
2492
- return withDetails(
2493
- { kind: "ok", output: `${body}${observeToolsNudge(args.command, options?.sessionId)}` },
2494
- shaped.details
2495
- );
2496
- } catch (err) {
2497
- const msg = err instanceof Error ? err.message : String(err);
2498
- return { kind: "error", message: `bash: ${msg}` };
2499
- }
2500
- }
2501
- };
2502
-
2503
2386
  // src/tools/credential-present.ts
2504
2387
  init_esm_shims();
2505
2388
  import { createReadStream } from "node:fs";
@@ -5019,13 +4902,13 @@ function registerCoreTools(registry, deps = {}) {
5019
4902
  });
5020
4903
  registry.register({
5021
4904
  ...builtin(
5022
- lazyTool(verifyToolSurface, async () => (await import("./verify-G6V4D2G7.js")).verifyTool),
4905
+ lazyTool(verifyToolSurface, async () => (await import("./verify-X5HDROLA.js")).verifyTool),
5023
4906
  { path: "src/tools/verify/index.ts", scope: "core" }
5024
4907
  )
5025
4908
  });
5026
4909
  registry.register({
5027
4910
  ...builtin(
5028
- lazyTool(codeNavToolSurface, async () => (await import("./code-nav-7AX6FYE6.js")).codeNavTool),
4911
+ lazyTool(codeNavToolSurface, async () => (await import("./code-nav-AXCXSBHX.js")).codeNavTool),
5029
4912
  { path: "src/tools/codewiki/code-nav.ts", scope: "core" }
5030
4913
  )
5031
4914
  });
@@ -5046,14 +4929,27 @@ function registerCoreTools(registry, deps = {}) {
5046
4929
  ...builtin(credentialPresentTool, { path: "src/tools/credential-present.ts", scope: "core" })
5047
4930
  });
5048
4931
  const session = deps.session;
4932
+ const readSessionEntries = deps.readSessionEntries;
5049
4933
  registry.register({
5050
4934
  ...builtin(
5051
4935
  lazyTool(contextToolSurface, async () => {
5052
- const { createContextTool } = await import("./context-5VKGUVJJ.js");
4936
+ const { createContextTool } = await import("./context-EKDCKUUZ.js");
5053
4937
  if (!session) return createContextTool(skillToolDeps);
5054
4938
  const { probeWorkspace } = await import("./workspace-G4ZWUIPR.js");
5055
4939
  return createContextTool({
5056
4940
  ...skillToolDeps,
4941
+ ...readSessionEntries ? {
4942
+ session: {
4943
+ hasSession: () => session.current() !== null,
4944
+ readEntries: readSessionEntries,
4945
+ activeLeafTurnId: () => {
4946
+ const meta = session.current();
4947
+ return meta ? session.tree(meta.id).leafId ?? void 0 : void 0;
4948
+ },
4949
+ appendEntry: (entry) => session.appendEntry(entry),
4950
+ ...deps.onContextRecalled ? { onRecalled: deps.onContextRecalled } : {}
4951
+ }
4952
+ } : {},
5057
4953
  workspace: {
5058
4954
  hasSession: () => session.current() !== null,
5059
4955
  getSnapshot: () => session.current()?.workspace ?? null,
@@ -5132,4 +5028,4 @@ export {
5132
5028
  assertRegisteredBuiltinTools,
5133
5029
  createRegistry
5134
5030
  };
5135
- //# sourceMappingURL=chunk-OHHN2SO4.js.map
5031
+ //# sourceMappingURL=chunk-VMNQ6OZA.js.map
@@ -0,0 +1,122 @@
1
+ import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
+ import {
3
+ EMPTY_WORKING_SET_VIEW,
4
+ callPathsByToolCallId,
5
+ offloadPathOf,
6
+ parseRefKey,
7
+ primaryPathOf,
8
+ refKey,
9
+ toolResultPayload,
10
+ toolResultText
11
+ } from "./chunk-TZSKNMZG.js";
12
+ import {
13
+ filterEntriesToActivePath
14
+ } from "./chunk-W6GROXXM.js";
15
+ import {
16
+ ceilChars
17
+ } from "./chunk-BPGS2WCQ.js";
18
+ import {
19
+ init_esm_shims
20
+ } from "./chunk-3R73A4XB.js";
21
+
22
+ // src/domains/context/working-set/recall.ts
23
+ init_esm_shims();
24
+ function isThinkingEntry(entry) {
25
+ return entry.kind === "message" && entry.role === "assistant";
26
+ }
27
+ function isToolResultEntry(entry) {
28
+ return entry.kind === "message" && entry.role === "tool_result";
29
+ }
30
+ function resolveRecall(entries, view, ref, activeLeafTurnId) {
31
+ const parsed = parseRefKey(ref);
32
+ if (parsed === null) return { ok: false, error: { kind: "invalid_ref", ref } };
33
+ const key = refKey(parsed);
34
+ const active = filterEntriesToActivePath(entries, activeLeafTurnId);
35
+ const entry = active.find((candidate) => candidate.turnId === key);
36
+ if (entry === void 0) {
37
+ return { ok: false, error: { kind: "not_on_active_path", ref: key } };
38
+ }
39
+ if (isThinkingEntry(entry) || !view.evicted.has(key) || !isToolResultEntry(entry)) {
40
+ return { ok: false, error: { kind: "not_evicted", ref: key } };
41
+ }
42
+ const payload = toolResultPayload(entry.payload);
43
+ const body = toolResultText(payload.result);
44
+ const offloadPath = offloadPathOf(payload);
45
+ return {
46
+ ok: true,
47
+ result: {
48
+ ref: parsed,
49
+ entry,
50
+ body,
51
+ tokens: ceilChars(body.length),
52
+ ...offloadPath !== void 0 ? { offloadPath } : {}
53
+ }
54
+ };
55
+ }
56
+ function recallParentTurnId(entries, activeLeafTurnId) {
57
+ const active = filterEntriesToActivePath(entries, activeLeafTurnId);
58
+ for (let i = active.length - 1; i >= 0; i -= 1) {
59
+ const candidate = active[i];
60
+ if (candidate?.kind === "message") return candidate.turnId;
61
+ }
62
+ return null;
63
+ }
64
+ function buildRecallFields(result, meta) {
65
+ return {
66
+ kind: "contextRecall",
67
+ ref: { entry: result.ref.entry },
68
+ trigger: meta.trigger,
69
+ tokensReadmitted: result.tokens,
70
+ ...meta.toolCallId !== void 0 ? { toolCallId: meta.toolCallId } : {}
71
+ };
72
+ }
73
+ var MAX_LISTED_REFS = 8;
74
+ function recallableRefListing(entries, view) {
75
+ const byTurnId = /* @__PURE__ */ new Map();
76
+ for (const entry of entries) byTurnId.set(entry.turnId, entry);
77
+ const callPaths = callPathsByToolCallId(entries);
78
+ const refs = [];
79
+ for (const key of view.evicted.keys()) {
80
+ const entry = byTurnId.get(key);
81
+ if (entry === void 0 || !isToolResultEntry(entry)) continue;
82
+ const payload = toolResultPayload(entry.payload);
83
+ const toolCallId = typeof payload.obj.toolCallId === "string" ? payload.obj.toolCallId : void 0;
84
+ const path = primaryPathOf(payload) ?? (toolCallId === void 0 ? void 0 : callPaths.get(toolCallId));
85
+ refs.push(`${key} (${payload.toolName}${path === void 0 ? "" : ` ${path}`})`);
86
+ }
87
+ return {
88
+ refs: refs.slice(0, MAX_LISTED_REFS),
89
+ remaining: Math.max(0, refs.length - MAX_LISTED_REFS)
90
+ };
91
+ }
92
+ function recallableRefMessage(entries, view) {
93
+ const listing = recallableRefListing(entries, view);
94
+ if (listing.refs.length === 0) return "No recallable refs on the active path.";
95
+ const more = listing.remaining > 0 ? `, and ${listing.remaining} more` : "";
96
+ return `Recallable refs on the active path: ${listing.refs.join(", ")}${more}.`;
97
+ }
98
+ function recallErrorMessage(error, entries = [], view = EMPTY_WORKING_SET_VIEW) {
99
+ const listing = ` ${recallableRefMessage(entries, view)}`;
100
+ switch (error.kind) {
101
+ case "invalid_ref":
102
+ return `recall ref must be a single turnId without whitespace; got '${error.ref}'.`;
103
+ case "not_on_active_path":
104
+ return `ref ${error.ref} is not on the active path of this session (unknown or on an abandoned branch).${listing}`;
105
+ case "not_evicted": {
106
+ const entry = entries.find((candidate) => candidate.turnId === error.ref);
107
+ if (entry !== void 0 && isThinkingEntry(entry)) {
108
+ return `ref ${error.ref} is an assistant turn; thinking is not recallable.${listing}`;
109
+ }
110
+ return `ref ${error.ref} is not evicted; its content is already in context.${listing}`;
111
+ }
112
+ }
113
+ }
114
+
115
+ export {
116
+ resolveRecall,
117
+ recallParentTurnId,
118
+ buildRecallFields,
119
+ recallableRefListing,
120
+ recallErrorMessage
121
+ };
122
+ //# sourceMappingURL=chunk-VSNATDE6.js.map
@@ -0,0 +1,69 @@
1
+ import { createRequire as __clioCreateRequire } from "node:module"; const require = __clioCreateRequire(import.meta.url);
2
+ import {
3
+ init_esm_shims
4
+ } from "./chunk-3R73A4XB.js";
5
+
6
+ // src/domains/session/tree/active-path.ts
7
+ init_esm_shims();
8
+ function filterEntriesToActivePath(entries, leafTurnId) {
9
+ const messages = [];
10
+ const messagesById = /* @__PURE__ */ new Map();
11
+ for (const entry of entries) {
12
+ if (entry.kind !== "message") continue;
13
+ messages.push(entry);
14
+ messagesById.set(entry.turnId, entry);
15
+ }
16
+ const latest = messages[messages.length - 1];
17
+ const pinnedLeaf = resolveLeafMessage(entries, messagesById, leafTurnId);
18
+ if (!hasBranch(messages) && (pinnedLeaf === void 0 || pinnedLeaf.turnId === latest?.turnId)) return [...entries];
19
+ const leaf = pinnedLeaf ?? latest;
20
+ if (!leaf) return [...entries];
21
+ const pathIds = /* @__PURE__ */ new Set();
22
+ let current = leaf;
23
+ while (current && !pathIds.has(current.turnId)) {
24
+ pathIds.add(current.turnId);
25
+ if (current.parentTurnId === null) break;
26
+ current = messagesById.get(current.parentTurnId);
27
+ }
28
+ const leafIndex = entries.findIndex((entry) => entry.kind === "message" && entry.turnId === leaf.turnId);
29
+ return entries.filter((entry, index) => entryBelongsToPath(entry, pathIds, leafIndex >= 0 && index <= leafIndex));
30
+ }
31
+ function resolveLeafMessage(entries, messagesById, leafTurnId) {
32
+ if (leafTurnId === void 0) return void 0;
33
+ const direct = messagesById.get(leafTurnId);
34
+ if (direct) return direct;
35
+ const sidecar = entries.find((entry) => entry.turnId === leafTurnId);
36
+ if (!sidecar) return void 0;
37
+ const anchor = sidecarAnchorTurnId(sidecar);
38
+ return anchor === null ? void 0 : messagesById.get(anchor);
39
+ }
40
+ function sidecarAnchorTurnId(entry) {
41
+ if (entry.kind === "label") return entry.targetTurnId;
42
+ if (entry.kind === "sessionInfo") return entry.targetTurnId ?? entry.parentTurnId;
43
+ if (entry.kind === "compactionSummary" && entry.firstKeptTurnId.length > 0) return entry.firstKeptTurnId;
44
+ return entry.parentTurnId;
45
+ }
46
+ function hasBranch(messages) {
47
+ const seenParents = /* @__PURE__ */ new Set();
48
+ for (const message of messages) {
49
+ if (message.parentTurnId === null) continue;
50
+ if (seenParents.has(message.parentTurnId)) return true;
51
+ seenParents.add(message.parentTurnId);
52
+ }
53
+ return false;
54
+ }
55
+ function entryBelongsToPath(entry, pathIds, atOrBeforeLeaf) {
56
+ if (entry.kind === "message") return pathIds.has(entry.turnId);
57
+ if (entry.kind === "label") return pathIds.has(entry.targetTurnId);
58
+ if (entry.kind === "sessionInfo") return entry.targetTurnId === void 0 || pathIds.has(entry.targetTurnId);
59
+ if (entry.kind === "compactionSummary" && entry.firstKeptTurnId.length > 0 && pathIds.has(entry.firstKeptTurnId)) {
60
+ return true;
61
+ }
62
+ return entry.parentTurnId === null ? atOrBeforeLeaf : pathIds.has(entry.parentTurnId);
63
+ }
64
+
65
+ export {
66
+ filterEntriesToActivePath,
67
+ entryBelongsToPath
68
+ };
69
+ //# sourceMappingURL=chunk-W6GROXXM.js.map