@dreamlake/dreamlake-cli 0.117.0 → 0.118.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.
- package/dist/api/agent.d.ts +1 -0
- package/dist/api/file-multipart.d.ts +6 -0
- package/dist/api/file-multipart.js +34 -0
- package/dist/api/file-source.d.ts +30 -0
- package/dist/api/file-source.js +165 -0
- package/dist/api/file-workspace.d.ts +79 -0
- package/dist/api/file-workspace.js +142 -0
- package/dist/api/index.d.ts +60 -1
- package/dist/api/index.js +8 -2
- package/dist/api/native-experiments.d.ts +25 -0
- package/dist/api/native-experiments.js +49 -4
- package/dist/api/sessions.d.ts +6 -0
- package/dist/cli/agents/chat.d.ts +21 -0
- package/dist/cli/agents/chat.js +126 -0
- package/dist/cli/agents/index.js +3 -1
- package/dist/cli/experiments/index.js +4 -0
- package/dist/cli/experiments/management.d.ts +16 -0
- package/dist/cli/experiments/management.js +82 -0
- package/dist/cli/experiments/transfer/adapter.d.ts +86 -0
- package/dist/cli/experiments/transfer/adapter.js +637 -0
- package/dist/cli/experiments/transfer/context.d.ts +13 -0
- package/dist/cli/experiments/transfer/context.js +20 -0
- package/dist/cli/experiments/transfer/download.d.ts +24 -0
- package/dist/cli/experiments/transfer/download.js +516 -0
- package/dist/cli/experiments/transfer/index.d.ts +2 -0
- package/dist/cli/experiments/transfer/index.js +38 -0
- package/dist/cli/experiments/transfer/local/safe-path.d.ts +29 -0
- package/dist/cli/experiments/transfer/local/safe-path.js +106 -0
- package/dist/cli/experiments/transfer/local/storage.d.ts +125 -0
- package/dist/cli/experiments/transfer/local/storage.js +432 -0
- package/dist/cli/experiments/transfer/transport.d.ts +7 -0
- package/dist/cli/experiments/transfer/transport.js +31 -0
- package/dist/cli/experiments/transfer/types.d.ts +48 -0
- package/dist/cli/experiments/transfer/types.js +1 -0
- package/dist/cli/experiments/transfer/upload.d.ts +58 -0
- package/dist/cli/experiments/transfer/upload.js +665 -0
- package/dist/cli/experiments/transfer/util/ansi.d.ts +24 -0
- package/dist/cli/experiments/transfer/util/ansi.js +70 -0
- package/dist/cli/experiments/transfer/util/glob.d.ts +4 -0
- package/dist/cli/experiments/transfer/util/glob.js +39 -0
- package/dist/cli/experiments/transfer/util/json.d.ts +6 -0
- package/dist/cli/experiments/transfer/util/json.js +58 -0
- package/dist/cli/experiments/transfer/util/pool.d.ts +5 -0
- package/dist/cli/experiments/transfer/util/pool.js +21 -0
- package/dist/cli/help-examples.generated.js +17 -0
- package/dist/cli/library/discover.d.ts +4 -2
- package/dist/cli/library/discover.js +5 -3
- package/dist/cli/sessions/control.js +2 -28
- package/dist/cli/sessions/runner/native-result.d.ts +34 -0
- package/dist/cli/sessions/runner/native-result.js +101 -0
- package/dist/cli/sessions/runner/serve.js +45 -2
- package/dist/cli/source/files.d.ts +2 -0
- package/dist/cli/source/files.js +39 -0
- package/dist/cli/source/index.js +2 -0
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { fileMultipart } from "./file-multipart.js";
|
|
2
3
|
import { namespaceSeg, seg } from "./client.js";
|
|
3
4
|
import { call } from "./common.js";
|
|
4
5
|
function trackQuery(q) {
|
|
@@ -37,6 +38,26 @@ async function sha256(data) {
|
|
|
37
38
|
* The multipart body of a file upload. Text fields precede the file part: the server reads
|
|
38
39
|
* only the fields received before the file, and verifies `sizeBytes` and `checksum` against it.
|
|
39
40
|
*/
|
|
41
|
+
export async function nativeFileMultipart(upload) {
|
|
42
|
+
const blob = upload.data instanceof Uint8Array
|
|
43
|
+
? new Blob([upload.data], { type: upload.contentType ?? "application/octet-stream" })
|
|
44
|
+
: upload.data;
|
|
45
|
+
const fields = {
|
|
46
|
+
sizeBytes: String(blob.size), checksum: upload.checksum ?? await sha256(upload.data),
|
|
47
|
+
};
|
|
48
|
+
if (upload.prefix !== undefined)
|
|
49
|
+
fields.prefix = upload.prefix;
|
|
50
|
+
if (upload.description !== undefined)
|
|
51
|
+
fields.description = upload.description;
|
|
52
|
+
if (upload.tags?.length)
|
|
53
|
+
fields.tags = upload.tags.join(",");
|
|
54
|
+
if (upload.metadata !== undefined)
|
|
55
|
+
fields.metadata = JSON.stringify(upload.metadata);
|
|
56
|
+
if (upload.folderId !== undefined)
|
|
57
|
+
fields.folderId = upload.folderId;
|
|
58
|
+
return fileMultipart(fields, blob, upload.filename, upload.contentType);
|
|
59
|
+
}
|
|
60
|
+
/** @deprecated Prefer nativeFileMultipart for filenames containing quotes. Kept for source compatibility. */
|
|
40
61
|
export async function nativeFileForm(upload) {
|
|
41
62
|
const blob = upload.data instanceof Uint8Array
|
|
42
63
|
? new Blob([upload.data], { type: upload.contentType ?? "application/octet-stream" })
|
|
@@ -54,13 +75,17 @@ export async function nativeFileForm(upload) {
|
|
|
54
75
|
form.append("metadata", JSON.stringify(upload.metadata));
|
|
55
76
|
if (upload.folderId !== undefined)
|
|
56
77
|
form.append("folderId", upload.folderId);
|
|
57
|
-
const typed = upload.contentType && blob.type !== upload.contentType ?
|
|
78
|
+
const typed = upload.contentType && blob.type !== upload.contentType ? blob.slice(0, blob.size, upload.contentType) : blob;
|
|
58
79
|
form.append("file", typed, upload.filename);
|
|
59
80
|
return form;
|
|
60
81
|
}
|
|
61
82
|
export function nativeExperimentsApi(t, namespace, project) {
|
|
62
83
|
const p = nativeExperimentPaths(namespace, project);
|
|
63
84
|
const { base, run } = p;
|
|
85
|
+
const sendFile = async (method, path, upload) => {
|
|
86
|
+
const form = await nativeFileMultipart(upload);
|
|
87
|
+
return t.request(method, path, { body: form.body, headers: { "content-type": form.contentType } });
|
|
88
|
+
};
|
|
64
89
|
return {
|
|
65
90
|
status: () => call(t, "GET", `${base}/status`),
|
|
66
91
|
session: (mode) => call(t, "POST", `${base}/session`, { mode }),
|
|
@@ -114,7 +139,7 @@ export function nativeExperimentsApi(t, namespace, project) {
|
|
|
114
139
|
files: {
|
|
115
140
|
list: (id, query = {}) => call(t, "GET", p.files(id), undefined, { prefix: query.prefix, tags: query.tags?.join(",") }),
|
|
116
141
|
get: (id, fileId) => call(t, "GET", p.file(id, fileId)),
|
|
117
|
-
upload: async (id, upload) =>
|
|
142
|
+
upload: async (id, upload) => sendFile("POST", p.files(id), upload),
|
|
118
143
|
/** The file's bytes from the central API; redirects are refused, so the bearer never leaves it. */
|
|
119
144
|
download: (id, fileId, options = {}) => {
|
|
120
145
|
if (!t.raw)
|
|
@@ -129,7 +154,7 @@ export function nativeExperimentsApi(t, namespace, project) {
|
|
|
129
154
|
/** Project and folder files (README.md, `.dashrc`): not a run's. `folderId` absent or "root": the project root. */
|
|
130
155
|
projectFiles: {
|
|
131
156
|
list: (query = {}) => call(t, "GET", `${base}/project-files`, undefined, query),
|
|
132
|
-
upload: async (upload) =>
|
|
157
|
+
upload: async (upload) => sendFile("POST", `${base}/project-files`, upload),
|
|
133
158
|
get: (fileId) => call(t, "GET", `${base}/project-files/${seg(fileId)}`),
|
|
134
159
|
/** UTF-8 text, at most 512 KiB (larger: 413, never truncated). */
|
|
135
160
|
text: (fileId) => call(t, "GET", `${base}/project-files/${seg(fileId)}/text`),
|
|
@@ -140,7 +165,7 @@ export function nativeExperimentsApi(t, namespace, project) {
|
|
|
140
165
|
},
|
|
141
166
|
media: (fileId) => call(t, "GET", `${base}/project-files/${seg(fileId)}/media`),
|
|
142
167
|
/** New bytes for the same file: its id, name and metadata stay. */
|
|
143
|
-
replace: async (fileId, upload) =>
|
|
168
|
+
replace: async (fileId, upload) => sendFile("PUT", `${base}/project-files/${seg(fileId)}/content`, upload),
|
|
144
169
|
/** description/tags/metadata, and/or `filename` and `folderId` (null: the root) to rename or move. */
|
|
145
170
|
update: (fileId, patch) => call(t, "PATCH", `${base}/project-files/${seg(fileId)}`, patch),
|
|
146
171
|
delete: (fileId) => call(t, "DELETE", `${base}/project-files/${seg(fileId)}`),
|
|
@@ -171,6 +196,26 @@ export function nativeExperimentsApi(t, namespace, project) {
|
|
|
171
196
|
...(options.signal ? { signal: options.signal, timeoutMs: null } : {}) });
|
|
172
197
|
},
|
|
173
198
|
},
|
|
199
|
+
writers: {
|
|
200
|
+
list: (query = {}) => call(t, "GET", `${base}/credentials`, undefined, query),
|
|
201
|
+
get: (id) => call(t, "GET", `${base}/credentials/${seg(id)}`),
|
|
202
|
+
create: (idempotencyKey, runId) => call(t, "POST", `${base}/credentials`, { operation: "create", idempotencyKey, ...(runId ? { runId } : {}) }),
|
|
203
|
+
rotate: (credentialId, expectedGeneration) => call(t, "POST", `${base}/credentials`, { operation: "rotate", credentialId, expectedGeneration }),
|
|
204
|
+
retire: (credentialId, expectedGeneration) => call(t, "POST", `${base}/credentials`, { operation: "retire", credentialId, expectedGeneration }),
|
|
205
|
+
},
|
|
206
|
+
jobs: {
|
|
207
|
+
submit: (input) => call(t, "POST", `${base}/jobs`, input),
|
|
208
|
+
list: (query = {}) => call(t, "GET", `${base}/jobs`, undefined, query),
|
|
209
|
+
summary: (id) => call(t, "GET", `${base}/jobs/${seg(id)}/summary`),
|
|
210
|
+
cancel: async (id) => {
|
|
211
|
+
await call(t, "GET", `${base}/jobs/${seg(id)}/summary`);
|
|
212
|
+
return call(t, "POST", `/namespaces/${namespaceSeg(namespace)}/runs/${seg(id)}/cancel`);
|
|
213
|
+
},
|
|
214
|
+
logs: async (id, query = {}) => {
|
|
215
|
+
await call(t, "GET", `${base}/jobs/${seg(id)}/summary`);
|
|
216
|
+
return call(t, "GET", `/namespaces/${namespaceSeg(namespace)}/runs/${seg(id)}/logs`, undefined, query);
|
|
217
|
+
},
|
|
218
|
+
},
|
|
174
219
|
setStatus: (id, status) => call(t, "POST", `${run(id)}/status`, { status }),
|
|
175
220
|
};
|
|
176
221
|
}
|
package/dist/api/sessions.d.ts
CHANGED
|
@@ -335,6 +335,12 @@ export interface Command<K extends CommandKind = CommandKind> {
|
|
|
335
335
|
turnId: string;
|
|
336
336
|
toolCallId: string;
|
|
337
337
|
};
|
|
338
|
+
memoContext?: {
|
|
339
|
+
memoId: string;
|
|
340
|
+
namespaceId: string;
|
|
341
|
+
revision: string;
|
|
342
|
+
promptHash: string;
|
|
343
|
+
} | null;
|
|
338
344
|
cancelRequested?: boolean;
|
|
339
345
|
reconciliation?: {
|
|
340
346
|
observation: Record<string, unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
import type { AgentApi } from '../../api/agent.js';
|
|
4
|
+
export interface ChatOptions {
|
|
5
|
+
conversation?: string;
|
|
6
|
+
namespace?: string;
|
|
7
|
+
control?: boolean;
|
|
8
|
+
notesWrite?: boolean;
|
|
9
|
+
toolsWrite?: boolean;
|
|
10
|
+
extensions?: boolean;
|
|
11
|
+
page?: string;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
file?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function chatTurn(api: Pick<AgentApi, 'chat'>, message: string, opts: ChatOptions, output?: {
|
|
16
|
+
out: (text: string) => boolean;
|
|
17
|
+
err: (text: string) => boolean;
|
|
18
|
+
}, signal?: AbortSignal): Promise<string>;
|
|
19
|
+
/** readline does not settle a pending question when stdin closes. */
|
|
20
|
+
export declare function terminalQuestion(terminal: ReturnType<typeof createInterface>, signal: AbortSignal): Promise<string | null>;
|
|
21
|
+
export declare function registerAgentChat(group: Command): void;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Terminal presentation of the browser's server-owned harness. */
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { createInterface } from 'node:readline/promises';
|
|
4
|
+
import { createClient, isObjectId } from '../../api/index.js';
|
|
5
|
+
import { resolveRemote, resolveToken } from '../config.js';
|
|
6
|
+
export async function chatTurn(api, message, opts, output = { out: (text) => process.stdout.write(text), err: (text) => process.stderr.write(text) }, signal) {
|
|
7
|
+
if (!message.trim())
|
|
8
|
+
throw new Error('Provide a nonempty message');
|
|
9
|
+
if (opts.conversation && !isObjectId(opts.conversation))
|
|
10
|
+
throw new Error('--conversation requires a 24-hex conversation ID');
|
|
11
|
+
let conversation = opts.conversation;
|
|
12
|
+
let done = false;
|
|
13
|
+
for await (const event of api.chat({ message, sessionId: conversation, actingNamespace: opts.namespace,
|
|
14
|
+
capabilities: { ...(opts.control ? { sessionControl: 1 } : {}),
|
|
15
|
+
...(opts.notesWrite ? { notesWrite: 1 } : {}), ...(opts.toolsWrite ? { toolsWrite: 1 } : {}),
|
|
16
|
+
...(opts.extensions ? { personalExtensions: 1 } : {}) },
|
|
17
|
+
page: { pathname: opts.page ?? '/', layouts: [] }, signal })) {
|
|
18
|
+
if (event.type === 'context') {
|
|
19
|
+
conversation = event.sessionId;
|
|
20
|
+
if (!opts.json)
|
|
21
|
+
output.err(`conversation ${conversation} (continue with --conversation ${conversation})\n`);
|
|
22
|
+
}
|
|
23
|
+
if (event.type === 'error')
|
|
24
|
+
throw new Error(event.error);
|
|
25
|
+
if (opts.json)
|
|
26
|
+
output.out(JSON.stringify(event) + '\n');
|
|
27
|
+
else if (event.type === 'delta')
|
|
28
|
+
output.out(event.text);
|
|
29
|
+
else if (event.type === 'tool')
|
|
30
|
+
output.err(`\n[tool ${event.name} ${event.status}${event.error ? ' ' + event.error : ''}${event.commandId ? ' command=' + event.commandId : ''}]\n`);
|
|
31
|
+
if (event.type === 'done') {
|
|
32
|
+
done = true;
|
|
33
|
+
if (!opts.json)
|
|
34
|
+
output.out('\n');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!done)
|
|
38
|
+
throw new Error('Agent stream ended before done; inspect the conversation before retrying');
|
|
39
|
+
if (!conversation || !isObjectId(conversation))
|
|
40
|
+
throw new Error('Agent response did not identify a conversation');
|
|
41
|
+
return conversation;
|
|
42
|
+
}
|
|
43
|
+
/** readline does not settle a pending question when stdin closes. */
|
|
44
|
+
export async function terminalQuestion(terminal, signal) {
|
|
45
|
+
const eof = new AbortController();
|
|
46
|
+
const closed = () => eof.abort();
|
|
47
|
+
terminal.once('close', closed);
|
|
48
|
+
try {
|
|
49
|
+
return await terminal.question('You> ', { signal: AbortSignal.any([signal, eof.signal]) });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (eof.signal.aborted || error.code === 'ERR_USE_AFTER_CLOSE')
|
|
53
|
+
return null;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
terminal.off('close', closed);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function stdinText() {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
for await (const chunk of process.stdin)
|
|
63
|
+
chunks.push(Buffer.from(chunk));
|
|
64
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
65
|
+
}
|
|
66
|
+
export function registerAgentChat(group) {
|
|
67
|
+
group.command('chat [message]').description('talk to the built-in browser agent; no message opens an interactive conversation')
|
|
68
|
+
.option('--conversation <id>', 'continue a browser or CLI conversation')
|
|
69
|
+
.option('--file <path>', "read one message from a UTF-8 file; '-' reads stdin")
|
|
70
|
+
.option('--namespace <slug>', 'explicit agent namespace; server verifies access')
|
|
71
|
+
.option('--extensions', 'enable personal extensions and MCP discovery when the server makes them available')
|
|
72
|
+
.option('--control', 'allow session control tools this turn')
|
|
73
|
+
.option('--notes-write', 'allow memo changes this turn')
|
|
74
|
+
.option('--tools-write', 'allow tool changes, as in the browser; existing resource permissions still apply')
|
|
75
|
+
.option('--page <pathname>', 'page context pathname', '/')
|
|
76
|
+
.option('--json', 'emit one JSON event per line (requires a message, file or stdin)')
|
|
77
|
+
.action(async (message, opts) => {
|
|
78
|
+
const abort = new AbortController();
|
|
79
|
+
const interrupt = () => abort.abort();
|
|
80
|
+
let terminal;
|
|
81
|
+
try {
|
|
82
|
+
if (message !== undefined && opts.file !== undefined)
|
|
83
|
+
throw new Error('Choose a message or --file, not both');
|
|
84
|
+
if (opts.file !== undefined)
|
|
85
|
+
message = opts.file === '-' ? await stdinText() : await readFile(opts.file, 'utf8');
|
|
86
|
+
else if (message === undefined && !process.stdin.isTTY)
|
|
87
|
+
message = await stdinText();
|
|
88
|
+
if (message === undefined && opts.json)
|
|
89
|
+
throw new Error('--json requires a message, --file or stdin');
|
|
90
|
+
const token = resolveToken();
|
|
91
|
+
if (!token)
|
|
92
|
+
throw new Error('Log in to DreamLake before chatting');
|
|
93
|
+
const api = createClient({ remote: resolveRemote(), token }).agent;
|
|
94
|
+
process.once('SIGINT', interrupt);
|
|
95
|
+
if (message !== undefined) {
|
|
96
|
+
await chatTurn(api, message, opts, undefined, abort.signal);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
terminal = createInterface({ input: process.stdin, output: process.stderr });
|
|
100
|
+
terminal.on('SIGINT', interrupt);
|
|
101
|
+
process.stderr.write('DreamLake agent. /exit or Ctrl+D leaves the conversation. Ctrl+C interrupts.\n');
|
|
102
|
+
while (!abort.signal.aborted) {
|
|
103
|
+
const next = await terminalQuestion(terminal, abort.signal);
|
|
104
|
+
if (next === null || next.trim() === '/exit')
|
|
105
|
+
break;
|
|
106
|
+
if (!next.trim())
|
|
107
|
+
continue;
|
|
108
|
+
opts.conversation = await chatTurn(api, next, opts, undefined, abort.signal);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const text = abort.signal.aborted ? 'Interrupted; inspect the conversation before retrying' : error instanceof Error ? error.message : String(error);
|
|
113
|
+
if (opts.json)
|
|
114
|
+
process.stdout.write(JSON.stringify({ type: 'error', error: text }) + '\n');
|
|
115
|
+
else
|
|
116
|
+
process.stderr.write(text + '\n');
|
|
117
|
+
process.exitCode = abort.signal.aborted ? 130 : 1;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (abort.signal.aborted)
|
|
121
|
+
process.exitCode = 130;
|
|
122
|
+
terminal?.close();
|
|
123
|
+
process.off('SIGINT', interrupt);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
package/dist/cli/agents/index.js
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
//
|
|
34
34
|
// Creation writes a definition. Running the built-in assistant is a separate
|
|
35
35
|
// invocation; external Claude declarations keep their existing runtime contract.
|
|
36
|
+
import { registerAgentChat } from "./chat.js";
|
|
36
37
|
import { spawnSync } from "node:child_process";
|
|
37
38
|
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
38
39
|
import { tmpdir } from "node:os";
|
|
@@ -529,8 +530,9 @@ export function registerAgentsCommand(program) {
|
|
|
529
530
|
const agents = program
|
|
530
531
|
.command("agents")
|
|
531
532
|
.alias("agent")
|
|
532
|
-
.description("
|
|
533
|
+
.description("chat with the built-in agent and manage agent definitions");
|
|
533
534
|
registerAgentManagement(agents);
|
|
535
|
+
registerAgentChat(agents);
|
|
534
536
|
agents
|
|
535
537
|
.command("create")
|
|
536
538
|
.description("declare an agent from a Claude agent file, a heredoc, or $EDITOR")
|
|
@@ -2,6 +2,8 @@ import { HttpError, requestJson } from "../client.js";
|
|
|
2
2
|
import { resolveRemote, resolveToken } from "../config.js";
|
|
3
3
|
import { emitJson, fail } from "../helpers.js";
|
|
4
4
|
import { registerNativeExperimentCommands } from "./native-commands.js";
|
|
5
|
+
import { registerExperimentManagementCommands } from "./management.js";
|
|
6
|
+
import { registerExperimentTransferCommands } from "./transfer/index.js";
|
|
5
7
|
class BindingError extends Error {
|
|
6
8
|
code;
|
|
7
9
|
remediation;
|
|
@@ -149,6 +151,8 @@ export async function runExperiments(action, opts, selection) {
|
|
|
149
151
|
export function registerExperimentsCommand(program) {
|
|
150
152
|
const command = program.command("experiments").description("discover and explicitly bind an existing managed Dash workspace (JSON receipts)");
|
|
151
153
|
registerNativeExperimentCommands(command);
|
|
154
|
+
registerExperimentTransferCommands(command);
|
|
155
|
+
registerExperimentManagementCommands(command);
|
|
152
156
|
for (const action of ["workspaces", "binding", "connect", "disconnect"]) {
|
|
153
157
|
const sub = command.command(action)
|
|
154
158
|
.description({ workspaces: "list verified eligible Dash organization workspaces", binding: "inspect the current binding and revision", connect: "preview a workspace binding; --apply commits it", disconnect: "preview detaching; remote experiments and SDK access are retained" }[action])
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Native project writer metadata and compute jobs. All actions use the selected DreamLake login. */
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
interface Options {
|
|
4
|
+
namespace: string;
|
|
5
|
+
project: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
limit?: string;
|
|
8
|
+
cursor?: string;
|
|
9
|
+
runId?: string;
|
|
10
|
+
idempotencyKey?: string;
|
|
11
|
+
expectedGeneration?: string;
|
|
12
|
+
spec?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function runExperimentManagement(group: 'writers' | 'jobs', action: string, opts: Options, subject?: string): Promise<number>;
|
|
15
|
+
export declare function registerExperimentManagementCommands(parent: Command): void;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createTransport, ApiError } from '../../api/client.js';
|
|
3
|
+
import { nativeExperimentsApi } from '../../api/native-experiments.js';
|
|
4
|
+
import { resolveRemote, resolveToken } from '../config.js';
|
|
5
|
+
import { emitJson, fail } from '../helpers.js';
|
|
6
|
+
const id = (v) => { if (!/^[a-f0-9]{24}$/.test(v))
|
|
7
|
+
throw Error('Expected a native run or job ID (24 hex characters).'); return v; };
|
|
8
|
+
const uuid = (v) => { if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v))
|
|
9
|
+
throw Error('Expected a UUID writer or idempotency key.'); return v.toLowerCase(); };
|
|
10
|
+
export async function runExperimentManagement(group, action, opts, subject) {
|
|
11
|
+
try {
|
|
12
|
+
const token = resolveToken();
|
|
13
|
+
if (!token)
|
|
14
|
+
throw Error('DreamLake login is required; run dl login.');
|
|
15
|
+
const api = nativeExperimentsApi(createTransport({ remote: resolveRemote(), token }), opts.namespace, opts.project);
|
|
16
|
+
let result;
|
|
17
|
+
const query = { ...(opts.limit !== undefined ? { limit: Number(opts.limit) } : {}), ...(opts.cursor !== undefined ? { cursor: opts.cursor } : {}) };
|
|
18
|
+
if (opts.limit !== undefined && (!/^[1-9][0-9]*$/.test(opts.limit) || !Number.isSafeInteger(query.limit) || query.limit > 100))
|
|
19
|
+
throw Error('--limit must be 1-100.');
|
|
20
|
+
if (group === 'writers') {
|
|
21
|
+
if (action === 'list')
|
|
22
|
+
result = await api.writers.list(query);
|
|
23
|
+
else if (action === 'create')
|
|
24
|
+
result = await api.writers.create(uuid(opts.idempotencyKey), opts.runId === undefined ? undefined : id(opts.runId));
|
|
25
|
+
else if (action === 'inspect')
|
|
26
|
+
result = await api.writers.get(uuid(subject));
|
|
27
|
+
else {
|
|
28
|
+
const generation = Number(opts.expectedGeneration);
|
|
29
|
+
if (!/^[1-9][0-9]*$/.test(opts.expectedGeneration ?? '') || !Number.isSafeInteger(generation))
|
|
30
|
+
throw Error('--expected-generation must be the writer generation you inspected.');
|
|
31
|
+
result = await api.writers[action](uuid(subject), generation);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (action === 'submit') {
|
|
36
|
+
const spec = JSON.parse(readFileSync(opts.spec, 'utf8'));
|
|
37
|
+
if (!spec || typeof spec !== 'object' || Array.isArray(spec) || typeof spec.requestId !== 'string' || typeof spec.target !== 'string' || !spec.execution || !spec.source)
|
|
38
|
+
throw Error('--spec must contain requestId, target, execution and explicit source.files.');
|
|
39
|
+
result = await api.jobs.submit(spec);
|
|
40
|
+
}
|
|
41
|
+
else if (action === 'list')
|
|
42
|
+
result = await api.jobs.list(query);
|
|
43
|
+
else if (action === 'logs')
|
|
44
|
+
result = await api.jobs.logs(id(subject), { cursor: opts.cursor });
|
|
45
|
+
else if (action === 'cancel')
|
|
46
|
+
result = await api.jobs.cancel(id(subject));
|
|
47
|
+
else
|
|
48
|
+
result = await api.jobs.summary(id(subject));
|
|
49
|
+
}
|
|
50
|
+
emitJson(result);
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
const code = error instanceof ApiError ? error.code : 'NATIVE_INVALID_REQUEST';
|
|
55
|
+
const message = error instanceof ApiError ? `Experiment request failed (HTTP ${error.status}); inspect the original operation before retrying.` : error instanceof Error ? error.message : 'Experiment request failed.';
|
|
56
|
+
if (opts.json)
|
|
57
|
+
emitJson({ ok: false, error: { code, message } });
|
|
58
|
+
else
|
|
59
|
+
fail(`${code}: ${message}`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function registerExperimentManagementCommands(parent) {
|
|
64
|
+
const common = (c) => c.requiredOption('--namespace <slug>', 'DreamLake namespace').requiredOption('--project <slug>', 'DreamLake project').option('--json', 'structured errors (success is JSON)');
|
|
65
|
+
for (const group of ['writers', 'jobs']) {
|
|
66
|
+
const root = parent.command(group).description(group === 'writers' ? 'native project writer metadata and session lifecycle' : 'native project compute jobs on configured hosts');
|
|
67
|
+
const act = (action) => (...input) => { const options = input.find(v => v && typeof v === 'object' && !v.commands); return runExperimentManagement(group, action, options, input.find(v => typeof v === 'string')).then(code => { process.exitCode = code; }); };
|
|
68
|
+
common(root.command('list').description(`list project ${group}`)).option('--limit <count>', 'page size, 1-100').option('--cursor <cursor>', 'server nextCursor').action(act('list'));
|
|
69
|
+
if (group === 'writers') {
|
|
70
|
+
common(root.command('create').description('register or recover one writer intent')).requiredOption('--idempotency-key <uuid>', 'stable creation intent UUID').option('--run-id <id>', 'bind to exactly this existing run').action(act('create'));
|
|
71
|
+
common(root.command('inspect <writer-id>').description('inspect one writer')).action(act('inspect'));
|
|
72
|
+
for (const action of ['rotate', 'retire'])
|
|
73
|
+
common(root.command(`${action} <writer-id>`).description(`${action} the inspected writer generation`)).requiredOption('--expected-generation <number>', 'generation from inspect').action(act(action));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
common(root.command('submit').description('submit an explicit native job manifest')).requiredOption('--spec <path>', 'JSON manifest: requestId, target, enrollmentId?, execution, source, timeoutSeconds?').action(act('submit'));
|
|
77
|
+
common(root.command('show <job-id>').description('show job receipt and native run binding')).action(act('summary'));
|
|
78
|
+
common(root.command('cancel <job-id>').description('request cancellation of a job in this project')).action(act('cancel'));
|
|
79
|
+
common(root.command('logs <job-id>').description('read job output after checking project binding')).option('--cursor <cursor>', 'server output cursor').action(act('logs'));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ParsedArgs } from './types.js';
|
|
2
|
+
import type { LocalStorage } from './local/storage.js';
|
|
3
|
+
import type { ExperimentInfo, ExperimentUploadClient } from './upload.js';
|
|
4
|
+
import type { ExperimentDownloadClient, RemoteExperiment } from './download.js';
|
|
5
|
+
import { type Context } from './context.js';
|
|
6
|
+
import { validName } from './transport.js';
|
|
7
|
+
/**
|
|
8
|
+
* Make sure a canonical DreamLake project exists, creating it PRIVATE when it does not, as the old
|
|
9
|
+
* uploader's upsert did. A readable project is used as is; a slug held by a project the caller cannot
|
|
10
|
+
* see is reported, never taken over; a missing namespace is never created. Auth, network and other
|
|
11
|
+
* errors propagate unchanged, so only a real "not found" leads to a create.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensureProject(c: Context, ns: string, project: string, description?: string): Promise<{
|
|
14
|
+
created: boolean;
|
|
15
|
+
project: Record<string, any>;
|
|
16
|
+
}>;
|
|
17
|
+
export { validName };
|
|
18
|
+
/** RemoteClient's upload surface over native REST. Run IDs map to their project route. */
|
|
19
|
+
declare class NativeUploadClient implements ExperimentUploadClient {
|
|
20
|
+
readonly c: Context;
|
|
21
|
+
private readonly bases;
|
|
22
|
+
/** Capabilities per `namespace/project`, read in the preflight (after the project exists). */
|
|
23
|
+
readonly caps: Map<string, string[]>;
|
|
24
|
+
personal: string | null;
|
|
25
|
+
constructor(c: Context);
|
|
26
|
+
private run;
|
|
27
|
+
createOrUpdateExperiment(args: Parameters<ExperimentUploadClient['createOrUpdateExperiment']>[0]): Promise<any>;
|
|
28
|
+
/** `write_protected`: a person's protection, set last (PATCH `writeProtected: true`), after all data was written. */
|
|
29
|
+
protectExperiment(id: string): Promise<void>;
|
|
30
|
+
setParameters(id: string, data: Record<string, unknown>): Promise<any>;
|
|
31
|
+
createLogEntries(id: string, logs: Record<string, unknown>[]): Promise<any>;
|
|
32
|
+
appendBatchToMetric(id: string, name: string, points: unknown[]): Promise<any>;
|
|
33
|
+
uploadFile(args: Parameters<ExperimentUploadClient['uploadFile']>[0]): Promise<any>;
|
|
34
|
+
}
|
|
35
|
+
interface PreflightItem {
|
|
36
|
+
info: ExperimentInfo;
|
|
37
|
+
validation: {
|
|
38
|
+
metadata?: Record<string, any>;
|
|
39
|
+
};
|
|
40
|
+
fullPrefix: string;
|
|
41
|
+
targetProject: string;
|
|
42
|
+
}
|
|
43
|
+
/** The upload pipeline's native target: its client, state identity and pre-write check. */
|
|
44
|
+
export declare function nativeUploadTarget(args: ParsedArgs): {
|
|
45
|
+
client: NativeUploadClient;
|
|
46
|
+
server: string;
|
|
47
|
+
stateIdentity: string;
|
|
48
|
+
preflight: (storage: LocalStorage, items: PreflightItem[], skipLogs: boolean, skipMetrics: boolean) => Promise<string[]>;
|
|
49
|
+
};
|
|
50
|
+
/** RemoteClient's download surface over native REST, for one DreamLake project. */
|
|
51
|
+
declare class NativeDownloadClient implements ExperimentDownloadClient {
|
|
52
|
+
private readonly c;
|
|
53
|
+
private readonly fileRuns;
|
|
54
|
+
private readonly bindrSupport;
|
|
55
|
+
/** The project route of each discovered run: a glob may select runs of several projects. */
|
|
56
|
+
readonly bases: Map<string, string>;
|
|
57
|
+
constructor(c: Context);
|
|
58
|
+
private run;
|
|
59
|
+
getParameters(id: string): Promise<Record<string, unknown>>;
|
|
60
|
+
queryLogs(id: string, opts?: Parameters<ExperimentDownloadClient['queryLogs']>[1]): Promise<any>;
|
|
61
|
+
listMetrics(id: string): Promise<any[]>;
|
|
62
|
+
/** Native metrics have no chunk index: the pipeline reads them by index pages instead. */
|
|
63
|
+
getMetricStats(): Promise<any>;
|
|
64
|
+
downloadMetricChunk(): Promise<any>;
|
|
65
|
+
getMetricData(id: string, name: string, opts?: {
|
|
66
|
+
startIndex?: number;
|
|
67
|
+
limit?: number;
|
|
68
|
+
bufferOnly?: boolean;
|
|
69
|
+
}): Promise<any>;
|
|
70
|
+
/** Native file listing is one response: the first page holds every file. */
|
|
71
|
+
listFiles(id: string, _limit?: number, offset?: number): Promise<any>;
|
|
72
|
+
bindrs(id: string, itemKind?: string, itemId?: string): Promise<string[]>;
|
|
73
|
+
downloadFileStreaming(fileId: string, destPath: string): Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
/** The download pipeline's native source: `-p namespace/project[/folder…|/glob]` (globs anywhere), every page of runs. */
|
|
76
|
+
export declare function nativeDownloadSource(args: ParsedArgs): {
|
|
77
|
+
client: NativeDownloadClient;
|
|
78
|
+
stateIdentity: string;
|
|
79
|
+
discover(experiment?: string): Promise<RemoteExperiment[]>;
|
|
80
|
+
};
|
|
81
|
+
export declare function reportNativeError(e: unknown): number;
|
|
82
|
+
/** `upload --tracks FILE --remote-path ns/project/run/topic --backend native` */
|
|
83
|
+
export declare function uploadTrackNative(args: ParsedArgs): Promise<number>;
|
|
84
|
+
/** `download --tracks ns/project/run/topic [--format F] [-o FILE] --backend native` */
|
|
85
|
+
export declare function downloadTrackNative(args: ParsedArgs): Promise<number>;
|
|
86
|
+
export declare function runNativeTransfer(work: () => Promise<number>): Promise<number>;
|