@dreamlake/dreamlake-cli 0.118.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 +3 -3
- package/dist/api/file-multipart.js +29 -6
- 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 +16 -1
- package/dist/api/index.js +8 -2
- package/dist/api/native-experiments.js +2 -3
- 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/help-examples.generated.js +5 -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
package/dist/api/agent.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Transport } from "./client.js";
|
|
|
4
4
|
import type { PageContentSnapshot } from "./browser.js";
|
|
5
5
|
export type { PageContentSnapshot } from "./browser.js";
|
|
6
6
|
export type TurnCapabilities = {
|
|
7
|
+
personalExtensions?: 1;
|
|
7
8
|
layoutActions?: 1;
|
|
8
9
|
sessionControl?: 1;
|
|
9
10
|
notesWrite?: 1;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface FileMultipart {
|
|
2
|
-
body:
|
|
2
|
+
body: ReadableStream<Uint8Array>;
|
|
3
3
|
contentType: string;
|
|
4
4
|
}
|
|
5
|
-
/**
|
|
6
|
-
export declare function fileMultipart(fields: Record<string, string>, file: Blob, filename: string): FileMultipart;
|
|
5
|
+
/** Preserve filenames and stream file-backed Blobs directly (Bun drops them inside composite Blobs). */
|
|
6
|
+
export declare function fileMultipart(fields: Record<string, string>, file: Blob, filename: string, contentType?: string): FileMultipart;
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
/**
|
|
3
|
-
export function fileMultipart(fields, file, filename) {
|
|
2
|
+
/** Preserve filenames and stream file-backed Blobs directly (Bun drops them inside composite Blobs). */
|
|
3
|
+
export function fileMultipart(fields, file, filename, contentType = file.type || 'application/octet-stream') {
|
|
4
4
|
const boundary = `dreamlake-${randomUUID()}`;
|
|
5
|
-
|
|
5
|
+
let head = '';
|
|
6
6
|
for (const [name, value] of Object.entries(fields))
|
|
7
|
-
|
|
7
|
+
head += `--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`;
|
|
8
8
|
const encoded = encodeURIComponent(filename).replace(/['()*]/g, c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
head += `--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="file"; filename*=UTF-8''${encoded}\r\nContent-Type: ${contentType}\r\n\r\n`;
|
|
10
|
+
const encoder = new TextEncoder();
|
|
11
|
+
async function* chunks() {
|
|
12
|
+
yield encoder.encode(head);
|
|
13
|
+
for await (const chunk of file.stream())
|
|
14
|
+
yield chunk;
|
|
15
|
+
yield encoder.encode(`\r\n--${boundary}--\r\n`);
|
|
16
|
+
}
|
|
17
|
+
const iterator = chunks();
|
|
18
|
+
const body = new ReadableStream({
|
|
19
|
+
async pull(controller) {
|
|
20
|
+
try {
|
|
21
|
+
const next = await iterator.next();
|
|
22
|
+
if (next.done)
|
|
23
|
+
controller.close();
|
|
24
|
+
else
|
|
25
|
+
controller.enqueue(next.value);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
controller.error(error);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
async cancel() { await iterator.return(undefined); },
|
|
32
|
+
});
|
|
33
|
+
return { body, contentType: `multipart/form-data; boundary=${boundary}` };
|
|
11
34
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Transport } from "./client.js";
|
|
2
|
+
import { type FileAdapter } from "./file-workspace.js";
|
|
3
|
+
/** Managed Source workspace only. External layers are asset inputs, not writable workspace files. */
|
|
4
|
+
export declare class SourceFileAdapter implements FileAdapter {
|
|
5
|
+
readonly api: Transport;
|
|
6
|
+
readonly signal: AbortSignal;
|
|
7
|
+
readonly transport: typeof fetch;
|
|
8
|
+
readonly base: string;
|
|
9
|
+
constructor(api: Transport, namespace: string, sourceId: string, signal: AbortSignal, transport?: typeof fetch);
|
|
10
|
+
list(path: string, cursor?: string): Promise<{
|
|
11
|
+
entries: {
|
|
12
|
+
path: string;
|
|
13
|
+
kind: "file" | "directory";
|
|
14
|
+
size: number | null;
|
|
15
|
+
revision: null;
|
|
16
|
+
}[];
|
|
17
|
+
nextCursor: string | null;
|
|
18
|
+
}>;
|
|
19
|
+
private requestStorage;
|
|
20
|
+
read(path: string): Promise<{
|
|
21
|
+
path: string;
|
|
22
|
+
content: string;
|
|
23
|
+
revision: string;
|
|
24
|
+
}>;
|
|
25
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<{
|
|
26
|
+
path: string;
|
|
27
|
+
content: string;
|
|
28
|
+
revision: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { FileError, MAX_TEXT_BYTES, boundedText, canonicalPath, } from "./file-workspace.js";
|
|
3
|
+
const etag = (value) => !!value &&
|
|
4
|
+
/^"[\x21\x23-\x7e\x80-\xff]+"$/.test(value) &&
|
|
5
|
+
value.length <= 1024;
|
|
6
|
+
/** Managed Source workspace only. External layers are asset inputs, not writable workspace files. */
|
|
7
|
+
export class SourceFileAdapter {
|
|
8
|
+
api;
|
|
9
|
+
signal;
|
|
10
|
+
transport;
|
|
11
|
+
base;
|
|
12
|
+
constructor(api, namespace, sourceId, signal, transport = fetch) {
|
|
13
|
+
this.api = api;
|
|
14
|
+
this.signal = signal;
|
|
15
|
+
this.transport = transport;
|
|
16
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(namespace) ||
|
|
17
|
+
!/^[a-fA-F0-9]{24}$/.test(sourceId))
|
|
18
|
+
throw new FileError("file_endpoint_invalid");
|
|
19
|
+
this.base = `/namespaces/${encodeURIComponent(namespace)}/sources/${sourceId}`;
|
|
20
|
+
}
|
|
21
|
+
async list(path, cursor) {
|
|
22
|
+
canonicalPath(path, true);
|
|
23
|
+
const page = await this.api.request("GET", this.base + "/browse", {
|
|
24
|
+
query: { path, cursor, limit: 10 },
|
|
25
|
+
signal: this.signal,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
entries: page.entries
|
|
29
|
+
.filter((e) => e.origin.kind === "dreamlake-storage")
|
|
30
|
+
.map((e) => ({
|
|
31
|
+
path: e.path,
|
|
32
|
+
kind: e.kind,
|
|
33
|
+
size: e.size,
|
|
34
|
+
revision: null,
|
|
35
|
+
})),
|
|
36
|
+
nextCursor: page.nextCursor,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async requestStorage(url, headers = {}, body) {
|
|
40
|
+
// Only route-minted capabilities reach here; model input never supplies a URL or credential.
|
|
41
|
+
const target = new URL(url);
|
|
42
|
+
if (target.protocol !== "https:" ||
|
|
43
|
+
target.username ||
|
|
44
|
+
target.password ||
|
|
45
|
+
Object.keys(headers).some((k) => /^(authorization|cookie)$/i.test(k)))
|
|
46
|
+
throw new FileError("file_capability_invalid");
|
|
47
|
+
try {
|
|
48
|
+
return await this.transport(url, {
|
|
49
|
+
method: body === undefined ? "GET" : "PUT",
|
|
50
|
+
headers,
|
|
51
|
+
body,
|
|
52
|
+
redirect: "error",
|
|
53
|
+
signal: AbortSignal.any([this.signal, AbortSignal.timeout(30000)]),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new FileError(body === undefined ? "file_read_failed" : "file_write_unconfirmed");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async read(path) {
|
|
61
|
+
canonicalPath(path);
|
|
62
|
+
const cap = await this.api.request("POST", this.base + "/managed-read-capabilities", {
|
|
63
|
+
json: { path },
|
|
64
|
+
signal: this.signal,
|
|
65
|
+
});
|
|
66
|
+
if (cap.method !== "GET")
|
|
67
|
+
throw new FileError("file_capability_invalid");
|
|
68
|
+
const response = await this.requestStorage(cap.url, cap.allowedHeaders);
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
await response.body?.cancel();
|
|
71
|
+
throw new FileError(response.status === 404 ? "file_not_found" : "file_read_failed");
|
|
72
|
+
}
|
|
73
|
+
if (!response.body)
|
|
74
|
+
throw new FileError("file_read_failed");
|
|
75
|
+
const reader = response.body.getReader(), chunks = [];
|
|
76
|
+
let size = 0;
|
|
77
|
+
try {
|
|
78
|
+
for (;;) {
|
|
79
|
+
const item = await reader.read();
|
|
80
|
+
if (item.done)
|
|
81
|
+
break;
|
|
82
|
+
size += item.value.length;
|
|
83
|
+
if (size > MAX_TEXT_BYTES)
|
|
84
|
+
throw new FileError("file_text_too_large_or_binary");
|
|
85
|
+
chunks.push(item.value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await reader.cancel().catch(() => undefined);
|
|
90
|
+
reader.releaseLock();
|
|
91
|
+
}
|
|
92
|
+
let content;
|
|
93
|
+
try {
|
|
94
|
+
content = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
throw new FileError("file_text_too_large_or_binary");
|
|
98
|
+
}
|
|
99
|
+
boundedText(content);
|
|
100
|
+
const revision = response.headers.get("etag");
|
|
101
|
+
if (!etag(revision))
|
|
102
|
+
throw new FileError("file_revision_unavailable");
|
|
103
|
+
// Fresh route authorization after the storage read: do not return bytes after access was revoked.
|
|
104
|
+
await this.api.request("POST", this.base + "/managed-read-capabilities", {
|
|
105
|
+
json: { path },
|
|
106
|
+
signal: this.signal,
|
|
107
|
+
});
|
|
108
|
+
return { path, content, revision };
|
|
109
|
+
}
|
|
110
|
+
async write(path, content, expectedRevision) {
|
|
111
|
+
canonicalPath(path);
|
|
112
|
+
boundedText(content);
|
|
113
|
+
if (expectedRevision !== null && !etag(expectedRevision))
|
|
114
|
+
throw new FileError("file_revision_invalid");
|
|
115
|
+
const precondition = expectedRevision === null
|
|
116
|
+
? { "if-none-match": "*" }
|
|
117
|
+
: { "if-match": expectedRevision };
|
|
118
|
+
const size = Buffer.byteLength(content);
|
|
119
|
+
const plan = await this.api.request("POST", this.base + "/upload-authorizations", {
|
|
120
|
+
json: {
|
|
121
|
+
files: [
|
|
122
|
+
{
|
|
123
|
+
relativePath: path,
|
|
124
|
+
size,
|
|
125
|
+
mediaType: "text/plain; charset=utf-8",
|
|
126
|
+
...(expectedRevision === null
|
|
127
|
+
? { ifNoneMatch: "*" }
|
|
128
|
+
: { ifMatch: expectedRevision }),
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
signal: this.signal,
|
|
133
|
+
});
|
|
134
|
+
const file = plan.files?.[0];
|
|
135
|
+
if (plan.mode !== "s3-presigned-batch" ||
|
|
136
|
+
plan.files.length !== 1 ||
|
|
137
|
+
file.relativePath !== path ||
|
|
138
|
+
file.canonicalPath !== path ||
|
|
139
|
+
file.size !== size ||
|
|
140
|
+
file.transfer.kind !== "single-put")
|
|
141
|
+
throw new FileError("file_capability_invalid");
|
|
142
|
+
const put = file.transfer.put;
|
|
143
|
+
const headers = Object.fromEntries(Object.entries(put.headers).map(([k, v]) => [k.toLowerCase(), v]));
|
|
144
|
+
if (Object.entries(precondition).some(([k, v]) => headers[k] !== v) ||
|
|
145
|
+
("if-match" in headers && "if-none-match" in headers))
|
|
146
|
+
throw new FileError("file_precondition_missing");
|
|
147
|
+
const response = await this.requestStorage(put.url, put.headers, content);
|
|
148
|
+
await response.body?.cancel();
|
|
149
|
+
if (response.status === 409 || response.status === 412)
|
|
150
|
+
throw new FileError("file_revision_conflict");
|
|
151
|
+
if (!response.ok)
|
|
152
|
+
throw new FileError("file_write_unconfirmed");
|
|
153
|
+
// Read back through the managed layer; never verify against an external fallback.
|
|
154
|
+
try {
|
|
155
|
+
const result = await this.read(path);
|
|
156
|
+
if (createHash("sha256").update(result.content).digest("hex") !==
|
|
157
|
+
createHash("sha256").update(content).digest("hex"))
|
|
158
|
+
throw new FileError("file_write_unconfirmed");
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
throw new FileError("file_write_unconfirmed");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Endpoint-independent file operations. An endpoint is supplied by the host, never inferred from a prompt. */
|
|
2
|
+
export declare const MAX_TEXT_BYTES: number;
|
|
3
|
+
export declare class FileError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
constructor(code: string);
|
|
6
|
+
}
|
|
7
|
+
export interface FileEntry {
|
|
8
|
+
path: string;
|
|
9
|
+
kind: "file" | "directory";
|
|
10
|
+
size: number | null;
|
|
11
|
+
revision: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface TextFile {
|
|
14
|
+
path: string;
|
|
15
|
+
content: string;
|
|
16
|
+
revision: string;
|
|
17
|
+
}
|
|
18
|
+
export interface FileAdapter {
|
|
19
|
+
list(path: string, cursor?: string): Promise<{
|
|
20
|
+
entries: FileEntry[];
|
|
21
|
+
nextCursor: string | null;
|
|
22
|
+
}>;
|
|
23
|
+
read(path: string): Promise<TextFile>;
|
|
24
|
+
/** null means create-only. An opaque revision means compare-and-swap; never an unconditional overwrite. */
|
|
25
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<TextFile>;
|
|
26
|
+
}
|
|
27
|
+
export declare function canonicalPath(path: string, root?: boolean): string;
|
|
28
|
+
export declare function boundedText(content: string): string;
|
|
29
|
+
/** Prefix is a containment boundary, not an authority grant. Adapters must authorize every call. */
|
|
30
|
+
export declare class FileWorkspace {
|
|
31
|
+
readonly adapter: FileAdapter;
|
|
32
|
+
readonly prefix: string;
|
|
33
|
+
constructor(adapter: FileAdapter, prefix?: string);
|
|
34
|
+
private resolve;
|
|
35
|
+
private relative;
|
|
36
|
+
list(path?: string, cursor?: string): Promise<{
|
|
37
|
+
entries: {
|
|
38
|
+
path: string;
|
|
39
|
+
kind: "file" | "directory";
|
|
40
|
+
size: number | null;
|
|
41
|
+
revision: string | null;
|
|
42
|
+
}[];
|
|
43
|
+
nextCursor: string | null;
|
|
44
|
+
}>;
|
|
45
|
+
read(path: string): Promise<{
|
|
46
|
+
path: string;
|
|
47
|
+
content: string;
|
|
48
|
+
revision: string;
|
|
49
|
+
}>;
|
|
50
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<{
|
|
51
|
+
path: string;
|
|
52
|
+
content: string;
|
|
53
|
+
revision: string;
|
|
54
|
+
}>;
|
|
55
|
+
replace(path: string, oldText: string, newText: string, expectedRevision: string): Promise<{
|
|
56
|
+
path: string;
|
|
57
|
+
content: string;
|
|
58
|
+
revision: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/** Browser-session cache adapter. Each instance is isolated; no durable persistence is claimed. */
|
|
62
|
+
export declare class MemoryFileAdapter implements FileAdapter {
|
|
63
|
+
private files;
|
|
64
|
+
private revision;
|
|
65
|
+
list(path: string, cursor?: string): Promise<{
|
|
66
|
+
entries: FileEntry[];
|
|
67
|
+
nextCursor: null;
|
|
68
|
+
}>;
|
|
69
|
+
read(path: string): Promise<{
|
|
70
|
+
path: string;
|
|
71
|
+
content: string;
|
|
72
|
+
revision: string;
|
|
73
|
+
}>;
|
|
74
|
+
write(path: string, content: string, expectedRevision: string | null): Promise<{
|
|
75
|
+
path: string;
|
|
76
|
+
content: string;
|
|
77
|
+
revision: string;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Endpoint-independent file operations. An endpoint is supplied by the host, never inferred from a prompt. */
|
|
2
|
+
export const MAX_TEXT_BYTES = 256 * 1024;
|
|
3
|
+
export class FileError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(code);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function canonicalPath(path, root = false) {
|
|
11
|
+
if (typeof path !== "string" ||
|
|
12
|
+
(!root && !path) ||
|
|
13
|
+
path.startsWith("/") ||
|
|
14
|
+
path.endsWith("/") ||
|
|
15
|
+
/[\\\u0000-\u001f\u007f-\u009f]/.test(path) ||
|
|
16
|
+
new TextEncoder().encode(path).length > 1024 ||
|
|
17
|
+
path
|
|
18
|
+
.split("/")
|
|
19
|
+
.some((s) => (!s && !!path) ||
|
|
20
|
+
s === "." ||
|
|
21
|
+
s === ".." ||
|
|
22
|
+
new TextEncoder().encode(s).length > 255))
|
|
23
|
+
throw new FileError("file_path_invalid");
|
|
24
|
+
return path;
|
|
25
|
+
}
|
|
26
|
+
export function boundedText(content) {
|
|
27
|
+
if (typeof content !== "string" ||
|
|
28
|
+
content.includes("\0") ||
|
|
29
|
+
new TextEncoder().encode(content).length > MAX_TEXT_BYTES)
|
|
30
|
+
throw new FileError("file_text_too_large_or_binary");
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
/** Prefix is a containment boundary, not an authority grant. Adapters must authorize every call. */
|
|
34
|
+
export class FileWorkspace {
|
|
35
|
+
adapter;
|
|
36
|
+
prefix;
|
|
37
|
+
constructor(adapter, prefix = "") {
|
|
38
|
+
this.adapter = adapter;
|
|
39
|
+
this.prefix = prefix;
|
|
40
|
+
canonicalPath(prefix, true);
|
|
41
|
+
}
|
|
42
|
+
resolve(path, root = false) {
|
|
43
|
+
canonicalPath(path, root);
|
|
44
|
+
return this.prefix ? this.prefix + (path ? "/" + path : "") : path;
|
|
45
|
+
}
|
|
46
|
+
relative(path) {
|
|
47
|
+
canonicalPath(path, true);
|
|
48
|
+
if (!this.prefix)
|
|
49
|
+
return path;
|
|
50
|
+
if (path === this.prefix)
|
|
51
|
+
return "";
|
|
52
|
+
if (!path.startsWith(this.prefix + "/"))
|
|
53
|
+
throw new FileError("file_endpoint_outside_prefix");
|
|
54
|
+
return path.slice(this.prefix.length + 1);
|
|
55
|
+
}
|
|
56
|
+
async list(path = "", cursor) {
|
|
57
|
+
const result = await this.adapter.list(this.resolve(path, true), cursor);
|
|
58
|
+
return {
|
|
59
|
+
entries: result.entries.map((e) => ({
|
|
60
|
+
...e,
|
|
61
|
+
path: this.relative(e.path),
|
|
62
|
+
})),
|
|
63
|
+
nextCursor: result.nextCursor,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async read(path) {
|
|
67
|
+
const result = await this.adapter.read(this.resolve(path));
|
|
68
|
+
if (this.relative(result.path) !== path)
|
|
69
|
+
throw new FileError("file_endpoint_path_mismatch");
|
|
70
|
+
boundedText(result.content);
|
|
71
|
+
return { ...result, path };
|
|
72
|
+
}
|
|
73
|
+
async write(path, content, expectedRevision) {
|
|
74
|
+
boundedText(content);
|
|
75
|
+
if (expectedRevision !== null &&
|
|
76
|
+
(typeof expectedRevision !== "string" || !expectedRevision))
|
|
77
|
+
throw new FileError("file_revision_required");
|
|
78
|
+
const result = await this.adapter.write(this.resolve(path), content, expectedRevision);
|
|
79
|
+
if (this.relative(result.path) !== path)
|
|
80
|
+
throw new FileError("file_endpoint_path_mismatch");
|
|
81
|
+
return { ...result, path };
|
|
82
|
+
}
|
|
83
|
+
async replace(path, oldText, newText, expectedRevision) {
|
|
84
|
+
if (!oldText)
|
|
85
|
+
throw new FileError("file_replace_empty_match");
|
|
86
|
+
const file = await this.read(path);
|
|
87
|
+
if (file.revision !== expectedRevision)
|
|
88
|
+
throw new FileError("file_revision_conflict");
|
|
89
|
+
const at = file.content.indexOf(oldText);
|
|
90
|
+
if (at < 0 || file.content.indexOf(oldText, at + 1) >= 0)
|
|
91
|
+
throw new FileError("file_replace_match_not_unique");
|
|
92
|
+
return this.write(path, file.content.slice(0, at) +
|
|
93
|
+
newText +
|
|
94
|
+
file.content.slice(at + oldText.length), expectedRevision);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Browser-session cache adapter. Each instance is isolated; no durable persistence is claimed. */
|
|
98
|
+
export class MemoryFileAdapter {
|
|
99
|
+
files = new Map();
|
|
100
|
+
revision = 0;
|
|
101
|
+
async list(path, cursor) {
|
|
102
|
+
canonicalPath(path, true);
|
|
103
|
+
if (cursor)
|
|
104
|
+
throw new FileError("file_cursor_invalid");
|
|
105
|
+
const prefix = path ? path + "/" : "", entries = new Map();
|
|
106
|
+
for (const [key, value] of this.files)
|
|
107
|
+
if (key.startsWith(prefix)) {
|
|
108
|
+
const tail = key.slice(prefix.length), child = prefix + tail.split("/")[0];
|
|
109
|
+
entries.set(child, tail.includes("/")
|
|
110
|
+
? { path: child, kind: "directory", size: null, revision: null }
|
|
111
|
+
: {
|
|
112
|
+
path: key,
|
|
113
|
+
kind: "file",
|
|
114
|
+
size: new TextEncoder().encode(value.content).length,
|
|
115
|
+
revision: value.revision,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
entries: [...entries.values()].sort((a, b) => a.path.localeCompare(b.path)),
|
|
120
|
+
nextCursor: null,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async read(path) {
|
|
124
|
+
canonicalPath(path);
|
|
125
|
+
const file = this.files.get(path);
|
|
126
|
+
if (!file)
|
|
127
|
+
throw new FileError("file_not_found");
|
|
128
|
+
return { ...file };
|
|
129
|
+
}
|
|
130
|
+
async write(path, content, expectedRevision) {
|
|
131
|
+
canonicalPath(path);
|
|
132
|
+
boundedText(content);
|
|
133
|
+
if ((this.files.get(path)?.revision ?? null) !== expectedRevision)
|
|
134
|
+
throw new FileError("file_revision_conflict");
|
|
135
|
+
for (const key of this.files.keys())
|
|
136
|
+
if (key.startsWith(path + "/") || path.startsWith(key + "/"))
|
|
137
|
+
throw new FileError("file_directory_conflict");
|
|
138
|
+
const file = { path, content, revision: `memory:${++this.revision}` };
|
|
139
|
+
this.files.set(path, file);
|
|
140
|
+
return { ...file };
|
|
141
|
+
}
|
|
142
|
+
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { FileWorkspace } from "./file-workspace.js";
|
|
2
|
+
export * from "./file-workspace.js";
|
|
3
|
+
export * from "./file-source.js";
|
|
1
4
|
export * from './apps.js';
|
|
2
5
|
export * from './lakeshore-connections.js';
|
|
3
6
|
export * from "./open-resources.js";
|
|
@@ -31,7 +34,7 @@ export * from "./memos.js";
|
|
|
31
34
|
export * from "./agent.js";
|
|
32
35
|
export * from "./skills.js";
|
|
33
36
|
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
34
|
-
export declare function createApi(transport: Transport): {
|
|
37
|
+
export declare function createApi(transport: Transport, storageFetch?: typeof fetch): {
|
|
35
38
|
transport: Transport;
|
|
36
39
|
apps: (namespace: string) => {
|
|
37
40
|
list: () => Promise<import("./apps.js").AppCatalog>;
|
|
@@ -1111,6 +1114,12 @@ export declare function createApi(transport: Transport): {
|
|
|
1111
1114
|
filesPresign: (name: string, paths: string[], ttlSeconds?: number) => Promise<unknown>;
|
|
1112
1115
|
register: (name: string, input: import("./common.js").JsonObject) => Promise<unknown>;
|
|
1113
1116
|
};
|
|
1117
|
+
files: (endpoint: {
|
|
1118
|
+
kind: "source";
|
|
1119
|
+
namespace: string;
|
|
1120
|
+
sourceId: string;
|
|
1121
|
+
prefix: string;
|
|
1122
|
+
}, signal?: AbortSignal) => FileWorkspace;
|
|
1114
1123
|
sources: (namespace: string) => {
|
|
1115
1124
|
list: (query?: {
|
|
1116
1125
|
cursor?: string;
|
|
@@ -2432,6 +2441,12 @@ export declare function createClient(options: ClientOptions): {
|
|
|
2432
2441
|
filesPresign: (name: string, paths: string[], ttlSeconds?: number) => Promise<unknown>;
|
|
2433
2442
|
register: (name: string, input: import("./common.js").JsonObject) => Promise<unknown>;
|
|
2434
2443
|
};
|
|
2444
|
+
files: (endpoint: {
|
|
2445
|
+
kind: "source";
|
|
2446
|
+
namespace: string;
|
|
2447
|
+
sourceId: string;
|
|
2448
|
+
prefix: string;
|
|
2449
|
+
}, signal?: AbortSignal) => FileWorkspace;
|
|
2435
2450
|
sources: (namespace: string) => {
|
|
2436
2451
|
list: (query?: {
|
|
2437
2452
|
cursor?: string;
|
package/dist/api/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { FileWorkspace } from "./file-workspace.js";
|
|
2
|
+
import { SourceFileAdapter } from "./file-source.js";
|
|
3
|
+
export * from "./file-workspace.js";
|
|
4
|
+
export * from "./file-source.js";
|
|
1
5
|
import { appsApi } from './apps.js';
|
|
2
6
|
export * from './apps.js';
|
|
3
7
|
import { lakeshoreConnectionsApi } from './lakeshore-connections.js';
|
|
@@ -61,7 +65,7 @@ export * from "./memos.js";
|
|
|
61
65
|
export * from "./agent.js";
|
|
62
66
|
export * from "./skills.js";
|
|
63
67
|
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
64
|
-
export function createApi(transport) {
|
|
68
|
+
export function createApi(transport, storageFetch = fetch) {
|
|
65
69
|
const memos = memosFacade(transport);
|
|
66
70
|
return {
|
|
67
71
|
transport,
|
|
@@ -97,6 +101,8 @@ export function createApi(transport) {
|
|
|
97
101
|
workflows: (namespace) => workflowsApi(transport, namespace),
|
|
98
102
|
runnables: (namespace) => runnablesApi(transport, namespace),
|
|
99
103
|
libraries: (namespace) => librariesApi(transport, namespace),
|
|
104
|
+
files: (endpoint, signal = new AbortController().signal) => { if (endpoint.kind !== 'source')
|
|
105
|
+
throw new Error('file_endpoint_invalid'); return new FileWorkspace(new SourceFileAdapter(transport, endpoint.namespace, endpoint.sourceId, signal, storageFetch), endpoint.prefix); },
|
|
100
106
|
sources: (namespace) => sourcesApi(transport, namespace),
|
|
101
107
|
runs: (namespace) => runsApi(transport, namespace),
|
|
102
108
|
providers: (namespace) => providersApi(transport, namespace),
|
|
@@ -109,7 +115,7 @@ export function createApi(transport) {
|
|
|
109
115
|
export function createClient(options) {
|
|
110
116
|
const transport = createTransport(options);
|
|
111
117
|
return {
|
|
112
|
-
...createApi(transport),
|
|
118
|
+
...createApi(transport, options.fetch ?? fetch),
|
|
113
119
|
agent: agentApi(transport, options),
|
|
114
120
|
jobs: (namespace) => JobsApi.create(options.remote, options.token, namespace, options.fetch),
|
|
115
121
|
get infra() {
|
|
@@ -55,8 +55,7 @@ export async function nativeFileMultipart(upload) {
|
|
|
55
55
|
fields.metadata = JSON.stringify(upload.metadata);
|
|
56
56
|
if (upload.folderId !== undefined)
|
|
57
57
|
fields.folderId = upload.folderId;
|
|
58
|
-
|
|
59
|
-
return fileMultipart(fields, typed, upload.filename);
|
|
58
|
+
return fileMultipart(fields, blob, upload.filename, upload.contentType);
|
|
60
59
|
}
|
|
61
60
|
/** @deprecated Prefer nativeFileMultipart for filenames containing quotes. Kept for source compatibility. */
|
|
62
61
|
export async function nativeFileForm(upload) {
|
|
@@ -76,7 +75,7 @@ export async function nativeFileForm(upload) {
|
|
|
76
75
|
form.append("metadata", JSON.stringify(upload.metadata));
|
|
77
76
|
if (upload.folderId !== undefined)
|
|
78
77
|
form.append("folderId", upload.folderId);
|
|
79
|
-
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;
|
|
80
79
|
form.append("file", typed, upload.filename);
|
|
81
80
|
return form;
|
|
82
81
|
}
|
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")
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by docs/scripts/gen-help-examples.mjs. Edit docs code blocks with cli-help metadata.
|
|
2
2
|
export const helpExamples = {
|
|
3
|
+
"agents chat": "# Interactive conversation; /exit or Ctrl+D leaves it.\ndl agent chat\n# One request, with streamed answer and tool receipts.\ndl agent chat \"Search my workspace for rope assets\"\n# Continue the conversation ID printed by a previous turn or the browser URL's s parameter.\ndl agent chat --conversation <id> \"Read the first result\"\n# One UTF-8 request from a file or pipe, with JSON events on stdout.\ndl agent chat --file request.txt --json\nprintf '%s' 'Search my workspace for rope assets' | dl agent chat --json\n# The request file identifies the Source namespace/ID, prefix and relative path.\n# Allow changes to that explicit target, matching the browser tool-changes toggle.\ndl agent chat --extensions --tools-write --file source-request.txt --json",
|
|
3
4
|
"agents create": "dl agents create reviewer --runtime builtin-v1 \\\n --prompt 'Read the evidence and summarize it with citations.' \\\n --tools dreamlake_notes_read --project dreamlake --namespace fortyfive\n\n# Existing Memo/folder IDs; references remain live and are authorized per caller.\ndl agents create researcher --instruction-note \"$MAIN_MEMO_ID\" \\\n --skill-note \"$SKILL_MEMO_ID\" --skill-folder \"$SKILLS_FOLDER_ID\" \\\n --project dreamlake --namespace fortyfive",
|
|
4
5
|
"agents list": "dl agents list --namespace my-workspace\n# Stable text, even in a terminal; redirected output also defaults to text.\ndl agents list --namespace my-workspace --plain\n# Prefixes match the beginning of a scoped agent name or registry ID.\ndl agents list --prefix my_repo. --project research",
|
|
5
6
|
"agents show": "dl agents show my_repo.tri --namespace my-workspace",
|
|
@@ -266,6 +267,10 @@ export const helpExamples = {
|
|
|
266
267
|
"skill install": "# The embedded dreamlake-cli skill; offline when it matches the release\ndl skill install dreamlake-cli\n# A catalog skill plus whatever it requires, from the latest release\ndl skill install dreamlake-memos --agent codex\n# One copy for Claude Code and one for Codex\ndl skill install dreamlake-memos --agent all --global\n# Replace files you edited with the release copies\ndl skill install dreamlake-memos --force",
|
|
267
268
|
"skill update": "# Every skill with a manifest in the selected scope\ndl skill update\ndl skill update dreamlake-cli --global\n# Overwrite edited files; retired files you edited are still kept\ndl skill update dreamlake-memos --force\n# Go back to an older release, or replace a copy whose version cannot be ordered\ndl skill update dreamlake-memos --allow-downgrade",
|
|
268
269
|
"skill remove": "dl skill remove dreamlake-memos\ndl skill remove dreamlake-memos --agent codex --global --json",
|
|
270
|
+
"source files write": "dl source files write --source my-workspace --prefix workspaces/v1/demo --path scene/manifest.json --file ./manifest.json --create --json",
|
|
271
|
+
"source files read": "dl source files read --source my-workspace --prefix workspaces/v1/demo --path scene/manifest.json --json",
|
|
272
|
+
"source files list": "dl source files list --source my-workspace --prefix workspaces/v1/demo --path '' --json",
|
|
273
|
+
"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",
|
|
269
274
|
"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",
|
|
270
275
|
"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",
|
|
271
276
|
"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",
|
|
@@ -13,8 +13,10 @@ export declare function isExcluded(relPath: string, patterns: readonly string[])
|
|
|
13
13
|
/**
|
|
14
14
|
* Every regular file under `root`, as sorted POSIX-relative paths.
|
|
15
15
|
*
|
|
16
|
-
* Skipped, always:
|
|
17
|
-
*
|
|
16
|
+
* Skipped, always: dot-leading files and directories other than the asset payload
|
|
17
|
+
* directories `.metadata` and `.thumbs`. This keeps NVIDIA SimReady metadata
|
|
18
|
+
* and thumbnails in the source closure while excluding `.git`, `.DS_Store`,
|
|
19
|
+
* a stray `.dreamlake/` from an old pull, and `dreamlake.yml` itself (it is
|
|
18
20
|
* handled by name, not by discovery); plus everything `exclude` prunes.
|
|
19
21
|
* Symlinks are skipped too — a link out of the tree would upload bytes the
|
|
20
22
|
* closure never declared.
|
|
@@ -80,8 +80,10 @@ export function isExcluded(relPath, patterns) {
|
|
|
80
80
|
/**
|
|
81
81
|
* Every regular file under `root`, as sorted POSIX-relative paths.
|
|
82
82
|
*
|
|
83
|
-
* Skipped, always:
|
|
84
|
-
*
|
|
83
|
+
* Skipped, always: dot-leading files and directories other than the asset payload
|
|
84
|
+
* directories `.metadata` and `.thumbs`. This keeps NVIDIA SimReady metadata
|
|
85
|
+
* and thumbnails in the source closure while excluding `.git`, `.DS_Store`,
|
|
86
|
+
* a stray `.dreamlake/` from an old pull, and `dreamlake.yml` itself (it is
|
|
85
87
|
* handled by name, not by discovery); plus everything `exclude` prunes.
|
|
86
88
|
* Symlinks are skipped too — a link out of the tree would upload bytes the
|
|
87
89
|
* closure never declared.
|
|
@@ -91,7 +93,7 @@ export function walkUserFiles(root, exclude = []) {
|
|
|
91
93
|
const visit = (relDir) => {
|
|
92
94
|
const absDir = relDir === "" ? root : path.join(root, relDir);
|
|
93
95
|
for (const ent of readdirSync(absDir, { withFileTypes: true })) {
|
|
94
|
-
if (ent.name.startsWith("."))
|
|
96
|
+
if (ent.name.startsWith(".") && !(ent.isDirectory() && (ent.name === ".metadata" || ent.name === ".thumbs")))
|
|
95
97
|
continue;
|
|
96
98
|
const rel = relDir === "" ? ent.name : `${relDir}/${ent.name}`;
|
|
97
99
|
if (rel === DREAMLAKE_YML)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerAgentChat } from "../agents/chat.js";
|
|
1
2
|
import { loadPodConfig } from './runner/pod.js';
|
|
2
3
|
import { RunnerJournal } from './runner/journal.js';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
@@ -156,34 +157,7 @@ export function registerSessionControl(group) {
|
|
|
156
157
|
common(group.command('rename <id> <name>').description('rename one of your sessions')).action((id, name, opts) => guard(opts, async () => { const ns = await resolveHostNamespace(opts.namespace); emit({ session: await client().sessions(ns).rename(needId(id), name) }, !!opts.json); }));
|
|
157
158
|
common(group.command('archive <id>').description('hide a session from default listings; conversation and links are kept')).action((id, opts) => guard(opts, async () => { const ns = await resolveHostNamespace(opts.namespace); emit({ session: await client().sessions(ns).archive(needId(id), true) }, !!opts.json); }));
|
|
158
159
|
common(group.command('unarchive <id>').description('return an archived session to default listings')).action((id, opts) => guard(opts, async () => { const ns = await resolveHostNamespace(opts.namespace); emit({ session: await client().sessions(ns).archive(needId(id), false) }, !!opts.json); }));
|
|
159
|
-
group
|
|
160
|
-
.option('--conversation <id>', 'continue a conversation').option('--control', 'allow session control tools this turn').option('--notes-write', 'allow memo appends this turn').option('--page <pathname>', 'page context pathname', '/').option('--json', 'emit one JSON event per line')
|
|
161
|
-
.action((message, opts) => guard(opts, async () => {
|
|
162
|
-
const dl = client();
|
|
163
|
-
let conversation;
|
|
164
|
-
for await (const event of dl.agent.chat({ message, sessionId: opts.conversation, capabilities: { ...(opts.control ? { sessionControl: 1 } : {}), ...(opts.notesWrite ? { notesWrite: 1 } : {}) }, page: { pathname: opts.page, layouts: [] } })) {
|
|
165
|
-
if (opts.json) {
|
|
166
|
-
console.log(JSON.stringify(event));
|
|
167
|
-
if (event.type === 'error')
|
|
168
|
-
process.exitCode = 1;
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (event.type === 'context')
|
|
172
|
-
conversation = event.sessionId;
|
|
173
|
-
else if (event.type === 'delta')
|
|
174
|
-
process.stdout.write(event.text);
|
|
175
|
-
else if (event.type === 'tool')
|
|
176
|
-
process.stderr.write(`\n[tool ${event.name} ${event.status}${event.error ? ' ' + event.error : ''}${event.commandId ? ' command=' + event.commandId : ''}]\n`);
|
|
177
|
-
else if (event.type === 'error') {
|
|
178
|
-
process.stdout.write('\n');
|
|
179
|
-
throw new Error(event.error);
|
|
180
|
-
}
|
|
181
|
-
else if (event.type === 'done')
|
|
182
|
-
process.stdout.write('\n');
|
|
183
|
-
}
|
|
184
|
-
if (!opts.json && conversation)
|
|
185
|
-
console.error(`conversation ${conversation} (continue with --conversation ${conversation})`);
|
|
186
|
-
}));
|
|
160
|
+
registerAgentChat(group);
|
|
187
161
|
group.command('browser-actions <conversation-id>').description('inspect durable browser action receipts, including late acknowledgements').action(id => guard({}, async () => emit(await client().agent.browserActions(needId(id)), true)));
|
|
188
162
|
group.command('agent-projects').description('list projects explicitly granted to your built-in agent').action(() => guard({}, async () => emit(await client().agent.projects(), true)));
|
|
189
163
|
group.command('project-search <project-id> <query>').option('--content').option('--cursor <id>').description('search an explicitly granted project with source locations and pagination').action((id, query, opts) => guard({}, async () => emit(await client().agent.searchProject(needId(id), query, { content: !!opts.content, cursor: opts.cursor }), true)));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface NativeWatch {
|
|
2
|
+
path: string;
|
|
3
|
+
nativeSessionId: string;
|
|
4
|
+
device: number;
|
|
5
|
+
inode: number;
|
|
6
|
+
offset: number;
|
|
7
|
+
promptHash: string;
|
|
8
|
+
matchHash: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class NativeResultError extends Error {
|
|
11
|
+
}
|
|
12
|
+
export declare function prepareNativeWatch(path: string, nativeSessionId: string, prompt: string): NativeWatch;
|
|
13
|
+
export declare function nativeResultReader(watch: NativeWatch): () => {
|
|
14
|
+
reply: string;
|
|
15
|
+
nativeReceipt: {
|
|
16
|
+
provider: "codex";
|
|
17
|
+
nativeSessionId: string;
|
|
18
|
+
turnId: string;
|
|
19
|
+
promptHash: string;
|
|
20
|
+
terminalEvent: "task_complete";
|
|
21
|
+
transcriptEndOffset: number;
|
|
22
|
+
};
|
|
23
|
+
} | null;
|
|
24
|
+
export declare function waitForNativeResult(watch: NativeWatch, signal: AbortSignal, pollMs?: number): Promise<{
|
|
25
|
+
reply: string;
|
|
26
|
+
nativeReceipt: {
|
|
27
|
+
provider: "codex";
|
|
28
|
+
nativeSessionId: string;
|
|
29
|
+
turnId: string;
|
|
30
|
+
promptHash: string;
|
|
31
|
+
terminalEvent: "task_complete";
|
|
32
|
+
transcriptEndOffset: number;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** Correlate a delivered memo prompt with one native Codex terminal event.
|
|
2
|
+
* No provider execution, transcript discovery, or latest-message heuristics here. */
|
|
3
|
+
import { openSync, readSync, closeSync, statSync } from 'node:fs';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
|
+
import { redactSessionText } from '../redaction.js';
|
|
7
|
+
const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
8
|
+
const normalized = (text) => text.replace(/\r\n/g, '\n').trimEnd();
|
|
9
|
+
export class NativeResultError extends Error {
|
|
10
|
+
}
|
|
11
|
+
export function prepareNativeWatch(path, nativeSessionId, prompt) {
|
|
12
|
+
const stat = statSync(path), fd = openSync(path, 'r');
|
|
13
|
+
try {
|
|
14
|
+
const head = Buffer.alloc(Math.min(stat.size, 65536));
|
|
15
|
+
readSync(fd, head, 0, head.length, 0);
|
|
16
|
+
const first = JSON.parse(head.toString('utf8').split('\n')[0]);
|
|
17
|
+
if (first.type !== 'session_meta' || first.payload?.id !== nativeSessionId)
|
|
18
|
+
throw new NativeResultError('memo_native_identity_mismatch');
|
|
19
|
+
const tail = Buffer.alloc(1);
|
|
20
|
+
if (stat.size && (readSync(fd, tail, 0, 1, stat.size - 1) !== 1 || tail[0] !== 10))
|
|
21
|
+
throw new NativeResultError('memo_native_partial_baseline');
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
closeSync(fd);
|
|
25
|
+
}
|
|
26
|
+
return { path, nativeSessionId, device: stat.dev, inode: stat.ino, offset: stat.size, promptHash: digest(prompt), matchHash: digest(normalized(prompt)) };
|
|
27
|
+
}
|
|
28
|
+
export function nativeResultReader(watch) {
|
|
29
|
+
let offset = watch.offset, pending = Buffer.alloc(0), turn = null, matched = false;
|
|
30
|
+
let outcome = null;
|
|
31
|
+
return () => {
|
|
32
|
+
if (outcome)
|
|
33
|
+
return outcome;
|
|
34
|
+
const stat = statSync(watch.path);
|
|
35
|
+
if (stat.dev !== watch.device || stat.ino !== watch.inode || stat.size < offset)
|
|
36
|
+
throw new NativeResultError('memo_native_transcript_changed');
|
|
37
|
+
const fd = openSync(watch.path, 'r');
|
|
38
|
+
try {
|
|
39
|
+
while (offset < stat.size) {
|
|
40
|
+
const chunk = Buffer.alloc(Math.min(stat.size - offset, 256 * 1024));
|
|
41
|
+
const count = readSync(fd, chunk, 0, chunk.length, offset);
|
|
42
|
+
if (!count)
|
|
43
|
+
break;
|
|
44
|
+
offset += count;
|
|
45
|
+
pending = Buffer.concat([pending, chunk.subarray(0, count)]);
|
|
46
|
+
let end;
|
|
47
|
+
while ((end = pending.indexOf(10)) >= 0) {
|
|
48
|
+
const line = pending.subarray(0, end).toString('utf8');
|
|
49
|
+
pending = pending.subarray(end + 1);
|
|
50
|
+
if (!line.trim())
|
|
51
|
+
continue;
|
|
52
|
+
let row;
|
|
53
|
+
try {
|
|
54
|
+
row = JSON.parse(line);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new NativeResultError('memo_native_invalid_event');
|
|
58
|
+
}
|
|
59
|
+
const event = row.payload;
|
|
60
|
+
if (row.type === 'event_msg' && event?.type === 'task_started') {
|
|
61
|
+
if (matched)
|
|
62
|
+
throw new NativeResultError('memo_native_turn_superseded');
|
|
63
|
+
turn = typeof event.turn_id === 'string' ? event.turn_id : null;
|
|
64
|
+
}
|
|
65
|
+
if (row.type === 'response_item' && event?.type === 'message' && event.role === 'user') {
|
|
66
|
+
const parts = event.content;
|
|
67
|
+
const text = Array.isArray(parts) && parts.every((p) => p.type === 'input_text' && typeof p.text === 'string') ? parts.map((p) => p.text).join('\n') : null;
|
|
68
|
+
if (matched)
|
|
69
|
+
throw new NativeResultError('memo_native_turn_steered');
|
|
70
|
+
if (turn && text !== null && digest(normalized(text)) === watch.matchHash)
|
|
71
|
+
matched = true;
|
|
72
|
+
}
|
|
73
|
+
if (matched && row.type === 'event_msg' && event?.type === 'turn_aborted')
|
|
74
|
+
throw new NativeResultError('memo_native_turn_aborted');
|
|
75
|
+
if (matched && row.type === 'event_msg' && event?.type === 'task_complete' && event.turn_id === turn) {
|
|
76
|
+
if (typeof event.last_agent_message !== 'string' || !event.last_agent_message.trim())
|
|
77
|
+
throw new NativeResultError('memo_native_empty_result');
|
|
78
|
+
outcome = { reply: redactSessionText(event.last_agent_message).slice(0, 16000), nativeReceipt: { provider: 'codex', nativeSessionId: watch.nativeSessionId, turnId: turn, promptHash: watch.promptHash, terminalEvent: 'task_complete', transcriptEndOffset: offset - pending.length } };
|
|
79
|
+
return outcome;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (pending.length > 1024 * 1024)
|
|
83
|
+
throw new NativeResultError('memo_native_event_too_large');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
closeSync(fd);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export async function waitForNativeResult(watch, signal, pollMs = 1000) {
|
|
93
|
+
const read = nativeResultReader(watch);
|
|
94
|
+
for (;;) {
|
|
95
|
+
signal.throwIfAborted();
|
|
96
|
+
const result = read();
|
|
97
|
+
if (result)
|
|
98
|
+
return result;
|
|
99
|
+
await delay(pollMs, undefined, { signal });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { prepareNativeWatch, waitForNativeResult, nativeResultReader } from './native-result.js';
|
|
1
2
|
import { Pods } from './pod.js';
|
|
2
3
|
import { RunnerJournal } from './journal.js';
|
|
3
4
|
/** `dl sessions serve` — the session runner.
|
|
@@ -401,9 +402,32 @@ export function commandExecutors(input) {
|
|
|
401
402
|
throw new RunnerError('pane_ownership_unverified');
|
|
402
403
|
if (ownership === 'owned' && level !== row.permissionLevel)
|
|
403
404
|
throw new RunnerError('permission_change_requires_restart');
|
|
405
|
+
let nativeWatch;
|
|
406
|
+
if (command.memoContext) {
|
|
407
|
+
if (row.provider !== 'codex' || !i.prompt)
|
|
408
|
+
throw new RunnerError('memo_native_provider_unsupported');
|
|
409
|
+
const path = transcript(row);
|
|
410
|
+
if (!path)
|
|
411
|
+
throw new RunnerError('memo_native_transcript_missing');
|
|
412
|
+
nativeWatch = prepareNativeWatch(path, row.codexSessionId, i.prompt);
|
|
413
|
+
if (nativeWatch.promptHash !== command.memoContext.promptHash)
|
|
414
|
+
throw new RunnerError('memo_prompt_hash_mismatch');
|
|
415
|
+
if (!input.journal)
|
|
416
|
+
throw new RunnerError('memo_native_journal_required');
|
|
417
|
+
input.journal.checkpoint(command.id, { nativeWatch, sessionId: row.id, mode: chosen });
|
|
418
|
+
}
|
|
404
419
|
const r = await resumeTmux(run, { provider: row.provider, cwd: row.sessionSandbox ? '/workspace' : row.cwd, nativeSessionId: row.codexSessionId, permissionLevel: level, claudeConfigDir: row.claudeConfigDir, defaultClaudeConfigDir: roots.claude, prompt: i.prompt, marker: marker(row), signal: reservation.controller.signal, checkpoint: value => input.journal?.checkpoint(command.id, value) });
|
|
405
420
|
beats.allow(row.id);
|
|
406
421
|
void beats.beat(row.id, r.created ? 'starting' : r.delivered ? 'running' : 'idle');
|
|
422
|
+
if (nativeWatch) {
|
|
423
|
+
try {
|
|
424
|
+
const result = await waitForNativeResult(nativeWatch, reservation.controller.signal);
|
|
425
|
+
return { sessionId: row.id, mode: chosen, permissionLevel: level, ...r, ...result, runState: 'waiting' };
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
throw new RunnerError('memo_native_result_uncertain', error instanceof Error ? error.message : String(error), true, { nativeWatch, sessionId: row.id, mode: chosen });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
407
431
|
return { sessionId: row.id, mode: chosen, permissionLevel: level, ...r, runState: 'running' };
|
|
408
432
|
}
|
|
409
433
|
if (!row.sessionSandbox)
|
|
@@ -673,7 +697,10 @@ export async function handleCommand(input) {
|
|
|
673
697
|
}
|
|
674
698
|
try {
|
|
675
699
|
const final = await api.commands.finish(command.id, runnerId, receipt);
|
|
676
|
-
|
|
700
|
+
// Acknowledging delivery uncertainty must not discard the native observer.
|
|
701
|
+
// The same running runner retries its retained cursor without another send.
|
|
702
|
+
if (!(receipt.status === 'uncertain' && input.journal?.read(command.id)?.checkpoint?.nativeWatch))
|
|
703
|
+
input.journal?.update(command.id, { state: 'acknowledged' });
|
|
677
704
|
log(`${command.kind} ${command.id} ${final.status}`);
|
|
678
705
|
return final;
|
|
679
706
|
}
|
|
@@ -714,6 +741,21 @@ export async function serve(options) {
|
|
|
714
741
|
log(`retained command ${entry.commandId}: remote lease still active; inspect after expiry`);
|
|
715
742
|
continue;
|
|
716
743
|
}
|
|
744
|
+
if (entry.checkpoint?.nativeWatch) {
|
|
745
|
+
const result = nativeResultReader(entry.checkpoint.nativeWatch)();
|
|
746
|
+
if (!result) {
|
|
747
|
+
log(`retained memo ${entry.commandId}: waiting for its native terminal event; no replay`);
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
const reconciled = await api.commands.reconcile(entry.commandId, runner.id, { localState: entry.state, checkpoint: entry.checkpoint, nativeResult: { sessionId: entry.sessionId, mode: 'tmux', ...result } });
|
|
751
|
+
const retained = reconciled.reconciliation?.observation?.nativeResult;
|
|
752
|
+
if (!retained || retained.reply !== result.reply || JSON.stringify(retained.nativeReceipt) !== JSON.stringify(result.nativeReceipt))
|
|
753
|
+
throw new RunnerError('memo_native_reconciliation_unconfirmed');
|
|
754
|
+
journal.update(entry.commandId, { state: 'acknowledged' });
|
|
755
|
+
quarantined.delete(entry.commandId);
|
|
756
|
+
log(`reconciled memo ${entry.commandId}: native result retained without re-execution`);
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
717
759
|
const { leaseToken: _lease, ...receipt } = entry.receipt ?? { leaseToken: '' };
|
|
718
760
|
await api.commands.reconcile(entry.commandId, runner.id, { localState: entry.state, checkpoint: entry.checkpoint ?? {}, receipt });
|
|
719
761
|
let safe = entry.state === 'prepared' || entry.state === 'finished' && entry.receipt?.status !== 'uncertain';
|
|
@@ -747,7 +789,8 @@ export async function serve(options) {
|
|
|
747
789
|
const inFlight = new Set();
|
|
748
790
|
let handled = 0;
|
|
749
791
|
signal.addEventListener('abort', () => active.cancelAll(), { once: true });
|
|
750
|
-
const handle = (command) => handleCommand({ api, runnerId: runner.id, executors, log, command, shutdown: signal, journal }).then(() => {
|
|
792
|
+
const handle = (command) => handleCommand({ api, runnerId: runner.id, executors, log, command, shutdown: signal, journal }).then(() => { if (journal.read(command.id)?.state !== 'acknowledged')
|
|
793
|
+
quarantined.add(command.id); handled++; }).catch(error => { failure = error; fatal.abort(error); active.cancelAll(); log('runner persistence failed; stopping acceptance of new work'); });
|
|
751
794
|
try {
|
|
752
795
|
while (!signal.aborted) {
|
|
753
796
|
if (quarantined.size && Date.now() >= recoveryAfter) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Bounded text workspace operations; large objects remain source upload/download. */
|
|
2
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { FileWorkspace } from '../../api/file-workspace.js';
|
|
4
|
+
import { SourceFileAdapter } from '../../api/file-source.js';
|
|
5
|
+
import { requestJson } from '../client.js';
|
|
6
|
+
import { emitJson, fail } from '../helpers.js';
|
|
7
|
+
import { ctx, resolveSource } from './index.js';
|
|
8
|
+
export function registerSourceFiles(source) {
|
|
9
|
+
const files = source.command('files').description('list/read/create/replace bounded managed workspace text with revision guards');
|
|
10
|
+
for (const operation of ['list', 'read', 'write', 'replace']) {
|
|
11
|
+
const cmd = files.command(operation).requiredOption('--source <name>', 'Source name').requiredOption('--prefix <path>', 'explicit workspace root (empty selects Source root)').requiredOption('--path <path>', 'relative file path (empty lists root)').option('--namespace <slug>', 'namespace').option('--json', 'emit JSON (all results are JSON)');
|
|
12
|
+
if (operation === 'list')
|
|
13
|
+
cmd.option('--cursor <cursor>', 'next page cursor');
|
|
14
|
+
if (operation === 'write')
|
|
15
|
+
cmd.requiredOption('--file <local-path>', 'UTF-8 input file').option('--create', 'create only').option('--revision <etag>', 'exact revision from read');
|
|
16
|
+
if (operation === 'replace')
|
|
17
|
+
cmd.requiredOption('--old-file <local-path>', 'UTF-8 literal match').requiredOption('--new-file <local-path>', 'UTF-8 replacement').requiredOption('--revision <etag>', 'exact revision from read');
|
|
18
|
+
cmd.action(async (opts) => {
|
|
19
|
+
try {
|
|
20
|
+
if (operation === 'write' && ((!!opts.create) === (opts.revision !== undefined)))
|
|
21
|
+
throw new Error('Choose exactly one of --create or --revision');
|
|
22
|
+
const c = await ctx(opts.namespace);
|
|
23
|
+
if (!c)
|
|
24
|
+
return;
|
|
25
|
+
const source = await resolveSource(c, opts.source);
|
|
26
|
+
const api = { request: (method, path, options = {}) => requestJson(c.remote, path, { ...options, method, token: c.token }) };
|
|
27
|
+
const workspace = new FileWorkspace(new SourceFileAdapter(api, c.ns, source.id, new AbortController().signal), opts.prefix);
|
|
28
|
+
const read = (path) => { if (statSync(path).size > 256 * 1024)
|
|
29
|
+
throw new Error('file_text_too_large_or_binary'); return new TextDecoder('utf-8', { fatal: true }).decode(readFileSync(path)); };
|
|
30
|
+
const result = operation === 'list' ? await workspace.list(opts.path, opts.cursor) : operation === 'read' ? await workspace.read(opts.path) : operation === 'write' ? await workspace.write(opts.path, read(opts.file), opts.create ? null : opts.revision) : await workspace.replace(opts.path, read(opts.oldFile), read(opts.newFile), opts.revision);
|
|
31
|
+
emitJson(result);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
fail(error instanceof Error ? error.message : 'file_operation_failed');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/cli/source/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerSourceFiles } from "./files.js";
|
|
1
2
|
import { collectionList } from "../collection-list.js";
|
|
2
3
|
// `dl source ...` — read data out of connected sources (S3 and Hugging
|
|
3
4
|
// Face; those are the two connectors Source v1 has).
|
|
@@ -1337,6 +1338,7 @@ export function registerSourceCommand(program) {
|
|
|
1337
1338
|
.option("-o, --output <dir>", "output directory (default: current directory)")
|
|
1338
1339
|
.option("-r, --recursive", "download every file under <path>")
|
|
1339
1340
|
.action(async (pathArg, opts) => process.exit(await runSourceDownload(pathArg, opts)));
|
|
1341
|
+
registerSourceFiles(source);
|
|
1340
1342
|
registerSourceWriteCommands(source);
|
|
1341
1343
|
registerSourceUploadCommand(source);
|
|
1342
1344
|
registerSourceDeleteCommands(source);
|
package/dist/cli/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.118.
|
|
1
|
+
export declare const VERSION = "0.118.1";
|
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.118.
|
|
3
|
+
"version": "0.118.1",
|
|
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.118.
|
|
41
|
-
"@dreamlake/dreamlake-cli-darwin-x64": "0.118.
|
|
42
|
-
"@dreamlake/dreamlake-cli-linux-x64": "0.118.
|
|
43
|
-
"@dreamlake/dreamlake-cli-linux-arm64": "0.118.
|
|
44
|
-
"@dreamlake/dreamlake-cli-linux-x64-musl": "0.118.
|
|
45
|
-
"@dreamlake/dreamlake-cli-linux-arm64-musl": "0.118.
|
|
46
|
-
"@dreamlake/dreamlake-cli-win32-x64": "0.118.
|
|
47
|
-
"@dreamlake/dreamlake-cli-win32-arm64": "0.118.
|
|
40
|
+
"@dreamlake/dreamlake-cli-darwin-arm64": "0.118.1",
|
|
41
|
+
"@dreamlake/dreamlake-cli-darwin-x64": "0.118.1",
|
|
42
|
+
"@dreamlake/dreamlake-cli-linux-x64": "0.118.1",
|
|
43
|
+
"@dreamlake/dreamlake-cli-linux-arm64": "0.118.1",
|
|
44
|
+
"@dreamlake/dreamlake-cli-linux-x64-musl": "0.118.1",
|
|
45
|
+
"@dreamlake/dreamlake-cli-linux-arm64-musl": "0.118.1",
|
|
46
|
+
"@dreamlake/dreamlake-cli-win32-x64": "0.118.1",
|
|
47
|
+
"@dreamlake/dreamlake-cli-win32-arm64": "0.118.1"
|
|
48
48
|
}
|
|
49
49
|
}
|