@dreamlake/dreamlake-cli 0.117.0 → 0.118.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/api/agent.d.ts +1 -0
  2. package/dist/api/file-multipart.d.ts +6 -0
  3. package/dist/api/file-multipart.js +34 -0
  4. package/dist/api/file-source.d.ts +30 -0
  5. package/dist/api/file-source.js +165 -0
  6. package/dist/api/file-workspace.d.ts +79 -0
  7. package/dist/api/file-workspace.js +142 -0
  8. package/dist/api/index.d.ts +60 -1
  9. package/dist/api/index.js +8 -2
  10. package/dist/api/native-experiments.d.ts +25 -0
  11. package/dist/api/native-experiments.js +49 -4
  12. package/dist/api/sessions.d.ts +6 -0
  13. package/dist/cli/agents/chat.d.ts +21 -0
  14. package/dist/cli/agents/chat.js +126 -0
  15. package/dist/cli/agents/index.js +3 -1
  16. package/dist/cli/experiments/index.js +4 -0
  17. package/dist/cli/experiments/management.d.ts +16 -0
  18. package/dist/cli/experiments/management.js +82 -0
  19. package/dist/cli/experiments/transfer/adapter.d.ts +86 -0
  20. package/dist/cli/experiments/transfer/adapter.js +637 -0
  21. package/dist/cli/experiments/transfer/context.d.ts +13 -0
  22. package/dist/cli/experiments/transfer/context.js +20 -0
  23. package/dist/cli/experiments/transfer/download.d.ts +24 -0
  24. package/dist/cli/experiments/transfer/download.js +516 -0
  25. package/dist/cli/experiments/transfer/index.d.ts +2 -0
  26. package/dist/cli/experiments/transfer/index.js +38 -0
  27. package/dist/cli/experiments/transfer/local/safe-path.d.ts +29 -0
  28. package/dist/cli/experiments/transfer/local/safe-path.js +106 -0
  29. package/dist/cli/experiments/transfer/local/storage.d.ts +125 -0
  30. package/dist/cli/experiments/transfer/local/storage.js +432 -0
  31. package/dist/cli/experiments/transfer/transport.d.ts +7 -0
  32. package/dist/cli/experiments/transfer/transport.js +31 -0
  33. package/dist/cli/experiments/transfer/types.d.ts +48 -0
  34. package/dist/cli/experiments/transfer/types.js +1 -0
  35. package/dist/cli/experiments/transfer/upload.d.ts +58 -0
  36. package/dist/cli/experiments/transfer/upload.js +665 -0
  37. package/dist/cli/experiments/transfer/util/ansi.d.ts +24 -0
  38. package/dist/cli/experiments/transfer/util/ansi.js +70 -0
  39. package/dist/cli/experiments/transfer/util/glob.d.ts +4 -0
  40. package/dist/cli/experiments/transfer/util/glob.js +39 -0
  41. package/dist/cli/experiments/transfer/util/json.d.ts +6 -0
  42. package/dist/cli/experiments/transfer/util/json.js +58 -0
  43. package/dist/cli/experiments/transfer/util/pool.d.ts +5 -0
  44. package/dist/cli/experiments/transfer/util/pool.js +21 -0
  45. package/dist/cli/help-examples.generated.js +17 -0
  46. package/dist/cli/library/discover.d.ts +4 -2
  47. package/dist/cli/library/discover.js +5 -3
  48. package/dist/cli/sessions/control.js +2 -28
  49. package/dist/cli/sessions/runner/native-result.d.ts +34 -0
  50. package/dist/cli/sessions/runner/native-result.js +101 -0
  51. package/dist/cli/sessions/runner/serve.js +45 -2
  52. package/dist/cli/source/files.d.ts +2 -0
  53. package/dist/cli/source/files.js +39 -0
  54. package/dist/cli/source/index.js +2 -0
  55. package/dist/cli/version.d.ts +1 -1
  56. package/dist/cli/version.js +1 -1
  57. package/package.json +9 -9
