@dreamlake/dreamlake-cli 0.107.1 → 0.108.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/api/apps.d.ts +56 -0
  2. package/dist/api/apps.js +23 -0
  3. package/dist/api/bindrs.d.ts +76 -0
  4. package/dist/api/bindrs.js +83 -0
  5. package/dist/api/client.d.ts +3 -0
  6. package/dist/api/client.js +4 -1
  7. package/dist/api/common.js +2 -2
  8. package/dist/api/execution.js +4 -4
  9. package/dist/api/host-moves.js +2 -2
  10. package/dist/api/index.d.ts +157 -14
  11. package/dist/api/index.js +3 -0
  12. package/dist/api/memo-facade.js +2 -2
  13. package/dist/api/memo-reading.js +2 -2
  14. package/dist/api/memos.js +3 -3
  15. package/dist/api/native-experiments.js +2 -2
  16. package/dist/api/platform.js +6 -6
  17. package/dist/api/sessions.js +5 -5
  18. package/dist/api/workspace.d.ts +64 -7
  19. package/dist/api/workspace.js +4 -10
  20. package/dist/cli/apps/index.d.ts +14 -0
  21. package/dist/cli/apps/index.js +205 -0
  22. package/dist/cli/connection/oauth.d.ts +2 -0
  23. package/dist/cli/connection/oauth.js +4 -2
  24. package/dist/cli/create/index.d.ts +1 -0
  25. package/dist/cli/create/index.js +23 -9
  26. package/dist/cli/delete/index.js +13 -4
  27. package/dist/cli/help-examples.generated.js +12 -0
  28. package/dist/cli/index.js +2 -0
  29. package/dist/cli/list/index.js +5 -7
  30. package/dist/cli/resources.d.ts +2 -0
  31. package/dist/cli/resources.js +17 -3
  32. package/dist/cli/self-update/index.js +6 -4
  33. package/dist/cli/self-update/install.d.ts +5 -1
  34. package/dist/cli/self-update/install.js +28 -86
  35. package/dist/cli/self-update/shell-path.d.ts +4 -0
  36. package/dist/cli/self-update/shell-path.js +135 -0
  37. package/dist/cli/update/index.js +29 -65
  38. package/dist/cli/version.d.ts +1 -1
  39. package/dist/cli/version.js +1 -1
  40. package/package.json +9 -9
@@ -1,3 +1,4 @@
1
+ import { seg } from "../api/client.js";
1
2
  // Shared helpers for project-scoped resource commands (list / create /
2
3
  // update / delete of bindrs and datasets). Centralizes project-context
3
4
  // resolution, paginated fetches, and glob matching.
@@ -64,13 +65,26 @@ async function fetchEveryPage(remote, path, token, key) {
64
65
  }
65
66
  /** Fetch all episodes in a project (throws on error). */
66
67
  export async function fetchAllEpisodes(remote, namespace, project, token, options = {}) {
67
- const r = await fetchAllPages(remote, `/namespaces/${namespace}/projects/${project}/episodes${options.includeArchived ? "?includeArchived=true" : ""}`, token, "episodes");
68
+ const r = await fetchAllPages(remote, `/namespaces/${seg(namespace)}/projects/${seg(project)}/episodes${options.includeArchived ? "?includeArchived=true" : ""}`, token, "episodes");
68
69
  return r === "not-found" ? [] : r.items;
69
70
  }
70
71
  /** Fetch all bindrs in a project (throws on error). */
71
72
  export async function fetchAllBindrs(remote, namespace, project, token) {
72
- const r = await fetchAllPages(remote, `/namespaces/${namespace}/projects/${project}/bindrs`, token, "bindrs");
73
- return r === "not-found" ? [] : r.items;
73
+ const result = await requestJson(remote, `/namespaces/${seg(namespace)}/projects/${seg(project)}/bindrs`, { token });
74
+ return result.bindrs;
75
+ }
76
+ /** Resolve once before a mutation or confirmation; never silently pick a duplicate name. */
77
+ export async function resolveBindr(ctx, nameOrId) {
78
+ const rows = await fetchAllBindrs(ctx.remote, ctx.s.namespace, ctx.s.project, ctx.token);
79
+ const byId = rows.find(row => row.id === nameOrId);
80
+ if (byId)
81
+ return byId;
82
+ const matches = rows.filter(row => row.name === nameOrId);
83
+ if (!matches.length)
84
+ throw new Error(`bindr '${nameOrId}' not found in ${ctx.s.project}`);
85
+ if (matches.length > 1)
86
+ throw new Error(`bindr '${nameOrId}' is ambiguous; use its ID (${matches.map(row => row.id).join(", ")})`);
87
+ return matches[0];
74
88
  }
