@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,201 @@
1
+ /**
2
+ * 会话 JSONL 树契约(设计 §8,格式沿用 v1 §5)。[B0] 契约文件,实现归 B2。
3
+ *
4
+ * 补全与偏差:
5
+ * - `message` 条目只装 LLM 消息(`Message`:system / user / assistant / toolResult),
6
+ * 这样 session 不必反向依赖 agent。
7
+ * - 投影(projection.ts)产出的上下文消息 `AgentMessage` = `Message` + 三种非 LLM 角色
8
+ * (custom / compactionSummary / branchSummary),定义在这里,agent/types.ts 再导出;
9
+ * `convertToLlm` 负责把三种扩展角色转成 user 消息。
10
+ * - `context_edit.reason` 在 v1 的 prune / abort / manual 之外加 `retry`(§3.6 失败尝试剔除)
11
+ * 与 `overflow`(§9 溢出恢复剔除)。
12
+ * - `compaction` / `branch_summary` 的 details 统一为 `FileOpsDetails`。
13
+ * - 补全 `SessionTreeNode`、`SessionListItem` 与 B6 / B7 需要的 `SessionManagerApi`。
14
+ * `append()` 同步:返回带 id 的条目并把叶子移到它(落盘可延迟到首条提示,§11.1 第 16 步)。
15
+ * - (W3-C0)第三波 §1.7 / A7:新增 `usage` 条目(保温等不进上下文的请求用量,计入统计)与
16
+ * 非条目的 `leaf` 行(`/tree` 位置落盘);都是 v1 可选行,格式版本不升。
17
+ */
18
+ import type { ContentBlock, Message, ModelThinkingLevel, Usage } from "../ai/types.js";
19
+ export declare const SESSION_FORMAT_VERSION: 1;
20
+ export interface SessionHeader {
21
+ type: "session";
22
+ version: typeof SESSION_FORMAT_VERSION;
23
+ id: string;
24
+ /** ISO 8601。 */
25
+ timestamp: string;
26
+ cwd: string;
27
+ agent: {
28
+ name: "ama";
29
+ version: string;
30
+ };
31
+ /** fork / clone / task 的来源文件。 */
32
+ parentSession?: string;
33
+ }
34
+ export interface EntryBase {
35
+ id: string;
36
+ parentId: string | null;
37
+ /** ISO 8601。 */
38
+ timestamp: string;
39
+ }
40
+ export interface FileOpsDetails {
41
+ readFiles: string[];
42
+ modifiedFiles: string[];
43
+ }
44
+ export interface MessageEntry extends EntryBase {
45
+ type: "message";
46
+ message: Message;
47
+ }
48
+ export interface CompactionEntry extends EntryBase {
49
+ type: "compaction";
50
+ summary: string;
51
+ firstKeptEntryId: string;
52
+ tokensBefore: number;
53
+ usage?: Usage;
54
+ details?: FileOpsDetails;
55
+ }
56
+ export interface BranchSummaryEntry extends EntryBase {
57
+ type: "branch_summary";
58
+ fromId: string;
59
+ summary: string;
60
+ usage?: Usage;
61
+ details?: FileOpsDetails;
62
+ }
63
+ export type ContextEditReason = "prune" | "abort" | "retry" | "overflow" | "manual";
64
+ /** 同一目标最新一条赢;replacement 为 null 表示从上下文剔除。 */
65
+ export interface ContextEditEntry extends EntryBase {
66
+ type: "context_edit";
67
+ targetId: string;
68
+ replacement: string | null;
69
+ reason: ContextEditReason;
70
+ }
71
+ export interface ModelChangeEntry extends EntryBase {
72
+ type: "model_change";
73
+ provider: string;
74
+ modelId: string;
75
+ /** 所选渠道(多渠道供应商);没有时走模型的首选渠道。 */
76
+ channel?: string;
77
+ }
78
+ export interface ThinkingLevelChangeEntry extends EntryBase {
79
+ type: "thinking_level_change";
80
+ thinkingLevel: ModelThinkingLevel;
81
+ }
82
+ /** 不进上下文(如 ama.todo、ama.task)。 */
83
+ export interface CustomEntry extends EntryBase {
84
+ type: "custom";
85
+ customType: string;
86
+ data: unknown;
87
+ }
88
+ /** 进上下文(如 ama.aborted、Hook 的 additionalContext)。 */
89
+ export interface CustomMessageEntry extends EntryBase {
90
+ type: "custom_message";
91
+ customType: string;
92
+ content: string | ContentBlock[];
93
+ display: boolean;
94
+ details?: unknown;
95
+ }
96
+ export interface LabelEntry extends EntryBase {
97
+ type: "label";
98
+ targetId: string;
99
+ /** 缺省 = 清除标签。 */
100
+ label?: string;
101
+ }
102
+ export interface SessionInfoEntry extends EntryBase {
103
+ type: "session_info";
104
+ name?: string;
105
+ }
106
+ /** 不进上下文的请求用量的来源;第一期只有缓存保温。 */
107
+ export type UsageEntryKind = "cache_warm" | (string & {});
108
+ /**
109
+ * [W3-C0] 不进上下文的请求用量(第三波 §1.7):计入 `/session` 费用与 RPC 统计,投影跳过。
110
+ */
111
+ export interface UsageEntry extends EntryBase {
112
+ type: "usage";
113
+ kind: UsageEntryKind;
114
+ provider: string;
115
+ /** 模型 id(不含 provider)。 */
116
+ model: string;
117
+ usage: Usage;
118
+ }
119
+ export type SessionEntry = MessageEntry | CompactionEntry | BranchSummaryEntry | ContextEditEntry | ModelChangeEntry | ThinkingLevelChangeEntry | CustomEntry | CustomMessageEntry | LabelEntry | SessionInfoEntry | UsageEntry;
120
+ export type SessionEntryType = SessionEntry["type"];
121
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
122
+ /** `append()` 的入参:id / parentId / timestamp 由管理器填。 */
123
+ export type SessionEntryInput = DistributiveOmit<SessionEntry, keyof EntryBase>;
124
+ /**
125
+ * [W3-C0] `/tree` 换叶子的落盘记录(第三波 A7):不是条目,`getEntries` / 树不返回它;
126
+ * 最后一条 `leaf` 行若晚于最后一条条目,打开文件时作为叶子。fork 不复制。
127
+ */
128
+ export interface LeafLine {
129
+ type: "leaf";
130
+ /** 叶子条目 id;null = 回到根之前(空分支)。 */
131
+ id: string | null;
132
+ /** ISO 8601。 */
133
+ timestamp: string;
134
+ }
135
+ /** JSONL 一行:首行是头,其后是条目(以及可选的 `leaf` 行)。 */
136
+ export type SessionLine = SessionHeader | SessionEntry | LeafLine;
137
+ export interface CustomMessage {
138
+ role: "custom";
139
+ customType: string;
140
+ content: string | ContentBlock[];
141
+ display: boolean;
142
+ details?: unknown;
143
+ timestamp: number;
144
+ }
145
+ export interface CompactionSummaryMessage {
146
+ role: "compactionSummary";
147
+ summary: string;
148
+ tokensBefore: number;
149
+ timestamp: number;
150
+ }
151
+ export interface BranchSummaryMessage {
152
+ role: "branchSummary";
153
+ summary: string;
154
+ fromId: string;
155
+ timestamp: number;
156
+ }
157
+ export type AgentMessage = Message | CustomMessage | CompactionSummaryMessage | BranchSummaryMessage;
158
+ export interface SessionTreeNode {
159
+ entry: SessionEntry;
160
+ children: SessionTreeNode[];
161
+ label?: string;
162
+ }
163
+ export interface SessionListItem {
164
+ id: string;
165
+ file: string;
166
+ cwd: string;
167
+ name?: string;
168
+ /** ISO 8601。 */
169
+ createdAt: string;
170
+ modifiedAt: string;
171
+ firstPrompt?: string;
172
+ messageCount: number;
173
+ }
174
+ export interface SessionManagerApi {
175
+ readonly id: string;
176
+ readonly cwd: string;
177
+ /** 未落盘(内存会话或首条提示前)为 undefined。 */
178
+ file(): string | undefined;
179
+ header(): SessionHeader;
180
+ /** 全部条目(文件顺序)。 */
181
+ entries(): readonly SessionEntry[];
182
+ getEntry(id: string): SessionEntry | undefined;
183
+ leafId(): string | null;
184
+ /** 追加到当前叶子之后并把叶子移到新条目。 */
185
+ append(input: SessionEntryInput): SessionEntry;
186
+ /** `/tree`:同文件换叶子。 */
187
+ setLeaf(id: string | null): void;
188
+ /** 根 → 叶子的活动分支。 */
189
+ branch(leafId?: string | null): SessionEntry[];
190
+ /** 以 entry id 为游标(不含 since 本身)。 */
191
+ getEntries(since?: string): {
192
+ entries: SessionEntry[];
193
+ leafId: string | null;
194
+ };
195
+ getTree(): SessionTreeNode[];
196
+ name(): string | undefined;
197
+ setName(name: string): void;
198
+ /** 复制 root → entryId 的分支到新文件(parentSession 指回)。 */
199
+ fork(entryId: string): SessionManagerApi;
200
+ }
201
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 会话 JSONL 树契约(设计 §8,格式沿用 v1 §5)。[B0] 契约文件,实现归 B2。
3
+ *
4
+ * 补全与偏差:
5
+ * - `message` 条目只装 LLM 消息(`Message`:system / user / assistant / toolResult),
6
+ * 这样 session 不必反向依赖 agent。
7
+ * - 投影(projection.ts)产出的上下文消息 `AgentMessage` = `Message` + 三种非 LLM 角色
8
+ * (custom / compactionSummary / branchSummary),定义在这里,agent/types.ts 再导出;
9
+ * `convertToLlm` 负责把三种扩展角色转成 user 消息。
10
+ * - `context_edit.reason` 在 v1 的 prune / abort / manual 之外加 `retry`(§3.6 失败尝试剔除)
11
+ * 与 `overflow`(§9 溢出恢复剔除)。
12
+ * - `compaction` / `branch_summary` 的 details 统一为 `FileOpsDetails`。
13
+ * - 补全 `SessionTreeNode`、`SessionListItem` 与 B6 / B7 需要的 `SessionManagerApi`。
14
+ * `append()` 同步:返回带 id 的条目并把叶子移到它(落盘可延迟到首条提示,§11.1 第 16 步)。
15
+ * - (W3-C0)第三波 §1.7 / A7:新增 `usage` 条目(保温等不进上下文的请求用量,计入统计)与
16
+ * 非条目的 `leaf` 行(`/tree` 位置落盘);都是 v1 可选行,格式版本不升。
17
+ */
18
+ export const SESSION_FORMAT_VERSION = 1;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Skill 发现(设计 §5.3、§7.3)。[B3]
3
+ *
4
+ * 顺序:`--skill-dir`(可重复)→ profile `skillDirs` → config `skills.dirs` → `<configDir>/skills/`
5
+ * → `<cwd>/.ama/skills/`(需信任)→ 祖先目录的 `.agents/skills/`(需信任;从 cwd 向上到仓库根,
6
+ * 近者在前)。每个含 `SKILL.md` 的子目录是一个技能(递归查找,技能目录内部不再下钻);重名保留
7
+ * 先发现者并 warning。信任结果由调用方(B5 的 trust 决策)作为参数传入;未信任时需信任的来源被
8
+ * 跳过并记入 `skippedUntrusted`。
9
+ *
10
+ * frontmatter:`name`(≤ 64,`^[a-z0-9-]+$`,缺省取目录名)、`description`(必填,≤ 1024)、
11
+ * `disable-model-invocation`、`allowed-tools`(只做提示)。
12
+ */
13
+ export type SkillScope = "cli" | "profile" | "config" | "user" | "project" | "ancestor";
14
+ export interface SkillSource {
15
+ dir: string;
16
+ scope: SkillScope;
17
+ requiresTrust: boolean;
18
+ }
19
+ export interface Skill {
20
+ name: string;
21
+ description: string;
22
+ /** SKILL.md 绝对路径。 */
23
+ location: string;
24
+ /** SKILL.md 所在目录。 */
25
+ baseDir: string;
26
+ disableModelInvocation: boolean;
27
+ allowedTools?: string[];
28
+ scope: SkillScope;
29
+ }
30
+ export interface DiscoverResult {
31
+ skills: Skill[];
32
+ warnings: string[];
33
+ /** 因未信任而跳过的目录(存在的才列出)。 */
34
+ skippedUntrusted: string[];
35
+ }
36
+ export declare const SKILL_FILE = "SKILL.md";
37
+ export declare const SKILL_NAME_RE: RegExp;
38
+ export declare const MAX_SKILL_NAME = 64;
39
+ export declare const MAX_SKILL_DESCRIPTION = 1024;
40
+ export interface SkillSourceOptions {
41
+ cwd: string;
42
+ /** 用户级配置目录(`~/.config/ama`)。 */
43
+ configDir: string;
44
+ cliDirs?: readonly string[];
45
+ profileDirs?: readonly string[];
46
+ configDirs?: readonly string[];
47
+ }
48
+ /** 从 cwd 向上到仓库根(含 `.git` 的目录,含其本身);无仓库则到文件系统根。近者在前。 */
49
+ export declare function ancestorDirs(cwd: string): string[];
50
+ export declare function skillSources(options: SkillSourceOptions): SkillSource[];
51
+ /** 解析一份 SKILL.md;不合格返回 warning。 */
52
+ export declare function parseSkill(text: string, location: string, scope: SkillScope): {
53
+ skill?: Skill;
54
+ warnings: string[];
55
+ };
56
+ /** 一个来源目录下全部 SKILL.md(排序、递归;含 SKILL.md 的目录本身是技能,不再下钻)。 */
57
+ export declare function findSkillFiles(dir: string, depth?: number): Promise<string[]>;
58
+ export declare function discoverSkills(sources: readonly SkillSource[], options: {
59
+ trusted: boolean;
60
+ }): Promise<DiscoverResult>;
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Skill 发现(设计 §5.3、§7.3)。[B3]
3
+ *
4
+ * 顺序:`--skill-dir`(可重复)→ profile `skillDirs` → config `skills.dirs` → `<configDir>/skills/`
5
+ * → `<cwd>/.ama/skills/`(需信任)→ 祖先目录的 `.agents/skills/`(需信任;从 cwd 向上到仓库根,
6
+ * 近者在前)。每个含 `SKILL.md` 的子目录是一个技能(递归查找,技能目录内部不再下钻);重名保留
7
+ * 先发现者并 warning。信任结果由调用方(B5 的 trust 决策)作为参数传入;未信任时需信任的来源被
8
+ * 跳过并记入 `skippedUntrusted`。
9
+ *
10
+ * frontmatter:`name`(≤ 64,`^[a-z0-9-]+$`,缺省取目录名)、`description`(必填,≤ 1024)、
11
+ * `disable-model-invocation`、`allowed-tools`(只做提示)。
12
+ */
13
+ import { existsSync } from "node:fs";
14
+ import { readdir, readFile, stat } from "node:fs/promises";
15
+ import { basename, dirname, join, resolve } from "node:path";
16
+ import { parseFrontmatter } from "./frontmatter.js";
17
+ export const SKILL_FILE = "SKILL.md";
18
+ export const SKILL_NAME_RE = /^[a-z0-9-]+$/;
19
+ export const MAX_SKILL_NAME = 64;
20
+ export const MAX_SKILL_DESCRIPTION = 1024;
21
+ const MAX_DEPTH = 6;
22
+ const SKIP_DIRS = new Set(["node_modules", ".git"]);
23
+ /** 从 cwd 向上到仓库根(含 `.git` 的目录,含其本身);无仓库则到文件系统根。近者在前。 */
24
+ export function ancestorDirs(cwd) {
25
+ const out = [];
26
+ let dir = resolve(cwd);
27
+ for (;;) {
28
+ out.push(dir);
29
+ if (existsSync(join(dir, ".git")))
30
+ return out;
31
+ const parent = dirname(dir);
32
+ if (parent === dir)
33
+ return out;
34
+ dir = parent;
35
+ }
36
+ }
37
+ export function skillSources(options) {
38
+ const sources = [];
39
+ const add = (dir, scope, requiresTrust) => sources.push({ dir: resolve(options.cwd, dir), scope, requiresTrust });
40
+ for (const d of options.cliDirs ?? [])
41
+ add(d, "cli", false);
42
+ for (const d of options.profileDirs ?? [])
43
+ add(d, "profile", false);
44
+ for (const d of options.configDirs ?? [])
45
+ add(d, "config", false);
46
+ add(join(options.configDir, "skills"), "user", false);
47
+ add(join(options.cwd, ".ama", "skills"), "project", true);
48
+ for (const d of ancestorDirs(options.cwd))
49
+ add(join(d, ".agents", "skills"), "ancestor", true);
50
+ return sources;
51
+ }
52
+ /** 解析一份 SKILL.md;不合格返回 warning。 */
53
+ export function parseSkill(text, location, scope) {
54
+ const warnings = [];
55
+ const fm = parseFrontmatter(text);
56
+ for (const e of fm.errors)
57
+ warnings.push(`${location}: ${e}`);
58
+ const baseDir = dirname(location);
59
+ const rawName = fm.data["name"];
60
+ const name = typeof rawName === "string" && rawName !== "" ? rawName : basename(baseDir);
61
+ if (name.length > MAX_SKILL_NAME || !SKILL_NAME_RE.test(name)) {
62
+ warnings.push(`${location}: invalid skill name "${name}" (lowercase letters, digits, -)`);
63
+ return { warnings };
64
+ }
65
+ const description = fm.data["description"];
66
+ if (typeof description !== "string" || description.trim() === "") {
67
+ warnings.push(`${location}: missing description; skill "${name}" not loaded`);
68
+ return { warnings };
69
+ }
70
+ if (description.length > MAX_SKILL_DESCRIPTION) {
71
+ warnings.push(`${location}: description longer than ${MAX_SKILL_DESCRIPTION} characters`);
72
+ return { warnings };
73
+ }
74
+ const skill = {
75
+ name,
76
+ description: description.trim(),
77
+ location,
78
+ baseDir,
79
+ disableModelInvocation: fm.data["disable-model-invocation"] === true,
80
+ scope,
81
+ };
82
+ const allowed = fm.data["allowed-tools"];
83
+ if (Array.isArray(allowed))
84
+ skill.allowedTools = allowed.map(String);
85
+ else if (typeof allowed === "string" && allowed !== "") {
86
+ skill.allowedTools = allowed.split(/[\s,]+/).filter((t) => t !== "");
87
+ }
88
+ return { skill, warnings };
89
+ }
90
+ async function isDir(path) {
91
+ try {
92
+ return (await stat(path)).isDirectory();
93
+ }
94
+ catch {
95
+ return false;
96
+ }
97
+ }
98
+ /** 一个来源目录下全部 SKILL.md(排序、递归;含 SKILL.md 的目录本身是技能,不再下钻)。 */
99
+ export async function findSkillFiles(dir, depth = 0) {
100
+ if (depth > MAX_DEPTH)
101
+ return [];
102
+ const own = join(dir, SKILL_FILE);
103
+ if (existsSync(own))
104
+ return [own];
105
+ let names;
106
+ try {
107
+ names = await readdir(dir);
108
+ }
109
+ catch {
110
+ return [];
111
+ }
112
+ names.sort();
113
+ const out = [];
114
+ for (const name of names) {
115
+ if (SKIP_DIRS.has(name))
116
+ continue;
117
+ const child = join(dir, name);
118
+ if (await isDir(child))
119
+ out.push(...(await findSkillFiles(child, depth + 1)));
120
+ }
121
+ return out;
122
+ }
123
+ export async function discoverSkills(sources, options) {
124
+ const result = { skills: [], warnings: [], skippedUntrusted: [] };
125
+ const byName = new Map();
126
+ const seenDirs = new Set();
127
+ for (const source of sources) {
128
+ if (seenDirs.has(source.dir))
129
+ continue;
130
+ seenDirs.add(source.dir);
131
+ if (!(await isDir(source.dir)))
132
+ continue;
133
+ if (source.requiresTrust && !options.trusted) {
134
+ result.skippedUntrusted.push(source.dir);
135
+ continue;
136
+ }
137
+ for (const file of await findSkillFiles(source.dir)) {
138
+ let text;
139
+ try {
140
+ text = await readFile(file, "utf8");
141
+ }
142
+ catch (err) {
143
+ result.warnings.push(`${file}: ${err.message}`);
144
+ continue;
145
+ }
146
+ const parsed = parseSkill(text, file, source.scope);
147
+ result.warnings.push(...parsed.warnings);
148
+ if (!parsed.skill)
149
+ continue;
150
+ const existing = byName.get(parsed.skill.name);
151
+ if (existing) {
152
+ result.warnings.push(`${file}: skill "${parsed.skill.name}" already defined at ${existing.location}; ignored`);
153
+ continue;
154
+ }
155
+ byName.set(parsed.skill.name, parsed.skill);
156
+ result.skills.push(parsed.skill);
157
+ }
158
+ }
159
+ return result;
160
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `/skill:<name> [args]` 展开(设计 §5.3)。[B3]
3
+ *
4
+ * 展开格式:
5
+ * <skill name="…" location="…">
6
+ * References are relative to <dir>.
7
+ *
8
+ * <正文(去掉 frontmatter)>
9
+ * </skill>
10
+ *
11
+ * <args> ← 有参数时才有
12
+ * 用户手打的 `/skill:` 不受 `disable-model-invocation` 限制(那只约束模型调用)。
13
+ */
14
+ import type { Skill } from "./discover.js";
15
+ export declare const SKILL_COMMAND_PREFIX = "/skill:";
16
+ export interface SkillCommand {
17
+ name: string;
18
+ args: string;
19
+ }
20
+ export declare function parseSkillCommand(text: string): SkillCommand | undefined;
21
+ export declare function skillBody(fileText: string): string;
22
+ /** `<skill …>` 块(skill 工具与 `/skill:` 共用)。 */
23
+ export declare function formatSkillBlock(skill: Pick<Skill, "name" | "location" | "baseDir">, body: string): string;
24
+ export declare function formatSkillInvocation(skill: Pick<Skill, "name" | "location" | "baseDir">, body: string, args: string): string;
25
+ export type SkillExpansion = {
26
+ kind: "expanded";
27
+ text: string;
28
+ skill: Skill;
29
+ } | {
30
+ kind: "unknown";
31
+ name: string;
32
+ available: string[];
33
+ };
34
+ /** 不是 `/skill:` 命令返回 undefined。 */
35
+ export declare function expandSkillCommand(text: string, skills: readonly Skill[], read?: (path: string) => Promise<string>): Promise<SkillExpansion | undefined>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `/skill:<name> [args]` 展开(设计 §5.3)。[B3]
3
+ *
4
+ * 展开格式:
5
+ * <skill name="…" location="…">
6
+ * References are relative to <dir>.
7
+ *
8
+ * <正文(去掉 frontmatter)>
9
+ * </skill>
10
+ *
11
+ * <args> ← 有参数时才有
12
+ * 用户手打的 `/skill:` 不受 `disable-model-invocation` 限制(那只约束模型调用)。
13
+ */
14
+ import { readFile } from "node:fs/promises";
15
+ import { splitFrontmatter } from "./frontmatter.js";
16
+ import { escapeXml } from "./index-prompt.js";
17
+ export const SKILL_COMMAND_PREFIX = "/skill:";
18
+ export function parseSkillCommand(text) {
19
+ const m = /^\/skill:([a-z0-9-]+)(?:[ \t]+([\s\S]*))?$/.exec(text.trim());
20
+ if (!m)
21
+ return undefined;
22
+ return { name: m[1], args: (m[2] ?? "").trim() };
23
+ }
24
+ export function skillBody(fileText) {
25
+ return splitFrontmatter(fileText).body.replace(/^\n+/, "").replace(/\s+$/, "");
26
+ }
27
+ /** `<skill …>` 块(skill 工具与 `/skill:` 共用)。 */
28
+ export function formatSkillBlock(skill, body) {
29
+ return (`<skill name="${escapeXml(skill.name)}" location="${escapeXml(skill.location)}">\n` +
30
+ `References are relative to ${skill.baseDir}.\n\n${body}\n</skill>`);
31
+ }
32
+ export function formatSkillInvocation(skill, body, args) {
33
+ const block = formatSkillBlock(skill, body);
34
+ return args === "" ? block : `${block}\n\n${args}`;
35
+ }
36
+ /** 不是 `/skill:` 命令返回 undefined。 */
37
+ export async function expandSkillCommand(text, skills, read = (p) => readFile(p, "utf8")) {
38
+ const cmd = parseSkillCommand(text);
39
+ if (!cmd)
40
+ return undefined;
41
+ const skill = skills.find((s) => s.name === cmd.name);
42
+ if (!skill)
43
+ return { kind: "unknown", name: cmd.name, available: skills.map((s) => s.name) };
44
+ const body = skillBody(await read(skill.location));
45
+ return { kind: "expanded", text: formatSkillInvocation(skill, body, cmd.args), skill };
46
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * YAML 头**子集**解析(设计 §5.3、§2「YAML 只支持 frontmatter 子集自写」)。[B3]
3
+ *
4
+ * 支持:首行 `---` 到下一个 `---` / `...` 之间的
5
+ * - `key: value`(值为裸字串、单 / 双引号字串、`true/false`、整数 / 小数、`null` / `~`);
6
+ * - 行内数组 `key: [a, "b", 3]`;块数组(`key:` 后跟 `- item` 行);
7
+ * - `#` 注释(引号外)与空行。
8
+ * 不支持:嵌套映射、多行块标量(`|` / `>`)、锚点——遇到时记一条错误并跳过该键。
9
+ */
10
+ export type FrontmatterValue = string | number | boolean | null | FrontmatterScalar[];
11
+ type FrontmatterScalar = string | number | boolean | null;
12
+ export interface FrontmatterResult {
13
+ data: Record<string, FrontmatterValue>;
14
+ /** 头之后的正文(无头时为全文)。 */
15
+ body: string;
16
+ /** 是否有头。 */
17
+ hasFrontmatter: boolean;
18
+ errors: string[];
19
+ }
20
+ export declare function parseScalar(raw: string): FrontmatterScalar;
21
+ /** 拆出头与正文;不以 `---` 开头视为无头。 */
22
+ export declare function splitFrontmatter(text: string): {
23
+ header: string[] | undefined;
24
+ body: string;
25
+ };
26
+ export declare function parseFrontmatter(text: string): FrontmatterResult;
27
+ export {};