@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.
- package/README.md +262 -15
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/_virtual/rolldown_runtime.mjs +7 -0
- package/dist/cli.cjs +40 -0
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.mts +2 -1
- package/dist/cli.mjs +36 -24
- package/dist/cli.mjs.map +1 -0
- package/dist/config/afs-loader.cjs +578 -0
- package/dist/config/afs-loader.d.cts +19 -0
- package/dist/config/afs-loader.d.cts.map +1 -0
- package/dist/config/afs-loader.d.mts +19 -0
- package/dist/config/afs-loader.d.mts.map +1 -0
- package/dist/config/afs-loader.mjs +576 -0
- package/dist/config/afs-loader.mjs.map +1 -0
- package/dist/config/env.cjs +46 -0
- package/dist/config/env.mjs +46 -0
- package/dist/config/env.mjs.map +1 -0
- package/dist/config/loader.cjs +219 -0
- package/dist/config/loader.mjs +217 -0
- package/dist/config/loader.mjs.map +1 -0
- package/dist/config/mount-commands.cjs +226 -0
- package/dist/config/mount-commands.d.cts +14 -0
- package/dist/config/mount-commands.d.cts.map +1 -0
- package/dist/config/mount-commands.d.mts +14 -0
- package/dist/config/mount-commands.d.mts.map +1 -0
- package/dist/config/mount-commands.mjs +220 -0
- package/dist/config/mount-commands.mjs.map +1 -0
- package/dist/config/schema.cjs +99 -0
- package/dist/config/schema.mjs +98 -0
- package/dist/config/schema.mjs.map +1 -0
- 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 +98 -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 +99 -0
- package/dist/core/commands/exec.mjs.map +1 -0
- package/dist/core/commands/explain.cjs +278 -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 +279 -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 +222 -0
- package/dist/core/commands/mount.d.cts +35 -0
- package/dist/core/commands/mount.d.cts.map +1 -0
- package/dist/core/commands/mount.d.mts +35 -0
- package/dist/core/commands/mount.d.mts.map +1 -0
- package/dist/core/commands/mount.mjs +223 -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 +267 -0
- package/dist/core/commands/serve.d.mts +2 -0
- package/dist/core/commands/serve.mjs +267 -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 +18 -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 +19 -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 +99 -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 +98 -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/credential/auth-server.cjs +247 -0
- package/dist/credential/auth-server.mjs +247 -0
- package/dist/credential/auth-server.mjs.map +1 -0
- package/dist/credential/cli-auth-context.cjs +86 -0
- package/dist/credential/cli-auth-context.d.mts +1 -0
- package/dist/credential/cli-auth-context.mjs +86 -0
- package/dist/credential/cli-auth-context.mjs.map +1 -0
- package/dist/credential/index.cjs +5 -0
- package/dist/credential/index.d.mts +4 -0
- package/dist/credential/index.mjs +7 -0
- package/dist/credential/mcp-auth-context.cjs +186 -0
- package/dist/credential/mcp-auth-context.d.mts +1 -0
- package/dist/credential/mcp-auth-context.mjs +186 -0
- package/dist/credential/mcp-auth-context.mjs.map +1 -0
- package/dist/credential/resolver.cjs +127 -0
- package/dist/credential/resolver.d.mts +1 -0
- package/dist/credential/resolver.mjs +127 -0
- package/dist/credential/resolver.mjs.map +1 -0
- package/dist/credential/store.cjs +106 -0
- package/dist/credential/store.d.cts +30 -0
- package/dist/credential/store.d.cts.map +1 -0
- package/dist/credential/store.d.mts +30 -0
- package/dist/credential/store.d.mts.map +1 -0
- package/dist/credential/store.mjs +106 -0
- package/dist/credential/store.mjs.map +1 -0
- package/dist/errors.cjs +18 -0
- package/dist/errors.mjs +18 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/explorer/actions.cjs +311 -0
- package/dist/explorer/actions.mjs +305 -0
- package/dist/explorer/actions.mjs.map +1 -0
- package/dist/explorer/components/dialog.cjs +508 -0
- package/dist/explorer/components/dialog.mjs +509 -0
- package/dist/explorer/components/dialog.mjs.map +1 -0
- package/dist/explorer/components/file-list.cjs +107 -0
- package/dist/explorer/components/file-list.mjs +107 -0
- package/dist/explorer/components/file-list.mjs.map +1 -0
- package/dist/explorer/components/function-bar.cjs +55 -0
- package/dist/explorer/components/function-bar.mjs +55 -0
- package/dist/explorer/components/function-bar.mjs.map +1 -0
- package/dist/explorer/components/index.cjs +5 -0
- package/dist/explorer/components/index.mjs +7 -0
- package/dist/explorer/components/metadata-panel.cjs +219 -0
- package/dist/explorer/components/metadata-panel.mjs +219 -0
- package/dist/explorer/components/metadata-panel.mjs.map +1 -0
- package/dist/explorer/components/status-bar.cjs +53 -0
- package/dist/explorer/components/status-bar.mjs +54 -0
- package/dist/explorer/components/status-bar.mjs.map +1 -0
- package/dist/explorer/keybindings.cjs +214 -0
- package/dist/explorer/keybindings.mjs +213 -0
- package/dist/explorer/keybindings.mjs.map +1 -0
- package/dist/explorer/screen.cjs +251 -0
- 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 +250 -0
- package/dist/explorer/screen.mjs.map +1 -0
- package/dist/explorer/state.cjs +53 -0
- package/dist/explorer/state.mjs +53 -0
- package/dist/explorer/state.mjs.map +1 -0
- package/dist/explorer/theme.cjs +160 -0
- package/dist/explorer/theme.mjs +157 -0
- package/dist/explorer/theme.mjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +7 -4
- package/dist/index.mjs +7 -2
- package/dist/mcp/http-transport.cjs +87 -0
- package/dist/mcp/http-transport.mjs +87 -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 +74 -0
- package/dist/mcp/server.mjs +73 -0
- package/dist/mcp/server.mjs.map +1 -0
- package/dist/mcp/tools.cjs +152 -0
- package/dist/mcp/tools.mjs +152 -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 +105 -0
- 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 +104 -0
- package/dist/path-utils.mjs.map +1 -0
- package/dist/repl.cjs +491 -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 +491 -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 +12 -0
- package/dist/ui/header.mjs +13 -0
- package/dist/ui/header.mjs.map +1 -0
- package/dist/ui/index.cjs +8 -0
- package/dist/ui/index.mjs +9 -0
- package/dist/ui/index.mjs.map +1 -0
- package/dist/ui/terminal.cjs +88 -0
- package/dist/ui/terminal.mjs +88 -0
- package/dist/ui/terminal.mjs.map +1 -0
- package/dist/version.cjs +9 -0
- package/dist/version.d.cts +5 -0
- package/dist/version.d.cts.map +1 -0
- package/dist/version.d.mts +5 -0
- package/dist/version.d.mts.map +1 -0
- package/dist/version.mjs +9 -0
- package/dist/version.mjs.map +1 -0
- package/package.json +77 -11
- package/.turbo/turbo-build.log +0 -18
- package/.turbo/turbo-check-types.log +0 -4
- package/dist/version--p6A8sKX.mjs +0 -5
- package/src/cli.test.ts +0 -8
- package/src/cli.ts +0 -29
- package/src/index.ts +0 -7
- package/src/version.ts +0 -1
- package/tsconfig.json +0 -16
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/formatters/search.ts
|
|
3
|
+
/**
|
|
4
|
+
* Format search output for different views
|
|
5
|
+
*
|
|
6
|
+
* @param result - AFS search result (native type)
|
|
7
|
+
* @param view - View type (default, json, llm, human)
|
|
8
|
+
* @returns Formatted string (no ANSI colors)
|
|
9
|
+
*/
|
|
10
|
+
function formatSearchOutput(result, view) {
|
|
11
|
+
switch (view) {
|
|
12
|
+
case "json": return JSON.stringify(result, null, 2);
|
|
13
|
+
case "llm": return formatLlm(result);
|
|
14
|
+
case "human": return formatHuman(result);
|
|
15
|
+
default: return formatDefault(result);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function formatDefault(result) {
|
|
19
|
+
if (result.data.length === 0) return result.message || "No results found";
|
|
20
|
+
return result.data.map((entry) => entry.path).join("\n");
|
|
21
|
+
}
|
|
22
|
+
function formatLlm(result) {
|
|
23
|
+
const lines = [];
|
|
24
|
+
lines.push(`SEARCH_RESULTS ${result.data.length}`);
|
|
25
|
+
for (const entry of result.data) {
|
|
26
|
+
const summary = entry.summary ? ` "${entry.summary}"` : "";
|
|
27
|
+
lines.push(`RESULT ${entry.path}${summary}`);
|
|
28
|
+
}
|
|
29
|
+
return lines.join("\n");
|
|
30
|
+
}
|
|
31
|
+
function formatHuman(result) {
|
|
32
|
+
if (result.data.length === 0) return result.message || "No results found";
|
|
33
|
+
const lines = [];
|
|
34
|
+
lines.push(`Found ${result.data.length} result(s):`);
|
|
35
|
+
lines.push("");
|
|
36
|
+
for (const entry of result.data) {
|
|
37
|
+
const summary = entry.summary ? ` - ${entry.summary}` : "";
|
|
38
|
+
lines.push(` ${entry.path}${summary}`);
|
|
39
|
+
}
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.formatSearchOutput = formatSearchOutput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@aigne/afs";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/core/formatters/search.ts
|
|
2
|
+
/**
|
|
3
|
+
* Format search output for different views
|
|
4
|
+
*
|
|
5
|
+
* @param result - AFS search result (native type)
|
|
6
|
+
* @param view - View type (default, json, llm, human)
|
|
7
|
+
* @returns Formatted string (no ANSI colors)
|
|
8
|
+
*/
|
|
9
|
+
function formatSearchOutput(result, view) {
|
|
10
|
+
switch (view) {
|
|
11
|
+
case "json": return JSON.stringify(result, null, 2);
|
|
12
|
+
case "llm": return formatLlm(result);
|
|
13
|
+
case "human": return formatHuman(result);
|
|
14
|
+
default: return formatDefault(result);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function formatDefault(result) {
|
|
18
|
+
if (result.data.length === 0) return result.message || "No results found";
|
|
19
|
+
return result.data.map((entry) => entry.path).join("\n");
|
|
20
|
+
}
|
|
21
|
+
function formatLlm(result) {
|
|
22
|
+
const lines = [];
|
|
23
|
+
lines.push(`SEARCH_RESULTS ${result.data.length}`);
|
|
24
|
+
for (const entry of result.data) {
|
|
25
|
+
const summary = entry.summary ? ` "${entry.summary}"` : "";
|
|
26
|
+
lines.push(`RESULT ${entry.path}${summary}`);
|
|
27
|
+
}
|
|
28
|
+
return lines.join("\n");
|
|
29
|
+
}
|
|
30
|
+
function formatHuman(result) {
|
|
31
|
+
if (result.data.length === 0) return result.message || "No results found";
|
|
32
|
+
const lines = [];
|
|
33
|
+
lines.push(`Found ${result.data.length} result(s):`);
|
|
34
|
+
lines.push("");
|
|
35
|
+
for (const entry of result.data) {
|
|
36
|
+
const summary = entry.summary ? ` - ${entry.summary}` : "";
|
|
37
|
+
lines.push(` ${entry.path}${summary}`);
|
|
38
|
+
}
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { formatSearchOutput };
|
|
44
|
+
//# sourceMappingURL=search.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.mjs","names":[],"sources":["../../../src/core/formatters/search.ts"],"sourcesContent":["/**\n * search Formatter - Core Implementation\n *\n * Formats search output without colors.\n * Accepts AFS native AFSSearchResult directly.\n */\n\nimport type { AFSSearchResult } from \"@aigne/afs\";\nimport type { ViewType } from \"../types.js\";\n\n/**\n * Format search output for different views\n *\n * @param result - AFS search result (native type)\n * @param view - View type (default, json, llm, human)\n * @returns Formatted string (no ANSI colors)\n */\nexport function formatSearchOutput(result: AFSSearchResult, view: ViewType): string {\n switch (view) {\n case \"json\":\n return JSON.stringify(result, null, 2);\n case \"llm\":\n return formatLlm(result);\n case \"human\":\n return formatHuman(result);\n default:\n return formatDefault(result);\n }\n}\n\nfunction formatDefault(result: AFSSearchResult): string {\n if (result.data.length === 0) {\n return result.message || \"No results found\";\n }\n return result.data.map((entry) => entry.path).join(\"\\n\");\n}\n\nfunction formatLlm(result: AFSSearchResult): string {\n const lines: string[] = [];\n lines.push(`SEARCH_RESULTS ${result.data.length}`);\n for (const entry of result.data) {\n const summary = entry.summary ? ` \"${entry.summary}\"` : \"\";\n lines.push(`RESULT ${entry.path}${summary}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction formatHuman(result: AFSSearchResult): string {\n if (result.data.length === 0) {\n return result.message || \"No results found\";\n }\n const lines: string[] = [];\n lines.push(`Found ${result.data.length} result(s):`);\n lines.push(\"\");\n for (const entry of result.data) {\n const summary = entry.summary ? ` - ${entry.summary}` : \"\";\n lines.push(` ${entry.path}${summary}`);\n }\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;;;AAiBA,SAAgB,mBAAmB,QAAyB,MAAwB;AAClF,SAAQ,MAAR;EACE,KAAK,OACH,QAAO,KAAK,UAAU,QAAQ,MAAM,EAAE;EACxC,KAAK,MACH,QAAO,UAAU,OAAO;EAC1B,KAAK,QACH,QAAO,YAAY,OAAO;EAC5B,QACE,QAAO,cAAc,OAAO;;;AAIlC,SAAS,cAAc,QAAiC;AACtD,KAAI,OAAO,KAAK,WAAW,EACzB,QAAO,OAAO,WAAW;AAE3B,QAAO,OAAO,KAAK,KAAK,UAAU,MAAM,KAAK,CAAC,KAAK,KAAK;;AAG1D,SAAS,UAAU,QAAiC;CAClD,MAAM,QAAkB,EAAE;AAC1B,OAAM,KAAK,kBAAkB,OAAO,KAAK,SAAS;AAClD,MAAK,MAAM,SAAS,OAAO,MAAM;EAC/B,MAAM,UAAU,MAAM,UAAU,KAAK,MAAM,QAAQ,KAAK;AACxD,QAAM,KAAK,UAAU,MAAM,OAAO,UAAU;;AAE9C,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,YAAY,QAAiC;AACpD,KAAI,OAAO,KAAK,WAAW,EACzB,QAAO,OAAO,WAAW;CAE3B,MAAM,QAAkB,EAAE;AAC1B,OAAM,KAAK,SAAS,OAAO,KAAK,OAAO,aAAa;AACpD,OAAM,KAAK,GAAG;AACd,MAAK,MAAM,SAAS,OAAO,MAAM;EAC/B,MAAM,UAAU,MAAM,UAAU,MAAM,MAAM,YAAY;AACxD,QAAM,KAAK,KAAK,MAAM,OAAO,UAAU;;AAEzC,QAAO,MAAM,KAAK,KAAK"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/formatters/stat.ts
|
|
3
|
+
/**
|
|
4
|
+
* Format stat output for different views
|
|
5
|
+
*
|
|
6
|
+
* @param result - AFS stat result (native type)
|
|
7
|
+
* @param view - View type (default, json, llm, human)
|
|
8
|
+
* @returns Formatted string (no ANSI colors)
|
|
9
|
+
*/
|
|
10
|
+
function formatStatOutput(result, view) {
|
|
11
|
+
switch (view) {
|
|
12
|
+
case "json": return formatJson(result);
|
|
13
|
+
case "llm": return formatLlm(result);
|
|
14
|
+
case "human": return formatHuman(result);
|
|
15
|
+
default: return formatDefault(result);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* JSON format: Flattened structure
|
|
20
|
+
*/
|
|
21
|
+
function formatJson(result) {
|
|
22
|
+
const data = result.data;
|
|
23
|
+
if (!data) return JSON.stringify({ error: result.message || "No data" }, null, 2);
|
|
24
|
+
const meta = data.meta;
|
|
25
|
+
const output = { path: data.path };
|
|
26
|
+
if (data.updatedAt) output.modified = safeISOString(data.updatedAt);
|
|
27
|
+
if (data.createdAt) output.created = safeISOString(data.createdAt);
|
|
28
|
+
if (data.actions && data.actions.length > 0) output.actions = data.actions.map((a) => ({
|
|
29
|
+
name: a.name,
|
|
30
|
+
description: a.description
|
|
31
|
+
}));
|
|
32
|
+
if (meta) {
|
|
33
|
+
for (const [key, value] of Object.entries(meta)) if (value !== null && value !== void 0) output[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return JSON.stringify(output, null, 2);
|
|
36
|
+
}
|
|
37
|
+
function formatDefault(result) {
|
|
38
|
+
const data = result.data;
|
|
39
|
+
if (!data) return result.message || "No data";
|
|
40
|
+
const meta = data.meta;
|
|
41
|
+
const lines = [];
|
|
42
|
+
lines.push(`PATH=${data.path}`);
|
|
43
|
+
if (meta?.kind) lines.push(`KIND=${meta.kind}`);
|
|
44
|
+
const kinds = meta?.kinds;
|
|
45
|
+
if (kinds && Array.isArray(kinds) && kinds.length > 0) lines.push(`KINDS=${kinds.join(",")}`);
|
|
46
|
+
if (meta?.size !== void 0) lines.push(`SIZE=${meta.size}`);
|
|
47
|
+
if (meta?.childrenCount !== void 0) lines.push(`CHILDREN=${meta.childrenCount}`);
|
|
48
|
+
if (data.updatedAt) lines.push(`MODIFIED=${formatDateValue(data.updatedAt)}`);
|
|
49
|
+
if (data.actions && data.actions.length > 0) lines.push(`ACTIONS=${data.actions.map((a) => a.name).join(",")}`);
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
function formatLlm(result) {
|
|
53
|
+
const data = result.data;
|
|
54
|
+
if (!data) return result.message || "NO_DATA";
|
|
55
|
+
const lines = [];
|
|
56
|
+
const meta = data.meta;
|
|
57
|
+
lines.push(`NODE ${data.path}`);
|
|
58
|
+
if (meta?.kind) lines.push(`KIND ${meta.kind}`);
|
|
59
|
+
const kinds = meta?.kinds;
|
|
60
|
+
if (kinds && Array.isArray(kinds) && kinds.length > 0) lines.push(`KINDS ${kinds.join(" ")}`);
|
|
61
|
+
if (meta?.size !== void 0) lines.push(`SIZE ${meta.size}`);
|
|
62
|
+
if (meta?.childrenCount !== void 0) lines.push(`CHILDREN ${meta.childrenCount}`);
|
|
63
|
+
if (data.updatedAt) lines.push(`UPDATED ${formatDateValue(data.updatedAt)}`);
|
|
64
|
+
if (meta) for (let [key, value] of Object.entries(meta)) {
|
|
65
|
+
if ([
|
|
66
|
+
"kind",
|
|
67
|
+
"kinds",
|
|
68
|
+
"size",
|
|
69
|
+
"childrenCount"
|
|
70
|
+
].includes(key)) continue;
|
|
71
|
+
if (value === null || value === void 0) continue;
|
|
72
|
+
if (typeof value === "object") value = JSON.stringify(value);
|
|
73
|
+
lines.push(`META_${key.toUpperCase()} ${value}`);
|
|
74
|
+
}
|
|
75
|
+
if (data.actions && data.actions.length > 0) {
|
|
76
|
+
lines.push(`ACTIONS_COUNT ${data.actions.length}`);
|
|
77
|
+
for (const action of data.actions) {
|
|
78
|
+
const desc = action.description ? ` "${action.description}"` : "";
|
|
79
|
+
const schema = action.inputSchema;
|
|
80
|
+
const schemaPart = schema !== void 0 ? ` SCHEMA ${JSON.stringify(schema)}` : "";
|
|
81
|
+
lines.push(`ACTION ${action.name}${desc}${schemaPart}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
lines.push(`SIDE_EFFECT NONE`);
|
|
85
|
+
return lines.join("\n");
|
|
86
|
+
}
|
|
87
|
+
function formatHuman(result) {
|
|
88
|
+
const data = result.data;
|
|
89
|
+
if (!data) return result.message || "No data available";
|
|
90
|
+
const lines = [];
|
|
91
|
+
const meta = data.meta;
|
|
92
|
+
lines.push(`Path: ${data.path}`);
|
|
93
|
+
if (meta?.kind) lines.push(`Kind: ${meta.kind}`);
|
|
94
|
+
const kinds = meta?.kinds;
|
|
95
|
+
if (kinds && Array.isArray(kinds) && kinds.length > 0) lines.push(`Kinds: ${kinds.join(" → ")}`);
|
|
96
|
+
if (meta?.size !== void 0) lines.push(`Size: ${formatSize(meta.size)}`);
|
|
97
|
+
if (meta?.childrenCount !== void 0) lines.push(`Children: ${meta.childrenCount}`);
|
|
98
|
+
if (data.updatedAt) lines.push(`Modified: ${formatDate(data.updatedAt)}`);
|
|
99
|
+
if (meta) for (let [key, value] of Object.entries(meta)) {
|
|
100
|
+
if ([
|
|
101
|
+
"kind",
|
|
102
|
+
"kinds",
|
|
103
|
+
"size",
|
|
104
|
+
"childrenCount"
|
|
105
|
+
].includes(key)) continue;
|
|
106
|
+
if (value === null || value === void 0) continue;
|
|
107
|
+
if (typeof value === "object") value = JSON.stringify(value);
|
|
108
|
+
const label = `${key.charAt(0).toUpperCase() + key.slice(1)}:`;
|
|
109
|
+
const padding = label.length < 10 ? " ".repeat(10 - label.length) : "";
|
|
110
|
+
lines.push(`${label}${padding}${value}`);
|
|
111
|
+
}
|
|
112
|
+
if (data.actions && data.actions.length > 0) {
|
|
113
|
+
lines.push("");
|
|
114
|
+
lines.push(`Actions (${data.actions.length}):`);
|
|
115
|
+
for (const action of data.actions) {
|
|
116
|
+
const desc = action.description ? ` - ${action.description}` : "";
|
|
117
|
+
lines.push(` • ${action.name}${desc}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return lines.join("\n");
|
|
121
|
+
}
|
|
122
|
+
function formatSize(bytes) {
|
|
123
|
+
if (bytes < 1024) return `${bytes} bytes`;
|
|
124
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
125
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Safely convert a date value to ISO string.
|
|
129
|
+
* Handles Date objects, strings, and other types.
|
|
130
|
+
*/
|
|
131
|
+
function safeISOString(date) {
|
|
132
|
+
if (date instanceof Date) return date.toISOString();
|
|
133
|
+
if (typeof date === "string") return date;
|
|
134
|
+
return String(date);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Format Date to ISO string (for default/llm views)
|
|
138
|
+
*/
|
|
139
|
+
function formatDateValue(date) {
|
|
140
|
+
return safeISOString(date);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Format Date for human-readable display
|
|
144
|
+
*/
|
|
145
|
+
function formatDate(date) {
|
|
146
|
+
if (date instanceof Date) try {
|
|
147
|
+
return date.toLocaleString();
|
|
148
|
+
} catch {
|
|
149
|
+
return date.toISOString();
|
|
150
|
+
}
|
|
151
|
+
return safeISOString(date);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
exports.formatStatOutput = formatStatOutput;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViewType } from "../types.cjs";
|
|
2
|
+
import { AFSStatResult } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/formatters/stat.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Format stat output for different views
|
|
7
|
+
*
|
|
8
|
+
* @param result - AFS stat result (native type)
|
|
9
|
+
* @param view - View type (default, json, llm, human)
|
|
10
|
+
* @returns Formatted string (no ANSI colors)
|
|
11
|
+
*/
|
|
12
|
+
declare function formatStatOutput(result: AFSStatResult, view: ViewType): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { formatStatOutput };
|
|
15
|
+
//# sourceMappingURL=stat.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stat.d.cts","names":[],"sources":["../../../src/core/formatters/stat.ts"],"mappings":";;;;;;;;;;;iBAiBgB,gBAAA,CAAiB,MAAA,EAAQ,aAAA,EAAe,IAAA,EAAM,QAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViewType } from "../types.mjs";
|
|
2
|
+
import { AFSStatResult } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/formatters/stat.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Format stat output for different views
|
|
7
|
+
*
|
|
8
|
+
* @param result - AFS stat result (native type)
|
|
9
|
+
* @param view - View type (default, json, llm, human)
|
|
10
|
+
* @returns Formatted string (no ANSI colors)
|
|
11
|
+
*/
|
|
12
|
+
declare function formatStatOutput(result: AFSStatResult, view: ViewType): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { formatStatOutput };
|
|
15
|
+
//# sourceMappingURL=stat.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stat.d.mts","names":[],"sources":["../../../src/core/formatters/stat.ts"],"mappings":";;;;;;;;;;;iBAiBgB,gBAAA,CAAiB,MAAA,EAAQ,aAAA,EAAe,IAAA,EAAM,QAAA"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//#region src/core/formatters/stat.ts
|
|
2
|
+
/**
|
|
3
|
+
* Format stat output for different views
|
|
4
|
+
*
|
|
5
|
+
* @param result - AFS stat result (native type)
|
|
6
|
+
* @param view - View type (default, json, llm, human)
|
|
7
|
+
* @returns Formatted string (no ANSI colors)
|
|
8
|
+
*/
|
|
9
|
+
function formatStatOutput(result, view) {
|
|
10
|
+
switch (view) {
|
|
11
|
+
case "json": return formatJson(result);
|
|
12
|
+
case "llm": return formatLlm(result);
|
|
13
|
+
case "human": return formatHuman(result);
|
|
14
|
+
default: return formatDefault(result);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* JSON format: Flattened structure
|
|
19
|
+
*/
|
|
20
|
+
function formatJson(result) {
|
|
21
|
+
const data = result.data;
|
|
22
|
+
if (!data) return JSON.stringify({ error: result.message || "No data" }, null, 2);
|
|
23
|
+
const meta = data.meta;
|
|
24
|
+
const output = { path: data.path };
|
|
25
|
+
if (data.updatedAt) output.modified = safeISOString(data.updatedAt);
|
|
26
|
+
if (data.createdAt) output.created = safeISOString(data.createdAt);
|
|
27
|
+
if (data.actions && data.actions.length > 0) output.actions = data.actions.map((a) => ({
|
|
28
|
+
name: a.name,
|
|
29
|
+
description: a.description
|
|
30
|
+
}));
|
|
31
|
+
if (meta) {
|
|
32
|
+
for (const [key, value] of Object.entries(meta)) if (value !== null && value !== void 0) output[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return JSON.stringify(output, null, 2);
|
|
35
|
+
}
|
|
36
|
+
function formatDefault(result) {
|
|
37
|
+
const data = result.data;
|
|
38
|
+
if (!data) return result.message || "No data";
|
|
39
|
+
const meta = data.meta;
|
|
40
|
+
const lines = [];
|
|
41
|
+
lines.push(`PATH=${data.path}`);
|
|
42
|
+
if (meta?.kind) lines.push(`KIND=${meta.kind}`);
|
|
43
|
+
const kinds = meta?.kinds;
|
|
44
|
+
if (kinds && Array.isArray(kinds) && kinds.length > 0) lines.push(`KINDS=${kinds.join(",")}`);
|
|
45
|
+
if (meta?.size !== void 0) lines.push(`SIZE=${meta.size}`);
|
|
46
|
+
if (meta?.childrenCount !== void 0) lines.push(`CHILDREN=${meta.childrenCount}`);
|
|
47
|
+
if (data.updatedAt) lines.push(`MODIFIED=${formatDateValue(data.updatedAt)}`);
|
|
48
|
+
if (data.actions && data.actions.length > 0) lines.push(`ACTIONS=${data.actions.map((a) => a.name).join(",")}`);
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
}
|
|
51
|
+
function formatLlm(result) {
|
|
52
|
+
const data = result.data;
|
|
53
|
+
if (!data) return result.message || "NO_DATA";
|
|
54
|
+
const lines = [];
|
|
55
|
+
const meta = data.meta;
|
|
56
|
+
lines.push(`NODE ${data.path}`);
|
|
57
|
+
if (meta?.kind) lines.push(`KIND ${meta.kind}`);
|
|
58
|
+
const kinds = meta?.kinds;
|
|
59
|
+
if (kinds && Array.isArray(kinds) && kinds.length > 0) lines.push(`KINDS ${kinds.join(" ")}`);
|
|
60
|
+
if (meta?.size !== void 0) lines.push(`SIZE ${meta.size}`);
|
|
61
|
+
if (meta?.childrenCount !== void 0) lines.push(`CHILDREN ${meta.childrenCount}`);
|
|
62
|
+
if (data.updatedAt) lines.push(`UPDATED ${formatDateValue(data.updatedAt)}`);
|
|
63
|
+
if (meta) for (let [key, value] of Object.entries(meta)) {
|
|
64
|
+
if ([
|
|
65
|
+
"kind",
|
|
66
|
+
"kinds",
|
|
67
|
+
"size",
|
|
68
|
+
"childrenCount"
|
|
69
|
+
].includes(key)) continue;
|
|
70
|
+
if (value === null || value === void 0) continue;
|
|
71
|
+
if (typeof value === "object") value = JSON.stringify(value);
|
|
72
|
+
lines.push(`META_${key.toUpperCase()} ${value}`);
|
|
73
|
+
}
|
|
74
|
+
if (data.actions && data.actions.length > 0) {
|
|
75
|
+
lines.push(`ACTIONS_COUNT ${data.actions.length}`);
|
|
76
|
+
for (const action of data.actions) {
|
|
77
|
+
const desc = action.description ? ` "${action.description}"` : "";
|
|
78
|
+
const schema = action.inputSchema;
|
|
79
|
+
const schemaPart = schema !== void 0 ? ` SCHEMA ${JSON.stringify(schema)}` : "";
|
|
80
|
+
lines.push(`ACTION ${action.name}${desc}${schemaPart}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
lines.push(`SIDE_EFFECT NONE`);
|
|
84
|
+
return lines.join("\n");
|
|
85
|
+
}
|
|
86
|
+
function formatHuman(result) {
|
|
87
|
+
const data = result.data;
|
|
88
|
+
if (!data) return result.message || "No data available";
|
|
89
|
+
const lines = [];
|
|
90
|
+
const meta = data.meta;
|
|
91
|
+
lines.push(`Path: ${data.path}`);
|
|
92
|
+
if (meta?.kind) lines.push(`Kind: ${meta.kind}`);
|
|
93
|
+
const kinds = meta?.kinds;
|
|
94
|
+
if (kinds && Array.isArray(kinds) && kinds.length > 0) lines.push(`Kinds: ${kinds.join(" → ")}`);
|
|
95
|
+
if (meta?.size !== void 0) lines.push(`Size: ${formatSize(meta.size)}`);
|
|
96
|
+
if (meta?.childrenCount !== void 0) lines.push(`Children: ${meta.childrenCount}`);
|
|
97
|
+
if (data.updatedAt) lines.push(`Modified: ${formatDate(data.updatedAt)}`);
|
|
98
|
+
if (meta) for (let [key, value] of Object.entries(meta)) {
|
|
99
|
+
if ([
|
|
100
|
+
"kind",
|
|
101
|
+
"kinds",
|
|
102
|
+
"size",
|
|
103
|
+
"childrenCount"
|
|
104
|
+
].includes(key)) continue;
|
|
105
|
+
if (value === null || value === void 0) continue;
|
|
106
|
+
if (typeof value === "object") value = JSON.stringify(value);
|
|
107
|
+
const label = `${key.charAt(0).toUpperCase() + key.slice(1)}:`;
|
|
108
|
+
const padding = label.length < 10 ? " ".repeat(10 - label.length) : "";
|
|
109
|
+
lines.push(`${label}${padding}${value}`);
|
|
110
|
+
}
|
|
111
|
+
if (data.actions && data.actions.length > 0) {
|
|
112
|
+
lines.push("");
|
|
113
|
+
lines.push(`Actions (${data.actions.length}):`);
|
|
114
|
+
for (const action of data.actions) {
|
|
115
|
+
const desc = action.description ? ` - ${action.description}` : "";
|
|
116
|
+
lines.push(` • ${action.name}${desc}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return lines.join("\n");
|
|
120
|
+
}
|
|
121
|
+
function formatSize(bytes) {
|
|
122
|
+
if (bytes < 1024) return `${bytes} bytes`;
|
|
123
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
124
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Safely convert a date value to ISO string.
|
|
128
|
+
* Handles Date objects, strings, and other types.
|
|
129
|
+
*/
|
|
130
|
+
function safeISOString(date) {
|
|
131
|
+
if (date instanceof Date) return date.toISOString();
|
|
132
|
+
if (typeof date === "string") return date;
|
|
133
|
+
return String(date);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Format Date to ISO string (for default/llm views)
|
|
137
|
+
*/
|
|
138
|
+
function formatDateValue(date) {
|
|
139
|
+
return safeISOString(date);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Format Date for human-readable display
|
|
143
|
+
*/
|
|
144
|
+
function formatDate(date) {
|
|
145
|
+
if (date instanceof Date) try {
|
|
146
|
+
return date.toLocaleString();
|
|
147
|
+
} catch {
|
|
148
|
+
return date.toISOString();
|
|
149
|
+
}
|
|
150
|
+
return safeISOString(date);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
export { formatStatOutput };
|
|
155
|
+
//# sourceMappingURL=stat.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stat.mjs","names":[],"sources":["../../../src/core/formatters/stat.ts"],"sourcesContent":["/**\n * stat Formatter - Core Implementation\n *\n * Formats stat output without colors.\n * Accepts AFS native AFSStatResult directly.\n */\n\nimport type { AFSStatResult } from \"@aigne/afs\";\nimport type { ViewType } from \"../types.js\";\n\n/**\n * Format stat output for different views\n *\n * @param result - AFS stat result (native type)\n * @param view - View type (default, json, llm, human)\n * @returns Formatted string (no ANSI colors)\n */\nexport function formatStatOutput(result: AFSStatResult, view: ViewType): string {\n switch (view) {\n case \"json\":\n return formatJson(result);\n case \"llm\":\n return formatLlm(result);\n case \"human\":\n return formatHuman(result);\n default:\n return formatDefault(result);\n }\n}\n\n/**\n * JSON format: Flattened structure\n */\nfunction formatJson(result: AFSStatResult): string {\n const data = result.data;\n if (!data) {\n return JSON.stringify({ error: result.message || \"No data\" }, null, 2);\n }\n\n const meta = data.meta as Record<string, unknown> | undefined;\n const output: Record<string, unknown> = {\n path: data.path,\n };\n\n if (data.updatedAt) {\n output.modified = safeISOString(data.updatedAt);\n }\n if (data.createdAt) {\n output.created = safeISOString(data.createdAt);\n }\n if (data.actions && data.actions.length > 0) {\n output.actions = data.actions.map((a) => ({\n name: a.name,\n description: a.description,\n }));\n }\n\n // Merge metadata at top level (includes size, childrenCount, etc.)\n if (meta) {\n for (const [key, value] of Object.entries(meta)) {\n if (value !== null && value !== undefined) {\n output[key] = value;\n }\n }\n }\n\n return JSON.stringify(output, null, 2);\n}\n\nfunction formatDefault(result: AFSStatResult): string {\n const data = result.data;\n if (!data) {\n return result.message || \"No data\";\n }\n\n const meta = data.meta as Record<string, unknown> | undefined;\n const lines: string[] = [];\n\n lines.push(`PATH=${data.path}`);\n\n if (meta?.kind) {\n lines.push(`KIND=${meta.kind}`);\n }\n\n const kinds = meta?.kinds;\n if (kinds && Array.isArray(kinds) && kinds.length > 0) {\n lines.push(`KINDS=${kinds.join(\",\")}`);\n }\n\n if (meta?.size !== undefined) {\n lines.push(`SIZE=${meta.size}`);\n }\n\n if (meta?.childrenCount !== undefined) {\n lines.push(`CHILDREN=${meta.childrenCount}`);\n }\n\n if (data.updatedAt) {\n lines.push(`MODIFIED=${formatDateValue(data.updatedAt)}`);\n }\n\n if (data.actions && data.actions.length > 0) {\n lines.push(`ACTIONS=${data.actions.map((a) => a.name).join(\",\")}`);\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction formatLlm(result: AFSStatResult): string {\n const data = result.data;\n if (!data) {\n return result.message || \"NO_DATA\";\n }\n\n const lines: string[] = [];\n const meta = data.meta as Record<string, unknown> | undefined;\n\n lines.push(`NODE ${data.path}`);\n\n if (meta?.kind) {\n lines.push(`KIND ${meta.kind}`);\n }\n\n const kinds = meta?.kinds;\n if (kinds && Array.isArray(kinds) && kinds.length > 0) {\n lines.push(`KINDS ${kinds.join(\" \")}`);\n }\n\n if (meta?.size !== undefined) {\n lines.push(`SIZE ${meta.size}`);\n }\n\n if (meta?.childrenCount !== undefined) {\n lines.push(`CHILDREN ${meta.childrenCount}`);\n }\n\n if (data.updatedAt) {\n lines.push(`UPDATED ${formatDateValue(data.updatedAt)}`);\n }\n\n // Provider-specific metadata as META_* fields\n if (meta) {\n for (let [key, value] of Object.entries(meta)) {\n // Skip already handled fields\n if ([\"kind\", \"kinds\", \"size\", \"childrenCount\"].includes(key)) continue;\n // Skip complex values\n if (value === null || value === undefined) continue;\n if (typeof value === \"object\") value = JSON.stringify(value);\n\n lines.push(`META_${key.toUpperCase()} ${value}`);\n }\n }\n\n if (data.actions && data.actions.length > 0) {\n lines.push(`ACTIONS_COUNT ${data.actions.length}`);\n for (const action of data.actions) {\n const desc = action.description ? ` \"${action.description}\"` : \"\";\n const schema = action.inputSchema;\n const schemaPart = schema !== undefined ? ` SCHEMA ${JSON.stringify(schema)}` : \"\";\n lines.push(`ACTION ${action.name}${desc}${schemaPart}`);\n }\n }\n\n lines.push(`SIDE_EFFECT NONE`);\n\n return lines.join(\"\\n\");\n}\n\nfunction formatHuman(result: AFSStatResult): string {\n const data = result.data;\n if (!data) {\n return result.message || \"No data available\";\n }\n\n const lines: string[] = [];\n const meta = data.meta as Record<string, unknown> | undefined;\n\n lines.push(`Path: ${data.path}`);\n\n if (meta?.kind) {\n lines.push(`Kind: ${meta.kind}`);\n }\n\n const kinds = meta?.kinds;\n if (kinds && Array.isArray(kinds) && kinds.length > 0) {\n lines.push(`Kinds: ${kinds.join(\" → \")}`);\n }\n\n if (meta?.size !== undefined) {\n lines.push(`Size: ${formatSize(meta.size as number)}`);\n }\n\n if (meta?.childrenCount !== undefined) {\n lines.push(`Children: ${meta.childrenCount}`);\n }\n\n if (data.updatedAt) {\n lines.push(`Modified: ${formatDate(data.updatedAt)}`);\n }\n\n // Provider-specific metadata\n if (meta) {\n for (let [key, value] of Object.entries(meta)) {\n // Skip already handled fields\n if ([\"kind\", \"kinds\", \"size\", \"childrenCount\"].includes(key)) continue;\n // Skip complex values\n if (value === null || value === undefined) continue;\n if (typeof value === \"object\") value = JSON.stringify(value);\n\n // Format key in PascalCase with proper padding\n const formattedKey = key.charAt(0).toUpperCase() + key.slice(1);\n const label = `${formattedKey}:`;\n // Pad to 10 chars if shorter, otherwise no space between label and value\n const padding = label.length < 10 ? \" \".repeat(10 - label.length) : \"\";\n lines.push(`${label}${padding}${value}`);\n }\n }\n\n if (data.actions && data.actions.length > 0) {\n lines.push(\"\");\n lines.push(`Actions (${data.actions.length}):`);\n for (const action of data.actions) {\n const desc = action.description ? ` - ${action.description}` : \"\";\n lines.push(` • ${action.name}${desc}`);\n }\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction formatSize(bytes: number): string {\n if (bytes < 1024) return `${bytes} bytes`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n\n/**\n * Safely convert a date value to ISO string.\n * Handles Date objects, strings, and other types.\n */\nfunction safeISOString(date: unknown): string {\n if (date instanceof Date) return date.toISOString();\n if (typeof date === \"string\") return date;\n return String(date);\n}\n\n/**\n * Format Date to ISO string (for default/llm views)\n */\nfunction formatDateValue(date: unknown): string {\n return safeISOString(date);\n}\n\n/**\n * Format Date for human-readable display\n */\nfunction formatDate(date: unknown): string {\n if (date instanceof Date) {\n try {\n return date.toLocaleString();\n } catch {\n return date.toISOString();\n }\n }\n return safeISOString(date);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/formatters/write.ts
|
|
3
|
+
/**
|
|
4
|
+
* Format write output for different views
|
|
5
|
+
*
|
|
6
|
+
* @param result - AFS write result (native type)
|
|
7
|
+
* @param view - View type (default, json, llm, human)
|
|
8
|
+
* @param options - Format options (e.g., metadata fields)
|
|
9
|
+
* @returns Formatted string (no ANSI colors)
|
|
10
|
+
*/
|
|
11
|
+
function formatWriteOutput(result, view, options) {
|
|
12
|
+
switch (view) {
|
|
13
|
+
case "json": return formatJson(result, options);
|
|
14
|
+
case "llm": return formatLlm(result, options);
|
|
15
|
+
case "human": return formatHuman(result, options);
|
|
16
|
+
default: return formatDefault(result);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function formatJson(result, options) {
|
|
20
|
+
const output = {
|
|
21
|
+
path: result.data.path,
|
|
22
|
+
success: true
|
|
23
|
+
};
|
|
24
|
+
if (result.data.meta?.size !== void 0) output.size = result.data.meta.size;
|
|
25
|
+
if (options?.fields && options.fields.length > 0) output.fields = options.fields;
|
|
26
|
+
return JSON.stringify(output, null, 2);
|
|
27
|
+
}
|
|
28
|
+
function formatDefault(result) {
|
|
29
|
+
return `OK ${result.data.path}`;
|
|
30
|
+
}
|
|
31
|
+
function formatLlm(result, options) {
|
|
32
|
+
const lines = [];
|
|
33
|
+
lines.push(`WRITE ${result.data.path}`);
|
|
34
|
+
lines.push("STATUS SUCCESS");
|
|
35
|
+
if (result.data.meta?.size !== void 0) lines.push(`SIZE ${result.data.meta.size}`);
|
|
36
|
+
if (options?.fields && options.fields.length > 0) {
|
|
37
|
+
lines.push(`FIELDS ${options.fields.join(",")}`);
|
|
38
|
+
lines.push("SIDE_EFFECT META_UPDATED");
|
|
39
|
+
}
|
|
40
|
+
if (result.message) lines.push(`MESSAGE ${result.message}`);
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
}
|
|
43
|
+
function formatHuman(result, options) {
|
|
44
|
+
const parts = [`Successfully wrote to ${result.data.path}`];
|
|
45
|
+
if (result.data.meta?.size !== void 0) parts.push(`(${result.data.meta.size} bytes)`);
|
|
46
|
+
if (options?.fields && options.fields.length > 0) parts.push(`[meta: ${options.fields.join(", ")}]`);
|
|
47
|
+
return parts.join(" ");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.formatWriteOutput = formatWriteOutput;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ViewType } from "../types.cjs";
|
|
2
|
+
import { AFSWriteResult } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/formatters/write.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Additional metadata fields that were written
|
|
7
|
+
*/
|
|
8
|
+
interface WriteFormatOptions {
|
|
9
|
+
fields?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Format write output for different views
|
|
13
|
+
*
|
|
14
|
+
* @param result - AFS write result (native type)
|
|
15
|
+
* @param view - View type (default, json, llm, human)
|
|
16
|
+
* @param options - Format options (e.g., metadata fields)
|
|
17
|
+
* @returns Formatted string (no ANSI colors)
|
|
18
|
+
*/
|
|
19
|
+
declare function formatWriteOutput(result: AFSWriteResult, view: ViewType, options?: WriteFormatOptions): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { formatWriteOutput };
|
|
22
|
+
//# sourceMappingURL=write.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.cts","names":[],"sources":["../../../src/core/formatters/write.ts"],"mappings":";;;;;AAyBA;;UAZiB,kBAAA;EACf,MAAA;AAAA;;;;;;;;;iBAWc,iBAAA,CACd,MAAA,EAAQ,cAAA,EACR,IAAA,EAAM,QAAA,EACN,OAAA,GAAU,kBAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ViewType } from "../types.mjs";
|
|
2
|
+
import { AFSWriteResult } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/formatters/write.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Additional metadata fields that were written
|
|
7
|
+
*/
|
|
8
|
+
interface WriteFormatOptions {
|
|
9
|
+
fields?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Format write output for different views
|
|
13
|
+
*
|
|
14
|
+
* @param result - AFS write result (native type)
|
|
15
|
+
* @param view - View type (default, json, llm, human)
|
|
16
|
+
* @param options - Format options (e.g., metadata fields)
|
|
17
|
+
* @returns Formatted string (no ANSI colors)
|
|
18
|
+
*/
|
|
19
|
+
declare function formatWriteOutput(result: AFSWriteResult, view: ViewType, options?: WriteFormatOptions): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { formatWriteOutput };
|
|
22
|
+
//# sourceMappingURL=write.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.mts","names":[],"sources":["../../../src/core/formatters/write.ts"],"mappings":";;;;;AAyBA;;UAZiB,kBAAA;EACf,MAAA;AAAA;;;;;;;;;iBAWc,iBAAA,CACd,MAAA,EAAQ,cAAA,EACR,IAAA,EAAM,QAAA,EACN,OAAA,GAAU,kBAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/core/formatters/write.ts
|
|
2
|
+
/**
|
|
3
|
+
* Format write output for different views
|
|
4
|
+
*
|
|
5
|
+
* @param result - AFS write result (native type)
|
|
6
|
+
* @param view - View type (default, json, llm, human)
|
|
7
|
+
* @param options - Format options (e.g., metadata fields)
|
|
8
|
+
* @returns Formatted string (no ANSI colors)
|
|
9
|
+
*/
|
|
10
|
+
function formatWriteOutput(result, view, options) {
|
|
11
|
+
switch (view) {
|
|
12
|
+
case "json": return formatJson(result, options);
|
|
13
|
+
case "llm": return formatLlm(result, options);
|
|
14
|
+
case "human": return formatHuman(result, options);
|
|
15
|
+
default: return formatDefault(result);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function formatJson(result, options) {
|
|
19
|
+
const output = {
|
|
20
|
+
path: result.data.path,
|
|
21
|
+
success: true
|
|
22
|
+
};
|
|
23
|
+
if (result.data.meta?.size !== void 0) output.size = result.data.meta.size;
|
|
24
|
+
if (options?.fields && options.fields.length > 0) output.fields = options.fields;
|
|
25
|
+
return JSON.stringify(output, null, 2);
|
|
26
|
+
}
|
|
27
|
+
function formatDefault(result) {
|
|
28
|
+
return `OK ${result.data.path}`;
|
|
29
|
+
}
|
|
30
|
+
function formatLlm(result, options) {
|
|
31
|
+
const lines = [];
|
|
32
|
+
lines.push(`WRITE ${result.data.path}`);
|
|
33
|
+
lines.push("STATUS SUCCESS");
|
|
34
|
+
if (result.data.meta?.size !== void 0) lines.push(`SIZE ${result.data.meta.size}`);
|
|
35
|
+
if (options?.fields && options.fields.length > 0) {
|
|
36
|
+
lines.push(`FIELDS ${options.fields.join(",")}`);
|
|
37
|
+
lines.push("SIDE_EFFECT META_UPDATED");
|
|
38
|
+
}
|
|
39
|
+
if (result.message) lines.push(`MESSAGE ${result.message}`);
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
function formatHuman(result, options) {
|
|
43
|
+
const parts = [`Successfully wrote to ${result.data.path}`];
|
|
44
|
+
if (result.data.meta?.size !== void 0) parts.push(`(${result.data.meta.size} bytes)`);
|
|
45
|
+
if (options?.fields && options.fields.length > 0) parts.push(`[meta: ${options.fields.join(", ")}]`);
|
|
46
|
+
return parts.join(" ");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { formatWriteOutput };
|
|
51
|
+
//# sourceMappingURL=write.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.mjs","names":[],"sources":["../../../src/core/formatters/write.ts"],"sourcesContent":["/**\n * write Formatter - Core Implementation\n *\n * Formats write output without colors.\n * Accepts AFS native AFSWriteResult directly.\n */\n\nimport type { AFSWriteResult } from \"@aigne/afs\";\nimport type { ViewType } from \"../types.js\";\n\n/**\n * Additional metadata fields that were written\n */\nexport interface WriteFormatOptions {\n fields?: string[];\n}\n\n/**\n * Format write output for different views\n *\n * @param result - AFS write result (native type)\n * @param view - View type (default, json, llm, human)\n * @param options - Format options (e.g., metadata fields)\n * @returns Formatted string (no ANSI colors)\n */\nexport function formatWriteOutput(\n result: AFSWriteResult,\n view: ViewType,\n options?: WriteFormatOptions,\n): string {\n switch (view) {\n case \"json\":\n return formatJson(result, options);\n case \"llm\":\n return formatLlm(result, options);\n case \"human\":\n return formatHuman(result, options);\n default:\n return formatDefault(result);\n }\n}\n\nfunction formatJson(result: AFSWriteResult, options?: WriteFormatOptions): string {\n const output: Record<string, unknown> = {\n path: result.data.path,\n success: true,\n };\n\n if (result.data.meta?.size !== undefined) {\n output.size = result.data.meta.size;\n }\n\n if (options?.fields && options.fields.length > 0) {\n output.fields = options.fields;\n }\n\n return JSON.stringify(output, null, 2);\n}\n\nfunction formatDefault(result: AFSWriteResult): string {\n return `OK ${result.data.path}`;\n}\n\nfunction formatLlm(result: AFSWriteResult, options?: WriteFormatOptions): string {\n const lines: string[] = [];\n\n lines.push(`WRITE ${result.data.path}`);\n lines.push(\"STATUS SUCCESS\");\n\n if (result.data.meta?.size !== undefined) {\n lines.push(`SIZE ${result.data.meta.size}`);\n }\n\n if (options?.fields && options.fields.length > 0) {\n lines.push(`FIELDS ${options.fields.join(\",\")}`);\n lines.push(\"SIDE_EFFECT META_UPDATED\");\n }\n\n if (result.message) {\n lines.push(`MESSAGE ${result.message}`);\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction formatHuman(result: AFSWriteResult, options?: WriteFormatOptions): string {\n const parts = [`Successfully wrote to ${result.data.path}`];\n\n if (result.data.meta?.size !== undefined) {\n parts.push(`(${result.data.meta.size} bytes)`);\n }\n\n if (options?.fields && options.fields.length > 0) {\n parts.push(`[meta: ${options.fields.join(\", \")}]`);\n }\n\n return parts.join(\" \");\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,kBACd,QACA,MACA,SACQ;AACR,SAAQ,MAAR;EACE,KAAK,OACH,QAAO,WAAW,QAAQ,QAAQ;EACpC,KAAK,MACH,QAAO,UAAU,QAAQ,QAAQ;EACnC,KAAK,QACH,QAAO,YAAY,QAAQ,QAAQ;EACrC,QACE,QAAO,cAAc,OAAO;;;AAIlC,SAAS,WAAW,QAAwB,SAAsC;CAChF,MAAM,SAAkC;EACtC,MAAM,OAAO,KAAK;EAClB,SAAS;EACV;AAED,KAAI,OAAO,KAAK,MAAM,SAAS,OAC7B,QAAO,OAAO,OAAO,KAAK,KAAK;AAGjC,KAAI,SAAS,UAAU,QAAQ,OAAO,SAAS,EAC7C,QAAO,SAAS,QAAQ;AAG1B,QAAO,KAAK,UAAU,QAAQ,MAAM,EAAE;;AAGxC,SAAS,cAAc,QAAgC;AACrD,QAAO,MAAM,OAAO,KAAK;;AAG3B,SAAS,UAAU,QAAwB,SAAsC;CAC/E,MAAM,QAAkB,EAAE;AAE1B,OAAM,KAAK,SAAS,OAAO,KAAK,OAAO;AACvC,OAAM,KAAK,iBAAiB;AAE5B,KAAI,OAAO,KAAK,MAAM,SAAS,OAC7B,OAAM,KAAK,QAAQ,OAAO,KAAK,KAAK,OAAO;AAG7C,KAAI,SAAS,UAAU,QAAQ,OAAO,SAAS,GAAG;AAChD,QAAM,KAAK,UAAU,QAAQ,OAAO,KAAK,IAAI,GAAG;AAChD,QAAM,KAAK,2BAA2B;;AAGxC,KAAI,OAAO,QACT,OAAM,KAAK,WAAW,OAAO,UAAU;AAGzC,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,YAAY,QAAwB,SAAsC;CACjF,MAAM,QAAQ,CAAC,yBAAyB,OAAO,KAAK,OAAO;AAE3D,KAAI,OAAO,KAAK,MAAM,SAAS,OAC7B,OAAM,KAAK,IAAI,OAAO,KAAK,KAAK,KAAK,SAAS;AAGhD,KAAI,SAAS,UAAU,QAAQ,OAAO,SAAS,EAC7C,OAAM,KAAK,UAAU,QAAQ,OAAO,KAAK,KAAK,CAAC,GAAG;AAGpD,QAAO,MAAM,KAAK,IAAI"}
|