@aria-cli/cli 1.0.57 → 1.0.59

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 (319) hide show
  1. package/bin/aria.mjs +799 -668
  2. package/package.json +17 -76
  3. package/dist/.tsbuildinfo +0 -1
  4. package/dist/attached-local-control-client.js +0 -826
  5. package/dist/bootstrap-local-control-client.js +0 -2
  6. package/dist/capability-aware-method-proxy.js +0 -42
  7. package/dist/cli-context.js +0 -160
  8. package/dist/commands/arions.js +0 -174
  9. package/dist/commands/auth.js +0 -123
  10. package/dist/commands/daemon.js +0 -367
  11. package/dist/commands/definitions.js +0 -176
  12. package/dist/commands/index.js +0 -80
  13. package/dist/commands/login-handler.js +0 -1108
  14. package/dist/commands/logout-handler.js +0 -92
  15. package/dist/commands/memory-handlers.js +0 -89
  16. package/dist/commands/pairing.js +0 -60
  17. package/dist/commands/runtime-cutover-reset-command.js +0 -12
  18. package/dist/commands/runtime-cutover-reset.js +0 -265
  19. package/dist/commands/terminal-setup.js +0 -84
  20. package/dist/config/aria-config.js +0 -238
  21. package/dist/config/index.js +0 -3
  22. package/dist/config/loader.js +0 -97
  23. package/dist/config.js +0 -142
  24. package/dist/daemon-info.js +0 -10
  25. package/dist/ensure-daemon.js +0 -128
  26. package/dist/entrypoints/command-mode.js +0 -5
  27. package/dist/entrypoints/daemon.js +0 -50
  28. package/dist/entrypoints/headless-stdio.js +0 -25
  29. package/dist/entrypoints/interactive.js +0 -80
  30. package/dist/event-loop-watchdog.js +0 -73
  31. package/dist/headless/auth-orchestrator.js +0 -508
  32. package/dist/headless/auth-service.js +0 -43
  33. package/dist/headless/bootstrap-fast-path.js +0 -112
  34. package/dist/headless/call-command.js +0 -143
  35. package/dist/headless/daemon-service.js +0 -318
  36. package/dist/headless/hook-actions.js +0 -235
  37. package/dist/headless/hook-service.js +0 -42
  38. package/dist/headless/kernel-services.js +0 -216
  39. package/dist/headless/kernel.js +0 -785
  40. package/dist/headless/operations/arion.js +0 -119
  41. package/dist/headless/operations/auth.js +0 -45
  42. package/dist/headless/operations/client.js +0 -31
  43. package/dist/headless/operations/config.js +0 -69
  44. package/dist/headless/operations/daemon.js +0 -47
  45. package/dist/headless/operations/hook.js +0 -56
  46. package/dist/headless/operations/index.js +0 -11
  47. package/dist/headless/operations/memory.js +0 -102
  48. package/dist/headless/operations/message.js +0 -279
  49. package/dist/headless/operations/model.js +0 -100
  50. package/dist/headless/operations/peer.js +0 -56
  51. package/dist/headless/operations/run.js +0 -24
  52. package/dist/headless/operations/session.js +0 -90
  53. package/dist/headless/operations/system.js +0 -19
  54. package/dist/headless/operations/utils.js +0 -35
  55. package/dist/headless/run-orchestrator.js +0 -703
  56. package/dist/headless/stdio-server.js +0 -439
  57. package/dist/history/SessionHistory.js +0 -8
  58. package/dist/history/SessionHistoryClient.js +0 -186
  59. package/dist/history/conversation-message.js +0 -112
  60. package/dist/history/index.js +0 -8
  61. package/dist/history/jsonl-replay.js +0 -154
  62. package/dist/history/repair-tool-pairing.js +0 -84
  63. package/dist/history/stall-phase-bridge.js +0 -11
  64. package/dist/history/turn-accumulator.js +0 -427
  65. package/dist/index.js +0 -7
  66. package/dist/ink-repl.js +0 -4183
  67. package/dist/local-control-bootstrap.js +0 -26
  68. package/dist/local-control-client.js +0 -2
  69. package/dist/local-control-error-reporting.js +0 -34
  70. package/dist/local-control-http-client.js +0 -362
  71. package/dist/local-control-lazy-wrapper.js +0 -363
  72. package/dist/local-control-manager.js +0 -146
  73. package/dist/main.js +0 -62
  74. package/dist/network-security.js +0 -62
  75. package/dist/networking-server.js +0 -38
  76. package/dist/peer-identity.js +0 -23
  77. package/dist/polling-subscription.js +0 -34
  78. package/dist/relaunch.js +0 -617
  79. package/dist/release-notes.js +0 -35
  80. package/dist/repl-cleanup.js +0 -47
  81. package/dist/runtime/configure-bun-sqlite.js +0 -3
  82. package/dist/runtime/crash-handlers.js +0 -111
  83. package/dist/runtime/interactive-invocation.js +0 -39
  84. package/dist/runtime/internal-mode.js +0 -14
  85. package/dist/runtime/launch-spec.js +0 -64
  86. package/dist/runtime/owner-lease.js +0 -44
  87. package/dist/runtime/public-mode.js +0 -20
  88. package/dist/runtime/run-internal-mode.js +0 -18
  89. package/dist/runtime/runtime-kind.js +0 -32
  90. package/dist/runtime/spawn-aria.js +0 -38
  91. package/dist/selectable-client.js +0 -2
  92. package/dist/selectable-peer.js +0 -2
  93. package/dist/session.js +0 -203
  94. package/dist/slash-commands.js +0 -80
  95. package/dist/sounds.js +0 -210
  96. package/dist/ui/App.js +0 -526
  97. package/dist/ui/components/AnthropicMethodPicker.js +0 -6
  98. package/dist/ui/components/ArionPrompt.js +0 -15
  99. package/dist/ui/components/AutocompleteDropdown.js +0 -23
  100. package/dist/ui/components/AutonomySelector.js +0 -55
  101. package/dist/ui/components/Banner.js +0 -98
  102. package/dist/ui/components/ConversationHistory.js +0 -175
  103. package/dist/ui/components/CopilotDeviceLoginFlow.js +0 -88
  104. package/dist/ui/components/CopilotSourcePicker.js +0 -50
  105. package/dist/ui/components/Cost.js +0 -10
  106. package/dist/ui/components/CustomSelect/option-map.js +0 -30
  107. package/dist/ui/components/CustomSelect/select-option.js +0 -13
  108. package/dist/ui/components/CustomSelect/select.js +0 -42
  109. package/dist/ui/components/CustomSelect/use-select-state.js +0 -179
  110. package/dist/ui/components/CustomSelect/use-select.js +0 -15
  111. package/dist/ui/components/ErrorDisplay.js +0 -35
  112. package/dist/ui/components/FallbackToolUseRejectedMessage.js +0 -7
  113. package/dist/ui/components/FileEditToolUpdatedMessage.js +0 -57
  114. package/dist/ui/components/HandoffMarker.js +0 -18
  115. package/dist/ui/components/HighlightedCode.js +0 -21
  116. package/dist/ui/components/InputArea.js +0 -187
  117. package/dist/ui/components/Message.js +0 -25
  118. package/dist/ui/components/OAuthLoginFlow.js +0 -113
  119. package/dist/ui/components/OutputTruncation.js +0 -35
  120. package/dist/ui/components/PermissionPrompt.js +0 -79
  121. package/dist/ui/components/PipelineTimingPanel.js +0 -15
  122. package/dist/ui/components/ProviderMethodPicker.js +0 -61
  123. package/dist/ui/components/ProviderPicker.js +0 -63
  124. package/dist/ui/components/RenderItemView.js +0 -71
  125. package/dist/ui/components/Spinner.js +0 -46
  126. package/dist/ui/components/StatusBar.js +0 -95
  127. package/dist/ui/components/StreamingIndicator.js +0 -55
  128. package/dist/ui/components/StructuredDiff.js +0 -168
  129. package/dist/ui/components/TextInputOverlay.js +0 -43
  130. package/dist/ui/components/ThinkingBlock.js +0 -82
  131. package/dist/ui/components/ToolCost.js +0 -17
  132. package/dist/ui/components/ToolExecution.js +0 -61
  133. package/dist/ui/components/ToolHeader.js +0 -51
  134. package/dist/ui/components/ToolRenderLayoutContext.js +0 -14
  135. package/dist/ui/components/ToolResultWrapper.js +0 -6
  136. package/dist/ui/components/ToolUseLoader.js +0 -35
  137. package/dist/ui/components/TraceWaterfall.js +0 -91
  138. package/dist/ui/components/index.js +0 -33
  139. package/dist/ui/components/messages/AssistantTextMessage.js +0 -25
  140. package/dist/ui/components/messages/UserImageMessage.js +0 -12
  141. package/dist/ui/components/messages/UserTextMessage.js +0 -12
  142. package/dist/ui/components/overlays/ArionSelector.js +0 -68
  143. package/dist/ui/components/overlays/ClientSelector.js +0 -62
  144. package/dist/ui/components/overlays/CommandPalette.js +0 -67
  145. package/dist/ui/components/overlays/DaemonControl.js +0 -87
  146. package/dist/ui/components/overlays/InviteShareOverlay.js +0 -15
  147. package/dist/ui/components/overlays/JoinInviteOverlay.js +0 -32
  148. package/dist/ui/components/overlays/MemoryBrowser.js +0 -100
  149. package/dist/ui/components/overlays/MessageSelector.js +0 -123
  150. package/dist/ui/components/overlays/ModelSelector.js +0 -211
  151. package/dist/ui/components/overlays/PairRequestOverlay.js +0 -42
  152. package/dist/ui/components/overlays/PeerSelector.js +0 -84
  153. package/dist/ui/components/overlays/SessionSelector.js +0 -102
  154. package/dist/ui/components/overlays/SoundSelector.js +0 -86
  155. package/dist/ui/components/overlays/ThemeSelector.js +0 -139
  156. package/dist/ui/components/overlays/index.js +0 -15
  157. package/dist/ui/components/permissions/BashPermissionRequest/BashPermissionRequest.js +0 -53
  158. package/dist/ui/components/permissions/FallbackPermissionRequest.js +0 -56
  159. package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +0 -76
  160. package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js +0 -18
  161. package/dist/ui/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +0 -64
  162. package/dist/ui/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +0 -26
  163. package/dist/ui/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +0 -141
  164. package/dist/ui/components/permissions/PermissionRequest.js +0 -70
  165. package/dist/ui/components/permissions/PermissionRequestTitle.js +0 -41
  166. package/dist/ui/components/permissions/hooks.js +0 -10
  167. package/dist/ui/components/permissions/toolUseOptions.js +0 -68
  168. package/dist/ui/components/permissions/utils.js +0 -10
  169. package/dist/ui/components/text-input/Cursor.js +0 -326
  170. package/dist/ui/components/text-input/TextInput.js +0 -231
  171. package/dist/ui/components/text-input/imagePaste.js +0 -28
  172. package/dist/ui/components/text-input/index.js +0 -6
  173. package/dist/ui/components/text-input/useDoublePress.js +0 -30
  174. package/dist/ui/components/text-input/useTextInput.js +0 -245
  175. package/dist/ui/components/tool-types.js +0 -9
  176. package/dist/ui/constants/figures.js +0 -4
  177. package/dist/ui/constants/index.js +0 -3
  178. package/dist/ui/display-mode.js +0 -93
  179. package/dist/ui/display-policy.js +0 -19
  180. package/dist/ui/hooks/index.js +0 -6
  181. package/dist/ui/hooks/useCommandAutocomplete.js +0 -93
  182. package/dist/ui/hooks/useDoublePress.js +0 -37
  183. package/dist/ui/hooks/useIndicatorState.js +0 -55
  184. package/dist/ui/hooks/useInterval.js +0 -23
  185. package/dist/ui/hooks/useKeyboardShortcuts.js +0 -127
  186. package/dist/ui/hooks/useTerminalSize.js +0 -55
  187. package/dist/ui/hooks/useUnifiedMessages.js +0 -117
  188. package/dist/ui/indicator-state.js +0 -44
  189. package/dist/ui/markdown/highlight.js +0 -44
  190. package/dist/ui/markdown/index.js +0 -1460
  191. package/dist/ui/markdown/tokenizer.js +0 -24
  192. package/dist/ui/render-item.js +0 -5
  193. package/dist/ui/screens/REPL.js +0 -119
  194. package/dist/ui/screens/approval-lifecycle.js +0 -38
  195. package/dist/ui/status-line.js +0 -72
  196. package/dist/ui/theme/index.js +0 -51
  197. package/dist/ui/theme/themes/claude-dark-daltonized.js +0 -51
  198. package/dist/ui/theme/themes/claude-dark.js +0 -50
  199. package/dist/ui/theme/themes/claude-light-daltonized.js +0 -51
  200. package/dist/ui/theme/themes/claude-light.js +0 -50
  201. package/dist/ui/theme/themes/dark-accessible.js +0 -18
  202. package/dist/ui/theme/themes/dark.js +0 -49
  203. package/dist/ui/theme/themes/light-accessible.js +0 -18
  204. package/dist/ui/theme/themes/light.js +0 -49
  205. package/dist/ui/theme/types.js +0 -3
  206. package/dist/ui/theme.js +0 -142
  207. package/dist/ui/to-render-items.js +0 -145
  208. package/dist/ui/tools/AgentTool/index.js +0 -30
  209. package/dist/ui/tools/ArchitectTool/index.js +0 -31
  210. package/dist/ui/tools/AskUserTool/index.js +0 -46
  211. package/dist/ui/tools/BashTool/BashToolResultMessage.js +0 -11
  212. package/dist/ui/tools/BashTool/OutputLine.js +0 -21
  213. package/dist/ui/tools/BashTool/index.js +0 -91
  214. package/dist/ui/tools/BrowseTool/index.js +0 -43
  215. package/dist/ui/tools/BrowserTool/index.js +0 -47
  216. package/dist/ui/tools/CbmTool/index.js +0 -188
  217. package/dist/ui/tools/CheckDelegationTool/index.js +0 -46
  218. package/dist/ui/tools/CheckMessagesTool/index.js +0 -85
  219. package/dist/ui/tools/CreateQuipTool/index.js +0 -30
  220. package/dist/ui/tools/CreateSkillTool/index.js +0 -22
  221. package/dist/ui/tools/CreateToolTool/index.js +0 -31
  222. package/dist/ui/tools/DelegateRemoteTool/index.js +0 -42
  223. package/dist/ui/tools/DeployTool/index.js +0 -47
  224. package/dist/ui/tools/FffTool/index.js +0 -103
  225. package/dist/ui/tools/FileEditTool/index.js +0 -67
  226. package/dist/ui/tools/FileReadTool/index.js +0 -68
  227. package/dist/ui/tools/FileWriteTool/index.js +0 -61
  228. package/dist/ui/tools/ForkTool/index.js +0 -47
  229. package/dist/ui/tools/FrgTool/index.js +0 -96
  230. package/dist/ui/tools/GetThreadTool/index.js +0 -39
  231. package/dist/ui/tools/GlobTool/index.js +0 -50
  232. package/dist/ui/tools/GrepTool/index.js +0 -84
  233. package/dist/ui/tools/HatchArionTool/index.js +0 -36
  234. package/dist/ui/tools/LearnSkillTool/index.js +0 -22
  235. package/dist/ui/tools/LearnTool/index.js +0 -43
  236. package/dist/ui/tools/LearnToolTool/index.js +0 -22
  237. package/dist/ui/tools/ListClientsTool/index.js +0 -39
  238. package/dist/ui/tools/LspTool/index.js +0 -261
  239. package/dist/ui/tools/MCPTool/index.js +0 -33
  240. package/dist/ui/tools/ManageNetworkTool/index.js +0 -53
  241. package/dist/ui/tools/MemoryReadTool/index.js +0 -64
  242. package/dist/ui/tools/MemoryWriteTool/index.js +0 -20
  243. package/dist/ui/tools/NotebookEditTool/index.js +0 -33
  244. package/dist/ui/tools/NotebookReadTool/index.js +0 -25
  245. package/dist/ui/tools/OutlookReadTool/index.js +0 -66
  246. package/dist/ui/tools/OutlookReplyTool/index.js +0 -49
  247. package/dist/ui/tools/OutlookSendTool/index.js +0 -49
  248. package/dist/ui/tools/PauseDelegationTool/index.js +0 -35
  249. package/dist/ui/tools/ProbeTool/index.js +0 -121
  250. package/dist/ui/tools/ProcessTool/index.js +0 -66
  251. package/dist/ui/tools/QuestListTool/index.js +0 -46
  252. package/dist/ui/tools/QuestReportTool/index.js +0 -49
  253. package/dist/ui/tools/QuestUpdateTool/index.js +0 -87
  254. package/dist/ui/tools/QuipCommentTool/index.js +0 -69
  255. package/dist/ui/tools/QuipReadTool/index.js +0 -71
  256. package/dist/ui/tools/RestArionTool/index.js +0 -32
  257. package/dist/ui/tools/RestartTool/index.js +0 -35
  258. package/dist/ui/tools/ResumeDelegationTool/index.js +0 -35
  259. package/dist/ui/tools/RetireArionTool/index.js +0 -32
  260. package/dist/ui/tools/RgTool/index.js +0 -73
  261. package/dist/ui/tools/SearchKnowledgeTool/index.js +0 -43
  262. package/dist/ui/tools/SearchMessagesTool/index.js +0 -43
  263. package/dist/ui/tools/SelfDiagnoseTool/index.js +0 -61
  264. package/dist/ui/tools/SendMessageTool/index.js +0 -45
  265. package/dist/ui/tools/SerenaTool/index.js +0 -124
  266. package/dist/ui/tools/SessionHistoryTool/index.js +0 -52
  267. package/dist/ui/tools/SgTool/index.js +0 -80
  268. package/dist/ui/tools/SlackReactTool/index.js +0 -41
  269. package/dist/ui/tools/SlackReadTool/index.js +0 -48
  270. package/dist/ui/tools/SlackSendTool/index.js +0 -45
  271. package/dist/ui/tools/SpawnWorkerTool/index.js +0 -33
  272. package/dist/ui/tools/StickerRequestTool/index.js +0 -19
  273. package/dist/ui/tools/ThinkTool/index.js +0 -17
  274. package/dist/ui/tools/UgTool/index.js +0 -108
  275. package/dist/ui/tools/UseSkillTool/index.js +0 -22
  276. package/dist/ui/tools/WakeArionTool/index.js +0 -32
  277. package/dist/ui/tools/WebFetchTool/index.js +0 -56
  278. package/dist/ui/tools/WebSearchTool/index.js +0 -44
  279. package/dist/ui/tools/lsTool/index.js +0 -58
  280. package/dist/ui/tools/registry.js +0 -197
  281. package/dist/ui/tools/tool-renderer.js +0 -11
  282. package/dist/ui/tools/truncation.js +0 -35
  283. package/dist/ui/types/anthropic.js +0 -4
  284. package/dist/ui/types/index.js +0 -2
  285. package/dist/ui/types/message.js +0 -3
  286. package/dist/ui/types/tool.js +0 -4
  287. package/dist/ui/utils/array.js +0 -4
  288. package/dist/ui/utils/cursor.js +0 -131
  289. package/dist/ui/utils/diff.js +0 -120
  290. package/dist/ui/utils/format.js +0 -42
  291. package/dist/ui/utils/fuzzy.js +0 -59
  292. package/dist/ui/utils/index.js +0 -11
  293. package/dist/ui/utils/keys.js +0 -8
  294. package/dist/ui/utils/patch.js +0 -17
  295. package/dist/ui/utils/risk.js +0 -114
  296. package/dist/ui/utils/terminal-image.js +0 -70
  297. package/dist/ui/utils/validation.js +0 -48
  298. package/dist/ui/verb-pairs.js +0 -248
  299. package/dist/ui.js +0 -131
  300. package/src/entrypoints/command-mode.ts +0 -5
  301. package/src/entrypoints/daemon.ts +0 -54
  302. package/src/entrypoints/headless-stdio.ts +0 -27
  303. package/src/entrypoints/interactive.ts +0 -112
  304. package/src/main.ts +0 -72
  305. package/src/runtime/configure-bun-sqlite.ts +0 -3
  306. package/src/runtime/crash-handlers.ts +0 -128
  307. package/src/runtime/interactive-invocation.test.ts +0 -42
  308. package/src/runtime/interactive-invocation.ts +0 -51
  309. package/src/runtime/internal-mode.test.ts +0 -19
  310. package/src/runtime/internal-mode.ts +0 -24
  311. package/src/runtime/launch-spec.test.ts +0 -26
  312. package/src/runtime/launch-spec.ts +0 -84
  313. package/src/runtime/owner-lease.ts +0 -52
  314. package/src/runtime/public-mode.test.ts +0 -18
  315. package/src/runtime/public-mode.ts +0 -19
  316. package/src/runtime/run-internal-mode.ts +0 -19
  317. package/src/runtime/runtime-kind.test.ts +0 -23
  318. package/src/runtime/runtime-kind.ts +0 -41
  319. package/src/runtime/spawn-aria.ts +0 -62