75
89
  /** Match episodes by glob against their name OR node path (leading "/" stripped). */
76
90
  export function matchEpisodes(episodes, pattern) {
@@ -1,5 +1,5 @@
1
1
  // Commander wiring for the self-updating native install.
2
- import { installedVersion, installWarnings, performInstall, shadowingBinary } from "./install.js";
2
+ import { binaryOnPath, installedVersion, installWarnings, performInstall, shadowingBinary } from "./install.js";
3
3
  import { binDir, isNativeInstall, launcherPath, versionsDir } from "./paths.js";
4
4
  import { CHANNELS, isChannel } from "./releases.js";
5
5
  import { activeChannel, pinnedVersion, writeSettings } from "./settings.js";
@@ -12,13 +12,14 @@ export function registerInstallCommand(program) {
12
12
  .command("install")
13
13
  .description("install or re-install the native binary under ~/.local")
14
14
  .argument("[target]", `${CHANNELS.join(" | ")} | version (default: saved channel)`)
15
- .action(async (target) => {
15
+ .option("--no-modify-path", "leave shell startup files and user PATH unchanged")
16
+ .action(async (target, opts) => {
16
17
  try {
17
18
  // install.sh always runs us from a throwaway download, so "you are
18
19
  // now a native install" is only news when the user invoked this
19
20
  // themselves from an npm or from-source copy.
20
21
  const converting = !isNativeInstall() && process.env.DREAMLAKE_BOOTSTRAP !== "1";
21
- const result = await performInstall(target);
22
+ const result = await performInstall(target, { modifyPath: opts.modifyPath });
22
23
  process.stdout.write(`Installed dreamlake ${result.version} → ${result.launcher}\n`);
23
24
  if (converting) {
24
25
  process.stdout.write("This is now a native install under ~/.local; the copy you ran this from is untouched.\n");
@@ -87,6 +88,7 @@ export function registerDoctorCommand(program) {
87
88
  .description("print install and auto-update diagnostics")
88
89
  .action(() => {
89
90
  const shadow = shadowingBinary();
91
+ const found = binaryOnPath();
90
92
  const lines = [
91
93
  `dreamlake ${VERSION}`,
92
94
  `executable: ${process.execPath}`,
@@ -94,7 +96,7 @@ export function registerDoctorCommand(program) {
94
96
  `versions: ${versionsDir()}`,
95
97
  `linked: ${installedVersion() ?? "(none — the launcher is not ours; `dreamlake` may resolve elsewhere)"}`,
96
98
  `native: ${isNativeInstall() ? "yes" : "no"}`,
97
- `on PATH: ${shadow ?? `${launcherPath()} (ours)`}`,
99
+ `on PATH: ${shadow ?? (found ? `${found} (ours)` : "launcher is not available on the current PATH")}`,
98
100
  "",
99
101
  updateStatus(),
100
102
  ];
@@ -4,7 +4,7 @@ export interface InstallResult {
4
4
  /** Previous version the launcher pointed at, if any. */
5
5
  previous: string | null;
6
6
  launcher: string;
7
- /** Set when ~/.local/bin is not yet on PATH and we edited a shell rc. */
7
+ /** Shell edits, skipped setup, and instructions for the calling shell. */
8
8
  pathAdvice: string | null;
9
9
  /** Set when the version is frozen rather than following a channel. */
10
10
  pinned: string | null;
@@ -43,11 +43,15 @@ export declare function installedVersion(): string | null;
43
43
  * failure mode tells you nothing at all.
44
44
  */
45
45
  export declare function shadowingBinary(): string | null;
46
+ /** First executable on PATH, including user-created aliases to our launcher. */
47
+ export declare function binaryOnPath(): string | null;
46
48
  export interface InstallOptions {
47
49
  /** Unattended run by the detached auto-updater: no progress output (it
48
50
  * has no terminal of its own to draw on), and yield to anything the
49
51
  * user did explicitly while the download was in flight. */
50
52
  background?: boolean;
53
+ /** Explicit install only; updates must not edit shell configuration. */
54
+ modifyPath?: boolean;
51
55
  }
52
56
  export declare function performInstall(target?: string, opts?: InstallOptions): Promise<InstallResult>;
53
57
  /**
@@ -8,8 +8,9 @@
8
8
  // instead of requiring every user to re-curl a new script.
9
9
  import { spawnSync } from "node:child_process";
10
10
  import { createHash } from "node:crypto";
11
- import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync, } from "node:fs";
11
+ import { accessSync, constants, statSync, chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync, } from "node:fs";
12
12
  import { homedir } from "node:os";
13
+ import { binOnPath, configureShellPath } from "./shell-path.js";
13
14
  import path from "node:path";
14
15
  import { binDir, canonical, isWindows, launcherPath, versionFromEntry, versionPath, versionsDir, } from "./paths.js";
15
16
  import { compareVersions, detectPlatform, downloadBinary, fetchManifest, isChannel, resolveChannel, VERSION_RE, } from "./releases.js";
@@ -217,48 +218,6 @@ function prune(keep) {
217
218
  }
218
219
  }
219
220
  // ─── PATH setup ──────────────────────────────────────────────────────
220
- const PATH_MARKER = "# added by the dreamlake installer";
221
- function onPath(dir) {
222
- const entries = (process.env.PATH ?? "").split(path.delimiter).filter(Boolean);
223
- return entries.some((e) => path.resolve(e) === path.resolve(dir));
224
- }
225
- /**
226
- * Config file for the user's login shell, plus the syntax to extend PATH in
227
- * it. Only the active shell is touched: appending to every rc we can find
228
- * means fish users get a line in ~/.bashrc that fish never reads, and
229
- * everyone gets four blocks to clean up at uninstall time for one install.
230
- */
231
- function shellRc() {
232
- const home = homedir();
233
- const shell = path.basename(process.env.SHELL ?? "");
234
- if (shell === "fish") {
235
- return {
236
- file: path.join(home, ".config", "fish", "config.fish"),
237
- // fish_add_path is already a no-op when the entry is present.
238
- line: `\n${PATH_MARKER}\nfish_add_path "$HOME/.local/bin"\n`,
239
- };
240
- }
241
- // Guarded, so re-sourcing the rc in a live shell does not prepend a
242
- // second copy. An unguarded `export PATH=...:$PATH` grows PATH every
243
- // time the file is sourced, and `where dreamlake` starts listing the
244
- // same binary twice. Same shape uv uses in ~/.local/bin/env.
245
- const posixLine = `\n${PATH_MARKER}\n` +
246
- `case ":$PATH:" in\n` +
247
- ` *":$HOME/.local/bin:"*) ;;\n` +
248
- ` *) export PATH="$HOME/.local/bin:$PATH" ;;\n` +
249
- `esac\n`;
250
- if (shell === "zsh")
251
- return { file: path.join(home, ".zshrc"), line: posixLine };
252
- if (shell === "bash") {
253
- // bash reads .bash_profile for login shells and .bashrc otherwise;
254
- // prefer whichever already exists so we extend the user's setup
255
- // instead of creating a second file that shadows it.
256
- const profile = path.join(home, ".bash_profile");
257
- const rc = path.join(home, ".bashrc");
258
- return { file: existsSync(rc) || !existsSync(profile) ? rc : profile, line: posixLine };
259
- }
260
- return { file: path.join(home, ".profile"), line: posixLine };
261
- }
262
221
  /**
263
222
  * Add binDir() to the user's persistent PATH on Windows, via the registry
264
223
  * environment block that PowerShell exposes.
@@ -285,39 +244,6 @@ function ensureOnPathWindows() {
285
244
  return [];
286
245
  return res.stdout?.includes("added") ? ["your user PATH"] : [];
287
246
  }
288
- /**
289
- * Put ~/.local/bin on PATH for the next login shell. Returns the files
290
- * touched (at most one). Idempotent via PATH_MARKER — re-running the
291
- * installer does not stack up duplicate exports.
292
- */
293
- function ensureOnPath() {
294
- if (isWindows)
295
- return onPath(binDir()) ? [] : ensureOnPathWindows();
296
- const { file, line } = shellRc();
297
- let current = "";
298
- try {
299
- current = readFileSync(file, "utf8");
300
- }
301
- catch {
302
- /* new file */
303
- }
304
- if (current.includes(PATH_MARKER)) {
305
- // Earlier versions wrote an unguarded export, which prepends again on
306
- // every `source ~/.zshrc`. Upgrade our own block in place; leaving it
307
- // means the duplicate never goes away for anyone already installed.
308
- const legacy = `${PATH_MARKER}\nexport PATH="$HOME/.local/bin:$PATH"\n`;
309
- if (current.includes(legacy)) {
310
- writeFileSync(file, current.replace(legacy, line.replace(/^\n/, "")));
311
- return [file];
312
- }
313
- return [];
314
- }
315
- if (onPath(binDir()))
316
- return [];
317
- mkdirSync(path.dirname(file), { recursive: true });
318
- writeFileSync(file, current + line);
319
- return [file];
320
- }
321
247
  /**
322
248
  * The `dreamlake` the user's current PATH would actually run, when that is
323
249
  * something other than the launcher we manage.
@@ -329,15 +255,23 @@ function ensureOnPath() {
329
255
  * failure mode tells you nothing at all.
330
256
  */
331
257
  export function shadowingBinary() {
258
+ const candidate = binaryOnPath();
259
+ return candidate && canonical(candidate) !== canonical(launcherPath()) ? candidate : null;
260
+ }
261
+ /** First executable on PATH, including user-created aliases to our launcher. */
262
+ export function binaryOnPath() {
332
263
  const exe = isWindows ? "dreamlake.exe" : "dreamlake";
333
- const ours = canonical(launcherPath());
334
264
  for (const dir of (process.env.PATH ?? "").split(path.delimiter)) {
335
265
  if (!dir)
336
266
  continue;
337
267
  const candidate = path.join(dir, exe);
338
- if (!existsSync(candidate))
339
- continue;
340
- return canonical(candidate) === ours ? null : candidate;
268
+ try {
269
+ if (!statSync(candidate).isFile())
270
+ continue;
271
+ accessSync(candidate, constants.X_OK);
272
+ return candidate;
273
+ }
274
+ catch { /* absent or not executable */ }
341
275
  }
342
276
  return null;
343
277
  }
@@ -372,7 +306,19 @@ export async function performInstall(target, opts = {}) {
372
306
  // a long-lived session does not lose its own executable mid-run.
373
307
  const running = installedVersion();
374
308
  prune([version, ...(running ? [running] : []), ...(previous ? [previous] : [])].filter(Boolean));
375
- const touched = ensureOnPath();
309
+ let pathAdvice = null;
310
+ if (!opts.background && opts.modifyPath !== undefined && !conflict) {
311
+ const modify = opts.modifyPath && process.env.DREAMLAKE_INSTALL_NO_MODIFY_PATH !== "1";
312
+ if (isWindows) {
313
+ const touched = modify ? ensureOnPathWindows() : [];
314
+ pathAdvice = !modify ? "User PATH setup skipped (--no-modify-path or DREAMLAKE_INSTALL_NO_MODIFY_PATH=1)."
315
+ : touched.length ? "Added ~/.local/bin to your user PATH. Open a new terminal to use it."
316
+ : binOnPath() ? null : "Could not confirm user PATH setup. Add ~/.local/bin to your user PATH and open a new terminal.";
317
+ }
318
+ else {
319
+ pathAdvice = configureShellPath(modify);
320
+ }
321
+ }
376
322
  // Only meaningful once the launcher is really ours; a conflict there is
377
323
  // reported on its own and would otherwise produce two warnings for one
378
324
  // problem.
@@ -384,11 +330,7 @@ export async function performInstall(target, opts = {}) {
384
330
  pinned: channel ? null : version,
385
331
  launcherConflict: conflict,
386
332
  shadowedBy,
387
- pathAdvice: touched.length
388
- ? `Added ~/.local/bin to PATH in ${touched.map((f) => f.replace(homedir(), "~")).join(", ")} — open a new shell or run: export PATH="$HOME/.local/bin:$PATH"`
389
- : onPath(binDir())
390
- ? null
391
- : `~/.local/bin is not on your PATH — add it with: export PATH="$HOME/.local/bin:$PATH"`,
333
+ pathAdvice,
392
334
  };
393
335
  }
394
336
  /**
@@ -0,0 +1,4 @@
1
+ export declare function binOnPath(): boolean;
2
+ /** No prompts: --no-modify-path / DREAMLAKE_INSTALL_NO_MODIFY_PATH=1 opt out
3
+ * equally in terminals, curl pipelines, and unattended provisioning. */
4
+ export declare function configureShellPath(modify?: boolean): string;
@@ -0,0 +1,135 @@
1
+ // Persistent PATH setup is an explicit install operation, never an updater task.
2
+ import { closeSync, constants, existsSync, fstatSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, writeSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import path from "node:path";
5
+ import { binDir } from "./paths.js";
6
+ const MARKER = "# added by the dreamlake installer";
7
+ const POSIX = `${MARKER}\ncase ":$PATH:" in\n *":$HOME/.local/bin:"*) ;;\n *) export PATH="$HOME/.local/bin\${PATH:+:$PATH}" ;;\nesac\n`;
8
+ const LEGACY = `${MARKER}\nexport PATH="$HOME/.local/bin:$PATH"\n`;
9
+ const FISH = `${MARKER}\nif not contains -- "$HOME/.local/bin" $PATH\n set -gx PATH "$HOME/.local/bin" $PATH\nend\n`;
10
+ export function binOnPath() {
11
+ return (process.env.PATH ?? "").split(path.delimiter).filter(Boolean)
12
+ .some((entry) => path.resolve(entry) === path.resolve(binDir()));
13
+ }
14
+ /** Never execute user startup files to discover configuration. SHELL describes
15
+ * the user's shell, even when the bootstrap itself runs through piped bash. */
16
+ function startupFiles(shell) {
17
+ const home = homedir();
18
+ switch (shell) {
19
+ case "bash": {
20
+ // Creating .bash_profile unconditionally would hide .bash_login/.profile.
21
+ const login = [".bash_profile", ".bash_login", ".profile"]
22
+ .map((name) => path.join(home, name)).find((file) => {
23
+ try {
24
+ lstatSync(file);
25
+ return true;
26
+ }
27
+ catch (err) {
28
+ if (err.code === "ENOENT")
29
+ return false;
30
+ throw err;
31
+ }
32
+ }) ?? path.join(home, ".profile");
33
+ return [login, path.join(home, ".bashrc")];
34
+ }
35
+ case "zsh": {
36
+ const dir = process.env.ZDOTDIR || home;
37
+ if (!path.isAbsolute(dir))
38
+ throw new Error("ZDOTDIR must be absolute for automatic setup");
39
+ return [path.join(dir, ".zprofile"), path.join(dir, ".zshrc")];
40
+ }
41
+ case "fish": {
42
+ const xdg = process.env.XDG_CONFIG_HOME;
43
+ const config = xdg && path.isAbsolute(xdg) ? xdg : path.join(home, ".config");
44
+ return [path.join(config, "fish", "conf.d", "dreamlake-path.fish")];
45
+ }
46
+ case "sh":
47
+ case "dash": return [path.join(home, ".profile")];
48
+ default: return [];
49
+ }
50
+ }
51
+ /** Append without replacing user bytes or following a dotfile symlink. A
52
+ * customized marker is deliberately not a license to rewrite the user's code.
53
+ * Refuse special files and files belonging to another account, even as root. */
54
+ function configureFile(file, block) {
55
+ if (existsSync(file) && !lstatSync(file).isFile()) {
56
+ throw new Error("not a regular file (symlink/custom setup left unchanged)");
57
+ }
58
+ // Require an owned directory before creating missing configuration folders.
59
+ // Explicit XDG_CONFIG_HOME/ZDOTDIR may live outside HOME.
60
+ let parent = path.dirname(file);
61
+ while (!existsSync(parent))
62
+ parent = path.dirname(parent);
63
+ const info = lstatSync(parent);
64
+ if (!info.isDirectory() || (process.getuid && info.uid !== process.getuid())) {
65
+ throw new Error("configuration directory is not an owned directory");
66
+ }
67
+ mkdirSync(path.dirname(file), { recursive: true });
68
+ const fd = openSync(file, constants.O_RDWR | constants.O_CREAT | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o644);
69
+ try {
70
+ const stat = fstatSync(fd);
71
+ if (!stat.isFile() || (process.getuid && stat.uid !== process.getuid())) {
72
+ throw new Error("configuration is not an owned regular file");
73
+ }
74
+ const current = readFileSync(fd, "utf8");
75
+ if (current.includes(LEGACY)) {
76
+ const next = Buffer.from(current.replace(LEGACY, block));
77
+ writeSync(fd, next, 0, next.length, 0);
78
+ ftruncateSync(fd, next.length);
79
+ return true;
80
+ }
81
+ if (current.includes(MARKER)) {
82
+ // Recognize both the current block and the prior guarded POSIX block.
83
+ const previous = POSIX.replace('${PATH:+:$PATH}', ':$PATH');
84
+ if (current.includes(block) || (block === POSIX && current.includes(previous)))
85
+ return false;
86
+ throw new Error("customized DreamLake PATH block left unchanged; review it manually");
87
+ }
88
+ const suffix = Buffer.from(`${current && !current.endsWith("\n") ? "\n" : ""}\n${block}`);
89
+ writeSync(fd, suffix, 0, suffix.length, stat.size);
90
+ return true;
91
+ }
92
+ finally {
93
+ closeSync(fd);
94
+ }
95
+ }
96
+ /** No prompts: --no-modify-path / DREAMLAKE_INSTALL_NO_MODIFY_PATH=1 opt out
97
+ * equally in terminals, curl pipelines, and unattended provisioning. */
98
+ export function configureShellPath(modify = true) {
99
+ const shell = path.basename(process.env.SHELL ?? "");
100
+ const supported = ["bash", "zsh", "fish", "sh", "dash"].includes(shell);
101
+ const lines = [];
102
+ if (!modify) {
103
+ lines.push("Shell PATH setup skipped (--no-modify-path or DREAMLAKE_INSTALL_NO_MODIFY_PATH=1).");
104
+ }
105
+ else if (!supported) {
106
+ lines.push(`No automatic PATH setup for SHELL=${process.env.SHELL || "(unset)"}. Add ~/.local/bin using your shell's PATH configuration.`);
107
+ }
108
+ else {
109
+ try {
110
+ for (const file of startupFiles(shell)) {
111
+ try {
112
+ const changed = configureFile(file, shell === "fish" ? FISH : POSIX);
113
+ lines.push(`${changed ? "Updated" : "Already configured"} PATH: ${file}`);
114
+ }
115
+ catch (err) {
116
+ lines.push(`Could not configure PATH in ${file}: ${err.message}. Add ~/.local/bin there manually.`);
117
+ }
118
+ }
119
+ }
120
+ catch (err) {
121
+ lines.push(`Could not configure shell PATH: ${err.message}.`);
122
+ }
123
+ }
124
+ if (supported) {
125
+ const command = shell === "fish"
126
+ ? 'contains -- "$HOME/.local/bin" $PATH; or set -gx PATH "$HOME/.local/bin" $PATH'
127
+ : 'case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) export PATH="$HOME/.local/bin${PATH:+:$PATH}" ;; esac';
128
+ lines.push(`The installer cannot change the calling shell. For this ${shell} session, run:\n ${command}`);
129
+ lines.push(shell === "sh" || shell === "dash"
130
+ ? "The .profile setup applies to login shells only."
131
+ : "Configured startup files take effect in new shells that read them; later user PATH assignments can override them.");
132
+ }
133
+ lines.push('For noninteractive SSH commands, services, or shells that skip startup files, set PATH explicitly or use "$HOME/.local/bin/dreamlake".');
134
+ return lines.join("\n");
135
+ }
@@ -1,16 +1,11 @@
1
- // `dreamlake update bindr|dataset <name> --project <target> [--add <glob>]
2
- // [--remove <glob>] [--add-note <note>] [--description] [--tags]`.
3
- // Port of dreamlake-py's cli/commands/update.py.
4
- //
5
- // bindr — add/remove EPISODES (matched by node-path glob), or tag one
6
- // NOTE's node in the project (--add-note)
7
- // dataset — add/remove BINDRS (matched by name glob)
1
+ import { bindrsApi } from "../../api/bindrs.js";
2
+ import { createTransport } from "../../api/client.js";
8
3
  import { HttpError, requestJson } from "../client.js";
9
4
  import { resolveNamespace, resolveRemote, resolveToken } from "../config.js";
10
5
  import { fail, ok, splitCsv } from "../helpers.js";
11
6
  import { resolveNote, seg } from "../memos/index.js";
12
7
  import { memoProjectNode } from "../memos/move-command.js";
13
- import { fetchAllBindrs, fetchAllEpisodes, matchBindrs, matchEpisodes, resolveProjectCtx, } from "../resources.js";
8
+ import { fetchAllBindrs, fetchAllEpisodes, matchBindrs, matchEpisodes, resolveProjectCtx, resolveBindr, } from "../resources.js";
14
9
  import { formatProject } from "../target.js";
15
10
  function nothingToDo(opts) {
16
11
  return !opts.add && !opts.remove && !opts.addNote && opts.description === undefined && opts.tags === undefined;
@@ -51,75 +46,44 @@ export async function runUpdateBindr(name, opts) {
51
46
  return 1;
52
47
  const { s, token, remote } = ctx;
53
48
  const proj = formatProject(s);
54
- const base = `/namespaces/${s.namespace}/projects/${s.project}/bindrs/${name}`;
55
- if (opts.addNote) {
56
- try {
57
- const bindr = (await fetchAllBindrs(remote, s.namespace, s.project, token)).find((b) => b.name === name);
58
- if (!bindr) {
59
- fail(`bindr '${name}' not found in ${proj}`);
60
- return 1;
61
- }
49
+ try {
50
+ const bindr = await resolveBindr(ctx, name);
51
+ const base = `/bindrs/${seg(bindr.id)}`;
52
+ const api = bindrsApi(createTransport({ remote, token }), s.namespace, s.project);
53
+ const episodes = opts.add || opts.remove
54
+ ? await fetchAllEpisodes(remote, s.namespace, s.project, token, { includeArchived: true }) : [];
55
+ const toAdd = opts.add ? matchEpisodes(episodes, opts.add) : [];
56
+ const toRemove = opts.remove ? matchEpisodes(episodes, opts.remove) : [];
57
+ // Resolve every selector before the first write, including combined operations.
58
+ if (opts.add && !toAdd.length)
59
+ throw new Error(`no episodes match '${opts.add}'`);
60
+ if (opts.remove && !toRemove.length)
61
+ throw new Error(`no episodes match '${opts.remove}'`);
62
+ let noteNode;
63
+ if (opts.addNote) {
62
64
  const noteId = await resolveNote({ remote, token, ns: s.namespace }, opts.addNote);
63
65
  if (!noteId)
64
66
  return 1;
65
- const node = await memoProjectNode(remote, token, s.namespace, noteId, s.project);
66
- // Idempotent on the server: re-tagging an already-tagged node changes nothing.
67
- const res = await requestJson(remote, `/bindrs/${seg(bindr.id)}/members`, {
68
- method: "POST",
69
- token,
70
- json: { nodeId: node.id },
71
- });
72
- ok(`Tagged memo '${node.name}' with bindr ${name} → ${res.memberCount ?? "?"} total members`);
67
+ noteNode = await memoProjectNode(remote, token, s.namespace, noteId, s.project);
73
68
  }
74
- catch (err) {
75
- fail(err.message);
76
- return 1;
69
+ if (noteNode) {
70
+ const res = await api.addMember(bindr.id, noteNode.id);
71
+ ok(`Tagged memo '${noteNode.name}' with bindr ${name} → ${res.memberCount} total members`);
77
72
  }
78
- }
79
- const episodes = opts.add || opts.remove ? await fetchAllEpisodes(remote, s.namespace, s.project, token, { includeArchived: true }) : [];
80
- try {
81
- if (opts.add) {
82
- const toAdd = matchEpisodes(episodes, opts.add);
83
- if (toAdd.length === 0) {
84
- fail(`no episodes match '${opts.add}'`);
85
- return 1;
86
- }
87
- process.stdout.write(`Adding ${toAdd.length} episode(s) matching '${opts.add}':\n`);
88
- for (const ep of toAdd)
89
- process.stdout.write(` ${ep.nodePath ?? ep.name ?? ""}\n`);
90
- const res = await requestJson(remote, `${base}/members`, {
91
- method: "POST",
92
- token,
93
- json: { add: toAdd.map((e) => e.id) },
94
- });
95
- ok(`Added ${toAdd.length} → ${res.total ?? "?"} total members`);
73
+ if (toAdd.length) {
74
+ const res = await api.addMembers(bindr.id, toAdd.map(ep => ep.id));
75
+ ok(`Tagged ${res.completedNodeIds.length} episode(s) → ${res.memberCount} total members`);
96
76
  }
97
- if (opts.remove) {
98
- const toRemove = matchEpisodes(episodes, opts.remove);
99
- if (toRemove.length === 0) {
100
- fail(`no episodes match '${opts.remove}'`);
101
- return 1;
102
- }
103
- process.stdout.write(`Removing ${toRemove.length} episode(s) matching '${opts.remove}':\n`);
104
- for (const ep of toRemove)
105
- process.stdout.write(` ${ep.nodePath ?? ep.name ?? ""}\n`);
106
- const res = await requestJson(remote, `${base}/members`, {
107
- method: "DELETE",
108
- token,
109
- json: { remove: toRemove.map((e) => e.id) },
110
- });
111
- ok(`Removed ${toRemove.length} → ${res.total ?? "?"} total members`);
77
+ if (toRemove.length) {
78
+ const res = await api.removeMembers(bindr.id, toRemove.map(ep => ep.id));
79
+ ok(`Untagged ${res.completedNodeIds.length} episode(s) → ${res.memberCount} total members`);
112
80
  }
81
+ return (await patchMetadata(remote, base, token, opts, "bindr", name, proj)) ? 0 : 1;
113
82
  }
114
83
  catch (err) {
115
- if (err instanceof HttpError && err.status === 404) {
116
- fail(`bindr '${name}' not found in ${proj}`);
117
- return 1;
118
- }
119
84
  fail(err.message);
120
85
  return 1;
121
86
  }
122
- return (await patchMetadata(remote, base, token, opts, "bindr", name, proj)) ? 0 : 1;
123
87
  }
124
88
  export async function runUpdateDataset(name, opts) {
125
89
  if (!opts.project) {
@@ -1 +1 @@
1
- export declare const VERSION = "0.107.1";
1
+ export declare const VERSION = "0.108.0";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.107.1";
9
+ export const VERSION = "0.108.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.107.1",
3
+ "version": "0.108.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -36,13 +36,13 @@
36
36
  "node": ">=18"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@dreamlake/dreamlake-cli-darwin-arm64": "0.107.1",
40
- "@dreamlake/dreamlake-cli-darwin-x64": "0.107.1",
41
- "@dreamlake/dreamlake-cli-linux-x64": "0.107.1",
42
- "@dreamlake/dreamlake-cli-linux-arm64": "0.107.1",
43
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.107.1",
44
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.107.1",
45
- "@dreamlake/dreamlake-cli-win32-x64": "0.107.1",
46
- "@dreamlake/dreamlake-cli-win32-arm64": "0.107.1"
39
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.108.0",
40
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.108.0",
41
+ "@dreamlake/dreamlake-cli-linux-x64": "0.108.0",
42
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.108.0",
43
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.108.0",
44
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.108.0",
45
+ "@dreamlake/dreamlake-cli-win32-x64": "0.108.0",
46
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.108.0"
47
47
  }
48
48
  }