@dreamlake/dreamlake-cli 0.107.0 → 0.107.2

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.
@@ -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
+ }
package/dist/cli/share.js CHANGED
@@ -10,7 +10,7 @@ export async function runShare(kind, operation, ref, opts) {
10
10
  fail("--role must be read or write");
11
11
  return 1;
12
12
  }
13
- const visibilities = kind === "artifact" ? ["private", "public", "unlisted"] : ["private", "public"];
13
+ const visibilities = ["private", "public", "unlisted"];
14
14
  if (operation === "visibility" && !visibilities.includes(opts.visibility ?? "")) {
15
15
  fail(`visibility must be ${visibilities.join(", ")}`);
16
16
  return 1;
@@ -96,7 +96,7 @@ export async function runShare(kind, operation, ref, opts) {
96
96
  const url = `${webBase(c.remote)}/${encodeURIComponent(ns)}/${kind === "notes" ? "notes" : "artifacts"}/${encodeURIComponent(urlId)}`;
97
97
  const result = {
98
98
  url, visibility: row.visibility,
99
- publicUrl: row.visibility === "public" || (kind === "artifact" && row.visibility === "unlisted") ? url : null,
99
+ publicUrl: row.visibility === "public" || row.visibility === "unlisted" ? url : null,
100
100
  shareUrl: row.shareToken ? `${url}?share=${encodeURIComponent(row.shareToken)}` : null,
101
101
  shareRole: kind === "notes" ? row.shareRole ?? null : row.shareToken ? "read" : null,
102
102
  // An omitted token is redacted, not evidence that sharing is disabled.
@@ -136,7 +136,7 @@ export function registerShareCommands(parent, kind) {
136
136
  else
137
137
  cmd.action(async (ref, opts) => { process.exit(await runShare(kind, operation, ref, opts)); });
138
138
  }
139
- withConnFlags(parent.command("visibility").argument("<resource>").argument("<visibility>", kind === "artifact" ? "private, public or unlisted" : "private or public")
139
+ withConnFlags(parent.command("visibility").argument("<resource>").argument("<visibility>", "private, public or unlisted")
140
140
  .description("set read visibility; does not revoke share links or accepted access")
141
141
  .option("--namespace <slug>", "namespace").option("--json", "emit structured JSON"))
142
142
  .action(async (ref, visibility, opts) => { process.exit(await runShare(kind, "visibility", ref, { ...opts, visibility })); });
@@ -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.0";
1
+ export declare const VERSION = "0.107.2";
@@ -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.0";
9
+ export const VERSION = "0.107.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.107.0",
3
+ "version": "0.107.2",
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.0",
40
- "@dreamlake/dreamlake-cli-darwin-x64": "0.107.0",
41
- "@dreamlake/dreamlake-cli-linux-x64": "0.107.0",
42
- "@dreamlake/dreamlake-cli-linux-arm64": "0.107.0",
43
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.107.0",
44
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.107.0",
45
- "@dreamlake/dreamlake-cli-win32-x64": "0.107.0",
46
- "@dreamlake/dreamlake-cli-win32-arm64": "0.107.0"
39
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.107.2",
40
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.107.2",
41
+ "@dreamlake/dreamlake-cli-linux-x64": "0.107.2",
42
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.107.2",
43
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.107.2",
44
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.107.2",
45
+ "@dreamlake/dreamlake-cli-win32-x64": "0.107.2",
46
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.107.2"
47
47
  }
48
48
  }