@aigne/afs-cli 1.11.0-beta.1 → 1.11.0-beta.2
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 +13 -9
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/cli.cjs +215 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.mjs +205 -19
- package/dist/cli.mjs.map +1 -0
- package/dist/commands/exec.cjs +46 -0
- package/dist/commands/exec.mjs +45 -0
- package/dist/commands/exec.mjs.map +1 -0
- package/dist/commands/explain.cjs +244 -0
- package/dist/commands/explain.mjs +242 -0
- package/dist/commands/explain.mjs.map +1 -0
- package/dist/commands/index.cjs +7 -0
- package/dist/commands/index.mjs +9 -0
- package/dist/commands/ls.cjs +136 -0
- package/dist/commands/ls.mjs +135 -0
- package/dist/commands/ls.mjs.map +1 -0
- package/dist/commands/mount.cjs +157 -0
- package/dist/commands/mount.mjs +153 -0
- package/dist/commands/mount.mjs.map +1 -0
- package/dist/commands/read.cjs +65 -0
- package/dist/commands/read.mjs +64 -0
- package/dist/commands/read.mjs.map +1 -0
- package/dist/commands/stat.cjs +113 -0
- package/dist/commands/stat.mjs +112 -0
- package/dist/commands/stat.mjs.map +1 -0
- package/dist/commands/write.cjs +52 -0
- package/dist/commands/write.mjs +51 -0
- package/dist/commands/write.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 +160 -0
- package/dist/config/loader.mjs +158 -0
- package/dist/config/loader.mjs.map +1 -0
- package/dist/config/provider-factory.cjs +74 -0
- package/dist/config/provider-factory.mjs +75 -0
- package/dist/config/provider-factory.mjs.map +1 -0
- package/dist/config/schema.cjs +22 -0
- package/dist/config/schema.mjs +22 -0
- package/dist/config/schema.mjs.map +1 -0
- package/dist/config/uri-parser.cjs +75 -0
- package/dist/config/uri-parser.mjs +75 -0
- package/dist/config/uri-parser.mjs.map +1 -0
- package/dist/errors.cjs +29 -0
- package/dist/errors.mjs +28 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +1 -1
- package/dist/runtime.cjs +82 -0
- package/dist/runtime.mjs +82 -0
- package/dist/runtime.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 +51 -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,244 @@
|
|
|
1
|
+
const require_mount = require('./mount.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/commands/explain.ts
|
|
4
|
+
/**
|
|
5
|
+
* Explain AFS concepts or current configuration
|
|
6
|
+
*/
|
|
7
|
+
async function explainCommand(cwd, topic) {
|
|
8
|
+
switch (topic) {
|
|
9
|
+
case "mount":
|
|
10
|
+
case "mounts": return explainMounts(cwd);
|
|
11
|
+
case "path":
|
|
12
|
+
case "paths": return explainPaths();
|
|
13
|
+
case "uri": return explainUri();
|
|
14
|
+
default: return explainOverview();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Explain an AFS object at a given path
|
|
19
|
+
*/
|
|
20
|
+
async function explainPathCommand(runtime, path) {
|
|
21
|
+
const entry = (await runtime.read(path)).data;
|
|
22
|
+
if (!entry) return {
|
|
23
|
+
path,
|
|
24
|
+
type: "unknown"
|
|
25
|
+
};
|
|
26
|
+
const metadata = entry.metadata || {};
|
|
27
|
+
const entryType = metadata.type || "file";
|
|
28
|
+
const result = {
|
|
29
|
+
path: entry.path,
|
|
30
|
+
type: entryType,
|
|
31
|
+
description: metadata.description,
|
|
32
|
+
metadata: {}
|
|
33
|
+
};
|
|
34
|
+
if (metadata.provider) result.metadata.provider = String(metadata.provider);
|
|
35
|
+
if (metadata.permissions) {
|
|
36
|
+
const perms = metadata.permissions;
|
|
37
|
+
result.metadata.permissions = Array.isArray(perms) ? perms.join(", ") : String(perms);
|
|
38
|
+
}
|
|
39
|
+
if (entryType === "exec") {
|
|
40
|
+
if (metadata.inputs) result.inputs = Array.isArray(metadata.inputs) ? metadata.inputs : [String(metadata.inputs)];
|
|
41
|
+
if (metadata.outputs) result.outputs = Array.isArray(metadata.outputs) ? metadata.outputs : [String(metadata.outputs)];
|
|
42
|
+
if (metadata.errors) result.errors = Array.isArray(metadata.errors) ? metadata.errors : [String(metadata.errors)];
|
|
43
|
+
if (metadata.sideEffects) result.sideEffects = Array.isArray(metadata.sideEffects) ? metadata.sideEffects : [String(metadata.sideEffects)];
|
|
44
|
+
}
|
|
45
|
+
if (Object.keys(result.metadata).length === 0) delete result.metadata;
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function explainOverview() {
|
|
49
|
+
return {
|
|
50
|
+
topic: "AFS Overview",
|
|
51
|
+
explanation: `AFS (Abstract File System) is a virtual filesystem that unifies different data sources into a single namespace.
|
|
52
|
+
|
|
53
|
+
Core Concepts:
|
|
54
|
+
- mount: Mount a data source to a virtual path
|
|
55
|
+
- path: Virtual path, e.g., /src, /data
|
|
56
|
+
- uri: Data source address, e.g., fs://, git://, sqlite://
|
|
57
|
+
|
|
58
|
+
Data Flow:
|
|
59
|
+
User Path -> AFS -> /modules/{name} -> Provider -> Actual Data`,
|
|
60
|
+
examples: [
|
|
61
|
+
"afs mount add /src fs:///path/to/source",
|
|
62
|
+
"afs ls /modules/src",
|
|
63
|
+
"afs read /modules/src/file.txt"
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function explainMounts(cwd) {
|
|
68
|
+
const result = await require_mount.mountListCommand(cwd);
|
|
69
|
+
if (result.mounts.length === 0) return {
|
|
70
|
+
topic: "Mounts",
|
|
71
|
+
explanation: `No mounts configured.
|
|
72
|
+
|
|
73
|
+
Use mount add to add a mount:
|
|
74
|
+
afs mount add <path> <uri>
|
|
75
|
+
|
|
76
|
+
path: Virtual path for accessing data in AFS
|
|
77
|
+
uri: Data source URI specifying the data origin`,
|
|
78
|
+
examples: ["afs mount add /src fs:///Users/me/project", "afs mount add /data sqlite:///data.db"]
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
topic: "Mounts",
|
|
82
|
+
explanation: `Current mount configuration:
|
|
83
|
+
|
|
84
|
+
${result.mounts.map((m) => ` ${m.path} → ${m.uri}${m.description ? ` (${m.description})` : ""}`).join("\n")}
|
|
85
|
+
|
|
86
|
+
After mounting, data is accessed via /modules/{name}:
|
|
87
|
+
path="/src" -> /modules/src`,
|
|
88
|
+
examples: result.mounts.map((m) => {
|
|
89
|
+
return `afs ls /modules/${m.path.slice(1).replace(/\//g, "-") || "root"}`;
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function explainPaths() {
|
|
94
|
+
return {
|
|
95
|
+
topic: "Paths",
|
|
96
|
+
explanation: `AFS Path Structure:
|
|
97
|
+
|
|
98
|
+
/ Root directory
|
|
99
|
+
/modules All mounted modules
|
|
100
|
+
/modules/{name} Specific module, name derived from mount path
|
|
101
|
+
|
|
102
|
+
Path Mapping:
|
|
103
|
+
config: path="/src" -> access: /modules/src
|
|
104
|
+
config: path="/data" -> access: /modules/data
|
|
105
|
+
|
|
106
|
+
Note: The path configured by user is transformed to /modules/{name}`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function explainUri() {
|
|
110
|
+
return {
|
|
111
|
+
topic: "URI",
|
|
112
|
+
explanation: `AFS URI Schemes and Objects:
|
|
113
|
+
|
|
114
|
+
fs:// Local Filesystem Provider
|
|
115
|
+
Format: fs:///absolute/path or fs://./relative/path
|
|
116
|
+
Objects:
|
|
117
|
+
- directory: folder entries, supports list
|
|
118
|
+
- file: file entries, supports read/write
|
|
119
|
+
Operations: list, read, write, delete
|
|
120
|
+
|
|
121
|
+
git:// Git Repository Provider
|
|
122
|
+
Format: git:///local/repo or git://github.com/user/repo?branch=main
|
|
123
|
+
Objects:
|
|
124
|
+
- directory: tree entries
|
|
125
|
+
- file: blob entries, read-only
|
|
126
|
+
Operations: list, read
|
|
127
|
+
|
|
128
|
+
sqlite:// SQLite Database Provider
|
|
129
|
+
Format: sqlite:///path/to/db.sqlite
|
|
130
|
+
Objects:
|
|
131
|
+
- directory: database root, tables list
|
|
132
|
+
- exec: table entries, supports query operations
|
|
133
|
+
Operations: list, read, exec (SQL queries)
|
|
134
|
+
|
|
135
|
+
json:// JSON Data Provider
|
|
136
|
+
Format: json:///path/to/data.json
|
|
137
|
+
Objects:
|
|
138
|
+
- directory: object/array entries
|
|
139
|
+
- file: primitive values
|
|
140
|
+
Operations: list, read, write`,
|
|
141
|
+
examples: [
|
|
142
|
+
"afs mount add /src fs:///Users/me/project",
|
|
143
|
+
"afs mount add /repo git://github.com/user/repo",
|
|
144
|
+
"afs mount add /db sqlite:///data.sqlite"
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Format explain output for different views
|
|
150
|
+
*/
|
|
151
|
+
function formatExplainOutput(result, view) {
|
|
152
|
+
switch (view) {
|
|
153
|
+
case "json": return JSON.stringify(result, null, 2);
|
|
154
|
+
case "llm": return formatLlm(result);
|
|
155
|
+
default: return formatDefault(result);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function formatDefault(result) {
|
|
159
|
+
let output = `${result.topic}\n${"=".repeat(result.topic.length)}\n\n${result.explanation}`;
|
|
160
|
+
if (result.examples && result.examples.length > 0) output += `\n\nExamples:\n${result.examples.map((e) => ` $ ${e}`).join("\n")}`;
|
|
161
|
+
return output;
|
|
162
|
+
}
|
|
163
|
+
function formatLlm(result) {
|
|
164
|
+
const lines = [
|
|
165
|
+
`TOPIC ${result.topic}`,
|
|
166
|
+
"",
|
|
167
|
+
result.explanation
|
|
168
|
+
];
|
|
169
|
+
if (result.examples && result.examples.length > 0) {
|
|
170
|
+
lines.push("", "EXAMPLES");
|
|
171
|
+
for (const example of result.examples) lines.push(`CMD ${example}`);
|
|
172
|
+
}
|
|
173
|
+
return lines.join("\n");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Format object explain output for different views
|
|
177
|
+
*/
|
|
178
|
+
function formatPathExplainOutput(result, view) {
|
|
179
|
+
switch (view) {
|
|
180
|
+
case "json": return JSON.stringify(result, null, 2);
|
|
181
|
+
case "llm": return formatPathLlm(result);
|
|
182
|
+
default: return formatPathDefault(result);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function formatPathDefault(result) {
|
|
186
|
+
const lines = [];
|
|
187
|
+
lines.push(`PATH ${result.path}`);
|
|
188
|
+
lines.push("");
|
|
189
|
+
lines.push("TYPE");
|
|
190
|
+
lines.push(result.type);
|
|
191
|
+
if (result.description) {
|
|
192
|
+
lines.push("");
|
|
193
|
+
lines.push("DESCRIPTION");
|
|
194
|
+
lines.push(result.description);
|
|
195
|
+
}
|
|
196
|
+
if (result.inputs && result.inputs.length > 0) {
|
|
197
|
+
lines.push("");
|
|
198
|
+
lines.push("INPUTS");
|
|
199
|
+
for (const input of result.inputs) lines.push(`- ${input}`);
|
|
200
|
+
}
|
|
201
|
+
if (result.outputs && result.outputs.length > 0) {
|
|
202
|
+
lines.push("");
|
|
203
|
+
lines.push("OUTPUTS");
|
|
204
|
+
for (const output of result.outputs) lines.push(`- ${output}`);
|
|
205
|
+
}
|
|
206
|
+
if (result.errors && result.errors.length > 0) {
|
|
207
|
+
lines.push("");
|
|
208
|
+
lines.push("ERRORS");
|
|
209
|
+
for (const error of result.errors) lines.push(`- ${error}`);
|
|
210
|
+
}
|
|
211
|
+
if (result.sideEffects && result.sideEffects.length > 0) {
|
|
212
|
+
lines.push("");
|
|
213
|
+
lines.push("SIDE EFFECTS");
|
|
214
|
+
for (const effect of result.sideEffects) lines.push(`- ${effect}`);
|
|
215
|
+
} else {
|
|
216
|
+
lines.push("");
|
|
217
|
+
lines.push("SIDE EFFECTS");
|
|
218
|
+
lines.push("- none");
|
|
219
|
+
}
|
|
220
|
+
if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
221
|
+
lines.push("");
|
|
222
|
+
lines.push("METADATA");
|
|
223
|
+
for (const [key, value] of Object.entries(result.metadata)) lines.push(`- ${key}: ${value}`);
|
|
224
|
+
}
|
|
225
|
+
return lines.join("\n");
|
|
226
|
+
}
|
|
227
|
+
function formatPathLlm(result) {
|
|
228
|
+
const lines = [];
|
|
229
|
+
lines.push(`PATH ${result.path}`);
|
|
230
|
+
lines.push(`TYPE ${result.type.toUpperCase()}`);
|
|
231
|
+
if (result.description) lines.push(`DESC ${result.description}`);
|
|
232
|
+
if (result.inputs && result.inputs.length > 0) lines.push(`INPUTS ${result.inputs.join(", ")}`);
|
|
233
|
+
if (result.outputs && result.outputs.length > 0) lines.push(`OUTPUTS ${result.outputs.join(", ")}`);
|
|
234
|
+
if (result.errors && result.errors.length > 0) lines.push(`ERRORS ${result.errors.join(", ")}`);
|
|
235
|
+
lines.push(`SIDE_EFFECTS ${result.sideEffects?.join(", ") || "none"}`);
|
|
236
|
+
if (result.metadata) for (const [key, value] of Object.entries(result.metadata)) lines.push(`${key.toUpperCase()} ${value}`);
|
|
237
|
+
return lines.join("\n");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
exports.explainCommand = explainCommand;
|
|
242
|
+
exports.explainPathCommand = explainPathCommand;
|
|
243
|
+
exports.formatExplainOutput = formatExplainOutput;
|
|
244
|
+
exports.formatPathExplainOutput = formatPathExplainOutput;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { mountListCommand } from "./mount.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/commands/explain.ts
|
|
4
|
+
/**
|
|
5
|
+
* Explain AFS concepts or current configuration
|
|
6
|
+
*/
|
|
7
|
+
async function explainCommand(cwd, topic) {
|
|
8
|
+
switch (topic) {
|
|
9
|
+
case "mount":
|
|
10
|
+
case "mounts": return explainMounts(cwd);
|
|
11
|
+
case "path":
|
|
12
|
+
case "paths": return explainPaths();
|
|
13
|
+
case "uri": return explainUri();
|
|
14
|
+
default: return explainOverview();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Explain an AFS object at a given path
|
|
19
|
+
*/
|
|
20
|
+
async function explainPathCommand(runtime, path) {
|
|
21
|
+
const entry = (await runtime.read(path)).data;
|
|
22
|
+
if (!entry) return {
|
|
23
|
+
path,
|
|
24
|
+
type: "unknown"
|
|
25
|
+
};
|
|
26
|
+
const metadata = entry.metadata || {};
|
|
27
|
+
const entryType = metadata.type || "file";
|
|
28
|
+
const result = {
|
|
29
|
+
path: entry.path,
|
|
30
|
+
type: entryType,
|
|
31
|
+
description: metadata.description,
|
|
32
|
+
metadata: {}
|
|
33
|
+
};
|
|
34
|
+
if (metadata.provider) result.metadata.provider = String(metadata.provider);
|
|
35
|
+
if (metadata.permissions) {
|
|
36
|
+
const perms = metadata.permissions;
|
|
37
|
+
result.metadata.permissions = Array.isArray(perms) ? perms.join(", ") : String(perms);
|
|
38
|
+
}
|
|
39
|
+
if (entryType === "exec") {
|
|
40
|
+
if (metadata.inputs) result.inputs = Array.isArray(metadata.inputs) ? metadata.inputs : [String(metadata.inputs)];
|
|
41
|
+
if (metadata.outputs) result.outputs = Array.isArray(metadata.outputs) ? metadata.outputs : [String(metadata.outputs)];
|
|
42
|
+
if (metadata.errors) result.errors = Array.isArray(metadata.errors) ? metadata.errors : [String(metadata.errors)];
|
|
43
|
+
if (metadata.sideEffects) result.sideEffects = Array.isArray(metadata.sideEffects) ? metadata.sideEffects : [String(metadata.sideEffects)];
|
|
44
|
+
}
|
|
45
|
+
if (Object.keys(result.metadata).length === 0) delete result.metadata;
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function explainOverview() {
|
|
49
|
+
return {
|
|
50
|
+
topic: "AFS Overview",
|
|
51
|
+
explanation: `AFS (Abstract File System) is a virtual filesystem that unifies different data sources into a single namespace.
|
|
52
|
+
|
|
53
|
+
Core Concepts:
|
|
54
|
+
- mount: Mount a data source to a virtual path
|
|
55
|
+
- path: Virtual path, e.g., /src, /data
|
|
56
|
+
- uri: Data source address, e.g., fs://, git://, sqlite://
|
|
57
|
+
|
|
58
|
+
Data Flow:
|
|
59
|
+
User Path -> AFS -> /modules/{name} -> Provider -> Actual Data`,
|
|
60
|
+
examples: [
|
|
61
|
+
"afs mount add /src fs:///path/to/source",
|
|
62
|
+
"afs ls /modules/src",
|
|
63
|
+
"afs read /modules/src/file.txt"
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function explainMounts(cwd) {
|
|
68
|
+
const result = await mountListCommand(cwd);
|
|
69
|
+
if (result.mounts.length === 0) return {
|
|
70
|
+
topic: "Mounts",
|
|
71
|
+
explanation: `No mounts configured.
|
|
72
|
+
|
|
73
|
+
Use mount add to add a mount:
|
|
74
|
+
afs mount add <path> <uri>
|
|
75
|
+
|
|
76
|
+
path: Virtual path for accessing data in AFS
|
|
77
|
+
uri: Data source URI specifying the data origin`,
|
|
78
|
+
examples: ["afs mount add /src fs:///Users/me/project", "afs mount add /data sqlite:///data.db"]
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
topic: "Mounts",
|
|
82
|
+
explanation: `Current mount configuration:
|
|
83
|
+
|
|
84
|
+
${result.mounts.map((m) => ` ${m.path} → ${m.uri}${m.description ? ` (${m.description})` : ""}`).join("\n")}
|
|
85
|
+
|
|
86
|
+
After mounting, data is accessed via /modules/{name}:
|
|
87
|
+
path="/src" -> /modules/src`,
|
|
88
|
+
examples: result.mounts.map((m) => {
|
|
89
|
+
return `afs ls /modules/${m.path.slice(1).replace(/\//g, "-") || "root"}`;
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function explainPaths() {
|
|
94
|
+
return {
|
|
95
|
+
topic: "Paths",
|
|
96
|
+
explanation: `AFS Path Structure:
|
|
97
|
+
|
|
98
|
+
/ Root directory
|
|
99
|
+
/modules All mounted modules
|
|
100
|
+
/modules/{name} Specific module, name derived from mount path
|
|
101
|
+
|
|
102
|
+
Path Mapping:
|
|
103
|
+
config: path="/src" -> access: /modules/src
|
|
104
|
+
config: path="/data" -> access: /modules/data
|
|
105
|
+
|
|
106
|
+
Note: The path configured by user is transformed to /modules/{name}`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function explainUri() {
|
|
110
|
+
return {
|
|
111
|
+
topic: "URI",
|
|
112
|
+
explanation: `AFS URI Schemes and Objects:
|
|
113
|
+
|
|
114
|
+
fs:// Local Filesystem Provider
|
|
115
|
+
Format: fs:///absolute/path or fs://./relative/path
|
|
116
|
+
Objects:
|
|
117
|
+
- directory: folder entries, supports list
|
|
118
|
+
- file: file entries, supports read/write
|
|
119
|
+
Operations: list, read, write, delete
|
|
120
|
+
|
|
121
|
+
git:// Git Repository Provider
|
|
122
|
+
Format: git:///local/repo or git://github.com/user/repo?branch=main
|
|
123
|
+
Objects:
|
|
124
|
+
- directory: tree entries
|
|
125
|
+
- file: blob entries, read-only
|
|
126
|
+
Operations: list, read
|
|
127
|
+
|
|
128
|
+
sqlite:// SQLite Database Provider
|
|
129
|
+
Format: sqlite:///path/to/db.sqlite
|
|
130
|
+
Objects:
|
|
131
|
+
- directory: database root, tables list
|
|
132
|
+
- exec: table entries, supports query operations
|
|
133
|
+
Operations: list, read, exec (SQL queries)
|
|
134
|
+
|
|
135
|
+
json:// JSON Data Provider
|
|
136
|
+
Format: json:///path/to/data.json
|
|
137
|
+
Objects:
|
|
138
|
+
- directory: object/array entries
|
|
139
|
+
- file: primitive values
|
|
140
|
+
Operations: list, read, write`,
|
|
141
|
+
examples: [
|
|
142
|
+
"afs mount add /src fs:///Users/me/project",
|
|
143
|
+
"afs mount add /repo git://github.com/user/repo",
|
|
144
|
+
"afs mount add /db sqlite:///data.sqlite"
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Format explain output for different views
|
|
150
|
+
*/
|
|
151
|
+
function formatExplainOutput(result, view) {
|
|
152
|
+
switch (view) {
|
|
153
|
+
case "json": return JSON.stringify(result, null, 2);
|
|
154
|
+
case "llm": return formatLlm(result);
|
|
155
|
+
default: return formatDefault(result);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function formatDefault(result) {
|
|
159
|
+
let output = `${result.topic}\n${"=".repeat(result.topic.length)}\n\n${result.explanation}`;
|
|
160
|
+
if (result.examples && result.examples.length > 0) output += `\n\nExamples:\n${result.examples.map((e) => ` $ ${e}`).join("\n")}`;
|
|
161
|
+
return output;
|
|
162
|
+
}
|
|
163
|
+
function formatLlm(result) {
|
|
164
|
+
const lines = [
|
|
165
|
+
`TOPIC ${result.topic}`,
|
|
166
|
+
"",
|
|
167
|
+
result.explanation
|
|
168
|
+
];
|
|
169
|
+
if (result.examples && result.examples.length > 0) {
|
|
170
|
+
lines.push("", "EXAMPLES");
|
|
171
|
+
for (const example of result.examples) lines.push(`CMD ${example}`);
|
|
172
|
+
}
|
|
173
|
+
return lines.join("\n");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Format object explain output for different views
|
|
177
|
+
*/
|
|
178
|
+
function formatPathExplainOutput(result, view) {
|
|
179
|
+
switch (view) {
|
|
180
|
+
case "json": return JSON.stringify(result, null, 2);
|
|
181
|
+
case "llm": return formatPathLlm(result);
|
|
182
|
+
default: return formatPathDefault(result);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function formatPathDefault(result) {
|
|
186
|
+
const lines = [];
|
|
187
|
+
lines.push(`PATH ${result.path}`);
|
|
188
|
+
lines.push("");
|
|
189
|
+
lines.push("TYPE");
|
|
190
|
+
lines.push(result.type);
|
|
191
|
+
if (result.description) {
|
|
192
|
+
lines.push("");
|
|
193
|
+
lines.push("DESCRIPTION");
|
|
194
|
+
lines.push(result.description);
|
|
195
|
+
}
|
|
196
|
+
if (result.inputs && result.inputs.length > 0) {
|
|
197
|
+
lines.push("");
|
|
198
|
+
lines.push("INPUTS");
|
|
199
|
+
for (const input of result.inputs) lines.push(`- ${input}`);
|
|
200
|
+
}
|
|
201
|
+
if (result.outputs && result.outputs.length > 0) {
|
|
202
|
+
lines.push("");
|
|
203
|
+
lines.push("OUTPUTS");
|
|
204
|
+
for (const output of result.outputs) lines.push(`- ${output}`);
|
|
205
|
+
}
|
|
206
|
+
if (result.errors && result.errors.length > 0) {
|
|
207
|
+
lines.push("");
|
|
208
|
+
lines.push("ERRORS");
|
|
209
|
+
for (const error of result.errors) lines.push(`- ${error}`);
|
|
210
|
+
}
|
|
211
|
+
if (result.sideEffects && result.sideEffects.length > 0) {
|
|
212
|
+
lines.push("");
|
|
213
|
+
lines.push("SIDE EFFECTS");
|
|
214
|
+
for (const effect of result.sideEffects) lines.push(`- ${effect}`);
|
|
215
|
+
} else {
|
|
216
|
+
lines.push("");
|
|
217
|
+
lines.push("SIDE EFFECTS");
|
|
218
|
+
lines.push("- none");
|
|
219
|
+
}
|
|
220
|
+
if (result.metadata && Object.keys(result.metadata).length > 0) {
|
|
221
|
+
lines.push("");
|
|
222
|
+
lines.push("METADATA");
|
|
223
|
+
for (const [key, value] of Object.entries(result.metadata)) lines.push(`- ${key}: ${value}`);
|
|
224
|
+
}
|
|
225
|
+
return lines.join("\n");
|
|
226
|
+
}
|
|
227
|
+
function formatPathLlm(result) {
|
|
228
|
+
const lines = [];
|
|
229
|
+
lines.push(`PATH ${result.path}`);
|
|
230
|
+
lines.push(`TYPE ${result.type.toUpperCase()}`);
|
|
231
|
+
if (result.description) lines.push(`DESC ${result.description}`);
|
|
232
|
+
if (result.inputs && result.inputs.length > 0) lines.push(`INPUTS ${result.inputs.join(", ")}`);
|
|
233
|
+
if (result.outputs && result.outputs.length > 0) lines.push(`OUTPUTS ${result.outputs.join(", ")}`);
|
|
234
|
+
if (result.errors && result.errors.length > 0) lines.push(`ERRORS ${result.errors.join(", ")}`);
|
|
235
|
+
lines.push(`SIDE_EFFECTS ${result.sideEffects?.join(", ") || "none"}`);
|
|
236
|
+
if (result.metadata) for (const [key, value] of Object.entries(result.metadata)) lines.push(`${key.toUpperCase()} ${value}`);
|
|
237
|
+
return lines.join("\n");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
//#endregion
|
|
241
|
+
export { explainCommand, explainPathCommand, formatExplainOutput, formatPathExplainOutput };
|
|
242
|
+
//# sourceMappingURL=explain.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.mjs","names":[],"sources":["../../src/commands/explain.ts"],"sourcesContent":["import type { AFSRuntime } from \"../runtime.js\";\nimport type { ViewType } from \"./ls.js\";\nimport { mountListCommand } from \"./mount.js\";\n\nexport interface ExplainResult {\n topic: string;\n explanation: string;\n examples?: string[];\n}\n\nexport interface PathExplainResult {\n path: string;\n type: string;\n description?: string;\n inputs?: string[];\n outputs?: string[];\n errors?: string[];\n sideEffects?: string[];\n metadata?: Record<string, string>;\n}\n\n/**\n * Explain AFS concepts or current configuration\n */\nexport async function explainCommand(cwd: string, topic?: string): Promise<ExplainResult> {\n switch (topic) {\n case \"mount\":\n case \"mounts\":\n return explainMounts(cwd);\n case \"path\":\n case \"paths\":\n return explainPaths();\n case \"uri\":\n return explainUri();\n default:\n return explainOverview();\n }\n}\n\n/**\n * Explain an AFS object at a given path\n */\nexport async function explainPathCommand(\n runtime: AFSRuntime,\n path: string,\n): Promise<PathExplainResult> {\n const readResult = await runtime.read(path);\n const entry = readResult.data;\n\n if (!entry) {\n return {\n path,\n type: \"unknown\",\n };\n }\n\n const metadata = entry.metadata || {};\n const entryType = (metadata.type as string) || \"file\";\n\n const result: PathExplainResult = {\n path: entry.path,\n type: entryType,\n description: metadata.description as string | undefined,\n metadata: {},\n };\n\n // Add metadata\n if (metadata.provider) {\n result.metadata!.provider = String(metadata.provider);\n }\n if (metadata.permissions) {\n const perms = metadata.permissions;\n result.metadata!.permissions = Array.isArray(perms) ? perms.join(\", \") : String(perms);\n }\n\n // For exec type, try to get schema info\n if (entryType === \"exec\") {\n if (metadata.inputs) {\n result.inputs = Array.isArray(metadata.inputs)\n ? (metadata.inputs as string[])\n : [String(metadata.inputs)];\n }\n if (metadata.outputs) {\n result.outputs = Array.isArray(metadata.outputs)\n ? (metadata.outputs as string[])\n : [String(metadata.outputs)];\n }\n if (metadata.errors) {\n result.errors = Array.isArray(metadata.errors)\n ? (metadata.errors as string[])\n : [String(metadata.errors)];\n }\n if (metadata.sideEffects) {\n result.sideEffects = Array.isArray(metadata.sideEffects)\n ? (metadata.sideEffects as string[])\n : [String(metadata.sideEffects)];\n }\n }\n\n // Clean up empty metadata\n if (Object.keys(result.metadata!).length === 0) {\n delete result.metadata;\n }\n\n return result;\n}\n\nfunction explainOverview(): ExplainResult {\n return {\n topic: \"AFS Overview\",\n explanation: `AFS (Abstract File System) is a virtual filesystem that unifies different data sources into a single namespace.\n\nCore Concepts:\n- mount: Mount a data source to a virtual path\n- path: Virtual path, e.g., /src, /data\n- uri: Data source address, e.g., fs://, git://, sqlite://\n\nData Flow:\n User Path -> AFS -> /modules/{name} -> Provider -> Actual Data`,\n examples: [\n \"afs mount add /src fs:///path/to/source\",\n \"afs ls /modules/src\",\n \"afs read /modules/src/file.txt\",\n ],\n };\n}\n\nasync function explainMounts(cwd: string): Promise<ExplainResult> {\n const result = await mountListCommand(cwd);\n\n if (result.mounts.length === 0) {\n return {\n topic: \"Mounts\",\n explanation: `No mounts configured.\n\nUse mount add to add a mount:\n afs mount add <path> <uri>\n\npath: Virtual path for accessing data in AFS\nuri: Data source URI specifying the data origin`,\n examples: [\n \"afs mount add /src fs:///Users/me/project\",\n \"afs mount add /data sqlite:///data.db\",\n ],\n };\n }\n\n const mountList = result.mounts\n .map((m) => ` ${m.path} → ${m.uri}${m.description ? ` (${m.description})` : \"\"}`)\n .join(\"\\n\");\n\n return {\n topic: \"Mounts\",\n explanation: `Current mount configuration:\n\n${mountList}\n\nAfter mounting, data is accessed via /modules/{name}:\n path=\"/src\" -> /modules/src`,\n examples: result.mounts.map((m) => {\n const name = m.path.slice(1).replace(/\\//g, \"-\") || \"root\";\n return `afs ls /modules/${name}`;\n }),\n };\n}\n\nfunction explainPaths(): ExplainResult {\n return {\n topic: \"Paths\",\n explanation: `AFS Path Structure:\n\n/ Root directory\n/modules All mounted modules\n/modules/{name} Specific module, name derived from mount path\n\nPath Mapping:\n config: path=\"/src\" -> access: /modules/src\n config: path=\"/data\" -> access: /modules/data\n\nNote: The path configured by user is transformed to /modules/{name}`,\n };\n}\n\nfunction explainUri(): ExplainResult {\n return {\n topic: \"URI\",\n explanation: `AFS URI Schemes and Objects:\n\nfs:// Local Filesystem Provider\n Format: fs:///absolute/path or fs://./relative/path\n Objects:\n - directory: folder entries, supports list\n - file: file entries, supports read/write\n Operations: list, read, write, delete\n\ngit:// Git Repository Provider\n Format: git:///local/repo or git://github.com/user/repo?branch=main\n Objects:\n - directory: tree entries\n - file: blob entries, read-only\n Operations: list, read\n\nsqlite:// SQLite Database Provider\n Format: sqlite:///path/to/db.sqlite\n Objects:\n - directory: database root, tables list\n - exec: table entries, supports query operations\n Operations: list, read, exec (SQL queries)\n\njson:// JSON Data Provider\n Format: json:///path/to/data.json\n Objects:\n - directory: object/array entries\n - file: primitive values\n Operations: list, read, write`,\n examples: [\n \"afs mount add /src fs:///Users/me/project\",\n \"afs mount add /repo git://github.com/user/repo\",\n \"afs mount add /db sqlite:///data.sqlite\",\n ],\n };\n}\n\n/**\n * Format explain output for different views\n */\nexport function formatExplainOutput(result: ExplainResult, view: ViewType): string {\n switch (view) {\n case \"json\":\n return JSON.stringify(result, null, 2);\n case \"llm\":\n return formatLlm(result);\n default:\n return formatDefault(result);\n }\n}\n\nfunction formatDefault(result: ExplainResult): string {\n let output = `${result.topic}\\n${\"=\".repeat(result.topic.length)}\\n\\n${result.explanation}`;\n\n if (result.examples && result.examples.length > 0) {\n output += `\\n\\nExamples:\\n${result.examples.map((e) => ` $ ${e}`).join(\"\\n\")}`;\n }\n\n return output;\n}\n\nfunction formatLlm(result: ExplainResult): string {\n const lines = [`TOPIC ${result.topic}`, \"\", result.explanation];\n\n if (result.examples && result.examples.length > 0) {\n lines.push(\"\", \"EXAMPLES\");\n for (const example of result.examples) {\n lines.push(`CMD ${example}`);\n }\n }\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Format object explain output for different views\n */\nexport function formatPathExplainOutput(result: PathExplainResult, view: ViewType): string {\n switch (view) {\n case \"json\":\n return JSON.stringify(result, null, 2);\n case \"llm\":\n return formatPathLlm(result);\n default:\n return formatPathDefault(result);\n }\n}\n\nfunction formatPathDefault(result: PathExplainResult): string {\n const lines: string[] = [];\n\n lines.push(`PATH ${result.path}`);\n lines.push(\"\");\n lines.push(\"TYPE\");\n lines.push(result.type);\n\n if (result.description) {\n lines.push(\"\");\n lines.push(\"DESCRIPTION\");\n lines.push(result.description);\n }\n\n if (result.inputs && result.inputs.length > 0) {\n lines.push(\"\");\n lines.push(\"INPUTS\");\n for (const input of result.inputs) {\n lines.push(`- ${input}`);\n }\n }\n\n if (result.outputs && result.outputs.length > 0) {\n lines.push(\"\");\n lines.push(\"OUTPUTS\");\n for (const output of result.outputs) {\n lines.push(`- ${output}`);\n }\n }\n\n if (result.errors && result.errors.length > 0) {\n lines.push(\"\");\n lines.push(\"ERRORS\");\n for (const error of result.errors) {\n lines.push(`- ${error}`);\n }\n }\n\n if (result.sideEffects && result.sideEffects.length > 0) {\n lines.push(\"\");\n lines.push(\"SIDE EFFECTS\");\n for (const effect of result.sideEffects) {\n lines.push(`- ${effect}`);\n }\n } else {\n lines.push(\"\");\n lines.push(\"SIDE EFFECTS\");\n lines.push(\"- none\");\n }\n\n if (result.metadata && Object.keys(result.metadata).length > 0) {\n lines.push(\"\");\n lines.push(\"METADATA\");\n for (const [key, value] of Object.entries(result.metadata)) {\n lines.push(`- ${key}: ${value}`);\n }\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction formatPathLlm(result: PathExplainResult): string {\n const lines: string[] = [];\n\n lines.push(`PATH ${result.path}`);\n lines.push(`TYPE ${result.type.toUpperCase()}`);\n\n if (result.description) {\n lines.push(`DESC ${result.description}`);\n }\n\n if (result.inputs && result.inputs.length > 0) {\n lines.push(`INPUTS ${result.inputs.join(\", \")}`);\n }\n\n if (result.outputs && result.outputs.length > 0) {\n lines.push(`OUTPUTS ${result.outputs.join(\", \")}`);\n }\n\n if (result.errors && result.errors.length > 0) {\n lines.push(`ERRORS ${result.errors.join(\", \")}`);\n }\n\n lines.push(`SIDE_EFFECTS ${result.sideEffects?.join(\", \") || \"none\"}`);\n\n if (result.metadata) {\n for (const [key, value] of Object.entries(result.metadata)) {\n lines.push(`${key.toUpperCase()} ${value}`);\n }\n }\n\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;AAwBA,eAAsB,eAAe,KAAa,OAAwC;AACxF,SAAQ,OAAR;EACE,KAAK;EACL,KAAK,SACH,QAAO,cAAc,IAAI;EAC3B,KAAK;EACL,KAAK,QACH,QAAO,cAAc;EACvB,KAAK,MACH,QAAO,YAAY;EACrB,QACE,QAAO,iBAAiB;;;;;;AAO9B,eAAsB,mBACpB,SACA,MAC4B;CAE5B,MAAM,SADa,MAAM,QAAQ,KAAK,KAAK,EAClB;AAEzB,KAAI,CAAC,MACH,QAAO;EACL;EACA,MAAM;EACP;CAGH,MAAM,WAAW,MAAM,YAAY,EAAE;CACrC,MAAM,YAAa,SAAS,QAAmB;CAE/C,MAAM,SAA4B;EAChC,MAAM,MAAM;EACZ,MAAM;EACN,aAAa,SAAS;EACtB,UAAU,EAAE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,KAAK,QAAQ,OAAO,OAAO;AACjC,OAAM,KAAK,QAAQ,OAAO,KAAK,aAAa,GAAG;AAE/C,KAAI,OAAO,YACT,OAAM,KAAK,QAAQ,OAAO,cAAc;AAG1C,KAAI,OAAO,UAAU,OAAO,OAAO,SAAS,EAC1C,OAAM,KAAK,UAAU,OAAO,OAAO,KAAK,KAAK,GAAG;AAGlD,KAAI,OAAO,WAAW,OAAO,QAAQ,SAAS,EAC5C,OAAM,KAAK,WAAW,OAAO,QAAQ,KAAK,KAAK,GAAG;AAGpD,KAAI,OAAO,UAAU,OAAO,OAAO,SAAS,EAC1C,OAAM,KAAK,UAAU,OAAO,OAAO,KAAK,KAAK,GAAG;AAGlD,OAAM,KAAK,gBAAgB,OAAO,aAAa,KAAK,KAAK,IAAI,SAAS;AAEtE,KAAI,OAAO,SACT,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,SAAS,CACxD,OAAM,KAAK,GAAG,IAAI,aAAa,CAAC,GAAG,QAAQ;AAI/C,QAAO,MAAM,KAAK,KAAK"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_exec = require('./exec.cjs');
|
|
2
|
+
const require_mount = require('./mount.cjs');
|
|
3
|
+
const require_explain = require('./explain.cjs');
|
|
4
|
+
const require_ls = require('./ls.cjs');
|
|
5
|
+
const require_read = require('./read.cjs');
|
|
6
|
+
const require_stat = require('./stat.cjs');
|
|
7
|
+
const require_write = require('./write.cjs');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { execCommand, formatExecOutput } from "./exec.mjs";
|
|
2
|
+
import { formatMountListOutput, mountAddCommand, mountListCommand, mountRemoveCommand, mountValidateCommand } from "./mount.mjs";
|
|
3
|
+
import { explainCommand, explainPathCommand, formatExplainOutput, formatPathExplainOutput } from "./explain.mjs";
|
|
4
|
+
import { formatLsOutput, lsCommand } from "./ls.mjs";
|
|
5
|
+
import { formatReadOutput, readCommand } from "./read.mjs";
|
|
6
|
+
import { formatStatOutput, statCommand } from "./stat.mjs";
|
|
7
|
+
import { formatWriteOutput, writeCommand } from "./write.mjs";
|
|
8
|
+
|
|
9
|
+
export { };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/commands/ls.ts
|
|
3
|
+
/**
|
|
4
|
+
* List directory contents
|
|
5
|
+
*/
|
|
6
|
+
async function lsCommand(runtime, path, options = {}) {
|
|
7
|
+
const result = await runtime.list(path, {
|
|
8
|
+
maxDepth: options.maxDepth ?? 1,
|
|
9
|
+
limit: options.limit,
|
|
10
|
+
maxChildren: options.maxChildren,
|
|
11
|
+
pattern: options.pattern
|
|
12
|
+
});
|
|
13
|
+
const entries = result.data.map((entry) => ({
|
|
14
|
+
path: entry.path,
|
|
15
|
+
type: mapEntryType(entry.metadata?.type),
|
|
16
|
+
size: entry.metadata?.size,
|
|
17
|
+
modified: entry.updatedAt?.toISOString(),
|
|
18
|
+
childrenCount: entry.metadata?.childrenCount,
|
|
19
|
+
childrenTruncated: entry.metadata?.childrenTruncated
|
|
20
|
+
}));
|
|
21
|
+
const truncated = entries.some((e) => e.childrenTruncated) || options.limit !== void 0 && entries.length >= options.limit || result.message?.toLowerCase().includes("truncat");
|
|
22
|
+
return {
|
|
23
|
+
entries,
|
|
24
|
+
total: entries.length,
|
|
25
|
+
truncated,
|
|
26
|
+
message: result.message
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function mapEntryType(type) {
|
|
30
|
+
if (type === "file") return "file";
|
|
31
|
+
return "directory";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Format ls output for different views
|
|
35
|
+
*/
|
|
36
|
+
function formatLsOutput(result, view) {
|
|
37
|
+
switch (view) {
|
|
38
|
+
case "json": return formatJson(result);
|
|
39
|
+
case "llm": return formatLlm(result);
|
|
40
|
+
case "human": return formatHuman(result);
|
|
41
|
+
default: return formatDefault(result);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Default format: Machine truth, one path per line
|
|
46
|
+
*/
|
|
47
|
+
function formatDefault(result) {
|
|
48
|
+
const lines = result.entries.map((entry) => entry.path);
|
|
49
|
+
if (result.truncated) lines.push(`# Results truncated (${result.total} shown)`);
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* JSON format: Structured output
|
|
54
|
+
*/
|
|
55
|
+
function formatJson(result) {
|
|
56
|
+
return JSON.stringify({
|
|
57
|
+
entries: result.entries,
|
|
58
|
+
total: result.total,
|
|
59
|
+
truncated: result.truncated,
|
|
60
|
+
message: result.message
|
|
61
|
+
}, null, 2);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* LLM format: Token-efficient, semantic facts
|
|
65
|
+
*/
|
|
66
|
+
function formatLlm(result) {
|
|
67
|
+
const lines = [];
|
|
68
|
+
for (const entry of result.entries) {
|
|
69
|
+
const parts = [`ENTRY ${entry.path}`];
|
|
70
|
+
parts.push(`TYPE=${entry.type}`);
|
|
71
|
+
if (entry.size !== void 0) parts.push(`SIZE=${entry.size}`);
|
|
72
|
+
if (entry.childrenCount !== void 0) parts.push(`CHILDREN=${entry.childrenCount}`);
|
|
73
|
+
if (entry.childrenTruncated) parts.push("TRUNCATED");
|
|
74
|
+
lines.push(parts.join(" "));
|
|
75
|
+
}
|
|
76
|
+
lines.push(`TOTAL ${result.total}`);
|
|
77
|
+
if (result.truncated) lines.push("TRUNCATED true");
|
|
78
|
+
return lines.join("\n");
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Human format: Tree structure
|
|
82
|
+
*/
|
|
83
|
+
function formatHuman(result) {
|
|
84
|
+
const root = {
|
|
85
|
+
name: "",
|
|
86
|
+
children: /* @__PURE__ */ new Map()
|
|
87
|
+
};
|
|
88
|
+
for (const entry of result.entries) {
|
|
89
|
+
const parts = entry.path.split("/").filter(Boolean);
|
|
90
|
+
let current = root;
|
|
91
|
+
for (let i = 0; i < parts.length; i++) {
|
|
92
|
+
const part = parts[i];
|
|
93
|
+
if (!current.children.has(part)) current.children.set(part, {
|
|
94
|
+
name: part,
|
|
95
|
+
children: /* @__PURE__ */ new Map()
|
|
96
|
+
});
|
|
97
|
+
current = current.children.get(part);
|
|
98
|
+
if (i === parts.length - 1) current.entry = entry;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const lines = [];
|
|
102
|
+
renderTree(root, "", lines);
|
|
103
|
+
if (result.truncated) {
|
|
104
|
+
lines.push("");
|
|
105
|
+
lines.push(`(Results truncated - ${result.total} entries shown)`);
|
|
106
|
+
}
|
|
107
|
+
return lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
function renderTree(node, prefix, lines) {
|
|
110
|
+
const children = Array.from(node.children.values());
|
|
111
|
+
for (let i = 0; i < children.length; i++) {
|
|
112
|
+
const child = children[i];
|
|
113
|
+
const isLast = i === children.length - 1;
|
|
114
|
+
const connector = isLast ? "└── " : "├── ";
|
|
115
|
+
const icon = child.entry ? getTypeIcon(child.entry.type) : "📂";
|
|
116
|
+
const sizeStr = child.entry?.size !== void 0 ? ` ${formatSize(child.entry.size)}` : "";
|
|
117
|
+
lines.push(`${prefix}${connector}${icon} ${child.name}${sizeStr}`);
|
|
118
|
+
renderTree(child, prefix + (isLast ? " " : "│ "), lines);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function getTypeIcon(type) {
|
|
122
|
+
switch (type) {
|
|
123
|
+
case "directory": return "📂";
|
|
124
|
+
case "file": return "📄";
|
|
125
|
+
default: return "📄";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function formatSize(bytes) {
|
|
129
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
130
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
131
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
exports.formatLsOutput = formatLsOutput;
|
|
136
|
+
exports.lsCommand = lsCommand;
|