@aigne/afs-cli 1.11.0-beta.5 → 1.11.0-beta.7

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 (318) hide show
  1. package/dist/cli.cjs +25 -328
  2. package/dist/cli.d.cts +2 -1
  3. package/dist/cli.d.mts +2 -1
  4. package/dist/cli.mjs +26 -328
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/config/afs-loader.cjs +123 -0
  7. package/dist/config/afs-loader.d.cts +14 -0
  8. package/dist/config/afs-loader.d.cts.map +1 -0
  9. package/dist/config/afs-loader.d.mts +14 -0
  10. package/dist/config/afs-loader.d.mts.map +1 -0
  11. package/dist/config/afs-loader.mjs +122 -0
  12. package/dist/config/afs-loader.mjs.map +1 -0
  13. package/dist/config/loader.cjs +14 -3
  14. package/dist/config/loader.mjs +14 -3
  15. package/dist/config/loader.mjs.map +1 -1
  16. package/dist/{commands/mount.cjs → config/mount-commands.cjs} +13 -49
  17. package/dist/config/mount-commands.d.cts +20 -0
  18. package/dist/config/mount-commands.d.cts.map +1 -0
  19. package/dist/config/mount-commands.d.mts +20 -0
  20. package/dist/config/mount-commands.d.mts.map +1 -0
  21. package/dist/{commands/mount.mjs → config/mount-commands.mjs} +14 -49
  22. package/dist/config/mount-commands.mjs.map +1 -0
  23. package/dist/config/schema.cjs +9 -1
  24. package/dist/config/schema.mjs +9 -1
  25. package/dist/config/schema.mjs.map +1 -1
  26. package/dist/core/commands/delete.cjs +41 -0
  27. package/dist/core/commands/delete.d.cts +18 -0
  28. package/dist/core/commands/delete.d.cts.map +1 -0
  29. package/dist/core/commands/delete.d.mts +18 -0
  30. package/dist/core/commands/delete.d.mts.map +1 -0
  31. package/dist/core/commands/delete.mjs +42 -0
  32. package/dist/core/commands/delete.mjs.map +1 -0
  33. package/dist/core/commands/exec.cjs +95 -0
  34. package/dist/core/commands/exec.d.cts +26 -0
  35. package/dist/core/commands/exec.d.cts.map +1 -0
  36. package/dist/core/commands/exec.d.mts +26 -0
  37. package/dist/core/commands/exec.d.mts.map +1 -0
  38. package/dist/core/commands/exec.mjs +96 -0
  39. package/dist/core/commands/exec.mjs.map +1 -0
  40. package/dist/core/commands/explain.cjs +254 -0
  41. package/dist/core/commands/explain.d.cts +25 -0
  42. package/dist/core/commands/explain.d.cts.map +1 -0
  43. package/dist/core/commands/explain.d.mts +25 -0
  44. package/dist/core/commands/explain.d.mts.map +1 -0
  45. package/dist/core/commands/explain.mjs +255 -0
  46. package/dist/core/commands/explain.mjs.map +1 -0
  47. package/dist/core/commands/explore.cjs +30 -0
  48. package/dist/core/commands/explore.d.mts +2 -0
  49. package/dist/core/commands/explore.mjs +31 -0
  50. package/dist/core/commands/explore.mjs.map +1 -0
  51. package/dist/core/commands/index.cjs +36 -0
  52. package/dist/core/commands/index.d.cts +21 -0
  53. package/dist/core/commands/index.d.cts.map +1 -0
  54. package/dist/core/commands/index.d.mts +24 -0
  55. package/dist/core/commands/index.d.mts.map +1 -0
  56. package/dist/core/commands/index.mjs +37 -0
  57. package/dist/core/commands/index.mjs.map +1 -0
  58. package/dist/core/commands/ls.cjs +57 -0
  59. package/dist/core/commands/ls.d.cts +21 -0
  60. package/dist/core/commands/ls.d.cts.map +1 -0
  61. package/dist/core/commands/ls.d.mts +21 -0
  62. package/dist/core/commands/ls.d.mts.map +1 -0
  63. package/dist/core/commands/ls.mjs +58 -0
  64. package/dist/core/commands/ls.mjs.map +1 -0
  65. package/dist/core/commands/mount.cjs +139 -0
  66. package/dist/core/commands/mount.d.cts +33 -0
  67. package/dist/core/commands/mount.d.cts.map +1 -0
  68. package/dist/core/commands/mount.d.mts +33 -0
  69. package/dist/core/commands/mount.d.mts.map +1 -0
  70. package/dist/core/commands/mount.mjs +140 -0
  71. package/dist/core/commands/mount.mjs.map +1 -0
  72. package/dist/core/commands/read.cjs +48 -0
  73. package/dist/core/commands/read.d.cts +17 -0
  74. package/dist/core/commands/read.d.cts.map +1 -0
  75. package/dist/core/commands/read.d.mts +17 -0
  76. package/dist/core/commands/read.d.mts.map +1 -0
  77. package/dist/core/commands/read.mjs +49 -0
  78. package/dist/core/commands/read.mjs.map +1 -0
  79. package/dist/core/commands/search.cjs +40 -0
  80. package/dist/core/commands/search.d.mts +2 -0
  81. package/dist/core/commands/search.mjs +41 -0
  82. package/dist/core/commands/search.mjs.map +1 -0
  83. package/dist/core/commands/serve.cjs +242 -0
  84. package/dist/core/commands/serve.d.mts +2 -0
  85. package/dist/core/commands/serve.mjs +242 -0
  86. package/dist/core/commands/serve.mjs.map +1 -0
  87. package/dist/core/commands/stat.cjs +53 -0
  88. package/dist/core/commands/stat.d.cts +17 -0
  89. package/dist/core/commands/stat.d.cts.map +1 -0
  90. package/dist/core/commands/stat.d.mts +17 -0
  91. package/dist/core/commands/stat.d.mts.map +1 -0
  92. package/dist/core/commands/stat.mjs +54 -0
  93. package/dist/core/commands/stat.mjs.map +1 -0
  94. package/dist/core/commands/types.cjs +13 -0
  95. package/dist/core/commands/types.d.cts +54 -0
  96. package/dist/core/commands/types.d.cts.map +1 -0
  97. package/dist/core/commands/types.d.mts +54 -0
  98. package/dist/core/commands/types.d.mts.map +1 -0
  99. package/dist/core/commands/types.mjs +14 -0
  100. package/dist/core/commands/types.mjs.map +1 -0
  101. package/dist/core/commands/write.cjs +70 -0
  102. package/dist/core/commands/write.d.cts +20 -0
  103. package/dist/core/commands/write.d.cts.map +1 -0
  104. package/dist/core/commands/write.d.mts +20 -0
  105. package/dist/core/commands/write.d.mts.map +1 -0
  106. package/dist/core/commands/write.mjs +71 -0
  107. package/dist/core/commands/write.mjs.map +1 -0
  108. package/dist/core/executor/index.cjs +196 -0
  109. package/dist/core/executor/index.d.cts +77 -0
  110. package/dist/core/executor/index.d.cts.map +1 -0
  111. package/dist/core/executor/index.d.mts +77 -0
  112. package/dist/core/executor/index.d.mts.map +1 -0
  113. package/dist/core/executor/index.mjs +195 -0
  114. package/dist/core/executor/index.mjs.map +1 -0
  115. package/dist/core/formatters/delete.cjs +37 -0
  116. package/dist/core/formatters/delete.d.cts +18 -0
  117. package/dist/core/formatters/delete.d.cts.map +1 -0
  118. package/dist/core/formatters/delete.d.mts +18 -0
  119. package/dist/core/formatters/delete.d.mts.map +1 -0
  120. package/dist/core/formatters/delete.mjs +37 -0
  121. package/dist/core/formatters/delete.mjs.map +1 -0
  122. package/dist/core/formatters/exec.cjs +60 -0
  123. package/dist/core/formatters/exec.d.cts +18 -0
  124. package/dist/core/formatters/exec.d.cts.map +1 -0
  125. package/dist/core/formatters/exec.d.mts +18 -0
  126. package/dist/core/formatters/exec.d.mts.map +1 -0
  127. package/dist/core/formatters/exec.mjs +60 -0
  128. package/dist/core/formatters/exec.mjs.map +1 -0
  129. package/dist/core/formatters/explain.cjs +97 -0
  130. package/dist/core/formatters/explain.d.cts +11 -0
  131. package/dist/core/formatters/explain.d.cts.map +1 -0
  132. package/dist/core/formatters/explain.d.mts +11 -0
  133. package/dist/core/formatters/explain.d.mts.map +1 -0
  134. package/dist/core/formatters/explain.mjs +96 -0
  135. package/dist/core/formatters/explain.mjs.map +1 -0
  136. package/dist/core/formatters/index.d.mts +9 -0
  137. package/dist/core/formatters/ls.cjs +179 -0
  138. package/dist/core/formatters/ls.d.cts +20 -0
  139. package/dist/core/formatters/ls.d.cts.map +1 -0
  140. package/dist/core/formatters/ls.d.mts +20 -0
  141. package/dist/core/formatters/ls.d.mts.map +1 -0
  142. package/dist/core/formatters/ls.mjs +179 -0
  143. package/dist/core/formatters/ls.mjs.map +1 -0
  144. package/dist/core/formatters/mount.cjs +55 -0
  145. package/dist/core/formatters/mount.d.cts +15 -0
  146. package/dist/core/formatters/mount.d.cts.map +1 -0
  147. package/dist/core/formatters/mount.d.mts +15 -0
  148. package/dist/core/formatters/mount.d.mts.map +1 -0
  149. package/dist/core/formatters/mount.mjs +55 -0
  150. package/dist/core/formatters/mount.mjs.map +1 -0
  151. package/dist/core/formatters/read.cjs +100 -0
  152. package/dist/core/formatters/read.d.cts +22 -0
  153. package/dist/core/formatters/read.d.cts.map +1 -0
  154. package/dist/core/formatters/read.d.mts +22 -0
  155. package/dist/core/formatters/read.d.mts.map +1 -0
  156. package/dist/core/formatters/read.mjs +100 -0
  157. package/dist/core/formatters/read.mjs.map +1 -0
  158. package/dist/core/formatters/search.cjs +44 -0
  159. package/dist/core/formatters/search.d.mts +1 -0
  160. package/dist/core/formatters/search.mjs +44 -0
  161. package/dist/core/formatters/search.mjs.map +1 -0
  162. package/dist/core/formatters/stat.cjs +155 -0
  163. package/dist/core/formatters/stat.d.cts +15 -0
  164. package/dist/core/formatters/stat.d.cts.map +1 -0
  165. package/dist/core/formatters/stat.d.mts +15 -0
  166. package/dist/core/formatters/stat.d.mts.map +1 -0
  167. package/dist/core/formatters/stat.mjs +155 -0
  168. package/dist/core/formatters/stat.mjs.map +1 -0
  169. package/dist/core/formatters/write.cjs +51 -0
  170. package/dist/core/formatters/write.d.cts +22 -0
  171. package/dist/core/formatters/write.d.cts.map +1 -0
  172. package/dist/core/formatters/write.d.mts +22 -0
  173. package/dist/core/formatters/write.d.mts.map +1 -0
  174. package/dist/core/formatters/write.mjs +51 -0
  175. package/dist/core/formatters/write.mjs.map +1 -0
  176. package/dist/core/helpers/exec-args.cjs +142 -0
  177. package/dist/core/helpers/exec-args.d.cts +46 -0
  178. package/dist/core/helpers/exec-args.d.cts.map +1 -0
  179. package/dist/core/helpers/exec-args.d.mts +46 -0
  180. package/dist/core/helpers/exec-args.d.mts.map +1 -0
  181. package/dist/core/helpers/exec-args.mjs +139 -0
  182. package/dist/core/helpers/exec-args.mjs.map +1 -0
  183. package/dist/core/helpers/stdin.cjs +41 -0
  184. package/dist/core/helpers/stdin.d.cts +15 -0
  185. package/dist/core/helpers/stdin.d.cts.map +1 -0
  186. package/dist/core/helpers/stdin.d.mts +15 -0
  187. package/dist/core/helpers/stdin.d.mts.map +1 -0
  188. package/dist/core/helpers/stdin.mjs +41 -0
  189. package/dist/core/helpers/stdin.mjs.map +1 -0
  190. package/dist/core/index.cjs +49 -0
  191. package/dist/core/index.d.cts +24 -0
  192. package/dist/core/index.d.mts +25 -0
  193. package/dist/core/index.mjs +24 -0
  194. package/dist/core/path-utils.cjs +1 -0
  195. package/dist/core/path-utils.mjs +3 -0
  196. package/dist/core/types.d.cts +24 -0
  197. package/dist/core/types.d.cts.map +1 -0
  198. package/dist/core/types.d.mts +24 -0
  199. package/dist/core/types.d.mts.map +1 -0
  200. package/dist/errors.cjs +0 -11
  201. package/dist/errors.mjs +1 -11
  202. package/dist/errors.mjs.map +1 -1
  203. package/dist/explorer/actions.cjs +113 -48
  204. package/dist/explorer/actions.mjs +113 -48
  205. package/dist/explorer/actions.mjs.map +1 -1
  206. package/dist/explorer/components/dialog.cjs +287 -10
  207. package/dist/explorer/components/dialog.mjs +287 -10
  208. package/dist/explorer/components/dialog.mjs.map +1 -1
  209. package/dist/explorer/components/file-list.mjs.map +1 -1
  210. package/dist/explorer/components/metadata-panel.cjs +121 -24
  211. package/dist/explorer/components/metadata-panel.mjs +121 -24
  212. package/dist/explorer/components/metadata-panel.mjs.map +1 -1
  213. package/dist/explorer/screen.cjs +72 -21
  214. package/dist/explorer/screen.d.cts +23 -0
  215. package/dist/explorer/screen.d.cts.map +1 -0
  216. package/dist/explorer/screen.d.mts +23 -0
  217. package/dist/explorer/screen.d.mts.map +1 -0
  218. package/dist/explorer/screen.mjs +73 -22
  219. package/dist/explorer/screen.mjs.map +1 -1
  220. package/dist/explorer/theme.cjs +4 -2
  221. package/dist/explorer/theme.mjs +4 -2
  222. package/dist/explorer/theme.mjs.map +1 -1
  223. package/dist/index.cjs +7 -1
  224. package/dist/index.d.cts +4 -1
  225. package/dist/index.d.mts +4 -1
  226. package/dist/index.mjs +4 -1
  227. package/dist/mcp/http-transport.cjs +68 -0
  228. package/dist/mcp/http-transport.mjs +68 -0
  229. package/dist/mcp/http-transport.mjs.map +1 -0
  230. package/dist/mcp/prompts.cjs +48 -0
  231. package/dist/mcp/prompts.mjs +48 -0
  232. package/dist/mcp/prompts.mjs.map +1 -0
  233. package/dist/mcp/resources.cjs +25 -0
  234. package/dist/mcp/resources.mjs +25 -0
  235. package/dist/mcp/resources.mjs.map +1 -0
  236. package/dist/mcp/server.cjs +30 -0
  237. package/dist/mcp/server.mjs +30 -0
  238. package/dist/mcp/server.mjs.map +1 -0
  239. package/dist/mcp/tools.cjs +196 -0
  240. package/dist/mcp/tools.mjs +196 -0
  241. package/dist/mcp/tools.mjs.map +1 -0
  242. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.cts +10 -0
  243. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.cts.map +1 -0
  244. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.mts +10 -0
  245. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.mts.map +1 -0
  246. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.cts +46 -0
  247. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.cts.map +1 -0
  248. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.mts +46 -0
  249. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.mts.map +1 -0
  250. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.cjs +902 -0
  251. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.mjs +902 -0
  252. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.mjs.map +1 -0
  253. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.cjs +6 -0
  254. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.mjs +8 -0
  255. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.mjs.map +1 -0
  256. package/dist/path-utils.cjs +2 -1
  257. package/dist/path-utils.d.cts +50 -0
  258. package/dist/path-utils.d.cts.map +1 -0
  259. package/dist/path-utils.d.mts +50 -0
  260. package/dist/path-utils.d.mts.map +1 -0
  261. package/dist/path-utils.mjs +1 -1
  262. package/dist/repl.cjs +485 -0
  263. package/dist/repl.d.cts +15 -0
  264. package/dist/repl.d.cts.map +1 -0
  265. package/dist/repl.d.mts +16 -0
  266. package/dist/repl.d.mts.map +1 -0
  267. package/dist/repl.mjs +485 -0
  268. package/dist/repl.mjs.map +1 -0
  269. package/dist/serve.cjs +146 -0
  270. package/dist/serve.d.cts +41 -0
  271. package/dist/serve.d.cts.map +1 -0
  272. package/dist/serve.d.mts +41 -0
  273. package/dist/serve.d.mts.map +1 -0
  274. package/dist/serve.mjs +146 -0
  275. package/dist/serve.mjs.map +1 -0
  276. package/dist/ui/header.cjs +1 -49
  277. package/dist/ui/header.mjs +1 -47
  278. package/dist/ui/header.mjs.map +1 -1
  279. package/dist/ui/index.cjs +2 -11
  280. package/dist/ui/index.mjs +2 -8
  281. package/dist/ui/index.mjs.map +1 -1
  282. package/dist/ui/terminal.cjs +1 -10
  283. package/dist/ui/terminal.mjs +1 -8
  284. package/dist/ui/terminal.mjs.map +1 -1
  285. package/package.json +32 -9
  286. package/dist/commands/exec.cjs +0 -46
  287. package/dist/commands/exec.mjs +0 -45
  288. package/dist/commands/exec.mjs.map +0 -1
  289. package/dist/commands/explain.cjs +0 -244
  290. package/dist/commands/explain.mjs +0 -242
  291. package/dist/commands/explain.mjs.map +0 -1
  292. package/dist/commands/index.cjs +0 -8
  293. package/dist/commands/index.mjs +0 -10
  294. package/dist/commands/ls.cjs +0 -143
  295. package/dist/commands/ls.mjs +0 -143
  296. package/dist/commands/ls.mjs.map +0 -1
  297. package/dist/commands/mount.mjs.map +0 -1
  298. package/dist/commands/read.cjs +0 -65
  299. package/dist/commands/read.mjs +0 -64
  300. package/dist/commands/read.mjs.map +0 -1
  301. package/dist/commands/serve.cjs +0 -144
  302. package/dist/commands/serve.mjs +0 -143
  303. package/dist/commands/serve.mjs.map +0 -1
  304. package/dist/commands/stat.cjs +0 -113
  305. package/dist/commands/stat.mjs +0 -112
  306. package/dist/commands/stat.mjs.map +0 -1
  307. package/dist/commands/write.cjs +0 -52
  308. package/dist/commands/write.mjs +0 -51
  309. package/dist/commands/write.mjs.map +0 -1
  310. package/dist/config/provider-factory.cjs +0 -93
  311. package/dist/config/provider-factory.mjs +0 -94
  312. package/dist/config/provider-factory.mjs.map +0 -1
  313. package/dist/config/uri-parser.cjs +0 -92
  314. package/dist/config/uri-parser.mjs +0 -92
  315. package/dist/config/uri-parser.mjs.map +0 -1
  316. package/dist/runtime.cjs +0 -96
  317. package/dist/runtime.mjs +0 -96
  318. package/dist/runtime.mjs.map +0 -1
