@dreamlake/dreamlake-cli 0.108.0 → 0.110.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.
@@ -3,7 +3,7 @@ import { type MemoSource } from "./memo-edits.js";
3
3
  import * as editing from "./memo-editing.js";
4
4
  import { type MemoFocusedRead } from "./memo-reading.js";
5
5
  import { type MemoCommandStatus, type MemoWriteMode, type MemoWriteReceipt } from "./memo-write.js";
6
- import { type MemoRow, type MemosApi, type MemoVersion } from "./memos.js";
6
+ import { type MemoRow, type MemoPermalink, type MemosApi, type MemoVersion } from "./memos.js";
7
7
  /** `{note, content, hash, revision}`: four distinct values. A hash describes text; a revision is the write baseline. */
8
8
  export type MemoSnapshot = MemoSource;
9
9
  /** A qualified reference: the first `/` separates the lookup namespace from a 24-hex id or a slug. */
@@ -191,6 +191,10 @@ export interface MemoHandle {
191
191
  since: string;
192
192
  format?: "diff" | "inline-dff";
193
193
  }): Promise<MemoDiff>;
194
+ /** Get or allocate a public URL, or edit its slug; previous slugs remain reserved aliases. */
195
+ permalink(input?: {
196
+ slug?: string;
197
+ }): Promise<MemoPermalink>;
194
198
  presence(): Promise<unknown>;
195
199
  /** Announce the caller once. `address`/`cursor` locations are a documented target (UnsupportedTarget today). */
196
200
  visit(input?: MemoVisitInput): Promise<unknown>;
@@ -309,6 +309,7 @@ export function memoHandle(t, ref, context = {}) {
309
309
  return result;
310
310
  });
311
311
  },
312
+ async permalink(input = {}) { return guarded(async (api) => api.permalink(await id(api), input), "write"); },
312
313
  async presence() { return guarded(async (api) => api.presence(await id(api))); },
