@code-yeongyu/senpi 2026.8.13 → 2026.8.16

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 (514) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.md +1 -0
  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/auth-command.d.ts.map +1 -1
  8. package/dist/cli/auth-command.js +5 -4
  9. package/dist/cli/auth-command.js.map +1 -1
  10. package/dist/core/agent-session.d.ts +80 -8
  11. package/dist/core/agent-session.d.ts.map +1 -1
  12. package/dist/core/agent-session.js +206 -31
  13. package/dist/core/agent-session.js.map +1 -1
  14. package/dist/core/auth-storage.d.ts.map +1 -1
  15. package/dist/core/auth-storage.js +19 -8
  16. package/dist/core/auth-storage.js.map +1 -1
  17. package/dist/core/experimental.d.ts +4 -0
  18. package/dist/core/experimental.d.ts.map +1 -1
  19. package/dist/core/experimental.js +4 -0
  20. package/dist/core/experimental.js.map +1 -1
  21. package/dist/core/export-html/template.js +31 -9
  22. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-environment.d.ts +4 -0
  23. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-environment.d.ts.map +1 -0
  24. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-environment.js +30 -0
  25. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-environment.js.map +1 -0
  26. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.d.ts +2 -0
  27. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.d.ts.map +1 -1
  28. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js +13 -47
  29. package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js.map +1 -1
  30. package/dist/core/extensions/builtin/claude-sdk-oauth/availability.d.ts +18 -1
  31. package/dist/core/extensions/builtin/claude-sdk-oauth/availability.d.ts.map +1 -1
  32. package/dist/core/extensions/builtin/claude-sdk-oauth/availability.js +64 -2
  33. package/dist/core/extensions/builtin/claude-sdk-oauth/availability.js.map +1 -1
  34. package/dist/core/extensions/builtin/claude-sdk-oauth/config-dir-credentials.d.ts +3 -0
  35. package/dist/core/extensions/builtin/claude-sdk-oauth/config-dir-credentials.d.ts.map +1 -0
  36. package/dist/core/extensions/builtin/claude-sdk-oauth/config-dir-credentials.js +27 -0
  37. package/dist/core/extensions/builtin/claude-sdk-oauth/config-dir-credentials.js.map +1 -0
  38. package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts +15 -2
  39. package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts.map +1 -1
  40. package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js +45 -11
  41. package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js.map +1 -1
  42. package/dist/core/extensions/builtin/claude-sdk-oauth/options.d.ts.map +1 -1
  43. package/dist/core/extensions/builtin/claude-sdk-oauth/options.js +1 -0
  44. package/dist/core/extensions/builtin/claude-sdk-oauth/options.js.map +1 -1
  45. package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
  46. package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +3 -1
  47. package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
  48. package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js +1 -0
  49. package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js.map +1 -1
  50. package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.d.ts.map +1 -1
  51. package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js +17 -1
  52. package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js.map +1 -1
  53. package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
  54. package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +1 -0
  55. package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
  56. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  57. package/dist/core/extensions/builtin/compaction/index.js +225 -75
  58. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  59. package/dist/core/extensions/builtin/compaction/lane-policy.d.ts +2 -3
  60. package/dist/core/extensions/builtin/compaction/lane-policy.d.ts.map +1 -1
  61. package/dist/core/extensions/builtin/compaction/lane-policy.js +2 -3
  62. package/dist/core/extensions/builtin/compaction/lane-policy.js.map +1 -1
  63. package/dist/core/extensions/builtin/compaction/log.d.ts +1 -1
  64. package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
  65. package/dist/core/extensions/builtin/compaction/log.js +2 -0
  66. package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
  67. package/dist/core/extensions/builtin/compaction/overflow-retry.d.ts.map +1 -1
  68. package/dist/core/extensions/builtin/compaction/overflow-retry.js +38 -4
  69. package/dist/core/extensions/builtin/compaction/overflow-retry.js.map +1 -1
  70. package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
  71. package/dist/core/extensions/builtin/compaction/speculative.js +2 -1
  72. package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
  73. package/dist/core/extensions/builtin/compaction/summarization-turn-order.d.ts +33 -0
  74. package/dist/core/extensions/builtin/compaction/summarization-turn-order.d.ts.map +1 -0
  75. package/dist/core/extensions/builtin/compaction/summarization-turn-order.js +67 -0
  76. package/dist/core/extensions/builtin/compaction/summarization-turn-order.js.map +1 -0
  77. package/dist/core/extensions/builtin/config-reload/index.d.ts.map +1 -1
  78. package/dist/core/extensions/builtin/config-reload/index.js +31 -8
  79. package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
  80. package/dist/core/extensions/builtin/config-reload/routine-settings.d.ts.map +1 -1
  81. package/dist/core/extensions/builtin/config-reload/routine-settings.js +11 -12
  82. package/dist/core/extensions/builtin/config-reload/routine-settings.js.map +1 -1
  83. package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts.map +1 -1
  84. package/dist/core/extensions/builtin/goal/terminal-provider-error.js +16 -0
  85. package/dist/core/extensions/builtin/goal/terminal-provider-error.js.map +1 -1
  86. package/dist/core/extensions/builtin/index.d.ts.map +1 -1
  87. package/dist/core/extensions/builtin/index.js +4 -0
  88. package/dist/core/extensions/builtin/index.js.map +1 -1
  89. package/dist/core/extensions/builtin/mcp/process-tree.js +6 -1
  90. package/dist/core/extensions/builtin/mcp/process-tree.js.map +1 -1
  91. package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts +3 -0
  92. package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts.map +1 -0
  93. package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js +14 -0
  94. package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js.map +1 -0
  95. package/dist/core/extensions/builtin/prompt-preset/grok-4.6.d.ts +3 -0
  96. package/dist/core/extensions/builtin/prompt-preset/grok-4.6.d.ts.map +1 -0
  97. package/dist/core/extensions/builtin/prompt-preset/grok-4.6.js +91 -0
  98. package/dist/core/extensions/builtin/prompt-preset/grok-4.6.js.map +1 -0
  99. package/dist/core/extensions/builtin/prompt-preset/index.d.ts.map +1 -1
  100. package/dist/core/extensions/builtin/prompt-preset/index.js +22 -2
  101. package/dist/core/extensions/builtin/prompt-preset/index.js.map +1 -1
  102. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  103. package/dist/core/extensions/builtin/prompt-preset/presets.js +25 -0
  104. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  105. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  106. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  107. package/dist/core/extensions/builtin/prompt-preset/settings.js +2 -0
  108. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  109. package/dist/core/extensions/builtin/reasoning/index.d.ts +3 -0
  110. package/dist/core/extensions/builtin/reasoning/index.d.ts.map +1 -0
  111. package/dist/core/extensions/builtin/reasoning/index.js +211 -0
  112. package/dist/core/extensions/builtin/reasoning/index.js.map +1 -0
  113. package/dist/core/extensions/builtin/service-tier.d.ts +44 -1
  114. package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
  115. package/dist/core/extensions/builtin/service-tier.js +176 -24
  116. package/dist/core/extensions/builtin/service-tier.js.map +1 -1
  117. package/dist/core/extensions/runner.d.ts.map +1 -1
  118. package/dist/core/extensions/runner.js +4 -4
  119. package/dist/core/extensions/runner.js.map +1 -1
  120. package/dist/core/extensions/types.d.ts +13 -1
  121. package/dist/core/extensions/types.d.ts.map +1 -1
  122. package/dist/core/extensions/types.js.map +1 -1
  123. package/dist/core/keybindings.d.ts +24 -0
  124. package/dist/core/keybindings.d.ts.map +1 -1
  125. package/dist/core/lockfile-policy.d.ts +15 -0
  126. package/dist/core/lockfile-policy.d.ts.map +1 -0
  127. package/dist/core/lockfile-policy.js +15 -0
  128. package/dist/core/lockfile-policy.js.map +1 -0
  129. package/dist/core/model-config.d.ts.map +1 -1
  130. package/dist/core/model-config.js +1 -0
  131. package/dist/core/model-config.js.map +1 -1
  132. package/dist/core/model-resolver.d.ts +34 -7
  133. package/dist/core/model-resolver.d.ts.map +1 -1
  134. package/dist/core/model-resolver.js +115 -27
  135. package/dist/core/model-resolver.js.map +1 -1
  136. package/dist/core/model-runtime.d.ts.map +1 -1
  137. package/dist/core/model-runtime.js +5 -3
  138. package/dist/core/model-runtime.js.map +1 -1
  139. package/dist/core/provider-api-key-auth.d.ts.map +1 -1
  140. package/dist/core/provider-api-key-auth.js +45 -2
  141. package/dist/core/provider-api-key-auth.js.map +1 -1
  142. package/dist/core/provider-composer.d.ts +12 -1
  143. package/dist/core/provider-composer.d.ts.map +1 -1
  144. package/dist/core/provider-composer.js.map +1 -1
  145. package/dist/core/provider-display-names.d.ts.map +1 -1
  146. package/dist/core/provider-display-names.js +1 -0
  147. package/dist/core/provider-display-names.js.map +1 -1
  148. package/dist/core/remote-catalog-provider.d.ts +13 -0
  149. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  150. package/dist/core/remote-catalog-provider.js +15 -0
  151. package/dist/core/remote-catalog-provider.js.map +1 -1
  152. package/dist/core/retry-fallback/controller.d.ts +1 -1
  153. package/dist/core/retry-fallback/controller.d.ts.map +1 -1
  154. package/dist/core/retry-fallback/controller.js +5 -3
  155. package/dist/core/retry-fallback/controller.js.map +1 -1
  156. package/dist/core/retry-fallback/settings.d.ts.map +1 -1
  157. package/dist/core/retry-fallback/settings.js +4 -1
  158. package/dist/core/retry-fallback/settings.js.map +1 -1
  159. package/dist/core/sdk.d.ts +5 -3
  160. package/dist/core/sdk.d.ts.map +1 -1
  161. package/dist/core/sdk.js +14 -8
  162. package/dist/core/sdk.js.map +1 -1
  163. package/dist/core/session-manager.d.ts.map +1 -1
  164. package/dist/core/session-manager.js +20 -4
  165. package/dist/core/session-manager.js.map +1 -1
  166. package/dist/core/settings-manager.d.ts +50 -1
  167. package/dist/core/settings-manager.d.ts.map +1 -1
  168. package/dist/core/settings-manager.js +258 -15
  169. package/dist/core/settings-manager.js.map +1 -1
  170. package/dist/core/system-prompt.js +1 -1
  171. package/dist/core/system-prompt.js.map +1 -1
  172. package/dist/core/thinking-levels.d.ts +22 -0
  173. package/dist/core/thinking-levels.d.ts.map +1 -1
  174. package/dist/core/thinking-levels.js +29 -0
  175. package/dist/core/thinking-levels.js.map +1 -1
  176. package/dist/core/tools/bash.d.ts.map +1 -1
  177. package/dist/core/tools/bash.js +2 -0
  178. package/dist/core/tools/bash.js.map +1 -1
  179. package/dist/core/tools/edit.d.ts.map +1 -1
  180. package/dist/core/tools/edit.js +2 -0
  181. package/dist/core/tools/edit.js.map +1 -1
  182. package/dist/core/tools/find.js +1 -1
  183. package/dist/core/tools/find.js.map +1 -1
  184. package/dist/core/tools/grep.js +1 -1
  185. package/dist/core/tools/grep.js.map +1 -1
  186. package/dist/core/tools/read.d.ts.map +1 -1
  187. package/dist/core/tools/read.js +2 -0
  188. package/dist/core/tools/read.js.map +1 -1
  189. package/dist/core/tools/write.d.ts.map +1 -1
  190. package/dist/core/tools/write.js +2 -0
  191. package/dist/core/tools/write.js.map +1 -1
  192. package/dist/index.d.ts +1 -1
  193. package/dist/index.d.ts.map +1 -1
  194. package/dist/index.js.map +1 -1
  195. package/dist/main.d.ts.map +1 -1
  196. package/dist/main.js +18 -1
  197. package/dist/main.js.map +1 -1
  198. package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
  199. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  200. package/dist/modes/interactive/components/extension-selector.js +17 -1
  201. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  202. package/dist/modes/interactive/components/model-favorites.d.ts +2 -1
  203. package/dist/modes/interactive/components/model-favorites.d.ts.map +1 -1
  204. package/dist/modes/interactive/components/model-favorites.js +72 -6
  205. package/dist/modes/interactive/components/model-favorites.js.map +1 -1
  206. package/dist/modes/interactive/components/model-selector.d.ts +5 -1
  207. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  208. package/dist/modes/interactive/components/model-selector.js +10 -6
  209. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  210. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  211. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  212. package/dist/modes/interactive/components/settings-selector.js +10 -0
  213. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  214. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  215. package/dist/modes/interactive/components/tool-execution.js +22 -1
  216. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  217. package/dist/modes/interactive/interactive-mode.d.ts +14 -4
  218. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  219. package/dist/modes/interactive/interactive-mode.js +109 -50
  220. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  221. package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
  222. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
  223. package/dist/modes/interactive/model-catalog-refresh.js +36 -0
  224. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
  225. package/dist/modes/interactive/theme/dark.json +2 -0
  226. package/dist/modes/interactive/theme/grok-day.json +2 -0
  227. package/dist/modes/interactive/theme/grok-night.json +2 -0
  228. package/dist/modes/interactive/theme/light.json +2 -0
  229. package/dist/modes/interactive/theme/theme-controller.d.ts +10 -2
  230. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  231. package/dist/modes/interactive/theme/theme-controller.js +23 -10
  232. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  233. package/dist/modes/interactive/theme/theme-schema.json +9 -1
  234. package/dist/modes/interactive/theme/theme.d.ts +5 -3
  235. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  236. package/dist/modes/interactive/theme/theme.js +12 -2
  237. package/dist/modes/interactive/theme/theme.js.map +1 -1
  238. package/dist/modes/json-event.d.ts +4 -1
  239. package/dist/modes/json-event.d.ts.map +1 -1
  240. package/dist/modes/json-event.js +5 -2
  241. package/dist/modes/json-event.js.map +1 -1
  242. package/dist/modes/rpc/connection-handler.d.ts +10 -0
  243. package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
  244. package/dist/modes/rpc/connection-handler.js +87 -19
  245. package/dist/modes/rpc/connection-handler.js.map +1 -1
  246. package/dist/modes/rpc/multi-session-host.js +3 -3
  247. package/dist/modes/rpc/multi-session-host.js.map +1 -1
  248. package/dist/modes/rpc/rpc-client.d.ts +26 -1
  249. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  250. package/dist/modes/rpc/rpc-client.js +25 -2
  251. package/dist/modes/rpc/rpc-client.js.map +1 -1
  252. package/dist/modes/rpc/rpc-types.d.ts +60 -0
  253. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  254. package/dist/modes/rpc/rpc-types.js.map +1 -1
  255. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  256. package/dist/modes/rpc/session-command-router.js +2 -14
  257. package/dist/modes/rpc/session-command-router.js.map +1 -1
  258. package/dist/modes/rpc/session-event-writer.d.ts +29 -10
  259. package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
  260. package/dist/modes/rpc/session-event-writer.js +229 -50
  261. package/dist/modes/rpc/session-event-writer.js.map +1 -1
  262. package/dist/server/create-harness.d.ts.map +1 -1
  263. package/dist/server/create-harness.js +2 -0
  264. package/dist/server/create-harness.js.map +1 -1
  265. package/dist/utils/shell.d.ts +27 -0
  266. package/dist/utils/shell.d.ts.map +1 -1
  267. package/dist/utils/shell.js +79 -13
  268. package/dist/utils/shell.js.map +1 -1
  269. package/dist/utils/tools-manager.d.ts +10 -1
  270. package/dist/utils/tools-manager.d.ts.map +1 -1
  271. package/dist/utils/tools-manager.js +14 -19
  272. package/dist/utils/tools-manager.js.map +1 -1
  273. package/docs/compaction.md +3 -3
  274. package/docs/custom-provider.md +1 -1
  275. package/docs/environment-variables.md +8 -2
  276. package/docs/extensions.md +13 -1
  277. package/docs/json.md +9 -5
  278. package/docs/keybindings.md +8 -2
  279. package/docs/providers.md +9 -1
  280. package/docs/rpc.md +128 -6
  281. package/docs/sdk.md +9 -0
  282. package/docs/settings.md +93 -1
  283. package/docs/terminal-setup.md +23 -2
  284. package/docs/themes.md +24 -3
  285. package/docs/tui.md +2 -2
  286. package/docs/usage.md +24 -4
  287. package/examples/extensions/subagent/agents.ts +40 -9
  288. package/examples/extensions/subagent/index.ts +26 -3
  289. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +38 -0
  290. package/node_modules/@code-yeongyu/senpi-codemode/README.md +5 -0
  291. package/node_modules/@code-yeongyu/senpi-codemode/package.json +5 -4
  292. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +14 -1
  293. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/call-capture.ts +64 -0
  294. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-handler.ts +45 -61
  295. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-runtime.ts +6 -0
  296. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-execution-event.ts +201 -0
  297. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +2 -0
  298. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +22 -0
  299. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts +25 -0
  300. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts.map +1 -1
  301. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +77 -12
  302. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js.map +1 -1
  303. package/node_modules/@earendil-works/pi-agent-core/dist/harness/events.d.ts +43 -0
  304. package/node_modules/@earendil-works/pi-agent-core/dist/harness/events.d.ts.map +1 -0
  305. package/node_modules/@earendil-works/pi-agent-core/dist/harness/events.js +67 -0
  306. package/node_modules/@earendil-works/pi-agent-core/dist/harness/events.js.map +1 -0
  307. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.d.ts +4 -2
  308. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.d.ts.map +1 -1
  309. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.js +127 -88
  310. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/codec.js.map +1 -1
  311. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.d.ts +5 -1
  312. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.d.ts.map +1 -1
  313. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js +9 -2
  314. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/errors.js.map +1 -1
  315. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.d.ts +12 -3
  316. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.d.ts.map +1 -1
  317. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.js +88 -45
  318. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/repo.js.map +1 -1
  319. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.d.ts +1 -1
  320. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.d.ts.map +1 -1
  321. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.js +28 -19
  322. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/storage.js.map +1 -1
  323. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.d.ts +1 -1
  324. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.d.ts.map +1 -1
  325. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl/types.js.map +1 -1
  326. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.d.ts +1 -1
  327. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.d.ts.map +1 -1
  328. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory.js.map +1 -1
  329. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts +6 -1
  330. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts.map +1 -1
  331. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +7 -2
  332. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js.map +1 -1
  333. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.d.ts +1 -1
  334. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.d.ts.map +1 -1
  335. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/state.js.map +1 -1
  336. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.d.ts.map +1 -1
  337. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js +19 -0
  338. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/testing/conformance.js.map +1 -1
  339. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.d.ts +18 -5
  340. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.d.ts.map +1 -1
  341. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/types.js.map +1 -1
  342. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +1 -1
  343. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  344. package/node_modules/@earendil-works/pi-agent-core/dist/index.js +1 -1
  345. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
  346. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +4 -1
  347. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts.map +1 -1
  348. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js.map +1 -1
  349. package/node_modules/@earendil-works/pi-agent-core/dist/search/index.d.ts +21 -0
  350. package/node_modules/@earendil-works/pi-agent-core/dist/search/index.d.ts.map +1 -0
  351. package/node_modules/@earendil-works/pi-agent-core/dist/search/index.js +2 -0
  352. package/node_modules/@earendil-works/pi-agent-core/dist/search/index.js.map +1 -0
  353. package/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.d.ts +29 -0
  354. package/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.d.ts.map +1 -0
  355. package/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js +103 -0
  356. package/node_modules/@earendil-works/pi-agent-core/dist/search/scanning.js.map +1 -0
  357. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  358. package/node_modules/@earendil-works/pi-ai/README.md +2 -0
  359. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  360. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +40 -14
  361. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  362. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  363. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +16 -4
  364. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
  365. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.d.ts +69 -0
  366. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.d.ts.map +1 -0
  367. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js +159 -0
  368. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-gateway-binding.js.map +1 -0
  369. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.d.ts +3 -0
  370. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.d.ts.map +1 -1
  371. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +125 -5
  372. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js.map +1 -1
  373. package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +7 -3
  374. package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js.map +1 -1
  375. package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts +1 -1
  376. package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts.map +1 -1
  377. package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +13 -9
  378. package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js.map +1 -1
  379. package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +7 -3
  380. package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js.map +1 -1
  381. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts +1 -1
  382. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts.map +1 -1
  383. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +208 -42
  384. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js.map +1 -1
  385. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
  386. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +13 -4
  387. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
  388. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
  389. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +10 -7
  390. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
  391. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.d.ts +1 -0
  392. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.d.ts.map +1 -1
  393. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +31 -7
  394. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js.map +1 -1
  395. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
  396. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +8 -1
  397. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
  398. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/cursor.d.ts +16 -0
  399. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/cursor.d.ts.map +1 -0
  400. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/cursor.js +234 -0
  401. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/cursor.js.map +1 -0
  402. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.d.ts.map +1 -1
  403. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js +6 -3
  404. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js.map +1 -1
  405. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts +2 -0
  406. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts.map +1 -1
  407. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
  408. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js.map +1 -1
  409. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +44 -9
  410. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
  411. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +2 -0
  412. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
  413. package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
  414. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts.map +1 -1
  415. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
  416. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js.map +1 -1
  417. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +15 -0
  418. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  419. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +15 -0
  420. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  421. package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
  422. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +2 -0
  423. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
  424. package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.d.ts +15 -0
  425. package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.d.ts.map +1 -0
  426. package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.js +32 -0
  427. package/node_modules/@earendil-works/pi-ai/dist/providers/cursor.js.map +1 -0
  428. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  429. package/node_modules/@earendil-works/pi-ai/dist/providers/data/alibaba-token-plan.json +1 -1
  430. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  431. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  432. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  433. package/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
  434. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  435. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  436. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
  437. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  438. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  439. package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  440. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  441. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  442. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  443. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  444. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  445. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  446. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  447. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  448. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  449. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  450. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  451. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +14 -3
  452. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  453. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  454. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  455. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -0
  456. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
  457. package/node_modules/@earendil-works/pi-ai/dist/utils/pi-user-agent.d.ts +2 -0
  458. package/node_modules/@earendil-works/pi-ai/dist/utils/pi-user-agent.d.ts.map +1 -0
  459. package/node_modules/@earendil-works/pi-ai/dist/utils/pi-user-agent.js +12 -0
  460. package/node_modules/@earendil-works/pi-ai/dist/utils/pi-user-agent.js.map +1 -0
  461. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
  462. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js +3 -2
  463. package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js.map +1 -1
  464. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  465. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -0
  466. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  467. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts.map +1 -1
  468. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js +34 -0
  469. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js.map +1 -1
  470. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  471. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  472. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  473. package/node_modules/@earendil-works/pi-tui/README.md +1 -1
  474. package/node_modules/@earendil-works/pi-tui/dist/alt-screen-search.d.ts +26 -0
  475. package/node_modules/@earendil-works/pi-tui/dist/alt-screen-search.d.ts.map +1 -0
  476. package/node_modules/@earendil-works/pi-tui/dist/alt-screen-search.js +121 -0
  477. package/node_modules/@earendil-works/pi-tui/dist/alt-screen-search.js.map +1 -0
  478. package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.d.ts +6 -1
  479. package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.d.ts.map +1 -1
  480. package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.js +23 -7
  481. package/node_modules/@earendil-works/pi-tui/dist/components/scroll-view.js.map +1 -1
  482. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +4 -1
  483. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
  484. package/node_modules/@earendil-works/pi-tui/dist/index.js +7 -1
  485. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
  486. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +30 -0
  487. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +1 -1
  488. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +24 -0
  489. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +1 -1
  490. package/node_modules/@earendil-works/pi-tui/dist/layout.d.ts.map +1 -1
  491. package/node_modules/@earendil-works/pi-tui/dist/layout.js +9 -2
  492. package/node_modules/@earendil-works/pi-tui/dist/layout.js.map +1 -1
  493. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +8 -2
  494. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts.map +1 -1
  495. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +6 -2
  496. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js.map +1 -1
  497. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +6 -0
  498. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
  499. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +18 -1
  500. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
  501. package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts +21 -0
  502. package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.d.ts.map +1 -1
  503. package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +243 -5
  504. package/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js.map +1 -1
  505. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +2 -0
  506. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  507. package/node_modules/@earendil-works/pi-tui/dist/tui.js +33 -8
  508. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  509. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  510. package/package.json +7 -7
  511. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search.d.ts +0 -19
  512. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search.d.ts.map +0 -1
  513. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search.js +0 -41
  514. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/search.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import { invalidFile } from "./errors.js";
