@armadra/agent 0.0.0-stage → 0.2.1

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 (407) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE +21 -0
  3. package/README.md +426 -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 +511 -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 +118 -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 +104 -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 +484 -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 +303 -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 +102 -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/registry.d.ts +83 -0
  101. package/dist/ai/providers/registry.js +305 -0
  102. package/dist/ai/sse.d.ts +32 -0
  103. package/dist/ai/sse.js +140 -0
  104. package/dist/ai/thinking.d.ts +42 -0
  105. package/dist/ai/thinking.js +101 -0
  106. package/dist/ai/types.d.ts +428 -0
  107. package/dist/ai/types.js +19 -0
  108. package/dist/bundle/ama-sandbox.cjs +324 -0
  109. package/dist/bundle/ama.cjs +25770 -0
  110. package/dist/bundle.d.ts +9 -0
  111. package/dist/bundle.js +15 -0
  112. package/dist/cli/args.d.ts +82 -0
  113. package/dist/cli/args.js +381 -0
  114. package/dist/cli/bootstrap.d.ts +18 -0
  115. package/dist/cli/bootstrap.js +398 -0
  116. package/dist/cli/compose-providers.d.ts +37 -0
  117. package/dist/cli/compose-providers.js +104 -0
  118. package/dist/cli/compose-session.d.ts +69 -0
  119. package/dist/cli/compose-session.js +370 -0
  120. package/dist/cli/compose-store.d.ts +24 -0
  121. package/dist/cli/compose-store.js +125 -0
  122. package/dist/cli/compose.d.ts +106 -0
  123. package/dist/cli/compose.js +206 -0
  124. package/dist/cli/default-model.d.ts +16 -0
  125. package/dist/cli/default-model.js +24 -0
  126. package/dist/cli/deps.d.ts +205 -0
  127. package/dist/cli/deps.js +12 -0
  128. package/dist/cli/exit-codes.d.ts +29 -0
  129. package/dist/cli/exit-codes.js +40 -0
  130. package/dist/cli/main.d.ts +26 -0
  131. package/dist/cli/main.js +165 -0
  132. package/dist/cli/runtime.d.ts +90 -0
  133. package/dist/cli/runtime.js +8 -0
  134. package/dist/cli/startup-screen.d.ts +15 -0
  135. package/dist/cli/startup-screen.js +56 -0
  136. package/dist/cli/startup-steps.d.ts +35 -0
  137. package/dist/cli/startup-steps.js +197 -0
  138. package/dist/cli/subcommands/auth.d.ts +12 -0
  139. package/dist/cli/subcommands/auth.js +91 -0
  140. package/dist/cli/subcommands/config.d.ts +44 -0
  141. package/dist/cli/subcommands/config.js +201 -0
  142. package/dist/cli/subcommands/context.d.ts +21 -0
  143. package/dist/cli/subcommands/context.js +41 -0
  144. package/dist/cli/subcommands/doctor.d.ts +11 -0
  145. package/dist/cli/subcommands/doctor.js +246 -0
  146. package/dist/cli/subcommands/models-cache-probe.d.ts +34 -0
  147. package/dist/cli/subcommands/models-cache-probe.js +190 -0
  148. package/dist/cli/subcommands/models-discover.d.ts +40 -0
  149. package/dist/cli/subcommands/models-discover.js +204 -0
  150. package/dist/cli/subcommands/models.d.ts +40 -0
  151. package/dist/cli/subcommands/models.js +144 -0
  152. package/dist/cli/subcommands/sessions.d.ts +11 -0
  153. package/dist/cli/subcommands/sessions.js +100 -0
  154. package/dist/codemode/capability.d.ts +37 -0
  155. package/dist/codemode/capability.js +55 -0
  156. package/dist/codemode/declarations.d.ts +44 -0
  157. package/dist/codemode/declarations.js +111 -0
  158. package/dist/codemode/host-side.d.ts +59 -0
  159. package/dist/codemode/host-side.js +253 -0
  160. package/dist/codemode/modes.d.ts +23 -0
  161. package/dist/codemode/modes.js +40 -0
  162. package/dist/codemode/protocol.d.ts +91 -0
  163. package/dist/codemode/protocol.js +114 -0
  164. package/dist/codemode/sandbox-entry.d.ts +25 -0
  165. package/dist/codemode/sandbox-entry.js +323 -0
  166. package/dist/codemode/store.d.ts +26 -0
  167. package/dist/codemode/store.js +53 -0
  168. package/dist/codemode/tool.d.ts +105 -0
  169. package/dist/codemode/tool.js +283 -0
  170. package/dist/compaction/branch-summary.d.ts +30 -0
  171. package/dist/compaction/branch-summary.js +79 -0
  172. package/dist/compaction/breaker.d.ts +32 -0
  173. package/dist/compaction/breaker.js +65 -0
  174. package/dist/compaction/cut-point.d.ts +23 -0
  175. package/dist/compaction/cut-point.js +70 -0
  176. package/dist/compaction/estimate.d.ts +30 -0
  177. package/dist/compaction/estimate.js +114 -0
  178. package/dist/compaction/prune-tier.d.ts +31 -0
  179. package/dist/compaction/prune-tier.js +83 -0
  180. package/dist/compaction/serialize.d.ts +20 -0
  181. package/dist/compaction/serialize.js +115 -0
  182. package/dist/compaction/summarize-tier.d.ts +111 -0
  183. package/dist/compaction/summarize-tier.js +305 -0
  184. package/dist/config/auth-file.d.ts +39 -0
  185. package/dist/config/auth-file.js +92 -0
  186. package/dist/config/context-files.d.ts +30 -0
  187. package/dist/config/context-files.js +77 -0
  188. package/dist/config/load.d.ts +45 -0
  189. package/dist/config/load.js +97 -0
  190. package/dist/config/merge.d.ts +73 -0
  191. package/dist/config/merge.js +248 -0
  192. package/dist/config/paths.d.ts +38 -0
  193. package/dist/config/paths.js +108 -0
  194. package/dist/config/profile.d.ts +27 -0
  195. package/dist/config/profile.js +65 -0
  196. package/dist/config/schema.d.ts +34 -0
  197. package/dist/config/schema.js +413 -0
  198. package/dist/config/trust.d.ts +42 -0
  199. package/dist/config/trust.js +122 -0
  200. package/dist/config/types.d.ts +172 -0
  201. package/dist/config/types.js +27 -0
  202. package/dist/config/write.d.ts +10 -0
  203. package/dist/config/write.js +25 -0
  204. package/dist/errors.d.ts +28 -0
  205. package/dist/errors.js +30 -0
  206. package/dist/hooks/config.d.ts +49 -0
  207. package/dist/hooks/config.js +102 -0
  208. package/dist/hooks/dispatcher.d.ts +41 -0
  209. package/dist/hooks/dispatcher.js +104 -0
  210. package/dist/hooks/matcher.d.ts +22 -0
  211. package/dist/hooks/matcher.js +108 -0
  212. package/dist/hooks/protocol.d.ts +33 -0
  213. package/dist/hooks/protocol.js +240 -0
  214. package/dist/hooks/runner.d.ts +30 -0
  215. package/dist/hooks/runner.js +143 -0
  216. package/dist/hooks/types.d.ts +147 -0
  217. package/dist/hooks/types.js +20 -0
  218. package/dist/host/api-impl.d.ts +75 -0
  219. package/dist/host/api-impl.js +173 -0
  220. package/dist/host/loader.d.ts +31 -0
  221. package/dist/host/loader.js +147 -0
  222. package/dist/host/types.d.ts +169 -0
  223. package/dist/host/types.js +14 -0
  224. package/dist/host.d.ts +5 -0
  225. package/dist/host.js +4 -0
  226. package/dist/index.d.ts +41 -0
  227. package/dist/index.js +28 -0
  228. package/dist/modes/commands-core.d.ts +44 -0
  229. package/dist/modes/commands-core.js +171 -0
  230. package/dist/modes/interactive/approval-dialog.d.ts +48 -0
  231. package/dist/modes/interactive/approval-dialog.js +202 -0
  232. package/dist/modes/interactive/commands.d.ts +41 -0
  233. package/dist/modes/interactive/commands.js +202 -0
  234. package/dist/modes/interactive/completion.d.ts +53 -0
  235. package/dist/modes/interactive/completion.js +157 -0
  236. package/dist/modes/interactive/interactive-mode.d.ts +46 -0
  237. package/dist/modes/interactive/interactive-mode.js +487 -0
  238. package/dist/modes/interactive/key-dispatch.d.ts +29 -0
  239. package/dist/modes/interactive/key-dispatch.js +107 -0
  240. package/dist/modes/interactive/line/line-editor.d.ts +50 -0
  241. package/dist/modes/interactive/line/line-editor.js +232 -0
  242. package/dist/modes/interactive/line/line-mode.d.ts +20 -0
  243. package/dist/modes/interactive/line/line-mode.js +216 -0
  244. package/dist/modes/interactive/line/line-render.d.ts +35 -0
  245. package/dist/modes/interactive/line/line-render.js +171 -0
  246. package/dist/modes/interactive/line/paste-state.d.ts +26 -0
  247. package/dist/modes/interactive/line/paste-state.js +72 -0
  248. package/dist/modes/interactive/message-view.d.ts +77 -0
  249. package/dist/modes/interactive/message-view.js +269 -0
  250. package/dist/modes/interactive/pickers.d.ts +42 -0
  251. package/dist/modes/interactive/pickers.js +115 -0
  252. package/dist/modes/interactive/startup-ui.d.ts +28 -0
  253. package/dist/modes/interactive/startup-ui.js +238 -0
  254. package/dist/modes/interactive/status-bar.d.ts +48 -0
  255. package/dist/modes/interactive/status-bar.js +139 -0
  256. package/dist/modes/interactive/tool-view.d.ts +95 -0
  257. package/dist/modes/interactive/tool-view.js +344 -0
  258. package/dist/modes/print/json-event.d.ts +15 -0
  259. package/dist/modes/print/json-event.js +39 -0
  260. package/dist/modes/print/print-mode.d.ts +15 -0
  261. package/dist/modes/print/print-mode.js +96 -0
  262. package/dist/modes/rpc/commands.d.ts +40 -0
  263. package/dist/modes/rpc/commands.js +258 -0
  264. package/dist/modes/rpc/jsonl.d.ts +16 -0
  265. package/dist/modes/rpc/jsonl.js +55 -0
  266. package/dist/modes/rpc/rpc-mode.d.ts +22 -0
  267. package/dist/modes/rpc/rpc-mode.js +153 -0
  268. package/dist/modes/session-report.d.ts +55 -0
  269. package/dist/modes/session-report.js +278 -0
  270. package/dist/modes/shared.d.ts +13 -0
  271. package/dist/modes/shared.js +52 -0
  272. package/dist/modes/startup-ui-text.d.ts +16 -0
  273. package/dist/modes/startup-ui-text.js +103 -0
  274. package/dist/permissions/broker.d.ts +47 -0
  275. package/dist/permissions/broker.js +107 -0
  276. package/dist/permissions/dangerous.d.ts +47 -0
  277. package/dist/permissions/dangerous.js +370 -0
  278. package/dist/permissions/pipeline.d.ts +51 -0
  279. package/dist/permissions/pipeline.js +181 -0
  280. package/dist/permissions/preview.d.ts +43 -0
  281. package/dist/permissions/preview.js +463 -0
  282. package/dist/permissions/rules.d.ts +58 -0
  283. package/dist/permissions/rules.js +249 -0
  284. package/dist/permissions/types.d.ts +100 -0
  285. package/dist/permissions/types.js +18 -0
  286. package/dist/rpc.d.ts +171 -0
  287. package/dist/rpc.js +13 -0
  288. package/dist/sdk.d.ts +98 -0
  289. package/dist/sdk.js +195 -0
  290. package/dist/session/manager.d.ts +70 -0
  291. package/dist/session/manager.js +278 -0
  292. package/dist/session/migrate.d.ts +19 -0
  293. package/dist/session/migrate.js +53 -0
  294. package/dist/session/projection.d.ts +50 -0
  295. package/dist/session/projection.js +180 -0
  296. package/dist/session/store.d.ts +47 -0
  297. package/dist/session/store.js +210 -0
  298. package/dist/session/tree.d.ts +21 -0
  299. package/dist/session/tree.js +88 -0
  300. package/dist/session/types.d.ts +199 -0
  301. package/dist/session/types.js +18 -0
  302. package/dist/skills/discover.d.ts +60 -0
  303. package/dist/skills/discover.js +160 -0
  304. package/dist/skills/expand.d.ts +35 -0
  305. package/dist/skills/expand.js +46 -0
  306. package/dist/skills/frontmatter.d.ts +27 -0
  307. package/dist/skills/frontmatter.js +157 -0
  308. package/dist/skills/index-prompt.d.ts +13 -0
  309. package/dist/skills/index-prompt.js +42 -0
  310. package/dist/skills/templates.d.ts +52 -0
  311. package/dist/skills/templates.js +177 -0
  312. package/dist/tools/bash.d.ts +49 -0
  313. package/dist/tools/bash.js +222 -0
  314. package/dist/tools/edit-fuzzy.d.ts +36 -0
  315. package/dist/tools/edit-fuzzy.js +129 -0
  316. package/dist/tools/edit.d.ts +38 -0
  317. package/dist/tools/edit.js +241 -0
  318. package/dist/tools/file-mutex.d.ts +8 -0
  319. package/dist/tools/file-mutex.js +29 -0
  320. package/dist/tools/glob.d.ts +44 -0
  321. package/dist/tools/glob.js +217 -0
  322. package/dist/tools/grep.d.ts +39 -0
  323. package/dist/tools/grep.js +179 -0
  324. package/dist/tools/ignore.d.ts +40 -0
  325. package/dist/tools/ignore.js +174 -0
  326. package/dist/tools/ls.d.ts +21 -0
  327. package/dist/tools/ls.js +96 -0
  328. package/dist/tools/output-accumulator.d.ts +48 -0
  329. package/dist/tools/output-accumulator.js +106 -0
  330. package/dist/tools/paths.d.ts +20 -0
  331. package/dist/tools/paths.js +58 -0
  332. package/dist/tools/presets.d.ts +71 -0
  333. package/dist/tools/presets.js +128 -0
  334. package/dist/tools/process-tree.d.ts +35 -0
  335. package/dist/tools/process-tree.js +125 -0
  336. package/dist/tools/read.d.ts +28 -0
  337. package/dist/tools/read.js +181 -0
  338. package/dist/tools/registry.d.ts +43 -0
  339. package/dist/tools/registry.js +106 -0
  340. package/dist/tools/shell.d.ts +38 -0
  341. package/dist/tools/shell.js +91 -0
  342. package/dist/tools/task.d.ts +29 -0
  343. package/dist/tools/task.js +107 -0
  344. package/dist/tools/todo.d.ts +28 -0
  345. package/dist/tools/todo.js +107 -0
  346. package/dist/tools/truncate.d.ts +44 -0
  347. package/dist/tools/truncate.js +175 -0
  348. package/dist/tools/types.d.ts +135 -0
  349. package/dist/tools/types.js +19 -0
  350. package/dist/tools/write.d.ts +20 -0
  351. package/dist/tools/write.js +84 -0
  352. package/dist/tui/ansi.d.ts +29 -0
  353. package/dist/tui/ansi.js +420 -0
  354. package/dist/tui/component.d.ts +38 -0
  355. package/dist/tui/component.js +13 -0
  356. package/dist/tui/components/box.d.ts +26 -0
  357. package/dist/tui/components/box.js +65 -0
  358. package/dist/tui/components/container.d.ts +14 -0
  359. package/dist/tui/components/container.js +39 -0
  360. package/dist/tui/components/editor-buffer.d.ts +67 -0
  361. package/dist/tui/components/editor-buffer.js +300 -0
  362. package/dist/tui/components/editor-paste.d.ts +29 -0
  363. package/dist/tui/components/editor-paste.js +64 -0
  364. package/dist/tui/components/editor.d.ts +114 -0
  365. package/dist/tui/components/editor.js +530 -0
  366. package/dist/tui/components/key-value.d.ts +29 -0
  367. package/dist/tui/components/key-value.js +48 -0
  368. package/dist/tui/components/loader.d.ts +35 -0
  369. package/dist/tui/components/loader.js +71 -0
  370. package/dist/tui/components/markdown.d.ts +90 -0
  371. package/dist/tui/components/markdown.js +462 -0
  372. package/dist/tui/components/meter.d.ts +29 -0
  373. package/dist/tui/components/meter.js +47 -0
  374. package/dist/tui/components/overlay.d.ts +24 -0
  375. package/dist/tui/components/overlay.js +52 -0
  376. package/dist/tui/components/select-list.d.ts +57 -0
  377. package/dist/tui/components/select-list.js +179 -0
  378. package/dist/tui/components/spacer.d.ts +11 -0
  379. package/dist/tui/components/spacer.js +16 -0
  380. package/dist/tui/components/text.d.ts +30 -0
  381. package/dist/tui/components/text.js +65 -0
  382. package/dist/tui/keybindings.d.ts +66 -0
  383. package/dist/tui/keybindings.js +120 -0
  384. package/dist/tui/keys.d.ts +38 -0
  385. package/dist/tui/keys.js +275 -0
  386. package/dist/tui/stdin-buffer.d.ts +41 -0
  387. package/dist/tui/stdin-buffer.js +206 -0
  388. package/dist/tui/terminal.d.ts +79 -0
  389. package/dist/tui/terminal.js +153 -0
  390. package/dist/tui/theme.d.ts +31 -0
  391. package/dist/tui/theme.js +199 -0
  392. package/dist/tui/tui.d.ts +103 -0
  393. package/dist/tui/tui.js +363 -0
  394. package/dist/tui/vt-screen.d.ts +46 -0
  395. package/dist/tui/vt-screen.js +251 -0
  396. package/dist/tui.d.ts +30 -0
  397. package/dist/tui.js +31 -0
  398. package/dist/version.d.ts +8 -0
  399. package/dist/version.js +24 -0
  400. package/docs/codemode.md +102 -0
  401. package/docs/hooks.md +196 -0
  402. package/docs/host-api.md +161 -0
  403. package/docs/providers.md +316 -0
  404. package/docs/rpc.md +253 -0
  405. package/docs/session-format.md +119 -0
  406. package/docs/tui.md +168 -0
  407. package/package.json +101 -4
