@dreamlake/dreamlake-cli 0.119.2 → 0.121.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>;
@@ -2636,3 +2656,5 @@ export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
2636
2656
  export type { HostMovePreview, HostMoveRequest, HostMoveReceipt, HostMoveRetainedSessions, HostMoveRetainedRuns } from "./host-moves.js";
2637
2657
  export * from "./project-access.js";
2638
2658
  export * from "./project-audience.js";
2659
+ export { publishSourceVisualization, prepareVisualization, visualizationConfig } from './source-visualization.js';
2660
+ export type { VisualizationFile } from "./source-visualization.js";
package/dist/api/index.js CHANGED
@@ -147,3 +147,4 @@ export * from "./memo-facade.js";
147
147
  export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
148
148
  export * from "./project-access.js";
149
149
  export * from "./project-audience.js";
150
+ export { publishSourceVisualization, prepareVisualization, visualizationConfig } from './source-visualization.js';
@@ -0,0 +1,31 @@
1
+ export interface VisualizationApi {
2
+ request<T>(method: 'GET' | 'POST', path: string, options?: {
3
+ json?: unknown;
4
+ signal?: AbortSignal;
5
+ }): Promise<T>;
6
+ }
7
+ export interface VisualizationFile {
8
+ path: string;
9
+ bytes: Uint8Array;
10
+ }
11
+ export declare function prepareVisualization(files: readonly VisualizationFile[], entry?: string): {
12
+ files: {
13
+ path: string;
14
+ bytes: Uint8Array<ArrayBuffer>;
15
+ }[];
16
+ prefix: string;
17
+ entry: string;
18
+ };
19
+ export declare function visualizationConfig(text: string, entry: string): string;
20
+ /** Upload a new code generation before publishing the guarded .dreamrc pointer. Never creates an Artifact. */
21
+ export declare function publishSourceVisualization(api: VisualizationApi, namespace: string, sourceId: string, files: readonly VisualizationFile[], options?: {
22
+ entry?: string;
23
+ transport?: typeof fetch;
24
+ signal?: AbortSignal;
25
+ }): Promise<{
26
+ namespace: string;
27
+ sourceId: string;
28
+ entry: string;
29
+ files: number;
30
+ url: string;
31
+ }>;
@@ -0,0 +1,87 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { parseDocument, isMap } from 'yaml';
3
+ import { SourceFileAdapter } from './file-source.js';
4
+ import { FileError, canonicalPath } from './file-workspace.js';
5
+ export function prepareVisualization(files, entry = 'index.html') {
6
+ canonicalPath(entry);
7
+ if (!/\.html?$/.test(entry) || /[%?#]/.test(entry))
8
+ throw new Error('Entry must be a relative HTML path');
9
+ if (!files.length || files.length > 1000)
10
+ throw new Error('Visualization requires 1–1000 files');
11
+ let total = 0;
12
+ const names = new Set();
13
+ // Copy supplied bytes so callers cannot mutate an upload after its digest is computed.
14
+ const snapshot = files.map(file => {
15
+ canonicalPath(file.path);
16
+ if (/[%?#]/.test(file.path) || file.path.startsWith('_dreamlake/') || names.has(file.path) || !(file.bytes instanceof Uint8Array))
17
+ throw new Error('Invalid visualization asset');
18
+ names.add(file.path);
19
+ total += file.bytes.byteLength;
20
+ if (file.bytes.byteLength > 32 * 1024 * 1024 || total > 128 * 1024 * 1024)
21
+ throw new Error('Visualization exceeds asset or bundle limit');
22
+ return { path: file.path, bytes: new Uint8Array(file.bytes) };
23
+ }).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
24
+ if (!names.has(entry))
25
+ throw new Error('Visualization entry is missing');
26
+ const digest = createHash('sha256');
27
+ for (const file of snapshot)
28
+ digest.update(JSON.stringify([file.path, createHash('sha256').update(file.bytes).digest('hex')]));
29
+ return { files: snapshot, prefix: '.dreamlake/visualization/' + digest.digest('hex'), entry };
30
+ }
31
+ export function visualizationConfig(text, entry) {
32
+ const doc = parseDocument(text);
33
+ if (doc.errors.length || (doc.contents !== null && !isMap(doc.contents)))
34
+ throw new Error('Existing .dreamrc must be a YAML mapping');
35
+ doc.set('visualize', { type: 'custom', entry });
36
+ return doc.toString();
37
+ }
38
+ /** Upload a new code generation before publishing the guarded .dreamrc pointer. Never creates an Artifact. */
39
+ export async function publishSourceVisualization(api, namespace, sourceId, files, options = {}) {
40
+ const bundle = prepareVisualization(files, options.entry);
41
+ const signal = options.signal ?? AbortSignal.timeout(120000), transport = options.transport ?? fetch;
42
+ const adapter = new SourceFileAdapter(api, namespace, sourceId, signal, transport);
43
+ const detail = await api.request('GET', adapter.base, { signal });
44
+ if (typeof detail.name !== 'string' || !detail.name)
45
+ throw new Error('Source detail has no name');
46
+ let text = '', revision = null;
47
+ try {
48
+ const baseline = await adapter.read('.dreamrc');
49
+ text = baseline.content;
50
+ revision = baseline.revision;
51
+ }
52
+ catch (e) {
53
+ if (!(e instanceof FileError) || e.code !== 'file_not_found')
54
+ throw e;
55
+ // Do not silently replace external configuration. The caller can materialize it in the managed layer first.
56
+ const page = await api.request('GET', adapter.base + '/landing', { signal });
57
+ if (page.dreamrc.state !== 'absent')
58
+ throw new Error('An external .dreamrc exists or is unavailable. Copy its resolved contents to the managed .dreamrc before publishing.');
59
+ }
60
+ const entry = bundle.prefix + '/' + bundle.entry;
61
+ const content = visualizationConfig(text, entry);
62
+ // Detect unsupported servers before uploading any files.
63
+ await api.request('POST', adapter.base + '/visualization-session', { json: { entry }, signal });
64
+ const plan = await api.request('POST', adapter.base + '/upload-authorizations', { json: {
65
+ targetPrefix: bundle.prefix, files: bundle.files.map(f => ({ relativePath: f.path, size: f.bytes.length })),
66
+ }, signal });
67
+ if (plan.mode !== 's3-presigned-batch' || plan.files?.length !== bundle.files.length)
68
+ throw new Error('Invalid upload plan');
69
+ // Validate every authorization before sending the first byte.
70
+ for (let i = 0; i < bundle.files.length; i++) {
71
+ const f = bundle.files[i], granted = plan.files[i];
72
+ if (granted.relativePath !== f.path || granted.canonicalPath !== bundle.prefix + '/' + f.path || granted.size !== f.bytes.length || granted.transfer?.kind !== 'single-put')
73
+ throw new Error('Invalid asset authorization');
74
+ const url = new URL(granted.transfer.put.url);
75
+ if (url.protocol !== 'https:' || url.username || url.password || Object.keys(granted.transfer.put.headers ?? {}).some(k => /^(authorization|cookie)$/i.test(k)))
76
+ throw new Error('Unsafe upload capability');
77
+ }
78
+ for (let i = 0; i < bundle.files.length; i++) {
79
+ const put = plan.files[i].transfer.put;
80
+ const response = await transport(put.url, { method: 'PUT', headers: put.headers, body: new Uint8Array(bundle.files[i].bytes), redirect: 'error', signal });
81
+ await response.body?.cancel();
82
+ if (!response.ok)
83
+ throw new Error('Visualization upload failed; .dreamrc was not changed');
84
+ }
85
+ await adapter.write('.dreamrc', content, revision);
86
+ return { namespace, sourceId, entry, files: bundle.files.length, url: `https://dreamlake.ai/${encodeURIComponent(namespace)}/sources/${encodeURIComponent(detail.name)}?view=visualize` };
87
+ }
@@ -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",
@@ -271,6 +273,7 @@ export const helpExamples = {
271
273
  "source files read": "dl source files read --source my-workspace --prefix workspaces/v1/demo --path scene/manifest.json --json",
272
274
  "source files list": "dl source files list --source my-workspace --prefix workspaces/v1/demo --path '' --json",
273
275
  "source files replace": "dl source files replace --source my-workspace --prefix workspaces/v1/demo --path scene/manifest.json --old-file ./old.txt --new-file ./new.txt --revision '\"etag-from-read\"' --json",
276
+ "source visualization push": "dl source visualization push ./dist --source my-data --namespace my-team",
274
277
  "vault cloud import": "# No --file: list standard candidate paths without opening their contents.\ndl vault cloud import --provider aws -p alice/aws/dev\n# Explicit selections: preview names, sizes and profile metadata, without upload.\ndl vault cloud import --provider aws -p alice/aws/dev \\\n --file \"$HOME/.aws/config\" --file \"$HOME/.aws/credentials\"\n# Repeat the selection with --apply to upload.\ndl vault cloud import --provider aws -p alice/aws/dev \\\n --file \"$HOME/.aws/config\" --file \"$HOME/.aws/credentials\" --apply\ndl vault cloud import --provider gcp -p alice/gcp/dev \\\n --file /private/config/service-account.json --apply",
275
278
  "vault cloud restore": "# Preview checks metadata and destination without retrieving the secret.\ndl vault cloud restore -n alice/aws/dev/credentials \\\n --to '~/.aws/credentials'\n# Write only after explicit --apply; existing files additionally need --overwrite.\ndl vault cloud restore -n alice/aws/dev/credentials \\\n --to '~/.aws/credentials' --apply",
276
279
  "vault add": "# Keep a 90-day registry token for exactly as long as the registry honors it.\npbpaste | dl vault add -p alice -n cli/npm/access-token --stdin --expires-in 90d --env NPM_TOKEN\n# An exact UTC timestamp works the same way.\npbpaste | dl vault add -p alice -n cli/npm/access-token --stdin --expires-at 2027-01-24T00:00:00Z\n# Replace a value and clear its expiry, pinning the current revision.\npbpaste | dl vault add -p alice -n cli/npm/access-token --stdin --if-match 2 --no-expiry",
@@ -1,3 +1,4 @@
1
+ import { registerSourceVisualization } from './visualization.js';
1
2
  import { registerSourceFiles } from "./files.js";
2
3
  import { collectionList } from "../collection-list.js";
3
4
  // `dl source ...` — read data out of connected sources (S3 and Hugging
@@ -1338,6 +1339,7 @@ export function registerSourceCommand(program) {
1338
1339
  .option("-o, --output <dir>", "output directory (default: current directory)")
1339
1340
  .option("-r, --recursive", "download every file under <path>")
1340
1341
  .action(async (pathArg, opts) => process.exit(await runSourceDownload(pathArg, opts)));
1342
+ registerSourceVisualization(source);
1341
1343
  registerSourceFiles(source);
1342
1344
  registerSourceWriteCommands(source);
1343
1345
  registerSourceUploadCommand(source);
@@ -0,0 +1,9 @@
1
+ /** Local filesystem preparation belongs to the CLI, not the transport-only SDK. */
2
+ export declare function collectVisualization(directory: string, entry?: string): Promise<{
3
+ files: {
4
+ path: string;
5
+ bytes: Uint8Array<ArrayBuffer>;
6
+ }[];
7
+ prefix: string;
8
+ entry: string;
9
+ }>;
@@ -0,0 +1,31 @@
1
+ import { lstat, readdir, readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { prepareVisualization } from '../../api/source-visualization.js';
4
+ /** Local filesystem preparation belongs to the CLI, not the transport-only SDK. */
5
+ export async function collectVisualization(directory, entry = 'index.html') {
6
+ const files = [];
7
+ let total = 0;
8
+ async function walk(relative) {
9
+ const full = join(directory, relative), info = await lstat(full);
10
+ if (info.isSymbolicLink())
11
+ throw new Error('Visualization symlinks are not supported');
12
+ if (info.isDirectory()) {
13
+ for (const name of (await readdir(full)).sort())
14
+ await walk(relative ? relative + '/' + name : name);
15
+ return;
16
+ }
17
+ if (!info.isFile())
18
+ throw new Error('Visualization must contain regular files');
19
+ if (info.size > 32 * 1024 * 1024 || files.length >= 1000 || info.size + total > 128 * 1024 * 1024)
20
+ throw new Error('Visualization exceeds asset, bundle, or file count limit');
21
+ const bytes = await readFile(full);
22
+ total += bytes.length;
23
+ if (bytes.length > 32 * 1024 * 1024 || total > 128 * 1024 * 1024)
24
+ throw new Error('Visualization changed while reading');
25
+ files.push({ path: relative, bytes });
26
+ }
27
+ if (!(await lstat(directory)).isDirectory())
28
+ throw new Error('Supply a static build directory');
29
+ await walk('');
30
+ return prepareVisualization(files, entry);
31
+ }
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerSourceVisualization(source: Command): void;
@@ -0,0 +1,31 @@
1
+ import { collectVisualization } from './visualization-files.js';
2
+ import { publishSourceVisualization } from '../../api/source-visualization.js';
3
+ import { requestJson } from '../client.js';
4
+ import { emitJson, fail } from '../helpers.js';
5
+ import { ctx, resolveSource } from './index.js';
6
+ export function registerSourceVisualization(source) {
7
+ source.command('visualization').description('publish Source-owned custom visualization code').command('push')
8
+ .argument('<directory>', 'static build directory; build with relative asset URLs')
9
+ .requiredOption('--source <name>', 'Source name').option('--namespace <slug>', 'namespace')
10
+ .option('--entry <path>', 'HTML entry relative to the build directory', 'index.html').option('--json', 'emit JSON')
11
+ .action(async (directory, options) => {
12
+ try {
13
+ const c = await ctx(options.namespace);
14
+ if (!c) {
15
+ process.exitCode = 1;
16
+ return;
17
+ }
18
+ const source = await resolveSource(c, options.source);
19
+ const bundle = await collectVisualization(directory, options.entry);
20
+ const result = await publishSourceVisualization({ request: (method, path, opts = {}) => requestJson(c.remote, path, { ...opts, method, token: c.token }) }, c.ns, source.id, bundle.files, { entry: options.entry });
21
+ if (options.json)
22
+ emitJson(result);
23
+ else
24
+ process.stdout.write(`Published ${result.files} files\n${result.url}\n`);
25
+ }
26
+ catch (e) {
27
+ process.exitCode = 1;
28
+ fail(e instanceof Error ? e.message : 'Visualization publication failed');
29
+ }
30
+ });
31
+ }
@@ -1 +1 @@
1
- export declare const VERSION = "0.119.2";
1
+ export declare const VERSION = "0.121.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.2";
9
+ export const VERSION = "0.121.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.119.2",
3
+ "version": "0.121.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.2",
41
- "@dreamlake/dreamlake-cli-darwin-x64": "0.119.2",
42
- "@dreamlake/dreamlake-cli-linux-x64": "0.119.2",
43
- "@dreamlake/dreamlake-cli-linux-arm64": "0.119.2",
44
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.119.2",
45
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.119.2",
46
- "@dreamlake/dreamlake-cli-win32-x64": "0.119.2",
47
- "@dreamlake/dreamlake-cli-win32-arm64": "0.119.2"
40
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.121.0",
41
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.121.0",
42
+ "@dreamlake/dreamlake-cli-linux-x64": "0.121.0",
43
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.121.0",
44
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.121.0",
45
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.121.0",
46
+ "@dreamlake/dreamlake-cli-win32-x64": "0.121.0",
47
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.121.0"
48
48
  }
49
49
  }