@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,249 @@
1
+ /**
2
+ * 权限规则(设计 §7.2、§5.2「通用安全」)。[B3]
3
+ *
4
+ * 语法:`tool` 或 `tool(pattern)`;`tool` 是工具名 glob(`canvas_*`、`*`);pattern:
5
+ * - bash:对命令文本做通配(`*` 任意字符含空格与 `/`,`?` 单字符),命令先折叠空白;
6
+ * - 带 `path` 的工具(read / write / edit / ls / grep / glob 及宿主工具):对路径做 glob(`**`)。
7
+ * 相对模式匹配 cwd 内的相对路径;以 `**` 开头的模式也匹配绝对路径(例如 .ssh 目录规则命中 ~/.ssh 下的文件);
8
+ * 绝对模式(`/…`、`~/…`)匹配绝对路径。缺 path 的调用以 cwd 为路径。
9
+ * - 其它工具带 pattern 的规则不匹配(无可比对的对象)。
10
+ *
11
+ * bash 复合命令:deny 规则命中整条或**任一**段即生效;allow 规则要求**每一**段都被某条 allow 覆盖,
12
+ * 且命令里没有 `$(…)` / 反引号替换——否则 allow 不生效(回到「问」)。
13
+ *
14
+ * 来源约束(§7.2):项目级只能收紧——allow 被忽略、mode 只能更严,均产生 warning。
15
+ */
16
+ import { isAbsolute, relative, resolve } from "node:path";
17
+ import { AmaError } from "../errors.js";
18
+ import { PERMISSION_MODES_STRICT_FIRST } from "./types.js";
19
+ import { globBody } from "../tools/glob.js";
20
+ import { expandHome, resolvePath, toPosix } from "../tools/paths.js";
21
+ /** 内置缺省 deny 表(用户可经 `builtinDeny` 选项移除)。 */
22
+ export const BUILTIN_DENY_RULES = [
23
+ "write(**/.git/**)",
24
+ "edit(**/.git/**)",
25
+ "read(**/.ssh/**)",
26
+ "write(**/.ssh/**)",
27
+ "edit(**/.ssh/**)",
28
+ ];
29
+ const RULE_RE = /^([A-Za-z0-9_*?]+)(?:\((.*)\))?$/s;
30
+ export function parseRule(raw, effect, source) {
31
+ const text = raw.trim();
32
+ const m = RULE_RE.exec(text);
33
+ if (!m || (m[2] !== undefined && m[2].trim() === "")) {
34
+ throw new AmaError("invalid_arguments", `Invalid permission rule "${raw}"`);
35
+ }
36
+ const rule = { effect, tool: m[1], source, raw: text };
37
+ if (m[2] !== undefined)
38
+ rule.pattern = m[2].trim();
39
+ return rule;
40
+ }
41
+ export function wildcardToRegExp(pattern) {
42
+ let out = "";
43
+ for (const ch of pattern) {
44
+ if (ch === "*")
45
+ out += "[\\s\\S]*";
46
+ else if (ch === "?")
47
+ out += "[\\s\\S]";
48
+ else
49
+ out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
50
+ }
51
+ return new RegExp(`^${out}$`);
52
+ }
53
+ export function toolNameMatches(ruleTool, toolName) {
54
+ return ruleTool === toolName || wildcardToRegExp(ruleTool).test(toolName);
55
+ }
56
+ export function normalizeCommand(command) {
57
+ return command.trim().replace(/\s+/g, " ");
58
+ }
59
+ /**
60
+ * 按 `&&`、`||`、`;`、`|`、`&`、换行切分(引号内不切),每段 trim 后返回非空段。
61
+ */
62
+ export function splitShellSegments(command) {
63
+ const out = [];
64
+ let cur = "";
65
+ let quote;
66
+ for (let i = 0; i < command.length; i++) {
67
+ const ch = command[i];
68
+ if (quote) {
69
+ cur += ch;
70
+ if (ch === "\\" && quote === '"' && i + 1 < command.length)
71
+ cur += command[++i];
72
+ else if (ch === quote)
73
+ quote = undefined;
74
+ continue;
75
+ }
76
+ if (ch === "'" || ch === '"') {
77
+ quote = ch;
78
+ cur += ch;
79
+ }
80
+ else if (ch === "\\" && i + 1 < command.length) {
81
+ cur += ch + command[++i];
82
+ }
83
+ else if (ch === ";" || ch === "\n" || ch === "|" || ch === "&") {
84
+ // `>&2`、`2>&1`、`&>` 是重定向不是分隔。
85
+ if (ch === "&" && (command[i - 1] === ">" || command[i + 1] === ">")) {
86
+ cur += ch;
87
+ continue;
88
+ }
89
+ out.push(cur);
90
+ cur = "";
91
+ if ((ch === "|" || ch === "&") && command[i + 1] === ch)
92
+ i++;
93
+ }
94
+ else {
95
+ cur += ch;
96
+ }
97
+ }
98
+ out.push(cur);
99
+ return out.map((s) => normalizeCommand(s)).filter((s) => s !== "");
100
+ }
101
+ export function hasCommandSubstitution(command) {
102
+ return /\$\(|`|<\(|>\(/.test(command);
103
+ }
104
+ function pathGlob(pattern) {
105
+ return new RegExp(`^${globBody(pattern, { braces: true })}$`);
106
+ }
107
+ /** 输入里的路径(绝对);没有 path 字段的工具返回 undefined。 */
108
+ export function inputPath(toolName, input, cwd) {
109
+ const raw = typeof input === "object" && input !== null
110
+ ? input["path"]
111
+ : undefined;
112
+ if (typeof raw === "string") {
113
+ try {
114
+ return resolvePath(raw, cwd);
115
+ }
116
+ catch {
117
+ return undefined;
118
+ }
119
+ }
120
+ if (["read", "write", "edit", "ls", "grep", "glob"].includes(toolName))
121
+ return resolvePath(".", cwd);
122
+ return undefined;
123
+ }
124
+ export function inputCommand(input) {
125
+ const raw = typeof input === "object" && input !== null
126
+ ? input["command"]
127
+ : undefined;
128
+ return typeof raw === "string" ? raw : undefined;
129
+ }
130
+ export function pathMatches(pattern, absPath, cwd) {
131
+ const absPosix = toPosix(absPath);
132
+ const expanded = expandHome(pattern);
133
+ if (isAbsolute(expanded))
134
+ return pathGlob(toPosix(resolve(expanded))).test(absPosix);
135
+ const regex = pathGlob(pattern.replace(/^\.\//, ""));
136
+ const rel = relative(cwd, absPath);
137
+ const inside = rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
138
+ if (inside && regex.test(toPosix(rel)))
139
+ return true;
140
+ if (rel === "" && (pattern === "**" || pattern === "*" || pattern === "."))
141
+ return true;
142
+ return pattern.startsWith("**") && regex.test(absPosix.replace(/^\/+/, ""));
143
+ }
144
+ /** 单条规则对一个(非复合)对象是否命中。 */
145
+ function matchesSubject(rule, toolName, input, cwd, command) {
146
+ if (!toolNameMatches(rule.tool, toolName))
147
+ return false;
148
+ if (rule.pattern === undefined)
149
+ return true;
150
+ if (command !== undefined)
151
+ return wildcardToRegExp(rule.pattern).test(command);
152
+ const abs = inputPath(toolName, input, cwd);
153
+ return abs !== undefined && pathMatches(rule.pattern, abs, cwd);
154
+ }
155
+ /** 第一条命中的 deny 规则。 */
156
+ export function findDenyRule(rules, toolName, input, cwd) {
157
+ const command = inputCommand(input);
158
+ for (const rule of rules) {
159
+ if (rule.effect !== "deny")
160
+ continue;
161
+ if (command === undefined || rule.pattern === undefined) {
162
+ if (matchesSubject(rule, toolName, input, cwd))
163
+ return rule;
164
+ continue;
165
+ }
166
+ const subjects = [normalizeCommand(command), ...splitShellSegments(command)];
167
+ if (subjects.some((s) => matchesSubject(rule, toolName, input, cwd, s)))
168
+ return rule;
169
+ }
170
+ return undefined;
171
+ }
172
+ /** 覆盖本次调用的 allow 规则(复合命令返回第一段的覆盖者);不覆盖返回 undefined。 */
173
+ export function findAllowRule(rules, toolName, input, cwd) {
174
+ const allows = rules.filter((r) => r.effect === "allow");
175
+ const command = inputCommand(input);
176
+ if (command === undefined)
177
+ return allows.find((r) => matchesSubject(r, toolName, input, cwd));
178
+ const unconditional = allows.find((r) => r.pattern === undefined && toolNameMatches(r.tool, toolName));
179
+ if (unconditional)
180
+ return unconditional;
181
+ if (hasCommandSubstitution(command))
182
+ return undefined;
183
+ const segments = splitShellSegments(command);
184
+ if (segments.length === 0)
185
+ return undefined;
186
+ let first;
187
+ for (const seg of segments) {
188
+ const hit = allows.find((r) => matchesSubject(r, toolName, input, cwd, seg));
189
+ if (!hit)
190
+ return undefined;
191
+ first ??= hit;
192
+ }
193
+ return first;
194
+ }
195
+ // ---------------------------------------------------------------------------
196
+ // 来源合并与收紧校验
197
+ // ---------------------------------------------------------------------------
198
+ /** a 是否比 b 更严(或相等)。 */
199
+ export function isAtLeastAsStrict(a, b) {
200
+ return PERMISSION_MODES_STRICT_FIRST.indexOf(a) <= PERMISSION_MODES_STRICT_FIRST.indexOf(b);
201
+ }
202
+ /**
203
+ * 按给定顺序(调用方排好:用户级 → profile → 项目级 → 命令行)合并。项目级只能收紧。
204
+ * 不合法的规则文本记 warning 并跳过。
205
+ */
206
+ export function resolvePermissionLayers(layers, options = {}) {
207
+ const warnings = [];
208
+ const rules = [];
209
+ const removed = options.builtinDeny;
210
+ if (removed !== false) {
211
+ for (const raw of BUILTIN_DENY_RULES) {
212
+ if (Array.isArray(removed) && removed.includes(raw))
213
+ continue;
214
+ rules.push(parseRule(raw, "deny", "builtin"));
215
+ }
216
+ }
217
+ let mode = options.defaultMode ?? "default";
218
+ const add = (raw, effect, source) => {
219
+ try {
220
+ rules.push(parseRule(raw, effect, source));
221
+ }
222
+ catch (err) {
223
+ warnings.push(`${source}: ${err.message}`);
224
+ }
225
+ };
226
+ for (const layer of layers) {
227
+ const restricted = layer.source === "project";
228
+ if (layer.mode !== undefined) {
229
+ if (!PERMISSION_MODES_STRICT_FIRST.includes(layer.mode)) {
230
+ warnings.push(`${layer.source}: unknown permission mode "${String(layer.mode)}"`);
231
+ }
232
+ else if (restricted && !isAtLeastAsStrict(layer.mode, mode)) {
233
+ warnings.push(`project config cannot relax permission mode from "${mode}" to "${layer.mode}"; ignored`);
234
+ }
235
+ else {
236
+ mode = layer.mode;
237
+ }
238
+ }
239
+ for (const raw of layer.deny ?? [])
240
+ add(raw, "deny", layer.source);
241
+ for (const raw of layer.allow ?? []) {
242
+ if (restricted)
243
+ warnings.push(`project config cannot add allow rule "${raw}"; ignored`);
244
+ else
245
+ add(raw, "allow", layer.source);
246
+ }
247
+ }
248
+ return { mode, rules, warnings };
249
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * 权限契约(设计 §6.2–§6.3、§7)。[B0] 契约文件,实现归 B3。
3
+ *
4
+ * 补全与偏差:
5
+ * - `ApprovalRequest / ApprovalDecision / ApprovalBroker` 在设计 §6.2 写在 host 契约里,
6
+ * §1.2 又把 ApprovalRequest 列在本文件。统一定义在这里,host/types.ts 再导出。
7
+ * - 设计只写了 `Rule、Mode、Decision`;补全 `RuleSource`、`PermissionCheckInput`、
8
+ * `PermissionVerdict`(带决定来自哪一步)与 Runtime 需要的 `PermissionPipelineApi`。
9
+ * - (W3-C0)执行前预览(第三波 §2.2):`ActionPreview` 定义在这里,`ApprovalRequest.preview`
10
+ * 与 `permission_request` 事件携带;`ApprovalRequestContext.readFiles` 供 write 预览判断
11
+ * 「覆盖未读过的文件」。`previewAction()` 实现归 W3-B9a-2。
12
+ */
13
+ import type { ToolPermission } from "../tools/types.js";
14
+ /** 严格程度:plan > default > auto-edit > full-auto(项目级只能往左收紧,§7.2)。 */
15
+ export type PermissionMode = "plan" | "default" | "auto-edit" | "full-auto";
16
+ export declare const PERMISSION_MODES_STRICT_FIRST: readonly PermissionMode[];
17
+ export type Decision = "allow" | "ask" | "deny";
18
+ export type RuleSource = "builtin" | "user" | "profile" | "project" | "cli" | "sdk";
19
+ /** `bash(git push*)`、`write(src/**)`、`read(**)`、`canvas_*` 解析结果。 */
20
+ export interface Rule {
21
+ effect: "allow" | "deny";
22
+ /** 工具名 glob。 */
23
+ tool: string;
24
+ /** 括号内的 glob:bash 对命令文本,文件工具对路径;缺省匹配全部。 */
25
+ pattern?: string;
26
+ source: RuleSource;
27
+ /** 原始文本,用于诊断。 */
28
+ raw: string;
29
+ }
30
+ export type ApprovalReason = "mode" | "dangerous" | "hook";
31
+ export interface ApprovalRequest {
32
+ requestId: string;
33
+ toolName: string;
34
+ input: unknown;
35
+ reason: ApprovalReason;
36
+ hookReason?: string;
37
+ /** [W3-C0] 执行前预览(只读、有上限);预览超时或未实现时缺省。 */
38
+ preview?: ActionPreview;
39
+ /**
40
+ * 发起方上下文:`depth > 0` 表示来自 `task` 子 Agent(对话框标 `[task]`);codemode 内层
41
+ * 调用带外层调用的 `parentToolCallId`。由子会话包装的 broker 填入,缺省视为主会话。
42
+ */
43
+ context?: ApprovalRequestContext;
44
+ }
45
+ export interface ApprovalRequestContext {
46
+ depth: number;
47
+ parentToolCallId?: string;
48
+ /** [W3-C0] 本会话已 read 过的路径(`ToolContext.readFiles`),由 `gateToolCall` 填入。 */
49
+ readFiles?: ReadonlySet<string>;
50
+ }
51
+ /** [W3-C0] 预览涉及的路径(bash 的 rm / mv / 重定向目标,write / edit 的目标文件)。 */
52
+ export interface ActionPreviewTarget {
53
+ path: string;
54
+ exists: boolean;
55
+ bytes?: number;
56
+ /** 目录递归计数(上限外不再计)。 */
57
+ files?: number;
58
+ }
59
+ /** [W3-C0] 审批时「这一步会碰到什么」(第三波 §2.2)。线上形状,可 JSON 序列化。 */
60
+ export interface ActionPreview {
61
+ kind: "bash" | "write" | "edit" | "other";
62
+ /** 已排好的人读文本(不含颜色)。 */
63
+ lines: string[];
64
+ severity: "info" | "warn" | "danger";
65
+ affected?: ActionPreviewTarget[];
66
+ }
67
+ export type ApprovalDecision = "allow" | "deny" | "allow_session";
68
+ /** 返回 undefined 表示交给链上下一个回答者(宿主 → UI → 无人值守 deny)。 */
69
+ export interface ApprovalBroker {
70
+ ask(request: ApprovalRequest, signal: AbortSignal): Promise<ApprovalDecision | undefined>;
71
+ }
72
+ export interface PermissionCheckInput {
73
+ toolName: string;
74
+ permission: ToolPermission;
75
+ input: unknown;
76
+ /** 命令式 Hook PreToolUse 合并后的决策(§6.3 第 2 步);无决策为 undefined。 */
77
+ hookDecision?: Decision;
78
+ hookReason?: string;
79
+ /** 无人值守:ask → deny。 */
80
+ unattended: boolean;
81
+ }
82
+ /** 管线哪一步做出了最终决定。 */
83
+ export type PermissionStep = "deny-rule" | "hook-deny" | "dangerous" | "mode" | "allow-rule" | "hook" | "session";
84
+ export interface PermissionVerdict {
85
+ decision: Decision;
86
+ step: PermissionStep;
87
+ /** decision 为 ask 时给 broker 的 reason。 */
88
+ approvalReason?: ApprovalReason;
89
+ rule?: Rule;
90
+ /** 给模型 / 用户看的说明(deny 时写进 tool_result)。 */
91
+ message?: string;
92
+ }
93
+ export interface PermissionPipelineApi {
94
+ readonly mode: PermissionMode;
95
+ setMode(mode: PermissionMode): void;
96
+ readonly rules: readonly Rule[];
97
+ check(input: PermissionCheckInput): PermissionVerdict;
98
+ /** allow_session:内存记住 toolName + 归一化输入前缀,不落盘。 */
99
+ rememberForSession(toolName: string, input: unknown): void;
100
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 权限契约(设计 §6.2–§6.3、§7)。[B0] 契约文件,实现归 B3。
3
+ *
4
+ * 补全与偏差:
5
+ * - `ApprovalRequest / ApprovalDecision / ApprovalBroker` 在设计 §6.2 写在 host 契约里,
6
+ * §1.2 又把 ApprovalRequest 列在本文件。统一定义在这里,host/types.ts 再导出。
7
+ * - 设计只写了 `Rule、Mode、Decision`;补全 `RuleSource`、`PermissionCheckInput`、
8
+ * `PermissionVerdict`(带决定来自哪一步)与 Runtime 需要的 `PermissionPipelineApi`。
9
+ * - (W3-C0)执行前预览(第三波 §2.2):`ActionPreview` 定义在这里,`ApprovalRequest.preview`
10
+ * 与 `permission_request` 事件携带;`ApprovalRequestContext.readFiles` 供 write 预览判断
11
+ * 「覆盖未读过的文件」。`previewAction()` 实现归 W3-B9a-2。
12
+ */
13
+ export const PERMISSION_MODES_STRICT_FIRST = [
14
+ "plan",
15
+ "default",
16
+ "auto-edit",
17
+ "full-auto",
18
+ ];
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,171 @@
1
+ /**
2
+ * `@armadra/agent/rpc`:RPC(stdio JSONL,`--mode rpc`)命令 / 响应 / 事件类型(设计 §13.2,
3
+ * 框架沿用 v1 §8.4)。[B0] 契约文件,实现归 B6(modes/rpc/、modes/print/json-event.ts)。
4
+ *
5
+ * 补全与偏差:
6
+ * - 设计只列了命令名;参数形状按 v1 §8.4 补全,新增命令(get_available_thinking_levels、
7
+ * set_auto_retry、abort_retry、get_fork_messages、set_permission_mode、get_commands、
8
+ * get_skills)按名字含义补全。
9
+ * - 线上事件 = 进程内 `SessionEvent`,但 `message_update` 换成纯增量(去掉 partial / 累计消息,
10
+ * 附最新 usage);stream-json 输出同一形状。
11
+ * - 类型定义直接放在本文件(B6 实现 import 它),避免子路径入口依赖实现文件。
12
+ */
13
+ import type { AssistantEvent, ImageBlock, ModelThinkingLevel, Usage } from "./ai/types.js";
14
+ import type { QueueMode, SessionEvent } from "./agent/types.js";
15
+ import type { ApprovalDecision, PermissionMode } from "./permissions/types.js";
16
+ export type { SessionEvent } from "./agent/types.js";
17
+ export declare const RPC_PROTOCOL_VERSION: 1;
18
+ export type RpcCapability = "approvals" | "images" | "hooks";
19
+ export interface RpcHello {
20
+ type: "hello";
21
+ protocolVersion: typeof RPC_PROTOCOL_VERSION;
22
+ agent: "ama";
23
+ version: string;
24
+ capabilities: RpcCapability[];
25
+ }
26
+ /** 无参数命令。 */
27
+ export type NoParams = Record<never, never>;
28
+ export interface RpcCommandMap {
29
+ prompt: {
30
+ message: string;
31
+ images?: ImageBlock[];
32
+ streamingBehavior?: "steer" | "followUp";
33
+ };
34
+ steer: {
35
+ message: string;
36
+ images?: ImageBlock[];
37
+ };
38
+ follow_up: {
39
+ message: string;
40
+ images?: ImageBlock[];
41
+ };
42
+ abort: NoParams;
43
+ clear_queue: NoParams;
44
+ get_state: NoParams;
45
+ get_messages: NoParams;
46
+ get_last_assistant_text: NoParams;
47
+ get_session_stats: NoParams;
48
+ set_model: {
49
+ provider: string;
50
+ modelId: string;
51
+ };
52
+ get_available_models: NoParams;
53
+ set_thinking_level: {
54
+ level: ModelThinkingLevel;
55
+ };
56
+ get_available_thinking_levels: NoParams;
57
+ set_steering_mode: {
58
+ mode: QueueMode;
59
+ };
60
+ set_follow_up_mode: {
61
+ mode: QueueMode;
62
+ };
63
+ compact: {
64
+ customInstructions?: string;
65
+ };
66
+ set_auto_compaction: {
67
+ enabled: boolean;
68
+ };
69
+ set_auto_retry: {
70
+ enabled: boolean;
71
+ };
72
+ abort_retry: NoParams;
73
+ new_session: {
74
+ parentSession?: string;
75
+ };
76
+ switch_session: {
77
+ sessionPath: string;
78
+ };
79
+ fork: {
80
+ entryId: string;
81
+ };
82
+ get_entries: {
83
+ since?: string;
84
+ };
85
+ get_tree: NoParams;
86
+ set_session_name: {
87
+ name: string;
88
+ };
89
+ get_fork_messages: NoParams;
90
+ set_client_capabilities: {
91
+ capabilities: RpcCapability[];
92
+ };
93
+ permission_response: {
94
+ requestId: string;
95
+ decision: ApprovalDecision;
96
+ };
97
+ get_tools: NoParams;
98
+ set_active_tools: {
99
+ names: string[];
100
+ };
101
+ set_permission_mode: {
102
+ mode: PermissionMode;
103
+ };
104
+ get_commands: NoParams;
105
+ get_skills: NoParams;
106
+ }
107
+ export type RpcCommandType = keyof RpcCommandMap;
108
+ /** `{ id?, type, ...参数 }`。 */
109
+ export type RpcCommand = {
110
+ [K in RpcCommandType]: {
111
+ id?: string;
112
+ type: K;
113
+ } & RpcCommandMap[K];
114
+ }[RpcCommandType];
115
+ export type RpcCommandOf<K extends RpcCommandType> = Extract<RpcCommand, {
116
+ type: K;
117
+ }>;
118
+ export interface RpcModelInfo {
119
+ provider: string;
120
+ id: string;
121
+ name: string;
122
+ /** 只报有无,不回密钥。 */
123
+ hasKey: boolean;
124
+ keySource: "cli" | "auth-file" | "config" | "env" | "none";
125
+ contextWindow?: number;
126
+ maxTokens: number;
127
+ reasoning: boolean;
128
+ input: ("text" | "image")[];
129
+ }
130
+ export interface RpcCommandInfo {
131
+ name: string;
132
+ description?: string;
133
+ source: "builtin" | "template" | "skill";
134
+ }
135
+ export interface RpcSuccessResponse<D = unknown> {
136
+ id?: string;
137
+ type: "response";
138
+ command: RpcCommandType;
139
+ success: true;
140
+ data?: D;
141
+ }
142
+ export interface RpcErrorResponse {
143
+ id?: string;
144
+ type: "response";
145
+ /** JSON 解析失败时为 "parse" 且无 id。 */
146
+ command: RpcCommandType | "parse";
147
+ success: false;
148
+ error: string;
149
+ /** AmaError.code(若有)。 */
150
+ code?: string;
151
+ }
152
+ export type RpcResponse<D = unknown> = RpcSuccessResponse<D> | RpcErrorResponse;
153
+ /** prompt / steer / follow_up 的 data。 */
154
+ export interface RpcPromptData {
155
+ disposition: "started" | "queued" | "handled";
156
+ }
157
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
158
+ /** 线上助手事件:去掉 partial;done / error 仍带最终 message。 */
159
+ export type WireAssistantEvent = DistributiveOmit<AssistantEvent, "partial">;
160
+ export interface WireMessageUpdate {
161
+ type: "message_update";
162
+ assistantMessageEvent: WireAssistantEvent;
163
+ /** 最新 usage(供应商流中可得时)。 */
164
+ usage?: Usage;
165
+ }
166
+ export type RpcEvent = Exclude<SessionEvent, {
167
+ type: "message_update";
168
+ }> | WireMessageUpdate;
169
+ export type RpcEventType = RpcEvent["type"];
170
+ /** stdout 上的一行。 */
171
+ export type RpcOutbound = RpcHello | RpcResponse | RpcEvent;
package/dist/rpc.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@armadra/agent/rpc`:RPC(stdio JSONL,`--mode rpc`)命令 / 响应 / 事件类型(设计 §13.2,
3
+ * 框架沿用 v1 §8.4)。[B0] 契约文件,实现归 B6(modes/rpc/、modes/print/json-event.ts)。
4
+ *
5
+ * 补全与偏差:
6
+ * - 设计只列了命令名;参数形状按 v1 §8.4 补全,新增命令(get_available_thinking_levels、
7
+ * set_auto_retry、abort_retry、get_fork_messages、set_permission_mode、get_commands、
8
+ * get_skills)按名字含义补全。
9
+ * - 线上事件 = 进程内 `SessionEvent`,但 `message_update` 换成纯增量(去掉 partial / 累计消息,
10
+ * 附最新 usage);stream-json 输出同一形状。
11
+ * - 类型定义直接放在本文件(B6 实现 import 它),避免子路径入口依赖实现文件。
12
+ */
13
+ export const RPC_PROTOCOL_VERSION = 1;
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * SDK(设计 §13.1、实施计划 §1.3 C2)。[B6]
3
+ *
4
+ * - `createRuntime(options)`:与 CLI 同一条启动序列(bootstrap 第 3–14 步 + 组装根),读用户级 /
5
+ * 项目级配置、AGENTS.md、Skill、hooks.json、auth.json;不进入任何模式。参数可以写成字段,
6
+ * 也可以直接给 `argv`(与 `ama` 命令行同语法)。
7
+ * - `createAgentSession(options)`:不读文件系统配置的轻量装配——内存会话(或传入的
8
+ * SessionManager)、选定的工具、规则与回调审批,直接返回 `AgentSessionImpl`
9
+ * (含 `addTool / updateSystem / navigate` 等扩展方法)。
10
+ *
11
+ * 两者共用组装根(cli/compose*.ts),审批链、系统提示装配、工具预设与缓存行为与 CLI 一致。
12
+ */
13
+ import type { ApiRegistry } from "./ai/apis/api.js";
14
+ import type { ModelThinkingLevel, ProviderData } from "./ai/types.js";
15
+ import type { AgentSessionImpl } from "./agent/session.js";
16
+ import { type LogFn } from "./cli/compose-session.js";
17
+ import { type ComposeOptions } from "./cli/compose.js";
18
+ import type { Runtime } from "./cli/runtime.js";
19
+ import type { AmaConfig, ToolsPreset } from "./config/types.js";
20
+ import type { HookConfig } from "./hooks/types.js";
21
+ import type { InstructionSource } from "./host/types.js";
22
+ import type { ApprovalDecision, ApprovalRequest, PermissionMode } from "./permissions/types.js";
23
+ import { SessionManager } from "./session/manager.js";
24
+ import type { ToolDefinition } from "./tools/types.js";
25
+ /** [W3-C2] 统计类型:`session.getStats()`、RPC `get_session_stats`、`-p --output-format json` 的 `cache`。 */
26
+ export type { SessionCacheStats, SessionStats } from "./agent/types.js";
27
+ export type { CacheMiss, CacheMissReason, CacheReporting, WarmerStatus, WarmingMode, } from "./ai/cache/types.js";
28
+ export interface RuntimeOptions {
29
+ cwd?: string;
30
+ /** 与 `ama` 命令行同语法的参数(字段优先于这里的同名参数)。 */
31
+ argv?: string[];
32
+ model?: string;
33
+ thinkingLevel?: ModelThinkingLevel;
34
+ permissionMode?: PermissionMode;
35
+ toolsPreset?: ToolsPreset;
36
+ /** 信任项目(项目级 Hook / Skill / 提示模板)。 */
37
+ trust?: boolean;
38
+ sessionDir?: string;
39
+ profile?: string;
40
+ /** true:无人值守(ask → deny),同 `ama -p`。 */
41
+ unattended?: boolean;
42
+ env?: NodeJS.ProcessEnv;
43
+ stderr?: (text: string) => void;
44
+ /** 组装根选项:追加供应商 / 协议 / 工具 / 工具工厂。 */
45
+ compose?: ComposeOptions;
46
+ }
47
+ export declare function createRuntime(options?: RuntimeOptions): Promise<Runtime>;
48
+ export type SessionAuth = {
49
+ kind: "file";
50
+ path: string;
51
+ } | {
52
+ kind: "env";
53
+ } | {
54
+ kind: "inline";
55
+ keys: Record<string, string>;
56
+ } | {
57
+ kind: "none";
58
+ };
59
+ export interface CreateSessionOptions {
60
+ cwd?: string;
61
+ /** `provider/model-id`;缺省 config.defaultModel,再缺省零配置选择(第一个有 key 的供应商)。 */
62
+ model?: string | {
63
+ provider: string;
64
+ id: string;
65
+ };
66
+ thinkingLevel?: ModelThinkingLevel;
67
+ /** 缺省:用户级 auth.json + 环境变量。 */
68
+ auth?: SessionAuth;
69
+ /** 追加 / 覆盖的供应商(fake 总是可用)。 */
70
+ providers?: ProviderData[];
71
+ apis?: ApiRegistry;
72
+ /** 缺省内存会话。 */
73
+ sessionManager?: SessionManager;
74
+ /** `default`(缺省,按预设)/ `none` / 指定工具全集。 */
75
+ tools?: "default" | "none" | ToolDefinition[];
76
+ toolsPreset?: ToolsPreset;
77
+ extraTools?: ToolDefinition[];
78
+ disableTools?: string[];
79
+ /** 进系统提示 host 节。 */
80
+ instructions?: InstructionSource[];
81
+ skillDirs?: string[];
82
+ /** 读 AGENTS.md(缺省 false)。 */
83
+ contextFiles?: boolean;
84
+ permission?: {
85
+ mode?: PermissionMode;
86
+ allow?: string[];
87
+ deny?: string[];
88
+ /** 审批回调;缺省无人作答 → deny。 */
89
+ ask?(request: ApprovalRequest, signal: AbortSignal): Promise<ApprovalDecision>;
90
+ };
91
+ /** 命令式 Hook(缺省不加载文件系统里的 hooks.json)。 */
92
+ hooks?: HookConfig | false;
93
+ config?: Partial<AmaConfig>;
94
+ unattended?: boolean;
95
+ onWarning?: (message: string) => void;
96
+ log?: LogFn;
97
+ }
98
+ export declare function createAgentSession(options?: CreateSessionOptions): Promise<AgentSessionImpl>;