@seedvault/cli 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/sv.js +36 -38
  2. package/package.json +6 -1
package/dist/sv.js CHANGED
@@ -200,22 +200,48 @@ function createClient(serverUrl, token) {
200
200
  return res.json();
201
201
  },
202
202
  async putFile(username, path, content) {
203
- const res = await request("PUT", `/v1/contributors/${username}/files/${encodePath(path)}`, {
203
+ const res = await request("PUT", `/v1/files/${username}/${encodePath(path)}`, {
204
204
  body: content,
205
205
  contentType: "text/markdown"
206
206
  });
207
207
  return res.json();
208
208
  },
209
209
  async deleteFile(username, path) {
210
- await request("DELETE", `/v1/contributors/${username}/files/${encodePath(path)}`);
210
+ await request("DELETE", `/v1/files/${username}/${encodePath(path)}`);
211
211
  },
212
212
  async listFiles(username, prefix) {
213
- const qs = prefix ? `?prefix=${encodeURIComponent(prefix)}` : "";
214
- const res = await request("GET", `/v1/contributors/${username}/files${qs}`);
215
- return res.json();
213
+ const fullPrefix = prefix ? `${username}/${prefix}` : `${username}/`;
214
+ const qs = `?prefix=${encodeURIComponent(fullPrefix)}`;
215
+ const res = await request("GET", `/v1/files${qs}`);
216
+ const data = await res.json();
217
+ return {
218
+ files: data.files.map((f) => ({
219
+ ...f,
220
+ path: f.path.startsWith(`${username}/`) ? f.path.slice(username.length + 1) : f.path
221
+ }))
222
+ };
216
223
  },
217
224
  async getFile(username, path) {
218
- const res = await request("GET", `/v1/contributors/${username}/files/${encodePath(path)}`);
225
+ const fullPath = `${username}/${path}`;
226
+ const res = await request("POST", "/v1/sh", {
227
+ body: JSON.stringify({ cmd: `cat "${fullPath}"` }),
228
+ contentType: "application/json"
229
+ });
230
+ const exitCode = parseInt(res.headers.get("X-Exit-Code") || "0", 10);
231
+ if (exitCode !== 0) {
232
+ const stderr = decodeURIComponent(res.headers.get("X-Stderr") || "");
233
+ if (stderr.includes("No such file or directory")) {
234
+ throw new ApiError(404, "File not found");
235
+ }
236
+ throw new ApiError(500, stderr || `cat exited with code ${exitCode}`);
237
+ }
238
+ return res.text();
239
+ },
240
+ async sh(cmd) {
241
+ const res = await request("POST", "/v1/sh", {
242
+ body: JSON.stringify({ cmd }),
243
+ contentType: "application/json"
244
+ });
219
245
  return res.text();
220
246
  },
221
247
  async health() {
@@ -2908,27 +2934,8 @@ async function status() {
2908
2934
  async function ls(args) {
2909
2935
  const config = loadConfig();
2910
2936
  const client = createClient(config.server, config.token);
2911
- const prefix = args[0] || undefined;
2912
- const { files } = await client.listFiles(config.username, prefix);
2913
- if (files.length === 0) {
2914
- console.log(prefix ? `No files matching '${prefix}'.` : "No files in your contributor.");
2915
- return;
2916
- }
2917
- const maxPath = Math.max(...files.map((f) => f.path.length));
2918
- for (const f of files) {
2919
- const size = formatSize(f.size);
2920
- const date = new Date(f.modifiedAt).toLocaleString();
2921
- console.log(` ${f.path.padEnd(maxPath + 2)} ${size.padStart(8)} ${date}`);
2922
- }
2923
- console.log(`
2924
- ${files.length} file(s)`);
2925
- }
2926
- function formatSize(bytes) {
2927
- if (bytes < 1024)
2928
- return `${bytes} B`;
2929
- if (bytes < 1024 * 1024)
2930
- return `${(bytes / 1024).toFixed(1)} KB`;
2931
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
2937
+ const output = await client.sh(`ls ${args.join(" ")}`);
2938
+ process.stdout.write(output);
2932
2939
  }
2933
2940
 
2934
2941
  // src/commands/cat.ts
@@ -2937,19 +2944,10 @@ async function cat(args) {
2937
2944
  console.error("Usage: sv cat <path>");
2938
2945
  process.exit(1);
2939
2946
  }
2940
- const filePath = args[0];
2941
2947
  const config = loadConfig();
2942
2948
  const client = createClient(config.server, config.token);
2943
- try {
2944
- const content = await client.getFile(config.username, filePath);
2945
- process.stdout.write(content);
2946
- } catch (e) {
2947
- if (e instanceof ApiError && e.status === 404) {
2948
- console.error(`File not found: ${filePath}`);
2949
- process.exit(1);
2950
- }
2951
- throw e;
2952
- }
2949
+ const output = await client.sh(`cat ${args.join(" ")}`);
2950
+ process.stdout.write(output);
2953
2951
  }
2954
2952
 
2955
2953
  // src/commands/contributors.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seedvault/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "sv": "bin/sv.mjs"
@@ -15,6 +15,11 @@
15
15
  "dist",
16
16
  "bin"
17
17
  ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/collaborator-ai/seedvault.git",
21
+ "directory": "cli"
22
+ },
18
23
  "dependencies": {
19
24
  "chokidar": "^4"
20
25
  },