1
+ import { err, ok } from "../../types.js";
2
+ import { JsonlDecodeError } from "./errors.js";
2
3
  const ENTRY_TYPES = new Set([
3
4
  "message",
4
5
  "model_change",
@@ -23,71 +24,84 @@ const OPERATION_KINDS = new Set(["run", "compaction", "navigation"]);
23
24
  function isObject(value) {
24
25
  return typeof value === "object" && value !== null && !Array.isArray(value);
25
26
  }
26
- function parseObject(line, path, lineNumber) {
27
+ function parseObject(line) {
27
28
  let value;
28
29
  try {
29
30
  value = JSON.parse(line);
30
31
  }
31
32
  catch (error) {
32
- throw invalidFile(path, lineNumber, "is not valid JSON", error instanceof Error ? error : undefined);
33
+ throw new JsonlDecodeError("syntax", "is not valid JSON", error instanceof Error ? error : undefined);
33
34
  }
34
35
  if (!isObject(value))
35
- throw invalidFile(path, lineNumber, "is not a JSON object");
36
+ throw new JsonlDecodeError("schema", "is not a JSON object");
36
37
  return value;
37
38
  }
38
- function requireString(value, path, line, field) {
39
+ function requireString(value, field) {
39
40
  if (typeof value !== "string")
40
- throw invalidFile(path, line, `has invalid ${field}`);
41
+ throw new JsonlDecodeError("schema", `has invalid ${field}`);
41
42
  return value;
42
43
  }
43
- function requireSequence(value, path, line) {
44
- if (!Number.isSafeInteger(value) || value <= 0)
45
- throw invalidFile(path, line, "has invalid seq");
44
+ function requireSequence(value) {
45
+ if (!Number.isSafeInteger(value) || value <= 0) {
46
+ throw new JsonlDecodeError("schema", "has invalid seq");
47
+ }
46
48
  return value;
47
49
  }
48
- function requireTimestamp(value, path, line) {
49
- if (!Number.isSafeInteger(value) || value < 0)
50
- throw invalidFile(path, line, "has invalid timestamp");
50
+ function requireTimestamp(value) {
51
+ if (!Number.isSafeInteger(value) || value < 0) {
52
+ throw new JsonlDecodeError("schema", "has invalid timestamp");
53
+ }
51
54
  return value;
52
55
  }
53
- function requireNullableId(value, path, line, field) {
56
+ function requireNullableId(value, field) {
54
57
  if (value !== null && typeof value !== "string") {
55
- throw invalidFile(path, line, `has invalid ${field}`);
58
+ throw new JsonlDecodeError("schema", `has invalid ${field}`);
56
59
  }
57
60
  return value;
58
61
  }
59
- export function parseHeader(line, path) {
60
- const value = parseObject(line, path, 1);
62
+ function decodeHeader(line) {
63
+ const value = parseObject(line);
61
64
  if (value.kind !== "header")
62
- throw invalidFile(path, 1, "is not a header");
65
+ throw new JsonlDecodeError("schema", "is not a header");
63
66
  if (value.version !== 4)
64
- throw invalidFile(path, 1, "has unsupported session version");
67
+ throw new JsonlDecodeError("schema", "has unsupported session version");
65
68
  const parentSessionId = value.parentSessionId;
66
69
  if (parentSessionId !== undefined && typeof parentSessionId !== "string") {
67
- throw invalidFile(path, 1, "has invalid parentSessionId");
70
+ throw new JsonlDecodeError("schema", "has invalid parentSessionId");
68
71
  }
69
72
  const legacyParentSessionPath = value.legacyParentSessionPath;
70
73
  if (legacyParentSessionPath !== undefined && typeof legacyParentSessionPath !== "string") {
71
- throw invalidFile(path, 1, "has invalid legacyParentSessionPath");
74
+ throw new JsonlDecodeError("schema", "has invalid legacyParentSessionPath");
72
75
  }
73
76
  if (parentSessionId !== undefined && legacyParentSessionPath !== undefined) {
74
- throw invalidFile(path, 1, "has both parentSessionId and legacyParentSessionPath");
77
+ throw new JsonlDecodeError("schema", "has both parentSessionId and legacyParentSessionPath");
75
78
  }
76
79
  const metadataValue = value.metadata;
77
- if (metadataValue !== undefined && !isObject(metadataValue))
78
- throw invalidFile(path, 1, "has invalid metadata");
80
+ if (metadataValue !== undefined && !isObject(metadataValue)) {
81
+ throw new JsonlDecodeError("schema", "has invalid metadata");
82
+ }
79
83
  const metadata = metadataValue;
80
84
  return {
81
85
  kind: "header",
82
86
  version: 4,
83
- id: requireString(value.id, path, 1, "id"),
84
- createdAt: requireTimestamp(value.createdAt, path, 1),
85
- cwd: requireString(value.cwd, path, 1, "cwd"),
87
+ id: requireString(value.id, "id"),
88
+ createdAt: requireTimestamp(value.createdAt),
89
+ cwd: requireString(value.cwd, "cwd"),
86
90
  parentSessionId,
87
91
  legacyParentSessionPath,
88
92
  metadata,
89
93
  };
90
94
  }
95
+ export function parseHeader(line) {
96
+ try {
97
+ return ok(decodeHeader(line));
98
+ }
99
+ catch (error) {
100
+ if (error instanceof JsonlDecodeError)
101
+ return err(error);
102
+ throw error;
103
+ }
104
+ }
91
105
  export function encodeHeader(header) {
92
106
  return `${JSON.stringify(header)}\n`;
93
107
  }
@@ -106,73 +120,98 @@ export function metadataFromHeader(header, path, modifiedAt) {
106
120
  ...(header.metadata === undefined ? {} : { metadata: header.metadata }),
107
121
  };
108
122
  }
109
- export function parseMutation(line, path, lineNumber) {
110
- const value = parseObject(line, path, lineNumber);
111
- const seq = requireSequence(value.seq, path, lineNumber);
112
- switch (value.kind) {
113
- case "entry": {
114
- const lane = value.lane === undefined ? undefined : requireString(value.lane, path, lineNumber, "lane");
115
- const id = requireString(value.id, path, lineNumber, "id");
116
- const type = requireString(value.type, path, lineNumber, "entry type");
117
- if (!ENTRY_TYPES.has(type))
118
- throw invalidFile(path, lineNumber, `has unknown entry type ${type}`);
119
- const parentId = requireNullableId(value.parentId, path, lineNumber, "parentId");
120
- const timestamp = requireTimestamp(value.timestamp, path, lineNumber);
121
- if (type === "custom")
122
- requireString(value.customType, path, lineNumber, "customType");
123
- const { kind: _kind, lane: _lane, ...entryFields } = value;
124
- const entry = { ...entryFields, id, type, parentId, seq, timestamp };
125
- return lane === undefined ? { kind: "entry", entry } : { kind: "entry", lane, entry };
123
+ function parseEntryMutation(value, seq) {
124
+ const lane = value.lane === undefined ? undefined : requireString(value.lane, "lane");
125
+ const id = requireString(value.id, "id");
126
+ const type = requireString(value.type, "entry type");
127
+ if (!ENTRY_TYPES.has(type)) {
128
+ throw new JsonlDecodeError("schema", `has unknown entry type ${type}`);
129
+ }
130
+ const parentId = requireNullableId(value.parentId, "parentId");
131
+ const timestamp = requireTimestamp(value.timestamp);
132
+ if (type === "custom")
133
+ requireString(value.customType, "customType");
134
+ const { kind: _kind, lane: _lane, ...entryFields } = value;
135
+ const entry = { ...entryFields, id, type, parentId, seq, timestamp };
136
+ return lane === undefined ? { kind: "entry", entry } : { kind: "entry", lane, entry };
137
+ }
138
+ function parseRecordMutation(value, seq) {
139
+ const id = requireString(value.id, "id");
140
+ const lane = requireString(value.lane, "lane");
141
+ const type = requireString(value.type, "record type");
142
+ if (!RECORD_TYPES.has(type)) {
143
+ throw new JsonlDecodeError("schema", `has unknown record type ${type}`);
144
+ }
145
+ const timestamp = requireTimestamp(value.timestamp);
146
+ if (type === "operation_started") {
147
+ if (!isObject(value.intent))
148
+ throw new JsonlDecodeError("schema", "has invalid intent");
149
+ const operationKind = requireString(value.intent.kind, "operation kind");
150
+ if (!OPERATION_KINDS.has(operationKind)) {
151
+ throw new JsonlDecodeError("schema", `has unknown operation kind ${operationKind}`);
126
152
  }
127
- case "record": {
128
- const id = requireString(value.id, path, lineNumber, "id");
129
- const lane = requireString(value.lane, path, lineNumber, "lane");
130
- const type = requireString(value.type, path, lineNumber, "record type");
131
- if (!RECORD_TYPES.has(type))
132
- throw invalidFile(path, lineNumber, `has unknown record type ${type}`);
133
- const timestamp = requireTimestamp(value.timestamp, path, lineNumber);
134
- if (type === "operation_started") {
135
- if (!isObject(value.intent))
136
- throw invalidFile(path, lineNumber, "has invalid intent");
137
- const operationKind = requireString(value.intent.kind, path, lineNumber, "operation kind");
138
- if (!OPERATION_KINDS.has(operationKind)) {
139
- throw invalidFile(path, lineNumber, `has unknown operation kind ${operationKind}`);
140
- }
141
- }
142
- if (type === "operation_finished")
143
- requireString(value.runId, path, lineNumber, "runId");
144
- const { kind: _kind, ...recordFields } = value;
145
- return {
146
- kind: "record",
147
- record: { ...recordFields, id, lane, type, seq, timestamp },
148
- };
153
+ }
154
+ if (type === "operation_finished")
155
+ requireString(value.runId, "runId");
156
+ const { kind: _kind, ...recordFields } = value;
157
+ return {
158
+ kind: "record",
159
+ record: { ...recordFields, id, lane, type, seq, timestamp },
160
+ };
161
+ }
162
+ function parseLaneMutation(value, seq) {
163
+ return {
164
+ kind: "lane",
165
+ seq,
166
+ lane: requireString(value.lane, "lane"),
167
+ leafId: requireNullableId(value.leafId, "leafId"),
168
+ };
169
+ }
170
+ function parseFactMutation(value, seq) {
171
+ if (value.fact === "name") {
172
+ if (value.name !== undefined && typeof value.name !== "string") {
173
+ throw new JsonlDecodeError("schema", "has invalid name");
174
+ }
175
+ return { kind: "fact", seq, fact: "name", name: value.name };
176
+ }
177
+ if (value.fact === "label") {
178
+ if (value.label !== undefined && typeof value.label !== "string") {
179
+ throw new JsonlDecodeError("schema", "has invalid label");
149
180
  }
181
+ return {
182
+ kind: "fact",
183
+ seq,
184
+ fact: "label",
185
+ targetId: requireString(value.targetId, "targetId"),
186
+ label: value.label,
187
+ };
188
+ }
189
+ throw new JsonlDecodeError("schema", "has unknown fact type");
190
+ }
191
+ function decodeMutation(line) {
192
+ const value = parseObject(line);
193
+ const seq = requireSequence(value.seq);
194
+ switch (value.kind) {
195
+ case "entry":
196
+ return parseEntryMutation(value, seq);
197
+ case "record":
198
+ return parseRecordMutation(value, seq);
150
199
  case "lane":
151
- return {
152
- kind: "lane",
153
- seq,
154
- lane: requireString(value.lane, path, lineNumber, "lane"),
155
- leafId: requireNullableId(value.leafId, path, lineNumber, "leafId"),
156
- };
200
+ return parseLaneMutation(value, seq);
157
201
  case "fact":
158
- if (value.fact === "name") {
159
- return { kind: "fact", seq, fact: "name", name: requireString(value.name, path, lineNumber, "name") };
160
- }
161
- if (value.fact === "label") {
162
- if (value.label !== undefined && typeof value.label !== "string") {
163
- throw invalidFile(path, lineNumber, "has invalid label");
164
- }
165
- return {
166
- kind: "fact",
167
- seq,
168
- fact: "label",
169
- targetId: requireString(value.targetId, path, lineNumber, "targetId"),
170
- label: value.label,
171
- };
172
- }
173
- throw invalidFile(path, lineNumber, "has unknown fact type");
202
+ return parseFactMutation(value, seq);
174
203
  default:
175
- throw invalidFile(path, lineNumber, "has unknown mutation kind");
204
+ throw new JsonlDecodeError("schema", "has unknown mutation kind");
205
+ }
206
+ }
207
+ export function parseMutation(line) {
208
+ try {
209
+ return ok(decodeMutation(line));
210
+ }
211
+ catch (error) {
212
+ if (error instanceof JsonlDecodeError)
213
+ return err(error);
214
+ throw error;
176
215
  }
177
216
  }
178
217
  export function encodeMutation(mutation) {
@@ -1 +1 @@
1
- {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/codec.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,MAAM,WAAW,GAAG,IAAI,GAAG,CAAgB;IAC1C,SAAS;IACT,cAAc;IACd,uBAAuB;IACvB,qBAAqB;IACrB,YAAY;IACZ,gBAAgB;IAChB,QAAQ;CACR,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAqB;IAChD,mBAAmB;IACnB,iBAAiB;IACjB,oBAAoB;IACpB,cAAc;IACd,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,OAAO;CACP,CAAC,CAAC;AACH,MAAM,eAAe,GAAG,IAAI,GAA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,CAAC,QAAQ,CAAC,IAAI,CAAC;IACzC,CAAC;AACF,CAAC","sourcesContent":["import type { SessionMutation } from \"../state.ts\";\nimport type { Entry, LaneRecord } from \"../types.ts\";\nimport { invalidFile } from \"./errors.ts\";\nimport type { JsonlSessionMetadata, JsonlV4Header } from \"./types.ts\";\n\nconst ENTRY_TYPES = new Set<Entry[\"type\"]>([\n\t\"message\",\n\t\"model_change\",\n\t\"thinking_level_change\",\n\t\"active_tools_change\",\n\t\"compaction\",\n\t\"branch_summary\",\n\t\"custom\",\n]);\nconst RECORD_TYPES = new Set<LaneRecord[\"type\"]>([\n\t\"operation_started\",\n\t\"abort_requested\",\n\t\"operation_finished\",\n\t\"step_attempt\",\n\t\"tool_started\",\n\t\"queue_enqueued\",\n\t\"queue_cancelled\",\n\t\"write_deferred\",\n\t\"usage\",\n]);\nconst OPERATION_KINDS = new Set([\"run\", \"compaction\", \"navigation\"]);\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction parseObject(line: string, path: string, lineNumber: number): Record<string, unknown> {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(line);\n\t} catch (error) {\n\t\tthrow invalidFile(path, lineNumber, \"is not valid JSON\", error instanceof Error ? error : undefined);\n\t}\n\tif (!isObject(value)) throw invalidFile(path, lineNumber, \"is not a JSON object\");\n\treturn value;\n}\n\nfunction requireString(value: unknown, path: string, line: number, field: string): string {\n\tif (typeof value !== \"string\") throw invalidFile(path, line, `has invalid ${field}`);\n\treturn value;\n}\n\nfunction requireSequence(value: unknown, path: string, line: number): number {\n\tif (!Number.isSafeInteger(value) || (value as number) <= 0) throw invalidFile(path, line, \"has invalid seq\");\n\treturn value as number;\n}\n\nfunction requireTimestamp(value: unknown, path: string, line: number): number {\n\tif (!Number.isSafeInteger(value) || (value as number) < 0) throw invalidFile(path, line, \"has invalid timestamp\");\n\treturn value as number;\n}\n\nfunction requireNullableId(value: unknown, path: string, line: number, field: string): string | null {\n\tif (value !== null && typeof value !== \"string\") {\n\t\tthrow invalidFile(path, line, `has invalid ${field}`);\n\t}\n\treturn value as string | null;\n}\n\nexport function parseHeader(line: string, path: string): JsonlV4Header {\n\tconst value = parseObject(line, path, 1);\n\tif (value.kind !== \"header\") throw invalidFile(path, 1, \"is not a header\");\n\tif (value.version !== 4) throw invalidFile(path, 1, \"has unsupported session version\");\n\tconst parentSessionId = value.parentSessionId;\n\tif (parentSessionId !== undefined && typeof parentSessionId !== \"string\") {\n\t\tthrow invalidFile(path, 1, \"has invalid parentSessionId\");\n\t}\n\tconst legacyParentSessionPath = value.legacyParentSessionPath;\n\tif (legacyParentSessionPath !== undefined && typeof legacyParentSessionPath !== \"string\") {\n\t\tthrow invalidFile(path, 1, \"has invalid legacyParentSessionPath\");\n\t}\n\tif (parentSessionId !== undefined && legacyParentSessionPath !== undefined) {\n\t\tthrow invalidFile(path, 1, \"has both parentSessionId and legacyParentSessionPath\");\n\t}\n\tconst metadataValue = value.metadata;\n\tif (metadataValue !== undefined && !isObject(metadataValue)) throw invalidFile(path, 1, \"has invalid metadata\");\n\tconst metadata = metadataValue as JsonlV4Header[\"metadata\"];\n\treturn {\n\t\tkind: \"header\",\n\t\tversion: 4,\n\t\tid: requireString(value.id, path, 1, \"id\"),\n\t\tcreatedAt: requireTimestamp(value.createdAt, path, 1),\n\t\tcwd: requireString(value.cwd, path, 1, \"cwd\"),\n\t\tparentSessionId,\n\t\tlegacyParentSessionPath,\n\t\tmetadata,\n\t};\n}\n\nexport function encodeHeader(header: JsonlV4Header): string {\n\treturn `${JSON.stringify(header)}\\n`;\n}\n\nexport function metadataFromHeader(header: JsonlV4Header, path: string, modifiedAt: number): JsonlSessionMetadata {\n\treturn {\n\t\tid: header.id,\n\t\tcreatedAt: header.createdAt,\n\t\tcwd: header.cwd,\n\t\tpath,\n\t\tmodifiedAt,\n\t\tsourceFormat: 4,\n\t\t...(header.parentSessionId === undefined ? {} : { parentSessionId: header.parentSessionId }),\n\t\t...(header.legacyParentSessionPath === undefined\n\t\t\t? {}\n\t\t\t: { legacyParentSessionPath: header.legacyParentSessionPath }),\n\t\t...(header.metadata === undefined ? {} : { metadata: header.metadata }),\n\t};\n}\n\nexport function parseMutation(line: string, path: string, lineNumber: number): SessionMutation {\n\tconst value = parseObject(line, path, lineNumber);\n\tconst seq = requireSequence(value.seq, path, lineNumber);\n\tswitch (value.kind) {\n\t\tcase \"entry\": {\n\t\t\tconst lane = value.lane === undefined ? undefined : requireString(value.lane, path, lineNumber, \"lane\");\n\t\t\tconst id = requireString(value.id, path, lineNumber, \"id\");\n\t\t\tconst type = requireString(value.type, path, lineNumber, \"entry type\");\n\t\t\tif (!ENTRY_TYPES.has(type as Entry[\"type\"]))\n\t\t\t\tthrow invalidFile(path, lineNumber, `has unknown entry type ${type}`);\n\t\t\tconst parentId = requireNullableId(value.parentId, path, lineNumber, \"parentId\");\n\t\t\tconst timestamp = requireTimestamp(value.timestamp, path, lineNumber);\n\t\t\tif (type === \"custom\") requireString(value.customType, path, lineNumber, \"customType\");\n\t\t\tconst { kind: _kind, lane: _lane, ...entryFields } = value;\n\t\t\tconst entry = { ...entryFields, id, type, parentId, seq, timestamp } as unknown as Entry;\n\t\t\treturn lane === undefined ? { kind: \"entry\", entry } : { kind: \"entry\", lane, entry };\n\t\t}\n\t\tcase \"record\": {\n\t\t\tconst id = requireString(value.id, path, lineNumber, \"id\");\n\t\t\tconst lane = requireString(value.lane, path, lineNumber, \"lane\");\n\t\t\tconst type = requireString(value.type, path, lineNumber, \"record type\");\n\t\t\tif (!RECORD_TYPES.has(type as LaneRecord[\"type\"]))\n\t\t\t\tthrow invalidFile(path, lineNumber, `has unknown record type ${type}`);\n\t\t\tconst timestamp = requireTimestamp(value.timestamp, path, lineNumber);\n\t\t\tif (type === \"operation_started\") {\n\t\t\t\tif (!isObject(value.intent)) throw invalidFile(path, lineNumber, \"has invalid intent\");\n\t\t\t\tconst operationKind = requireString(value.intent.kind, path, lineNumber, \"operation kind\");\n\t\t\t\tif (!OPERATION_KINDS.has(operationKind)) {\n\t\t\t\t\tthrow invalidFile(path, lineNumber, `has unknown operation kind ${operationKind}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (type === \"operation_finished\") requireString(value.runId, path, lineNumber, \"runId\");\n\t\t\tconst { kind: _kind, ...recordFields } = value;\n\t\t\treturn {\n\t\t\t\tkind: \"record\",\n\t\t\t\trecord: { ...recordFields, id, lane, type, seq, timestamp } as unknown as LaneRecord,\n\t\t\t};\n\t\t}\n\t\tcase \"lane\":\n\t\t\treturn {\n\t\t\t\tkind: \"lane\",\n\t\t\t\tseq,\n\t\t\t\tlane: requireString(value.lane, path, lineNumber, \"lane\"),\n\t\t\t\tleafId: requireNullableId(value.leafId, path, lineNumber, \"leafId\"),\n\t\t\t};\n\t\tcase \"fact\":\n\t\t\tif (value.fact === \"name\") {\n\t\t\t\treturn { kind: \"fact\", seq, fact: \"name\", name: requireString(value.name, path, lineNumber, \"name\") };\n\t\t\t}\n\t\t\tif (value.fact === \"label\") {\n\t\t\t\tif (value.label !== undefined && typeof value.label !== \"string\") {\n\t\t\t\t\tthrow invalidFile(path, lineNumber, \"has invalid label\");\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"fact\",\n\t\t\t\t\tseq,\n\t\t\t\t\tfact: \"label\",\n\t\t\t\t\ttargetId: requireString(value.targetId, path, lineNumber, \"targetId\"),\n\t\t\t\t\tlabel: value.label,\n\t\t\t\t};\n\t\t\t}\n\t\t\tthrow invalidFile(path, lineNumber, \"has unknown fact type\");\n\t\tdefault:\n\t\t\tthrow invalidFile(path, lineNumber, \"has unknown mutation kind\");\n\t}\n}\n\nexport function encodeMutation(mutation: SessionMutation): string {\n\tswitch (mutation.kind) {\n\t\tcase \"entry\":\n\t\t\treturn `${JSON.stringify({ kind: \"entry\", lane: mutation.lane, ...mutation.entry })}\\n`;\n\t\tcase \"record\":\n\t\t\treturn `${JSON.stringify({ kind: \"record\", ...mutation.record })}\\n`;\n\t\tcase \"lane\":\n\t\t\treturn `${JSON.stringify(mutation)}\\n`;\n\t\tcase \"fact\":\n\t\t\treturn `${JSON.stringify(mutation)}\\n`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,WAAW,GAAG,IAAI,GAAG,CAAgB;IAC1C,SAAS;IACT,cAAc;IACd,uBAAuB;IACvB,qBAAqB;IACrB,YAAY;IACZ,gBAAgB;IAChB,QAAQ;CACR,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAqB;IAChD,mBAAmB;IACnB,iBAAiB;IACjB,oBAAoB;IACpB,cAAc;IACd,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,OAAO;CACP,CAAC,CAAC;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;AAErE,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAChC,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACJ,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,C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types.ts\";\nimport type { SessionMutation } from \"../state.ts\";\nimport type { Entry, LaneRecord } from \"../types.ts\";\nimport { JsonlDecodeError } from \"./errors.ts\";\nimport type { JsonlSessionMetadata, JsonlV4Header } from \"./types.ts\";\n\nconst ENTRY_TYPES = new Set<Entry[\"type\"]>([\n\t\"message\",\n\t\"model_change\",\n\t\"thinking_level_change\",\n\t\"active_tools_change\",\n\t\"compaction\",\n\t\"branch_summary\",\n\t\"custom\",\n]);\nconst RECORD_TYPES = new Set<LaneRecord[\"type\"]>([\n\t\"operation_started\",\n\t\"abort_requested\",\n\t\"operation_finished\",\n\t\"step_attempt\",\n\t\"tool_started\",\n\t\"queue_enqueued\",\n\t\"queue_cancelled\",\n\t\"write_deferred\",\n\t\"usage\",\n]);\nconst OPERATION_KINDS = new Set([\"run\", \"compaction\", \"navigation\"]);\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction parseObject(line: string): Record<string, unknown> {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(line);\n\t} catch (error) {\n\t\tthrow new JsonlDecodeError(\"syntax\", \"is not valid JSON\", error instanceof Error ? error : undefined);\n\t}\n\tif (!isObject(value)) throw new JsonlDecodeError(\"schema\", \"is not a JSON object\");\n\treturn value;\n}\n\nfunction requireString(value: unknown, field: string): string {\n\tif (typeof value !== \"string\") throw new JsonlDecodeError(\"schema\", `has invalid ${field}`);\n\treturn value;\n}\n\nfunction requireSequence(value: unknown): number {\n\tif (!Number.isSafeInteger(value) || (value as number) <= 0) {\n\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid seq\");\n\t}\n\treturn value as number;\n}\n\nfunction requireTimestamp(value: unknown): number {\n\tif (!Number.isSafeInteger(value) || (value as number) < 0) {\n\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid timestamp\");\n\t}\n\treturn value as number;\n}\n\nfunction requireNullableId(value: unknown, field: string): string | null {\n\tif (value !== null && typeof value !== \"string\") {\n\t\tthrow new JsonlDecodeError(\"schema\", `has invalid ${field}`);\n\t}\n\treturn value as string | null;\n}\n\nfunction decodeHeader(line: string): JsonlV4Header {\n\tconst value = parseObject(line);\n\tif (value.kind !== \"header\") throw new JsonlDecodeError(\"schema\", \"is not a header\");\n\tif (value.version !== 4) throw new JsonlDecodeError(\"schema\", \"has unsupported session version\");\n\tconst parentSessionId = value.parentSessionId;\n\tif (parentSessionId !== undefined && typeof parentSessionId !== \"string\") {\n\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid parentSessionId\");\n\t}\n\tconst legacyParentSessionPath = value.legacyParentSessionPath;\n\tif (legacyParentSessionPath !== undefined && typeof legacyParentSessionPath !== \"string\") {\n\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid legacyParentSessionPath\");\n\t}\n\tif (parentSessionId !== undefined && legacyParentSessionPath !== undefined) {\n\t\tthrow new JsonlDecodeError(\"schema\", \"has both parentSessionId and legacyParentSessionPath\");\n\t}\n\tconst metadataValue = value.metadata;\n\tif (metadataValue !== undefined && !isObject(metadataValue)) {\n\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid metadata\");\n\t}\n\tconst metadata = metadataValue as JsonlV4Header[\"metadata\"];\n\treturn {\n\t\tkind: \"header\",\n\t\tversion: 4,\n\t\tid: requireString(value.id, \"id\"),\n\t\tcreatedAt: requireTimestamp(value.createdAt),\n\t\tcwd: requireString(value.cwd, \"cwd\"),\n\t\tparentSessionId,\n\t\tlegacyParentSessionPath,\n\t\tmetadata,\n\t};\n}\n\nexport function parseHeader(line: string): Result<JsonlV4Header, JsonlDecodeError> {\n\ttry {\n\t\treturn ok<JsonlV4Header, JsonlDecodeError>(decodeHeader(line));\n\t} catch (error) {\n\t\tif (error instanceof JsonlDecodeError) return err<JsonlV4Header, JsonlDecodeError>(error);\n\t\tthrow error;\n\t}\n}\n\nexport function encodeHeader(header: JsonlV4Header): string {\n\treturn `${JSON.stringify(header)}\\n`;\n}\n\nexport function metadataFromHeader(header: JsonlV4Header, path: string, modifiedAt: number): JsonlSessionMetadata {\n\treturn {\n\t\tid: header.id,\n\t\tcreatedAt: header.createdAt,\n\t\tcwd: header.cwd,\n\t\tpath,\n\t\tmodifiedAt,\n\t\tsourceFormat: 4,\n\t\t...(header.parentSessionId === undefined ? {} : { parentSessionId: header.parentSessionId }),\n\t\t...(header.legacyParentSessionPath === undefined\n\t\t\t? {}\n\t\t\t: { legacyParentSessionPath: header.legacyParentSessionPath }),\n\t\t...(header.metadata === undefined ? {} : { metadata: header.metadata }),\n\t};\n}\n\nfunction parseEntryMutation(value: Record<string, unknown>, seq: number): Extract<SessionMutation, { kind: \"entry\" }> {\n\tconst lane = value.lane === undefined ? undefined : requireString(value.lane, \"lane\");\n\tconst id = requireString(value.id, \"id\");\n\tconst type = requireString(value.type, \"entry type\");\n\tif (!ENTRY_TYPES.has(type as Entry[\"type\"])) {\n\t\tthrow new JsonlDecodeError(\"schema\", `has unknown entry type ${type}`);\n\t}\n\tconst parentId = requireNullableId(value.parentId, \"parentId\");\n\tconst timestamp = requireTimestamp(value.timestamp);\n\tif (type === \"custom\") requireString(value.customType, \"customType\");\n\tconst { kind: _kind, lane: _lane, ...entryFields } = value;\n\tconst entry = { ...entryFields, id, type, parentId, seq, timestamp } as unknown as Entry;\n\treturn lane === undefined ? { kind: \"entry\", entry } : { kind: \"entry\", lane, entry };\n}\n\nfunction parseRecordMutation(\n\tvalue: Record<string, unknown>,\n\tseq: number,\n): Extract<SessionMutation, { kind: \"record\" }> {\n\tconst id = requireString(value.id, \"id\");\n\tconst lane = requireString(value.lane, \"lane\");\n\tconst type = requireString(value.type, \"record type\");\n\tif (!RECORD_TYPES.has(type as LaneRecord[\"type\"])) {\n\t\tthrow new JsonlDecodeError(\"schema\", `has unknown record type ${type}`);\n\t}\n\tconst timestamp = requireTimestamp(value.timestamp);\n\tif (type === \"operation_started\") {\n\t\tif (!isObject(value.intent)) throw new JsonlDecodeError(\"schema\", \"has invalid intent\");\n\t\tconst operationKind = requireString(value.intent.kind, \"operation kind\");\n\t\tif (!OPERATION_KINDS.has(operationKind)) {\n\t\t\tthrow new JsonlDecodeError(\"schema\", `has unknown operation kind ${operationKind}`);\n\t\t}\n\t}\n\tif (type === \"operation_finished\") requireString(value.runId, \"runId\");\n\tconst { kind: _kind, ...recordFields } = value;\n\treturn {\n\t\tkind: \"record\",\n\t\trecord: { ...recordFields, id, lane, type, seq, timestamp } as unknown as LaneRecord,\n\t};\n}\n\nfunction parseLaneMutation(value: Record<string, unknown>, seq: number): Extract<SessionMutation, { kind: \"lane\" }> {\n\treturn {\n\t\tkind: \"lane\",\n\t\tseq,\n\t\tlane: requireString(value.lane, \"lane\"),\n\t\tleafId: requireNullableId(value.leafId, \"leafId\"),\n\t};\n}\n\nfunction parseFactMutation(value: Record<string, unknown>, seq: number): Extract<SessionMutation, { kind: \"fact\" }> {\n\tif (value.fact === \"name\") {\n\t\tif (value.name !== undefined && typeof value.name !== \"string\") {\n\t\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid name\");\n\t\t}\n\t\treturn { kind: \"fact\", seq, fact: \"name\", name: value.name };\n\t}\n\tif (value.fact === \"label\") {\n\t\tif (value.label !== undefined && typeof value.label !== \"string\") {\n\t\t\tthrow new JsonlDecodeError(\"schema\", \"has invalid label\");\n\t\t}\n\t\treturn {\n\t\t\tkind: \"fact\",\n\t\t\tseq,\n\t\t\tfact: \"label\",\n\t\t\ttargetId: requireString(value.targetId, \"targetId\"),\n\t\t\tlabel: value.label,\n\t\t};\n\t}\n\tthrow new JsonlDecodeError(\"schema\", \"has unknown fact type\");\n}\n\nfunction decodeMutation(line: string): SessionMutation {\n\tconst value = parseObject(line);\n\tconst seq = requireSequence(value.seq);\n\tswitch (value.kind) {\n\t\tcase \"entry\":\n\t\t\treturn parseEntryMutation(value, seq);\n\t\tcase \"record\":\n\t\t\treturn parseRecordMutation(value, seq);\n\t\tcase \"lane\":\n\t\t\treturn parseLaneMutation(value, seq);\n\t\tcase \"fact\":\n\t\t\treturn parseFactMutation(value, seq);\n\t\tdefault:\n\t\t\tthrow new JsonlDecodeError(\"schema\", \"has unknown mutation kind\");\n\t}\n}\n\nexport function parseMutation(line: string): Result<SessionMutation, JsonlDecodeError> {\n\ttry {\n\t\treturn ok<SessionMutation, JsonlDecodeError>(decodeMutation(line));\n\t} catch (error) {\n\t\tif (error instanceof JsonlDecodeError) return err<SessionMutation, JsonlDecodeError>(error);\n\t\tthrow error;\n\t}\n}\n\nexport function encodeMutation(mutation: SessionMutation): string {\n\tswitch (mutation.kind) {\n\t\tcase \"entry\":\n\t\t\treturn `${JSON.stringify({ kind: \"entry\", lane: mutation.lane, ...mutation.entry })}\\n`;\n\t\tcase \"record\":\n\t\t\treturn `${JSON.stringify({ kind: \"record\", ...mutation.record })}\\n`;\n\t\tcase \"lane\":\n\t\t\treturn `${JSON.stringify(mutation)}\\n`;\n\t\tcase \"fact\":\n\t\t\treturn `${JSON.stringify(mutation)}\\n`;\n\t}\n}\n"]}
@@ -1,5 +1,9 @@
1
1
  import type { FileError, Result } from "../../types.ts";
2
2
  import { SessionError } from "../types.ts";
3
+ export declare class JsonlDecodeError extends Error {
4
+ readonly kind: "syntax" | "schema";
5
+ constructor(kind: "syntax" | "schema", message: string, cause?: Error);
6
+ }
3
7
  export declare function fileResult<T>(result: Result<T, FileError>, message: string): T;
4
- export declare function invalidFile(path: string, line: number, message: string, cause?: Error): SessionError;
8
+ export declare function invalidFile(path: string, line: number, cause: Error): SessionError;
5
9
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAS9E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,YAAY,CAEpG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;gBAEvB,IAAI,EAAE,QAAQ,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAKrE;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAS9E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,YAAY,CAElF"}
@@ -1,11 +1,18 @@
1
1
  import { SessionError } from "../types.js";
2
+ export class JsonlDecodeError extends Error {
3
+ constructor(kind, message, cause) {
4
+ super(message, cause === undefined ? undefined : { cause });
5
+ this.name = "JsonlDecodeError";
6
+ this.kind = kind;
7
+ }
8
+ }
2
9
  export function fileResult(result, message) {
3
10
  if (!result.ok) {
4
11
  throw new SessionError(result.error.code === "not_found" ? "not_found" : "storage", `${message}: ${result.error.message}`, result.error);
5
12
  }
6
13
  return result.value;
7
14
  }
8
- export function invalidFile(path, line, message, cause) {
9
- return new SessionError("invalid_entry", `Invalid JSONL v4 session ${path}: line ${line} ${message}`, cause);
15
+ export function invalidFile(path, line, cause) {
16
+ return new SessionError("invalid_entry", `Invalid JSONL v4 session ${path}: line ${line} ${cause.message}`, cause);
10
17
  }
11
18
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,UAAU,UAAU,CAAI,MAA4B,EAAE,OAAe;IAC1E,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,YAAY,CACrB,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAC3D,GAAG,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,EACrC,MAAM,CAAC,KAAK,CACZ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY,EAAE,OAAe,EAAE,KAAa;IACrF,OAAO,IAAI,YAAY,CAAC,eAAe,EAAE,4BAA4B,IAAI,UAAU,IAAI,IAAI,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;AAC9G,CAAC","sourcesContent":["import type { FileError, Result } from \"../../types.ts\";\nimport { SessionError } from \"../types.ts\";\n\nexport function fileResult<T>(result: Result<T, FileError>, message: string): T {\n\tif (!result.ok) {\n\t\tthrow new SessionError(\n\t\t\tresult.error.code === \"not_found\" ? \"not_found\" : \"storage\",\n\t\t\t`${message}: ${result.error.message}`,\n\t\t\tresult.error,\n\t\t);\n\t}\n\treturn result.value;\n}\n\nexport function invalidFile(path: string, line: number, message: string, cause?: Error): SessionError {\n\treturn new SessionError(\"invalid_entry\", `Invalid JSONL v4 session ${path}: line ${line} ${message}`, cause);\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAG1C,YAAY,IAAyB,EAAE,OAAe,EAAE,KAAa;QACpE,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,UAAU,UAAU,CAAI,MAA4B,EAAE,OAAe;IAC1E,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,YAAY,CACrB,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAC3D,GAAG,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,EACrC,MAAM,CAAC,KAAK,CACZ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY,EAAE,KAAY;IACnE,OAAO,IAAI,YAAY,CAAC,eAAe,EAAE,4BAA4B,IAAI,UAAU,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;AACpH,CAAC","sourcesContent":["import type { FileError, Result } from \"../../types.ts\";\nimport { SessionError } from \"../types.ts\";\n\nexport class JsonlDecodeError extends Error {\n\treadonly kind: \"syntax\" | \"schema\";\n\n\tconstructor(kind: \"syntax\" | \"schema\", message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"JsonlDecodeError\";\n\t\tthis.kind = kind;\n\t}\n}\n\nexport function fileResult<T>(result: Result<T, FileError>, message: string): T {\n\tif (!result.ok) {\n\t\tthrow new SessionError(\n\t\t\tresult.error.code === \"not_found\" ? \"not_found\" : \"storage\",\n\t\t\t`${message}: ${result.error.message}`,\n\t\t\tresult.error,\n\t\t);\n\t}\n\treturn result.value;\n}\n\nexport function invalidFile(path: string, line: number, cause: Error): SessionError {\n\treturn new SessionError(\"invalid_entry\", `Invalid JSONL v4 session ${path}: line ${line} ${cause.message}`, cause);\n}\n"]}
@@ -1,22 +1,31 @@
1
1
  import { Session } from "../session.ts";
2
2
  import { type ForkOptions, type SessionRepo } from "../types.ts";
3
+ import { JsonlSessionStorage } from "./storage.ts";
3
4
  import type { JsonlSessionCreateOptions, JsonlSessionListOptions, JsonlSessionMetadata, JsonlSessionRepoOptions } from "./types.ts";
5
+ export declare function listJsonlSessionMetadata(options: JsonlSessionRepoOptions, query?: JsonlSessionListOptions): Promise<JsonlSessionMetadata[]>;
6
+ export declare function loadJsonlSessionStorage(options: JsonlSessionRepoOptions, metadata: JsonlSessionMetadata): Promise<JsonlSessionStorage>;
4
7
  export declare class JsonlSessionRepo implements SessionRepo<JsonlSessionMetadata, JsonlSessionCreateOptions, JsonlSessionListOptions> {
5
8
  private readonly fs;
6
9
  private readonly sessionsRootInput;
10
+ private readonly activeCreateDestinations;
7
11
  private rootPromise;
8
12
  constructor(options: JsonlSessionRepoOptions);
9
13
  create(options: JsonlSessionCreateOptions): Promise<Session<JsonlSessionMetadata>>;
10
14
  open(metadata: JsonlSessionMetadata): Promise<Session<JsonlSessionMetadata>>;
11
- list(): Promise<JsonlSessionMetadata[]>;
12
- list(options: JsonlSessionListOptions): Promise<JsonlSessionMetadata[]>;
15
+ list(options?: JsonlSessionListOptions): Promise<JsonlSessionMetadata[]>;
13
16
  delete(metadata: JsonlSessionMetadata): Promise<void>;
14
17
  fork(source: JsonlSessionMetadata, options: ForkOptions & JsonlSessionCreateOptions): Promise<Session<JsonlSessionMetadata>>;
15
18
  private loadStorage;
19
+ private resolveCreateDestination;
20
+ /**
21
+ * Prevent same-process create/fork races for one logical destination. The durable filename includes a
22
+ * timestamp, so the async filesystem existence check alone can let two concurrent calls both decide the
23
+ * same {cwd, id} is free and publish duplicate sessions.
24
+ */
25
+ private claimCreateDestination;
16
26
  private prepareCreate;
17
27
  private listDirect;
18
28
  private sessionIdExists;
19
- private sessionDirectories;
20
29
  private sessionDirectory;
21
30
  private root;
22
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/repo.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,OAAO,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,KAAK,WAAW,EAAgB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/E,OAAO,KAAK,EACX,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EAEpB,uBAAuB,EAEvB,MAAM,YAAY,CAAC;AAsBpB,qBAAa,gBACZ,YAAW,WAAW,CAAC,oBAAoB,EAAE,yBAAyB,EAAE,uBAAuB,CAAC;IAEhG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAA6B;IAChD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,WAAW,CAA8B;gBAErC,OAAO,EAAE,uBAAuB;IAKtC,MAAM,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAKlF,IAAI,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAIlF,IAAI,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IACvC,IAAI,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAKjE,MAAM,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIr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