@neta-art/cohub-cli 6.1.6 → 6.2.0

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 CHANGED
@@ -278,6 +278,11 @@ cohub -s <spaceId> spaces files mv <from> <to>
278
278
  cohub -s <spaceId> spaces files rm <path>
279
279
  ```
280
280
 
281
+ `upload` places each file under `--dir`; a directory argument contributes its
282
+ contents directly (like `aws s3 cp dir remote:path`), so `upload dist --dir apps/demo`
283
+ lands at `apps/demo/index.html`, not `apps/demo/dist/index.html`. Upload adds or
284
+ overwrites files; it never deletes existing ones.
285
+
281
286
  Confirm before deleting files or directories.
282
287
 
283
288
  ## Works
@@ -9,9 +9,20 @@ export type SpaceCreateOptions = {
9
9
  spec?: string;
10
10
  json?: boolean;
11
11
  };
12
+ type UploadFile = {
13
+ id: string;
14
+ localPath: string;
15
+ relativePath: string;
16
+ name: string;
17
+ size: number;
18
+ mimeType: string | null;
19
+ };
12
20
  export declare function buildSpaceCreateInput(opts: SpaceCreateOptions): CreateSpaceInput;
21
+ export declare const planUploadInput: (input: string) => Promise<UploadFile[]>;
22
+ export declare function collectUploadFiles(paths: string[]): Promise<UploadFile[]>;
13
23
  export declare function registerPrompt(program: Command): void;
14
24
  export declare function registerSpaceCreate(spacesCmd: Command, dependencies?: {
15
25
  createClient?: () => CohubHttpClient;
16
26
  }): Command;
17
27
  export declare function registerSpaces(program: Command): void;
28
+ export {};
@@ -107,14 +107,13 @@ const formatAutoDestroy = (policy) => {
107
107
  return `${policy.ttlSeconds}s`;
108
108
  };
109
109
  const slashPath = (value) => value.split(sep).join("/");
110
- const walkUploadPath = async (input, root, prefix = "") => {
111
- const localPath = resolve(input);
110
+ const walkUploadPath = async (localPath, root) => {
112
111
  const info = await stat(localPath);
113
112
  const name = basename(localPath);
114
- const relativePath = slashPath(prefix ? `${prefix}/${name}` : relative(root, localPath) || name);
113
+ const relativePath = slashPath(relative(root, localPath) || name);
115
114
  if (info.isDirectory()) {
116
115
  const children = await readdir(localPath);
117
- const nested = await Promise.all(children.map((child) => walkUploadPath(resolve(localPath, child), root, relativePath)));
116
+ const nested = await Promise.all(children.map((child) => walkUploadPath(resolve(localPath, child), root)));
118
117
  return nested.flat();
119
118
  }
120
119
  if (!info.isFile())
@@ -129,17 +128,31 @@ const walkUploadPath = async (input, root, prefix = "") => {
129
128
  }];
130
129
  };
131
130
  const randomUploadEntryId = () => randomUUID();
132
- async function collectUploadFiles(paths) {
131
+ // Upload semantics: a file keeps its name, and a directory contributes its
132
+ // contents directly under the target dir — like `aws s3 cp dir remote:path`
133
+ // or `rclone copy`.
134
+ export const planUploadInput = async (input) => {
135
+ const localPath = resolve(input);
136
+ const info = await stat(localPath);
137
+ if (!info.isDirectory())
138
+ return walkUploadPath(localPath, dirname(localPath));
139
+ const children = await readdir(localPath);
140
+ const nested = await Promise.all(children.map((child) => walkUploadPath(resolve(localPath, child), localPath)));
141
+ return nested.flat();
142
+ };
143
+ export async function collectUploadFiles(paths) {
133
144
  if (paths.length === 0)
134
145
  return error("No files provided", "Pass one or more local files or directories.");
135
- const roots = paths.map((path) => {
136
- const resolved = resolve(path);
137
- return dirname(resolved);
138
- });
139
- const nested = await Promise.all(paths.map((path, index) => walkUploadPath(path, roots[index] ?? process.cwd())));
140
- const files = nested.flat();
146
+ const files = (await Promise.all(paths.map(planUploadInput))).flat();
141
147
  if (files.length === 0)
142
148
  return error("No regular files found");
149
+ const seen = new Map();
150
+ for (const file of files) {
151
+ const source = seen.get(file.relativePath);
152
+ if (source)
153
+ throw new Error(`Duplicate upload path "${file.relativePath}" from ${source} and ${file.localPath}`);
154
+ seen.set(file.relativePath, file.localPath);
155
+ }
143
156
  return files;
144
157
  }
145
158
  async function putUploadEntry(entry, uploadUrl, headers) {
@@ -1176,7 +1189,7 @@ function registerFiles(spacesCmd) {
1176
1189
  });
1177
1190
  filesCmd
1178
1191
  .command("upload <paths...>")
1179
- .description("Upload local files or directories")
1192
+ .description("Upload local files; directory contents land under the target dir")
1180
1193
  .option("--dir <path>", "Target directory in the space")
1181
1194
  .option("--json", "Output as JSON")
1182
1195
  .action((paths, opts) => uploadFiles(spacesCmd, paths, opts));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neta-art/cohub-cli",
3
- "version": "6.1.6",
3
+ "version": "6.2.0",
4
4
  "description": "CLI for Cohub — spaces, sessions, and agent collaboration.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",