@@ -1,427 +0,0 @@
1
- /**
2
- * TurnAccumulator — ingests RunEvent stream events and accumulates them into
3
- * ConversationMessage[] for batch persistence and rendering.
4
- *
5
- * Key behaviors:
6
- * - text_delta → single text block on assistant message
7
- * - thinking_start/delta/end → thinking block with durationMs, verb, content
8
- * - tool_start → tool_use block (deduped via seenToolIds Set)
9
- * - tool_args_delta → progressive JSON accumulation on tool_use arguments
10
- * - tool_result → SEPARATE ConversationMessage with role="tool"
11
- * - handoff_start/result → handoff blocks
12
- * - messages_snapshot → stored for getSnapshotMessages()
13
- * - turn_complete → returns "flush" signal
14
- * - Unknown event types → returns "continue" (default case)
15
- * - No error case — event loop throws before accumulator sees errors
16
- */
17
- export class TurnAccumulator {
18
- // --- Accumulated state ---
19
- textParts = [];
20
- thinkingBlocks = [];
21
- toolUseBlocks = [];
22
- handoffBlocks = [];
23
- toolResultMessages = [];
24
- // Dedup tool_start events
25
- seenToolIds = new Set();
26
- // Progressive JSON accumulation for tool_args_delta
27
- toolArgsAccumulator = new Map();
28
- // Thinking accumulation (for abort flush of partial thinking)
29
- thinkingInProgress = false;
30
- pendingThinkingContent = "";
31
- // Metadata
32
- arion;
33
- verb;
34
- tokenUsage;
35
- // Snapshot messages
36
- snapshotMessages;
37
- // Stable preview ID for snapshot messages (React reconciliation)
38
- previewAssistantId = `preview-${Date.now()}`;
39
- // --- Public API ---
40
- ingest(event) {
41
- switch (event.type) {
42
- case "text_delta":
43
- this.textParts.push(event.content);
44
- return "continue";
45
- case "thinking_start":
46
- this.thinkingInProgress = true;
47
- this.pendingThinkingContent = "";
48
- return "continue";
49
- case "thinking_delta":
50
- this.pendingThinkingContent += event.content;
51
- return "continue";
52
- case "thinking_end": {
53
- this.thinkingInProgress = false;
54
- // Field mapping: event.blocks[0].thinking → content
55
- const firstBlock = Array.isArray(event.blocks) && event.blocks.length > 0
56
- ? event.blocks[0]
57
- : undefined;
58
- const thinking = typeof firstBlock?.thinking === "string"
59
- ? firstBlock.thinking
60
- : this.pendingThinkingContent;
61
- const words = thinking.split(/\s+/).filter(Boolean).length;
62
- const thinkingBlock = {
63
- type: "thinking",
64
- content: thinking,
65
- wordCount: words,
66
- durationMs: event.durationMs,
67
- verb: this.verb,
68
- };
69
- this.thinkingBlocks.push(thinkingBlock);
70
- this.pendingThinkingContent = "";
71
- return "continue";
72
- }
73
- case "tool_start": {
74
- // Dedup via seenToolIds
75
- if (this.seenToolIds.has(event.id)) {
76
- return "continue";
77
- }
78
- this.seenToolIds.add(event.id);
79
- // Field mapping: event.input → arguments
80
- const toolUseBlock = {
81
- type: "tool_use",
82
- id: event.id,
83
- name: event.name,
84
- arguments: event.input ?? {},
85
- };
86
- this.toolUseBlocks.push(toolUseBlock);
87
- return "continue";
88
- }
89
- case "tool_args_delta": {
90
- // Progressive JSON accumulation
91
- const prev = this.toolArgsAccumulator.get(event.id) ?? "";
92
- const accumulated = prev + event.args;
93
- this.toolArgsAccumulator.set(event.id, accumulated);
94
- // Try to parse the accumulated JSON and update the tool_use block
95
- try {
96
- const parsed = JSON.parse(accumulated);
97
- const block = this.toolUseBlocks.find((b) => b.type === "tool_use" && b.id === event.id);
98
- if (block) {
99
- block.arguments = parsed;
100
- }
101
- }
102
- catch {
103
- // Not yet valid JSON — keep accumulating
104
- }
105
- return "continue";
106
- }
107
- case "tool_result": {
108
- // tool_result carries event.input — the tool's FULL arguments.
109
- // tool_start arrives WITHOUT input (args come via tool_args_delta or here).
110
- // Update the tool_use block with the authoritative args from tool_result.
111
- if (event.input) {
112
- const toolBlock = this.toolUseBlocks.find((b) => b.type === "tool_use" && b.id === event.id);
113
- if (toolBlock) {
114
- const args = typeof event.input === "object" && !Array.isArray(event.input)
115
- ? event.input
116
- : {};
117
- // Only update if current args are empty (from tool_start with no input)
118
- if (Object.keys(toolBlock.arguments).length === 0) {
119
- toolBlock.arguments = args;
120
- }
121
- }
122
- }
123
- // SEPARATE ConversationMessage per tool result
124
- // Field mapping: event.result.message → content, event.result.success → status
125
- const resultRecord = event.result;
126
- const toolUsage = "usage" in event &&
127
- event.usage &&
128
- typeof event.usage === "object" &&
129
- typeof event.usage.inputTokens === "number" &&
130
- typeof event.usage.outputTokens === "number" &&
131
- typeof event.usage.totalTokens === "number" &&
132
- typeof event.usage.estimatedCost === "number"
133
- ? event.usage
134
- : undefined;
135
- const toolResultBlock = {
136
- type: "tool_result",
137
- toolUseId: event.id,
138
- content: typeof resultRecord.message === "string" ? resultRecord.message : "",
139
- status: resultRecord.success === true ? "success" : "error",
140
- durationMs: event.durationMs,
141
- resultData: resultRecord.data,
142
- usage: toolUsage,
143
- };
144
- const resultMsg = {
145
- id: crypto.randomUUID(),
146
- role: "tool",
147
- content: [toolResultBlock],
148
- arion: this.arion,
149
- createdAt: new Date().toISOString(),
150
- };
151
- this.toolResultMessages.push(resultMsg);
152
- return "continue";
153
- }
154
- case "handoff_start": {
155
- const handoffToBlock = {
156
- type: "handoff",
157
- target: event.target,
158
- direction: "to",
159
- };
160
- this.handoffBlocks.push(handoffToBlock);
161
- return "continue";
162
- }
163
- case "handoff_result": {
164
- const handoffFromBlock = {
165
- type: "handoff",
166
- target: event.target,
167
- direction: "from",
168
- };
169
- this.handoffBlocks.push(handoffFromBlock);
170
- return "continue";
171
- }
172
- case "turn_complete":
173
- return "flush";
174
- case "messages_snapshot":
175
- this.snapshotMessages = event.messages;
176
- return "continue";
177
- default: {
178
- // Handle tool_end (not in RunEvent type but emitted by model-call.ts)
179
- // It carries args as a JSON string that updates the tool_use block
180
- // tool_end events are consumed by phase-model-call.ts and don't reach here.
181
- // Tool args arrive via tool_args_delta (incremental JSON) which is handled above.
182
- return "continue";
183
- }
184
- }
185
- }
186
- /**
187
- * Flush all accumulated content into ConversationMessage[].
188
- * Works anytime (including mid-accumulation for abort scenarios).
189
- * Resets all state after flush.
190
- */
191
- flush() {
192
- const messages = [];
193
- // Convert in-progress thinking to a partial block (abort mid-thinking)
194
- if (this.thinkingInProgress && this.pendingThinkingContent) {
195
- const trimmed = this.pendingThinkingContent.trim();
196
- const wordCount = trimmed.length === 0 ? 0 : trimmed.split(/\s+/).length;
197
- const partialThinking = {
198
- type: "thinking",
199
- content: this.pendingThinkingContent,
200
- wordCount,
201
- verb: this.verb,
202
- };
203
- this.thinkingBlocks.push(partialThinking);
204
- }
205
- // Build assistant message blocks
206
- const blocks = [];
207
- // Thinking blocks first
208
- blocks.push(...this.thinkingBlocks);
209
- // Text content
210
- const fullText = this.textParts.join("");
211
- if (fullText) {
212
- blocks.push({ type: "text", text: fullText });
213
- }
214
- // Tool use blocks — include all (even orphaned ones from abort)
215
- blocks.push(...this.toolUseBlocks);
216
- // Handoff blocks
217
- blocks.push(...this.handoffBlocks);
218
- // Only create assistant message if there's content
219
- if (blocks.length > 0) {
220
- const assistantMsg = {
221
- id: crypto.randomUUID(),
222
- role: "assistant",
223
- content: blocks,
224
- arion: this.arion,
225
- tokenUsage: this.tokenUsage,
226
- createdAt: new Date().toISOString(),
227
- };
228
- messages.push(assistantMsg);
229
- }
230
- // Tool result messages (separate ConversationMessage each)
231
- messages.push(...this.toolResultMessages);
232
- // Synthesize cancelled results for orphaned tool_use blocks (abort mid-tool).
233
- // Without matching tool_result messages, the model sees a tool call it made
234
- // but never got a response for — violating the message format invariant.
235
- // Only synthesize when some tool results exist (partial completion) to avoid
236
- // false positives during early abort or normal flush of tool_start-only state.
237
- if (this.toolResultMessages.length > 0 && this.toolUseBlocks.length > 0) {
238
- const resultToolIds = new Set(this.toolResultMessages.flatMap((m) => m.content
239
- .filter((b) => b.type === "tool_result")
240
- .map((b) => b.toolUseId)));
241
- for (const block of this.toolUseBlocks) {
242
- const toolUseId = block.id;
243
- if (toolUseId && !resultToolIds.has(toolUseId)) {
244
- const cancelledResult = {
245
- id: crypto.randomUUID(),
246
- role: "tool",
247
- content: [
248
- {
249
- type: "tool_result",
250
- toolUseId,
251
- content: "Tool execution cancelled by user.",
252
- status: "error",
253
- },
254
- ],
255
- arion: this.arion,
256
- createdAt: new Date().toISOString(),
257
- };
258
- messages.push(cancelledResult);
259
- }
260
- }
261
- }
262
- // Reset all state (arion is NOT reset — it's per-session, not per-turn)
263
- this.textParts = [];
264
- this.thinkingBlocks = [];
265
- this.toolUseBlocks = [];
266
- this.handoffBlocks = [];
267
- this.toolResultMessages = [];
268
- this.seenToolIds = new Set();
269
- this.toolArgsAccumulator = new Map();
270
- this.thinkingInProgress = false;
271
- this.pendingThinkingContent = "";
272
- this.tokenUsage = undefined;
273
- this.verb = undefined;
274
- this.previewAssistantId = `preview-${Date.now()}`;
275
- return messages;
276
- }
277
- /**
278
- * Returns a read-only view of current accumulated state as ConversationMessage[].
279
- * Does NOT reset state (unlike flush). Used for intermediate rendering.
280
- * Includes in-progress thinking content and progressive text content.
281
- */
282
- snapshot() {
283
- const blocks = [];
284
- // Completed thinking blocks
285
- blocks.push(...this.thinkingBlocks.map((b) => ({ ...b })));
286
- // In-progress thinking (streaming)
287
- if (this.thinkingInProgress && this.pendingThinkingContent) {
288
- const content = this.pendingThinkingContent;
289
- const partialThinking = {
290
- type: "thinking",
291
- content,
292
- wordCount: content.split(/\s+/).filter(Boolean).length,
293
- verb: this.verb,
294
- };
295
- blocks.push(partialThinking);
296
- }
297
- // Text content — render complete lines only (not token-by-token).
298
- // Buffer text until a line break (\n) so the UI shows text in meaningful
299
- // chunks. Prose paragraphs have no internal \n so they appear as whole
300
- // blocks; code appears line by line; list items appear individually.
301
- // No length fallback — partial lines are exactly the token-by-token
302
- // growth we're eliminating. flush() at turn end returns everything.
303
- const fullText = this.textParts.join("");
304
- if (fullText) {
305
- const lastLineBreak = fullText.lastIndexOf("\n");
306
- if (lastLineBreak >= 0) {
307
- blocks.push({ type: "text", text: fullText.slice(0, lastLineBreak + 1) });
308
- }
309
- }
310
- // Tool use blocks — enriched with partially-parsed args from streaming.
311
- // The execution path (flush) needs complete JSON to dispatch tools.
312
- // The display path (snapshot) needs whatever info is available for the UI.
313
- // We bridge this gap by trying to parse incomplete JSON from the accumulator.
314
- for (const b of this.toolUseBlocks) {
315
- const clone = { ...b };
316
- if (clone.type === "tool_use" &&
317
- Object.keys(clone.arguments).length === 0) {
318
- const rawArgs = this.toolArgsAccumulator.get(clone.id);
319
- if (rawArgs) {
320
- const partial = TurnAccumulator.tryParsePartialArgs(rawArgs);
321
- if (partial) {
322
- clone.arguments = partial;
323
- }
324
- }
325
- }
326
- blocks.push(clone);
327
- }
328
- // Handoff blocks
329
- blocks.push(...this.handoffBlocks.map((b) => ({ ...b })));
330
- const messages = [];
331
- if (blocks.length > 0) {
332
- messages.push({
333
- id: this.previewAssistantId,
334
- role: "assistant",
335
- content: blocks,
336
- arion: this.arion,
337
- createdAt: new Date().toISOString(),
338
- });
339
- }
340
- // Tool result messages (clone to prevent mutation leaking)
341
- messages.push(...this.toolResultMessages.map((m) => ({ ...m, content: [...m.content] })));
342
- return messages;
343
- }
344
- /** Get snapshot messages from the most recent messages_snapshot event */
345
- getSnapshotMessages() {
346
- return this.snapshotMessages;
347
- }
348
- /** Whether there is any pending content that would produce messages on flush */
349
- hasPendingContent() {
350
- return (this.textParts.length > 0 ||
351
- this.thinkingBlocks.length > 0 ||
352
- this.toolUseBlocks.length > 0 ||
353
- this.handoffBlocks.length > 0 ||
354
- this.toolResultMessages.length > 0 ||
355
- this.thinkingInProgress);
356
- }
357
- /** Set the arion reference — propagated to all flushed messages */
358
- setArion(arion) {
359
- this.arion = arion;
360
- }
361
- /** Set the composing verb — used in thinking blocks */
362
- setVerb(verb) {
363
- this.verb = verb;
364
- }
365
- /** Accumulate token usage — attached to assistant message on flush */
366
- setTokenUsage(usage) {
367
- if (this.tokenUsage) {
368
- this.tokenUsage = {
369
- input: this.tokenUsage.input + usage.input,
370
- output: this.tokenUsage.output + usage.output,
371
- };
372
- }
373
- else {
374
- this.tokenUsage = { ...usage };
375
- }
376
- }
377
- /**
378
- * Parse a partial JSON object string by trying progressive closings.
379
- * Used in snapshot() to extract displayable args from in-progress tool arg streaming.
380
- *
381
- * Strategy (ordered by information preserved):
382
- * 1. Complete parse (fast path — JSON already valid)
383
- * 2. Close object with '}' (last value complete, just needs brace)
384
- * 3. Close string + object with '"}' (last string value incomplete)
385
- * 4. Scan backward for commas — truncate to last complete pair + close
386
- *
387
- * Returns undefined when no useful partial extraction is possible.
388
- */
389
- static tryParsePartialArgs(raw) {
390
- const s = raw.trim();
391
- if (!s.startsWith("{") || s.length < 4)
392
- return undefined;
393
- // Fast path: already complete JSON
394
- try {
395
- return JSON.parse(s);
396
- }
397
- catch { }
398
- // Close object — handles: '{"command": "ls -la"' → + '}'
399
- try {
400
- const result = JSON.parse(s + "}");
401
- if (Object.keys(result).length > 0)
402
- return result;
403
- }
404
- catch { }
405
- // Close incomplete string value + object — handles: '{"command": "ls' → + '"}'
406
- try {
407
- const result = JSON.parse(s + '"}');
408
- if (Object.keys(result).length > 0)
409
- return result;
410
- }
411
- catch { }
412
- // Drop incomplete trailing pair: scan backward for commas, close at last complete pair.
413
- // Handles: '{"file_path": "/src/foo.ts", "content": "imp' → truncate → '{"file_path": "/src/foo.ts"}'
414
- for (let i = s.length - 1; i > 0; i--) {
415
- if (s[i] === ",") {
416
- try {
417
- const result = JSON.parse(s.slice(0, i) + "}");
418
- if (Object.keys(result).length > 0)
419
- return result;
420
- }
421
- catch { }
422
- }
423
- }
424
- return undefined;
425
- }
426
- }
427
- //# sourceMappingURL=turn-accumulator.js.map
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * @aria/cli - Simple chat interface for ARIA
3
- */
4
- export { SessionHistory } from "./history/SessionHistory.js";
5
- export { startInkRepl, startInkRepl as startRepl } from "./ink-repl.js";
6
- export { program, createArionsCommand, createAuthCommand } from "./commands/index.js";
7
- //# sourceMappingURL=index.js.map