@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.
- package/dist/cli.cjs +25 -328
- package/dist/cli.d.cts +2 -1
- package/dist/cli.d.mts +2 -1
- package/dist/cli.mjs +26 -328
- package/dist/cli.mjs.map +1 -1
- package/dist/config/afs-loader.cjs +123 -0
- package/dist/config/afs-loader.d.cts +14 -0
- package/dist/config/afs-loader.d.cts.map +1 -0
- package/dist/config/afs-loader.d.mts +14 -0
- package/dist/config/afs-loader.d.mts.map +1 -0
- package/dist/config/afs-loader.mjs +122 -0
- package/dist/config/afs-loader.mjs.map +1 -0
- package/dist/config/loader.cjs +14 -3
- package/dist/config/loader.mjs +14 -3
- package/dist/config/loader.mjs.map +1 -1
- package/dist/{commands/mount.cjs → config/mount-commands.cjs} +13 -49
- package/dist/config/mount-commands.d.cts +20 -0
- package/dist/config/mount-commands.d.cts.map +1 -0
- package/dist/config/mount-commands.d.mts +20 -0
- package/dist/config/mount-commands.d.mts.map +1 -0
- package/dist/{commands/mount.mjs → config/mount-commands.mjs} +14 -49
- package/dist/config/mount-commands.mjs.map +1 -0
- package/dist/config/schema.cjs +9 -1
- package/dist/config/schema.mjs +9 -1
- package/dist/config/schema.mjs.map +1 -1
- package/dist/core/commands/delete.cjs +41 -0
- package/dist/core/commands/delete.d.cts +18 -0
- package/dist/core/commands/delete.d.cts.map +1 -0
- package/dist/core/commands/delete.d.mts +18 -0
- package/dist/core/commands/delete.d.mts.map +1 -0
- package/dist/core/commands/delete.mjs +42 -0
- package/dist/core/commands/delete.mjs.map +1 -0
- package/dist/core/commands/exec.cjs +95 -0
- package/dist/core/commands/exec.d.cts +26 -0
- package/dist/core/commands/exec.d.cts.map +1 -0
- package/dist/core/commands/exec.d.mts +26 -0
- package/dist/core/commands/exec.d.mts.map +1 -0
- package/dist/core/commands/exec.mjs +96 -0
- package/dist/core/commands/exec.mjs.map +1 -0
- package/dist/core/commands/explain.cjs +254 -0
- package/dist/core/commands/explain.d.cts +25 -0
- package/dist/core/commands/explain.d.cts.map +1 -0
- package/dist/core/commands/explain.d.mts +25 -0
- package/dist/core/commands/explain.d.mts.map +1 -0
- package/dist/core/commands/explain.mjs +255 -0
- package/dist/core/commands/explain.mjs.map +1 -0
- package/dist/core/commands/explore.cjs +30 -0
- package/dist/core/commands/explore.d.mts +2 -0
- package/dist/core/commands/explore.mjs +31 -0
- package/dist/core/commands/explore.mjs.map +1 -0
- package/dist/core/commands/index.cjs +36 -0
- package/dist/core/commands/index.d.cts +21 -0
- package/dist/core/commands/index.d.cts.map +1 -0
- package/dist/core/commands/index.d.mts +24 -0
- package/dist/core/commands/index.d.mts.map +1 -0
- package/dist/core/commands/index.mjs +37 -0
- package/dist/core/commands/index.mjs.map +1 -0
- package/dist/core/commands/ls.cjs +57 -0
- package/dist/core/commands/ls.d.cts +21 -0
- package/dist/core/commands/ls.d.cts.map +1 -0
- package/dist/core/commands/ls.d.mts +21 -0
- package/dist/core/commands/ls.d.mts.map +1 -0
- package/dist/core/commands/ls.mjs +58 -0
- package/dist/core/commands/ls.mjs.map +1 -0
- package/dist/core/commands/mount.cjs +139 -0
- package/dist/core/commands/mount.d.cts +33 -0
- package/dist/core/commands/mount.d.cts.map +1 -0
- package/dist/core/commands/mount.d.mts +33 -0
- package/dist/core/commands/mount.d.mts.map +1 -0
- package/dist/core/commands/mount.mjs +140 -0
- package/dist/core/commands/mount.mjs.map +1 -0
- package/dist/core/commands/read.cjs +48 -0
- package/dist/core/commands/read.d.cts +17 -0
- package/dist/core/commands/read.d.cts.map +1 -0
- package/dist/core/commands/read.d.mts +17 -0
- package/dist/core/commands/read.d.mts.map +1 -0
- package/dist/core/commands/read.mjs +49 -0
- package/dist/core/commands/read.mjs.map +1 -0
- package/dist/core/commands/search.cjs +40 -0
- package/dist/core/commands/search.d.mts +2 -0
- package/dist/core/commands/search.mjs +41 -0
- package/dist/core/commands/search.mjs.map +1 -0
- package/dist/core/commands/serve.cjs +242 -0
- package/dist/core/commands/serve.d.mts +2 -0
- package/dist/core/commands/serve.mjs +242 -0
- package/dist/core/commands/serve.mjs.map +1 -0
- package/dist/core/commands/stat.cjs +53 -0
- package/dist/core/commands/stat.d.cts +17 -0
- package/dist/core/commands/stat.d.cts.map +1 -0
- package/dist/core/commands/stat.d.mts +17 -0
- package/dist/core/commands/stat.d.mts.map +1 -0
- package/dist/core/commands/stat.mjs +54 -0
- package/dist/core/commands/stat.mjs.map +1 -0
- package/dist/core/commands/types.cjs +13 -0
- package/dist/core/commands/types.d.cts +54 -0
- package/dist/core/commands/types.d.cts.map +1 -0
- package/dist/core/commands/types.d.mts +54 -0
- package/dist/core/commands/types.d.mts.map +1 -0
- package/dist/core/commands/types.mjs +14 -0
- package/dist/core/commands/types.mjs.map +1 -0
- package/dist/core/commands/write.cjs +70 -0
- package/dist/core/commands/write.d.cts +20 -0
- package/dist/core/commands/write.d.cts.map +1 -0
- package/dist/core/commands/write.d.mts +20 -0
- package/dist/core/commands/write.d.mts.map +1 -0
- package/dist/core/commands/write.mjs +71 -0
- package/dist/core/commands/write.mjs.map +1 -0
- package/dist/core/executor/index.cjs +196 -0
- package/dist/core/executor/index.d.cts +77 -0
- package/dist/core/executor/index.d.cts.map +1 -0
- package/dist/core/executor/index.d.mts +77 -0
- package/dist/core/executor/index.d.mts.map +1 -0
- package/dist/core/executor/index.mjs +195 -0
- package/dist/core/executor/index.mjs.map +1 -0
- package/dist/core/formatters/delete.cjs +37 -0
- package/dist/core/formatters/delete.d.cts +18 -0
- package/dist/core/formatters/delete.d.cts.map +1 -0
- package/dist/core/formatters/delete.d.mts +18 -0
- package/dist/core/formatters/delete.d.mts.map +1 -0
- package/dist/core/formatters/delete.mjs +37 -0
- package/dist/core/formatters/delete.mjs.map +1 -0
- package/dist/core/formatters/exec.cjs +60 -0
- package/dist/core/formatters/exec.d.cts +18 -0
- package/dist/core/formatters/exec.d.cts.map +1 -0
- package/dist/core/formatters/exec.d.mts +18 -0
- package/dist/core/formatters/exec.d.mts.map +1 -0
- package/dist/core/formatters/exec.mjs +60 -0
- package/dist/core/formatters/exec.mjs.map +1 -0
- package/dist/core/formatters/explain.cjs +97 -0
- package/dist/core/formatters/explain.d.cts +11 -0
- package/dist/core/formatters/explain.d.cts.map +1 -0
- package/dist/core/formatters/explain.d.mts +11 -0
- package/dist/core/formatters/explain.d.mts.map +1 -0
- package/dist/core/formatters/explain.mjs +96 -0
- package/dist/core/formatters/explain.mjs.map +1 -0
- package/dist/core/formatters/index.d.mts +9 -0
- package/dist/core/formatters/ls.cjs +179 -0
- package/dist/core/formatters/ls.d.cts +20 -0
- package/dist/core/formatters/ls.d.cts.map +1 -0
- package/dist/core/formatters/ls.d.mts +20 -0
- package/dist/core/formatters/ls.d.mts.map +1 -0
- package/dist/core/formatters/ls.mjs +179 -0
- package/dist/core/formatters/ls.mjs.map +1 -0
- package/dist/core/formatters/mount.cjs +55 -0
- package/dist/core/formatters/mount.d.cts +15 -0
- package/dist/core/formatters/mount.d.cts.map +1 -0
- package/dist/core/formatters/mount.d.mts +15 -0
- package/dist/core/formatters/mount.d.mts.map +1 -0
- package/dist/core/formatters/mount.mjs +55 -0
- package/dist/core/formatters/mount.mjs.map +1 -0
- package/dist/core/formatters/read.cjs +100 -0
- package/dist/core/formatters/read.d.cts +22 -0
- package/dist/core/formatters/read.d.cts.map +1 -0
- package/dist/core/formatters/read.d.mts +22 -0
- package/dist/core/formatters/read.d.mts.map +1 -0
- package/dist/core/formatters/read.mjs +100 -0
- package/dist/core/formatters/read.mjs.map +1 -0
- package/dist/core/formatters/search.cjs +44 -0
- package/dist/core/formatters/search.d.mts +1 -0
- package/dist/core/formatters/search.mjs +44 -0
- package/dist/core/formatters/search.mjs.map +1 -0
- package/dist/core/formatters/stat.cjs +155 -0
- package/dist/core/formatters/stat.d.cts +15 -0
- package/dist/core/formatters/stat.d.cts.map +1 -0
- package/dist/core/formatters/stat.d.mts +15 -0
- package/dist/core/formatters/stat.d.mts.map +1 -0
- package/dist/core/formatters/stat.mjs +155 -0
- package/dist/core/formatters/stat.mjs.map +1 -0
- package/dist/core/formatters/write.cjs +51 -0
- package/dist/core/formatters/write.d.cts +22 -0
- package/dist/core/formatters/write.d.cts.map +1 -0
- package/dist/core/formatters/write.d.mts +22 -0
- package/dist/core/formatters/write.d.mts.map +1 -0
- package/dist/core/formatters/write.mjs +51 -0
- package/dist/core/formatters/write.mjs.map +1 -0
- package/dist/core/helpers/exec-args.cjs +142 -0
- package/dist/core/helpers/exec-args.d.cts +46 -0
- package/dist/core/helpers/exec-args.d.cts.map +1 -0
- package/dist/core/helpers/exec-args.d.mts +46 -0
- package/dist/core/helpers/exec-args.d.mts.map +1 -0
- package/dist/core/helpers/exec-args.mjs +139 -0
- package/dist/core/helpers/exec-args.mjs.map +1 -0
- package/dist/core/helpers/stdin.cjs +41 -0
- package/dist/core/helpers/stdin.d.cts +15 -0
- package/dist/core/helpers/stdin.d.cts.map +1 -0
- package/dist/core/helpers/stdin.d.mts +15 -0
- package/dist/core/helpers/stdin.d.mts.map +1 -0
- package/dist/core/helpers/stdin.mjs +41 -0
- package/dist/core/helpers/stdin.mjs.map +1 -0
- package/dist/core/index.cjs +49 -0
- package/dist/core/index.d.cts +24 -0
- package/dist/core/index.d.mts +25 -0
- package/dist/core/index.mjs +24 -0
- package/dist/core/path-utils.cjs +1 -0
- package/dist/core/path-utils.mjs +3 -0
- package/dist/core/types.d.cts +24 -0
- package/dist/core/types.d.cts.map +1 -0
- package/dist/core/types.d.mts +24 -0
- package/dist/core/types.d.mts.map +1 -0
- package/dist/errors.cjs +0 -11
- package/dist/errors.mjs +1 -11
- package/dist/errors.mjs.map +1 -1
- package/dist/explorer/actions.cjs +113 -48
- package/dist/explorer/actions.mjs +113 -48
- package/dist/explorer/actions.mjs.map +1 -1
- package/dist/explorer/components/dialog.cjs +287 -10
- package/dist/explorer/components/dialog.mjs +287 -10
- package/dist/explorer/components/dialog.mjs.map +1 -1
- package/dist/explorer/components/file-list.mjs.map +1 -1
- package/dist/explorer/components/metadata-panel.cjs +121 -24
- package/dist/explorer/components/metadata-panel.mjs +121 -24
- package/dist/explorer/components/metadata-panel.mjs.map +1 -1
- package/dist/explorer/screen.cjs +72 -21
- package/dist/explorer/screen.d.cts +23 -0
- package/dist/explorer/screen.d.cts.map +1 -0
- package/dist/explorer/screen.d.mts +23 -0
- package/dist/explorer/screen.d.mts.map +1 -0
- package/dist/explorer/screen.mjs +73 -22
- package/dist/explorer/screen.mjs.map +1 -1
- package/dist/explorer/theme.cjs +4 -2
- package/dist/explorer/theme.mjs +4 -2
- package/dist/explorer/theme.mjs.map +1 -1
- package/dist/index.cjs +7 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +4 -1
- package/dist/mcp/http-transport.cjs +68 -0
- package/dist/mcp/http-transport.mjs +68 -0
- package/dist/mcp/http-transport.mjs.map +1 -0
- package/dist/mcp/prompts.cjs +48 -0
- package/dist/mcp/prompts.mjs +48 -0
- package/dist/mcp/prompts.mjs.map +1 -0
- package/dist/mcp/resources.cjs +25 -0
- package/dist/mcp/resources.mjs +25 -0
- package/dist/mcp/resources.mjs.map +1 -0
- package/dist/mcp/server.cjs +30 -0
- package/dist/mcp/server.mjs +30 -0
- package/dist/mcp/server.mjs.map +1 -0
- package/dist/mcp/tools.cjs +196 -0
- package/dist/mcp/tools.mjs +196 -0
- package/dist/mcp/tools.mjs.map +1 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.cts +10 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.cts.map +1 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.mts +10 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/index.d.mts.map +1 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.cts +46 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.cts.map +1 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.mts +46 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/types.d.mts.map +1 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.cjs +902 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.mjs +902 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/dist/urlpattern.mjs.map +1 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.cjs +6 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.mjs +8 -0
- package/dist/node_modules/.pnpm/urlpattern-polyfill@10.1.0/node_modules/urlpattern-polyfill/index.mjs.map +1 -0
- package/dist/path-utils.cjs +2 -1
- package/dist/path-utils.d.cts +50 -0
- package/dist/path-utils.d.cts.map +1 -0
- package/dist/path-utils.d.mts +50 -0
- package/dist/path-utils.d.mts.map +1 -0
- package/dist/path-utils.mjs +1 -1
- package/dist/repl.cjs +485 -0
- package/dist/repl.d.cts +15 -0
- package/dist/repl.d.cts.map +1 -0
- package/dist/repl.d.mts +16 -0
- package/dist/repl.d.mts.map +1 -0
- package/dist/repl.mjs +485 -0
- package/dist/repl.mjs.map +1 -0
- package/dist/serve.cjs +146 -0
- package/dist/serve.d.cts +41 -0
- package/dist/serve.d.cts.map +1 -0
- package/dist/serve.d.mts +41 -0
- package/dist/serve.d.mts.map +1 -0
- package/dist/serve.mjs +146 -0
- package/dist/serve.mjs.map +1 -0
- package/dist/ui/header.cjs +1 -49
- package/dist/ui/header.mjs +1 -47
- package/dist/ui/header.mjs.map +1 -1
- package/dist/ui/index.cjs +2 -11
- package/dist/ui/index.mjs +2 -8
- package/dist/ui/index.mjs.map +1 -1
- package/dist/ui/terminal.cjs +1 -10
- package/dist/ui/terminal.mjs +1 -8
- package/dist/ui/terminal.mjs.map +1 -1
- package/package.json +32 -9
- package/dist/commands/exec.cjs +0 -46
- package/dist/commands/exec.mjs +0 -45
- package/dist/commands/exec.mjs.map +0 -1
- package/dist/commands/explain.cjs +0 -244
- package/dist/commands/explain.mjs +0 -242
- package/dist/commands/explain.mjs.map +0 -1
- package/dist/commands/index.cjs +0 -8
- package/dist/commands/index.mjs +0 -10
- package/dist/commands/ls.cjs +0 -143
- package/dist/commands/ls.mjs +0 -143
- package/dist/commands/ls.mjs.map +0 -1
- package/dist/commands/mount.mjs.map +0 -1
- package/dist/commands/read.cjs +0 -65
- package/dist/commands/read.mjs +0 -64
- package/dist/commands/read.mjs.map +0 -1
- package/dist/commands/serve.cjs +0 -144
- package/dist/commands/serve.mjs +0 -143
- package/dist/commands/serve.mjs.map +0 -1
- package/dist/commands/stat.cjs +0 -113
- package/dist/commands/stat.mjs +0 -112
- package/dist/commands/stat.mjs.map +0 -1
- package/dist/commands/write.cjs +0 -52
- package/dist/commands/write.mjs +0 -51
- package/dist/commands/write.mjs.map +0 -1
- package/dist/config/provider-factory.cjs +0 -93
- package/dist/config/provider-factory.mjs +0 -94
- package/dist/config/provider-factory.mjs.map +0 -1
- package/dist/config/uri-parser.cjs +0 -92
- package/dist/config/uri-parser.mjs +0 -92
- package/dist/config/uri-parser.mjs.map +0 -1
- package/dist/runtime.cjs +0 -96
- package/dist/runtime.mjs +0 -96
- 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"}
|