313
314
  async visit(input = {}) {
314
315
  if (input.address !== undefined || input.cursor !== undefined)
@@ -6,6 +6,14 @@ import { type MemoSource, type MemoEdit } from "./memo-edits.js";
6
6
  export { memoEdits, type MemoSource, type MemoEdit, type MemoPatch, noteEdits, type NoteSource, type NoteEdit, type NotePatch, } from "./memo-edits.js";
7
7
  import { type Transport } from "./client.js";
8
8
  import { type MemoPatchRequest, type MemoWriteReceipt, type MemoCommandStatus } from "./memo-write.js";
9
+ /** Current public URL and retained previous slugs. */
10
+ export interface MemoPermalink {
11
+ noteId: string;
12
+ namespaceSlug: string;
13
+ slug: string;
14
+ href: string;
15
+ aliases: string[];
16
+ }
9
17
  export interface MemoSearchHit {
10
18
  noteId: string;
11
19
  noteSlug: string;
@@ -150,6 +158,10 @@ export declare function memosApi(t: Transport, namespace: string): {
150
158
  projects: string[];
151
159
  dryRun?: boolean;
152
160
  }) => Promise<unknown>;
161
+ /** Get or allocate a public/unlisted URL; an explicit slug edits it and retains aliases. */
162
+ permalink: (noteId: string, input?: {
163
+ slug?: string;
164
+ }) => Promise<MemoPermalink>;
153
165
  share: (noteId: string) => {
154
166
  get: () => Promise<Record<string, unknown>>;
155
167
  create: (role?: "read" | "write") => Promise<unknown>;
package/dist/api/memos.js CHANGED
@@ -123,6 +123,8 @@ export function memosApi(t, namespace) {
123
123
  shared: (query = {}) => t.request("GET", "/me/notes/shared", { query }),
124
124
  projects: (noteId, view) => t.request("GET", `/namespaces/${namespaceSeg(namespace)}/resources/note/${id(noteId)}/projects`, { query: { view } }),
125
125
  move: (noteId, input) => t.request("POST", `${base}/${id(noteId)}/move`, { json: input }),
126
+ /** Get or allocate a public/unlisted URL; an explicit slug edits it and retains aliases. */
127
+ permalink: (noteId, input = {}) => t.request("POST", `${base}/${id(noteId)}/permalink`, { json: input, redirect: "error" }),
126
128
  share: (noteId) => sharingApi(t, namespace, "notes", id(noteId)),
127
129
  files: (noteId) => memoFilesApi(t, `${base}/${id(noteId)}`),
128
130
  media: async (form) => {
@@ -140,6 +140,7 @@ export const helpExamples = {
140
140
  "memos share revoke": "MEMO=\"release-plan\" # Your existing memo id or slug.\ndreamlake memos share revoke \"$MEMO\" --revoke-accepted",
141
141
  "memos share access": "MEMO=\"release-plan\" # Your existing memo id or slug.\n# List acceptance records and stored roles as a readable table.\ndreamlake memos share access \"$MEMO\"",
142
142
  "memos share remove": "MEMO=\"release-plan\" # Your existing memo id or slug.\nUSER_ID=\"user-id-from-access-list\"\ndreamlake memos share remove \"$MEMO\" \"$USER_ID\"",
143
+ "memos permalink": "dreamlake memos permalink <memo-id> --namespace <namespace> --json\ndreamlake memos permalink <memo-id> --namespace <namespace> --slug my-article --json",
143
144
  "memos suggest-diff": "# Review a change as a new private note.\ndreamlake memos suggest-diff before.md after.md --user \"Docs review\" \\\n | dreamlake memos create \"Redline: release plan\" --file -\n# Propose edits inside the note itself; refuses changes it cannot express.\ndreamlake memos suggest-diff current.md edited.md --in-place --user \"$DREAMLAKE_AGENT_NAME\" > proposal.md\n# Count insertions, deletions, replacements and changed code blocks.\ndreamlake memos suggest-diff before.md after.md --json | jq .stats",
144
145
  "memos transfer": "dreamlake memos transfer MEMO_ID --namespace alice --to acme \\\n --dry-run --out note-transfer.json\n# Submit the exact reviewed file; the authorized destination member accepts separately.\ndreamlake memos transfer MEMO_ID --namespace alice --to acme \\\n --confirm --request-file note-transfer.json\n# If you also have destination acceptance authority:\ndreamlake memos transfer MEMO_ID --namespace alice --to acme \\\n --confirm --request-file note-transfer.json --accept-if-authorized --wait",
145
146
  "memos tag": "# Save the current content on the existing Memo.\ndreamlake memos tag MEMO_ID end-of-day --namespace my-org --summary \"Reviewed today's actions\"\n# Require the hash retained from a reviewed full read (not its opaque revision).\ndreamlake memos tag MEMO_ID reviewed --hash sha256:CONTENT_HASH --json\n# Connect this checkpoint to an earlier version in the same Memo.\ndreamlake memos tag MEMO_ID next-checkpoint --parent VERSION_ID\n# Read and validate without creating a version.\ndreamlake memos tag MEMO_ID preview --dry-run --json",
@@ -4,6 +4,7 @@ import { collectionList } from "../collection-list.js";
4
4
  import { registerVersionCommands, runSavedVersionRead } from "./version-commands.js";
5
5
  import { registerMoveCommand } from "./move-command.js";
6
6
  import { registerTransferCommand } from "./transfer-command.js";
7
+ import { registerPermalinkCommand } from "./permalink-command.js";
7
8
  import { registerArchiveCommands } from "./archive-command.js";
8
9
  import { registerRmCommand } from "./rm-command.js";
9
10
  import { registerSuggestDiffCommand } from "./suggest-diff.js";
@@ -201,6 +202,7 @@ export function registerMemosCommand(program) {
201
202
  registerTransferCommand(notes);
202
203
  registerRmCommand(notes);
203
204
  registerArchiveCommands(notes);
205
+ registerPermalinkCommand(notes);
204
206
  registerSuggestDiffCommand(notes);
205
207
  // Same connection flags as the other ported groups, so --debug/--remote
206
208
  // behave identically across the CLI.
@@ -0,0 +1,7 @@
1
+ import type { Command } from 'commander';
2
+ import { type ConnOpts } from './index.js';
3
+ export declare function runMemosPermalink(ref: string, opts: ConnOpts & {
4
+ slug?: string;
5
+ json?: boolean;
6
+ }): Promise<number>;
7
+ export declare function registerPermalinkCommand(memos: Command): void;
@@ -0,0 +1,50 @@
1
+ import { memoHandle } from '../../api/memo-facade.js';
2
+ import { resolveCtx } from '../compat/ctx.js';
3
+ import { requireToken } from '../compat/http.js';
4
+ import { withConnFlags } from '../compat/flags.js';
5
+ import { emitJson, fail } from '../helpers.js';
6
+ import { memoTransport } from './api-transport.js';
7
+ import { ctx, resolveNote } from './index.js';
8
+ export async function runMemosPermalink(ref, opts) {
9
+ const c = resolveCtx(opts), token = requireToken(c);
10
+ if (!token)
11
+ return 1;
12
+ try {
13
+ let target = ref;
14
+ let namespace = opts.namespace?.trim().replace(/^@/, '') || undefined;
15
+ if (!/^[a-f0-9]{24}$/i.test(ref) && !ref.includes('/')) {
16
+ const scope = await ctx(opts);
17
+ if (!scope)
18
+ return 1;
19
+ const id = await resolveNote(scope, ref);
20
+ if (!id)
21
+ return 1;
22
+ target = id;
23
+ namespace = scope.ns;
24
+ }
25
+ const result = await memoHandle(memoTransport({ remote: c.remote, token }), target, { namespace })
26
+ .permalink(opts.slug === undefined ? {} : { slug: opts.slug });
27
+ if (opts.json)
28
+ emitJson(result);
29
+ else {
30
+ process.stdout.write(`${result.href}\n`);
31
+ for (const slug of result.aliases)
32
+ process.stdout.write(`Previous: ${slug}\n`);
33
+ }
34
+ return 0;
35
+ }
36
+ catch (error) {
37
+ // Reserved slugs are permanent conflicts, not RTC contention. Do not retry.
38
+ fail(error instanceof Error ? error.message : String(error));
39
+ return 1;
40
+ }
41
+ }
42
+ export function registerPermalinkCommand(memos) {
43
+ withConnFlags(memos.command('permalink').allowExcessArguments(false))
44
+ .description('get or allocate a public article URL, edit its slug, and list previous slugs')
45
+ .argument('<memo>', 'memo id, qualified reference, internal slug or exact title')
46
+ .option('--namespace <slug>', 'lookup namespace; with an id, asserts the owner')
47
+ .option('--slug <slug>', 'set the public URL slug; retain previous URLs')
48
+ .option('--json', 'emit current URL, namespace and alias history')
49
+ .action(async (memo, opts) => { process.exitCode = await runMemosPermalink(memo, opts); });
50
+ }
@@ -0,0 +1,9 @@
1
+ export interface AliasOptions {
2
+ bin: string;
3
+ /** Known installed binaries, including the previous version before pruning. */
4
+ versions: string[];
5
+ windows?: boolean;
6
+ searchPath?: string;
7
+ }
8
+ /** Return a warning when dl cannot be installed safely; never replace a foreign command. */
9
+ export declare function installAlias(opts: AliasOptions): string | null;
@@ -0,0 +1,86 @@
1
+ // A command on PATH, not a shell alias: works in scripts and every shell.
2
+ import { accessSync, constants, copyFileSync, lstatSync, readFileSync, readlinkSync, renameSync, rmSync, statSync, symlinkSync } from "node:fs";
3
+ import path from "node:path";
4
+ /** Return a warning when dl cannot be installed safely; never replace a foreign command. */
5
+ export function installAlias(opts) {
6
+ const windows = opts.windows ?? process.platform === "win32";
7
+ const launcher = path.join(opts.bin, windows ? "dreamlake.exe" : "dreamlake");
8
+ const alias = path.join(opts.bin, windows ? "dl.exe" : "dl");
9
+ const conflict = (file) => `Warning: dl was not configured because ${file} already exists. It was left unchanged. Use dreamlake, or rename the conflicting command and re-run dreamlake install.`;
10
+ const staging = `${alias}.new-${process.pid}`;
11
+ let staged = false;
12
+ try {
13
+ let existing;
14
+ try {
15
+ existing = lstatSync(alias);
16
+ }
17
+ catch (err) {
18
+ if (err.code !== "ENOENT")
19
+ throw err;
20
+ }
21
+ if (existing) {
22
+ if (windows) {
23
+ if (!existing.isFile() || existing.isSymbolicLink())
24
+ return conflict(alias);
25
+ const bytes = readFileSync(alias);
26
+ if (!opts.versions.some(file => bytes.equals(readFileSync(file))))
27
+ return conflict(alias);
28
+ }
29
+ else if (!existing.isSymbolicLink() || path.resolve(opts.bin, readlinkSync(alias)) !== launcher) {
30
+ return conflict(alias);
31
+ }
32
+ }
33
+ // Check all PATH entries before creating a new alias: PATH setup may prepend
34
+ // our bin directory, which would otherwise silently take over another dl.
35
+ const extensions = windows ? ["", ...new Set([".exe", ".cmd", ".bat", ".com", ".ps1", ...(process.env.PATHEXT ?? "").toLowerCase().split(";").filter(Boolean)])] : [""];
36
+ let other = null;
37
+ for (const dir of (opts.searchPath ?? process.env.PATH ?? "").split(windows ? ";" : ":")) {
38
+ for (const ext of extensions) {
39
+ const candidate = path.resolve(dir || ".", `dl${ext}`);
40
+ if (windows ? candidate.toLowerCase() === alias.toLowerCase() : candidate === alias)
41
+ continue;
42
+ try {
43
+ if (!statSync(candidate).isFile())
44
+ continue;
45
+ accessSync(candidate, windows ? constants.F_OK : constants.X_OK);
46
+ other = candidate;
47
+ break;
48
+ }
49
+ catch { /* absent or not executable */ }
50
+ }
51
+ if (other)
52
+ break;
53
+ }
54
+ if (other && !existing)
55
+ return conflict(other);
56
+ if (windows) {
57
+ // A copy needs no symlink privileges, preserves argv/stdio/exit status,
58
+ // and can be invoked directly by PowerShell, CMD, or another program.
59
+ copyFileSync(launcher, staging, constants.COPYFILE_EXCL);
60
+ staged = true;
61
+ try {
62
+ renameSync(staging, alias);
63
+ }
64
+ catch (err) {
65
+ if (!existing || !["EBUSY", "EPERM", "EACCES"].includes(err.code ?? ""))
66
+ throw err;
67
+ // dl self-update may be running this executable. Windows permits
68
+ // renaming that copy; the installer prunes it once its process exits.
69
+ renameSync(alias, `${alias}.old-${process.pid}`);
70
+ renameSync(staging, alias);
71
+ }
72
+ }
73
+ else if (!existing) {
74
+ // Exclusive creation also protects a command created since the check.
75
+ symlinkSync("dreamlake", alias);
76
+ }
77
+ return other ? `Warning: another dl is on PATH at ${other}. PATH order selects which runs; use ${alias} for DreamLake. Shell aliases and functions can also override dl.` : null;
78
+ }
79
+ catch (err) {
80
+ return `Warning: could not configure dl at ${alias}: ${err.message}. Use dreamlake and re-run dreamlake install after resolving this.`;
81
+ }
82
+ finally {
83
+ if (staged)
84
+ rmSync(staging, { force: true });
85
+ }
86
+ }
@@ -21,6 +21,8 @@ export function registerInstallCommand(program) {
21
21
  const converting = !isNativeInstall() && process.env.DREAMLAKE_BOOTSTRAP !== "1";
22
22
  const result = await performInstall(target, { modifyPath: opts.modifyPath });
23
23
  process.stdout.write(`Installed dreamlake ${result.version} → ${result.launcher}\n`);
24
+ if (!result.launcherConflict && !result.aliasWarning)
25
+ process.stdout.write("Also available as dl (same commands and settings).\n");
24
26
  if (converting) {
25
27
  process.stdout.write("This is now a native install under ~/.local; the copy you ran this from is untouched.\n");
26
28
  }
@@ -20,6 +20,7 @@ export interface InstallResult {
20
20
  * user ends up with `command not found` after a green checkmark.
21
21
  */
22
22
  launcherConflict: string | null;
23
+ aliasWarning: string | null;
23
24
  }
24
25
  /**
25
26
  * Resolve a user-supplied target into a concrete version. Accepts a channel
@@ -17,6 +17,7 @@ import { compareVersions, detectPlatform, downloadBinary, fetchManifest, isChann
17
17
  import { activeChannel, pinnedVersion, updatesDisabled, writeSettings } from "./settings.js";
18
18
  import { BytesProgress } from "../progress.js";
19
19
  import { VERSION } from "../version.js";
20
+ import { installAlias } from "./alias.js";
20
21
  /**
21
22
  * Resolve a user-supplied target into a concrete version. Accepts a channel
22
23
  * name or an exact version; a channel also becomes the saved default for
@@ -208,7 +209,7 @@ function prune(keep) {
208
209
  // Launchers renamed out of the way because Windows had them locked.
209
210
  try {
210
211
  for (const entry of readdirSync(binDir())) {
211
- if (/^dreamlake\.exe\.old-\d+$/.test(entry)) {
212
+ if (/^(dreamlake|dl)\.exe\.old-\d+$/.test(entry)) {
212
213
  rmSync(path.join(binDir(), entry), { force: true });
213
214
  }
214
215
  }
@@ -295,6 +296,7 @@ export async function performInstall(target, opts = {}) {
295
296
  throw new Error(`superseded by a pin to ${pinnedVersion()} set while downloading`);
296
297
  }
297
298
  const { previous, conflict } = linkLauncher(version);
299
+ const aliasWarning = conflict ? null : installAlias({ bin: binDir(), versions: listVersions().map(versionPath) });
298
300
  // Asking for an exact version pins it; asking for a channel resumes
299
301
  // following that channel. Without this the background updater would move
300
302
  // you straight off the version you just asked for.
@@ -329,6 +331,7 @@ export async function performInstall(target, opts = {}) {
329
331
  launcher: launcherPath(),
330
332
  pinned: channel ? null : version,
331
333
  launcherConflict: conflict,
334
+ aliasWarning,
332
335
  shadowedBy,
333
336
  pathAdvice,
334
337
  };
@@ -339,6 +342,7 @@ export async function performInstall(target, opts = {}) {
339
342
  */
340
343
  export function installWarnings(result) {
341
344
  const tilde = (p) => p.replace(homedir(), "~");
345
+ const aliasWarnings = result.aliasWarning ? [result.aliasWarning] : [];
342
346
  if (result.launcherConflict) {
343
347
  return [
344
348
  `Warning: ${tilde(result.launcherConflict)} already exists and is not a symlink we manage.`,
@@ -349,6 +353,7 @@ export function installWarnings(result) {
349
353
  }
350
354
  if (result.shadowedBy) {
351
355
  return [
356
+ ...aliasWarnings,
352
357
  `Warning: another dreamlake is earlier on your PATH and will keep running instead:`,
353
358
  ` ${tilde(result.shadowedBy)}`,
354
359
  `Installed ${result.version} at ${tilde(result.launcher)}.`,
@@ -356,7 +361,7 @@ export function installWarnings(result) {
356
361
  `or put ~/.local/bin ahead of it in PATH. Check with: dreamlake doctor`,
357
362
  ];
358
363
  }
359
- return [];
364
+ return aliasWarnings;
360
365
  }
361
366
  /** Newest version available on `channel`, or null when the check fails. */
362
367
  export async function latestAvailable(channel) {
@@ -1 +1 @@
1
- export declare const VERSION = "0.108.0";
1
+ export declare const VERSION = "0.110.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.108.0";
9
+ export const VERSION = "0.110.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.108.0",
3
+ "version": "0.110.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -8,7 +8,8 @@
8
8
  "homepage": "https://cli.dreamlake.ai",
9
9
  "description": "dreamlake — data-warehouse CLI. The `dreamlake` command uploads/downloads assets, manages episodes, bindrs, datasets, organizations and teams, and versions artifacts, workflow specs and pipelines against a DreamLake server + BSS.",
10
10
  "bin": {
11
- "dreamlake": "bin/dreamlake.js"
11
+ "dreamlake": "bin/dreamlake.js",
12
+ "dl": "bin/dreamlake.js"
12
13
  },
13
14
  "exports": {
14
15
  "./api": {
@@ -36,13 +37,13 @@
36
37
  "node": ">=18"
37
38
  },
38
39
  "optionalDependencies": {
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"
40
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.110.0",
41
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.110.0",
42
+ "@dreamlake/dreamlake-cli-linux-x64": "0.110.0",
43
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.110.0",
44
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.110.0",
45
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.110.0",
46
+ "@dreamlake/dreamlake-cli-win32-x64": "0.110.0",
47
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.110.0"
47
48
  }
48
49
  }