@dreamlake/dreamlake-cli 0.119.1 → 0.120.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.
@@ -864,6 +864,16 @@ export declare function createApi(transport: Transport, storageFetch?: typeof fe
864
864
  delete: (id: string) => Promise<unknown>;
865
865
  };
866
866
  nodes: {
867
+ move: (nodes: {
868
+ id: string;
869
+ expectedPath: string;
870
+ }[], parentId: string) => Promise<{
871
+ nodes: {
872
+ id: string;
873
+ path: string;
874
+ name: string;
875
+ }[];
876
+ }>;
867
877
  list: (query?: import("./workspace.js").NodeTreeQuery) => Promise<unknown>;
868
878
  children: (query: import("./workspace.js").NodeTreeQuery) => Promise<import("./workspace.js").NodeChildrenPage>;
869
879
  descendants: (id: string, query?: import("./workspace.js").NodeTreeQuery) => Promise<unknown>;
@@ -2191,6 +2201,16 @@ export declare function createClient(options: ClientOptions): {
2191
2201
  delete: (id: string) => Promise<unknown>;
2192
2202
  };
2193
2203
  nodes: {
2204
+ move: (nodes: {
2205
+ id: string;
2206
+ expectedPath: string;
2207
+ }[], parentId: string) => Promise<{
2208
+ nodes: {
2209
+ id: string;
2210
+ path: string;
2211
+ name: string;
2212
+ }[];
2213
+ }>;
2194
2214
  list: (query?: import("./workspace.js").NodeTreeQuery) => Promise<unknown>;
2195
2215
  children: (query: import("./workspace.js").NodeTreeQuery) => Promise<import("./workspace.js").NodeChildrenPage>;
2196
2216
  descendants: (id: string, query?: import("./workspace.js").NodeTreeQuery) => Promise<unknown>;
@@ -170,6 +170,16 @@ export interface NodeChildrenPage {
170
170
  searchMode?: string;
171
171
  }
172
172
  export declare function nodesApi(t: Transport): {
173
+ move: (nodes: {
174
+ id: string;
175
+ expectedPath: string;
176
+ }[], parentId: string) => Promise<{
177
+ nodes: {
178
+ id: string;
179
+ path: string;
180
+ name: string;
181
+ }[];
182
+ }>;
173
183
  list: (query?: NodeTreeQuery) => Promise<unknown>;
174
184
  children: (query: NodeTreeQuery) => Promise<NodeChildrenPage>;
175
185
  descendants: (id: string, query?: NodeTreeQuery) => Promise<unknown>;
@@ -66,6 +66,7 @@ export function projectsApi(t, namespace) {
66
66
  }
67
67
  export function nodesApi(t) {
68
68
  return {
69
+ move: (nodes, parentId) => call(t, "POST", "/nodes/move", { nodes, parentId }),
69
70
  list: (query = {}) => call(t, "GET", "/nodes", undefined, query),
70
71
  children: (query) => call(t, "GET", "/nodes/children", undefined, query),
71
72
  descendants: (id, query = {}) => call(t, "GET", `/nodes/${seg(id)}/descendants`, undefined, { ...query, includeArchived: query.includeArchived ?? false }),
@@ -12,4 +12,10 @@ type Options = ConnOpts & {
12
12
  export declare function runFoldersList(opts: Options): Promise<number>;
13
13
  export declare function runFoldersArchive(id: string, archived: boolean, opts: Options): Promise<number>;
14
14
  export declare function registerFoldersCommand(program: Command): void;
15
+ /** File and folder moves share an atomic endpoint; no recursive client copies. */
16
+ export declare function runNodesMove(ids: string[], opts: ConnOpts & {
17
+ to: string;
18
+ json?: boolean;
19
+ }): Promise<number>;
20
+ export declare function registerNodeMoveCommand(command: Command): void;
15
21
  export {};
@@ -61,6 +61,8 @@ export async function runFoldersArchive(id, archived, opts) {
61
61
  }
62
62
  export function registerFoldersCommand(program) {
63
63
  const folders = program.command('folders').description('browse folder contents and manage folder archival');
64
+ registerNodeMoveCommand(folders);
65
+ registerNodeMoveCommand(program.command('files').description('move project files without copying stored bytes'));
64
66
  withConnFlags(folders.command('list').allowExcessArguments(false))
65
67
  .description('list immediate contents of a folder or project root')
66
68
  .option('--parent-id <id>', 'folder node id')
@@ -79,3 +81,39 @@ export function registerFoldersCommand(program) {
79
81
  .action(async (id, opts) => { process.exitCode = await runFoldersArchive(id, action === 'archive', opts); });
80
82
  }
81
83
  }
84
+ /** File and folder moves share an atomic endpoint; no recursive client copies. */
85
+ export async function runNodesMove(ids, opts) {
86
+ const c = resolveCtx(opts), token = requireToken(c);
87
+ if (!token)
88
+ return 1;
89
+ if (!ids.length || ids.length > 200 || new Set(ids).size !== ids.length ||
90
+ [...ids, opts.to].some(id => !/^[a-f0-9]{24}$/i.test(id))) {
91
+ fail('Supply 1–200 unique node IDs and a destination folder/project node ID');
92
+ return 1;
93
+ }
94
+ try {
95
+ const transport = memoTransport({ remote: c.remote, token });
96
+ const nodes = [];
97
+ for (const id of ids) {
98
+ const node = await transport.request('GET', `/nodes/${id}`);
99
+ nodes.push({ id, expectedPath: node.path });
100
+ }
101
+ const result = await nodesApi(transport).move(nodes, opts.to);
102
+ if (opts.json)
103
+ emitJson(result);
104
+ else
105
+ process.stdout.write(`Moved ${result.nodes.length} item(s) to ${opts.to}\n`);
106
+ return 0;
107
+ }
108
+ catch (error) {
109
+ return report(error);
110
+ }
111
+ }
112
+ export function registerNodeMoveCommand(command) {
113
+ withConnFlags(command.command('move').allowExcessArguments(false))
114
+ .description('atomically move files/folders within their project and Episode; never overwrite')
115
+ .argument('<ids...>', 'file or folder node IDs (at most 200)')
116
+ .requiredOption('--to <id>', 'destination folder, Episode or project node ID')
117
+ .option('--json', 'emit the confirmed node locations')
118
+ .action(async (ids, opts) => { process.exitCode = await runNodesMove(ids, opts); });
119
+ }
@@ -120,6 +120,8 @@ export const helpExamples = {
120
120
  "layout apply": "dl layout apply request.json --cdp http://127.0.0.1:9222 --page PAGE_ID --layout LAYOUT_ID",
121
121
  "machine": "dl machine self\ndl machine host 0123456789abcdef01234567\ndl machine project 0123456789abcdef01234567",
122
122
  "auth identity": "dl auth identity\ndl --identity machine profile\ndl --identity user profile",
123
+ "files move": "dl files move FILE_NODE_ID --to DESTINATION_FOLDER_ID",
124
+ "folders move": "dl folders move FOLDER_NODE_ID --to DESTINATION_FOLDER_ID\ndl folders move FIRST_NODE_ID SECOND_NODE_ID --to PROJECT_NODE_ID --json",
123
125
  "memos archive": "dl memos archive MEMO_ID --json\n# With a slug or exact title, select its owning namespace.\ndl memos archive release-plan --namespace acme",
124
126
  "memos unarchive": "dl memos unarchive MEMO_ID --json\n# Archived titles and slugs remain resolvable.\ndl memos unarchive release-plan --namespace acme",
125
127
  "folders list": "# List immediate contents at a project root or inside a folder.\ndl folders list --project project-slug --namespace acme --include-archived --json\ndl folders list --parent-id FOLDER_ID --include-archived --page 1 --page-size 50",
@@ -6,6 +6,15 @@ const SAFE_POWER_CODES = new Set([
6
6
  "provider_binding_revoked", "enrollment_revoked", "active_work_present", "request_id_conflict",
7
7
  "invalid_power_request", "invalid_request_id", "volume_disposition_required", "host_lifecycle_unavailable",
8
8
  ]);
9
+ // Terminal errors arrive as `error`; they name the failing stage, never a credential.
10
+ const TERMINAL_CODES = new Set([
11
+ "terminal_inventory_limit", "terminal_not_ready", "terminal_unavailable", "terminal_access_denied", "terminal_invalid_request",
12
+ "controlplane_unavailable", "controlplane_identity_conflict",
13
+ ]);
14
+ const TERMINAL_GUIDANCE = {
15
+ terminal_inventory_limit: "; the namespace has more terminal targets than one unpaged listing returns. dl exec, ssh and tmux resolve the exact host in current releases: update the CLI",
16
+ terminal_not_ready: "; the enrollment is not online with SSH available. Inspect it with dl hosts enrollments <host>",
17
+ };
9
18
  export class HostApiError extends Error {
10
19
  status;
11
20
  operationId;
@@ -45,10 +54,11 @@ export async function hostRequest(path, method = "GET", body, connection) {
45
54
  const retryAt = typeof data.retryAt === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(data.retryAt) && Number.isFinite(Date.parse(data.retryAt)) ? data.retryAt : undefined;
46
55
  // A busy control plane refused the write before running it, so the caller may resubmit after Retry-After.
47
56
  const busy = result.status === 503 && data.error === "controlplane_busy";
48
- const code = busy ? "controlplane_busy" : typeof data.code === "string" && SAFE_POWER_CODES.has(data.code) ? data.code : undefined;
57
+ const code = busy ? "controlplane_busy" : typeof data.code === "string" && SAFE_POWER_CODES.has(data.code) ? data.code
58
+ : typeof data.error === "string" && TERMINAL_CODES.has(data.error) ? data.error : undefined;
49
59
  const retryAfter = Number(result.headers.get("retry-after"));
50
60
  const busyRetryAt = busy && Number.isFinite(retryAfter) && retryAfter >= 0 ? new Date(Date.now() + retryAfter * 1000).toISOString() : undefined;
51
- throw new HostApiError(`Host API request failed (HTTP ${result.status})${code ? `: ${code}` : ""}`, result.status, operationId, retryAt ?? busyRetryAt, code);
61
+ throw new HostApiError(`Host API request failed (HTTP ${result.status})${code ? `: ${code}${TERMINAL_GUIDANCE[code] ?? ""}` : ""}`, result.status, operationId, retryAt ?? busyRetryAt, code);
52
62
  }
53
63
  try {
54
64
  return await result.json();
@@ -94,7 +94,7 @@ export async function hostStatus(selector, opts = {}, request = hostRequest) {
94
94
  export async function waitForWebTerminal(namespace, hostId, enrollmentId, deadline, request = hostRequest, sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))) {
95
95
  while (true) {
96
96
  try {
97
- const result = await request(`/namespaces/${encodeURIComponent(namespace)}/hosts/terminal-targets`);
97
+ const result = await request(`/namespaces/${encodeURIComponent(namespace)}/hosts/terminal-targets?hostId=${encodeURIComponent(hostId)}&enrollmentId=${encodeURIComponent(enrollmentId)}`);
98
98
  const target = result.targets?.find((entry) => entry.hostId === hostId && entry.enrollmentId === enrollmentId);
99
99
  if (typeof target?.id === "string")
100
100
  return { status: "ready", targetId: target.id };
@@ -88,5 +88,12 @@ export declare class SshRelay extends Duplex {
88
88
  _final(done: (error?: Error | null) => void): void;
89
89
  _destroy(error: Error | null, done: (error?: Error | null) => void): void;
90
90
  }
91
+ /**
92
+ * Ready targets of one host, or of one explicit enrollment on it. The exact lookup never lists the namespace, so the
93
+ * rest of the fleet (archived or not) cannot block a connection. An older API
94
+ * ignores the query and returns its whole catalog; the caller's hostId filter
95
+ * still narrows it.
96
+ */
97
+ export declare function hostTerminalTargets(request: SshIO['request'], base: string, hostId: string, enrollmentId?: string): Promise<SshTarget[]>;
91
98
  export declare function runHostSsh(selector: string, opts: SshOptions, argv?: string[], io?: SshIO): Promise<number>;
92
99
  export declare function registerHostSshCommands(hosts: Command, program: Command): void;
@@ -178,6 +178,28 @@ export class SshRelay extends Duplex {
178
178
  _final(done) { this.ws.send(Buffer.from([1]), { binary: true }, error => done(error ? new Error('SSH relay FIN failed') : undefined)); }
179
179
  _destroy(error, done) { this.ws.terminate(); done(error); }
180
180
  }
181
+ /**
182
+ * Ready targets of one host, or of one explicit enrollment on it. The exact lookup never lists the namespace, so the
183
+ * rest of the fleet (archived or not) cannot block a connection. An older API
184
+ * ignores the query and returns its whole catalog; the caller's hostId filter
185
+ * still narrows it.
186
+ */
187
+ export async function hostTerminalTargets(request, base, hostId, enrollmentId) {
188
+ const targets = [];
189
+ let cursor;
190
+ for (let page = 0; page < 10; page++) {
191
+ const catalog = await request(`${base}/terminal-targets?hostId=${hostId}${enrollmentId ? `&enrollmentId=${enrollmentId}` : ''}&limit=100${cursor ? `&cursor=${cursor}` : ''}`);
192
+ if (!Array.isArray(catalog?.targets))
193
+ throw new Error('Invalid SSH target catalog');
194
+ targets.push(...catalog.targets);
195
+ if (catalog.nextCursor == null)
196
+ return targets;
197
+ if (typeof catalog.nextCursor !== 'string' || !ID.test(catalog.nextCursor) || (cursor !== undefined && catalog.nextCursor <= cursor))
198
+ throw new Error('Invalid SSH target catalog');
199
+ cursor = catalog.nextCursor;
200
+ }
201
+ throw new Error('Invalid SSH target catalog');
202
+ }
181
203
  export async function runHostSsh(selector, opts, argv, io = defaultSshIO) {
182
204
  if (process.platform === 'win32')
183
205
  throw new Error('Host SSH currently requires Linux or macOS and OpenSSH');
@@ -224,10 +246,8 @@ export async function runHostSsh(selector, opts, argv, io = defaultSshIO) {
224
246
  if (/^[a-f0-9]{24}$/i.test(selector) ? detail.host.id !== selector.toLowerCase() : detail.host.name !== selector)
225
247
  throw new Error('Host API returned a different host identity');
226
248
  const base = hostApiPath(namespace);
227
- const catalog = await io.request(`${base}/terminal-targets`);
228
- if (!Array.isArray(catalog?.targets))
229
- throw new Error('Invalid SSH target catalog');
230
- const matches = catalog.targets.filter((t) => t.hostId === detail.host.id && (!opts.enrollment || t.enrollmentId === opts.enrollment));
249
+ const targets = await hostTerminalTargets(io.request, base, detail.host.id, opts.enrollment);
250
+ const matches = targets.filter((t) => t.hostId === detail.host.id && (!opts.enrollment || t.enrollmentId === opts.enrollment));
231
251
  // Validate every displayed identity before prompting, and preserve the same
232
252
  // host/enrollment binding and host-key checks after the selection.
233
253
  for (const target of matches) {
@@ -1 +1 @@
1
- export declare const VERSION = "0.119.1";
1
+ export declare const VERSION = "0.120.0";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.119.1";
9
+ export const VERSION = "0.120.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.119.1",
3
+ "version": "0.120.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -37,13 +37,13 @@
37
37
  "node": ">=18"
38
38
  },
39
39
  "optionalDependencies": {
40
- "@dreamlake/dreamlake-cli-darwin-arm64": "0.119.1",
41
- "@dreamlake/dreamlake-cli-darwin-x64": "0.119.1",
42
- "@dreamlake/dreamlake-cli-linux-x64": "0.119.1",
43
- "@dreamlake/dreamlake-cli-linux-arm64": "0.119.1",
44
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.119.1",
45
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.119.1",
46
- "@dreamlake/dreamlake-cli-win32-x64": "0.119.1",
47
- "@dreamlake/dreamlake-cli-win32-arm64": "0.119.1"
40
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.120.0",
41
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.120.0",
42
+ "@dreamlake/dreamlake-cli-linux-x64": "0.120.0",
43
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.120.0",
44
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.120.0",
45
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.120.0",
46
+ "@dreamlake/dreamlake-cli-win32-x64": "0.120.0",
47
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.120.0"
48
48
  }
49
49
  }