open-multi-agent-kit 0.98.2 → 0.98.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 (286) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +11 -2
  3. package/dist/cli/args.d.ts +1 -0
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +14 -0
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/help.d.ts.map +1 -1
  8. package/dist/cli/help.js +3 -0
  9. package/dist/cli/help.js.map +1 -1
  10. package/dist/cli/mcp-attach.d.ts +3 -3
  11. package/dist/cli/mcp-attach.d.ts.map +1 -1
  12. package/dist/cli/mcp-attach.js +5 -4
  13. package/dist/cli/mcp-attach.js.map +1 -1
  14. package/dist/cli/model-contract.d.ts +5 -0
  15. package/dist/cli/model-contract.d.ts.map +1 -0
  16. package/dist/cli/model-contract.js +45 -0
  17. package/dist/cli/model-contract.js.map +1 -0
  18. package/dist/commands/adaptorch-doctor-cli.d.ts.map +1 -1
  19. package/dist/commands/adaptorch-doctor-cli.js +32 -10
  20. package/dist/commands/adaptorch-doctor-cli.js.map +1 -1
  21. package/dist/commands/init-cli.d.ts +12 -0
  22. package/dist/commands/init-cli.d.ts.map +1 -0
  23. package/dist/commands/init-cli.js +76 -0
  24. package/dist/commands/init-cli.js.map +1 -0
  25. package/dist/commands/provider-sync-cli.d.ts +27 -0
  26. package/dist/commands/provider-sync-cli.d.ts.map +1 -0
  27. package/dist/commands/provider-sync-cli.js +177 -0
  28. package/dist/commands/provider-sync-cli.js.map +1 -0
  29. package/dist/commands/run-command.d.ts +8 -0
  30. package/dist/commands/run-command.d.ts.map +1 -0
  31. package/dist/commands/run-command.js +26 -0
  32. package/dist/commands/run-command.js.map +1 -0
  33. package/dist/core/active-skill-state.d.ts +7 -0
  34. package/dist/core/active-skill-state.d.ts.map +1 -0
  35. package/dist/core/active-skill-state.js +25 -0
  36. package/dist/core/active-skill-state.js.map +1 -0
  37. package/dist/core/advisory-judge-model.d.ts.map +1 -1
  38. package/dist/core/advisory-judge-model.js +8 -1
  39. package/dist/core/advisory-judge-model.js.map +1 -1
  40. package/dist/core/advisory-judge-types.d.ts +18 -1
  41. package/dist/core/advisory-judge-types.d.ts.map +1 -1
  42. package/dist/core/advisory-judge-types.js.map +1 -1
  43. package/dist/core/advisory-judge.d.ts.map +1 -1
  44. package/dist/core/advisory-judge.js +41 -6
  45. package/dist/core/advisory-judge.js.map +1 -1
  46. package/dist/core/agent-session-services.d.ts +2 -0
  47. package/dist/core/agent-session-services.d.ts.map +1 -1
  48. package/dist/core/agent-session-services.js +2 -0
  49. package/dist/core/agent-session-services.js.map +1 -1
  50. package/dist/core/agent-session.d.ts +0 -1
  51. package/dist/core/agent-session.d.ts.map +1 -1
  52. package/dist/core/agent-session.js +30 -85
  53. package/dist/core/agent-session.js.map +1 -1
  54. package/dist/core/codex-chatgpt-web-bridge.d.ts +99 -0
  55. package/dist/core/codex-chatgpt-web-bridge.d.ts.map +1 -0
  56. package/dist/core/codex-chatgpt-web-bridge.js +192 -0
  57. package/dist/core/codex-chatgpt-web-bridge.js.map +1 -0
  58. package/dist/core/codex-chatgpt-web-sync.d.ts +50 -0
  59. package/dist/core/codex-chatgpt-web-sync.d.ts.map +1 -0
  60. package/dist/core/codex-chatgpt-web-sync.js +119 -0
  61. package/dist/core/codex-chatgpt-web-sync.js.map +1 -0
  62. package/dist/core/compaction/compaction-headroom.d.ts +30 -0
  63. package/dist/core/compaction/compaction-headroom.d.ts.map +1 -0
  64. package/dist/core/compaction/compaction-headroom.js +48 -0
  65. package/dist/core/compaction/compaction-headroom.js.map +1 -0
  66. package/dist/core/compaction/compaction.d.ts +2 -29
  67. package/dist/core/compaction/compaction.d.ts.map +1 -1
  68. package/dist/core/compaction/compaction.js +19 -47
  69. package/dist/core/compaction/compaction.js.map +1 -1
  70. package/dist/core/compaction/overflow-retry-guard.d.ts +20 -0
  71. package/dist/core/compaction/overflow-retry-guard.d.ts.map +1 -0
  72. package/dist/core/compaction/overflow-retry-guard.js +38 -0
  73. package/dist/core/compaction/overflow-retry-guard.js.map +1 -0
  74. package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
  75. package/dist/core/context-budget-headroom-types.js +1 -1
  76. package/dist/core/context-budget-headroom-types.js.map +1 -1
  77. package/dist/core/context-budget-token-counter-types.d.ts +27 -0
  78. package/dist/core/context-budget-token-counter-types.d.ts.map +1 -0
  79. package/dist/core/context-budget-token-counter-types.js +2 -0
  80. package/dist/core/context-budget-token-counter-types.js.map +1 -0
  81. package/dist/core/context-budget-token-counter.d.ts +2 -26
  82. package/dist/core/context-budget-token-counter.d.ts.map +1 -1
  83. package/dist/core/context-budget-token-counter.js +2 -0
  84. package/dist/core/context-budget-token-counter.js.map +1 -1
  85. package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
  86. package/dist/core/context-budget-v2-scoring.js +14 -10
  87. package/dist/core/context-budget-v2-scoring.js.map +1 -1
  88. package/dist/core/domain-router.d.ts.map +1 -1
  89. package/dist/core/domain-router.js +1 -1
  90. package/dist/core/domain-router.js.map +1 -1
  91. package/dist/core/grok-harness-dispatch.d.ts +4 -0
  92. package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
  93. package/dist/core/grok-harness-dispatch.js +20 -3
  94. package/dist/core/grok-harness-dispatch.js.map +1 -1
  95. package/dist/core/grok-harness.d.ts +15 -9
  96. package/dist/core/grok-harness.d.ts.map +1 -1
  97. package/dist/core/grok-harness.js +34 -8
  98. package/dist/core/grok-harness.js.map +1 -1
  99. package/dist/core/mcp/tools.d.ts +2 -2
  100. package/dist/core/mcp/tools.d.ts.map +1 -1
  101. package/dist/core/mcp/tools.js +29 -3
  102. package/dist/core/mcp/tools.js.map +1 -1
  103. package/dist/core/model-registry-schema.d.ts +1081 -0
  104. package/dist/core/model-registry-schema.d.ts.map +1 -0
  105. package/dist/core/model-registry-schema.js +148 -0
  106. package/dist/core/model-registry-schema.js.map +1 -0
  107. package/dist/core/model-registry.d.ts.map +1 -1
  108. package/dist/core/model-registry.js +1 -146
  109. package/dist/core/model-registry.js.map +1 -1
  110. package/dist/core/model-resolver.d.ts +2 -1
  111. package/dist/core/model-resolver.d.ts.map +1 -1
  112. package/dist/core/model-resolver.js +2 -1
  113. package/dist/core/model-resolver.js.map +1 -1
  114. package/dist/core/prompt-preset.d.ts +1 -1
  115. package/dist/core/prompt-preset.d.ts.map +1 -1
  116. package/dist/core/prompt-preset.js +16 -1
  117. package/dist/core/prompt-preset.js.map +1 -1
  118. package/dist/core/provider-display-names.d.ts.map +1 -1
  119. package/dist/core/provider-display-names.js +1 -0
  120. package/dist/core/provider-display-names.js.map +1 -1
  121. package/dist/core/provider-resilience.d.ts +8 -0
  122. package/dist/core/provider-resilience.d.ts.map +1 -1
  123. package/dist/core/provider-resilience.js +20 -3
  124. package/dist/core/provider-resilience.js.map +1 -1
  125. package/dist/core/provider-usage-types.d.ts +42 -0
  126. package/dist/core/provider-usage-types.d.ts.map +1 -0
  127. package/dist/core/provider-usage-types.js +2 -0
  128. package/dist/core/provider-usage-types.js.map +1 -0
  129. package/dist/core/provider-usage.d.ts +2 -31
  130. package/dist/core/provider-usage.d.ts.map +1 -1
  131. package/dist/core/provider-usage.js +4 -0
  132. package/dist/core/provider-usage.js.map +1 -1
  133. package/dist/core/redaction.d.ts.map +1 -1
  134. package/dist/core/redaction.js +18 -2
  135. package/dist/core/redaction.js.map +1 -1
  136. package/dist/core/sandbox/policy-merge.d.ts +6 -0
  137. package/dist/core/sandbox/policy-merge.d.ts.map +1 -0
  138. package/dist/core/sandbox/policy-merge.js +74 -0
  139. package/dist/core/sandbox/policy-merge.js.map +1 -0
  140. package/dist/core/sandbox/policy-paths.d.ts +4 -0
  141. package/dist/core/sandbox/policy-paths.d.ts.map +1 -0
  142. package/dist/core/sandbox/policy-paths.js +21 -0
  143. package/dist/core/sandbox/policy-paths.js.map +1 -0
  144. package/dist/core/sandbox/policy-types.d.ts +75 -0
  145. package/dist/core/sandbox/policy-types.d.ts.map +1 -0
  146. package/dist/core/sandbox/policy-types.js +2 -0
  147. package/dist/core/sandbox/policy-types.js.map +1 -0
  148. package/dist/core/sandbox/policy.d.ts +3 -77
  149. package/dist/core/sandbox/policy.d.ts.map +1 -1
  150. package/dist/core/sandbox/policy.js +3 -98
  151. package/dist/core/sandbox/policy.js.map +1 -1
  152. package/dist/core/sdk-provider-stream.d.ts +14 -0
  153. package/dist/core/sdk-provider-stream.d.ts.map +1 -0
  154. package/dist/core/sdk-provider-stream.js +38 -0
  155. package/dist/core/sdk-provider-stream.js.map +1 -0
  156. package/dist/core/sdk.d.ts +5 -1
  157. package/dist/core/sdk.d.ts.map +1 -1
  158. package/dist/core/sdk.js +17 -33
  159. package/dist/core/sdk.js.map +1 -1
  160. package/dist/core/session-bash-runtime.d.ts +7 -0
  161. package/dist/core/session-bash-runtime.d.ts.map +1 -1
  162. package/dist/core/session-bash-runtime.js +10 -1
  163. package/dist/core/session-bash-runtime.js.map +1 -1
  164. package/dist/core/session-failure-cause.d.ts.map +1 -1
  165. package/dist/core/session-failure-cause.js +10 -3
  166. package/dist/core/session-failure-cause.js.map +1 -1
  167. package/dist/core/session-run-termination.d.ts +18 -0
  168. package/dist/core/session-run-termination.d.ts.map +1 -0
  169. package/dist/core/session-run-termination.js +61 -0
  170. package/dist/core/session-run-termination.js.map +1 -0
  171. package/dist/core/session-termination.d.ts.map +1 -1
  172. package/dist/core/session-termination.js +1 -1
  173. package/dist/core/session-termination.js.map +1 -1
  174. package/dist/core/skill-selector.d.ts +40 -0
  175. package/dist/core/skill-selector.d.ts.map +1 -0
  176. package/dist/core/skill-selector.js +102 -0
  177. package/dist/core/skill-selector.js.map +1 -0
  178. package/dist/core/tools/render-utils.d.ts.map +1 -1
  179. package/dist/core/tools/render-utils.js +2 -4
  180. package/dist/core/tools/render-utils.js.map +1 -1
  181. package/dist/core/turn-metrics-record.d.ts +55 -0
  182. package/dist/core/turn-metrics-record.d.ts.map +1 -0
  183. package/dist/core/turn-metrics-record.js +149 -0
  184. package/dist/core/turn-metrics-record.js.map +1 -0
  185. package/dist/core/turn-metrics.d.ts +4 -56
  186. package/dist/core/turn-metrics.d.ts.map +1 -1
  187. package/dist/core/turn-metrics.js +12 -60
  188. package/dist/core/turn-metrics.js.map +1 -1
  189. package/dist/core/verified-bash-runtime.d.ts +40 -0
  190. package/dist/core/verified-bash-runtime.d.ts.map +1 -1
  191. package/dist/core/verified-bash-runtime.js +60 -13
  192. package/dist/core/verified-bash-runtime.js.map +1 -1
  193. package/dist/guardrails/evidence-system.d.ts +1 -1
  194. package/dist/guardrails/evidence-system.d.ts.map +1 -1
  195. package/dist/guardrails/evidence-system.js +18 -29
  196. package/dist/guardrails/evidence-system.js.map +1 -1
  197. package/dist/guardrails/merge-gate-result.d.ts +4 -0
  198. package/dist/guardrails/merge-gate-result.d.ts.map +1 -0
  199. package/dist/guardrails/merge-gate-result.js +32 -0
  200. package/dist/guardrails/merge-gate-result.js.map +1 -0
  201. package/dist/index.d.ts +2 -0
  202. package/dist/index.d.ts.map +1 -1
  203. package/dist/index.js +1 -0
  204. package/dist/index.js.map +1 -1
  205. package/dist/main.d.ts.map +1 -1
  206. package/dist/main.js +22 -22
  207. package/dist/main.js.map +1 -1
  208. package/dist/modes/interactive/interactive-login-options.d.ts +27 -0
  209. package/dist/modes/interactive/interactive-login-options.d.ts.map +1 -0
  210. package/dist/modes/interactive/interactive-login-options.js +54 -0
  211. package/dist/modes/interactive/interactive-login-options.js.map +1 -0
  212. package/dist/modes/interactive/interactive-mode.d.ts +7 -4
  213. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  214. package/dist/modes/interactive/interactive-mode.js +138 -140
  215. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  216. package/dist/modes/interactive/interactive-resume-command.d.ts +3 -0
  217. package/dist/modes/interactive/interactive-resume-command.d.ts.map +1 -0
  218. package/dist/modes/interactive/interactive-resume-command.js +24 -0
  219. package/dist/modes/interactive/interactive-resume-command.js.map +1 -0
  220. package/dist/modes/interactive/interactive-tool-result.d.ts +32 -0
  221. package/dist/modes/interactive/interactive-tool-result.d.ts.map +1 -0
  222. package/dist/modes/interactive/interactive-tool-result.js +59 -0
  223. package/dist/modes/interactive/interactive-tool-result.js.map +1 -0
  224. package/dist/modes/print-mode.d.ts.map +1 -1
  225. package/dist/modes/print-mode.js +22 -0
  226. package/dist/modes/print-mode.js.map +1 -1
  227. package/dist/utils/clipboard-image.d.ts.map +1 -1
  228. package/dist/utils/clipboard-image.js +10 -60
  229. package/dist/utils/clipboard-image.js.map +1 -1
  230. package/dist/utils/terminal-links.d.ts +13 -0
  231. package/dist/utils/terminal-links.d.ts.map +1 -0
  232. package/dist/utils/terminal-links.js +68 -0
  233. package/dist/utils/terminal-links.js.map +1 -0
  234. package/dist/utils/windows-clipboard-image.d.ts +16 -0
  235. package/dist/utils/windows-clipboard-image.d.ts.map +1 -0
  236. package/dist/utils/windows-clipboard-image.js +87 -0
  237. package/dist/utils/windows-clipboard-image.js.map +1 -0
  238. package/docs/adaptorch-onboarding.md +80 -0
  239. package/docs/advisory-selection.md +112 -0
  240. package/docs/containerization.md +12 -0
  241. package/docs/context-files.md +97 -0
  242. package/docs/correctness-wall.md +8 -0
  243. package/docs/custom-provider.md +35 -0
  244. package/docs/development.md +18 -3
  245. package/docs/environment-variables.md +2 -0
  246. package/docs/grok-harness.md +4 -0
  247. package/docs/harness-boundaries.md +154 -0
  248. package/docs/harness-improvements.md +90 -0
  249. package/docs/json.md +19 -0
  250. package/docs/keybindings.md +1 -1
  251. package/docs/mcp.md +22 -2
  252. package/docs/metrics.md +66 -16
  253. package/docs/model-catalog-refresh.md +190 -0
  254. package/docs/model-contract.md +168 -0
  255. package/docs/models.md +21 -4
  256. package/docs/provider-resilience.md +5 -3
  257. package/docs/providers.md +68 -1
  258. package/docs/quickstart.md +4 -0
  259. package/docs/release-audit-0.98.3.md +97 -0
  260. package/docs/release-audit-0.98.4.md +112 -0
  261. package/docs/review-bundle-followup.md +195 -0
  262. package/docs/run-protocol.md +3 -1
  263. package/docs/runtime-algorithms.md +38 -2
  264. package/docs/sdk.md +35 -3
  265. package/docs/sessions.md +1 -1
  266. package/docs/settings.md +17 -1
  267. package/docs/skills.md +2 -0
  268. package/docs/tb21-audit.md +131 -0
  269. package/docs/terminal-setup.md +20 -0
  270. package/docs/usage.md +23 -1
  271. package/docs/windows.md +48 -0
  272. package/examples/README.md +4 -0
  273. package/examples/context/AGENTS.md +64 -0
  274. package/examples/context/CLAUDE.md +17 -0
  275. package/examples/context/INTERNET.md +42 -0
  276. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  277. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  278. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  279. package/examples/extensions/gondolin/package-lock.json +2 -2
  280. package/examples/extensions/gondolin/package.json +1 -1
  281. package/examples/extensions/sandbox/package-lock.json +2 -2
  282. package/examples/extensions/sandbox/package.json +1 -1
  283. package/examples/extensions/with-deps/package-lock.json +2 -2
  284. package/examples/extensions/with-deps/package.json +1 -1
  285. package/npm-shrinkwrap.json +18 -18
  286. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"session-termination.js","sourceRoot":"","sources":["../../src/core/session-termination.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC9C,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,mBAAmB;CACV,CA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AC,WAAW;QAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,GAAG,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;QACjF,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QACrE,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5D,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;QAC3E,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QACrE,GAAG,CAAC,cAAc,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,cAAc,CAAC,aAAa,EAAE,CAAC;QACtG,GAAG,CAAC,cAAc,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,cAAc,CAAC,eAAe,EAAE,CAAC;KAC5G,CAAC,CAAC;AAAA,CACH","sourcesContent":["export const SESSION_TERMINATION_SCHEMA_VERSION = 1 as const;\nexport const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;\n\n/**\n * Canonical list of termination kinds. The run-journal validator derives its\n * runtime bounds from this tuple so a newly added kind can never crash\n * journaling with \"termination kind is out of bounds\" again.\n */\nexport const SESSION_TERMINATION_KIND_VALUES = [\n\t\"completed\",\n\t\"user_abort\",\n\t\"provider_abort\",\n\t\"provider_auth\",\n\t\"provider_rate_limit\",\n\t\"provider_network\",\n\t\"provider_protocol\",\n\t\"provider_refusal\",\n\t\"context_overflow\",\n\t\"transcript_invalid\",\n\t\"tool_timeout\",\n\t\"tool_fatal\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process_signal\",\n\t\"process_crash\",\n\t\"configuration\",\n\t\"internal_error\",\n\t\"resource_pressure\",\n] as const;\n\nexport type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];\n\nexport type SessionTerminationPhase =\n\t| \"completed\"\n\t| \"control\"\n\t| \"preflight\"\n\t| \"provider\"\n\t| \"tool\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process\"\n\t| \"resume\";\n\nexport type SessionTerminationSource = \"observed\" | \"inferred_on_resume\";\nexport type SessionSideEffects = \"none\" | \"possible\" | \"confirmed\";\nexport type SessionProcessSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGHUP\" | \"SIGQUIT\";\n\nexport type ProviderTerminationCauseCode =\n\t| \"abort\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"network\"\n\t| \"protocol\"\n\t| \"refusal\"\n\t| \"context_overflow\";\nexport type ToolTerminationCauseCode = \"timeout\" | \"fatal\";\n/** §15.4 resource-aware runtime roadmap: host-pressure termination causes. */\nexport type ResourceTerminationCauseCode = \"memory\" | \"disk\" | \"cpu\" | \"heap\" | \"probe_unavailable\" | \"queue_overflow\";\nexport type CompactionTerminationCauseCode = \"aborted\" | \"failed\" | \"stale\" | \"quota_exhausted\";\nexport type PersistenceTerminationCauseCode =\n\t| \"read_failed\"\n\t| \"append_failed\"\n\t| \"replace_failed\"\n\t| \"fsync_failed\"\n\t| \"lock_failed\";\nexport type TranscriptTerminationCauseCode =\n\t| \"missing_result\"\n\t| \"duplicate_result\"\n\t| \"orphan_result\"\n\t| \"duplicate_call_id\"\n\t| \"interleaved_non_result\"\n\t| \"invalid_jsonl\"\n\t| \"invalid_tree\"\n\t| \"unsupported_version\"\n\t| \"trailing_fragment\";\nexport type SessionTerminationCauseCode =\n\t| \"session.completed\"\n\t| \"session.user_abort\"\n\t| `provider.${ProviderTerminationCauseCode}`\n\t| `tool.${ToolTerminationCauseCode}`\n\t| `compaction.${CompactionTerminationCauseCode}`\n\t| `persistence.${PersistenceTerminationCauseCode}`\n\t| \"process.signal\"\n\t| \"process.crash\"\n\t| `transcript.${TranscriptTerminationCauseCode}`\n\t| \"configuration.invalid\"\n\t| \"internal.unclassified\"\n\t| `resource.${ResourceTerminationCauseCode}`;\n\nexport type SessionTerminationCause =\n\t| { readonly area: \"completed\" }\n\t| { readonly area: \"user\"; readonly code: \"abort\" }\n\t| { readonly area: \"provider\"; readonly code: ProviderTerminationCauseCode }\n\t| { readonly area: \"tool\"; readonly code: ToolTerminationCauseCode }\n\t| { readonly area: \"compaction\"; readonly code: CompactionTerminationCauseCode }\n\t| { readonly area: \"persistence\"; readonly code: PersistenceTerminationCauseCode }\n\t| { readonly area: \"process\"; readonly code: \"signal\"; readonly signal: SessionProcessSignal }\n\t| { readonly area: \"process\"; readonly code: \"crash\" }\n\t| { readonly area: \"transcript\"; readonly code: TranscriptTerminationCauseCode }\n\t| { readonly area: \"configuration\"; readonly code: \"invalid\" }\n\t| { readonly area: \"internal\"; readonly code: \"unclassified\" }\n\t| { readonly area: \"resource\"; readonly code: ResourceTerminationCauseCode };\n\nexport interface ClassifySessionTerminationInput {\n\treadonly sessionId: string;\n\treadonly runId: string;\n\t/** Deterministic caller-provided ISO-8601 timestamp. */\n\treadonly timestamp: string;\n\treadonly source: SessionTerminationSource;\n\t/** Caller-supplied, pre-redacted diagnostic text. */\n\treadonly message: string;\n\treadonly cause: SessionTerminationCause;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n}\n\nexport interface SessionTermination {\n\treadonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly source: SessionTerminationSource;\n\treadonly message: string;\n\treadonly causeCode: SessionTerminationCauseCode;\n\t/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */\n\treadonly nextAction: string;\n\treadonly retryable: boolean;\n\treadonly safeToAutoRetry: boolean;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly timestamp: string;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nexport class SessionTerminationError extends Error {\n\treadonly termination: SessionTermination;\n\n\tconstructor(message: string, termination: SessionTermination) {\n\t\tsuper(message);\n\t\tthis.name = \"SessionTerminationError\";\n\t\tthis.termination = termination;\n\t}\n}\n\ninterface Classification {\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly causeCode: SessionTerminationCauseCode;\n\treadonly retryable: boolean;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nconst CREDENTIAL_SHAPES = [\n\t/-----BEGIN [A-Z ]*PRIVATE KEY-----/i,\n\t/\\b(?:sk-[A-Za-z0-9_-]{16,}|github_pat_[A-Za-z0-9_]{16,}|gh[pousr]_[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[A-Z0-9]{16})\\b/,\n\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}={0,2}\\b/i,\n\t/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\b/,\n\t/(?:^|[^A-Za-z0-9])(?:[A-Za-z0-9]+[_-])*(?:authorization|api[-_ ]?key|access[-_ ]?token|token|password|secret(?:[-_ ]?key)?|private[-_ ]?key|cookie)[\"']?\\s*[:=]/i,\n] as const;\n\nconst TOP_LEVEL_KEYS = new Set([\n\t\"sessionId\",\n\t\"runId\",\n\t\"timestamp\",\n\t\"source\",\n\t\"message\",\n\t\"cause\",\n\t\"sideEffects\",\n\t\"retryAfterMs\",\n\t\"provider\",\n\t\"model\",\n\t\"toolCallId\",\n\t\"toolName\",\n]);\nconst PROVIDER_CAUSE_CODES = new Set<ProviderTerminationCauseCode>([\n\t\"abort\",\n\t\"auth\",\n\t\"rate_limit\",\n\t\"network\",\n\t\"protocol\",\n\t\"refusal\",\n\t\"context_overflow\",\n]);\nconst TOOL_CAUSE_CODES = new Set<ToolTerminationCauseCode>([\"timeout\", \"fatal\"]);\nconst RESOURCE_CAUSE_CODES = new Set<ResourceTerminationCauseCode>([\n\t\"memory\",\n\t\"disk\",\n\t\"cpu\",\n\t\"heap\",\n\t\"probe_unavailable\",\n\t\"queue_overflow\",\n]);\nconst COMPACTION_CAUSE_CODES = new Set<CompactionTerminationCauseCode>([\n\t\"aborted\",\n\t\"failed\",\n\t\"stale\",\n\t\"quota_exhausted\",\n]);\nconst PERSISTENCE_CAUSE_CODES = new Set<PersistenceTerminationCauseCode>([\n\t\"read_failed\",\n\t\"append_failed\",\n\t\"replace_failed\",\n\t\"fsync_failed\",\n\t\"lock_failed\",\n]);\nconst TRANSCRIPT_CAUSE_CODES = new Set<TranscriptTerminationCauseCode>([\n\t\"missing_result\",\n\t\"duplicate_result\",\n\t\"orphan_result\",\n\t\"duplicate_call_id\",\n\t\"interleaved_non_result\",\n\t\"invalid_jsonl\",\n\t\"invalid_tree\",\n\t\"unsupported_version\",\n\t\"trailing_fragment\",\n]);\nconst PROCESS_SIGNALS = new Set<SessionProcessSignal>([\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {\n\tconst allowed = new Set(keys);\n\treturn Object.keys(value).every((key) => allowed.has(key));\n}\n\nfunction assertCause(cause: unknown): asserts cause is SessionTerminationCause {\n\tif (!isRecord(cause) || typeof cause.area !== \"string\") {\n\t\tthrow new TypeError(\"cause must be a bounded structured termination cause\");\n\t}\n\tconst code = cause.code;\n\tlet valid = false;\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\tvalid = hasOnlyKeys(cause, [\"area\"]);\n\t\t\tbreak;\n\t\tcase \"user\":\n\t\t\tvalid = code === \"abort\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"provider\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPROVIDER_CAUSE_CODES.has(code as ProviderTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTOOL_CAUSE_CODES.has(code as ToolTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"compaction\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tCOMPACTION_CAUSE_CODES.has(code as CompactionTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"persistence\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPERSISTENCE_CAUSE_CODES.has(code as PersistenceTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"process\":\n\t\t\tvalid =\n\t\t\t\t(code === \"crash\" && hasOnlyKeys(cause, [\"area\", \"code\"])) ||\n\t\t\t\t(code === \"signal\" &&\n\t\t\t\t\ttypeof cause.signal === \"string\" &&\n\t\t\t\t\tPROCESS_SIGNALS.has(cause.signal as SessionProcessSignal) &&\n\t\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\", \"signal\"]));\n\t\t\tbreak;\n\t\tcase \"transcript\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTRANSCRIPT_CAUSE_CODES.has(code as TranscriptTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"configuration\":\n\t\t\tvalid = code === \"invalid\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"internal\":\n\t\t\tvalid = code === \"unclassified\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"resource\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tRESOURCE_CAUSE_CODES.has(code as ResourceTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t}\n\tif (!valid) throw new TypeError(\"cause must be a bounded structured termination cause\");\n}\n\nfunction assertClassifierInput(input: unknown): asserts input is ClassifySessionTerminationInput {\n\tif (!isRecord(input) || Object.keys(input).some((key) => !TOP_LEVEL_KEYS.has(key))) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tif (\n\t\ttypeof input.sessionId !== \"string\" ||\n\t\ttypeof input.runId !== \"string\" ||\n\t\ttypeof input.timestamp !== \"string\" ||\n\t\ttypeof input.message !== \"string\" ||\n\t\t(input.source !== \"observed\" && input.source !== \"inferred_on_resume\") ||\n\t\t(input.sideEffects !== \"none\" && input.sideEffects !== \"possible\" && input.sideEffects !== \"confirmed\") ||\n\t\t(input.retryAfterMs !== undefined && typeof input.retryAfterMs !== \"number\") ||\n\t\t(input.provider !== undefined && typeof input.provider !== \"string\") ||\n\t\t(input.model !== undefined && typeof input.model !== \"string\") ||\n\t\t(input.toolCallId !== undefined && typeof input.toolCallId !== \"string\") ||\n\t\t(input.toolName !== undefined && typeof input.toolName !== \"string\")\n\t) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tassertCause(input.cause);\n}\n\nfunction assertIdentifier(value: string, name: string, maxLength: number): void {\n\tif (value.length === 0 || value.length > maxLength || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new TypeError(`${name} must be non-empty bounded text without C0 or DEL control characters`);\n\t}\n}\n\n/** Validate text at the termination trust boundary without attempting redaction. */\nexport function assertPreRedactedTerminationMessage(message: string): void {\n\tif (message.length === 0 || message.length > MAX_SESSION_TERMINATION_MESSAGE_LENGTH) {\n\t\tthrow new TypeError(\n\t\t\t`message must contain 1-${MAX_SESSION_TERMINATION_MESSAGE_LENGTH} characters of pre-redacted text`,\n\t\t);\n\t}\n\tif (message.includes(\"\\0\")) {\n\t\tthrow new TypeError(\"message must not contain NUL\");\n\t}\n\tif (CREDENTIAL_SHAPES.some((pattern) => pattern.test(message))) {\n\t\tthrow new TypeError(\"message contains a credential-shaped literal; redact it before classification\");\n\t}\n}\n\nfunction assertTimestamp(timestamp: string): void {\n\tconst parsed = new Date(timestamp);\n\tif (!Number.isFinite(parsed.getTime()) || parsed.toISOString() !== timestamp) {\n\t\tthrow new TypeError(\"timestamp must be a canonical ISO-8601 UTC instant\");\n\t}\n}\n\nfunction classifyProvider(code: ProviderTerminationCauseCode): Classification {\n\tswitch (code) {\n\t\tcase \"abort\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_abort\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.abort\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"auth\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_auth\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.auth\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"rate_limit\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_rate_limit\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.rate_limit\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"network\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_network\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.network\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"protocol\":\n\t\t\t// Many \"protocol\" stops are sticky transcript shape bugs (orphan tool_call_id)\n\t\t\t// that succeed after transform-messages sanitizes and the turn is retried.\n\t\t\t// Mark retryable so auto-retry can heal; safeToAutoRetry stays false (needs sanitize path).\n\t\t\treturn {\n\t\t\t\tkind: \"provider_protocol\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.protocol\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"context_overflow\":\n\t\t\treturn {\n\t\t\t\tkind: \"context_overflow\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.context_overflow\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"refusal\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_refusal\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.refusal\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t}\n}\n\nfunction classifyCause(cause: SessionTerminationCause, source: SessionTerminationSource): Classification {\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\treturn {\n\t\t\t\tkind: \"completed\",\n\t\t\t\tphase: \"completed\",\n\t\t\t\tcauseCode: \"session.completed\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"user\":\n\t\t\treturn {\n\t\t\t\tkind: \"user_abort\",\n\t\t\t\tphase: \"control\",\n\t\t\t\tcauseCode: \"session.user_abort\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"provider\":\n\t\t\treturn classifyProvider(cause.code);\n\t\tcase \"tool\":\n\t\t\treturn cause.code === \"timeout\"\n\t\t\t\t? { kind: \"tool_timeout\", phase: \"tool\", causeCode: \"tool.timeout\", retryable: true }\n\t\t\t\t: { kind: \"tool_fatal\", phase: \"tool\", causeCode: \"tool.fatal\", retryable: false };\n\t\tcase \"compaction\":\n\t\t\treturn {\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tphase: \"compaction\",\n\t\t\t\tcauseCode: `compaction.${cause.code}`,\n\t\t\t\t// Quota exhaustion does not heal by retrying: same-model retries\n\t\t\t\t// keep failing until the provider cycle resets or the model changes.\n\t\t\t\tretryable: cause.code !== \"quota_exhausted\",\n\t\t\t};\n\t\tcase \"persistence\":\n\t\t\treturn {\n\t\t\t\tkind: \"persistence\",\n\t\t\t\tphase: \"persistence\",\n\t\t\t\tcauseCode: `persistence.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"process\":\n\t\t\tif (cause.code === \"signal\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"process_signal\",\n\t\t\t\t\tphase: \"process\",\n\t\t\t\t\tcauseCode: \"process.signal\",\n\t\t\t\t\tretryable: false,\n\t\t\t\t\tprocessSignal: cause.signal,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"process_crash\",\n\t\t\t\tphase: \"resume\",\n\t\t\t\tcauseCode: \"process.crash\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"transcript\":\n\t\t\treturn {\n\t\t\t\tkind: \"transcript_invalid\",\n\t\t\t\tphase: source === \"inferred_on_resume\" ? \"resume\" : \"preflight\",\n\t\t\t\tcauseCode: `transcript.${cause.code}`,\n\t\t\t\tretryable: false,\n\t\t\t\ttranscriptIssue: cause.code,\n\t\t\t};\n\t\tcase \"configuration\":\n\t\t\treturn {\n\t\t\t\tkind: \"configuration\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"configuration.invalid\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"internal\":\n\t\t\treturn {\n\t\t\t\tkind: \"internal_error\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"internal.unclassified\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"resource\":\n\t\t\t// §15.4: every resource cause is retryable; queue overflow surfaces at\n\t\t\t// the tool boundary, everything else at preflight admission.\n\t\t\treturn {\n\t\t\t\tkind: \"resource_pressure\",\n\t\t\t\tphase: cause.code === \"queue_overflow\" ? \"tool\" : \"preflight\",\n\t\t\t\tcauseCode: `resource.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t}\n}\n\nfunction isSafeToAutoRetry(classification: Classification, input: ClassifySessionTerminationInput): boolean {\n\t// provider_refusal: Fable/Claude often false-positive on benign turns. Safe to auto-retry once\n\t// when no tool side effects occurred (same class of recovery as rate_limit/network).\n\treturn (\n\t\tclassification.retryable &&\n\t\tinput.source === \"observed\" &&\n\t\tinput.sideEffects === \"none\" &&\n\t\t(classification.kind === \"provider_rate_limit\" ||\n\t\t\tclassification.kind === \"provider_network\" ||\n\t\t\tclassification.kind === \"provider_refusal\" ||\n\t\t\t// §15.4 mapping: only cpu pressure is safe to auto-retry (with delay).\n\t\t\tclassification.causeCode === \"resource.cpu\")\n\t);\n}\n\nfunction nextActionFor(classification: Classification, input: ClassifySessionTerminationInput): string {\n\tswitch (classification.kind) {\n\t\tcase \"completed\":\n\t\t\treturn \"No recovery action is required; continue with the next prompt.\";\n\t\tcase \"user_abort\":\n\t\t\treturn \"Review possible partial side effects, then retry only if intended.\";\n\t\tcase \"resource_pressure\":\n\t\t\treturn \"Host resources are constrained; reduce load or wait for recovery, then retry.\";\n\t\tcase \"provider_abort\":\n\t\t\treturn \"Confirm provider availability, then retry the request.\";\n\t\tcase \"provider_auth\":\n\t\t\t// A credential-less install resolves a placeholder model whose provider is\n\t\t\t// literally \"unknown\"; never echo that back as a login target.\n\t\t\treturn `Run /login${input.provider && input.provider !== \"unknown\" ? ` ${input.provider}` : \"\"} in an interactive session, or set the provider's API key environment variable, then retry.`;\n\t\tcase \"provider_rate_limit\":\n\t\t\treturn \"Wait for the provider retry window or choose another model, then retry.\";\n\t\tcase \"provider_network\":\n\t\t\treturn \"Check network and provider connectivity, then retry.\";\n\t\tcase \"provider_protocol\":\n\t\t\treturn \"Often an orphan tool_call_id / sticky transcript after a dropped error turn — auto-retry after sanitize, or /new session if it persists.\";\n\t\tcase \"provider_refusal\":\n\t\t\treturn \"Model declined this turn (content/safety stop). Usually a false positive on Fable/Claude — auto-retry once, or switch model (k3/qwen3.8-max/grok-4.5/deepseek) / rephrase as a pure coding task.\";\n\t\tcase \"context_overflow\":\n\t\t\treturn \"Compact or reduce context, or switch to a larger-context model.\";\n\t\tcase \"tool_timeout\":\n\t\t\treturn \"Inspect possible tool side effects and increase the tool timeout only if safe.\";\n\t\tcase \"tool_fatal\":\n\t\t\treturn \"Inspect the failed tool result and repair its configuration before retrying.\";\n\t\tcase \"compaction\":\n\t\t\tswitch (classification.causeCode) {\n\t\t\t\tcase \"compaction.aborted\":\n\t\t\t\t\treturn \"Retry /compact if cancellation was unintended; avoid Escape while compaction is running.\";\n\t\t\t\tcase \"compaction.stale\":\n\t\t\t\t\treturn \"Retry /compact after pending session changes settle.\";\n\t\t\t\tcase \"compaction.quota_exhausted\":\n\t\t\t\t\treturn \"The summarization model's quota is exhausted — retrying cannot help yet. Switch model (/model), set compaction.model in settings, or wait for the quota reset, then retry /compact. OMK already tried the failover chain automatically.\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn \"Resolve the reported compaction error, then retry /compact.\";\n\t\t\t}\n\t\tcase \"persistence\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} before resuming.`;\n\t\tcase \"process_signal\":\n\t\t\treturn \"Review possible partial side effects before resuming the session.\";\n\t\tcase \"process_crash\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} and review partial side effects.`;\n\t\tcase \"transcript_invalid\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId}; do not resume until integrity passes.`;\n\t\tcase \"configuration\":\n\t\t\treturn \"Correct the provider, model, tool, or session configuration and retry.\";\n\t\tcase \"internal_error\":\n\t\t\treturn `Inspect run ${input.runId} diagnostics and the run journal before retrying.`;\n\t}\n}\n\n/** Concise actionable rendering shared by non-JSON and TUI surfaces. */\nexport function formatSessionTermination(termination: SessionTermination): string {\n\tconst route =\n\t\ttermination.provider || termination.model\n\t\t\t? `${termination.provider ?? \"unknown\"}/${termination.model ?? \"unknown\"}`\n\t\t\t: \"n/a\";\n\treturn [\n\t\t`kind=${termination.kind}`,\n\t\t`provider/model=${route}`,\n\t\t`retryable=${termination.retryable}`,\n\t\t`cause=${termination.causeCode}`,\n\t\t`message=${termination.message}`,\n\t\t`run=${termination.runId}`,\n\t\t`next=${termination.nextAction}`,\n\t].join(\" \");\n}\n\n/**\n * Classify a bounded, structured termination cause. This intentionally accepts\n * no raw Error value, stack, provider body, or arbitrary cause code.\n */\nexport function classifySessionTermination(input: ClassifySessionTerminationInput): SessionTermination {\n\tassertClassifierInput(input);\n\tassertIdentifier(input.sessionId, \"sessionId\", 128);\n\tassertIdentifier(input.runId, \"runId\", 128);\n\tassertTimestamp(input.timestamp);\n\tassertPreRedactedTerminationMessage(input.message);\n\tif (input.provider !== undefined) assertIdentifier(input.provider, \"provider\", 128);\n\tif (input.model !== undefined) assertIdentifier(input.model, \"model\", 256);\n\tif (input.toolCallId !== undefined) assertIdentifier(input.toolCallId, \"toolCallId\", 512);\n\tif (input.toolName !== undefined) assertIdentifier(input.toolName, \"toolName\", 128);\n\tif (input.retryAfterMs !== undefined && (!Number.isSafeInteger(input.retryAfterMs) || input.retryAfterMs < 0)) {\n\t\tthrow new TypeError(\"retryAfterMs must be a non-negative safe integer\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"crash\" && input.source !== \"inferred_on_resume\") {\n\t\tthrow new TypeError(\"process crashes may only be classified as inferred_on_resume\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"signal\" && input.source !== \"observed\") {\n\t\tthrow new TypeError(\"process signals must be observed\");\n\t}\n\n\tconst classification = classifyCause(input.cause, input.source);\n\treturn Object.freeze({\n\t\tschemaVersion: SESSION_TERMINATION_SCHEMA_VERSION,\n\t\tsessionId: input.sessionId,\n\t\trunId: input.runId,\n\t\tkind: classification.kind,\n\t\tphase: classification.phase,\n\t\tsource: input.source,\n\t\tmessage: input.message,\n\t\tcauseCode: classification.causeCode,\n\t\tnextAction: nextActionFor(classification, input),\n\t\tretryable: classification.retryable,\n\t\tsafeToAutoRetry: isSafeToAutoRetry(classification, input),\n\t\tsideEffects: input.sideEffects,\n\t\ttimestamp: input.timestamp,\n\t\t...(input.retryAfterMs === undefined ? {} : { retryAfterMs: input.retryAfterMs }),\n\t\t...(input.provider === undefined ? {} : { provider: input.provider }),\n\t\t...(input.model === undefined ? {} : { model: input.model }),\n\t\t...(input.toolCallId === undefined ? {} : { toolCallId: input.toolCallId }),\n\t\t...(input.toolName === undefined ? {} : { toolName: input.toolName }),\n\t\t...(classification.processSignal === undefined ? {} : { processSignal: classification.processSignal }),\n\t\t...(classification.transcriptIssue === undefined ? {} : { transcriptIssue: classification.transcriptIssue }),\n\t});\n}\n"]}
1
+ {"version":3,"file":"session-termination.js","sourceRoot":"","sources":["../../src/core/session-termination.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAE1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC9C,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;IACnB,k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ERMINATION_SCHEMA_VERSION = 1 as const;\nexport const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;\n\n/**\n * Canonical list of termination kinds. The run-journal validator derives its\n * runtime bounds from this tuple so a newly added kind can never crash\n * journaling with \"termination kind is out of bounds\" again.\n */\nexport const SESSION_TERMINATION_KIND_VALUES = [\n\t\"completed\",\n\t\"user_abort\",\n\t\"provider_abort\",\n\t\"provider_auth\",\n\t\"provider_rate_limit\",\n\t\"provider_network\",\n\t\"provider_protocol\",\n\t\"provider_refusal\",\n\t\"context_overflow\",\n\t\"transcript_invalid\",\n\t\"tool_timeout\",\n\t\"tool_fatal\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process_signal\",\n\t\"process_crash\",\n\t\"configuration\",\n\t\"internal_error\",\n\t\"resource_pressure\",\n] as const;\n\nexport type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];\n\nexport type SessionTerminationPhase =\n\t| \"completed\"\n\t| \"control\"\n\t| \"preflight\"\n\t| \"provider\"\n\t| \"tool\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process\"\n\t| \"resume\";\n\nexport type SessionTerminationSource = \"observed\" | \"inferred_on_resume\";\nexport type SessionSideEffects = \"none\" | \"possible\" | \"confirmed\";\nexport type SessionProcessSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGHUP\" | \"SIGQUIT\";\n\nexport type ProviderTerminationCauseCode =\n\t| \"abort\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"network\"\n\t| \"protocol\"\n\t| \"refusal\"\n\t| \"context_overflow\";\nexport type ToolTerminationCauseCode = \"timeout\" | \"fatal\";\n/** §15.4 resource-aware runtime roadmap: host-pressure termination causes. */\nexport type ResourceTerminationCauseCode = \"memory\" | \"disk\" | \"cpu\" | \"heap\" | \"probe_unavailable\" | \"queue_overflow\";\nexport type CompactionTerminationCauseCode = \"aborted\" | \"failed\" | \"stale\" | \"quota_exhausted\";\nexport type PersistenceTerminationCauseCode =\n\t| \"read_failed\"\n\t| \"append_failed\"\n\t| \"replace_failed\"\n\t| \"fsync_failed\"\n\t| \"lock_failed\";\nexport type TranscriptTerminationCauseCode =\n\t| \"missing_result\"\n\t| \"duplicate_result\"\n\t| \"orphan_result\"\n\t| \"duplicate_call_id\"\n\t| \"interleaved_non_result\"\n\t| \"invalid_jsonl\"\n\t| \"invalid_tree\"\n\t| \"unsupported_version\"\n\t| \"trailing_fragment\";\nexport type SessionTerminationCauseCode =\n\t| \"session.completed\"\n\t| \"session.user_abort\"\n\t| `provider.${ProviderTerminationCauseCode}`\n\t| `tool.${ToolTerminationCauseCode}`\n\t| `compaction.${CompactionTerminationCauseCode}`\n\t| `persistence.${PersistenceTerminationCauseCode}`\n\t| \"process.signal\"\n\t| \"process.crash\"\n\t| `transcript.${TranscriptTerminationCauseCode}`\n\t| \"configuration.invalid\"\n\t| \"internal.unclassified\"\n\t| `resource.${ResourceTerminationCauseCode}`;\n\nexport type SessionTerminationCause =\n\t| { readonly area: \"completed\" }\n\t| { readonly area: \"user\"; readonly code: \"abort\" }\n\t| { readonly area: \"provider\"; readonly code: ProviderTerminationCauseCode }\n\t| { readonly area: \"tool\"; readonly code: ToolTerminationCauseCode }\n\t| { readonly area: \"compaction\"; readonly code: CompactionTerminationCauseCode }\n\t| { readonly area: \"persistence\"; readonly code: PersistenceTerminationCauseCode }\n\t| { readonly area: \"process\"; readonly code: \"signal\"; readonly signal: SessionProcessSignal }\n\t| { readonly area: \"process\"; readonly code: \"crash\" }\n\t| { readonly area: \"transcript\"; readonly code: TranscriptTerminationCauseCode }\n\t| { readonly area: \"configuration\"; readonly code: \"invalid\" }\n\t| { readonly area: \"internal\"; readonly code: \"unclassified\" }\n\t| { readonly area: \"resource\"; readonly code: ResourceTerminationCauseCode };\n\nexport interface ClassifySessionTerminationInput {\n\treadonly sessionId: string;\n\treadonly runId: string;\n\t/** Deterministic caller-provided ISO-8601 timestamp. */\n\treadonly timestamp: string;\n\treadonly source: SessionTerminationSource;\n\t/** Caller-supplied, pre-redacted diagnostic text. */\n\treadonly message: string;\n\treadonly cause: SessionTerminationCause;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n}\n\nexport interface SessionTermination {\n\treadonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly source: SessionTerminationSource;\n\treadonly message: string;\n\treadonly causeCode: SessionTerminationCauseCode;\n\t/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */\n\treadonly nextAction: string;\n\treadonly retryable: boolean;\n\treadonly safeToAutoRetry: boolean;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly timestamp: string;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nexport class SessionTerminationError extends Error {\n\treadonly termination: SessionTermination;\n\n\tconstructor(message: string, termination: SessionTermination) {\n\t\tsuper(message);\n\t\tthis.name = \"SessionTerminationError\";\n\t\tthis.termination = termination;\n\t}\n}\n\ninterface Classification {\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly causeCode: SessionTerminationCauseCode;\n\treadonly retryable: boolean;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nconst CREDENTIAL_SHAPES = [\n\t/-----BEGIN [A-Z ]*PRIVATE KEY-----/i,\n\t/\\b(?:sk-[A-Za-z0-9_-]{16,}|github_pat_[A-Za-z0-9_]{16,}|gh[pousr]_[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[A-Z0-9]{16})\\b/,\n\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}={0,2}\\b/i,\n\t/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\b/,\n\t/(?:^|[^A-Za-z0-9])(?:[A-Za-z0-9]+[_-])*(?:authorization|api[-_ ]?key|access[-_ ]?token|token|password|secret(?:[-_ ]?key)?|private[-_ ]?key|cookie)[\"']?\\s*[:=]/i,\n] as const;\n\nconst TOP_LEVEL_KEYS = new Set([\n\t\"sessionId\",\n\t\"runId\",\n\t\"timestamp\",\n\t\"source\",\n\t\"message\",\n\t\"cause\",\n\t\"sideEffects\",\n\t\"retryAfterMs\",\n\t\"provider\",\n\t\"model\",\n\t\"toolCallId\",\n\t\"toolName\",\n]);\nconst PROVIDER_CAUSE_CODES = new Set<ProviderTerminationCauseCode>([\n\t\"abort\",\n\t\"auth\",\n\t\"rate_limit\",\n\t\"network\",\n\t\"protocol\",\n\t\"refusal\",\n\t\"context_overflow\",\n]);\nconst TOOL_CAUSE_CODES = new Set<ToolTerminationCauseCode>([\"timeout\", \"fatal\"]);\nconst RESOURCE_CAUSE_CODES = new Set<ResourceTerminationCauseCode>([\n\t\"memory\",\n\t\"disk\",\n\t\"cpu\",\n\t\"heap\",\n\t\"probe_unavailable\",\n\t\"queue_overflow\",\n]);\nconst COMPACTION_CAUSE_CODES = new Set<CompactionTerminationCauseCode>([\n\t\"aborted\",\n\t\"failed\",\n\t\"stale\",\n\t\"quota_exhausted\",\n]);\nconst PERSISTENCE_CAUSE_CODES = new Set<PersistenceTerminationCauseCode>([\n\t\"read_failed\",\n\t\"append_failed\",\n\t\"replace_failed\",\n\t\"fsync_failed\",\n\t\"lock_failed\",\n]);\nconst TRANSCRIPT_CAUSE_CODES = new Set<TranscriptTerminationCauseCode>([\n\t\"missing_result\",\n\t\"duplicate_result\",\n\t\"orphan_result\",\n\t\"duplicate_call_id\",\n\t\"interleaved_non_result\",\n\t\"invalid_jsonl\",\n\t\"invalid_tree\",\n\t\"unsupported_version\",\n\t\"trailing_fragment\",\n]);\nconst PROCESS_SIGNALS = new Set<SessionProcessSignal>([\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {\n\tconst allowed = new Set(keys);\n\treturn Object.keys(value).every((key) => allowed.has(key));\n}\n\nfunction assertCause(cause: unknown): asserts cause is SessionTerminationCause {\n\tif (!isRecord(cause) || typeof cause.area !== \"string\") {\n\t\tthrow new TypeError(\"cause must be a bounded structured termination cause\");\n\t}\n\tconst code = cause.code;\n\tlet valid = false;\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\tvalid = hasOnlyKeys(cause, [\"area\"]);\n\t\t\tbreak;\n\t\tcase \"user\":\n\t\t\tvalid = code === \"abort\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"provider\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPROVIDER_CAUSE_CODES.has(code as ProviderTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTOOL_CAUSE_CODES.has(code as ToolTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"compaction\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tCOMPACTION_CAUSE_CODES.has(code as CompactionTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"persistence\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPERSISTENCE_CAUSE_CODES.has(code as PersistenceTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"process\":\n\t\t\tvalid =\n\t\t\t\t(code === \"crash\" && hasOnlyKeys(cause, [\"area\", \"code\"])) ||\n\t\t\t\t(code === \"signal\" &&\n\t\t\t\t\ttypeof cause.signal === \"string\" &&\n\t\t\t\t\tPROCESS_SIGNALS.has(cause.signal as SessionProcessSignal) &&\n\t\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\", \"signal\"]));\n\t\t\tbreak;\n\t\tcase \"transcript\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTRANSCRIPT_CAUSE_CODES.has(code as TranscriptTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"configuration\":\n\t\t\tvalid = code === \"invalid\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"internal\":\n\t\t\tvalid = code === \"unclassified\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"resource\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tRESOURCE_CAUSE_CODES.has(code as ResourceTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t}\n\tif (!valid) throw new TypeError(\"cause must be a bounded structured termination cause\");\n}\n\nfunction assertClassifierInput(input: unknown): asserts input is ClassifySessionTerminationInput {\n\tif (!isRecord(input) || Object.keys(input).some((key) => !TOP_LEVEL_KEYS.has(key))) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tif (\n\t\ttypeof input.sessionId !== \"string\" ||\n\t\ttypeof input.runId !== \"string\" ||\n\t\ttypeof input.timestamp !== \"string\" ||\n\t\ttypeof input.message !== \"string\" ||\n\t\t(input.source !== \"observed\" && input.source !== \"inferred_on_resume\") ||\n\t\t(input.sideEffects !== \"none\" && input.sideEffects !== \"possible\" && input.sideEffects !== \"confirmed\") ||\n\t\t(input.retryAfterMs !== undefined && typeof input.retryAfterMs !== \"number\") ||\n\t\t(input.provider !== undefined && typeof input.provider !== \"string\") ||\n\t\t(input.model !== undefined && typeof input.model !== \"string\") ||\n\t\t(input.toolCallId !== undefined && typeof input.toolCallId !== \"string\") ||\n\t\t(input.toolName !== undefined && typeof input.toolName !== \"string\")\n\t) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tassertCause(input.cause);\n}\n\nfunction assertIdentifier(value: string, name: string, maxLength: number): void {\n\tif (value.length === 0 || value.length > maxLength || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new TypeError(`${name} must be non-empty bounded text without C0 or DEL control characters`);\n\t}\n}\n\n/** Validate text at the termination trust boundary without attempting redaction. */\nexport function assertPreRedactedTerminationMessage(message: string): void {\n\tif (message.length === 0 || message.length > MAX_SESSION_TERMINATION_MESSAGE_LENGTH) {\n\t\tthrow new TypeError(\n\t\t\t`message must contain 1-${MAX_SESSION_TERMINATION_MESSAGE_LENGTH} characters of pre-redacted text`,\n\t\t);\n\t}\n\tif (message.includes(\"\\0\")) {\n\t\tthrow new TypeError(\"message must not contain NUL\");\n\t}\n\tif (CREDENTIAL_SHAPES.some((pattern) => pattern.test(message))) {\n\t\tthrow new TypeError(\"message contains a credential-shaped literal; redact it before classification\");\n\t}\n}\n\nfunction assertTimestamp(timestamp: string): void {\n\tconst parsed = new Date(timestamp);\n\tif (!Number.isFinite(parsed.getTime()) || parsed.toISOString() !== timestamp) {\n\t\tthrow new TypeError(\"timestamp must be a canonical ISO-8601 UTC instant\");\n\t}\n}\n\nfunction classifyProvider(code: ProviderTerminationCauseCode): Classification {\n\tswitch (code) {\n\t\tcase \"abort\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_abort\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.abort\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"auth\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_auth\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.auth\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"rate_limit\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_rate_limit\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.rate_limit\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"network\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_network\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.network\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"protocol\":\n\t\t\t// Many \"protocol\" stops are sticky transcript shape bugs (orphan tool_call_id)\n\t\t\t// that succeed after transform-messages sanitizes and the turn is retried.\n\t\t\t// Mark retryable so auto-retry can heal; safeToAutoRetry stays false (needs sanitize path).\n\t\t\treturn {\n\t\t\t\tkind: \"provider_protocol\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.protocol\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"context_overflow\":\n\t\t\treturn {\n\t\t\t\tkind: \"context_overflow\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.context_overflow\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"refusal\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_refusal\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.refusal\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t}\n}\n\nfunction classifyCause(cause: SessionTerminationCause, source: SessionTerminationSource): Classification {\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\treturn {\n\t\t\t\tkind: \"completed\",\n\t\t\t\tphase: \"completed\",\n\t\t\t\tcauseCode: \"session.completed\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"user\":\n\t\t\treturn {\n\t\t\t\tkind: \"user_abort\",\n\t\t\t\tphase: \"control\",\n\t\t\t\tcauseCode: \"session.user_abort\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"provider\":\n\t\t\treturn classifyProvider(cause.code);\n\t\tcase \"tool\":\n\t\t\treturn cause.code === \"timeout\"\n\t\t\t\t? { kind: \"tool_timeout\", phase: \"tool\", causeCode: \"tool.timeout\", retryable: true }\n\t\t\t\t: { kind: \"tool_fatal\", phase: \"tool\", causeCode: \"tool.fatal\", retryable: false };\n\t\tcase \"compaction\":\n\t\t\treturn {\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tphase: \"compaction\",\n\t\t\t\tcauseCode: `compaction.${cause.code}`,\n\t\t\t\t// Quota exhaustion does not heal by retrying: same-model retries\n\t\t\t\t// keep failing until the provider cycle resets or the model changes.\n\t\t\t\tretryable: cause.code !== \"quota_exhausted\",\n\t\t\t};\n\t\tcase \"persistence\":\n\t\t\treturn {\n\t\t\t\tkind: \"persistence\",\n\t\t\t\tphase: \"persistence\",\n\t\t\t\tcauseCode: `persistence.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"process\":\n\t\t\tif (cause.code === \"signal\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"process_signal\",\n\t\t\t\t\tphase: \"process\",\n\t\t\t\t\tcauseCode: \"process.signal\",\n\t\t\t\t\tretryable: false,\n\t\t\t\t\tprocessSignal: cause.signal,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"process_crash\",\n\t\t\t\tphase: \"resume\",\n\t\t\t\tcauseCode: \"process.crash\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"transcript\":\n\t\t\treturn {\n\t\t\t\tkind: \"transcript_invalid\",\n\t\t\t\tphase: source === \"inferred_on_resume\" ? \"resume\" : \"preflight\",\n\t\t\t\tcauseCode: `transcript.${cause.code}`,\n\t\t\t\tretryable: false,\n\t\t\t\ttranscriptIssue: cause.code,\n\t\t\t};\n\t\tcase \"configuration\":\n\t\t\treturn {\n\t\t\t\tkind: \"configuration\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"configuration.invalid\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"internal\":\n\t\t\treturn {\n\t\t\t\tkind: \"internal_error\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"internal.unclassified\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"resource\":\n\t\t\t// §15.4: every resource cause is retryable; queue overflow surfaces at\n\t\t\t// the tool boundary, everything else at preflight admission.\n\t\t\treturn {\n\t\t\t\tkind: \"resource_pressure\",\n\t\t\t\tphase: cause.code === \"queue_overflow\" ? \"tool\" : \"preflight\",\n\t\t\t\tcauseCode: `resource.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t}\n}\n\nfunction isSafeToAutoRetry(classification: Classification, input: ClassifySessionTerminationInput): boolean {\n\t// provider_refusal: Fable/Claude often false-positive on benign turns. Safe to auto-retry once\n\t// when no tool side effects occurred (same class of recovery as rate_limit/network).\n\treturn (\n\t\tclassification.retryable &&\n\t\tinput.source === \"observed\" &&\n\t\tinput.sideEffects === \"none\" &&\n\t\t(classification.kind === \"provider_rate_limit\" ||\n\t\t\tclassification.kind === \"provider_network\" ||\n\t\t\tclassification.kind === \"provider_refusal\" ||\n\t\t\t// §15.4 mapping: only cpu pressure is safe to auto-retry (with delay).\n\t\t\tclassification.causeCode === \"resource.cpu\")\n\t);\n}\n\nfunction nextActionFor(classification: Classification, input: ClassifySessionTerminationInput): string {\n\tswitch (classification.kind) {\n\t\tcase \"completed\":\n\t\t\treturn \"No recovery action is required; continue with the next prompt.\";\n\t\tcase \"user_abort\":\n\t\t\treturn \"Review possible partial side effects, then retry only if intended.\";\n\t\tcase \"resource_pressure\":\n\t\t\treturn \"Host resources are constrained; reduce load or wait for recovery, then retry.\";\n\t\tcase \"provider_abort\":\n\t\t\treturn \"Confirm provider availability, then retry the request.\";\n\t\tcase \"provider_auth\":\n\t\t\t// A credential-less install resolves a placeholder model whose provider is\n\t\t\t// literally \"unknown\"; never echo that back as a login target.\n\t\t\treturn `Run /login${input.provider && input.provider !== \"unknown\" ? ` ${input.provider}` : \"\"} in an interactive session, or set the provider's API key environment variable, then retry.`;\n\t\tcase \"provider_rate_limit\":\n\t\t\treturn \"Wait for the provider retry window or choose another model, then retry.\";\n\t\tcase \"provider_network\":\n\t\t\treturn \"Check network and provider connectivity, then retry.\";\n\t\tcase \"provider_protocol\":\n\t\t\treturn \"Often an orphan tool_call_id / sticky transcript after a dropped error turn — auto-retry after sanitize, or /new session if it persists.\";\n\t\tcase \"provider_refusal\":\n\t\t\treturn \"Model declined this turn (content/safety stop). Usually a false positive on Fable/Claude — auto-retry once, or switch model (k3/qwen3.8-max/grok-4.5/deepseek) / rephrase as a pure coding task.\";\n\t\tcase \"context_overflow\":\n\t\t\treturn \"Compact or reduce context, or switch to a larger-context model.\";\n\t\tcase \"tool_timeout\":\n\t\t\treturn \"Inspect possible tool side effects and increase the tool timeout only if safe.\";\n\t\tcase \"tool_fatal\":\n\t\t\treturn \"Inspect the failed tool result and repair its configuration before retrying.\";\n\t\tcase \"compaction\":\n\t\t\tswitch (classification.causeCode) {\n\t\t\t\tcase \"compaction.aborted\":\n\t\t\t\t\treturn \"Retry /compact if cancellation was unintended; avoid Escape while compaction is running.\";\n\t\t\t\tcase \"compaction.stale\":\n\t\t\t\t\treturn \"Retry /compact after pending session changes settle.\";\n\t\t\t\tcase \"compaction.quota_exhausted\":\n\t\t\t\t\treturn \"The summarization model's quota is exhausted — retrying cannot help yet. Switch model (/model), set compaction.model in settings, or wait for the quota reset, then retry /compact. OMK already tried the failover chain automatically.\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn \"Resolve the reported compaction error, then retry /compact.\";\n\t\t\t}\n\t\tcase \"persistence\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} before resuming.`;\n\t\tcase \"process_signal\":\n\t\t\treturn \"Review possible partial side effects before resuming the session.\";\n\t\tcase \"process_crash\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} and review partial side effects.`;\n\t\tcase \"transcript_invalid\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId}; do not resume until integrity passes.`;\n\t\tcase \"configuration\":\n\t\t\treturn \"This model or client is not valid for the current login. Switch with /model or fix provider/client settings; /new session will not grant access.\";\n\t\tcase \"internal_error\":\n\t\t\treturn `Inspect run ${input.runId} diagnostics and the run journal before retrying.`;\n\t}\n}\n\n/** Concise actionable rendering shared by non-JSON and TUI surfaces. */\nexport function formatSessionTermination(termination: SessionTermination): string {\n\tconst route =\n\t\ttermination.provider || termination.model\n\t\t\t? `${termination.provider ?? \"unknown\"}/${termination.model ?? \"unknown\"}`\n\t\t\t: \"n/a\";\n\treturn [\n\t\t`kind=${termination.kind}`,\n\t\t`provider/model=${route}`,\n\t\t`retryable=${termination.retryable}`,\n\t\t`cause=${termination.causeCode}`,\n\t\t`message=${termination.message}`,\n\t\t`run=${termination.runId}`,\n\t\t`next=${termination.nextAction}`,\n\t].join(\" \");\n}\n\n/**\n * Classify a bounded, structured termination cause. This intentionally accepts\n * no raw Error value, stack, provider body, or arbitrary cause code.\n */\nexport function classifySessionTermination(input: ClassifySessionTerminationInput): SessionTermination {\n\tassertClassifierInput(input);\n\tassertIdentifier(input.sessionId, \"sessionId\", 128);\n\tassertIdentifier(input.runId, \"runId\", 128);\n\tassertTimestamp(input.timestamp);\n\tassertPreRedactedTerminationMessage(input.message);\n\tif (input.provider !== undefined) assertIdentifier(input.provider, \"provider\", 128);\n\tif (input.model !== undefined) assertIdentifier(input.model, \"model\", 256);\n\tif (input.toolCallId !== undefined) assertIdentifier(input.toolCallId, \"toolCallId\", 512);\n\tif (input.toolName !== undefined) assertIdentifier(input.toolName, \"toolName\", 128);\n\tif (input.retryAfterMs !== undefined && (!Number.isSafeInteger(input.retryAfterMs) || input.retryAfterMs < 0)) {\n\t\tthrow new TypeError(\"retryAfterMs must be a non-negative safe integer\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"crash\" && input.source !== \"inferred_on_resume\") {\n\t\tthrow new TypeError(\"process crashes may only be classified as inferred_on_resume\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"signal\" && input.source !== \"observed\") {\n\t\tthrow new TypeError(\"process signals must be observed\");\n\t}\n\n\tconst classification = classifyCause(input.cause, input.source);\n\treturn Object.freeze({\n\t\tschemaVersion: SESSION_TERMINATION_SCHEMA_VERSION,\n\t\tsessionId: input.sessionId,\n\t\trunId: input.runId,\n\t\tkind: classification.kind,\n\t\tphase: classification.phase,\n\t\tsource: input.source,\n\t\tmessage: input.message,\n\t\tcauseCode: classification.causeCode,\n\t\tnextAction: nextActionFor(classification, input),\n\t\tretryable: classification.retryable,\n\t\tsafeToAutoRetry: isSafeToAutoRetry(classification, input),\n\t\tsideEffects: input.sideEffects,\n\t\ttimestamp: input.timestamp,\n\t\t...(input.retryAfterMs === undefined ? {} : { retryAfterMs: input.retryAfterMs }),\n\t\t...(input.provider === undefined ? {} : { provider: input.provider }),\n\t\t...(input.model === undefined ? {} : { model: input.model }),\n\t\t...(input.toolCallId === undefined ? {} : { toolCallId: input.toolCallId }),\n\t\t...(input.toolName === undefined ? {} : { toolName: input.toolName }),\n\t\t...(classification.processSignal === undefined ? {} : { processSignal: classification.processSignal }),\n\t\t...(classification.transcriptIssue === undefined ? {} : { transcriptIssue: classification.transcriptIssue }),\n\t});\n}\n"]}
@@ -0,0 +1,40 @@
1
+ /** Documented lane grant cap: load at most 2–3 skills. */
2
+ export declare const MAX_SELECTED_SKILLS = 3;
3
+ /** Coverage at/above which a skill is a confident match. */
4
+ export declare const SKILL_STRONG_THRESHOLD = 0.7;
5
+ /**
6
+ * Minimum score to grant a skill. Neutral (no-query) relevance is 0.3, so the
7
+ * weak floor sits above that and ignores idle overlap.
8
+ */
9
+ export declare const SKILL_WEAK_THRESHOLD = 0.35;
10
+ /** If the runner-up is within this margin of a tentative leader, flag ambiguous. */
11
+ export declare const SKILL_AMBIGUITY_MARGIN = 0.08;
12
+ type SkillConfidence = "confident" | "tentative" | "fallback";
13
+ export interface SkillCandidate {
14
+ readonly name: string;
15
+ readonly description: string;
16
+ }
17
+ interface SkillScore {
18
+ readonly name: string;
19
+ readonly score: number;
20
+ }
21
+ interface SelectedSkill extends SkillScore {
22
+ readonly description: string;
23
+ }
24
+ export interface SelectSkillsInput {
25
+ readonly task: string;
26
+ readonly skills: readonly SkillCandidate[];
27
+ readonly max?: number;
28
+ /** Path segments become independent, camelCase-aware skill-name signals. */
29
+ readonly paths?: readonly string[];
30
+ }
31
+ export interface SkillSelectionResult {
32
+ readonly selected: readonly SelectedSkill[];
33
+ readonly scores: readonly SkillScore[];
34
+ readonly confidence: SkillConfidence;
35
+ readonly ambiguous: boolean;
36
+ readonly reason: string;
37
+ }
38
+ export declare function selectSkills(input: SelectSkillsInput): SkillSelectionResult;
39
+ export {};
40
+ //# sourceMappingURL=skill-selector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-selector.d.ts","sourceRoot":"","sources":["../../src/core/skill-selector.ts"],"names":[],"mappings":"AAYA,4DAA0D;AAC1D,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,4DAA4D;AAC5D,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,oFAAoF;AACpF,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,KAAK,eAAe,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;AAE9D,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,UAAU;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,aAAc,SAAQ,UAAU;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC;IAC3C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,oBAAoB,CAgD3E","sourcesContent":["/**\n * Query-aware skill grant selection.\n *\n * Scores candidates with {@link scoreSkillRelevance}, then applies the same\n * ranking/confidence shape as domain routing: weak/strong thresholds, a 2–3\n * skill cap, input-order ties, and an ambiguity flag when a tentative leader\n * is within the documented margin of the runner-up.\n *\n * I/O-free. Callers still decide whether to mark the result active.\n */\nimport { scoreSkillRelevance } from \"./context-budget-relevance.ts\";\n\n/** Documented lane grant cap: load at most 2–3 skills. */\nexport const MAX_SELECTED_SKILLS = 3;\n/** Coverage at/above which a skill is a confident match. */\nexport const SKILL_STRONG_THRESHOLD = 0.7;\n/**\n * Minimum score to grant a skill. Neutral (no-query) relevance is 0.3, so the\n * weak floor sits above that and ignores idle overlap.\n */\nexport const SKILL_WEAK_THRESHOLD = 0.35;\n/** If the runner-up is within this margin of a tentative leader, flag ambiguous. */\nexport const SKILL_AMBIGUITY_MARGIN = 0.08;\n\ntype SkillConfidence = \"confident\" | \"tentative\" | \"fallback\";\n\nexport interface SkillCandidate {\n\treadonly name: string;\n\treadonly description: string;\n}\n\ninterface SkillScore {\n\treadonly name: string;\n\treadonly score: number;\n}\n\ninterface SelectedSkill extends SkillScore {\n\treadonly description: string;\n}\n\nexport interface SelectSkillsInput {\n\treadonly task: string;\n\treadonly skills: readonly SkillCandidate[];\n\treadonly max?: number;\n\t/** Path segments become independent, camelCase-aware skill-name signals. */\n\treadonly paths?: readonly string[];\n}\n\nexport interface SkillSelectionResult {\n\treadonly selected: readonly SelectedSkill[];\n\treadonly scores: readonly SkillScore[];\n\treadonly confidence: SkillConfidence;\n\treadonly ambiguous: boolean;\n\treadonly reason: string;\n}\n\nexport function selectSkills(input: SelectSkillsInput): SkillSelectionResult {\n\tconst task = input.task.trim();\n\tconst pathTokens = pathHintTokens(input.paths);\n\tconst max = resolveMax(input.max);\n\tconst skills = uniqueSkills(input.skills);\n\tif ((task === \"\" && pathTokens.length === 0) || skills.length === 0) {\n\t\treturn fallback([], \"no skill signals detected\");\n\t}\n\n\tconst ranked = skills\n\t\t.map((skill, index) => {\n\t\t\tlet score = task === \"\" ? 0 : scoreSkillRelevance(skill, task);\n\t\t\tconst pathIdentity = { name: skill.name, description: \"\" };\n\t\t\tfor (const token of pathTokens) {\n\t\t\t\tscore = Math.max(score, scoreSkillRelevance(pathIdentity, token));\n\t\t\t}\n\t\t\treturn { skill, index, score };\n\t\t})\n\t\t.sort((left, right) => {\n\t\t\tif (right.score !== left.score) return right.score - left.score;\n\t\t\treturn left.index - right.index;\n\t\t});\n\n\tconst scores: SkillScore[] = ranked.map((entry) => ({ name: entry.skill.name, score: entry.score }));\n\tconst aboveWeak = ranked.filter((entry) => entry.score >= SKILL_WEAK_THRESHOLD);\n\tif (aboveWeak.length === 0) {\n\t\treturn fallback(scores, \"no skill signals detected\");\n\t}\n\n\tconst leader = aboveWeak[0];\n\tif (!leader) {\n\t\treturn fallback(scores, \"no skill signals detected\");\n\t}\n\tconst selected = aboveWeak.slice(0, Math.max(0, max)).map((entry) => ({\n\t\tname: entry.skill.name,\n\t\tdescription: entry.skill.description,\n\t\tscore: entry.score,\n\t}));\n\tconst runner = aboveWeak[1];\n\tconst confidence: SkillConfidence = leader.score >= SKILL_STRONG_THRESHOLD ? \"confident\" : \"tentative\";\n\tconst ambiguous =\n\t\tconfidence === \"tentative\" && runner !== undefined && leader.score - runner.score <= SKILL_AMBIGUITY_MARGIN;\n\tconst reason =\n\t\tambiguous && runner\n\t\t\t? `ambiguous: ${leader.skill.name}(${formatScore(leader.score)}) vs ${runner.skill.name}(${formatScore(runner.score)})`\n\t\t\t: `${leader.skill.name} selected (${formatScore(leader.score)})`;\n\n\treturn { selected, scores, confidence, ambiguous, reason };\n}\n\nfunction fallback(scores: readonly SkillScore[], reason: string): SkillSelectionResult {\n\treturn { selected: [], scores, confidence: \"fallback\", ambiguous: false, reason };\n}\n\nfunction formatScore(score: number): string {\n\treturn score.toFixed(2);\n}\n\nfunction resolveMax(max: number | undefined): number {\n\tif (max === undefined || !Number.isFinite(max) || max < 0) return MAX_SELECTED_SKILLS;\n\treturn Math.min(Math.floor(max), MAX_SELECTED_SKILLS);\n}\n\nfunction uniqueSkills(skills: readonly SkillCandidate[]): SkillCandidate[] {\n\tconst seen = new Set<string>();\n\tconst unique: SkillCandidate[] = [];\n\tfor (const skill of skills) {\n\t\tif (seen.has(skill.name)) continue;\n\t\tseen.add(skill.name);\n\t\tunique.push(skill);\n\t}\n\treturn unique;\n}\n\nfunction pathHintTokens(paths: readonly string[] | undefined): string[] {\n\tif (!paths || paths.length === 0) return [];\n\tconst tokens = new Set<string>();\n\tfor (const path of paths) {\n\t\tconst splitCase = path.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\").replace(/([a-z0-9])([A-Z])/g, \"$1 $2\");\n\t\tfor (const raw of splitCase.toLowerCase().split(/[/\\\\._\\s-]+/)) {\n\t\t\tif (raw.length > 0) tokens.add(raw);\n\t\t}\n\t}\n\treturn [...tokens];\n}\n"]}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Query-aware skill grant selection.
3
+ *
4
+ * Scores candidates with {@link scoreSkillRelevance}, then applies the same
5
+ * ranking/confidence shape as domain routing: weak/strong thresholds, a 2–3
6
+ * skill cap, input-order ties, and an ambiguity flag when a tentative leader
7
+ * is within the documented margin of the runner-up.
8
+ *
9
+ * I/O-free. Callers still decide whether to mark the result active.
10
+ */
11
+ import { scoreSkillRelevance } from "./context-budget-relevance.js";
12
+ /** Documented lane grant cap: load at most 2–3 skills. */
13
+ export const MAX_SELECTED_SKILLS = 3;
14
+ /** Coverage at/above which a skill is a confident match. */
15
+ export const SKILL_STRONG_THRESHOLD = 0.7;
16
+ /**
17
+ * Minimum score to grant a skill. Neutral (no-query) relevance is 0.3, so the
18
+ * weak floor sits above that and ignores idle overlap.
19
+ */
20
+ export const SKILL_WEAK_THRESHOLD = 0.35;
21
+ /** If the runner-up is within this margin of a tentative leader, flag ambiguous. */
22
+ export const SKILL_AMBIGUITY_MARGIN = 0.08;
23
+ export function selectSkills(input) {
24
+ const task = input.task.trim();
25
+ const pathTokens = pathHintTokens(input.paths);
26
+ const max = resolveMax(input.max);
27
+ const skills = uniqueSkills(input.skills);
28
+ if ((task === "" && pathTokens.length === 0) || skills.length === 0) {
29
+ return fallback([], "no skill signals detected");
30
+ }
31
+ const ranked = skills
32
+ .map((skill, index) => {
33
+ let score = task === "" ? 0 : scoreSkillRelevance(skill, task);
34
+ const pathIdentity = { name: skill.name, description: "" };
35
+ for (const token of pathTokens) {
36
+ score = Math.max(score, scoreSkillRelevance(pathIdentity, token));
37
+ }
38
+ return { skill, index, score };
39
+ })
40
+ .sort((left, right) => {
41
+ if (right.score !== left.score)
42
+ return right.score - left.score;
43
+ return left.index - right.index;
44
+ });
45
+ const scores = ranked.map((entry) => ({ name: entry.skill.name, score: entry.score }));
46
+ const aboveWeak = ranked.filter((entry) => entry.score >= SKILL_WEAK_THRESHOLD);
47
+ if (aboveWeak.length === 0) {
48
+ return fallback(scores, "no skill signals detected");
49
+ }
50
+ const leader = aboveWeak[0];
51
+ if (!leader) {
52
+ return fallback(scores, "no skill signals detected");
53
+ }
54
+ const selected = aboveWeak.slice(0, Math.max(0, max)).map((entry) => ({
55
+ name: entry.skill.name,
56
+ description: entry.skill.description,
57
+ score: entry.score,
58
+ }));
59
+ const runner = aboveWeak[1];
60
+ const confidence = leader.score >= SKILL_STRONG_THRESHOLD ? "confident" : "tentative";
61
+ const ambiguous = confidence === "tentative" && runner !== undefined && leader.score - runner.score <= SKILL_AMBIGUITY_MARGIN;
62
+ const reason = ambiguous && runner
63
+ ? `ambiguous: ${leader.skill.name}(${formatScore(leader.score)}) vs ${runner.skill.name}(${formatScore(runner.score)})`
64
+ : `${leader.skill.name} selected (${formatScore(leader.score)})`;
65
+ return { selected, scores, confidence, ambiguous, reason };
66
+ }
67
+ function fallback(scores, reason) {
68
+ return { selected: [], scores, confidence: "fallback", ambiguous: false, reason };
69
+ }
70
+ function formatScore(score) {
71
+ return score.toFixed(2);
72
+ }
73
+ function resolveMax(max) {
74
+ if (max === undefined || !Number.isFinite(max) || max < 0)
75
+ return MAX_SELECTED_SKILLS;
76
+ return Math.min(Math.floor(max), MAX_SELECTED_SKILLS);
77
+ }
78
+ function uniqueSkills(skills) {
79
+ const seen = new Set();
80
+ const unique = [];
81
+ for (const skill of skills) {
82
+ if (seen.has(skill.name))
83
+ continue;
84
+ seen.add(skill.name);
85
+ unique.push(skill);
86
+ }
87
+ return unique;
88
+ }
89
+ function pathHintTokens(paths) {
90
+ if (!paths || paths.length === 0)
91
+ return [];
92
+ const tokens = new Set();
93
+ for (const path of paths) {
94
+ const splitCase = path.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/([a-z0-9])([A-Z])/g, "$1 $2");
95
+ for (const raw of splitCase.toLowerCase().split(/[/\\._\s-]+/)) {
96
+ if (raw.length > 0)
97
+ tokens.add(raw);
98
+ }
99
+ }
100
+ return [...tokens];
101
+ }
102
+ //# sourceMappingURL=skill-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-selector.js","sourceRoot":"","sources":["../../src/core/skill-selector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,4DAA0D;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AACzC,oFAAoF;AACpF,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAkC3C,MAAM,UAAU,YAAY,CAAC,KAAwB,EAAwB;IAC5E,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAI,KAAK,EAAE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrE,OAAO,QAAQ,CAAC,EAAE,EAAE,2BAA2B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM;SACnB,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QACtB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KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;YAChE,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;AAAA,CACnB","sourcesContent":["/**\n * Query-aware skill grant selection.\n *\n * Scores candidates with {@link scoreSkillRelevance}, then applies the same\n * ranking/confidence shape as domain routing: weak/strong thresholds, a 2–3\n * skill cap, input-order ties, and an ambiguity flag when a tentative leader\n * is within the documented margin of the runner-up.\n *\n * I/O-free. Callers still decide whether to mark the result active.\n */\nimport { scoreSkillRelevance } from \"./context-budget-relevance.ts\";\n\n/** Documented lane grant cap: load at most 2–3 skills. */\nexport const MAX_SELECTED_SKILLS = 3;\n/** Coverage at/above which a skill is a confident match. */\nexport const SKILL_STRONG_THRESHOLD = 0.7;\n/**\n * Minimum score to grant a skill. Neutral (no-query) relevance is 0.3, so the\n * weak floor sits above that and ignores idle overlap.\n */\nexport const SKILL_WEAK_THRESHOLD = 0.35;\n/** If the runner-up is within this margin of a tentative leader, flag ambiguous. */\nexport const SKILL_AMBIGUITY_MARGIN = 0.08;\n\ntype SkillConfidence = \"confident\" | \"tentative\" | \"fallback\";\n\nexport interface SkillCandidate {\n\treadonly name: string;\n\treadonly description: string;\n}\n\ninterface SkillScore {\n\treadonly name: string;\n\treadonly score: number;\n}\n\ninterface SelectedSkill extends SkillScore {\n\treadonly description: string;\n}\n\nexport interface SelectSkillsInput {\n\treadonly task: string;\n\treadonly skills: readonly SkillCandidate[];\n\treadonly max?: number;\n\t/** Path segments become independent, camelCase-aware skill-name signals. */\n\treadonly paths?: readonly string[];\n}\n\nexport interface SkillSelectionResult {\n\treadonly selected: readonly SelectedSkill[];\n\treadonly scores: readonly SkillScore[];\n\treadonly confidence: SkillConfidence;\n\treadonly ambiguous: boolean;\n\treadonly reason: string;\n}\n\nexport function selectSkills(input: SelectSkillsInput): SkillSelectionResult {\n\tconst task = input.task.trim();\n\tconst pathTokens = pathHintTokens(input.paths);\n\tconst max = resolveMax(input.max);\n\tconst skills = uniqueSkills(input.skills);\n\tif ((task === \"\" && pathTokens.length === 0) || skills.length === 0) {\n\t\treturn fallback([], \"no skill signals detected\");\n\t}\n\n\tconst ranked = skills\n\t\t.map((skill, index) => {\n\t\t\tlet score = task === \"\" ? 0 : scoreSkillRelevance(skill, task);\n\t\t\tconst pathIdentity = { name: skill.name, description: \"\" };\n\t\t\tfor (const token of pathTokens) {\n\t\t\t\tscore = Math.max(score, scoreSkillRelevance(pathIdentity, token));\n\t\t\t}\n\t\t\treturn { skill, index, score };\n\t\t})\n\t\t.sort((left, right) => {\n\t\t\tif (right.score !== left.score) return right.score - left.score;\n\t\t\treturn left.index - right.index;\n\t\t});\n\n\tconst scores: SkillScore[] = ranked.map((entry) => ({ name: entry.skill.name, score: entry.score }));\n\tconst aboveWeak = ranked.filter((entry) => entry.score >= SKILL_WEAK_THRESHOLD);\n\tif (aboveWeak.length === 0) {\n\t\treturn fallback(scores, \"no skill signals detected\");\n\t}\n\n\tconst leader = aboveWeak[0];\n\tif (!leader) {\n\t\treturn fallback(scores, \"no skill signals detected\");\n\t}\n\tconst selected = aboveWeak.slice(0, Math.max(0, max)).map((entry) => ({\n\t\tname: entry.skill.name,\n\t\tdescription: entry.skill.description,\n\t\tscore: entry.score,\n\t}));\n\tconst runner = aboveWeak[1];\n\tconst confidence: SkillConfidence = leader.score >= SKILL_STRONG_THRESHOLD ? \"confident\" : \"tentative\";\n\tconst ambiguous =\n\t\tconfidence === \"tentative\" && runner !== undefined && leader.score - runner.score <= SKILL_AMBIGUITY_MARGIN;\n\tconst reason =\n\t\tambiguous && runner\n\t\t\t? `ambiguous: ${leader.skill.name}(${formatScore(leader.score)}) vs ${runner.skill.name}(${formatScore(runner.score)})`\n\t\t\t: `${leader.skill.name} selected (${formatScore(leader.score)})`;\n\n\treturn { selected, scores, confidence, ambiguous, reason };\n}\n\nfunction fallback(scores: readonly SkillScore[], reason: string): SkillSelectionResult {\n\treturn { selected: [], scores, confidence: \"fallback\", ambiguous: false, reason };\n}\n\nfunction formatScore(score: number): string {\n\treturn score.toFixed(2);\n}\n\nfunction resolveMax(max: number | undefined): number {\n\tif (max === undefined || !Number.isFinite(max) || max < 0) return MAX_SELECTED_SKILLS;\n\treturn Math.min(Math.floor(max), MAX_SELECTED_SKILLS);\n}\n\nfunction uniqueSkills(skills: readonly SkillCandidate[]): SkillCandidate[] {\n\tconst seen = new Set<string>();\n\tconst unique: SkillCandidate[] = [];\n\tfor (const skill of skills) {\n\t\tif (seen.has(skill.name)) continue;\n\t\tseen.add(skill.name);\n\t\tunique.push(skill);\n\t}\n\treturn unique;\n}\n\nfunction pathHintTokens(paths: readonly string[] | undefined): string[] {\n\tif (!paths || paths.length === 0) return [];\n\tconst tokens = new Set<string>();\n\tfor (const path of paths) {\n\t\tconst splitCase = path.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\").replace(/([a-z0-9])([A-Z])/g, \"$1 $2\");\n\t\tfor (const raw of splitCase.toLowerCase().split(/[/\\\\._\\s-]+/)) {\n\t\t\tif (raw.length > 0) tokens.add(raw);\n\t\t}\n\t}\n\treturn [...tokens];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAExD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAKpE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOjD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjF;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,SAAS,EACzG,UAAU,EAAE,OAAO,GACjB,MAAM,CAsBR;AAED,MAAM,MAAM,oBAAoB,CAAC,QAAQ,IAAI;IAC5C,OAAO,EAAE,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAEnD;AAED,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,MAAM,CAKR","sourcesContent":["import * as os from \"node:os\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"omk-ai\";\nimport { getCapabilities, getImageDimensions, hyperlink, imageFallback } from \"omk-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
1
+ {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAExD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAKpE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAOjD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGjF;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,SAAS,EACzG,UAAU,EAAE,OAAO,GACjB,MAAM,CAsBR;AAED,MAAM,MAAM,oBAAoB,CAAC,QAAQ,IAAI;IAC5C,OAAO,EAAE,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAEnD;AAED,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,MAAM,CAKR","sourcesContent":["import * as os from \"node:os\";\nimport type { ImageContent, TextContent } from \"omk-ai\";\nimport { getCapabilities, getImageDimensions, hyperlink, imageFallback } from \"omk-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { terminalFileUrl } from \"../../utils/terminal-links.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\treturn hyperlink(styledText, terminalFileUrl(rawPath, cwd));\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
@@ -1,9 +1,8 @@
1
1
  import * as os from "node:os";
2
- import { pathToFileURL } from "node:url";
3
2
  import { getCapabilities, getImageDimensions, hyperlink, imageFallback } from "omk-tui";
4
3
  import { stripAnsi } from "../../utils/ansi.js";
5
- import { resolvePath } from "../../utils/paths.js";
6
4
  import { sanitizeBinaryOutput } from "../../utils/shell.js";
5
+ import { terminalFileUrl } from "../../utils/terminal-links.js";
7
6
  export function shortenPath(path) {
8
7
  if (typeof path !== "string")
9
8
  return "";
@@ -16,8 +15,7 @@ export function shortenPath(path) {
16
15
  export function linkPath(styledText, rawPath, cwd) {
17
16
  if (!getCapabilities().hyperlinks)
18
17
  return styledText;
19
- const absolutePath = resolvePath(rawPath, cwd);
20
- return hyperlink(styledText, pathToFileURL(absolutePath).href);
18
+ return hyperlink(styledText, terminalFileUrl(rawPath, cwd));
21
19
  }
22
20
  export function str(value) {
23
21
  if (typeof value === "string")
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,UAAU,WAAW,CAAC,IAAa,EAAU;IAClD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,OAAe,EAAE,GAAW,EAAU;IAClF,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU;QAAE,OAAO,UAAU,CAAC;IACrD,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC;AAAA,CAC/D;AAED,MAAM,UAAU,GAAG,CAAC,KAAc,EAAiB;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,KAAK,IAA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T,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAClG,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAAA,CACrC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd;AAOD,MAAM,UAAU,cAAc,CAAC,KAAY,EAAU;IACpD,OAAO,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAAA,CAC1C;AAED,MAAM,UAAU,cAAc,CAC7B,OAAsB,EACtB,KAAY,EACZ,GAAW,EACX,OAAoC,EAC3B;IACT,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,EAAE,aAAa,CAAC;IAChD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAAA,CACpE","sourcesContent":["import * as os from \"node:os\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"omk-ai\";\nimport { getCapabilities, getImageDimensions, hyperlink, imageFallback } from \"omk-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
1
+ {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,UAAU,WAAW,CAAC,IAAa,EAAU;IAClD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,OAAe,EAAE,GAAW,EAAU;IAClF,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU;QAAE,OAAO,UAAU,CAAC;IACrD,OAAO,SAAS,CAAC,UAAU,EAAE,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AAAA,CAC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aACjC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,IAAI,eAAe,CAAC;YACjD,MAAM,IAAI,GACT,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAClG,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAAA,CACrC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;IACrE,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd;AAOD,MAAM,UAAU,cAAc,CAAC,KAAY,EAAU;IACpD,OAAO,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAAA,CAC1C;AAED,MAAM,UAAU,cAAc,CAC7B,OAAsB,EACtB,KAAY,EACZ,GAAW,EACX,OAAoC,EAC3B;IACT,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,EAAE,aAAa,CAAC;IAChD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AAAA,CACpE","sourcesContent":["import * as os from \"node:os\";\nimport type { ImageContent, TextContent } from \"omk-ai\";\nimport { getCapabilities, getImageDimensions, hyperlink, imageFallback } from \"omk-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { terminalFileUrl } from \"../../utils/terminal-links.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\treturn hyperlink(styledText, terminalFileUrl(rawPath, cwd));\n}\n\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return value;\n\tif (value == null) return \"\";\n\treturn null;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
@@ -0,0 +1,55 @@
1
+ import { type RuntimeProvenance } from "./runtime-provenance.ts";
2
+ export declare const TURN_METRICS_SCHEMA_VERSION: "omk-turn-metrics-2";
3
+ /** Compatibility constant: maximum failure text inspected for classification, never retained. */
4
+ export declare const MAX_ERROR_CHARS = 200;
5
+ declare const ERROR_CLASSES: readonly ["timeout", "aborted", "permission", "not_found", "invalid_input", "unknown"];
6
+ type ErrorClass = (typeof ERROR_CLASSES)[number];
7
+ export interface ToolCallMetric {
8
+ readonly name: string;
9
+ readonly durationMs: number;
10
+ readonly ok: boolean;
11
+ /** Input-only failure text. Never written to the metrics stream. */
12
+ readonly error?: string;
13
+ }
14
+ export interface ToolCallMetricRecord extends Omit<ToolCallMetric, "error"> {
15
+ readonly errorClass?: ErrorClass;
16
+ }
17
+ export interface TurnUsageMetric {
18
+ readonly input: number;
19
+ readonly output: number;
20
+ readonly cacheRead: number;
21
+ readonly cacheWrite: number;
22
+ readonly costUsd: number;
23
+ }
24
+ export interface TurnMetricInput {
25
+ readonly sessionId: string;
26
+ readonly turnIndex: number;
27
+ readonly provider?: string;
28
+ readonly model?: string;
29
+ readonly startedAtEpochMs: number;
30
+ readonly endedAtEpochMs: number;
31
+ readonly timeToFirstChunkMs?: number;
32
+ readonly usage?: TurnUsageMetric;
33
+ readonly stopReason?: string;
34
+ readonly toolCalls?: readonly ToolCallMetric[];
35
+ readonly compacted?: boolean;
36
+ readonly failovers?: number;
37
+ readonly contextCache?: {
38
+ readonly planHit: boolean;
39
+ readonly hits: number;
40
+ readonly misses: number;
41
+ };
42
+ readonly runtimeProvenance?: RuntimeProvenance;
43
+ }
44
+ export interface TurnMetricRecord extends Omit<TurnMetricInput, "toolCalls"> {
45
+ readonly schemaVersion: typeof TURN_METRICS_SCHEMA_VERSION;
46
+ readonly durationMs: number;
47
+ readonly toolCalls: readonly ToolCallMetricRecord[];
48
+ readonly toolCallCount: number;
49
+ readonly toolFailureCount: number;
50
+ }
51
+ export declare function buildTurnMetricRecord(input: TurnMetricInput): TurnMetricRecord;
52
+ /** Invalid records count as malformed; legacy records are projected, never rewritten on disk. */
53
+ export declare function parseTurnMetricRecord(line: string): TurnMetricRecord | undefined;
54
+ export {};
55
+ //# sourceMappingURL=turn-metrics-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-metrics-record.d.ts","sourceRoot":"","sources":["../../src/core/turn-metrics-record.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEzF,eAAO,MAAM,2BAA2B,sBAAgC,CAAC;AACzE,iGAAiG;AACjG,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,QAAA,MAAM,aAAa,wFAAyF,CAAC;AAC7G,KAAK,UAAU,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAGjD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;IAC1E,QAAQ,CAAC,UAAU,CAA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AE,OAAO,2BAA2B,CAAC;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACpD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAClC;AA+GD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAE9E;AAED,iGAAiG;AACjG,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAiBhF","sourcesContent":["import { parseRuntimeProvenance, type RuntimeProvenance } from \"./runtime-provenance.ts\";\n\nexport const TURN_METRICS_SCHEMA_VERSION = \"omk-turn-metrics-2\" as const;\n/** Compatibility constant: maximum failure text inspected for classification, never retained. */\nexport const MAX_ERROR_CHARS = 200;\nconst ERROR_CLASSES = [\"timeout\", \"aborted\", \"permission\", \"not_found\", \"invalid_input\", \"unknown\"] as const;\ntype ErrorClass = (typeof ERROR_CLASSES)[number];\nconst STOP_REASONS = [\"stop\", \"length\", \"toolUse\", \"error\", \"aborted\"];\n\nexport interface ToolCallMetric {\n\treadonly name: string;\n\treadonly durationMs: number;\n\treadonly ok: boolean;\n\t/** Input-only failure text. Never written to the metrics stream. */\n\treadonly error?: string;\n}\nexport interface ToolCallMetricRecord extends Omit<ToolCallMetric, \"error\"> {\n\treadonly errorClass?: ErrorClass;\n}\nexport interface TurnUsageMetric {\n\treadonly input: number;\n\treadonly output: number;\n\treadonly cacheRead: number;\n\treadonly cacheWrite: number;\n\treadonly costUsd: number;\n}\nexport interface TurnMetricInput {\n\treadonly sessionId: string;\n\treadonly turnIndex: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly startedAtEpochMs: number;\n\treadonly endedAtEpochMs: number;\n\treadonly timeToFirstChunkMs?: number;\n\treadonly usage?: TurnUsageMetric;\n\treadonly stopReason?: string;\n\treadonly toolCalls?: readonly ToolCallMetric[];\n\treadonly compacted?: boolean;\n\treadonly failovers?: number;\n\treadonly contextCache?: { readonly planHit: boolean; readonly hits: number; readonly misses: number };\n\treadonly runtimeProvenance?: RuntimeProvenance;\n}\nexport interface TurnMetricRecord extends Omit<TurnMetricInput, \"toolCalls\"> {\n\treadonly schemaVersion: typeof TURN_METRICS_SCHEMA_VERSION;\n\treadonly durationMs: number;\n\treadonly toolCalls: readonly ToolCallMetricRecord[];\n\treadonly toolCallCount: number;\n\treadonly toolFailureCount: number;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction object(value: unknown): Record<string, unknown> {\n\tif (!isRecord(value)) throw new TypeError(\"Invalid metric object\");\n\treturn value;\n}\nfunction finite(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value)) throw new TypeError(\"Invalid metric number\");\n\treturn value;\n}\nfunction quantity(value: unknown, integer = false): number {\n\tconst number = finite(value);\n\tif (number < 0 || (integer && !Number.isSafeInteger(number))) throw new TypeError(\"Invalid metric quantity\");\n\treturn number;\n}\nfunction identifier(value: unknown): string {\n\tif (typeof value !== \"string\" || !value.trim() || value.length > 512 || /[\\u0000-\\u001f\\u007f]/u.test(value))\n\t\tthrow new TypeError(\"Invalid metric identifier\");\n\treturn value;\n}\nfunction boolean(value: unknown): boolean {\n\tif (typeof value !== \"boolean\") throw new TypeError(\"Invalid metric boolean\");\n\treturn value;\n}\nfunction classifyError(value: unknown): ErrorClass {\n\tif (value !== undefined && typeof value !== \"string\") throw new TypeError(\"Invalid metric error text\");\n\tconst text = value?.slice(0, MAX_ERROR_CHARS) ?? \"\";\n\tif (/timed? out|timeout/iu.test(text)) return \"timeout\";\n\tif (/abort|cancel/iu.test(text)) return \"aborted\";\n\tif (/permission|eacces|eperm/iu.test(text)) return \"permission\";\n\tif (/not found|enoent/iu.test(text)) return \"not_found\";\n\tif (/invalid|validation/iu.test(text)) return \"invalid_input\";\n\treturn \"unknown\";\n}\nfunction parseErrorClass(value: unknown): ErrorClass | undefined {\n\tif (value === undefined) return undefined;\n\tfor (const code of ERROR_CLASSES) if (value === code) return code;\n\tthrow new TypeError(\"Invalid metric error class\");\n}\n\n/** Explicit projection is shared by new input and legacy/current persisted records. */\nfunction project(value: unknown, source: \"input\" | \"v1\" | \"v2\"): TurnMetricRecord {\n\tconst input = object(value);\n\tconst rawTools = input.toolCalls === undefined ? [] : input.toolCalls;\n\tif (!Array.isArray(rawTools) || rawTools.length > 10000) throw new TypeError(\"Invalid metric tool list\");\n\tconst toolCalls = Array.from(rawTools, (raw): ToolCallMetricRecord => {\n\t\tconst call = object(raw);\n\t\tconst ok = boolean(call.ok);\n\t\tif (source === \"v2\" && call.error !== undefined) throw new TypeError(\"Raw errors are not v2 metrics\");\n\t\tconst errorClass = source === \"v2\" ? parseErrorClass(call.errorClass) : classifyError(call.error);\n\t\treturn {\n\t\t\tname: identifier(call.name),\n\t\t\tdurationMs: source === \"input\" ? Math.max(0, Math.round(finite(call.durationMs))) : quantity(call.durationMs),\n\t\t\tok,\n\t\t\t...(!ok && errorClass ? { errorClass } : {}),\n\t\t};\n\t});\n\tconst usage = input.usage === undefined ? undefined : object(input.usage);\n\tconst contextCache = input.contextCache === undefined ? undefined : object(input.contextCache);\n\tconst runtimeProvenance =\n\t\tinput.runtimeProvenance === undefined ? undefined : parseRuntimeProvenance(input.runtimeProvenance);\n\tconst startedAtEpochMs = quantity(input.startedAtEpochMs);\n\tconst endedAtEpochMs = quantity(input.endedAtEpochMs);\n\tif (\n\t\tinput.stopReason !== undefined &&\n\t\t(typeof input.stopReason !== \"string\" || !STOP_REASONS.includes(input.stopReason))\n\t)\n\t\tthrow new TypeError(\"Invalid metric stop reason\");\n\treturn {\n\t\tschemaVersion: TURN_METRICS_SCHEMA_VERSION,\n\t\tsessionId: identifier(input.sessionId),\n\t\tturnIndex: quantity(input.turnIndex, true),\n\t\tstartedAtEpochMs,\n\t\tendedAtEpochMs,\n\t\tdurationMs: Math.max(0, endedAtEpochMs - startedAtEpochMs),\n\t\ttoolCalls,\n\t\ttoolCallCount: toolCalls.length,\n\t\ttoolFailureCount: toolCalls.filter((call) => !call.ok).length,\n\t\t...(input.provider === undefined ? {} : { provider: identifier(input.provider) }),\n\t\t...(input.model === undefined ? {} : { model: identifier(input.model) }),\n\t\t...(input.timeToFirstChunkMs === undefined ? {} : { timeToFirstChunkMs: quantity(input.timeToFirstChunkMs) }),\n\t\t...(usage === undefined\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tusage: {\n\t\t\t\t\t\tinput: quantity(usage.input, true),\n\t\t\t\t\t\toutput: quantity(usage.output, true),\n\t\t\t\t\t\tcacheRead: quantity(usage.cacheRead, true),\n\t\t\t\t\t\tcacheWrite: quantity(usage.cacheWrite, true),\n\t\t\t\t\t\tcostUsd: quantity(usage.costUsd),\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t...(input.stopReason === undefined ? {} : { stopReason: input.stopReason }),\n\t\t...(input.compacted === undefined ? {} : { compacted: boolean(input.compacted) }),\n\t\t...(input.failovers === undefined ? {} : { failovers: quantity(input.failovers, true) }),\n\t\t...(contextCache === undefined\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tcontextCache: {\n\t\t\t\t\t\tplanHit: boolean(contextCache.planHit),\n\t\t\t\t\t\thits: quantity(contextCache.hits, true),\n\t\t\t\t\t\tmisses: quantity(contextCache.misses, true),\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t...(runtimeProvenance ? { runtimeProvenance } : {}),\n\t};\n}\n\nexport function buildTurnMetricRecord(input: TurnMetricInput): TurnMetricRecord {\n\treturn project(input, \"input\");\n}\n\n/** Invalid records count as malformed; legacy records are projected, never rewritten on disk. */\nexport function parseTurnMetricRecord(line: string): TurnMetricRecord | undefined {\n\ttry {\n\t\tconst value = object(JSON.parse(line));\n\t\tconst version = value.schemaVersion;\n\t\tif (version !== \"omk-turn-metrics-1\" && version !== TURN_METRICS_SCHEMA_VERSION) return undefined;\n\t\tconst projected = project(value, version === \"omk-turn-metrics-1\" ? \"v1\" : \"v2\");\n\t\tif (\n\t\t\tquantity(value.durationMs) !== projected.durationMs ||\n\t\t\tquantity(value.toolCallCount, true) !== projected.toolCallCount ||\n\t\t\tquantity(value.toolFailureCount, true) !== projected.toolFailureCount\n\t\t)\n\t\t\treturn undefined;\n\t\treturn projected;\n\t} catch (error) {\n\t\tif (error instanceof SyntaxError || error instanceof TypeError) return undefined;\n\t\tthrow error;\n\t}\n}\n"]}