@aigne/afs-cli 1.11.0-beta.1 → 1.11.0-beta.10

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 (348) hide show
  1. package/README.md +262 -15
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/_virtual/rolldown_runtime.mjs +7 -0
  4. package/dist/cli.cjs +40 -0
  5. package/dist/cli.d.cts +2 -0
  6. package/dist/cli.d.mts +2 -1
  7. package/dist/cli.mjs +36 -24
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/config/afs-loader.cjs +578 -0
  10. package/dist/config/afs-loader.d.cts +19 -0
  11. package/dist/config/afs-loader.d.cts.map +1 -0
  12. package/dist/config/afs-loader.d.mts +19 -0
  13. package/dist/config/afs-loader.d.mts.map +1 -0
  14. package/dist/config/afs-loader.mjs +576 -0
  15. package/dist/config/afs-loader.mjs.map +1 -0
  16. package/dist/config/env.cjs +46 -0
  17. package/dist/config/env.mjs +46 -0
  18. package/dist/config/env.mjs.map +1 -0
  19. package/dist/config/loader.cjs +219 -0
  20. package/dist/config/loader.mjs +217 -0
  21. package/dist/config/loader.mjs.map +1 -0
  22. package/dist/config/mount-commands.cjs +226 -0
  23. package/dist/config/mount-commands.d.cts +14 -0
  24. package/dist/config/mount-commands.d.cts.map +1 -0
  25. package/dist/config/mount-commands.d.mts +14 -0
  26. package/dist/config/mount-commands.d.mts.map +1 -0
  27. package/dist/config/mount-commands.mjs +220 -0
  28. package/dist/config/mount-commands.mjs.map +1 -0
  29. package/dist/config/schema.cjs +99 -0
  30. package/dist/config/schema.mjs +98 -0
  31. package/dist/config/schema.mjs.map +1 -0
  32. package/dist/core/commands/delete.cjs +41 -0
  33. package/dist/core/commands/delete.d.cts +18 -0
  34. package/dist/core/commands/delete.d.cts.map +1 -0
  35. package/dist/core/commands/delete.d.mts +18 -0
  36. package/dist/core/commands/delete.d.mts.map +1 -0
  37. package/dist/core/commands/delete.mjs +42 -0
  38. package/dist/core/commands/delete.mjs.map +1 -0
  39. package/dist/core/commands/exec.cjs +98 -0
  40. package/dist/core/commands/exec.d.cts +26 -0
  41. package/dist/core/commands/exec.d.cts.map +1 -0
  42. package/dist/core/commands/exec.d.mts +26 -0
  43. package/dist/core/commands/exec.d.mts.map +1 -0
  44. package/dist/core/commands/exec.mjs +99 -0
  45. package/dist/core/commands/exec.mjs.map +1 -0
  46. package/dist/core/commands/explain.cjs +278 -0
  47. package/dist/core/commands/explain.d.cts +25 -0
  48. package/dist/core/commands/explain.d.cts.map +1 -0
  49. package/dist/core/commands/explain.d.mts +25 -0
  50. package/dist/core/commands/explain.d.mts.map +1 -0
  51. package/dist/core/commands/explain.mjs +279 -0
  52. package/dist/core/commands/explain.mjs.map +1 -0
  53. package/dist/core/commands/explore.cjs +30 -0
  54. package/dist/core/commands/explore.d.mts +2 -0
  55. package/dist/core/commands/explore.mjs +31 -0
  56. package/dist/core/commands/explore.mjs.map +1 -0
  57. package/dist/core/commands/index.cjs +36 -0
  58. package/dist/core/commands/index.d.cts +21 -0
  59. package/dist/core/commands/index.d.cts.map +1 -0
  60. package/dist/core/commands/index.d.mts +24 -0
  61. package/dist/core/commands/index.d.mts.map +1 -0
  62. package/dist/core/commands/index.mjs +37 -0
  63. package/dist/core/commands/index.mjs.map +1 -0
  64. package/dist/core/commands/ls.cjs +57 -0
  65. package/dist/core/commands/ls.d.cts +21 -0
  66. package/dist/core/commands/ls.d.cts.map +1 -0
  67. package/dist/core/commands/ls.d.mts +21 -0
  68. package/dist/core/commands/ls.d.mts.map +1 -0
  69. package/dist/core/commands/ls.mjs +58 -0
  70. package/dist/core/commands/ls.mjs.map +1 -0
  71. package/dist/core/commands/mount.cjs +222 -0
  72. package/dist/core/commands/mount.d.cts +35 -0
  73. package/dist/core/commands/mount.d.cts.map +1 -0
  74. package/dist/core/commands/mount.d.mts +35 -0
  75. package/dist/core/commands/mount.d.mts.map +1 -0
  76. package/dist/core/commands/mount.mjs +223 -0
  77. package/dist/core/commands/mount.mjs.map +1 -0
  78. package/dist/core/commands/read.cjs +48 -0
  79. package/dist/core/commands/read.d.cts +17 -0
  80. package/dist/core/commands/read.d.cts.map +1 -0
  81. package/dist/core/commands/read.d.mts +17 -0
  82. package/dist/core/commands/read.d.mts.map +1 -0
  83. package/dist/core/commands/read.mjs +49 -0
  84. package/dist/core/commands/read.mjs.map +1 -0
  85. package/dist/core/commands/search.cjs +40 -0
  86. package/dist/core/commands/search.d.mts +2 -0
  87. package/dist/core/commands/search.mjs +41 -0
  88. package/dist/core/commands/search.mjs.map +1 -0
  89. package/dist/core/commands/serve.cjs +267 -0
  90. package/dist/core/commands/serve.d.mts +2 -0
  91. package/dist/core/commands/serve.mjs +267 -0
  92. package/dist/core/commands/serve.mjs.map +1 -0
  93. package/dist/core/commands/stat.cjs +53 -0
  94. package/dist/core/commands/stat.d.cts +17 -0
  95. package/dist/core/commands/stat.d.cts.map +1 -0
  96. package/dist/core/commands/stat.d.mts +17 -0
  97. package/dist/core/commands/stat.d.mts.map +1 -0
  98. package/dist/core/commands/stat.mjs +54 -0
  99. package/dist/core/commands/stat.mjs.map +1 -0
  100. package/dist/core/commands/types.cjs +18 -0
  101. package/dist/core/commands/types.d.cts +54 -0
  102. package/dist/core/commands/types.d.cts.map +1 -0
  103. package/dist/core/commands/types.d.mts +54 -0
  104. package/dist/core/commands/types.d.mts.map +1 -0
  105. package/dist/core/commands/types.mjs +19 -0
  106. package/dist/core/commands/types.mjs.map +1 -0
  107. package/dist/core/commands/write.cjs +70 -0
  108. package/dist/core/commands/write.d.cts +20 -0
  109. package/dist/core/commands/write.d.cts.map +1 -0
  110. package/dist/core/commands/write.d.mts +20 -0
  111. package/dist/core/commands/write.d.mts.map +1 -0
  112. package/dist/core/commands/write.mjs +71 -0
  113. package/dist/core/commands/write.mjs.map +1 -0
  114. package/dist/core/executor/index.cjs +196 -0
  115. package/dist/core/executor/index.d.cts +77 -0
  116. package/dist/core/executor/index.d.cts.map +1 -0
  117. package/dist/core/executor/index.d.mts +77 -0
  118. package/dist/core/executor/index.d.mts.map +1 -0
  119. package/dist/core/executor/index.mjs +195 -0
  120. package/dist/core/executor/index.mjs.map +1 -0
  121. package/dist/core/formatters/delete.cjs +37 -0
  122. package/dist/core/formatters/delete.d.cts +18 -0
  123. package/dist/core/formatters/delete.d.cts.map +1 -0
  124. package/dist/core/formatters/delete.d.mts +18 -0
  125. package/dist/core/formatters/delete.d.mts.map +1 -0
  126. package/dist/core/formatters/delete.mjs +37 -0
  127. package/dist/core/formatters/delete.mjs.map +1 -0
  128. package/dist/core/formatters/exec.cjs +60 -0
  129. package/dist/core/formatters/exec.d.cts +18 -0
  130. package/dist/core/formatters/exec.d.cts.map +1 -0
  131. package/dist/core/formatters/exec.d.mts +18 -0
  132. package/dist/core/formatters/exec.d.mts.map +1 -0
  133. package/dist/core/formatters/exec.mjs +60 -0
  134. package/dist/core/formatters/exec.mjs.map +1 -0
  135. package/dist/core/formatters/explain.cjs +99 -0
  136. package/dist/core/formatters/explain.d.cts +11 -0
  137. package/dist/core/formatters/explain.d.cts.map +1 -0
  138. package/dist/core/formatters/explain.d.mts +11 -0
  139. package/dist/core/formatters/explain.d.mts.map +1 -0
  140. package/dist/core/formatters/explain.mjs +98 -0
  141. package/dist/core/formatters/explain.mjs.map +1 -0
  142. package/dist/core/formatters/index.d.mts +9 -0
  143. package/dist/core/formatters/ls.cjs +179 -0
  144. package/dist/core/formatters/ls.d.cts +20 -0
  145. package/dist/core/formatters/ls.d.cts.map +1 -0
  146. package/dist/core/formatters/ls.d.mts +20 -0
  147. package/dist/core/formatters/ls.d.mts.map +1 -0
  148. package/dist/core/formatters/ls.mjs +179 -0
  149. package/dist/core/formatters/ls.mjs.map +1 -0
  150. package/dist/core/formatters/mount.cjs +55 -0
  151. package/dist/core/formatters/mount.d.cts +15 -0
  152. package/dist/core/formatters/mount.d.cts.map +1 -0
  153. package/dist/core/formatters/mount.d.mts +15 -0
  154. package/dist/core/formatters/mount.d.mts.map +1 -0
  155. package/dist/core/formatters/mount.mjs +55 -0
  156. package/dist/core/formatters/mount.mjs.map +1 -0
  157. package/dist/core/formatters/read.cjs +100 -0
  158. package/dist/core/formatters/read.d.cts +22 -0
  159. package/dist/core/formatters/read.d.cts.map +1 -0
  160. package/dist/core/formatters/read.d.mts +22 -0
  161. package/dist/core/formatters/read.d.mts.map +1 -0
  162. package/dist/core/formatters/read.mjs +100 -0
  163. package/dist/core/formatters/read.mjs.map +1 -0
  164. package/dist/core/formatters/search.cjs +44 -0
  165. package/dist/core/formatters/search.d.mts +1 -0
  166. package/dist/core/formatters/search.mjs +44 -0
  167. package/dist/core/formatters/search.mjs.map +1 -0
  168. package/dist/core/formatters/stat.cjs +155 -0
  169. package/dist/core/formatters/stat.d.cts +15 -0
  170. package/dist/core/formatters/stat.d.cts.map +1 -0
  171. package/dist/core/formatters/stat.d.mts +15 -0
  172. package/dist/core/formatters/stat.d.mts.map +1 -0
  173. package/dist/core/formatters/stat.mjs +155 -0
  174. package/dist/core/formatters/stat.mjs.map +1 -0
  175. package/dist/core/formatters/write.cjs +51 -0
  176. package/dist/core/formatters/write.d.cts +22 -0
  177. package/dist/core/formatters/write.d.cts.map +1 -0
  178. package/dist/core/formatters/write.d.mts +22 -0
  179. package/dist/core/formatters/write.d.mts.map +1 -0
  180. package/dist/core/formatters/write.mjs +51 -0
  181. package/dist/core/formatters/write.mjs.map +1 -0
  182. package/dist/core/helpers/exec-args.cjs +142 -0
  183. package/dist/core/helpers/exec-args.d.cts +46 -0
  184. package/dist/core/helpers/exec-args.d.cts.map +1 -0
  185. package/dist/core/helpers/exec-args.d.mts +46 -0
  186. package/dist/core/helpers/exec-args.d.mts.map +1 -0
  187. package/dist/core/helpers/exec-args.mjs +139 -0
  188. package/dist/core/helpers/exec-args.mjs.map +1 -0
  189. package/dist/core/helpers/stdin.cjs +41 -0
  190. package/dist/core/helpers/stdin.d.cts +15 -0
  191. package/dist/core/helpers/stdin.d.cts.map +1 -0
  192. package/dist/core/helpers/stdin.d.mts +15 -0
  193. package/dist/core/helpers/stdin.d.mts.map +1 -0
  194. package/dist/core/helpers/stdin.mjs +41 -0
  195. package/dist/core/helpers/stdin.mjs.map +1 -0
  196. package/dist/core/index.cjs +49 -0
  197. package/dist/core/index.d.cts +24 -0
  198. package/dist/core/index.d.mts +25 -0
  199. package/dist/core/index.mjs +24 -0
  200. package/dist/core/path-utils.cjs +1 -0
  201. package/dist/core/path-utils.mjs +3 -0
  202. package/dist/core/types.d.cts +24 -0
  203. package/dist/core/types.d.cts.map +1 -0
  204. package/dist/core/types.d.mts +24 -0
  205. package/dist/core/types.d.mts.map +1 -0
  206. package/dist/credential/auth-server.cjs +247 -0
  207. package/dist/credential/auth-server.mjs +247 -0
  208. package/dist/credential/auth-server.mjs.map +1 -0
  209. package/dist/credential/cli-auth-context.cjs +86 -0
  210. package/dist/credential/cli-auth-context.d.mts +1 -0
  211. package/dist/credential/cli-auth-context.mjs +86 -0
  212. package/dist/credential/cli-auth-context.mjs.map +1 -0
  213. package/dist/credential/index.cjs +5 -0
  214. package/dist/credential/index.d.mts +4 -0
  215. package/dist/credential/index.mjs +7 -0
  216. package/dist/credential/mcp-auth-context.cjs +186 -0
  217. package/dist/credential/mcp-auth-context.d.mts +1 -0
  218. package/dist/credential/mcp-auth-context.mjs +186 -0
  219. package/dist/credential/mcp-auth-context.mjs.map +1 -0
  220. package/dist/credential/resolver.cjs +127 -0
  221. package/dist/credential/resolver.d.mts +1 -0
  222. package/dist/credential/resolver.mjs +127 -0
  223. package/dist/credential/resolver.mjs.map +1 -0
  224. package/dist/credential/store.cjs +106 -0
  225. package/dist/credential/store.d.cts +30 -0
  226. package/dist/credential/store.d.cts.map +1 -0
  227. package/dist/credential/store.d.mts +30 -0
  228. package/dist/credential/store.d.mts.map +1 -0
  229. package/dist/credential/store.mjs +106 -0
  230. package/dist/credential/store.mjs.map +1 -0
  231. package/dist/errors.cjs +18 -0
  232. package/dist/errors.mjs +18 -0
  233. package/dist/errors.mjs.map +1 -0
  234. package/dist/explorer/actions.cjs +311 -0
  235. package/dist/explorer/actions.mjs +305 -0
  236. package/dist/explorer/actions.mjs.map +1 -0
  237. package/dist/explorer/components/dialog.cjs +508 -0
  238. package/dist/explorer/components/dialog.mjs +509 -0
  239. package/dist/explorer/components/dialog.mjs.map +1 -0
  240. package/dist/explorer/components/file-list.cjs +107 -0
  241. package/dist/explorer/components/file-list.mjs +107 -0
  242. package/dist/explorer/components/file-list.mjs.map +1 -0
  243. package/dist/explorer/components/function-bar.cjs +55 -0
  244. package/dist/explorer/components/function-bar.mjs +55 -0
  245. package/dist/explorer/components/function-bar.mjs.map +1 -0
  246. package/dist/explorer/components/index.cjs +5 -0
  247. package/dist/explorer/components/index.mjs +7 -0
  248. package/dist/explorer/components/metadata-panel.cjs +219 -0
  249. package/dist/explorer/components/metadata-panel.mjs +219 -0
  250. package/dist/explorer/components/metadata-panel.mjs.map +1 -0
  251. package/dist/explorer/components/status-bar.cjs +53 -0
  252. package/dist/explorer/components/status-bar.mjs +54 -0
  253. package/dist/explorer/components/status-bar.mjs.map +1 -0
  254. package/dist/explorer/keybindings.cjs +214 -0
  255. package/dist/explorer/keybindings.mjs +213 -0
  256. package/dist/explorer/keybindings.mjs.map +1 -0
  257. package/dist/explorer/screen.cjs +251 -0
  258. package/dist/explorer/screen.d.cts +23 -0
  259. package/dist/explorer/screen.d.cts.map +1 -0
  260. package/dist/explorer/screen.d.mts +23 -0
  261. package/dist/explorer/screen.d.mts.map +1 -0
  262. package/dist/explorer/screen.mjs +250 -0
  263. package/dist/explorer/screen.mjs.map +1 -0
  264. package/dist/explorer/state.cjs +53 -0
  265. package/dist/explorer/state.mjs +53 -0
  266. package/dist/explorer/state.mjs.map +1 -0
  267. package/dist/explorer/theme.cjs +160 -0
  268. package/dist/explorer/theme.mjs +157 -0
  269. package/dist/explorer/theme.mjs.map +1 -0
  270. package/dist/index.cjs +12 -0
  271. package/dist/index.d.cts +6 -0
  272. package/dist/index.d.mts +7 -4
  273. package/dist/index.mjs +7 -2
  274. package/dist/mcp/http-transport.cjs +87 -0
  275. package/dist/mcp/http-transport.mjs +87 -0
  276. package/dist/mcp/http-transport.mjs.map +1 -0
  277. package/dist/mcp/prompts.cjs +48 -0
  278. package/dist/mcp/prompts.mjs +48 -0
  279. package/dist/mcp/prompts.mjs.map +1 -0
  280. package/dist/mcp/resources.cjs +25 -0
  281. package/dist/mcp/resources.mjs +25 -0
  282. package/dist/mcp/resources.mjs.map +1 -0
  283. package/dist/mcp/server.cjs +74 -0
  284. package/dist/mcp/server.mjs +73 -0
  285. package/dist/mcp/server.mjs.map +1 -0
  286. package/dist/mcp/tools.cjs +152 -0
  287. package/dist/mcp/tools.mjs +152 -0
  288. package/dist/mcp/tools.mjs.map +1 -0
  289. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.cts +10 -0
  290. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.cts.map +1 -0
  291. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.mts +10 -0
  292. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.mts.map +1 -0
  293. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.cts +46 -0
  294. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.cts.map +1 -0
  295. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.mts +46 -0
  296. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.mts.map +1 -0
  297. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.cjs +902 -0
  298. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.mjs +902 -0
  299. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.mjs.map +1 -0
  300. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.cjs +6 -0
  301. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.mjs +8 -0
  302. package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.mjs.map +1 -0
  303. package/dist/path-utils.cjs +105 -0
  304. package/dist/path-utils.d.cts +50 -0
  305. package/dist/path-utils.d.cts.map +1 -0
  306. package/dist/path-utils.d.mts +50 -0
  307. package/dist/path-utils.d.mts.map +1 -0
  308. package/dist/path-utils.mjs +104 -0
  309. package/dist/path-utils.mjs.map +1 -0
  310. package/dist/repl.cjs +491 -0
  311. package/dist/repl.d.cts +15 -0
  312. package/dist/repl.d.cts.map +1 -0
  313. package/dist/repl.d.mts +16 -0
  314. package/dist/repl.d.mts.map +1 -0
  315. package/dist/repl.mjs +491 -0
  316. package/dist/repl.mjs.map +1 -0
  317. package/dist/serve.cjs +146 -0
  318. package/dist/serve.d.cts +41 -0
  319. package/dist/serve.d.cts.map +1 -0
  320. package/dist/serve.d.mts +41 -0
  321. package/dist/serve.d.mts.map +1 -0
  322. package/dist/serve.mjs +146 -0
  323. package/dist/serve.mjs.map +1 -0
  324. package/dist/ui/header.cjs +12 -0
  325. package/dist/ui/header.mjs +13 -0
  326. package/dist/ui/header.mjs.map +1 -0
  327. package/dist/ui/index.cjs +8 -0
  328. package/dist/ui/index.mjs +9 -0
  329. package/dist/ui/index.mjs.map +1 -0
  330. package/dist/ui/terminal.cjs +88 -0
  331. package/dist/ui/terminal.mjs +88 -0
  332. package/dist/ui/terminal.mjs.map +1 -0
  333. package/dist/version.cjs +9 -0
  334. package/dist/version.d.cts +5 -0
  335. package/dist/version.d.cts.map +1 -0
  336. package/dist/version.d.mts +5 -0
  337. package/dist/version.d.mts.map +1 -0
  338. package/dist/version.mjs +9 -0
  339. package/dist/version.mjs.map +1 -0
  340. package/package.json +77 -11
  341. package/.turbo/turbo-build.log +0 -18
  342. package/.turbo/turbo-check-types.log +0 -4
  343. package/dist/version--p6A8sKX.mjs +0 -5
  344. package/src/cli.test.ts +0 -8
  345. package/src/cli.ts +0 -29
  346. package/src/index.ts +0 -7
  347. package/src/version.ts +0 -1
  348. package/tsconfig.json +0 -16