@@ -0,0 +1,13 @@
1
+ const require_afs_loader = require('../../config/afs-loader.cjs');
2
+
3
+ //#region src/core/commands/types.ts
4
+ /**
5
+ * Resolve AFS instance: use injected instance or lazy-load from config
6
+ */
7
+ function resolveAFS(options) {
8
+ if (options.afs) return Promise.resolve(options.afs);
9
+ return require_afs_loader.loadAFS(options.cwd ?? process.cwd()).then((result) => result.afs);
10
+ }
11
+
12
+ //#endregion
13
+ exports.resolveAFS = resolveAFS;
@@ -0,0 +1,54 @@
1
+ import { ViewType } from "../types.cjs";
2
+ import { CommandModule } from "yargs";
3
+ import { AFS } from "@aigne/afs";
4
+
5
+ //#region src/core/commands/types.d.ts
6
+ /**
7
+ * Format function type for command output
8
+ *
9
+ * Uses `any` for result type to allow different AFS result types
10
+ * (AFSListResult, AFSReadResult, etc.) to be passed to the formatter.
11
+ */
12
+ type FormatFunction = (result: any, view: ViewType, options?: {
13
+ path?: string;
14
+ }) => string;
15
+ /**
16
+ * Command output passed to executor via onResult callback
17
+ */
18
+ interface CommandOutput {
19
+ /** The command name (ls, read, write, etc.) */
20
+ command: string;
21
+ /** Raw result from AFS operation */
22
+ result: unknown;
23
+ /** Format function to convert result to string */
24
+ format: FormatFunction;
25
+ /** Error info if command failed (presence indicates failure) */
26
+ error?: {
27
+ /** Exit code (from ExitCode enum) */code?: number; /** Error message */
28
+ message: string;
29
+ };
30
+ }
31
+ /**
32
+ * Options passed to command factory functions
33
+ */
34
+ interface CommandFactoryOptions {
35
+ /** AFS instance for executing operations (optional: injected in tests, lazy-loaded in production) */
36
+ afs?: AFS;
37
+ /** Original command line arguments (for pre-parsing in builder) */
38
+ argv: string[];
39
+ /** Callback to pass result back to executor */
40
+ onResult: (output: CommandOutput) => void;
41
+ /** Current working directory (for explore command) */
42
+ cwd?: string;
43
+ }
44
+ /**
45
+ * Command factory function type
46
+ *
47
+ * Uses `any` for CommandModule generics to allow different command
48
+ * factories (with different argument types) to be stored in a common array.
49
+ * Each individual factory uses strict types internally.
50
+ */
51
+ type CommandFactory = (options: CommandFactoryOptions) => CommandModule<unknown, any>;
52
+ //#endregion
53
+ export { CommandFactory, CommandFactoryOptions, CommandOutput, FormatFunction };
54
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../../src/core/commands/types.ts"],"mappings":";;;;;;;;;;;KAiBY,cAAA,IAAkB,MAAA,OAAa,IAAA,EAAM,QAAA,EAAU,OAAA;EAAY,IAAA;AAAA;;;;UAKtD,aAAA;EAIf;EAFA,OAAA;EAIQ;EAFR,MAAA;EAME;EAJF,MAAA,EAAQ,cAAA;EAMC;EAJT,KAAA;IAWe,qCATb,IAAA,WAWI;IATJ,OAAA;EAAA;AAAA;;;;UAOa,qBAAA;EAQf;EANA,GAAA,GAAM,GAAA;EAMH;EAJH,IAAA;EAsBwB;EApBxB,QAAA,GAAW,MAAA,EAAQ,aAAA;EAoByD;EAlB5E,GAAA;AAAA;;;;;;;;KAkBU,cAAA,IAAkB,OAAA,EAAS,qBAAA,KAA0B,aAAA"}
@@ -0,0 +1,54 @@
1
+ import { ViewType } from "../types.mjs";
2
+ import { AFS } from "@aigne/afs";
3
+ import { CommandModule } from "yargs";
4
+
5
+ //#region src/core/commands/types.d.ts
6
+ /**
7
+ * Format function type for command output
8
+ *
9
+ * Uses `any` for result type to allow different AFS result types
10
+ * (AFSListResult, AFSReadResult, etc.) to be passed to the formatter.
11
+ */
12
+ type FormatFunction = (result: any, view: ViewType, options?: {
13
+ path?: string;
14
+ }) => string;
15
+ /**
16
+ * Command output passed to executor via onResult callback
17
+ */
18
+ interface CommandOutput {
19
+ /** The command name (ls, read, write, etc.) */
20
+ command: string;
21
+ /** Raw result from AFS operation */
22
+ result: unknown;
23
+ /** Format function to convert result to string */
24
+ format: FormatFunction;
25
+ /** Error info if command failed (presence indicates failure) */
26
+ error?: {
27
+ /** Exit code (from ExitCode enum) */code?: number; /** Error message */
28
+ message: string;
29
+ };
30
+ }
31
+ /**
32
+ * Options passed to command factory functions
33
+ */
34
+ interface CommandFactoryOptions {
35
+ /** AFS instance for executing operations (optional: injected in tests, lazy-loaded in production) */
36
+ afs?: AFS;
37
+ /** Original command line arguments (for pre-parsing in builder) */
38
+ argv: string[];
39
+ /** Callback to pass result back to executor */
40
+ onResult: (output: CommandOutput) => void;
41
+ /** Current working directory (for explore command) */
42
+ cwd?: string;
43
+ }
44
+ /**
45
+ * Command factory function type
46
+ *
47
+ * Uses `any` for CommandModule generics to allow different command
48
+ * factories (with different argument types) to be stored in a common array.
49
+ * Each individual factory uses strict types internally.
50
+ */
51
+ type CommandFactory = (options: CommandFactoryOptions) => CommandModule<unknown, any>;
52
+ //#endregion
53
+ export { CommandFactory, CommandFactoryOptions, CommandOutput, FormatFunction };
54
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../../src/core/commands/types.ts"],"mappings":";;;;;;;;;;;KAiBY,cAAA,IAAkB,MAAA,OAAa,IAAA,EAAM,QAAA,EAAU,OAAA;EAAY,IAAA;AAAA;;;;UAKtD,aAAA;EAIf;EAFA,OAAA;EAIQ;EAFR,MAAA;EAME;EAJF,MAAA,EAAQ,cAAA;EAMC;EAJT,KAAA;IAWe,qCATb,IAAA,WAWI;IATJ,OAAA;EAAA;AAAA;;;;UAOa,qBAAA;EAQf;EANA,GAAA,GAAM,GAAA;EAMH;EAJH,IAAA;EAsBwB;EApBxB,QAAA,GAAW,MAAA,EAAQ,aAAA;EAoByD;EAlB5E,GAAA;AAAA;;;;;;;;KAkBU,cAAA,IAAkB,OAAA,EAAS,qBAAA,KAA0B,aAAA"}
@@ -0,0 +1,14 @@
1
+ import { loadAFS } from "../../config/afs-loader.mjs";
2
+
3
+ //#region src/core/commands/types.ts
4
+ /**
5
+ * Resolve AFS instance: use injected instance or lazy-load from config
6
+ */
7
+ function resolveAFS(options) {
8
+ if (options.afs) return Promise.resolve(options.afs);
9
+ return loadAFS(options.cwd ?? process.cwd()).then((result) => result.afs);
10
+ }
11
+
12
+ //#endregion
13
+ export { resolveAFS };
14
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../../../src/core/commands/types.ts"],"sourcesContent":["/**\n * Command Factory Types\n *\n * Defines the interface for yargs CommandModule factories.\n */\n\nimport type { AFS } from \"@aigne/afs\";\nimport type { CommandModule } from \"yargs\";\nimport { loadAFS } from \"../../config/afs-loader.js\";\nimport type { ViewType } from \"../types.js\";\n\n/**\n * Format function type for command output\n *\n * Uses `any` for result type to allow different AFS result types\n * (AFSListResult, AFSReadResult, etc.) to be passed to the formatter.\n */\nexport type FormatFunction = (result: any, view: ViewType, options?: { path?: string }) => string;\n\n/**\n * Command output passed to executor via onResult callback\n */\nexport interface CommandOutput {\n /** The command name (ls, read, write, etc.) */\n command: string;\n /** Raw result from AFS operation */\n result: unknown;\n /** Format function to convert result to string */\n format: FormatFunction;\n /** Error info if command failed (presence indicates failure) */\n error?: {\n /** Exit code (from ExitCode enum) */\n code?: number;\n /** Error message */\n message: string;\n };\n}\n\n/**\n * Options passed to command factory functions\n */\nexport interface CommandFactoryOptions {\n /** AFS instance for executing operations (optional: injected in tests, lazy-loaded in production) */\n afs?: AFS;\n /** Original command line arguments (for pre-parsing in builder) */\n argv: string[];\n /** Callback to pass result back to executor */\n onResult: (output: CommandOutput) => void;\n /** Current working directory (for explore command) */\n cwd?: string;\n}\n\n/**\n * Resolve AFS instance: use injected instance or lazy-load from config\n */\nexport function resolveAFS(options: CommandFactoryOptions): Promise<AFS> {\n if (options.afs) return Promise.resolve(options.afs);\n return loadAFS(options.cwd ?? process.cwd()).then((result) => result.afs);\n}\n\n/**\n * Command factory function type\n *\n * Uses `any` for CommandModule generics to allow different command\n * factories (with different argument types) to be stored in a common array.\n * Each individual factory uses strict types internally.\n */\nexport type CommandFactory = (options: CommandFactoryOptions) => CommandModule<unknown, any>;\n"],"mappings":";;;;;;AAuDA,SAAgB,WAAW,SAA8C;AACvE,KAAI,QAAQ,IAAK,QAAO,QAAQ,QAAQ,QAAQ,IAAI;AACpD,QAAO,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,MAAM,WAAW,OAAO,IAAI"}
@@ -0,0 +1,70 @@
1
+ const require_write = require('../formatters/write.cjs');
2
+ const require_path_utils = require('../../path-utils.cjs');
3
+ require('../path-utils.cjs');
4
+ const require_types = require('./types.cjs');
5
+
6
+ //#region src/core/commands/write.ts
7
+ /**
8
+ * Parse --meta values into metadata object
9
+ */
10
+ function parseMetaValues(metaValues) {
11
+ if (!metaValues || metaValues.length === 0) return void 0;
12
+ const meta = {};
13
+ for (const item of metaValues) {
14
+ const idx = item.indexOf("=");
15
+ if (idx > 0) {
16
+ const key = item.slice(0, idx);
17
+ meta[key] = item.slice(idx + 1);
18
+ }
19
+ }
20
+ return Object.keys(meta).length > 0 ? meta : void 0;
21
+ }
22
+ /**
23
+ * Create write command factory
24
+ */
25
+ function createWriteCommand(options) {
26
+ return {
27
+ command: "write <path> [content]",
28
+ describe: "Write content to file",
29
+ builder: {
30
+ path: {
31
+ type: "string",
32
+ demandOption: true,
33
+ description: "Path to write"
34
+ },
35
+ content: {
36
+ type: "string",
37
+ description: "Content to write"
38
+ },
39
+ append: {
40
+ type: "boolean",
41
+ description: "Append to file instead of overwriting",
42
+ default: false
43
+ },
44
+ meta: {
45
+ type: "string",
46
+ array: true,
47
+ description: "Set metadata field (key=value)"
48
+ }
49
+ },
50
+ handler: async (argv) => {
51
+ const metadata = parseMetaValues(argv.meta);
52
+ const fields = metadata ? Object.keys(metadata) : void 0;
53
+ if (argv.content === void 0 && !metadata) throw new Error("write requires content (use --content or provide as second argument)");
54
+ const afs = await require_types.resolveAFS(options);
55
+ const canonicalPath = require_path_utils.cliPathToCanonical(argv.path);
56
+ const writeData = {};
57
+ if (argv.content !== void 0) writeData.content = argv.content;
58
+ if (metadata) writeData.meta = metadata;
59
+ const result = await afs.write(canonicalPath, writeData, { append: argv.append });
60
+ options.onResult({
61
+ command: "write",
62
+ result,
63
+ format: (res, view) => require_write.formatWriteOutput(res, view, { fields })
64
+ });
65
+ }
66
+ };
67
+ }
68
+
69
+ //#endregion
70
+ exports.createWriteCommand = createWriteCommand;
@@ -0,0 +1,20 @@
1
+ import { CommandFactoryOptions } from "./types.cjs";
2
+ import { CommandModule } from "yargs";
3
+
4
+ //#region src/core/commands/write.d.ts
5
+ /**
6
+ * Write command arguments
7
+ */
8
+ interface WriteArgs {
9
+ path: string;
10
+ content?: string;
11
+ append: boolean;
12
+ meta?: string[];
13
+ }
14
+ /**
15
+ * Create write command factory
16
+ */
17
+ declare function createWriteCommand(options: CommandFactoryOptions): CommandModule<unknown, WriteArgs>;
18
+ //#endregion
19
+ export { WriteArgs, createWriteCommand };
20
+ //# sourceMappingURL=write.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.cts","names":[],"sources":["../../../src/core/commands/write.ts"],"mappings":";;;;;;;UAgBiB,SAAA;EACf,IAAA;EACA,OAAA;EACA,MAAA;EACA,IAAA;AAAA;;;;iBAwBc,kBAAA,CACd,OAAA,EAAS,qBAAA,GACR,aAAA,UAAuB,SAAA"}
@@ -0,0 +1,20 @@
1
+ import { CommandFactoryOptions } from "./types.mjs";
2
+ import { CommandModule } from "yargs";
3
+
4
+ //#region src/core/commands/write.d.ts
5
+ /**
6
+ * Write command arguments
7
+ */
8
+ interface WriteArgs {
9
+ path: string;
10
+ content?: string;
11
+ append: boolean;
12
+ meta?: string[];
13
+ }
14
+ /**
15
+ * Create write command factory
16
+ */
17
+ declare function createWriteCommand(options: CommandFactoryOptions): CommandModule<unknown, WriteArgs>;
18
+ //#endregion
19
+ export { WriteArgs, createWriteCommand };
20
+ //# sourceMappingURL=write.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.mts","names":[],"sources":["../../../src/core/commands/write.ts"],"mappings":";;;;;;;UAgBiB,SAAA;EACf,IAAA;EACA,OAAA;EACA,MAAA;EACA,IAAA;AAAA;;;;iBAwBc,kBAAA,CACd,OAAA,EAAS,qBAAA,GACR,aAAA,UAAuB,SAAA"}
@@ -0,0 +1,71 @@
1
+ import { formatWriteOutput } from "../formatters/write.mjs";
2
+ import { cliPathToCanonical } from "../../path-utils.mjs";
3
+ import "../path-utils.mjs";
4
+ import { resolveAFS } from "./types.mjs";
5
+
6
+ //#region src/core/commands/write.ts
7
+ /**
8
+ * Parse --meta values into metadata object
9
+ */
10
+ function parseMetaValues(metaValues) {
11
+ if (!metaValues || metaValues.length === 0) return void 0;
12
+ const meta = {};
13
+ for (const item of metaValues) {
14
+ const idx = item.indexOf("=");
15
+ if (idx > 0) {
16
+ const key = item.slice(0, idx);
17
+ meta[key] = item.slice(idx + 1);
18
+ }
19
+ }
20
+ return Object.keys(meta).length > 0 ? meta : void 0;
21
+ }
22
+ /**
23
+ * Create write command factory
24
+ */
25
+ function createWriteCommand(options) {
26
+ return {
27
+ command: "write <path> [content]",
28
+ describe: "Write content to file",
29
+ builder: {
30
+ path: {
31
+ type: "string",
32
+ demandOption: true,
33
+ description: "Path to write"
34
+ },
35
+ content: {
36
+ type: "string",
37
+ description: "Content to write"
38
+ },
39
+ append: {
40
+ type: "boolean",
41
+ description: "Append to file instead of overwriting",
42
+ default: false
43
+ },
44
+ meta: {
45
+ type: "string",
46
+ array: true,
47
+ description: "Set metadata field (key=value)"
48
+ }
49
+ },
50
+ handler: async (argv) => {
51
+ const metadata = parseMetaValues(argv.meta);
52
+ const fields = metadata ? Object.keys(metadata) : void 0;
53
+ if (argv.content === void 0 && !metadata) throw new Error("write requires content (use --content or provide as second argument)");
54
+ const afs = await resolveAFS(options);
55
+ const canonicalPath = cliPathToCanonical(argv.path);
56
+ const writeData = {};
57
+ if (argv.content !== void 0) writeData.content = argv.content;
58
+ if (metadata) writeData.meta = metadata;
59
+ const result = await afs.write(canonicalPath, writeData, { append: argv.append });
60
+ options.onResult({
61
+ command: "write",
62
+ result,
63
+ format: (res, view) => formatWriteOutput(res, view, { fields })
64
+ });
65
+ }
66
+ };
67
+ }
68
+
69
+ //#endregion
70
+ export { createWriteCommand };
71
+ //# sourceMappingURL=write.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.mjs","names":[],"sources":["../../../src/core/commands/write.ts"],"sourcesContent":["/**\n * write Command - Core Implementation\n *\n * Writes content to a file/node. Accepts AFS instance directly.\n * Returns AFSWriteResult directly (no custom type).\n */\n\nimport type { AFSWriteEntryPayload } from \"@aigne/afs\";\nimport type { CommandModule } from \"yargs\";\nimport { formatWriteOutput } from \"../formatters/index.js\";\nimport { cliPathToCanonical } from \"../path-utils.js\";\nimport { type CommandFactoryOptions, resolveAFS } from \"./types.js\";\n\n/**\n * Write command arguments\n */\nexport interface WriteArgs {\n path: string;\n content?: string;\n append: boolean;\n meta?: string[];\n}\n\n/**\n * Parse --meta values into metadata object\n */\nfunction parseMetaValues(metaValues?: string[]): Record<string, string> | undefined {\n if (!metaValues || metaValues.length === 0) return undefined;\n\n const meta: Record<string, string> = {};\n for (const item of metaValues) {\n const idx = item.indexOf(\"=\");\n if (idx > 0) {\n const key = item.slice(0, idx);\n const value = item.slice(idx + 1);\n meta[key] = value;\n }\n }\n return Object.keys(meta).length > 0 ? meta : undefined;\n}\n\n/**\n * Create write command factory\n */\nexport function createWriteCommand(\n options: CommandFactoryOptions,\n): CommandModule<unknown, WriteArgs> {\n return {\n command: \"write <path> [content]\",\n describe: \"Write content to file\",\n builder: {\n path: {\n type: \"string\",\n demandOption: true,\n description: \"Path to write\",\n },\n content: {\n type: \"string\",\n description: \"Content to write\",\n },\n append: {\n type: \"boolean\",\n description: \"Append to file instead of overwriting\",\n default: false,\n },\n meta: {\n type: \"string\",\n array: true,\n description: \"Set metadata field (key=value)\",\n },\n },\n handler: async (argv) => {\n const metadata = parseMetaValues(argv.meta);\n const fields = metadata ? Object.keys(metadata) : undefined;\n\n // Content is required unless only setting metadata\n if (argv.content === undefined && !metadata) {\n throw new Error(\"write requires content (use --content or provide as second argument)\");\n }\n\n const afs = await resolveAFS(options);\n const canonicalPath = cliPathToCanonical(argv.path);\n const writeData: AFSWriteEntryPayload = {};\n\n if (argv.content !== undefined) {\n writeData.content = argv.content;\n }\n if (metadata) {\n writeData.meta = metadata;\n }\n\n const result = await afs.write(canonicalPath, writeData, { append: argv.append });\n options.onResult({\n command: \"write\",\n result,\n format: (res, view) => formatWriteOutput(res, view, { fields }),\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAS,gBAAgB,YAA2D;AAClF,KAAI,CAAC,cAAc,WAAW,WAAW,EAAG,QAAO;CAEnD,MAAM,OAA+B,EAAE;AACvC,MAAK,MAAM,QAAQ,YAAY;EAC7B,MAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,MAAM,GAAG;GACX,MAAM,MAAM,KAAK,MAAM,GAAG,IAAI;AAE9B,QAAK,OADS,KAAK,MAAM,MAAM,EAAE;;;AAIrC,QAAO,OAAO,KAAK,KAAK,CAAC,SAAS,IAAI,OAAO;;;;;AAM/C,SAAgB,mBACd,SACmC;AACnC,QAAO;EACL,SAAS;EACT,UAAU;EACV,SAAS;GACP,MAAM;IACJ,MAAM;IACN,cAAc;IACd,aAAa;IACd;GACD,SAAS;IACP,MAAM;IACN,aAAa;IACd;GACD,QAAQ;IACN,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACD,MAAM;IACJ,MAAM;IACN,OAAO;IACP,aAAa;IACd;GACF;EACD,SAAS,OAAO,SAAS;GACvB,MAAM,WAAW,gBAAgB,KAAK,KAAK;GAC3C,MAAM,SAAS,WAAW,OAAO,KAAK,SAAS,GAAG;AAGlD,OAAI,KAAK,YAAY,UAAa,CAAC,SACjC,OAAM,IAAI,MAAM,uEAAuE;GAGzF,MAAM,MAAM,MAAM,WAAW,QAAQ;GACrC,MAAM,gBAAgB,mBAAmB,KAAK,KAAK;GACnD,MAAM,YAAkC,EAAE;AAE1C,OAAI,KAAK,YAAY,OACnB,WAAU,UAAU,KAAK;AAE3B,OAAI,SACF,WAAU,OAAO;GAGnB,MAAM,SAAS,MAAM,IAAI,MAAM,eAAe,WAAW,EAAE,QAAQ,KAAK,QAAQ,CAAC;AACjF,WAAQ,SAAS;IACf,SAAS;IACT;IACA,SAAS,KAAK,SAAS,kBAAkB,KAAK,MAAM,EAAE,QAAQ,CAAC;IAChE,CAAC;;EAEL"}
@@ -0,0 +1,196 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_index = require('../commands/index.cjs');
3
+ let yargs = require("yargs");
4
+ yargs = require_rolldown_runtime.__toESM(yargs);
5
+
6
+ //#region src/core/executor/index.ts
7
+ /**
8
+ * AFS Command Executor
9
+ *
10
+ * Provides a unified interface for executing AFS commands using yargs.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const executor = new AFSCommandExecutor(afs, { tty: false });
15
+ * const result = await executor.execute("afs ls /path --depth=2");
16
+ * console.log(result.formatted);
17
+ * ```
18
+ */
19
+ var AFSCommandExecutor = class {
20
+ afs;
21
+ options;
22
+ constructor(afs, options) {
23
+ this.afs = afs;
24
+ this.options = options ?? {};
25
+ }
26
+ /**
27
+ * Execute an AFS command
28
+ *
29
+ * @param argv - Command string or array of arguments
30
+ * - String: "afs ls /path --depth=2" or "ls /path --depth=2"
31
+ * - Array: ["ls", "/path", "--depth=2"]
32
+ * @returns Execution result with formatted output
33
+ */
34
+ async execute(argv) {
35
+ const normalizedArgs = this.normalizeArgv(argv);
36
+ let commandResult;
37
+ const outputOptions = this.extractOutputOptions(normalizedArgs);
38
+ const factoryOptions = {
39
+ afs: this.afs,
40
+ argv: normalizedArgs,
41
+ cwd: this.options.cwd,
42
+ onResult: (result) => {
43
+ commandResult = result;
44
+ }
45
+ };
46
+ let parser = (0, yargs.default)(normalizedArgs).scriptName("afs").usage("$0 <command> [options]").option("json", {
47
+ type: "boolean",
48
+ description: "Output in JSON format",
49
+ global: true
50
+ }).option("yaml", {
51
+ type: "boolean",
52
+ description: "Output in YAML format",
53
+ global: true
54
+ }).option("view", {
55
+ type: "string",
56
+ choices: [
57
+ "default",
58
+ "llm",
59
+ "human"
60
+ ],
61
+ default: "default",
62
+ description: "Output view format",
63
+ global: true
64
+ }).option("interactive", {
65
+ alias: "i",
66
+ type: "boolean",
67
+ description: "Start interactive REPL mode",
68
+ global: false
69
+ }).help(true).alias("h", "help").version(this.options.version || "unknown").alias("v", "version").demandCommand().showHelpOnFail(true).exitProcess(false);
70
+ for (const factory of require_index.commandFactories) parser = parser.command(factory(factoryOptions));
71
+ try {
72
+ let output;
73
+ let error;
74
+ const parsed = await parser.parseAsync(normalizedArgs, {}, (e, _, o) => {
75
+ if (e) error = e;
76
+ output = o;
77
+ });
78
+ if (error) return {
79
+ success: false,
80
+ command: normalizedArgs[0] || "unknown",
81
+ result: void 0,
82
+ formatted: output,
83
+ error: { message: error.message }
84
+ };
85
+ if (parsed.help) return {
86
+ success: true,
87
+ command: "help",
88
+ formatted: output
89
+ };
90
+ if (parsed.version) return {
91
+ success: true,
92
+ command: "version",
93
+ formatted: output
94
+ };
95
+ if (!commandResult) throw new Error("Command not found");
96
+ const view = outputOptions.json ? "json" : outputOptions.yaml ? "yaml" : outputOptions.view;
97
+ const formatted = commandResult.format(commandResult.result, view, { path: this.extractPath(normalizedArgs) });
98
+ if (commandResult.error) return {
99
+ success: false,
100
+ command: commandResult.command,
101
+ result: commandResult.result,
102
+ formatted,
103
+ error: commandResult.error
104
+ };
105
+ return {
106
+ success: true,
107
+ command: commandResult.command,
108
+ result: commandResult.result,
109
+ formatted
110
+ };
111
+ } catch (error) {
112
+ const errorMessage = error instanceof Error ? error.message : String(error);
113
+ return {
114
+ success: false,
115
+ command: normalizedArgs[0] || "unknown",
116
+ result: void 0,
117
+ formatted: `ERROR: ${errorMessage}`,
118
+ error: { message: errorMessage }
119
+ };
120
+ }
121
+ }
122
+ /**
123
+ * Normalize argv to an array of strings
124
+ */
125
+ normalizeArgv(argv) {
126
+ if (typeof argv === "string") return this.tokenize(argv);
127
+ const filtered = [];
128
+ let foundCommand = false;
129
+ for (const arg of argv) {
130
+ if (!foundCommand && (arg.includes("node") || arg.includes("bun") || arg.endsWith(".js") || arg.endsWith(".ts"))) continue;
131
+ if (!foundCommand && arg === "afs") continue;
132
+ filtered.push(arg);
133
+ if (!arg.startsWith("-")) foundCommand = true;
134
+ }
135
+ return filtered;
136
+ }
137
+ /**
138
+ * Tokenize a command string, respecting quotes
139
+ */
140
+ tokenize(input) {
141
+ const tokens = [];
142
+ let current = "";
143
+ let inQuote = false;
144
+ let quoteChar = "";
145
+ for (let i = 0; i < input.length; i++) {
146
+ const char = input[i];
147
+ if (inQuote) if (char === quoteChar) inQuote = false;
148
+ else current += char;
149
+ else if (char === "\"" || char === "'") {
150
+ inQuote = true;
151
+ quoteChar = char;
152
+ } else if (char === " " || char === " ") {
153
+ if (current) {
154
+ tokens.push(current);
155
+ current = "";
156
+ }
157
+ } else current += char;
158
+ }
159
+ if (current) tokens.push(current);
160
+ if (tokens[0] === "afs") tokens.shift();
161
+ return tokens;
162
+ }
163
+ /**
164
+ * Extract output options from args
165
+ */
166
+ extractOutputOptions(args) {
167
+ let json = false;
168
+ let yaml = false;
169
+ let view;
170
+ for (let i = 0; i < args.length; i++) {
171
+ const arg = args[i];
172
+ if (arg === "--json") json = true;
173
+ if (arg === "--yaml") yaml = true;
174
+ if (arg.startsWith("--view=")) view = arg.slice(7);
175
+ else if (arg === "--view" && args[i + 1] && !args[i + 1].startsWith("-")) view = args[i + 1];
176
+ }
177
+ if (!view) view = this.options.tty ? "human" : "default";
178
+ return {
179
+ json,
180
+ yaml,
181
+ view
182
+ };
183
+ }
184
+ /**
185
+ * Extract path from args (first non-option argument after command)
186
+ */
187
+ extractPath(args) {
188
+ for (let i = 1; i < args.length; i++) {
189
+ const arg = args[i];
190
+ if (!arg.startsWith("-")) return arg;
191
+ }
192
+ }
193
+ };
194
+
195
+ //#endregion
196
+ exports.AFSCommandExecutor = AFSCommandExecutor;
@@ -0,0 +1,77 @@
1
+ import { AFS } from "@aigne/afs";
2
+
3
+ //#region src/core/executor/index.d.ts
4
+ /**
5
+ * Result from executing a command
6
+ */
7
+ interface ExecuteResult {
8
+ /** Whether the command executed successfully */
9
+ success: boolean;
10
+ /** The command that was executed (ls, read, write, etc.) */
11
+ command: string;
12
+ /** The raw result data from AFS */
13
+ result?: unknown;
14
+ /** Formatted output string */
15
+ formatted: string;
16
+ /** Error info if the command failed */
17
+ error?: {
18
+ /** Exit code (from ExitCode enum) */code?: number; /** Error message */
19
+ message: string;
20
+ };
21
+ }
22
+ /**
23
+ * Options for the executor
24
+ */
25
+ interface ExecutorOptions {
26
+ /** Whether the output is for a TTY (enables colors) */
27
+ tty?: boolean;
28
+ /** Current working directory (for explore command) */
29
+ cwd?: string;
30
+ /** Version of the AFS CLI */
31
+ version?: string;
32
+ }
33
+ /**
34
+ * AFS Command Executor
35
+ *
36
+ * Provides a unified interface for executing AFS commands using yargs.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const executor = new AFSCommandExecutor(afs, { tty: false });
41
+ * const result = await executor.execute("afs ls /path --depth=2");
42
+ * console.log(result.formatted);
43
+ * ```
44
+ */
45
+ declare class AFSCommandExecutor {
46
+ private afs?;
47
+ private options;
48
+ constructor(afs?: AFS, options?: ExecutorOptions);
49
+ /**
50
+ * Execute an AFS command
51
+ *
52
+ * @param argv - Command string or array of arguments
53
+ * - String: "afs ls /path --depth=2" or "ls /path --depth=2"
54
+ * - Array: ["ls", "/path", "--depth=2"]
55
+ * @returns Execution result with formatted output
56
+ */
57
+ execute(argv: string | string[]): Promise<ExecuteResult>;
58
+ /**
59
+ * Normalize argv to an array of strings
60
+ */
61
+ private normalizeArgv;
62
+ /**
63
+ * Tokenize a command string, respecting quotes
64
+ */
65
+ private tokenize;
66
+ /**
67
+ * Extract output options from args
68
+ */
69
+ private extractOutputOptions;
70
+ /**
71
+ * Extract path from args (first non-option argument after command)
72
+ */
73
+ private extractPath;
74
+ }
75
+ //#endregion
76
+ export { AFSCommandExecutor, ExecuteResult, ExecutorOptions };
77
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/core/executor/index.ts"],"mappings":";;;;;;UAkBiB,aAAA;EAQf;EANA,OAAA;EAUE;EARF,OAAA;EAUS;EART,MAAA;EAee;EAbf,SAAA;;EAEA,KAAA;IAaA,qCAXE,IAAA,WAeF;IAbE,OAAA;EAAA;AAAA;;;;UAOa,eAAA;EAsCiC;EApChD,GAAA;EAoC+C;EAlC/C,GAAA;EAkBQ;EAhBR,OAAA;AAAA;;;;;;;;;;;;;cAeW,kBAAA;EAAA,QACH,GAAA;EAAA,QACA,OAAA;cAEI,GAAA,GAAM,GAAA,EAAK,OAAA,GAAU,eAAA;;;;;;;;;EAa3B,OAAA,CAAQ,IAAA,sBAA0B,OAAA,CAAQ,aAAA;;;;UA6IxC,aAAA;;;;UAoCA,QAAA;;;;UA2CA,oBAAA;;;;UA+BA,WAAA;AAAA"}