@dreamlake/dreamlake-cli 0.100.0 → 0.101.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/dist/api/access.d.ts +2 -0
- package/dist/api/access.js +2 -0
- package/dist/api/agent.d.ts +10 -0
- package/dist/api/agent.js +11 -0
- package/dist/api/host-moves.d.ts +34 -0
- package/dist/api/host-moves.js +48 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/cli/artifact/index.d.ts +2 -0
- package/dist/cli/artifact/index.js +23 -3
- package/dist/cli/artifact/site.d.ts +16 -0
- package/dist/cli/artifact/site.js +125 -0
- package/dist/cli/artifact/siteFormat.d.ts +25 -0
- package/dist/cli/artifact/siteFormat.js +53 -0
- package/dist/cli/compat/s3-backend.d.ts +26 -0
- package/dist/cli/compat/s3-backend.js +45 -0
- package/dist/cli/help-examples.generated.js +2 -1
- package/dist/cli/hosts/api.js +1 -0
- package/dist/cli/hosts/index.js +2 -0
- package/dist/cli/hosts/inventory.d.ts +3 -0
- package/dist/cli/hosts/move.d.ts +36 -0
- package/dist/cli/hosts/move.js +72 -0
- package/dist/cli/hosts/ssh.js +2 -1
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
package/dist/api/access.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare function hostsApi(t: Transport, namespace: string): {
|
|
|
29
29
|
durationSeconds: number;
|
|
30
30
|
}) => Promise<unknown>;
|
|
31
31
|
launch: (id: string) => Promise<unknown>;
|
|
32
|
+
movePreview(hostId: string, destinationNamespace: string): Promise<import("./host-moves.js").HostMovePreview>;
|
|
33
|
+
move(hostId: string, request: import("./host-moves.js").HostMoveRequest): Promise<import("./host-moves.js").HostMoveReceipt>;
|
|
32
34
|
};
|
|
33
35
|
export declare function serviceAccountsApi(t: Transport, namespace: string): {
|
|
34
36
|
list: (query?: {
|
package/dist/api/access.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { hostMoveApi } from "./host-moves.js";
|
|
1
2
|
import { seg } from "./client.js";
|
|
2
3
|
import { call, namespacePath } from "./common.js";
|
|
3
4
|
export function hostsApi(t, namespace) {
|
|
4
5
|
const base = namespacePath(namespace) + "/hosts", p = (id) => base + "/" + seg(id);
|
|
5
6
|
return {
|
|
7
|
+
...hostMoveApi(t, namespace),
|
|
6
8
|
list: (query = {}) => call(t, "GET", base, undefined, query),
|
|
7
9
|
status: (id) => call(t, "GET", p(id)),
|
|
8
10
|
enroll: (input) => call(t, "POST", base + "/enrollments", input),
|
package/dist/api/agent.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export type TurnCapabilities = {
|
|
|
7
7
|
layoutActions?: 1;
|
|
8
8
|
sessionControl?: 1;
|
|
9
9
|
notesWrite?: 1;
|
|
10
|
+
hostMove?: 1;
|
|
11
|
+
toolsWrite?: 1;
|
|
12
|
+
memoryWrite?: 1;
|
|
10
13
|
};
|
|
11
14
|
export type AgentEvent = {
|
|
12
15
|
type: "context";
|
|
@@ -64,6 +67,11 @@ export interface ConversationSummary {
|
|
|
64
67
|
/** Parse `data: {...}` server-sent events; a frame that is not JSON is dropped, never guessed. */
|
|
65
68
|
export declare function readAgentEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<AgentEvent>;
|
|
66
69
|
export declare function agentApi(t: Transport, options: Pick<ClientOptions, "remote" | "token" | "fetch">): {
|
|
70
|
+
namespaceScope: (namespace: string) => Promise<{
|
|
71
|
+
apiVersion: 1;
|
|
72
|
+
namespace: string;
|
|
73
|
+
allowed: true;
|
|
74
|
+
}>;
|
|
67
75
|
browserActions: (conversationId: string) => Promise<{
|
|
68
76
|
actions: unknown[];
|
|
69
77
|
}>;
|
|
@@ -79,6 +87,7 @@ export declare function agentApi(t: Transport, options: Pick<ClientOptions, "rem
|
|
|
79
87
|
restore: (conversationId: string) => Promise<{
|
|
80
88
|
sessionId: string;
|
|
81
89
|
status: string;
|
|
90
|
+
actingNamespace?: string;
|
|
82
91
|
messages: {
|
|
83
92
|
role: "user" | "assistant";
|
|
84
93
|
content: string;
|
|
@@ -96,6 +105,7 @@ export declare function agentApi(t: Transport, options: Pick<ClientOptions, "rem
|
|
|
96
105
|
chat(input: {
|
|
97
106
|
message: string;
|
|
98
107
|
sessionId?: string;
|
|
108
|
+
actingNamespace?: string;
|
|
99
109
|
capabilities?: TurnCapabilities;
|
|
100
110
|
page?: {
|
|
101
111
|
pathname: string;
|
package/dist/api/agent.js
CHANGED
|
@@ -38,6 +38,14 @@ export async function* readAgentEvents(body) {
|
|
|
38
38
|
export function agentApi(t, options) {
|
|
39
39
|
return {
|
|
40
40
|
...projectToolsApi(t),
|
|
41
|
+
namespaceScope: async (namespace) => {
|
|
42
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(namespace))
|
|
43
|
+
throw new Error('invalid agent namespace');
|
|
44
|
+
const result = await t.request('GET', '/agent/namespace-scope', { query: { namespace } });
|
|
45
|
+
if (result?.apiVersion !== 1 || result.namespace !== namespace || result.allowed !== true)
|
|
46
|
+
throw new Error('Agent namespace scope could not be verified');
|
|
47
|
+
return result;
|
|
48
|
+
},
|
|
41
49
|
browserActions: (conversationId) => {
|
|
42
50
|
if (!isObjectId(conversationId))
|
|
43
51
|
throw new Error("expected a 24-hex conversation id");
|
|
@@ -58,6 +66,8 @@ export function agentApi(t, options) {
|
|
|
58
66
|
},
|
|
59
67
|
/** One turn as a stream of events. `page` is the browser context; a CLI passes a pathname only. */
|
|
60
68
|
async *chat(input) {
|
|
69
|
+
if (input.actingNamespace !== undefined && !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(input.actingNamespace))
|
|
70
|
+
throw new Error('invalid agent namespace');
|
|
61
71
|
const doFetch = options.fetch ?? fetch;
|
|
62
72
|
const response = await doFetch(options.remote.replace(/\/+$/, "") + "/agent/chat", {
|
|
63
73
|
method: "POST",
|
|
@@ -71,6 +81,7 @@ export function agentApi(t, options) {
|
|
|
71
81
|
body: JSON.stringify({
|
|
72
82
|
message: input.message,
|
|
73
83
|
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
84
|
+
...(input.actingNamespace !== undefined ? { actingNamespace: input.actingNamespace } : {}),
|
|
74
85
|
...(input.capabilities ? { capabilities: input.capabilities } : {}),
|
|
75
86
|
page: input.page ?? { pathname: "/", layouts: [] },
|
|
76
87
|
}),
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Transport } from './client.js';
|
|
2
|
+
export type HostMovePreview = {
|
|
3
|
+
apiVersion: 1;
|
|
4
|
+
hostId: string;
|
|
5
|
+
sourceNamespaceId: string;
|
|
6
|
+
destinationNamespaceId: string;
|
|
7
|
+
destinationNamespace: string;
|
|
8
|
+
name: string;
|
|
9
|
+
ownerUserId: string;
|
|
10
|
+
visibility: 'private';
|
|
11
|
+
revision: number;
|
|
12
|
+
previewHash: string;
|
|
13
|
+
blockers: string[];
|
|
14
|
+
executable: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type HostMoveRequest = {
|
|
17
|
+
destinationNamespace: string;
|
|
18
|
+
requestId: string;
|
|
19
|
+
expectedRevision: number;
|
|
20
|
+
previewHash: string;
|
|
21
|
+
};
|
|
22
|
+
export type HostMoveReceipt = Omit<HostMovePreview, 'previewHash' | 'blockers' | 'executable'> & {
|
|
23
|
+
operationId: string;
|
|
24
|
+
requestId: string;
|
|
25
|
+
recordedAt: string;
|
|
26
|
+
replayed: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare function validateHostMovePreview(value: unknown, hostId: string, destinationNamespace: string): HostMovePreview;
|
|
29
|
+
export declare function validateHostMoveReceipt(value: unknown, hostId: string, request: HostMoveRequest): HostMoveReceipt;
|
|
30
|
+
export declare function hostMoveApi(t: Transport, namespace: string): {
|
|
31
|
+
movePreview(hostId: string, destinationNamespace: string): Promise<HostMovePreview>;
|
|
32
|
+
/** After uncertainty replay exactly this request; no new key, preview or automatic retry. */
|
|
33
|
+
move(hostId: string, request: HostMoveRequest): Promise<HostMoveReceipt>;
|
|
34
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { seg } from './client.js';
|
|
2
|
+
const nonempty = (v) => typeof v === 'string' && v.length > 0 && v.length <= 256 && !/[\x00-\x1f\x7f]/.test(v);
|
|
3
|
+
const invalid = () => { throw new Error('Host move response could not be verified. Keep the same request and reconcile before retrying.'); };
|
|
4
|
+
const base = (namespace, hostId) => {
|
|
5
|
+
if (!nonempty(namespace) || !/^[a-f0-9]{24}$/.test(hostId))
|
|
6
|
+
invalid();
|
|
7
|
+
return `/namespaces/${seg(namespace)}/hosts/${hostId}/move`;
|
|
8
|
+
};
|
|
9
|
+
function common(v, hostId, destinationNamespace) {
|
|
10
|
+
if (!v || v.apiVersion !== 1 || v.hostId !== hostId || v.destinationNamespace !== destinationNamespace ||
|
|
11
|
+
![v.sourceNamespaceId, v.destinationNamespaceId, v.ownerUserId, v.name].every(nonempty) ||
|
|
12
|
+
v.visibility !== 'private' || !Number.isSafeInteger(v.revision) || v.revision < 0)
|
|
13
|
+
invalid();
|
|
14
|
+
}
|
|
15
|
+
export function validateHostMovePreview(value, hostId, destinationNamespace) {
|
|
16
|
+
const v = value;
|
|
17
|
+
common(v, hostId, destinationNamespace);
|
|
18
|
+
if (!/^[a-f0-9]{64}$/.test(v.previewHash) || !Array.isArray(v.blockers) ||
|
|
19
|
+
v.blockers.some(b => !nonempty(b)) || typeof v.executable !== 'boolean' || v.executable !== (v.blockers.length === 0))
|
|
20
|
+
invalid();
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
export function validateHostMoveReceipt(value, hostId, request) {
|
|
24
|
+
const v = value;
|
|
25
|
+
common(v, hostId, request.destinationNamespace);
|
|
26
|
+
if (v.requestId !== request.requestId || !nonempty(v.operationId) || v.revision !== request.expectedRevision + 1 ||
|
|
27
|
+
!nonempty(v.recordedAt) || !Number.isFinite(Date.parse(v.recordedAt)) || typeof v.replayed !== 'boolean')
|
|
28
|
+
invalid();
|
|
29
|
+
return v;
|
|
30
|
+
}
|
|
31
|
+
export function hostMoveApi(t, namespace) {
|
|
32
|
+
return {
|
|
33
|
+
async movePreview(hostId, destinationNamespace) {
|
|
34
|
+
if (!nonempty(destinationNamespace) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(destinationNamespace))
|
|
35
|
+
invalid();
|
|
36
|
+
const result = await t.request('POST', `${base(namespace, hostId)}/preview`, { json: { destinationNamespace } });
|
|
37
|
+
return validateHostMovePreview(result, hostId, destinationNamespace);
|
|
38
|
+
},
|
|
39
|
+
/** After uncertainty replay exactly this request; no new key, preview or automatic retry. */
|
|
40
|
+
async move(hostId, request) {
|
|
41
|
+
if (!request || !nonempty(request.destinationNamespace) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(request.destinationNamespace) || !nonempty(request.requestId) || !/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(request.requestId) ||
|
|
42
|
+
!Number.isSafeInteger(request.expectedRevision) || request.expectedRevision < 0 || request.expectedRevision >= 2147483647 || !/^[a-f0-9]{64}$/.test(request.previewHash) ||
|
|
43
|
+
Object.keys(request).some(k => !['destinationNamespace', 'requestId', 'expectedRevision', 'previewHash'].includes(k)))
|
|
44
|
+
invalid();
|
|
45
|
+
return validateHostMoveReceipt(await t.request('POST', base(namespace, hostId), { json: request }), hostId, request);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -374,6 +374,8 @@ export declare function createApi(transport: Transport): {
|
|
|
374
374
|
durationSeconds: number;
|
|
375
375
|
}) => Promise<unknown>;
|
|
376
376
|
launch: (id: string) => Promise<unknown>;
|
|
377
|
+
movePreview(hostId: string, destinationNamespace: string): Promise<import("./host-moves.js").HostMovePreview>;
|
|
378
|
+
move(hostId: string, request: import("./host-moves.js").HostMoveRequest): Promise<import("./host-moves.js").HostMoveReceipt>;
|
|
377
379
|
};
|
|
378
380
|
serviceAccounts: (namespace: string) => {
|
|
379
381
|
list: (query?: {
|
|
@@ -1033,6 +1035,11 @@ export declare function createApi(transport: Transport): {
|
|
|
1033
1035
|
export type DreamLakeClient = ReturnType<typeof createClient>;
|
|
1034
1036
|
export declare function createClient(options: ClientOptions): {
|
|
1035
1037
|
agent: {
|
|
1038
|
+
namespaceScope: (namespace: string) => Promise<{
|
|
1039
|
+
apiVersion: 1;
|
|
1040
|
+
namespace: string;
|
|
1041
|
+
allowed: true;
|
|
1042
|
+
}>;
|
|
1036
1043
|
browserActions: (conversationId: string) => Promise<{
|
|
1037
1044
|
actions: unknown[];
|
|
1038
1045
|
}>;
|
|
@@ -1048,6 +1055,7 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1048
1055
|
restore: (conversationId: string) => Promise<{
|
|
1049
1056
|
sessionId: string;
|
|
1050
1057
|
status: string;
|
|
1058
|
+
actingNamespace?: string;
|
|
1051
1059
|
messages: {
|
|
1052
1060
|
role: "user" | "assistant";
|
|
1053
1061
|
content: string;
|
|
@@ -1064,6 +1072,7 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1064
1072
|
chat(input: {
|
|
1065
1073
|
message: string;
|
|
1066
1074
|
sessionId?: string;
|
|
1075
|
+
actingNamespace?: string;
|
|
1067
1076
|
capabilities?: import("./agent.js").TurnCapabilities;
|
|
1068
1077
|
page?: {
|
|
1069
1078
|
pathname: string;
|
|
@@ -1442,6 +1451,8 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1442
1451
|
durationSeconds: number;
|
|
1443
1452
|
}) => Promise<unknown>;
|
|
1444
1453
|
launch: (id: string) => Promise<unknown>;
|
|
1454
|
+
movePreview(hostId: string, destinationNamespace: string): Promise<import("./host-moves.js").HostMovePreview>;
|
|
1455
|
+
move(hostId: string, request: import("./host-moves.js").HostMoveRequest): Promise<import("./host-moves.js").HostMoveReceipt>;
|
|
1445
1456
|
};
|
|
1446
1457
|
serviceAccounts: (namespace: string) => {
|
|
1447
1458
|
list: (query?: {
|
|
@@ -2111,3 +2122,4 @@ export { documentEdits, documentInsertion } from "./note-edits.js";
|
|
|
2111
2122
|
export * from "./note-facade.js";
|
|
2112
2123
|
export type { NoteReadingOptions, NoteReadingPage, NoteFocusedRead } from "./note-reading.js";
|
|
2113
2124
|
export { lineRange, focusedRead, InvalidLineRange } from "./note-reading.js";
|
|
2125
|
+
export type { HostMovePreview, HostMoveRequest, HostMoveReceipt } from "./host-moves.js";
|
|
@@ -11,6 +11,8 @@ export declare function detectKind(file: string, override?: string): string | nu
|
|
|
11
11
|
export interface ArtifactPushArgs extends DreamlakeOpts {
|
|
12
12
|
file: string;
|
|
13
13
|
entry?: string;
|
|
14
|
+
site?: boolean;
|
|
15
|
+
spa?: boolean;
|
|
14
16
|
title?: string;
|
|
15
17
|
kind?: string;
|
|
16
18
|
artifactId?: string;
|
|
@@ -11,6 +11,7 @@ import { readFileSync, statSync } from "node:fs";
|
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import { uploadIncremental, MAX_SIZE } from "./incremental.js";
|
|
13
13
|
import { packPages } from "./pages.js";
|
|
14
|
+
import { collectSite, uploadSite } from "./site.js";
|
|
14
15
|
import { metaError, putArtifactCover, readCoverFile, registerArtifactMetaCommand } from "./meta.js";
|
|
15
16
|
// ../prompt.js, NOT @inquirer/prompts directly. This file used to import the
|
|
16
17
|
// inquirer prompt straight, which bypassed prompt.ts's `!process.stdin.isTTY`
|
|
@@ -86,10 +87,15 @@ function shellQuote(value) {
|
|
|
86
87
|
export async function runDreamlakeArtifactPush(args, deps = {}) {
|
|
87
88
|
const incremental = !args.full && args.incremental !== false;
|
|
88
89
|
let content;
|
|
90
|
+
let site;
|
|
89
91
|
let directory = false;
|
|
90
92
|
try {
|
|
91
93
|
const stat = statSync(args.file);
|
|
92
94
|
directory = stat.isDirectory();
|
|
95
|
+
if (args.site && !directory)
|
|
96
|
+
throw new Error('--site requires a built static directory');
|
|
97
|
+
if (args.spa && !args.site)
|
|
98
|
+
throw new Error('--spa requires --site');
|
|
93
99
|
if (!directory && !stat.isFile())
|
|
94
100
|
throw new Error("not a file or directory");
|
|
95
101
|
if (!directory && args.entry !== undefined)
|
|
@@ -100,7 +106,8 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
|
|
|
100
106
|
fail("incremental artifacts are limited to 512 MiB");
|
|
101
107
|
return 1;
|
|
102
108
|
}
|
|
103
|
-
|
|
109
|
+
site = args.site ? collectSite(args.file, args.entry, args.spa) : undefined;
|
|
110
|
+
content = site ? site.content : directory ? packPages(args.file, args.entry) : readFileSync(args.file);
|
|
104
111
|
}
|
|
105
112
|
catch (error) {
|
|
106
113
|
const missing = error.code === 'ENOENT';
|
|
@@ -141,6 +148,13 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
|
|
|
141
148
|
const namespace = await requireNamespace(ctx, args.namespace);
|
|
142
149
|
if (!namespace)
|
|
143
150
|
return 1;
|
|
151
|
+
if (site) {
|
|
152
|
+
const capability = await jsonRequest('GET', `${ctx.remote}/artifacts/site-capabilities`, token);
|
|
153
|
+
if (capability.status !== 200 || capability.body?.schema !== 'dreamlake-artifact-files/1') {
|
|
154
|
+
fail('Static artifact hosting is unavailable on this server; no files were uploaded.');
|
|
155
|
+
return 1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
144
158
|
// A title the user set once must survive every later push. Without
|
|
145
159
|
// --title, ask the catalog first: an existing row keeps its title (the
|
|
146
160
|
// registration below then carries none), a new one gets the file stem.
|
|
@@ -195,10 +209,14 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
|
|
|
195
209
|
process.stdout.write(`Uploading ${path.basename(args.file)} (${kind})\n`);
|
|
196
210
|
process.stdout.write(` namespace: ${namespace}\n`);
|
|
197
211
|
process.stdout.write(` artifact: ${artifactId} v${version}\n`);
|
|
198
|
-
process.stdout.write(` size: ${content.length} bytes\n`);
|
|
212
|
+
process.stdout.write(` size: ${site?.bytes ?? content.length} bytes\n`);
|
|
199
213
|
try {
|
|
200
214
|
let storedContent = content;
|
|
201
|
-
if (
|
|
215
|
+
if (site) {
|
|
216
|
+
const result = await uploadSite(site, backend);
|
|
217
|
+
process.stdout.write(` site: ${site.manifest.files.length} files, ${result.uploadedFiles} new files, ${result.uploadedBytes} bytes uploaded\n`);
|
|
218
|
+
}
|
|
219
|
+
else if (incremental) {
|
|
202
220
|
const result = await uploadIncremental(content, backend);
|
|
203
221
|
storedContent = result.content;
|
|
204
222
|
process.stdout.write(` incremental: ${result.uploadedChunks} new chunks, ${result.uploadedBytes} compressed bytes uploaded, ${result.reusedBytes} source bytes reused\n`);
|
|
@@ -374,6 +392,8 @@ export function registerArtifactCommand(program) {
|
|
|
374
392
|
.description("push a renderable artifact — a new version of --id (written straight to storage)")
|
|
375
393
|
.argument("<file>", "file or self-contained HTML page directory to push")
|
|
376
394
|
.option("--entry <path>", "entry page for a directory (default: index.html)")
|
|
395
|
+
.option("--site", "upload a static build with files loaded on demand (requires site hosting)")
|
|
396
|
+
.option("--spa", "serve the site entry for extensionless client routes (requires --site)")
|
|
377
397
|
.option("--title <title>", "human title (default: file stem)")
|
|
378
398
|
.option("--kind <kind>", "html, react, markdown, svg, code, mermaid (default: auto)")
|
|
379
399
|
.option("--id <artifact-id>", "stable artifact id for versioning (default: slug of title)")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type DreamdbBackend, type UploadFile } from '../compat/s3-backend.js';
|
|
2
|
+
import { type SiteManifest } from './siteFormat.js';
|
|
3
|
+
/** Snapshot the manifest before any network writes; retain file metadata, not media buffers. */
|
|
4
|
+
export declare function collectSite(directory: string, entry?: string, spa?: boolean): {
|
|
5
|
+
manifest: SiteManifest;
|
|
6
|
+
objects: Map<string, UploadFile>;
|
|
7
|
+
json: Buffer<ArrayBuffer>;
|
|
8
|
+
hash: string;
|
|
9
|
+
content: Buffer<ArrayBuffer>;
|
|
10
|
+
bytes: number;
|
|
11
|
+
};
|
|
12
|
+
/** Conditional immutable writes; publish the manifest only after every file exists. */
|
|
13
|
+
export declare function uploadSite(site: ReturnType<typeof collectSite>, backend: DreamdbBackend): Promise<{
|
|
14
|
+
uploadedBytes: number;
|
|
15
|
+
uploadedFiles: number;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readdirSync, readSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { S3_SINGLE_PUT_MAX_BYTES } from '../compat/s3-backend.js';
|
|
5
|
+
import { encodeSiteDescriptor, SITE_MAX_FILES, SITE_MANIFEST_MAX_BYTES, siteFileKey, siteManifestKey, validSitePath, validateSiteManifest } from './siteFormat.js';
|
|
6
|
+
const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
7
|
+
/** Hash with bounded memory; a signed upload rejects source changes before publication. */
|
|
8
|
+
function inspectFile(file, html) {
|
|
9
|
+
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
10
|
+
try {
|
|
11
|
+
const before = fstatSync(fd);
|
|
12
|
+
if (!before.isFile() || !Number.isSafeInteger(before.size) || before.size > S3_SINGLE_PUT_MAX_BYTES)
|
|
13
|
+
throw new Error('A site file exceeds the 5 GiB single-PUT transport limit');
|
|
14
|
+
if (html && before.size > 32 * 1024 * 1024)
|
|
15
|
+
throw new Error('A site HTML page exceeds 32 MiB; move large assets into separate files');
|
|
16
|
+
const hash = createHash('sha256'), buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
17
|
+
const decoder = html ? new TextDecoder('utf-8', { fatal: true }) : undefined;
|
|
18
|
+
let size = 0, count;
|
|
19
|
+
while ((count = readSync(fd, buffer, 0, buffer.length, null)) > 0) {
|
|
20
|
+
size += count;
|
|
21
|
+
if (size > before.size)
|
|
22
|
+
throw new Error('Site file changed while hashing; retry the push');
|
|
23
|
+
hash.update(buffer.subarray(0, count));
|
|
24
|
+
decoder?.decode(buffer.subarray(0, count), { stream: true });
|
|
25
|
+
}
|
|
26
|
+
decoder?.decode();
|
|
27
|
+
const after = fstatSync(fd);
|
|
28
|
+
if (size !== before.size || after.mtimeMs !== before.mtimeMs || after.ctimeMs !== before.ctimeMs)
|
|
29
|
+
throw new Error('Site file changed while hashing; retry the push');
|
|
30
|
+
return { path: file, size, sha256: hash.digest('hex'), mtimeMs: after.mtimeMs, ctimeMs: after.ctimeMs,
|
|
31
|
+
dev: after.dev, ino: after.ino };
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
closeSync(fd);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Snapshot the manifest before any network writes; retain file metadata, not media buffers. */
|
|
38
|
+
export function collectSite(directory, entry = 'index.html', spa = false) {
|
|
39
|
+
if (!lstatSync(directory).isDirectory())
|
|
40
|
+
throw new Error('Site must be a directory, not a symlink');
|
|
41
|
+
const manifest = { schema: 'dreamlake-artifact-files/1', entry, spa, files: [] };
|
|
42
|
+
const objects = new Map();
|
|
43
|
+
let bytes = 0;
|
|
44
|
+
let visited = 0;
|
|
45
|
+
function walk(relative, depth) {
|
|
46
|
+
if (depth > 32)
|
|
47
|
+
throw new Error('Artifact site nesting exceeds 32 directories');
|
|
48
|
+
for (const name of readdirSync(path.join(directory, relative)).sort()) {
|
|
49
|
+
if (++visited > SITE_MAX_FILES * 2)
|
|
50
|
+
throw new Error('Too many site directory entries');
|
|
51
|
+
const file = path.join(directory, relative, name);
|
|
52
|
+
const stat = lstatSync(file);
|
|
53
|
+
if (stat.isSymbolicLink())
|
|
54
|
+
throw new Error(`Symlinks are not supported: ${file}`);
|
|
55
|
+
if (name.startsWith('.'))
|
|
56
|
+
continue;
|
|
57
|
+
const local = relative ? `${relative}/${name}` : name;
|
|
58
|
+
if (!validSitePath(local))
|
|
59
|
+
throw new Error(`Invalid artifact path: ${local}`);
|
|
60
|
+
if (stat.isDirectory()) {
|
|
61
|
+
walk(local, depth + 1);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!stat.isFile())
|
|
65
|
+
throw new Error(`Not a regular file: ${local}`);
|
|
66
|
+
if (manifest.files.length >= SITE_MAX_FILES)
|
|
67
|
+
throw new Error('Artifact site exceeds 4096 files');
|
|
68
|
+
const data = inspectFile(file, /\.html?$/i.test(local));
|
|
69
|
+
bytes += data.size;
|
|
70
|
+
if (!Number.isSafeInteger(bytes))
|
|
71
|
+
throw new Error('Artifact site size exceeds safe integer accounting');
|
|
72
|
+
objects.set(data.sha256, data);
|
|
73
|
+
manifest.files.push({ path: local, sha256: data.sha256, size: data.size });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
walk('', 0);
|
|
77
|
+
validateSiteManifest(manifest);
|
|
78
|
+
const json = Buffer.from(JSON.stringify(manifest));
|
|
79
|
+
if (json.length > SITE_MANIFEST_MAX_BYTES)
|
|
80
|
+
throw new Error('Artifact manifest exceeds 2 MiB');
|
|
81
|
+
const hash = sha(json);
|
|
82
|
+
return { manifest, objects, json, hash, content: Buffer.from(encodeSiteDescriptor(hash)), bytes };
|
|
83
|
+
}
|
|
84
|
+
/** Conditional immutable writes; publish the manifest only after every file exists. */
|
|
85
|
+
export async function uploadSite(site, backend) {
|
|
86
|
+
if (!backend.putFile)
|
|
87
|
+
throw new Error('Artifact site uploads require a streaming file backend');
|
|
88
|
+
let uploadedBytes = 0;
|
|
89
|
+
let uploadedFiles = 0;
|
|
90
|
+
let next = 0;
|
|
91
|
+
const entries = [...site.objects];
|
|
92
|
+
let failure;
|
|
93
|
+
async function put(key, bytes) {
|
|
94
|
+
if ((await backend.head(key)).exists)
|
|
95
|
+
return false;
|
|
96
|
+
const result = await backend.put(key, bytes, { ifNoneMatchStar: true });
|
|
97
|
+
if (result.status !== 'created' && !(await backend.head(key)).exists)
|
|
98
|
+
throw new Error('Artifact file upload conflict; retry the push');
|
|
99
|
+
return result.status === 'created';
|
|
100
|
+
}
|
|
101
|
+
await Promise.all(Array.from({ length: Math.min(8, entries.length) }, async () => {
|
|
102
|
+
while (next < entries.length && !failure) {
|
|
103
|
+
const [hash, data] = entries[next++];
|
|
104
|
+
try {
|
|
105
|
+
const key = siteFileKey(hash);
|
|
106
|
+
if ((await backend.head(key)).exists)
|
|
107
|
+
continue;
|
|
108
|
+
const result = await backend.putFile(key, data, { ifNoneMatchStar: true });
|
|
109
|
+
if (result.status !== 'created' && !(await backend.head(key)).exists)
|
|
110
|
+
throw new Error('Artifact file upload conflict; retry the push');
|
|
111
|
+
if (result.status === 'created') {
|
|
112
|
+
uploadedBytes += data.size;
|
|
113
|
+
uploadedFiles++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
failure = error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
if (failure)
|
|
122
|
+
throw failure;
|
|
123
|
+
await put(siteManifestKey(site.hash), site.json);
|
|
124
|
+
return { uploadedBytes, uploadedFiles };
|
|
125
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const SITE_PREFIX = "<!--DREAMLAKE-ARTIFACT-FILES/1-->\n<script type=\"application/json\" id=\"dreamlake-artifact-files\">";
|
|
2
|
+
export declare const SITE_SUFFIX = "</script>\n<p>This artifact requires a viewer with static-site support.</p>";
|
|
3
|
+
export declare const SITE_MAX_FILES = 4096;
|
|
4
|
+
export declare const SITE_MANIFEST_MAX_BYTES: number;
|
|
5
|
+
export interface SiteFile {
|
|
6
|
+
path: string;
|
|
7
|
+
sha256: string;
|
|
8
|
+
size: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SiteManifest {
|
|
11
|
+
schema: 'dreamlake-artifact-files/1';
|
|
12
|
+
entry: string;
|
|
13
|
+
spa: boolean;
|
|
14
|
+
files: SiteFile[];
|
|
15
|
+
}
|
|
16
|
+
export interface SiteDescriptor {
|
|
17
|
+
manifest: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const isHash: (s: unknown) => s is string;
|
|
20
|
+
export declare function validSitePath(s: unknown): s is string;
|
|
21
|
+
export declare function validateSiteManifest(value: unknown): SiteManifest;
|
|
22
|
+
export declare function encodeSiteDescriptor(manifest: string): string;
|
|
23
|
+
export declare function decodeSiteDescriptor(content: string): SiteDescriptor | null;
|
|
24
|
+
export declare const siteManifestKey: (hash: string) => string;
|
|
25
|
+
export declare const siteFileKey: (hash: string) => string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Wire contract shared with dreamlake-server/src/services/artifactSiteFormat.ts
|
|
2
|
+
// and dreamlake-ai/frame/siteFormat.ts. Never change v1 in place.
|
|
3
|
+
export const SITE_PREFIX = '<!--DREAMLAKE-ARTIFACT-FILES/1-->\n<script type="application/json" id="dreamlake-artifact-files">';
|
|
4
|
+
export const SITE_SUFFIX = '</script>\n<p>This artifact requires a viewer with static-site support.</p>';
|
|
5
|
+
export const SITE_MAX_FILES = 4096;
|
|
6
|
+
export const SITE_MANIFEST_MAX_BYTES = 2 * 1024 * 1024;
|
|
7
|
+
export const isHash = (s) => typeof s === 'string' && /^[a-f0-9]{64}$/.test(s);
|
|
8
|
+
export function validSitePath(s) {
|
|
9
|
+
return typeof s === 'string' && s.length > 0 && s.length <= 512 && s === s.normalize('NFC') &&
|
|
10
|
+
!/[\\%?#:\u0000-\u0020\u007f]/.test(s) &&
|
|
11
|
+
!s.startsWith('_dreamlake/') && s !== '_dreamlake' &&
|
|
12
|
+
s.split('/').every(p => !!p && !p.startsWith('.'));
|
|
13
|
+
}
|
|
14
|
+
export function validateSiteManifest(value) {
|
|
15
|
+
const m = value;
|
|
16
|
+
if (!m || m.schema !== 'dreamlake-artifact-files/1' || !validSitePath(m.entry) ||
|
|
17
|
+
!/\.html?$/i.test(m.entry) || typeof m.spa !== 'boolean' || !Array.isArray(m.files) ||
|
|
18
|
+
!m.files.length || m.files.length > SITE_MAX_FILES)
|
|
19
|
+
throw new Error('Invalid artifact site manifest');
|
|
20
|
+
const paths = new Set();
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (const f of m.files) {
|
|
23
|
+
if (!f || !validSitePath(f.path) || !isHash(f.sha256) || !Number.isSafeInteger(f.size) || f.size < 0 ||
|
|
24
|
+
paths.has(f.path.toLowerCase()))
|
|
25
|
+
throw new Error('Invalid or duplicate artifact file');
|
|
26
|
+
paths.add(f.path.toLowerCase());
|
|
27
|
+
total += f.size;
|
|
28
|
+
if (!Number.isSafeInteger(total))
|
|
29
|
+
throw new Error('Artifact site size exceeds safe integer accounting');
|
|
30
|
+
if (/\.html?$/i.test(f.path) && f.size > 32 * 1024 * 1024)
|
|
31
|
+
throw new Error('A site HTML page exceeds 32 MiB; move large assets into separate files');
|
|
32
|
+
}
|
|
33
|
+
if (!m.files.some(f => f.path === m.entry))
|
|
34
|
+
throw new Error('Artifact entry page is missing');
|
|
35
|
+
return m;
|
|
36
|
+
}
|
|
37
|
+
export function encodeSiteDescriptor(manifest) {
|
|
38
|
+
if (!isHash(manifest))
|
|
39
|
+
throw new Error('Invalid artifact manifest hash');
|
|
40
|
+
return SITE_PREFIX + JSON.stringify({ manifest }) + SITE_SUFFIX;
|
|
41
|
+
}
|
|
42
|
+
export function decodeSiteDescriptor(content) {
|
|
43
|
+
if (!content.startsWith('<!--DREAMLAKE-ARTIFACT-FILES/'))
|
|
44
|
+
return null;
|
|
45
|
+
if (!content.startsWith(SITE_PREFIX) || !content.endsWith(SITE_SUFFIX) || content.length > 4096)
|
|
46
|
+
throw new Error('Unsupported artifact site format');
|
|
47
|
+
const value = JSON.parse(content.slice(SITE_PREFIX.length, -SITE_SUFFIX.length));
|
|
48
|
+
if (!isHash(value?.manifest))
|
|
49
|
+
throw new Error('Invalid artifact manifest hash');
|
|
50
|
+
return { manifest: value.manifest };
|
|
51
|
+
}
|
|
52
|
+
export const siteManifestKey = (hash) => `artifact-files/v1/manifests/${hash}.json`;
|
|
53
|
+
export const siteFileKey = (hash) => `artifact-files/v1/objects/${hash}`;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export declare const S3_SINGLE_PUT_MAX_BYTES: number;
|
|
2
|
+
export interface UploadFile {
|
|
3
|
+
path: string;
|
|
4
|
+
size: number;
|
|
5
|
+
sha256: string;
|
|
6
|
+
mtimeMs: number;
|
|
7
|
+
ctimeMs: number;
|
|
8
|
+
dev: number;
|
|
9
|
+
ino: number;
|
|
10
|
+
}
|
|
1
11
|
/** Result of a conditional PUT, as DreamDB's connector expects it. */
|
|
2
12
|
export type PutStatus = "created" | "exists" | "casFailed";
|
|
3
13
|
/**
|
|
@@ -25,6 +35,12 @@ export interface DreamdbBackend {
|
|
|
25
35
|
status: PutStatus;
|
|
26
36
|
etag?: string;
|
|
27
37
|
}>;
|
|
38
|
+
putFile?(key: string, file: UploadFile, opts?: {
|
|
39
|
+
ifNoneMatchStar?: boolean;
|
|
40
|
+
}): Promise<{
|
|
41
|
+
status: PutStatus;
|
|
42
|
+
etag?: string;
|
|
43
|
+
}>;
|
|
28
44
|
list(prefix: string): Promise<string[]>;
|
|
29
45
|
}
|
|
30
46
|
export interface S3Credentials {
|
|
@@ -68,6 +84,16 @@ export declare class S3Backend {
|
|
|
68
84
|
status: PutStatus;
|
|
69
85
|
etag?: string;
|
|
70
86
|
}>;
|
|
87
|
+
/** Stream a pre-hashed file, binding its expected bytes into the S3 signature/checksum. */
|
|
88
|
+
putFile(key: string, file: UploadFile, opts?: {
|
|
89
|
+
ifNoneMatchStar?: boolean;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
status: "exists" | "casFailed";
|
|
92
|
+
etag?: undefined;
|
|
93
|
+
} | {
|
|
94
|
+
status: "created";
|
|
95
|
+
etag: string | undefined;
|
|
96
|
+
}>;
|
|
71
97
|
/** Keys under `prefix`, relative to the dataset base (ListObjectsV2). */
|
|
72
98
|
list(prefix: string): Promise<string[]>;
|
|
73
99
|
}
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
// (POST .../upload-credentials) and are short-lived and prefix-scoped, so
|
|
14
14
|
// they never touch disk.
|
|
15
15
|
import { AwsClient } from "aws4fetch";
|
|
16
|
+
import { constants } from "node:fs";
|
|
17
|
+
import { open } from "node:fs/promises";
|
|
18
|
+
import { Readable } from "node:stream";
|
|
19
|
+
// S3's single PutObject ceiling; larger individual objects require multipart.
|
|
20
|
+
export const S3_SINGLE_PUT_MAX_BYTES = 5 * 1024 * 1024 * 1024;
|
|
16
21
|
/**
|
|
17
22
|
* S3 ETags come back quoted (`"abc123"`), but DreamDB hands them straight
|
|
18
23
|
* back as `ifMatch` unquoted. Comparing the two raw forms makes every
|
|
@@ -99,6 +104,46 @@ export class S3Backend {
|
|
|
99
104
|
}
|
|
100
105
|
return { status: "created", etag: unquote(res.headers.get("etag")) };
|
|
101
106
|
}
|
|
107
|
+
/** Stream a pre-hashed file, binding its expected bytes into the S3 signature/checksum. */
|
|
108
|
+
async putFile(key, file, opts = {}) {
|
|
109
|
+
if (!Number.isSafeInteger(file.size) || file.size < 0 || file.size > S3_SINGLE_PUT_MAX_BYTES ||
|
|
110
|
+
!/^[a-f0-9]{64}$/.test(file.sha256))
|
|
111
|
+
throw new Error('Invalid streaming S3 file');
|
|
112
|
+
const handle = await open(file.path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
113
|
+
let source;
|
|
114
|
+
try {
|
|
115
|
+
const stat = await handle.stat();
|
|
116
|
+
if (!stat.isFile() || stat.size !== file.size || stat.dev !== file.dev || stat.ino !== file.ino ||
|
|
117
|
+
stat.mtimeMs !== file.mtimeMs || stat.ctimeMs !== file.ctimeMs)
|
|
118
|
+
throw new Error('Site file changed after hashing; retry the push');
|
|
119
|
+
const headers = {
|
|
120
|
+
'Content-Length': String(file.size),
|
|
121
|
+
'X-Amz-Content-Sha256': file.sha256,
|
|
122
|
+
'X-Amz-Checksum-Sha256': Buffer.from(file.sha256, 'hex').toString('base64'),
|
|
123
|
+
};
|
|
124
|
+
if (opts.ifNoneMatchStar)
|
|
125
|
+
headers['If-None-Match'] = '*';
|
|
126
|
+
source = file.size ? handle.createReadStream({ autoClose: false, highWaterMark: 256 * 1024 }) : undefined;
|
|
127
|
+
const request = await this.client.sign(this.url(key), {
|
|
128
|
+
method: 'PUT', headers,
|
|
129
|
+
body: source ? Readable.toWeb(source, {
|
|
130
|
+
strategy: { highWaterMark: 256 * 1024, size: chunk => chunk.byteLength },
|
|
131
|
+
}) : new Uint8Array(),
|
|
132
|
+
duplex: 'half',
|
|
133
|
+
});
|
|
134
|
+
// A consumed stream cannot be retried by aws4fetch; a failed push can safely reuse completed objects.
|
|
135
|
+
const res = await fetch(request);
|
|
136
|
+
if (res.status === 412 || res.status === 409)
|
|
137
|
+
return { status: opts.ifNoneMatchStar ? 'exists' : 'casFailed' };
|
|
138
|
+
if (!res.ok)
|
|
139
|
+
throw new Error(`PUT ${key} → ${res.status} ${await res.text().catch(() => '')}`.slice(0, 300));
|
|
140
|
+
return { status: 'created', etag: unquote(res.headers.get('etag')) };
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
source?.destroy();
|
|
144
|
+
await handle.close();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
102
147
|
/** Keys under `prefix`, relative to the dataset base (ListObjectsV2). */
|
|
103
148
|
async list(prefix) {
|
|
104
149
|
// The bucket root is one level above the dataset prefix in a path-style
|
|
@@ -4,7 +4,7 @@ export const helpExamples = {
|
|
|
4
4
|
"agents show": "dreamlake agents show my_repo.tri --namespace my-workspace",
|
|
5
5
|
"agents edit": "dreamlake agents edit my_repo.tri --namespace my-workspace\n# Browser form: follow the localhost URL printed by the command.\ndreamlake agents edit my_repo.tri --namespace my-workspace --web",
|
|
6
6
|
"telemetry": "dreamlake telemetry disable --quiet\ndreamlake telemetry status\ndreamlake telemetry enable --quiet",
|
|
7
|
-
"artifact push": "dreamlake artifact push ./dashboard.html --id q1-dashboard\n# Edit the file, then repeat the same command to upload only new chunks.\n\n# Compatibility with older self-hosted viewers:\ndreamlake artifact push ./dashboard.html --id q1-dashboard --full\n\n# Multiple self-contained HTML pages (requires an updated viewer):\ndreamlake artifact push ./report --entry index.html --id quarterly-report",
|
|
7
|
+
"artifact push": "dreamlake artifact push ./dashboard.html --id q1-dashboard\n# Edit the file, then repeat the same command to upload only new chunks.\n\n# Static build with on-demand assets (CLI 0.101.0+; requires site hosting):\ndreamlake artifact push ./dist/client --site --id simulation\n\n# Compatibility with older self-hosted viewers:\ndreamlake artifact push ./dashboard.html --id q1-dashboard --full\n\n# Multiple self-contained HTML pages (requires an updated viewer):\ndreamlake artifact push ./report --entry index.html --id quarterly-report",
|
|
8
8
|
"artifact meta set": "# At push time:\ndreamlake artifact push ./report.html --id q1-dashboard \\\n --description \"Revenue, churn and pipeline for the quarter\" \\\n --cover ./cover.png\n\n# Or after the fact, for an artifact that already exists:\ndreamlake artifact meta set q1-dashboard --description \"Revenue, churn and pipeline\"\ndreamlake artifact meta set q1-dashboard --cover ./cover.png\ndreamlake artifact meta show q1-dashboard\n\n# Back to the automatic description / the generated cover:\ndreamlake artifact meta set q1-dashboard --clear-description --clear-cover",
|
|
9
9
|
"artifact share": "# Find the dashboard you already uploaded; no new version is needed.\ndreamlake artifact list\nARTIFACT=\"q1-dashboard\" # Replace with the id from list.\ndreamlake artifact share get \"$ARTIFACT\"\n\n# Give signed-in recipients read access, then verify the returned link.\ndreamlake artifact share create \"$ARTIFACT\"\ndreamlake artifact share get \"$ARTIFACT\"\n\n# When link access is no longer needed, revoke it and verify.\ndreamlake artifact share revoke \"$ARTIFACT\"\ndreamlake artifact share get \"$ARTIFACT\"",
|
|
10
10
|
"artifact visibility": "ARTIFACT=\"q1-dashboard\" # Your existing artifact id.\ndreamlake artifact visibility \"$ARTIFACT\" public\ndreamlake artifact visibility \"$ARTIFACT\" private",
|
|
@@ -53,6 +53,7 @@ export const helpExamples = {
|
|
|
53
53
|
"hosts exec": "dreamlake hosts exec geyang/dev/worker -- python3 -c 'print(\"hello\")'",
|
|
54
54
|
"hosts upgrade": "dreamlake hosts upgrade geyang/dev/worker --nymph-version 0.1.32 --dry-run\ndreamlake hosts upgrade geyang/dev/worker --nymph-version 0.1.32\ndreamlake hosts upgrade 'geyang/lab/*' --nymph-version 0.1.32 --concurrency 4 --max-failures 2\ndreamlake hosts upgrade --all --namespace geyang --nymph-version 0.1.32 --json",
|
|
55
55
|
"hosts rollback": "dreamlake hosts rollback geyang/dev/worker\ndreamlake hosts rollback geyang/dev/worker --upgrade-id 20261029-001 --json",
|
|
56
|
+
"hosts move": "dreamlake hosts move HOST_ID --namespace alice --to acme --dry-run --json",
|
|
56
57
|
"infra list": "dreamlake infra list --namespace fortyfive --project dreamlake-infra --json",
|
|
57
58
|
"infra status": "dreamlake infra status da8e49cf-1b37-446f-9494-9620faf3192d --json",
|
|
58
59
|
"infra connect": "dreamlake infra connect da8e49cf-1b37-446f-9494-9620faf3192d",
|
package/dist/cli/hosts/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveRemote, resolveToken } from "../config.js";
|
|
2
2
|
const SAFE_POWER_CODES = new Set([
|
|
3
|
+
"host_move_blocked", "move_preview_conflict", "catalog_revision_conflict", "move_conflict", "move_busy", "enrollment_moved", "connection_access_denied",
|
|
3
4
|
"host_power_unsupported", "provider_binding_ambiguous", "enrollment_not_provider_bound",
|
|
4
5
|
"provider_binding_revoked", "enrollment_revoked", "active_work_present", "request_id_conflict",
|
|
5
6
|
"invalid_power_request", "invalid_request_id", "volume_disposition_required", "host_lifecycle_unavailable",
|
package/dist/cli/hosts/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerHostMoveCommand } from './move.js';
|
|
1
2
|
import { collectionList } from "../collection-list.js";
|
|
2
3
|
import { inspectHostCatalog, changeHostCatalog, formatHostCatalog } from "./catalog.js";
|
|
3
4
|
import { registerHostLifecycleCommands } from "./lifecycle.js";
|
|
@@ -276,6 +277,7 @@ export function registerHostsCommand(program) {
|
|
|
276
277
|
}
|
|
277
278
|
});
|
|
278
279
|
registerHostSshCommands(group, program);
|
|
280
|
+
registerHostMoveCommand(group);
|
|
279
281
|
registerHostLifecycleCommands(group);
|
|
280
282
|
registerHostUpgradeCommands(group);
|
|
281
283
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { hostRequest } from './api.js';
|
|
3
|
+
export interface HostMovePreview {
|
|
4
|
+
apiVersion: 1;
|
|
5
|
+
hostId: string;
|
|
6
|
+
sourceNamespaceId: string;
|
|
7
|
+
destinationNamespaceId: string;
|
|
8
|
+
destinationNamespace: string;
|
|
9
|
+
name: string;
|
|
10
|
+
ownerUserId: string;
|
|
11
|
+
visibility: 'private';
|
|
12
|
+
revision: number;
|
|
13
|
+
previewHash: string;
|
|
14
|
+
blockers: string[];
|
|
15
|
+
executable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface HostMoveReceipt extends Omit<HostMovePreview, 'previewHash' | 'blockers' | 'executable'> {
|
|
18
|
+
operationId: string;
|
|
19
|
+
requestId: string;
|
|
20
|
+
recordedAt: string;
|
|
21
|
+
replayed: boolean;
|
|
22
|
+
}
|
|
23
|
+
type Options = {
|
|
24
|
+
namespace?: string;
|
|
25
|
+
to: string;
|
|
26
|
+
dryRun?: boolean;
|
|
27
|
+
confirm?: boolean;
|
|
28
|
+
requestId?: string;
|
|
29
|
+
expectedRevision?: string;
|
|
30
|
+
previewHash?: string;
|
|
31
|
+
json?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export declare function previewHostMove(hostId: string, opts: Pick<Options, 'namespace' | 'to'>, request?: typeof hostRequest): Promise<HostMovePreview>;
|
|
34
|
+
export declare function applyHostMove(hostId: string, opts: Pick<Options, 'namespace' | 'to' | 'requestId' | 'expectedRevision' | 'previewHash'>, request?: typeof hostRequest): Promise<HostMoveReceipt>;
|
|
35
|
+
export declare function registerHostMoveCommand(group: Command): void;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { hostApiPath, hostRequest } from './api.js';
|
|
2
|
+
import { resolveHostNamespace } from './inventory.js';
|
|
3
|
+
function input(hostId, to) {
|
|
4
|
+
if (!/^[a-f0-9]{24}$/.test(hostId) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(to))
|
|
5
|
+
throw new Error('Use one exact lowercase Host ID and a destination namespace slug');
|
|
6
|
+
}
|
|
7
|
+
function common(value, hostId, to) {
|
|
8
|
+
if (!value || value.apiVersion !== 1 || value.hostId !== hostId || value.destinationNamespace !== to ||
|
|
9
|
+
typeof value.sourceNamespaceId !== 'string' || !value.sourceNamespaceId || typeof value.destinationNamespaceId !== 'string' || !value.destinationNamespaceId ||
|
|
10
|
+
value.sourceNamespaceId === value.destinationNamespaceId || typeof value.name !== 'string' || !value.name.startsWith(`${to}/`) ||
|
|
11
|
+
typeof value.ownerUserId !== 'string' || !value.ownerUserId || value.visibility !== 'private' || !Number.isSafeInteger(value.revision) || value.revision < 0 || value.revision > 2147483647)
|
|
12
|
+
throw new Error('Host API returned an invalid private move response');
|
|
13
|
+
}
|
|
14
|
+
export async function previewHostMove(hostId, opts, request = hostRequest) {
|
|
15
|
+
input(hostId, opts.to);
|
|
16
|
+
const namespace = await resolveHostNamespace(opts.namespace);
|
|
17
|
+
const result = await request(`${hostApiPath(namespace)}/${hostId}/move/preview`, 'POST', { destinationNamespace: opts.to });
|
|
18
|
+
common(result, hostId, opts.to);
|
|
19
|
+
if (typeof result.previewHash !== 'string' || !/^[a-f0-9]{64}$/.test(result.previewHash) || !Array.isArray(result.blockers) ||
|
|
20
|
+
result.blockers.some((b) => typeof b !== 'string' || !/^[a-z_]+$/.test(b)) || result.executable !== (result.blockers.length === 0))
|
|
21
|
+
throw new Error('Host API returned an invalid move preview');
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
export async function applyHostMove(hostId, opts, request = hostRequest) {
|
|
25
|
+
input(hostId, opts.to);
|
|
26
|
+
if (typeof opts.requestId !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(opts.requestId) ||
|
|
27
|
+
typeof opts.expectedRevision !== 'string' || !/^(0|[1-9][0-9]*)$/.test(opts.expectedRevision) || Number(opts.expectedRevision) >= 2147483647 ||
|
|
28
|
+
typeof opts.previewHash !== 'string' || !/^[a-f0-9]{64}$/.test(opts.previewHash))
|
|
29
|
+
throw new Error('Apply requires the reviewed --preview-hash, --expected-revision, and a stable --request-id');
|
|
30
|
+
const namespace = await resolveHostNamespace(opts.namespace);
|
|
31
|
+
// Submit exactly once. After uncertainty retry these exact inputs, never refresh the plan implicitly.
|
|
32
|
+
const result = await request(`${hostApiPath(namespace)}/${hostId}/move`, 'POST', { destinationNamespace: opts.to,
|
|
33
|
+
requestId: opts.requestId, expectedRevision: Number(opts.expectedRevision), previewHash: opts.previewHash });
|
|
34
|
+
common(result, hostId, opts.to);
|
|
35
|
+
if (result.requestId !== opts.requestId || typeof result.operationId !== 'string' || !/^[a-f0-9]{64}$/.test(result.operationId) ||
|
|
36
|
+
result.revision !== Number(opts.expectedRevision) + 1 || typeof result.replayed !== 'boolean' ||
|
|
37
|
+
typeof result.recordedAt !== 'string' || !Number.isFinite(Date.parse(result.recordedAt)))
|
|
38
|
+
throw new Error('Host API returned an invalid move receipt');
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
export function registerHostMoveCommand(group) {
|
|
42
|
+
group.command('move').description('preview or apply an owner-private Host namespace move without re-enrolling')
|
|
43
|
+
.argument('<host-id>', 'exact lowercase Host ID').requiredOption('--to <namespace>', 'destination namespace slug')
|
|
44
|
+
.option('--namespace <namespace>', 'source namespace slug').option('--dry-run', 'read a server preview; do not move')
|
|
45
|
+
.option('--confirm', 'apply the exact reviewed preview').option('--request-id <id>', 'stable mutation request ID')
|
|
46
|
+
.option('--expected-revision <revision>', 'revision from the reviewed preview').option('--preview-hash <hash>', 'hash from the reviewed preview')
|
|
47
|
+
.option('--json', 'emit structured preview or receipt').action(async (hostId, opts) => {
|
|
48
|
+
try {
|
|
49
|
+
if (Boolean(opts.dryRun) === Boolean(opts.confirm))
|
|
50
|
+
throw new Error('Choose --dry-run to review or --confirm with the exact reviewed inputs');
|
|
51
|
+
if (opts.dryRun && (opts.requestId !== undefined || opts.expectedRevision !== undefined || opts.previewHash !== undefined))
|
|
52
|
+
throw new Error('Mutation inputs belong with --confirm');
|
|
53
|
+
const result = opts.dryRun ? await previewHostMove(hostId, opts) : await applyHostMove(hostId, opts);
|
|
54
|
+
if (opts.json)
|
|
55
|
+
console.log(JSON.stringify(result, null, 2));
|
|
56
|
+
else
|
|
57
|
+
console.log([`Host: ${result.name}`, 'Access: Private — only you', `Revision: ${result.revision}`,
|
|
58
|
+
...('previewHash' in result ? [`Preview hash: ${result.previewHash}`, result.executable ? 'Ready to move. Apply with --confirm and these reviewed inputs.' : `Blocked: ${result.blockers.join(', ')}`]
|
|
59
|
+
: [`Operation ID: ${result.operationId}`, `Request ID: ${result.requestId}`, result.replayed ? 'Stored original receipt; inspect the host for its current location.' : 'Move committed.'])].join('\n'));
|
|
60
|
+
if ('executable' in result && !result.executable)
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const message = error instanceof Error ? error.message : 'Host move failed';
|
|
65
|
+
if (opts.json)
|
|
66
|
+
console.log(JSON.stringify({ status: 'error', error: message }));
|
|
67
|
+
else
|
|
68
|
+
console.error(message);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
package/dist/cli/hosts/ssh.js
CHANGED
|
@@ -132,7 +132,8 @@ export class SshRelay extends Duplex {
|
|
|
132
132
|
this.push(null);
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
// The stream retains payload only; already-decoded frames may follow pause.
|
|
136
|
+
if (b[0] !== 0 || b.length < 2 || this.readableLength + b.length - 1 > 262144)
|
|
136
137
|
return this.destroy(new Error('Invalid SSH relay frame'));
|
|
137
138
|
if (!this.push(b.subarray(1)))
|
|
138
139
|
ws.pause();
|
package/dist/cli/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.101.0";
|
package/dist/cli/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamlake/dreamlake-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"node": ">=18"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@dreamlake/dreamlake-cli-darwin-arm64": "0.
|
|
39
|
-
"@dreamlake/dreamlake-cli-darwin-x64": "0.
|
|
40
|
-
"@dreamlake/dreamlake-cli-linux-x64": "0.
|
|
41
|
-
"@dreamlake/dreamlake-cli-linux-arm64": "0.
|
|
42
|
-
"@dreamlake/dreamlake-cli-linux-x64-musl": "0.
|
|
43
|
-
"@dreamlake/dreamlake-cli-linux-arm64-musl": "0.
|
|
44
|
-
"@dreamlake/dreamlake-cli-win32-x64": "0.
|
|
45
|
-
"@dreamlake/dreamlake-cli-win32-arm64": "0.
|
|
38
|
+
"@dreamlake/dreamlake-cli-darwin-arm64": "0.101.0",
|
|
39
|
+
"@dreamlake/dreamlake-cli-darwin-x64": "0.101.0",
|
|
40
|
+
"@dreamlake/dreamlake-cli-linux-x64": "0.101.0",
|
|
41
|
+
"@dreamlake/dreamlake-cli-linux-arm64": "0.101.0",
|
|
42
|
+
"@dreamlake/dreamlake-cli-linux-x64-musl": "0.101.0",
|
|
43
|
+
"@dreamlake/dreamlake-cli-linux-arm64-musl": "0.101.0",
|
|
44
|
+
"@dreamlake/dreamlake-cli-win32-x64": "0.101.0",
|
|
45
|
+
"@dreamlake/dreamlake-cli-win32-arm64": "0.101.0"
|
|
46
46
|
}
|
|
47
47
|
}
|