@armadra/agent 0.0.0-stage → 0.3.0

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 (433) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +470 -2
  4. package/dist/agent/agent.d.ts +56 -0
  5. package/dist/agent/agent.js +129 -0
  6. package/dist/agent/loop.d.ts +51 -0
  7. package/dist/agent/loop.js +158 -0
  8. package/dist/agent/queue.d.ts +25 -0
  9. package/dist/agent/queue.js +55 -0
  10. package/dist/agent/retry.d.ts +22 -0
  11. package/dist/agent/retry.js +92 -0
  12. package/dist/agent/schema.d.ts +27 -0
  13. package/dist/agent/schema.js +186 -0
  14. package/dist/agent/session-cache.d.ts +100 -0
  15. package/dist/agent/session-cache.js +514 -0
  16. package/dist/agent/session-compaction.d.ts +49 -0
  17. package/dist/agent/session-compaction.js +251 -0
  18. package/dist/agent/session-core.d.ts +103 -0
  19. package/dist/agent/session-core.js +7 -0
  20. package/dist/agent/session-run.d.ts +55 -0
  21. package/dist/agent/session-run.js +246 -0
  22. package/dist/agent/session-state.d.ts +39 -0
  23. package/dist/agent/session-state.js +119 -0
  24. package/dist/agent/session-subagent.d.ts +54 -0
  25. package/dist/agent/session-subagent.js +157 -0
  26. package/dist/agent/session-sync.d.ts +20 -0
  27. package/dist/agent/session-sync.js +111 -0
  28. package/dist/agent/session-tools.d.ts +24 -0
  29. package/dist/agent/session-tools.js +277 -0
  30. package/dist/agent/session.d.ts +117 -0
  31. package/dist/agent/session.js +485 -0
  32. package/dist/agent/system-prompt.d.ts +49 -0
  33. package/dist/agent/system-prompt.js +121 -0
  34. package/dist/agent/tool-runner.d.ts +64 -0
  35. package/dist/agent/tool-runner.js +309 -0
  36. package/dist/agent/transform.d.ts +26 -0
  37. package/dist/agent/transform.js +171 -0
  38. package/dist/agent/types.d.ts +378 -0
  39. package/dist/agent/types.js +21 -0
  40. package/dist/ai/apis/anthropic-messages.d.ts +26 -0
  41. package/dist/ai/apis/anthropic-messages.js +214 -0
  42. package/dist/ai/apis/anthropic-request.d.ts +42 -0
  43. package/dist/ai/apis/anthropic-request.js +282 -0
  44. package/dist/ai/apis/api.d.ts +28 -0
  45. package/dist/ai/apis/api.js +102 -0
  46. package/dist/ai/apis/cache-params.d.ts +48 -0
  47. package/dist/ai/apis/cache-params.js +163 -0
  48. package/dist/ai/apis/google-generative-ai.d.ts +32 -0
  49. package/dist/ai/apis/google-generative-ai.js +249 -0
  50. package/dist/ai/apis/google-request.d.ts +40 -0
  51. package/dist/ai/apis/google-request.js +255 -0
  52. package/dist/ai/apis/openai-compat.d.ts +35 -0
  53. package/dist/ai/apis/openai-compat.js +142 -0
  54. package/dist/ai/apis/openai-completions.d.ts +28 -0
  55. package/dist/ai/apis/openai-completions.js +246 -0
  56. package/dist/ai/apis/openai-request.d.ts +35 -0
  57. package/dist/ai/apis/openai-request.js +303 -0
  58. package/dist/ai/apis/openai-responses-request.d.ts +52 -0
  59. package/dist/ai/apis/openai-responses-request.js +266 -0
  60. package/dist/ai/apis/openai-responses.d.ts +28 -0
  61. package/dist/ai/apis/openai-responses.js +304 -0
  62. package/dist/ai/apis/shared.d.ts +56 -0
  63. package/dist/ai/apis/shared.js +179 -0
  64. package/dist/ai/cache/economics.d.ts +24 -0
  65. package/dist/ai/cache/economics.js +69 -0
  66. package/dist/ai/cache/fingerprint.d.ts +17 -0
  67. package/dist/ai/cache/fingerprint.js +39 -0
  68. package/dist/ai/cache/miss.d.ts +49 -0
  69. package/dist/ai/cache/miss.js +96 -0
  70. package/dist/ai/cache/reporting.d.ts +39 -0
  71. package/dist/ai/cache/reporting.js +103 -0
  72. package/dist/ai/cache/types.d.ts +94 -0
  73. package/dist/ai/cache/types.js +19 -0
  74. package/dist/ai/cache/warmer.d.ts +94 -0
  75. package/dist/ai/cache/warmer.js +224 -0
  76. package/dist/ai/context.d.ts +35 -0
  77. package/dist/ai/context.js +114 -0
  78. package/dist/ai/cost.d.ts +21 -0
  79. package/dist/ai/cost.js +60 -0
  80. package/dist/ai/event-stream.d.ts +33 -0
  81. package/dist/ai/event-stream.js +101 -0
  82. package/dist/ai/fake/fake-provider.d.ts +68 -0
  83. package/dist/ai/fake/fake-provider.js +278 -0
  84. package/dist/ai/fake/fake-script.d.ts +69 -0
  85. package/dist/ai/fake/fake-script.js +142 -0
  86. package/dist/ai/http.d.ts +54 -0
  87. package/dist/ai/http.js +212 -0
  88. package/dist/ai/json-partial.d.ts +17 -0
  89. package/dist/ai/json-partial.js +243 -0
  90. package/dist/ai/overflow.d.ts +22 -0
  91. package/dist/ai/overflow.js +61 -0
  92. package/dist/ai/providers/auth.d.ts +71 -0
  93. package/dist/ai/providers/auth.js +202 -0
  94. package/dist/ai/providers/builtin.d.ts +23 -0
  95. package/dist/ai/providers/builtin.js +148 -0
  96. package/dist/ai/providers/catalog-data.d.ts +5 -0
  97. package/dist/ai/providers/catalog-data.js +19 -0
  98. package/dist/ai/providers/catalog.d.ts +28 -0
  99. package/dist/ai/providers/catalog.js +166 -0
  100. package/dist/ai/providers/channels.d.ts +51 -0
  101. package/dist/ai/providers/channels.js +96 -0
  102. package/dist/ai/providers/enrich.d.ts +34 -0
  103. package/dist/ai/providers/enrich.js +86 -0
  104. package/dist/ai/providers/models-dev-cache.d.ts +53 -0
  105. package/dist/ai/providers/models-dev-cache.js +147 -0
  106. package/dist/ai/providers/models-dev.d.ts +99 -0
  107. package/dist/ai/providers/models-dev.js +315 -0
  108. package/dist/ai/providers/registry.d.ts +114 -0
  109. package/dist/ai/providers/registry.js +458 -0
  110. package/dist/ai/sse.d.ts +32 -0
  111. package/dist/ai/sse.js +140 -0
  112. package/dist/ai/thinking.d.ts +42 -0
  113. package/dist/ai/thinking.js +101 -0
  114. package/dist/ai/types.d.ts +448 -0
  115. package/dist/ai/types.js +19 -0
  116. package/dist/bundle/ama-sandbox.cjs +324 -0
  117. package/dist/bundle/ama.cjs +27837 -0
  118. package/dist/bundle.d.ts +9 -0
  119. package/dist/bundle.js +15 -0
  120. package/dist/cli/args.d.ts +85 -0
  121. package/dist/cli/args.js +408 -0
  122. package/dist/cli/bootstrap.d.ts +18 -0
  123. package/dist/cli/bootstrap.js +399 -0
  124. package/dist/cli/compose-providers.d.ts +37 -0
  125. package/dist/cli/compose-providers.js +107 -0
  126. package/dist/cli/compose-session.d.ts +72 -0
  127. package/dist/cli/compose-session.js +370 -0
  128. package/dist/cli/compose-store.d.ts +24 -0
  129. package/dist/cli/compose-store.js +125 -0
  130. package/dist/cli/compose.d.ts +108 -0
  131. package/dist/cli/compose.js +221 -0
  132. package/dist/cli/default-model.d.ts +16 -0
  133. package/dist/cli/default-model.js +24 -0
  134. package/dist/cli/deps.d.ts +207 -0
  135. package/dist/cli/deps.js +12 -0
  136. package/dist/cli/exit-codes.d.ts +29 -0
  137. package/dist/cli/exit-codes.js +40 -0
  138. package/dist/cli/main.d.ts +27 -0
  139. package/dist/cli/main.js +177 -0
  140. package/dist/cli/runtime.d.ts +90 -0
  141. package/dist/cli/runtime.js +8 -0
  142. package/dist/cli/startup-screen.d.ts +15 -0
  143. package/dist/cli/startup-screen.js +56 -0
  144. package/dist/cli/startup-steps.d.ts +35 -0
  145. package/dist/cli/startup-steps.js +202 -0
  146. package/dist/cli/subcommands/auth.d.ts +12 -0
  147. package/dist/cli/subcommands/auth.js +91 -0
  148. package/dist/cli/subcommands/config.d.ts +53 -0
  149. package/dist/cli/subcommands/config.js +277 -0
  150. package/dist/cli/subcommands/context.d.ts +21 -0
  151. package/dist/cli/subcommands/context.js +42 -0
  152. package/dist/cli/subcommands/doctor.d.ts +11 -0
  153. package/dist/cli/subcommands/doctor.js +246 -0
  154. package/dist/cli/subcommands/init.d.ts +6 -0
  155. package/dist/cli/subcommands/init.js +22 -0
  156. package/dist/cli/subcommands/model-meta.d.ts +16 -0
  157. package/dist/cli/subcommands/model-meta.js +54 -0
  158. package/dist/cli/subcommands/models-cache-probe.d.ts +34 -0
  159. package/dist/cli/subcommands/models-cache-probe.js +190 -0
  160. package/dist/cli/subcommands/models-discover.d.ts +46 -0
  161. package/dist/cli/subcommands/models-discover.js +232 -0
  162. package/dist/cli/subcommands/models.d.ts +40 -0
  163. package/dist/cli/subcommands/models.js +152 -0
  164. package/dist/cli/subcommands/providers-list.d.ts +8 -0
  165. package/dist/cli/subcommands/providers-list.js +97 -0
  166. package/dist/cli/subcommands/providers-plan.d.ts +79 -0
  167. package/dist/cli/subcommands/providers-plan.js +215 -0
  168. package/dist/cli/subcommands/providers.d.ts +27 -0
  169. package/dist/cli/subcommands/providers.js +433 -0
  170. package/dist/cli/subcommands/sessions.d.ts +11 -0
  171. package/dist/cli/subcommands/sessions.js +100 -0
  172. package/dist/codemode/capability.d.ts +37 -0
  173. package/dist/codemode/capability.js +55 -0
  174. package/dist/codemode/declarations.d.ts +44 -0
  175. package/dist/codemode/declarations.js +111 -0
  176. package/dist/codemode/host-side.d.ts +59 -0
  177. package/dist/codemode/host-side.js +253 -0
  178. package/dist/codemode/modes.d.ts +23 -0
  179. package/dist/codemode/modes.js +40 -0
  180. package/dist/codemode/protocol.d.ts +91 -0
  181. package/dist/codemode/protocol.js +114 -0
  182. package/dist/codemode/sandbox-entry.d.ts +25 -0
  183. package/dist/codemode/sandbox-entry.js +323 -0
  184. package/dist/codemode/store.d.ts +26 -0
  185. package/dist/codemode/store.js +53 -0
  186. package/dist/codemode/tool.d.ts +105 -0
  187. package/dist/codemode/tool.js +283 -0
  188. package/dist/compaction/branch-summary.d.ts +30 -0
  189. package/dist/compaction/branch-summary.js +79 -0
  190. package/dist/compaction/breaker.d.ts +32 -0
  191. package/dist/compaction/breaker.js +65 -0
  192. package/dist/compaction/cut-point.d.ts +23 -0
  193. package/dist/compaction/cut-point.js +70 -0
  194. package/dist/compaction/estimate.d.ts +30 -0
  195. package/dist/compaction/estimate.js +114 -0
  196. package/dist/compaction/prune-tier.d.ts +31 -0
  197. package/dist/compaction/prune-tier.js +83 -0
  198. package/dist/compaction/serialize.d.ts +20 -0
  199. package/dist/compaction/serialize.js +115 -0
  200. package/dist/compaction/summarize-tier.d.ts +111 -0
  201. package/dist/compaction/summarize-tier.js +305 -0
  202. package/dist/config/auth-file.d.ts +39 -0
  203. package/dist/config/auth-file.js +92 -0
  204. package/dist/config/context-files.d.ts +30 -0
  205. package/dist/config/context-files.js +77 -0
  206. package/dist/config/init.d.ts +30 -0
  207. package/dist/config/init.js +92 -0
  208. package/dist/config/json-schema.d.ts +14 -0
  209. package/dist/config/json-schema.js +182 -0
  210. package/dist/config/load.d.ts +45 -0
  211. package/dist/config/load.js +97 -0
  212. package/dist/config/merge.d.ts +73 -0
  213. package/dist/config/merge.js +248 -0
  214. package/dist/config/paths.d.ts +38 -0
  215. package/dist/config/paths.js +108 -0
  216. package/dist/config/profile.d.ts +27 -0
  217. package/dist/config/profile.js +65 -0
  218. package/dist/config/schema.d.ts +34 -0
  219. package/dist/config/schema.js +476 -0
  220. package/dist/config/trust.d.ts +42 -0
  221. package/dist/config/trust.js +122 -0
  222. package/dist/config/types.d.ts +190 -0
  223. package/dist/config/types.js +29 -0
  224. package/dist/config/write.d.ts +10 -0
  225. package/dist/config/write.js +25 -0
  226. package/dist/errors.d.ts +28 -0
  227. package/dist/errors.js +30 -0
  228. package/dist/hooks/config.d.ts +49 -0
  229. package/dist/hooks/config.js +102 -0
  230. package/dist/hooks/dispatcher.d.ts +41 -0
  231. package/dist/hooks/dispatcher.js +104 -0
  232. package/dist/hooks/matcher.d.ts +22 -0
  233. package/dist/hooks/matcher.js +108 -0
  234. package/dist/hooks/protocol.d.ts +33 -0
  235. package/dist/hooks/protocol.js +240 -0
  236. package/dist/hooks/runner.d.ts +30 -0
  237. package/dist/hooks/runner.js +143 -0
  238. package/dist/hooks/types.d.ts +147 -0
  239. package/dist/hooks/types.js +20 -0
  240. package/dist/host/api-impl.d.ts +75 -0
  241. package/dist/host/api-impl.js +173 -0
  242. package/dist/host/loader.d.ts +31 -0
  243. package/dist/host/loader.js +147 -0
  244. package/dist/host/types.d.ts +169 -0
  245. package/dist/host/types.js +14 -0
  246. package/dist/host.d.ts +5 -0
  247. package/dist/host.js +4 -0
  248. package/dist/index.d.ts +41 -0
  249. package/dist/index.js +28 -0
  250. package/dist/modes/commands-core.d.ts +44 -0
  251. package/dist/modes/commands-core.js +171 -0
  252. package/dist/modes/image-input.d.ts +27 -0
  253. package/dist/modes/image-input.js +78 -0
  254. package/dist/modes/interactive/approval-dialog.d.ts +48 -0
  255. package/dist/modes/interactive/approval-dialog.js +202 -0
  256. package/dist/modes/interactive/commands.d.ts +41 -0
  257. package/dist/modes/interactive/commands.js +201 -0
  258. package/dist/modes/interactive/completion.d.ts +53 -0
  259. package/dist/modes/interactive/completion.js +157 -0
  260. package/dist/modes/interactive/interactive-mode.d.ts +46 -0
  261. package/dist/modes/interactive/interactive-mode.js +491 -0
  262. package/dist/modes/interactive/key-dispatch.d.ts +29 -0
  263. package/dist/modes/interactive/key-dispatch.js +107 -0
  264. package/dist/modes/interactive/line/line-editor.d.ts +50 -0
  265. package/dist/modes/interactive/line/line-editor.js +232 -0
  266. package/dist/modes/interactive/line/line-mode.d.ts +20 -0
  267. package/dist/modes/interactive/line/line-mode.js +218 -0
  268. package/dist/modes/interactive/line/line-render.d.ts +35 -0
  269. package/dist/modes/interactive/line/line-render.js +171 -0
  270. package/dist/modes/interactive/line/paste-state.d.ts +26 -0
  271. package/dist/modes/interactive/line/paste-state.js +72 -0
  272. package/dist/modes/interactive/message-view.d.ts +77 -0
  273. package/dist/modes/interactive/message-view.js +269 -0
  274. package/dist/modes/interactive/pickers.d.ts +42 -0
  275. package/dist/modes/interactive/pickers.js +115 -0
  276. package/dist/modes/interactive/startup-ui.d.ts +33 -0
  277. package/dist/modes/interactive/startup-ui.js +268 -0
  278. package/dist/modes/interactive/status-bar.d.ts +48 -0
  279. package/dist/modes/interactive/status-bar.js +139 -0
  280. package/dist/modes/interactive/tool-view.d.ts +95 -0
  281. package/dist/modes/interactive/tool-view.js +344 -0
  282. package/dist/modes/print/json-event.d.ts +15 -0
  283. package/dist/modes/print/json-event.js +39 -0
  284. package/dist/modes/print/print-mode.d.ts +17 -0
  285. package/dist/modes/print/print-mode.js +107 -0
  286. package/dist/modes/rpc/commands.d.ts +40 -0
  287. package/dist/modes/rpc/commands.js +263 -0
  288. package/dist/modes/rpc/jsonl.d.ts +16 -0
  289. package/dist/modes/rpc/jsonl.js +55 -0
  290. package/dist/modes/rpc/rpc-mode.d.ts +22 -0
  291. package/dist/modes/rpc/rpc-mode.js +153 -0
  292. package/dist/modes/session-report.d.ts +55 -0
  293. package/dist/modes/session-report.js +278 -0
  294. package/dist/modes/shared.d.ts +13 -0
  295. package/dist/modes/shared.js +52 -0
  296. package/dist/modes/startup-ui-text.d.ts +16 -0
  297. package/dist/modes/startup-ui-text.js +103 -0
  298. package/dist/permissions/broker.d.ts +47 -0
  299. package/dist/permissions/broker.js +107 -0
  300. package/dist/permissions/dangerous.d.ts +47 -0
  301. package/dist/permissions/dangerous.js +370 -0
  302. package/dist/permissions/pipeline.d.ts +51 -0
  303. package/dist/permissions/pipeline.js +181 -0
  304. package/dist/permissions/preview.d.ts +43 -0
  305. package/dist/permissions/preview.js +463 -0
  306. package/dist/permissions/rules.d.ts +58 -0
  307. package/dist/permissions/rules.js +249 -0
  308. package/dist/permissions/types.d.ts +100 -0
  309. package/dist/permissions/types.js +18 -0
  310. package/dist/rpc.d.ts +173 -0
  311. package/dist/rpc.js +13 -0
  312. package/dist/sdk.d.ts +98 -0
  313. package/dist/sdk.js +195 -0
  314. package/dist/session/manager.d.ts +70 -0
  315. package/dist/session/manager.js +278 -0
  316. package/dist/session/migrate.d.ts +19 -0
  317. package/dist/session/migrate.js +53 -0
  318. package/dist/session/projection.d.ts +50 -0
  319. package/dist/session/projection.js +184 -0
  320. package/dist/session/store.d.ts +47 -0
  321. package/dist/session/store.js +210 -0
  322. package/dist/session/tree.d.ts +21 -0
  323. package/dist/session/tree.js +88 -0
  324. package/dist/session/types.d.ts +201 -0
  325. package/dist/session/types.js +18 -0
  326. package/dist/skills/discover.d.ts +60 -0
  327. package/dist/skills/discover.js +160 -0
  328. package/dist/skills/expand.d.ts +35 -0
  329. package/dist/skills/expand.js +46 -0
  330. package/dist/skills/frontmatter.d.ts +27 -0
  331. package/dist/skills/frontmatter.js +157 -0
  332. package/dist/skills/index-prompt.d.ts +13 -0
  333. package/dist/skills/index-prompt.js +42 -0
  334. package/dist/skills/templates.d.ts +52 -0
  335. package/dist/skills/templates.js +177 -0
  336. package/dist/tools/bash.d.ts +49 -0
  337. package/dist/tools/bash.js +222 -0
  338. package/dist/tools/edit-fuzzy.d.ts +36 -0
  339. package/dist/tools/edit-fuzzy.js +129 -0
  340. package/dist/tools/edit.d.ts +38 -0
  341. package/dist/tools/edit.js +241 -0
  342. package/dist/tools/file-mutex.d.ts +8 -0
  343. package/dist/tools/file-mutex.js +29 -0
  344. package/dist/tools/glob.d.ts +44 -0
  345. package/dist/tools/glob.js +217 -0
  346. package/dist/tools/grep.d.ts +39 -0
  347. package/dist/tools/grep.js +179 -0
  348. package/dist/tools/ignore.d.ts +40 -0
  349. package/dist/tools/ignore.js +174 -0
  350. package/dist/tools/image-file.d.ts +31 -0
  351. package/dist/tools/image-file.js +114 -0
  352. package/dist/tools/ls.d.ts +21 -0
  353. package/dist/tools/ls.js +96 -0
  354. package/dist/tools/output-accumulator.d.ts +48 -0
  355. package/dist/tools/output-accumulator.js +106 -0
  356. package/dist/tools/paths.d.ts +20 -0
  357. package/dist/tools/paths.js +58 -0
  358. package/dist/tools/presets.d.ts +71 -0
  359. package/dist/tools/presets.js +128 -0
  360. package/dist/tools/process-tree.d.ts +35 -0
  361. package/dist/tools/process-tree.js +125 -0
  362. package/dist/tools/read.d.ts +24 -0
  363. package/dist/tools/read.js +132 -0
  364. package/dist/tools/registry.d.ts +43 -0
  365. package/dist/tools/registry.js +106 -0
  366. package/dist/tools/shell.d.ts +38 -0
  367. package/dist/tools/shell.js +91 -0
  368. package/dist/tools/task.d.ts +29 -0
  369. package/dist/tools/task.js +107 -0
  370. package/dist/tools/todo.d.ts +28 -0
  371. package/dist/tools/todo.js +107 -0
  372. package/dist/tools/truncate.d.ts +44 -0
  373. package/dist/tools/truncate.js +175 -0
  374. package/dist/tools/types.d.ts +135 -0
  375. package/dist/tools/types.js +19 -0
  376. package/dist/tools/write.d.ts +20 -0
  377. package/dist/tools/write.js +84 -0
  378. package/dist/tui/ansi.d.ts +29 -0
  379. package/dist/tui/ansi.js +420 -0
  380. package/dist/tui/component.d.ts +38 -0
  381. package/dist/tui/component.js +13 -0
  382. package/dist/tui/components/box.d.ts +26 -0
  383. package/dist/tui/components/box.js +65 -0
  384. package/dist/tui/components/container.d.ts +14 -0
  385. package/dist/tui/components/container.js +39 -0
  386. package/dist/tui/components/editor-buffer.d.ts +67 -0
  387. package/dist/tui/components/editor-buffer.js +300 -0
  388. package/dist/tui/components/editor-paste.d.ts +29 -0
  389. package/dist/tui/components/editor-paste.js +64 -0
  390. package/dist/tui/components/editor.d.ts +114 -0
  391. package/dist/tui/components/editor.js +530 -0
  392. package/dist/tui/components/key-value.d.ts +29 -0
  393. package/dist/tui/components/key-value.js +48 -0
  394. package/dist/tui/components/loader.d.ts +35 -0
  395. package/dist/tui/components/loader.js +71 -0
  396. package/dist/tui/components/markdown.d.ts +90 -0
  397. package/dist/tui/components/markdown.js +462 -0
  398. package/dist/tui/components/meter.d.ts +29 -0
  399. package/dist/tui/components/meter.js +47 -0
  400. package/dist/tui/components/overlay.d.ts +24 -0
  401. package/dist/tui/components/overlay.js +52 -0
  402. package/dist/tui/components/select-list.d.ts +57 -0
  403. package/dist/tui/components/select-list.js +179 -0
  404. package/dist/tui/components/spacer.d.ts +11 -0
  405. package/dist/tui/components/spacer.js +16 -0
  406. package/dist/tui/components/text.d.ts +30 -0
  407. package/dist/tui/components/text.js +65 -0
  408. package/dist/tui/keybindings.d.ts +66 -0
  409. package/dist/tui/keybindings.js +120 -0
  410. package/dist/tui/keys.d.ts +38 -0
  411. package/dist/tui/keys.js +275 -0
  412. package/dist/tui/stdin-buffer.d.ts +41 -0
  413. package/dist/tui/stdin-buffer.js +206 -0
  414. package/dist/tui/terminal.d.ts +79 -0
  415. package/dist/tui/terminal.js +153 -0
  416. package/dist/tui/theme.d.ts +31 -0
  417. package/dist/tui/theme.js +199 -0
  418. package/dist/tui/tui.d.ts +103 -0
  419. package/dist/tui/tui.js +363 -0
  420. package/dist/tui/vt-screen.d.ts +46 -0
  421. package/dist/tui/vt-screen.js +251 -0
  422. package/dist/tui.d.ts +30 -0
  423. package/dist/tui.js +31 -0
  424. package/dist/version.d.ts +8 -0
  425. package/dist/version.js +24 -0
  426. package/docs/codemode.md +102 -0
  427. package/docs/hooks.md +196 -0
  428. package/docs/host-api.md +161 -0
  429. package/docs/providers.md +531 -0
  430. package/docs/rpc.md +253 -0
  431. package/docs/session-format.md +119 -0
  432. package/docs/tui.md +170 -0
  433. package/package.json +101 -4