@@ -0,0 +1,54 @@
1
+ import { formatStatOutput } from "../formatters/stat.mjs";
2
+ import { cliPathToCanonical } from "../../path-utils.mjs";
3
+ import "../path-utils.mjs";
4
+ import { resolveAFS } from "./types.mjs";
5
+ import { ExitCode } from "../../errors.mjs";
6
+
7
+ //#region src/core/commands/stat.ts
8
+ /**
9
+ * Create stat command factory
10
+ */
11
+ function createStatCommand(options) {
12
+ return {
13
+ command: "stat <path>",
14
+ describe: "Get file or directory info",
15
+ builder: { path: {
16
+ type: "string",
17
+ demandOption: true,
18
+ description: "Path to stat"
19
+ } },
20
+ handler: async (argv) => {
21
+ const afs = await resolveAFS(options);
22
+ const canonicalPath = cliPathToCanonical(argv.path);
23
+ let result;
24
+ try {
25
+ result = await afs.stat(canonicalPath);
26
+ } catch {}
27
+ if (!result) try {
28
+ const entry = (await afs.read(canonicalPath)).data;
29
+ if (entry) result = { data: {
30
+ ...entry,
31
+ meta: entry.meta ?? {}
32
+ } };
33
+ } catch {}
34
+ if (result?.data) result.data.path = argv.path;
35
+ const notFound = !result?.data;
36
+ options.onResult({
37
+ command: "stat",
38
+ result: result ?? {
39
+ data: void 0,
40
+ message: `No data found for path: ${argv.path}`
41
+ },
42
+ format: formatStatOutput,
43
+ ...notFound && { error: {
44
+ code: ExitCode.NOT_FOUND,
45
+ message: `No data found for path: ${argv.path}`
46
+ } }
47
+ });
48
+ }
49
+ };
50
+ }
51
+
52
+ //#endregion
53
+ export { createStatCommand };
54
+ //# sourceMappingURL=stat.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stat.mjs","names":[],"sources":["../../../src/core/commands/stat.ts"],"sourcesContent":["/**\n * stat Command - Core Implementation\n *\n * Gets file/node statistics. Accepts AFS instance directly.\n * Returns AFSStatResult directly (no custom type).\n */\n\nimport type { AFSStatResult } from \"@aigne/afs\";\nimport type { CommandModule } from \"yargs\";\nimport { ExitCode } from \"../../errors.js\";\nimport { formatStatOutput } from \"../formatters/index.js\";\nimport { cliPathToCanonical } from \"../path-utils.js\";\nimport { type CommandFactoryOptions, resolveAFS } from \"./types.js\";\n\n/**\n * Stat command arguments\n */\nexport interface StatArgs {\n path: string;\n}\n\n/**\n * Create stat command factory\n */\nexport function createStatCommand(\n options: CommandFactoryOptions,\n): CommandModule<unknown, StatArgs> {\n return {\n command: \"stat <path>\",\n describe: \"Get file or directory info\",\n builder: {\n path: {\n type: \"string\",\n demandOption: true,\n description: \"Path to stat\",\n },\n },\n handler: async (argv) => {\n const afs = await resolveAFS(options);\n const canonicalPath = cliPathToCanonical(argv.path);\n let result: AFSStatResult | undefined;\n try {\n result = await afs.stat(canonicalPath);\n } catch {}\n\n if (!result) {\n // Fallback: Use read to get detailed metadata\n try {\n const entry = (await afs.read(canonicalPath)).data;\n if (entry) {\n result = { data: { ...entry, meta: entry.meta ?? {} } };\n }\n } catch {}\n }\n\n // Use the original CLI path for display (UX-friendly, e.g. /fs instead of $afs/fs)\n if (result?.data) {\n result.data.path = argv.path;\n }\n\n const notFound = !result?.data;\n options.onResult({\n command: \"stat\",\n result: result ?? { data: undefined, message: `No data found for path: ${argv.path}` },\n format: formatStatOutput,\n ...(notFound && {\n error: {\n code: ExitCode.NOT_FOUND,\n message: `No data found for path: ${argv.path}`,\n },\n }),\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAwBA,SAAgB,kBACd,SACkC;AAClC,QAAO;EACL,SAAS;EACT,UAAU;EACV,SAAS,EACP,MAAM;GACJ,MAAM;GACN,cAAc;GACd,aAAa;GACd,EACF;EACD,SAAS,OAAO,SAAS;GACvB,MAAM,MAAM,MAAM,WAAW,QAAQ;GACrC,MAAM,gBAAgB,mBAAmB,KAAK,KAAK;GACnD,IAAI;AACJ,OAAI;AACF,aAAS,MAAM,IAAI,KAAK,cAAc;WAChC;AAER,OAAI,CAAC,OAEH,KAAI;IACF,MAAM,SAAS,MAAM,IAAI,KAAK,cAAc,EAAE;AAC9C,QAAI,MACF,UAAS,EAAE,MAAM;KAAE,GAAG;KAAO,MAAM,MAAM,QAAQ,EAAE;KAAE,EAAE;WAEnD;AAIV,OAAI,QAAQ,KACV,QAAO,KAAK,OAAO,KAAK;GAG1B,MAAM,WAAW,CAAC,QAAQ;AAC1B,WAAQ,SAAS;IACf,SAAS;IACT,QAAQ,UAAU;KAAE,MAAM;KAAW,SAAS,2BAA2B,KAAK;KAAQ;IACtF,QAAQ;IACR,GAAI,YAAY,EACd,OAAO;KACL,MAAM,SAAS;KACf,SAAS,2BAA2B,KAAK;KAC1C,EACF;IACF,CAAC;;EAEL"}
@@ -0,0 +1,18 @@
1
+ const require_cli_auth_context = require('../../credential/cli-auth-context.cjs');
2
+ const require_store = require('../../credential/store.cjs');
3
+ const require_afs_loader = require('../../config/afs-loader.cjs');
4
+
5
+ //#region src/core/commands/types.ts
6
+ /**
7
+ * Resolve AFS instance: use injected instance or lazy-load from config
8
+ */
9
+ function resolveAFS(options) {
10
+ if (options.afs) return Promise.resolve(options.afs);
11
+ return require_afs_loader.loadAFS(options.cwd ?? process.cwd(), {
12
+ authContext: require_cli_auth_context.createCLIAuthContext(),
13
+ credentialStore: require_store.createCredentialStore()
14
+ }).then((result) => result.afs);
15
+ }
16
+
17
+ //#endregion
18
+ 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":";;;;;;;;;;;KAmBY,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;EAyBwB;EAvBxB,QAAA,GAAW,MAAA,EAAQ,aAAA;EAuByD;EArB5E,GAAA;AAAA;;;;;;;;KAqBU,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":";;;;;;;;;;;KAmBY,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;EAyBwB;EAvBxB,QAAA,GAAW,MAAA,EAAQ,aAAA;EAuByD;EArB5E,GAAA;AAAA;;;;;;;;KAqBU,cAAA,IAAkB,OAAA,EAAS,qBAAA,KAA0B,aAAA"}
@@ -0,0 +1,19 @@
1
+ import { createCLIAuthContext } from "../../credential/cli-auth-context.mjs";
2
+ import { createCredentialStore } from "../../credential/store.mjs";
3
+ import { loadAFS } from "../../config/afs-loader.mjs";
4
+
5
+ //#region src/core/commands/types.ts
6
+ /**
7
+ * Resolve AFS instance: use injected instance or lazy-load from config
8
+ */
9
+ function resolveAFS(options) {
10
+ if (options.afs) return Promise.resolve(options.afs);
11
+ return loadAFS(options.cwd ?? process.cwd(), {
12
+ authContext: createCLIAuthContext(),
13
+ credentialStore: createCredentialStore()
14
+ }).then((result) => result.afs);
15
+ }
16
+
17
+ //#endregion
18
+ export { resolveAFS };
19
+ //# 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 { createCLIAuthContext } from \"../../credential/cli-auth-context.js\";\nimport { createCredentialStore } from \"../../credential/store.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(), {\n authContext: createCLIAuthContext(),\n credentialStore: createCredentialStore(),\n }).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":";;;;;;;;AAyDA,SAAgB,WAAW,SAA8C;AACvE,KAAI,QAAQ,IAAK,QAAO,QAAQ,QAAQ,QAAQ,IAAI;AACpD,QAAO,QAAQ,QAAQ,OAAO,QAAQ,KAAK,EAAE;EAC3C,aAAa,sBAAsB;EACnC,iBAAiB,uBAAuB;EACzC,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;