@@ -0,0 +1,169 @@
1
+ /**
2
+ * 宿主适配器契约(设计 §6.2,`@armadra/agent/host`)。[B0] 契约文件,实现归 B5。
3
+ *
4
+ * 补全与偏差:
5
+ * - `InstructionSource` 设计未展开,按 v1 §8.5 补全为 file / text 两种。
6
+ * - `ApprovalBroker / ApprovalRequest / ApprovalDecision` 定义在 permissions/types.ts,此处再导出。
7
+ * - `HostMode` 抽成具名类型;`AgentEvents` 中空载荷用 `Record<string, never>` 表示
8
+ * (设计写 `{}`,在 strict 下 `{}` 意为「任意非空值」,语义不对)。
9
+ * - `HostAdapterHandle` 是 Runtime 持有的已激活适配器(loader.ts 产出)。
10
+ * - (W3-C0)第三波 §1.10 / §1.7:`AgentEvents` 加 `cache_miss`、`context_pressure`;
11
+ * `HostApi.cache.onWarmingDecision` 为可选面(HOST_API_VERSION 不变,旧宿主不受影响),
12
+ * 多个处理器时最后注册的生效。
13
+ */
14
+ import type { CacheMiss, WarmingDecisionHandler } from "../ai/cache/types.js";
15
+ import type { HookEvent } from "../hooks/types.js";
16
+ import type { ApprovalBroker, ApprovalDecision } from "../permissions/types.js";
17
+ import type { ToolDefinition } from "../tools/types.js";
18
+ export type { ActionPreview, ActionPreviewTarget, ApprovalBroker, ApprovalDecision, ApprovalReason, ApprovalRequest, ApprovalRequestContext, } from "../permissions/types.js";
19
+ export type { ToolAnnotations, ToolContext, ToolDefinition, ToolExecutionMode, ToolPermission, ToolResult, } from "../tools/types.js";
20
+ export type { JsonSchema } from "../ai/types.js";
21
+ export type { CacheMiss, WarmDecision, WarmingDecisionHandler } from "../ai/cache/types.js";
22
+ export declare const HOST_API_VERSION: 1;
23
+ export type HostApiVersion = typeof HOST_API_VERSION;
24
+ export type HostMode = "interactive" | "line" | "print" | "rpc";
25
+ export type InstructionSource = {
26
+ kind: "file";
27
+ path: string;
28
+ } | {
29
+ kind: "text";
30
+ text: string;
31
+ name?: string;
32
+ };
33
+ export interface HostModule {
34
+ readonly hostApi: HostApiVersion;
35
+ create(api: HostApi): HostAdapter | undefined | Promise<HostAdapter | undefined>;
36
+ }
37
+ export interface HostAdapter {
38
+ readonly id: string;
39
+ /** session_shutdown 后调用,幂等。 */
40
+ dispose?(): void | Promise<void>;
41
+ }
42
+ type Empty = Record<string, never>;
43
+ export interface AgentEvents {
44
+ session_start: {
45
+ sessionId: string;
46
+ sessionFile?: string;
47
+ cwd: string;
48
+ reason: "startup" | "resume" | "new" | "fork";
49
+ };
50
+ before_agent_start: {
51
+ prompt: string;
52
+ };
53
+ agent_start: Empty;
54
+ turn_start: Empty;
55
+ turn_end: Empty;
56
+ tool_call: {
57
+ toolCallId: string;
58
+ toolName: string;
59
+ input: unknown;
60
+ };
61
+ tool_result: {
62
+ toolCallId: string;
63
+ toolName: string;
64
+ isError: boolean;
65
+ };
66
+ agent_end: {
67
+ stopReason: string;
68
+ willRetry: boolean;
69
+ };
70
+ agent_before_settle: Empty;
71
+ agent_settled: {
72
+ warning?: string;
73
+ };
74
+ session_compact: {
75
+ tokensBefore: number;
76
+ };
77
+ model_select: {
78
+ model: {
79
+ id: string;
80
+ provider: string;
81
+ };
82
+ };
83
+ tool_approval_requested: {
84
+ requestId: string;
85
+ toolName: string;
86
+ };
87
+ tool_approval_resolved: {
88
+ requestId: string;
89
+ decision: ApprovalDecision;
90
+ };
91
+ hook_executed: {
92
+ event: HookEvent;
93
+ command: string;
94
+ exitCode: number | null;
95
+ durationMs: number;
96
+ };
97
+ session_shutdown: Empty;
98
+ /** [W3-C0] 一次缓存未命中(重计费 token / 金额与原因)。 */
99
+ cache_miss: CacheMiss;
100
+ /** [W3-C0] 上下文占用跨越 70% / 90%。 */
101
+ context_pressure: {
102
+ percent: number;
103
+ threshold: 70 | 90;
104
+ remainingTokens?: number;
105
+ estimatedTurnsLeft?: number;
106
+ };
107
+ }
108
+ export type AgentEventName = keyof AgentEvents;
109
+ export interface HostApi {
110
+ readonly version: HostApiVersion;
111
+ readonly agent: {
112
+ readonly name: "ama";
113
+ readonly version: string;
114
+ };
115
+ readonly env: Readonly<NodeJS.ProcessEnv>;
116
+ readonly mode: HostMode;
117
+ readonly session: {
118
+ id(): string;
119
+ file(): string | undefined;
120
+ cwd(): string;
121
+ model(): {
122
+ provider: string;
123
+ id: string;
124
+ } | undefined;
125
+ };
126
+ readonly tools: {
127
+ /** 同名已存在则抛错。 */
128
+ register(tool: ToolDefinition): void;
129
+ /** 隐藏内置工具(如 task)。 */
130
+ disable(name: string): void;
131
+ list(): readonly string[];
132
+ };
133
+ /** 追加到系统提示 `host` 节(最后)。 */
134
+ readonly instructions: {
135
+ add(source: InstructionSource): void;
136
+ };
137
+ readonly events: {
138
+ on<E extends AgentEventName>(name: E, handler: (event: AgentEvents[E]) => void | Promise<void>): () => void;
139
+ };
140
+ readonly approvals: {
141
+ setBroker(broker: ApprovalBroker): void;
142
+ };
143
+ /** 以 user 消息注入(运行中按 steer 入队),origin 缺省 "host"。 */
144
+ readonly messages: {
145
+ sendUser(text: string, origin?: string): Promise<"started" | "queued">;
146
+ };
147
+ /** print / rpc 下 notify → stderr / 事件。 */
148
+ readonly ui: {
149
+ notify(message: string, level?: "info" | "warn" | "error"): void;
150
+ setStatus(key: string, text?: string): void;
151
+ };
152
+ readonly log: (level: "debug" | "info" | "warn" | "error", message: string, detail?: unknown) => void;
153
+ /**
154
+ * [W3-C0] 缓存保温的否决钩子(第三波 §1.7):每次保温前以内置决策调用,返回 `"stop"` 即不发;
155
+ * 处理器出错回落内置决策。返回值用于注销。可选面:旧版本运行时没有它。
156
+ */
157
+ readonly cache?: {
158
+ onWarmingDecision(handler: WarmingDecisionHandler): () => void;
159
+ };
160
+ }
161
+ /** Runtime 持有的已激活适配器。 */
162
+ export interface HostAdapterHandle {
163
+ readonly adapter: HostAdapter;
164
+ readonly api: HostApi;
165
+ /** 模块来源(路径或 "sdk")。 */
166
+ readonly source: string;
167
+ /** 宿主 setStatus 的当前值(状态栏显示)。 */
168
+ status(): ReadonlyMap<string, string>;
169
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 宿主适配器契约(设计 §6.2,`@armadra/agent/host`)。[B0] 契约文件,实现归 B5。
3
+ *
4
+ * 补全与偏差:
5
+ * - `InstructionSource` 设计未展开,按 v1 §8.5 补全为 file / text 两种。
6
+ * - `ApprovalBroker / ApprovalRequest / ApprovalDecision` 定义在 permissions/types.ts,此处再导出。
7
+ * - `HostMode` 抽成具名类型;`AgentEvents` 中空载荷用 `Record<string, never>` 表示
8
+ * (设计写 `{}`,在 strict 下 `{}` 意为「任意非空值」,语义不对)。
9
+ * - `HostAdapterHandle` 是 Runtime 持有的已激活适配器(loader.ts 产出)。
10
+ * - (W3-C0)第三波 §1.10 / §1.7:`AgentEvents` 加 `cache_miss`、`context_pressure`;
11
+ * `HostApi.cache.onWarmingDecision` 为可选面(HOST_API_VERSION 不变,旧宿主不受影响),
12
+ * 多个处理器时最后注册的生效。
13
+ */
14
+ export const HOST_API_VERSION = 1;
package/dist/host.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `@armadra/agent/host` 子路径:宿主适配器类型 + HOST_API_VERSION(设计 §6.2、D7)。[B0] 所有。
3
+ */
4
+ export { HOST_API_VERSION } from "./host/types.js";
5
+ export type * from "./host/types.js";
package/dist/host.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * `@armadra/agent/host` 子路径:宿主适配器类型 + HOST_API_VERSION(设计 §6.2、D7)。[B0] 所有。
3
+ */
4
+ export { HOST_API_VERSION } from "./host/types.js";
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `@armadra/agent`:SDK 公开面(设计 §13.1)。[B0] 所有。
3
+ *
4
+ * B0 导出契约类型与少量契约内的值(版本、错误、校验器、退出码);「SDK」段(B6)导出
5
+ * `createAgentSession`、`createRuntime` 与常用实现类。
6
+ */
7
+ export { AMA_VERSION } from "./version.js";
8
+ export { AmaError, StartupError, isAmaError } from "./errors.js";
9
+ export { HOST_API_VERSION } from "./host/types.js";
10
+ export { RPC_PROTOCOL_VERSION } from "./rpc.js";
11
+ export { SESSION_FORMAT_VERSION } from "./session/types.js";
12
+ export { HOOK_EVENTS } from "./hooks/types.js";
13
+ export { PERMISSION_MODES_STRICT_FIRST } from "./permissions/types.js";
14
+ export { ExitCode, describeExitCode } from "./cli/exit-codes.js";
15
+ export { defineTool } from "./tools/types.js";
16
+ export { validateSchema, checkSchemaSubset, formatSchemaErrors } from "./agent/schema.js";
17
+ export type { SchemaError, SchemaErrorKeyword } from "./agent/schema.js";
18
+ export type * from "./ai/types.js";
19
+ export type * from "./ai/cache/types.js";
20
+ export type * from "./agent/types.js";
21
+ export type * from "./session/types.js";
22
+ export type * from "./tools/types.js";
23
+ export type * from "./hooks/types.js";
24
+ export type * from "./permissions/types.js";
25
+ export type * from "./host/types.js";
26
+ export type * from "./config/types.js";
27
+ export type { AmaErrorOptions, ErrorCode, KnownErrorCode } from "./errors.js";
28
+ export type { Runtime, RuntimeMode, ResolvedPaths, TrustState, LoadedResources, } from "./cli/runtime.js";
29
+ export { createAgentSession, createRuntime } from "./sdk.js";
30
+ export type { CreateSessionOptions, RuntimeOptions, SessionAuth } from "./sdk.js";
31
+ export { AgentSessionImpl } from "./agent/session.js";
32
+ export { SessionManager } from "./session/manager.js";
33
+ export { ProviderRegistry } from "./ai/providers/registry.js";
34
+ export { FakeProvider } from "./ai/fake/fake-provider.js";
35
+ export { loadConfigFile as loadConfig } from "./config/load.js";
36
+ export { createToolRegistry } from "./tools/registry.js";
37
+ export { PRESET_TOOLS, effectiveCodemodeMode } from "./tools/presets.js";
38
+ export { createRuntimeDeps, DEFAULT_TOOL_FACTORIES } from "./cli/compose.js";
39
+ export type { ComposeOptions, ToolFactory, ToolFactoryContext } from "./cli/compose.js";
40
+ export { currentSession, switchSession } from "./cli/compose-session.js";
41
+ export type { SwitchRequest } from "./cli/compose-session.js";
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `@armadra/agent`:SDK 公开面(设计 §13.1)。[B0] 所有。
3
+ *
4
+ * B0 导出契约类型与少量契约内的值(版本、错误、校验器、退出码);「SDK」段(B6)导出
5
+ * `createAgentSession`、`createRuntime` 与常用实现类。
6
+ */
7
+ // 值
8
+ export { AMA_VERSION } from "./version.js";
9
+ export { AmaError, StartupError, isAmaError } from "./errors.js";
10
+ export { HOST_API_VERSION } from "./host/types.js";
11
+ export { RPC_PROTOCOL_VERSION } from "./rpc.js";
12
+ export { SESSION_FORMAT_VERSION } from "./session/types.js";
13
+ export { HOOK_EVENTS } from "./hooks/types.js";
14
+ export { PERMISSION_MODES_STRICT_FIRST } from "./permissions/types.js";
15
+ export { ExitCode, describeExitCode } from "./cli/exit-codes.js";
16
+ export { defineTool } from "./tools/types.js";
17
+ export { validateSchema, checkSchemaSubset, formatSchemaErrors } from "./agent/schema.js";
18
+ // SDK(B6 追加)
19
+ export { createAgentSession, createRuntime } from "./sdk.js";
20
+ export { AgentSessionImpl } from "./agent/session.js";
21
+ export { SessionManager } from "./session/manager.js";
22
+ export { ProviderRegistry } from "./ai/providers/registry.js";
23
+ export { FakeProvider } from "./ai/fake/fake-provider.js";
24
+ export { loadConfigFile as loadConfig } from "./config/load.js";
25
+ export { createToolRegistry } from "./tools/registry.js";
26
+ export { PRESET_TOOLS, effectiveCodemodeMode } from "./tools/presets.js";
27
+ export { createRuntimeDeps, DEFAULT_TOOL_FACTORIES } from "./cli/compose.js";
28
+ export { currentSession, switchSession } from "./cli/compose-session.js";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 斜杠命令语义层(line 模式与 B7 交互模式共用,不含渲染)。[B6]
3
+ *
4
+ * `runSlashCommand(line, ctx)`:
5
+ * - 不是内置命令(含 `/skill:<name>` 与提示模板 `/<模板名>`)→ undefined,调用方把整行当提示发出,
6
+ * 展开在会话的 expandPrompt 里做;
7
+ * - 内置命令 → `CommandResult`:`handled`(可带一段给用户看的文本)、`prompt`(改发这段文本)、
8
+ * `pick`(需要界面弹选择器,参数缺省时)、`exit`。
9
+ *
10
+ * 会话切换(/new /resume /fork)经 `ctx.switchSession`,调用方据返回的新会话重新订阅事件。
11
+ */
12
+ import type { AgentSession } from "../agent/types.js";
13
+ import type { SwitchRequest } from "../cli/compose-session.js";
14
+ import type { Runtime } from "../cli/runtime.js";
15
+ export { describeSession } from "./session-report.js";
16
+ export type CommandResult = {
17
+ kind: "handled";
18
+ message?: string;
19
+ } | {
20
+ kind: "prompt";
21
+ text: string;
22
+ } | {
23
+ kind: "pick";
24
+ what: "model" | "session" | "tree" | "permission" | "thinking";
25
+ } | {
26
+ kind: "exit";
27
+ };
28
+ export interface CommandContext {
29
+ readonly runtime: Runtime;
30
+ /** 当前会话(切换后是新的那个)。 */
31
+ session(): AgentSession;
32
+ switchSession(request: SwitchRequest): Promise<AgentSession>;
33
+ }
34
+ export interface CommandInfo {
35
+ name: string;
36
+ args?: string;
37
+ description: string;
38
+ }
39
+ export declare const BUILTIN_COMMANDS: readonly CommandInfo[];
40
+ export declare function parseSlash(line: string): {
41
+ name: string;
42
+ args: string;
43
+ } | undefined;
44
+ export declare function runSlashCommand(line: string, ctx: CommandContext): Promise<CommandResult | undefined>;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * 斜杠命令语义层(line 模式与 B7 交互模式共用,不含渲染)。[B6]
3
+ *
4
+ * `runSlashCommand(line, ctx)`:
5
+ * - 不是内置命令(含 `/skill:<name>` 与提示模板 `/<模板名>`)→ undefined,调用方把整行当提示发出,
6
+ * 展开在会话的 expandPrompt 里做;
7
+ * - 内置命令 → `CommandResult`:`handled`(可带一段给用户看的文本)、`prompt`(改发这段文本)、
8
+ * `pick`(需要界面弹选择器,参数缺省时)、`exit`。
9
+ *
10
+ * 会话切换(/new /resume /fork)经 `ctx.switchSession`,调用方据返回的新会话重新订阅事件。
11
+ */
12
+ import { AgentSessionImpl } from "../agent/session.js";
13
+ import { WARMING_MODES } from "../ai/cache/types.js";
14
+ import { THINKING_LEVELS } from "../ai/thinking.js";
15
+ import { AmaError } from "../errors.js";
16
+ import { PERMISSION_MODES_STRICT_FIRST } from "../permissions/types.js";
17
+ import { describeCache, describeFingerprint, describeSession } from "./session-report.js";
18
+ export { describeSession } from "./session-report.js";
19
+ export const BUILTIN_COMMANDS = [
20
+ { name: "help", description: "列出命令" },
21
+ { name: "new", description: "新建会话" },
22
+ { name: "resume", args: "[id]", description: "恢复会话(无 id 时选择)" },
23
+ { name: "fork", args: "[条目 id]", description: "从某条目分叉出新会话" },
24
+ { name: "compact", args: "[说明]", description: "压缩上下文" },
25
+ { name: "model", args: "[provider/id]", description: "切换模型" },
26
+ {
27
+ name: "thinking",
28
+ args: "[级别]",
29
+ description: "思考级别 off | minimal | low | medium | high | xhigh",
30
+ },
31
+ {
32
+ name: "permission",
33
+ args: "[模式]",
34
+ description: "权限模式 plan | default | auto-edit | full-auto",
35
+ },
36
+ { name: "tools", args: "[名字…]", description: "列出 / 设置活动工具" },
37
+ { name: "hooks", description: "列出已加载的 Hook" },
38
+ { name: "session", description: "会话信息、用量与缓存" },
39
+ {
40
+ name: "cache",
41
+ args: "[warm off|streaming|idle | fingerprint]",
42
+ description: "缓存统计;切换本会话保温;打印前缀指纹",
43
+ },
44
+ { name: "exit", description: "退出" },
45
+ ];
46
+ const ALIASES = { quit: "exit", q: "exit", "?": "help" };
47
+ export function parseSlash(line) {
48
+ const m = /^\/([A-Za-z?][\w-]*)(?:\s+([\s\S]*))?$/.exec(line.trim());
49
+ if (m === null)
50
+ return undefined;
51
+ const raw = m[1].toLowerCase();
52
+ return { name: ALIASES[raw] ?? raw, args: (m[2] ?? "").trim() };
53
+ }
54
+ function helpText() {
55
+ const lines = BUILTIN_COMMANDS.map((c) => `/${c.name}${c.args !== undefined ? ` ${c.args}` : ""} ${c.description}`);
56
+ return [...lines, "/skill:<名字> [参数] 使用 Skill", "/<模板名> [参数] 展开提示模板"].join("\n");
57
+ }
58
+ function toolNames(args) {
59
+ return args
60
+ .split(/[\s,]+/)
61
+ .map((s) => s.trim())
62
+ .filter((s) => s !== "");
63
+ }
64
+ /** `/cache`、`/cache warm <模式>`、`/cache fingerprint`。 */
65
+ function cacheCommand(session, args) {
66
+ const [sub, value, extra] = args.split(/\s+/).filter((s) => s !== "");
67
+ if (sub === undefined)
68
+ return describeCache(session);
69
+ if (sub === "fingerprint" && value === undefined)
70
+ return describeFingerprint(session);
71
+ if (sub === "warm" && extra === undefined) {
72
+ if (!(session instanceof AgentSessionImpl))
73
+ throw new AmaError("invalid_arguments", "当前会话不支持切换保温");
74
+ if (value === undefined)
75
+ return `保温:${session.cache.mode()}`;
76
+ if (!WARMING_MODES.includes(value))
77
+ throw new AmaError("invalid_arguments", `保温模式应为 ${WARMING_MODES.join(" | ")}`);
78
+ session.cache.setWarming(value);
79
+ return `保温:${session.cache.mode()}(本会话)`;
80
+ }
81
+ throw new AmaError("invalid_arguments", "用法:/cache [warm off|streaming|idle | fingerprint]");
82
+ }
83
+ export async function runSlashCommand(line, ctx) {
84
+ const parsed = parseSlash(line);
85
+ if (parsed === undefined)
86
+ return undefined;
87
+ const { name, args } = parsed;
88
+ const session = ctx.session();
89
+ switch (name) {
90
+ case "help":
91
+ return { kind: "handled", message: helpText() };
92
+ case "exit":
93
+ return { kind: "exit" };
94
+ case "new": {
95
+ const next = await ctx.switchSession({ kind: "new" });
96
+ return { kind: "handled", message: `已新建会话 ${next.state.sessionId.slice(0, 8)}` };
97
+ }
98
+ case "resume": {
99
+ if (args === "")
100
+ return { kind: "pick", what: "session" };
101
+ const next = await ctx.switchSession({ kind: "resume", id: args });
102
+ return {
103
+ kind: "handled",
104
+ message: `已恢复会话 ${next.state.sessionId.slice(0, 8)}(${next.messages.length} 条消息)`,
105
+ };
106
+ }
107
+ case "fork": {
108
+ if (args === "")
109
+ return { kind: "pick", what: "tree" };
110
+ const next = await ctx.switchSession({ kind: "fork", entryId: args });
111
+ return { kind: "handled", message: `已分叉到新会话 ${next.state.sessionId.slice(0, 8)}` };
112
+ }
113
+ case "compact": {
114
+ const result = await session.compact(args === "" ? undefined : args);
115
+ const after = result.tokensAfter !== undefined ? ` → ${result.tokensAfter}` : "";
116
+ return { kind: "handled", message: `已压缩:${result.tokensBefore}${after} token` };
117
+ }
118
+ case "model": {
119
+ if (args === "")
120
+ return { kind: "pick", what: "model" };
121
+ await session.setModel(args);
122
+ const model = session.state.model;
123
+ return { kind: "handled", message: `模型:${model?.provider}/${model?.id}` };
124
+ }
125
+ case "thinking": {
126
+ if (args === "")
127
+ return { kind: "pick", what: "thinking" };
128
+ if (!THINKING_LEVELS.includes(args))
129
+ throw new AmaError("invalid_arguments", `思考级别应为 ${THINKING_LEVELS.join(" | ")}`);
130
+ session.setThinkingLevel(args);
131
+ return { kind: "handled", message: `思考级别:${args}` };
132
+ }
133
+ case "permission": {
134
+ if (args === "")
135
+ return { kind: "pick", what: "permission" };
136
+ if (!PERMISSION_MODES_STRICT_FIRST.includes(args)) {
137
+ throw new AmaError("invalid_arguments", `权限模式应为 ${PERMISSION_MODES_STRICT_FIRST.join(" | ")}`);
138
+ }
139
+ session.setPermissionMode(args);
140
+ return { kind: "handled", message: `权限模式:${args}` };
141
+ }
142
+ case "tools": {
143
+ if (args !== "")
144
+ session.setActiveTools(toolNames(args));
145
+ const active = session.getTools().map((t) => t.name);
146
+ const all = ctx.runtime.tools.list();
147
+ const inactive = all.filter((n) => !active.includes(n));
148
+ return {
149
+ kind: "handled",
150
+ message: `活动:${active.join(", ") || "(无)"}${inactive.length > 0 ? `\n可用:${inactive.join(", ")}` : ""}`,
151
+ };
152
+ }
153
+ case "hooks": {
154
+ const hooks = ctx.runtime.hooks.list();
155
+ if (hooks.length === 0)
156
+ return { kind: "handled", message: "没有已加载的 Hook" };
157
+ return {
158
+ kind: "handled",
159
+ message: hooks
160
+ .map((h) => `${h.source} ${h.event}${h.matcher !== undefined ? ` [${h.matcher}]` : ""} → ${h.command}`)
161
+ .join("\n"),
162
+ };
163
+ }
164
+ case "session":
165
+ return { kind: "handled", message: describeSession(session) };
166
+ case "cache":
167
+ return { kind: "handled", message: cacheCommand(session, args) };
168
+ default:
169
+ return undefined;
170
+ }
171
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * 审批对话框(设计 §12.6):模式层的 UI `ApprovalBroker`,底部覆盖层。[B7]
3
+ *
4
+ * - 标题行:`[task]`(`request.context.depth > 0`,子 Agent 发起)+ 工具名 + 原因标签;
5
+ * - 输入:bash 显示命令全文,write 显示路径与行数,edit 显示路径与每处修改的 −/+ 摘要,其它显示
6
+ * 一行摘要;`v` 展开 / 收起完整输入(JSON);
7
+ * - 执行前预览(W3-B9a-2,`request.preview`):输入摘要之后列出会碰到的路径与规模,danger 红、
8
+ * warn 黄、info 暗色;`other` 类预览与输入摘要重复,不显示;
9
+ * - 原因:mode(当前权限模式需要确认)/ dangerous / hook + Hook 给的文本;
10
+ * - 按键:`y` 允许、`n` / Esc / Ctrl+C 拒绝、`a` 本会话允许同类;
11
+ * - 超时与中断:broker 链在超时(缺省 10 分钟)或运行被中断时 abort `signal`,对话框关闭并返回
12
+ * undefined(链按 deny 处理),消息区留一行说明。
13
+ *
14
+ * broker 链本身串行化审批,所以同一时刻最多一个对话框。
15
+ */
16
+ import type { ApprovalBroker, ApprovalDecision, ApprovalRequest } from "../../permissions/types.js";
17
+ import { type Component, type Keybindings, type OverlayHandle, type Theme } from "../../tui.js";
18
+ export interface ApprovalHost {
19
+ theme: Theme;
20
+ keybindings?: Keybindings;
21
+ /** 路径显示的基准。 */
22
+ cwd?: string;
23
+ /** 当前权限模式(原因为 mode 时显示)。 */
24
+ permissionMode(): string;
25
+ showOverlay(component: Component): OverlayHandle;
26
+ /** 对话框打开 / 关闭(交互模式据此禁用编辑器提交、重画)。 */
27
+ onOpen?(): void;
28
+ onClose?(): void;
29
+ /** 结果说明(消息区一行)。 */
30
+ report?(request: ApprovalRequest, outcome: ApprovalDecision | "cancelled"): void;
31
+ }
32
+ /** 对话框正文(不含按键行)。 */
33
+ export declare function describeRequest(request: ApprovalRequest, theme: Theme, options?: {
34
+ cwd?: string;
35
+ permissionMode?: string;
36
+ expanded?: boolean;
37
+ }): string[];
38
+ export declare const APPROVAL_KEYS_HINT = "[y] \u5141\u8BB8 [n] \u62D2\u7EDD [a] \u672C\u4F1A\u8BDD\u5141\u8BB8\u540C\u7C7B [v] \u5B8C\u6574\u8F93\u5165";
39
+ /** UI broker:每个请求开一个底部覆盖层,等用户按键或 signal abort。 */
40
+ export declare class ApprovalDialogBroker implements ApprovalBroker {
41
+ private readonly host;
42
+ private open;
43
+ constructor(host: ApprovalHost);
44
+ get isOpen(): boolean;
45
+ ask(request: ApprovalRequest, signal: AbortSignal): Promise<ApprovalDecision | undefined>;
46
+ }
47
+ /** 结果的一行说明(消息区)。 */
48
+ export declare function approvalOutcomeText(request: ApprovalRequest, outcome: ApprovalDecision | "cancelled"): string;