@@ -0,0 +1,153 @@
1
+ /**
2
+ * 终端抽象(设计 §12.2、§12.3、§12.8)。[B4]
3
+ *
4
+ * - `Terminal`:TUI 只依赖这个接口——尺寸、写入、输入回调、尺寸变化回调。
5
+ * - `ProcessTerminal`:真实 TTY。raw 模式、括号粘贴 `?2004`、stdout `resize`(SIGWINCH);
6
+ * 输入经 `StdinBuffer` 切分,括号粘贴以 `ESC[200~正文ESC[201~` 一次交给 onInput。
7
+ * 停止时关括号粘贴、显示光标、恢复 cooked 模式;**不清屏**(回滚保留对话)。
8
+ * - `MemoryTerminal`:测试用。记录每次写入,并用 `VirtualScreen` 还原屏幕与回滚。
9
+ */
10
+ import { PASTE_END, PASTE_START } from "./keys.js";
11
+ import { StdinBuffer } from "./stdin-buffer.js";
12
+ import { VirtualScreen } from "./vt-screen.js";
13
+ export const BRACKETED_PASTE_ON = "\x1b[?2004h";
14
+ export const BRACKETED_PASTE_OFF = "\x1b[?2004l";
15
+ export const SHOW_CURSOR = "\x1b[?25h";
16
+ export const HIDE_CURSOR = "\x1b[?25l";
17
+ export class ProcessTerminal {
18
+ stdin;
19
+ stdout;
20
+ escTimeoutMs;
21
+ buffer = null;
22
+ wasRaw = false;
23
+ dataListener = null;
24
+ resizeListener = null;
25
+ constructor(options = {}) {
26
+ this.stdin = options.stdin ?? process.stdin;
27
+ this.stdout = options.stdout ?? process.stdout;
28
+ this.escTimeoutMs = options.escTimeoutMs;
29
+ }
30
+ get columns() {
31
+ return this.stdout.columns || 80;
32
+ }
33
+ get rows() {
34
+ return this.stdout.rows || 24;
35
+ }
36
+ start(onInput, onResize) {
37
+ const bufferOptions = {
38
+ onData: onInput,
39
+ onPaste: (text) => onInput(PASTE_START + text + PASTE_END),
40
+ };
41
+ this.buffer = new StdinBuffer(this.escTimeoutMs === undefined
42
+ ? bufferOptions
43
+ : { ...bufferOptions, escTimeoutMs: this.escTimeoutMs });
44
+ if (this.stdin.isTTY) {
45
+ this.wasRaw = this.stdin.isRaw;
46
+ this.stdin.setRawMode(true);
47
+ }
48
+ this.stdin.setEncoding("utf8");
49
+ const buffer = this.buffer;
50
+ this.dataListener = (chunk) => buffer.process(chunk);
51
+ this.stdin.on("data", this.dataListener);
52
+ this.stdin.resume();
53
+ this.resizeListener = onResize;
54
+ this.stdout.on("resize", this.resizeListener);
55
+ this.write(BRACKETED_PASTE_ON);
56
+ }
57
+ stop() {
58
+ if (this.buffer === null)
59
+ return;
60
+ this.buffer.flush();
61
+ this.buffer.destroy();
62
+ this.buffer = null;
63
+ this.write(BRACKETED_PASTE_OFF + SHOW_CURSOR);
64
+ if (this.dataListener)
65
+ this.stdin.off("data", this.dataListener);
66
+ if (this.resizeListener)
67
+ this.stdout.off("resize", this.resizeListener);
68
+ this.dataListener = null;
69
+ this.resizeListener = null;
70
+ if (this.stdin.isTTY)
71
+ this.stdin.setRawMode(this.wasRaw);
72
+ this.stdin.pause();
73
+ }
74
+ write(data) {
75
+ this.stdout.write(data);
76
+ }
77
+ }
78
+ export class MemoryTerminal {
79
+ screen;
80
+ /** 每次 write 的原始数据(按顺序)。 */
81
+ writes = [];
82
+ started = false;
83
+ rawMode = false;
84
+ onInput = null;
85
+ onResize = null;
86
+ buffer;
87
+ constructor(options = {}) {
88
+ this.screen = new VirtualScreen(options.columns ?? 80, options.rows ?? 24);
89
+ this.buffer = new StdinBuffer({
90
+ onData: (data) => this.onInput?.(data),
91
+ onPaste: (text) => this.onInput?.(PASTE_START + text + PASTE_END),
92
+ escTimeoutMs: options.escTimeoutMs ?? 10,
93
+ });
94
+ }
95
+ get columns() {
96
+ return this.screen.columns;
97
+ }
98
+ get rows() {
99
+ return this.screen.height;
100
+ }
101
+ start(onInput, onResize) {
102
+ this.onInput = onInput;
103
+ this.onResize = onResize;
104
+ this.started = true;
105
+ this.rawMode = true;
106
+ this.write(BRACKETED_PASTE_ON);
107
+ }
108
+ stop() {
109
+ if (!this.started)
110
+ return;
111
+ this.buffer.flush();
112
+ this.write(BRACKETED_PASTE_OFF + SHOW_CURSOR);
113
+ this.started = false;
114
+ this.rawMode = false;
115
+ this.onInput = null;
116
+ this.onResize = null;
117
+ }
118
+ write(data) {
119
+ this.writes.push(data);
120
+ this.screen.write(data);
121
+ }
122
+ /** 模拟一个 stdin data 块(经 StdinBuffer 切分,与真实终端同路径)。 */
123
+ sendInput(chunk) {
124
+ this.buffer.process(chunk);
125
+ }
126
+ /** 立即发出挂起的不完整序列(替代等待 ESC 超时)。 */
127
+ flushInput() {
128
+ this.buffer.flush();
129
+ }
130
+ /** 改尺寸并触发 resize 回调(模拟 SIGWINCH)。 */
131
+ resize(columns, rows) {
132
+ this.screen.resize(columns, rows);
133
+ this.onResize?.();
134
+ }
135
+ /** 全部写入拼成一个字符串。 */
136
+ get output() {
137
+ return this.writes.join("");
138
+ }
139
+ /** 取走并清空写入记录(便于断言「这一帧写了什么」)。 */
140
+ takeWrites() {
141
+ const out = this.writes.join("");
142
+ this.writes.length = 0;
143
+ return out;
144
+ }
145
+ /** 可见屏幕各行(去掉右侧空白)。 */
146
+ viewport() {
147
+ return this.screen.viewport();
148
+ }
149
+ /** 回滚 + 屏幕(去掉底部空行)。 */
150
+ transcript() {
151
+ return this.screen.transcript();
152
+ }
153
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 主题与颜色能力(设计 §12.7)。[B4]
3
+ *
4
+ * - `dark` / `light` 两套语义色(§12.7 的 11 个名字),以 24 位 RGB 定义。
5
+ * - 能力降级:truecolor → 256 色(6×6×6 立方 + 灰阶取近)→ 16 色(xterm 缺省调色板取近)→ 无色。
6
+ * - `NO_COLOR`(非空)或 `TERM=dumb` → 无色;不探测终端背景(不发查询序列)。
7
+ * - 样式用各自的关闭码(39 / 49 / 22 / 23 / 24)而不是全重置,可以嵌套。
8
+ */
9
+ import type { ColorDepth, SemanticColor, Theme, ThemeCapabilities } from "./component.js";
10
+ export type ThemeName = "dark" | "light";
11
+ type Rgb = readonly [number, number, number];
12
+ export declare const THEME_PALETTES: Record<ThemeName, Record<SemanticColor, string>>;
13
+ /** 由环境推断颜色深度。 */
14
+ export declare function detectColorDepth(env?: NodeJS.ProcessEnv, isTTY?: boolean): ColorDepth;
15
+ export declare function detectCapabilities(env?: NodeJS.ProcessEnv, isTTY?: boolean): ThemeCapabilities;
16
+ export declare function parseHex(hex: string): Rgb;
17
+ /** RGB → xterm 256 色索引(立方与灰阶取较近者)。 */
18
+ export declare function rgbTo256(rgb: Rgb): number;
19
+ /** RGB → 16 色索引(0–15)。 */
20
+ export declare function rgbTo16(rgb: Rgb): number;
21
+ /** 生成前景 / 背景开启序列;depth 0 返回空串。 */
22
+ export declare function colorCode(hex: string, depth: ColorDepth, background: boolean): string;
23
+ export interface CreateThemeOptions {
24
+ caps?: ThemeCapabilities;
25
+ /** 覆盖部分语义色(`#rrggbb`)。 */
26
+ overrides?: Partial<Record<SemanticColor, string>>;
27
+ }
28
+ export declare function createTheme(name?: ThemeName, options?: CreateThemeOptions): Theme;
29
+ /** 无色主题(测试、line 模式、NO_COLOR):所有方法原样返回文本。 */
30
+ export declare function plainTheme(): Theme;
31
+ export {};
@@ -0,0 +1,199 @@
1
+ /**
2
+ * 主题与颜色能力(设计 §12.7)。[B4]
3
+ *
4
+ * - `dark` / `light` 两套语义色(§12.7 的 11 个名字),以 24 位 RGB 定义。
5
+ * - 能力降级:truecolor → 256 色(6×6×6 立方 + 灰阶取近)→ 16 色(xterm 缺省调色板取近)→ 无色。
6
+ * - `NO_COLOR`(非空)或 `TERM=dumb` → 无色;不探测终端背景(不发查询序列)。
7
+ * - 样式用各自的关闭码(39 / 49 / 22 / 23 / 24)而不是全重置,可以嵌套。
8
+ */
9
+ export const THEME_PALETTES = {
10
+ dark: {
11
+ text: "#e4e4e4",
12
+ dim: "#808080",
13
+ accent: "#5fafff",
14
+ success: "#5fd787",
15
+ warning: "#ffd75f",
16
+ error: "#ff5f5f",
17
+ user: "#87afff",
18
+ assistant: "#e4e4e4",
19
+ tool: "#af87ff",
20
+ border: "#5f5f5f",
21
+ code: "#ffaf5f",
22
+ },
23
+ light: {
24
+ text: "#1c1c1c",
25
+ dim: "#6c6c6c",
26
+ accent: "#005fd7",
27
+ success: "#008700",
28
+ warning: "#af5f00",
29
+ error: "#d70000",
30
+ user: "#005faf",
31
+ assistant: "#1c1c1c",
32
+ tool: "#8700af",
33
+ border: "#a8a8a8",
34
+ code: "#875f00",
35
+ },
36
+ };
37
+ /** 由环境推断颜色深度。 */
38
+ export function detectColorDepth(env = process.env, isTTY = process.stdout.isTTY === true) {
39
+ if (env["NO_COLOR"] !== undefined && env["NO_COLOR"] !== "")
40
+ return 0;
41
+ const force = env["FORCE_COLOR"];
42
+ if (force === "0")
43
+ return 0;
44
+ const term = (env["TERM"] ?? "").toLowerCase();
45
+ if (term === "dumb")
46
+ return 0;
47
+ if (!isTTY && (force === undefined || force === ""))
48
+ return 0;
49
+ const colorterm = (env["COLORTERM"] ?? "").toLowerCase();
50
+ if (colorterm === "truecolor" || colorterm === "24bit" || force === "3")
51
+ return 16_777_216;
52
+ if (term.includes("256color") || force === "2")
53
+ return 256;
54
+ return 16;
55
+ }
56
+ export function detectCapabilities(env = process.env, isTTY = process.stdout.isTTY === true) {
57
+ return { colors: detectColorDepth(env, isTTY) };
58
+ }
59
+ export function parseHex(hex) {
60
+ const h = hex.replace(/^#/, "");
61
+ const n = Number.parseInt(h.length === 3 ? [...h].map((c) => c + c).join("") : h, 16);
62
+ return [(n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff];
63
+ }
64
+ const CUBE_LEVELS = [0, 95, 135, 175, 215, 255];
65
+ function nearestIndex(levels, v) {
66
+ let best = 0;
67
+ for (let i = 1; i < levels.length; i++) {
68
+ if (Math.abs(levels[i] - v) < Math.abs(levels[best] - v))
69
+ best = i;
70
+ }
71
+ return best;
72
+ }
73
+ function distance(a, b) {
74
+ const dr = a[0] - b[0];
75
+ const dg = a[1] - b[1];
76
+ const db = a[2] - b[2];
77
+ return dr * dr * 0.3 + dg * dg * 0.59 + db * db * 0.11;
78
+ }
79
+ /** RGB → xterm 256 色索引(立方与灰阶取较近者)。 */
80
+ export function rgbTo256(rgb) {
81
+ const ri = nearestIndex(CUBE_LEVELS, rgb[0]);
82
+ const gi = nearestIndex(CUBE_LEVELS, rgb[1]);
83
+ const bi = nearestIndex(CUBE_LEVELS, rgb[2]);
84
+ const cube = [CUBE_LEVELS[ri], CUBE_LEVELS[gi], CUBE_LEVELS[bi]];
85
+ const avg = Math.round((rgb[0] + rgb[1] + rgb[2]) / 3);
86
+ const grayIndex = Math.max(0, Math.min(23, Math.round((avg - 8) / 10)));
87
+ const grayLevel = 8 + grayIndex * 10;
88
+ const gray = [grayLevel, grayLevel, grayLevel];
89
+ return distance(rgb, gray) < distance(rgb, cube) ? 232 + grayIndex : 16 + 36 * ri + 6 * gi + bi;
90
+ }
91
+ /** xterm 缺省 16 色调色板。 */
92
+ const ANSI16 = [
93
+ [0, 0, 0],
94
+ [205, 0, 0],
95
+ [0, 205, 0],
96
+ [205, 205, 0],
97
+ [0, 0, 238],
98
+ [205, 0, 205],
99
+ [0, 205, 205],
100
+ [229, 229, 229],
101
+ [127, 127, 127],
102
+ [255, 0, 0],
103
+ [0, 255, 0],
104
+ [255, 255, 0],
105
+ [92, 92, 255],
106
+ [255, 0, 255],
107
+ [0, 255, 255],
108
+ [255, 255, 255],
109
+ ];
110
+ /** RGB → 16 色索引(0–15)。 */
111
+ export function rgbTo16(rgb) {
112
+ let best = 0;
113
+ for (let i = 1; i < ANSI16.length; i++) {
114
+ if (distance(rgb, ANSI16[i]) < distance(rgb, ANSI16[best]))
115
+ best = i;
116
+ }
117
+ return best;
118
+ }
119
+ /** 生成前景 / 背景开启序列;depth 0 返回空串。 */
120
+ export function colorCode(hex, depth, background) {
121
+ if (depth === 0)
122
+ return "";
123
+ const rgb = parseHex(hex);
124
+ if (depth === 16_777_216)
125
+ return `\x1b[${background ? 48 : 38};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
126
+ if (depth === 256)
127
+ return `\x1b[${background ? 48 : 38};5;${rgbTo256(rgb)}m`;
128
+ const idx = rgbTo16(rgb);
129
+ const base = idx < 8 ? (background ? 40 : 30) + idx : (background ? 100 : 90) + idx - 8;
130
+ return `\x1b[${base}m`;
131
+ }
132
+ class PaletteTheme {
133
+ name;
134
+ caps;
135
+ fgCodes;
136
+ bgCodes;
137
+ constructor(name, palette, caps) {
138
+ this.name = name;
139
+ this.caps = caps;
140
+ const fg = {};
141
+ const bg = {};
142
+ for (const key of Object.keys(palette)) {
143
+ fg[key] = colorCode(palette[key], caps.colors, false);
144
+ bg[key] = colorCode(palette[key], caps.colors, true);
145
+ }
146
+ this.fgCodes = fg;
147
+ this.bgCodes = bg;
148
+ }
149
+ fg(color, text) {
150
+ const code = this.fgCodes[color];
151
+ return code === "" ? text : `${code}${text}\x1b[39m`;
152
+ }
153
+ bg(color, text) {
154
+ const code = this.bgCodes[color];
155
+ return code === "" ? text : `${code}${text}\x1b[49m`;
156
+ }
157
+ bold(text) {
158
+ return `\x1b[1m${text}\x1b[22m`;
159
+ }
160
+ dim(text) {
161
+ return this.caps.colors === 0 ? text : `\x1b[2m${text}\x1b[22m`;
162
+ }
163
+ italic(text) {
164
+ return `\x1b[3m${text}\x1b[23m`;
165
+ }
166
+ underline(text) {
167
+ return `\x1b[4m${text}\x1b[24m`;
168
+ }
169
+ }
170
+ export function createTheme(name = "dark", options = {}) {
171
+ const palette = { ...THEME_PALETTES[name], ...options.overrides };
172
+ return new PaletteTheme(name, palette, options.caps ?? detectCapabilities());
173
+ }
174
+ /** 无色主题(测试、line 模式、NO_COLOR):所有方法原样返回文本。 */
175
+ export function plainTheme() {
176
+ return new PlainTheme();
177
+ }
178
+ class PlainTheme {
179
+ name = "plain";
180
+ caps = { colors: 0 };
181
+ fg(_color, text) {
182
+ return text;
183
+ }
184
+ bg(_color, text) {
185
+ return text;
186
+ }
187
+ bold(text) {
188
+ return text;
189
+ }
190
+ dim(text) {
191
+ return text;
192
+ }
193
+ italic(text) {
194
+ return text;
195
+ }
196
+ underline(text) {
197
+ return text;
198
+ }
199
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * TUI 主类(设计 §12.1、§12.2,主屏 regular 模式)。[B4]
3
+ *
4
+ * 组件树(自身是纵向 Container)+ 焦点 + 覆盖层 + 差分渲染:
5
+ * 1. `requestRender()` 合并到 `process.nextTick`,两帧最小间隔 16 ms;键盘输入触发的渲染绕过节流。
6
+ * 2. 渲染组件树 → 合成覆盖层 → 提取并剔除 CURSOR_MARKER → 每行截断到宽度、含样式的行尾补重置。
7
+ * 3. 首帧全量;宽度 / 高度变化全量(回到屏幕左上清屏,只画最后一屏)。
8
+ * 4. 否则找首末变化行只重写该区间;首变化行已滚出视口 → 从视口顶清到屏底重画视口。
9
+ * 已滚出终端顶部的历史行不再重绘(它们在终端回滚里)。
10
+ * 5. 每帧写入包在同步输出 `?2026h … ?2026l` 内,按 64 KiB 分块写。
11
+ * 6. 记录硬件光标所在内容行;最后把硬件光标移到获焦组件的光标处(便于输入法候选窗)。
12
+ * 7. `stop()`:光标移到内容末尾下一行、显示光标、交还终端(关括号粘贴、cooked 模式);不清屏。
13
+ *
14
+ * 首帧前把当前行滚到屏幕顶(输出 height-1 个换行再上移),原屏内容进入回滚而不是被清掉;
15
+ * 这样内容起点与屏幕顶对齐,相对光标移动不会越过屏幕顶部。
16
+ */
17
+ import { type Component } from "./component.js";
18
+ import { Container } from "./components/container.js";
19
+ import { type OverlayOptions } from "./components/overlay.js";
20
+ import { type Terminal } from "./terminal.js";
21
+ export declare const SYNC_BEGIN = "\u001B[?2026h";
22
+ export declare const SYNC_END = "\u001B[?2026l";
23
+ export declare const WRITE_CHUNK_SIZE: number;
24
+ export declare const MIN_RENDER_INTERVAL_MS = 16;
25
+ export interface TuiOptions {
26
+ /** 两帧最小间隔(ms),缺省 16。 */
27
+ minRenderIntervalMs?: number;
28
+ /** 获焦组件有光标时是否显示硬件光标(缺省 false:只摆位置给输入法,组件自画光标)。 */
29
+ showHardwareCursor?: boolean;
30
+ /** 首帧前把当前行滚到屏幕顶(缺省 true)。 */
31
+ anchorToTop?: boolean;
32
+ now?: () => number;
33
+ }
34
+ export interface OverlayHandle {
35
+ hide(): void;
36
+ /** 重新把焦点交给覆盖层组件。 */
37
+ focus(): void;
38
+ readonly visible: boolean;
39
+ }
40
+ /** 返回 true 表示已消费,不再交给获焦组件。 */
41
+ export type InputListener = (data: string) => boolean | void;
42
+ export interface RenderStats {
43
+ renders: number;
44
+ fullRedraws: number;
45
+ }
46
+ export declare class TUI extends Container {
47
+ readonly terminal: Terminal;
48
+ private readonly options;
49
+ readonly stats: RenderStats;
50
+ private started;
51
+ private focused;
52
+ private readonly overlays;
53
+ private readonly listeners;
54
+ private readonly minInterval;
55
+ private readonly now;
56
+ private tickScheduled;
57
+ private renderGeneration;
58
+ private timer;
59
+ private lastRenderAt;
60
+ private prevLines;
61
+ private prevWidth;
62
+ private prevHeight;
63
+ /** 硬件光标所在内容行。 */
64
+ private hwRow;
65
+ /** 终端上已存在的内容行数(自上次全量起写到过的最大行 + 1)。 */
66
+ private bufferRows;
67
+ /** 可达的最小内容行(更早的行在回滚里或从未画过)。 */
68
+ private topLimit;
69
+ private cursorShown;
70
+ constructor(terminal: Terminal, options?: TuiOptions);
71
+ get isStarted(): boolean;
72
+ start(): void;
73
+ /** 画完最后一帧,光标移到内容末尾下一行,交还终端;不清屏。 */
74
+ stop(): void;
75
+ getFocus(): Component | null;
76
+ setFocus(component: Component | null): void;
77
+ /** 全局输入监听(先于获焦组件);返回取消函数。 */
78
+ addInputListener(listener: InputListener): () => void;
79
+ showOverlay(component: Component, options?: OverlayOptions): OverlayHandle;
80
+ get hasOverlay(): boolean;
81
+ /** 原始输入:监听器 → 获焦组件 → 立即渲染(绕过节流)。 */
82
+ handleInput(data: string): void;
83
+ /** 请求渲染;同一 tick 内合并。immediate 用于键盘输入与 resize,不受 16 ms 节流。 */
84
+ requestRender(immediate?: boolean): void;
85
+ /** 同步渲染一帧(测试与需要立刻落屏的场合)。 */
86
+ renderNow(): void;
87
+ /** 丢弃差分状态,下一帧按 resize 方式全量重画(例如外部程序写乱了屏幕)。 */
88
+ forceFullRedraw(): void;
89
+ private cancelScheduled;
90
+ /** 组件树 + 覆盖层 → 规范化行与光标位置。 */
91
+ private compose;
92
+ private viewportTop;
93
+ /** 从 hwRow 移到内容行 row 的行首;越过已有行时用换行(会滚屏)。 */
94
+ private moveTo;
95
+ private doRender;
96
+ private writeRows;
97
+ private fullFirst;
98
+ private fullResize;
99
+ /** 首变化行在视口之上:从视口顶清到屏底,重画视口(更早的行留在回滚里)。 */
100
+ private fullViewport;
101
+ private diff;
102
+ private placeCursor;
103
+ }