@@ -0,0 +1,70 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ const enabled = () => {
3
+ if (process.env.NO_COLOR !== undefined)
4
+ return false;
5
+ if (process.env.FORCE_COLOR !== undefined)
6
+ return true;
7
+ return process.stdout.isTTY === true;
8
+ };
9
+ const wrap = (code, close) => (s) => enabled() ? `\u001b[${code}m${s}\u001b[${close}m` : s;
10
+ export const bold = wrap(1, 22);
11
+ export const dim = wrap(2, 22);
12
+ export const red = wrap(31, 39);
13
+ export const green = wrap(32, 39);
14
+ export const yellow = wrap(33, 39);
15
+ export const blue = wrap(34, 39);
16
+ export const cyan = wrap(36, 39);
17
+ /** Visible width, ignoring the escape sequences the styles above insert. */
18
+ export const visibleWidth = (s) =>
19
+ // eslint-disable-next-line no-control-regex
20
+ s.replace(/\u001b\[[0-9;]*m/g, "").length;
21
+ const pad = (s, width, align) => {
22
+ const gap = Math.max(0, width - visibleWidth(s));
23
+ if (align === "right")
24
+ return " ".repeat(gap) + s;
25
+ if (align === "center") {
26
+ const l = Math.floor(gap / 2);
27
+ return " ".repeat(l) + s + " ".repeat(gap - l);
28
+ }
29
+ return s + " ".repeat(gap);
30
+ };
31
+ /** Rounded-box table, the same shape `rich.box.ROUNDED` produced. */
32
+ export function renderTable(columns, rows, opts = {}) {
33
+ const widths = columns.map((c, i) => Math.max(visibleWidth(c.header), ...rows.map((r) => visibleWidth(r[i] ?? ""))));
34
+ const line = (l, m, r) => l + widths.map((w) => "─".repeat(w + 2)).join(m) + r;
35
+ const out = [];
36
+ if (opts.title)
37
+ out.push(bold(opts.title));
38
+ out.push(line("╭", "┬", "╮"));
39
+ out.push("│ " + columns.map((c, i) => pad(bold(c.header), widths[i], c.align ?? "left")).join(" │ ") + " │");
40
+ out.push(line("├", "┼", "┤"));
41
+ for (const row of rows) {
42
+ out.push("│ " + columns.map((c, i) => pad(row[i] ?? "", widths[i], c.align ?? "left")).join(" │ ") + " │");
43
+ }
44
+ out.push(line("╰", "┴", "╯"));
45
+ if (opts.caption)
46
+ out.push(dim(opts.caption));
47
+ return out.join("\n");
48
+ }
49
+ /** Bordered panel, the shape `rich.panel.Panel` produced. */
50
+ export function renderPanel(body, opts = {}) {
51
+ const lines = body.split("\n");
52
+ const width = Math.max(...lines.map(visibleWidth), opts.title ? visibleWidth(opts.title) + 2 : 0);
53
+ const top = opts.title
54
+ ? "╭─ " + opts.title + " " + "─".repeat(Math.max(0, width - visibleWidth(opts.title) - 1)) + "╮"
55
+ : "╭" + "─".repeat(width + 2) + "╮";
56
+ const out = [top];
57
+ for (const l of lines)
58
+ out.push("│ " + pad(l, width, "left") + " │");
59
+ out.push("╰" + "─".repeat(width + 2) + "╯");
60
+ return out.join("\n");
61
+ }
62
+ export function formatBytes(n) {
63
+ let v = n;
64
+ for (const unit of ["B", "KB", "MB", "GB"]) {
65
+ if (v < 1024)
66
+ return `${v.toFixed(2)} ${unit}`;
67
+ v /= 1024;
68
+ }
69
+ return `${v.toFixed(2)} TB`;
70
+ }
@@ -0,0 +1,4 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ export declare function fnmatch(name: string, pattern: string): boolean;
3
+ export declare function fnmatchToRegExp(pattern: string): RegExp;
4
+ export declare const hasWildcard: (s: string) => boolean;
@@ -0,0 +1,39 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ export function fnmatch(name, pattern) {
3
+ return fnmatchToRegExp(pattern).test(name);
4
+ }
5
+ export function fnmatchToRegExp(pattern) {
6
+ let out = "";
7
+ let i = 0;
8
+ while (i < pattern.length) {
9
+ const c = pattern[i++];
10
+ if (c === "*")
11
+ out += ".*";
12
+ else if (c === "?")
13
+ out += ".";
14
+ else if (c === "[") {
15
+ let j = i;
16
+ if (j < pattern.length && (pattern[j] === "!" || pattern[j] === "^"))
17
+ j++;
18
+ if (j < pattern.length && pattern[j] === "]")
19
+ j++;
20
+ while (j < pattern.length && pattern[j] !== "]")
21
+ j++;
22
+ if (j >= pattern.length) {
23
+ out += "\\[";
24
+ }
25
+ else {
26
+ let body = pattern.slice(i, j);
27
+ if (body.startsWith("!") || body.startsWith("^"))
28
+ body = "^" + body.slice(1);
29
+ out += "[" + body.replace(/\\/g, "\\\\") + "]";
30
+ i = j + 1;
31
+ }
32
+ }
33
+ else {
34
+ out += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
35
+ }
36
+ }
37
+ return new RegExp(`^${out}$`, "s");
38
+ }
39
+ export const hasWildcard = (s) => /[*?[]/.test(s);
@@ -0,0 +1,6 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ /** Rewrite unsafe integer literals as strings, leaving strings and floats alone. */
3
+ export declare function preserveBigIntegers(text: string): string;
4
+ export declare function parseJson<T = any>(text: string): T;
5
+ /** Coerce whatever the server sent for an ID into a string, losslessly. */
6
+ export declare function asId(v: unknown): string | undefined;
@@ -0,0 +1,58 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ /** Rewrite unsafe integer literals as strings, leaving strings and floats alone. */
3
+ export function preserveBigIntegers(text) {
4
+ let out = "";
5
+ let i = 0;
6
+ const n = text.length;
7
+ while (i < n) {
8
+ const c = text[i];
9
+ if (c === '"') {
10
+ // Copy the string literal verbatim — digits inside it are not numbers.
11
+ const start = i++;
12
+ while (i < n) {
13
+ if (text[i] === "\\")
14
+ i += 2;
15
+ else if (text[i] === '"') {
16
+ i++;
17
+ break;
18
+ }
19
+ else
20
+ i++;
21
+ }
22
+ out += text.slice(start, i);
23
+ continue;
24
+ }
25
+ if (c === "-" || (c >= "0" && c <= "9")) {
26
+ const start = i;
27
+ if (text[i] === "-")
28
+ i++;
29
+ while (i < n && text[i] >= "0" && text[i] <= "9")
30
+ i++;
31
+ const isInteger = !(i < n && (text[i] === "." || text[i] === "e" || text[i] === "E"));
32
+ while (i < n && /[0-9.eE+-]/.test(text[i]))
33
+ i++;
34
+ const literal = text.slice(start, i);
35
+ // Only integers, and only those outside the exactly-representable range.
36
+ out += isInteger && !Number.isSafeInteger(Number(literal)) ? `"${literal}"` : literal;
37
+ continue;
38
+ }
39
+ out += c;
40
+ i++;
41
+ }
42
+ return out;
43
+ }
44
+ export function parseJson(text) {
45
+ return JSON.parse(preserveBigIntegers(text));
46
+ }
47
+ /** Coerce whatever the server sent for an ID into a string, losslessly. */
48
+ export function asId(v) {
49
+ if (v === null || v === undefined)
50
+ return undefined;
51
+ if (typeof v === "string")
52
+ return v;
53
+ if (typeof v === "number")
54
+ return String(v);
55
+ if (typeof v === "bigint")
56
+ return v.toString();
57
+ return String(v);
58
+ }
@@ -0,0 +1,5 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ export declare function runPool<T, R>(items: T[], limit: number, worker: (item: T, index: number) => Promise<R>): Promise<{
3
+ value?: R;
4
+ error?: Error;
5
+ }[]>;
@@ -0,0 +1,21 @@
1
+ /** .dash format compatibility, ported from the MIT-licensed ml-dash-cli. */
2
+ export async function runPool(items, limit, worker) {
3
+ const results = new Array(items.length);
4
+ const width = Math.max(1, Math.min(limit, items.length));
5
+ let cursor = 0;
6
+ const runners = Array.from({ length: width }, async () => {
7
+ for (;;) {
8
+ const index = cursor++;
9
+ if (index >= items.length)
10
+ return;
11
+ try {
12
+ results[index] = { value: await worker(items[index], index) };
13
+ }
14
+ catch (e) {
15
+ results[index] = { error: e instanceof Error ? e : new Error(String(e)) };
16
+ }
17
+ }
18
+ });
19
+ await Promise.all(runners);
20
+ return results;
21
+ }
@@ -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",
@@ -57,6 +58,18 @@ export const helpExamples = {
57
58
  "experiments binding": "dl experiments binding --namespace fortyfive --json",
58
59
  "experiments connect": "dl experiments connect research --namespace fortyfive --json\n# Apply only after reviewing the preview. Use its actual revision, not this example's 0.\ndl experiments connect \"$DASH_NAMESPACE_ID\" --namespace fortyfive --instance-id \"$DASH_INSTANCE_ID\" --apply --expected-revision 0 --json",
59
60
  "experiments disconnect": "dl experiments disconnect --namespace fortyfive --json\n# Replace 1 with the revision returned by this preview.\ndl experiments disconnect --namespace fortyfive --apply --expected-revision 1 --json",
61
+ "experiments upload": "dl experiments upload ./.dash --project 'fortyfive/research/*' --strict",
62
+ "experiments download": "dl experiments download ./experiment-copy --project fortyfive/research --experiment trial_1",
63
+ "experiments writers list": "dl experiments writers list --namespace fortyfive --project research",
64
+ "experiments writers create": "dl experiments writers create --namespace fortyfive --project research --idempotency-key \"$INTENT_UUID\" --run-id \"$RUN_ID\"",
65
+ "experiments writers inspect": "dl experiments writers inspect \"$WRITER_ID\" --namespace fortyfive --project research",
66
+ "experiments writers rotate": "dl experiments writers rotate \"$WRITER_ID\" --expected-generation 1 --namespace fortyfive --project research",
67
+ "experiments writers retire": "dl experiments writers retire \"$WRITER_ID\" --expected-generation 2 --namespace fortyfive --project research",
68
+ "experiments jobs submit": "dl experiments jobs submit --spec job.json --namespace fortyfive --project research",
69
+ "experiments jobs list": "dl experiments jobs list --namespace fortyfive --project research",
70
+ "experiments jobs show": "dl experiments jobs show \"$JOB_ID\" --namespace fortyfive --project research",
71
+ "experiments jobs logs": "dl experiments jobs logs \"$JOB_ID\" --namespace fortyfive --project research",
72
+ "experiments jobs cancel": "dl experiments jobs cancel \"$JOB_ID\" --namespace fortyfive --project research",
60
73
  "hosts list": "dl hosts list\ndl hosts list --namespace geyang --group workstations\ndl hosts list --json\ndl hosts list --all\ndl hosts list --wide\ndl hosts --fields\ndl hosts --format '{name} {user} {ips} {network_freshness}'\ndl hosts --probe --format '{name} {ip} {public_ip} {macs} {uptime}'",
61
74
  "hosts status": "dl hosts status geyang/workstations/worker\ndl hosts status HOST_ID --namespace geyang --json\ndl hosts status 'geyang/workstations/*' --page 2 --page-size 100 --json",
62
75
  "hosts lifecycle": "dl hosts lifecycle HOST_ID --namespace geyang --json",
@@ -254,6 +267,10 @@ export const helpExamples = {
254
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",
255
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",
256
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",
257
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",
258
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",
259
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: any path with a dot-leading segment (`.git`, `.DS_Store`,
17
- * a stray `.dreamlake/` from an old pull) and `dreamlake.yml` itself (it is
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: any path with a dot-leading segment (`.git`, `.DS_Store`,
84
- * a stray `.dreamlake/` from an old pull) and `dreamlake.yml` itself (it is
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.command('chat <message>').description('one turn with the built-in agent (the same harness the app uses); prints the streamed answer and tool receipts')
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
- input.journal?.update(command.id, { state: 'acknowledged' });
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(() => { handled++; }).catch(error => { failure = error; fatal.abort(error); active.cancelAll(); log('runner persistence failed; stopping acceptance of new work'); });
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,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerSourceFiles(source: Command): void;
@@ -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
+ }
@@ -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);
@@ -1 +1 @@
1
- export declare const VERSION = "0.117.0";
1
+ export declare const VERSION = "0.118.1";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.117.0";
9
+ export const VERSION = "0.118.1";