@dreamlake/dreamlake-cli 0.97.2 → 0.99.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 (70) hide show
  1. package/dist/api/client.d.ts +1 -1
  2. package/dist/api/client.js +4 -4
  3. package/dist/api/http.d.ts +48 -1
  4. package/dist/api/http.js +111 -4
  5. package/dist/api/index.d.ts +217 -511
  6. package/dist/api/index.js +12 -2
  7. package/dist/api/native-experiments.d.ts +77 -0
  8. package/dist/api/native-experiments.js +31 -0
  9. package/dist/api/note-edits.d.ts +40 -2
  10. package/dist/api/note-edits.js +197 -2
  11. package/dist/api/note-events.d.ts +40 -4
  12. package/dist/api/note-events.js +55 -2
  13. package/dist/api/note-facade.d.ts +268 -0
  14. package/dist/api/note-facade.js +376 -0
  15. package/dist/api/note-reading.d.ts +27 -0
  16. package/dist/api/note-reading.js +27 -0
  17. package/dist/api/note-write.d.ts +110 -0
  18. package/dist/api/note-write.js +217 -0
  19. package/dist/api/notes.d.ts +33 -44
  20. package/dist/api/notes.js +44 -34
  21. package/dist/api/sessions.d.ts +240 -7
  22. package/dist/api/sessions.js +56 -1
  23. package/dist/api/skills.d.ts +122 -0
  24. package/dist/api/skills.js +220 -0
  25. package/dist/cli/client.d.ts +2 -41
  26. package/dist/cli/client.js +13 -90
  27. package/dist/cli/experiments/index.js +2 -0
  28. package/dist/cli/experiments/native-commands.d.ts +13 -0
  29. package/dist/cli/experiments/native-commands.js +88 -0
  30. package/dist/cli/help-examples.generated.js +23 -6
  31. package/dist/cli/index.js +2 -0
  32. package/dist/cli/notes/api-transport.js +6 -6
  33. package/dist/cli/notes/document.d.ts +32 -26
  34. package/dist/cli/notes/document.js +150 -95
  35. package/dist/cli/notes/edit-commands.d.ts +26 -5
  36. package/dist/cli/notes/edit-commands.js +163 -36
  37. package/dist/cli/notes/events.d.ts +3 -33
  38. package/dist/cli/notes/events.js +4 -51
  39. package/dist/cli/notes/html-read.d.ts +6 -0
  40. package/dist/cli/notes/html-read.js +12 -0
  41. package/dist/cli/notes/index.d.ts +10 -1
  42. package/dist/cli/notes/index.js +98 -27
  43. package/dist/cli/notes/move-command.d.ts +4 -0
  44. package/dist/cli/notes/move-command.js +7 -0
  45. package/dist/cli/session-affiliation.js +3 -2
  46. package/dist/cli/sessions/affiliation.d.ts +12 -1
  47. package/dist/cli/sessions/affiliation.js +37 -0
  48. package/dist/cli/sessions/control.d.ts +11 -0
  49. package/dist/cli/sessions/control.js +49 -4
  50. package/dist/cli/sessions/index.js +70 -17
  51. package/dist/cli/sessions/live.d.ts +85 -0
  52. package/dist/cli/sessions/live.js +258 -0
  53. package/dist/cli/sessions/runner/exec.d.ts +118 -6
  54. package/dist/cli/sessions/runner/exec.js +298 -47
  55. package/dist/cli/sessions/runner/native.js +4 -1
  56. package/dist/cli/sessions/runner/serve.d.ts +37 -2
  57. package/dist/cli/sessions/runner/serve.js +273 -28
  58. package/dist/cli/sessions/wrap.d.ts +63 -0
  59. package/dist/cli/sessions/wrap.js +226 -0
  60. package/dist/cli/skill/index.d.ts +19 -1
  61. package/dist/cli/skill/index.js +65 -12
  62. package/dist/cli/skill/read.d.ts +25 -0
  63. package/dist/cli/skill/read.js +65 -0
  64. package/dist/cli/skill/registry.d.ts +95 -0
  65. package/dist/cli/skill/registry.js +284 -0
  66. package/dist/cli/skill/reminders.js +2 -1
  67. package/dist/cli/vault/sshTransfer.d.ts +1 -1
  68. package/dist/cli/version.d.ts +1 -1
  69. package/dist/cli/version.js +1 -1
  70. package/package.json +9 -9
@@ -18,8 +18,9 @@ import { runNotesTextSelect } from "./select-command.js";
18
18
  import { readFileSync } from "node:fs";
19
19
  import { runMediaUpload } from "./media-commands.js";
20
20
  import { runNotesLinger } from "./linger.js";
21
- import { runDocumentRead, runDocumentPatch, readDocumentSnapshot, readStdinBytes, documentInsertion, documentEdits, submitDocumentPatch, printPatchReceipt, documentWriteError } from "./document.js";
22
- import { characterDiff, NotePatchError, PATCH_LIMITS } from "./character-plan.js";
21
+ import { runDocumentRead, runDocumentPatch, runNotesCommandStatus, readDocumentSnapshot, readStdinBytes, submitDocumentPatch, printPatchReceipt, documentWriteError, commandIdFlag, withCommandId, canonicalInput } from "./document.js";
22
+ import { appendPlan, writePlan } from "../../api/note-write.js";
23
+ import { NotePatchError } from "./character-plan.js";
23
24
  import { HttpError, requestJson, requestRaw } from "../client.js";
24
25
  import { runNotesDelete, runNotesFind, runNotesInsert, runNotesReplace, runNotesGrep, runNotesSelect, runNotesToc, } from "./edit-commands.js";
25
26
  import { runFilesCat, runFilesPreview, runFilesCopy, runFilesDownload, runFilesList, runFilesMove, runFilesRestore, runFilesRm, runFilesUpload, runFilesWrite, runFilesOperation, } from "./files-commands.js";
@@ -125,7 +126,7 @@ export async function resolveNote(c, ref) {
125
126
  }
126
127
  /** Body text from --file, --text, or stdin. Exactly one, so an empty write is
127
128
  * always deliberate rather than the result of a forgotten flag. */
128
- async function bodyFrom(opts, nativeSourceStdin = false) {
129
+ export async function bodyFrom(opts, nativeSourceStdin = false) {
129
130
  const given = [opts.file, opts.text].filter((v) => v !== undefined).length;
130
131
  if (given > 1) {
131
132
  fail("pass one of --file or --text, not both");
@@ -220,11 +221,11 @@ export function registerNotesCommand(program) {
220
221
  strict(notes.command("projects"))
221
222
  .argument("<note-id>", "stable Note ID")
222
223
  .description("inspect current project filing and server-computed filing permissions (JSON)")
223
- .requiredOption("--namespace <slug>", "the Note's owning namespace")
224
+ .option("--namespace <slug>", "the Note's owning namespace (or --ns)")
224
225
  .action(async (id, opts) => { process.exitCode = await runNotesProjects(id, opts); });
225
226
  // ── notes create ──
226
227
  strict(notes.command("create"))
227
- .argument("<name>", "the note's title")
228
+ .argument("[name]", "the note's title (default: Untitled)")
228
229
  .description("create a note, optionally with a body")
229
230
  .option("--project <slug>", "file the new Note in this same-namespace project (repeatable)", (value, previous) => [...previous, value], [])
230
231
  .option("--file <path>", "initial body from a file ('-' for stdin)")
@@ -238,6 +239,7 @@ export function registerNotesCommand(program) {
238
239
  .description("list notes in one namespace")
239
240
  .option("--include-archived", "include archived notes")
240
241
  .option("--limit <n>", "page size", "50")
242
+ .option("--offset <n>", "skip this many rows first (zero-based paging: 0, 20, 40, …)")
241
243
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
242
244
  .option("--shared", "list notes other people shared with you, across namespaces")
243
245
  .option("--json", "emit JSON")
@@ -397,20 +399,21 @@ export function registerNotesCommand(program) {
397
399
  .action(async (ref, opts) => { process.exitCode = await runNotesSections(ref, opts); });
398
400
  // ── notes read ──
399
401
  strict(notes.command("read"))
400
- .option("--start-line <n>", "first line to read (1-based, inclusive)")
401
- .option("--end-line <n>", "last line to read (1-based, inclusive)")
402
+ .option("--lines <a:b>", "only these source lines (1-based, inclusive) with their code-point address; never a complete body")
403
+ .option("--start-line <n>", "legacy: first line to read (1-based, inclusive)")
404
+ .option("--end-line <n>", "legacy: last line to read (1-based, inclusive)")
402
405
  // Positional OR --note. The issue's examples use `--note`, matching the
403
406
  // edit commands; the positional came first and scripts use it. Accepting
404
407
  // one form and rejecting the other would make half the documented recipes
405
408
  // fail on a flag rather than on anything real.
406
409
  .argument("[note]", "note id, slug or name (or pass --note)")
407
410
  .option("--note <ref>", "the note to read, as an alternative to the positional")
408
- .description("read canonical source or a mapped HTML snapshot with its write revision")
411
+ .description("read the mapped Markdown view, exact canonical source (--json, --view source) or a mapped HTML snapshot with its write revision")
409
412
  .option("--linger", "stay present and stream batched diffs, presence and activity in the foreground")
410
413
  .option("--debounce <duration>", "edit quiet period with --linger (default 2s; 250ms–5m)")
411
414
  .option("--throttle <duration>", "minimum output interval with --linger (default 2s; 250ms–5m)")
412
415
  .option("--intent <text>", "with --linger: one short sentence of purpose, shown on your presence card")
413
- .option("--view <view>", "source (default), html with source attributes, or markdown with address hints")
416
+ .option("--view <view>", "markdown with address hints (default for text), source (exact; default for --json), or html with source attributes")
414
417
  .option("--version <version-id>", "read an immutable saved version instead of the live note")
415
418
  .option("--at <revision>", "read a retained snapshot without advancing to the current revision")
416
419
  .option("--toc", "read only the heading outline as mapped HTML")
@@ -448,6 +451,7 @@ export function registerNotesCommand(program) {
448
451
  .option("--legacy", "use the retained ETag/body replacement write")
449
452
  .option("--base-revision <revision>", "compare the target body to this original retained source snapshot")
450
453
  .option("--exact", "require the original revision to remain current")
454
+ .option("--command-id <id>", "caller-stable id (8–128 chars of A-Za-z0-9._:-); a retry with the same id returns the same receipt")
451
455
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
452
456
  .option("--json", "emit JSON")
453
457
  .option("--dry-run", "show the write that would be sent, and send nothing")
@@ -462,6 +466,7 @@ export function registerNotesCommand(program) {
462
466
  .option("--legacy", "use the retained ETag/body replacement append")
463
467
  .option("--base-revision <revision>", "append against this original retained source snapshot")
464
468
  .option("--exact", "require the original revision to remain current")
469
+ .option("--command-id <id>", "caller-stable id (8–128 chars of A-Za-z0-9._:-); a retry with the same id returns the same receipt")
465
470
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
466
471
  .option("--json", "emit JSON")
467
472
  .option("--dry-run", "show the write that would be sent, and send nothing")
@@ -469,7 +474,7 @@ export function registerNotesCommand(program) {
469
474
  // ── notes patch ──
470
475
  strict(notes.command("patch"))
471
476
  .argument("<note>", "note id, slug or name")
472
- .description("apply a source patch to its original RTC identities; merge by default, exact revision checks opt-in")
477
+ .description("apply a source patch to its original RTC identities; merge by default, exact revision checks opt-in (sends without reading: the reading-view header check is best-effort here, the server enforces it)")
473
478
  .option("--format <format>", "inline-dff (default) or diff")
474
479
  .option("--legacy", "use the previous unified diff/etag interface")
475
480
  .option("--file <path>", "read the diff from a file ('-' for stdin)")
@@ -477,6 +482,7 @@ export function registerNotesCommand(program) {
477
482
  .option("--exact", "require the current note to match the original revision for this request")
478
483
  .option("--base-revision <revision>", "original saved snapshot used to validate source and RTC identities")
479
484
  .option("--if-match <revision>", "compatibility exact-mode token; must match --base-revision when both are given")
485
+ .option("--command-id <id>", "caller-stable id (8–128 chars of A-Za-z0-9._:-); a retry with the same id returns the same receipt")
480
486
  .option("--force", "legacy only: apply without a precondition")
481
487
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
482
488
  .option("--json", "emit JSON")
@@ -509,21 +515,28 @@ export function registerNotesCommand(program) {
509
515
  .option("--regex <pattern>", "search with a JavaScript regular expression")
510
516
  .option("--flags <flags>", "regex flags: i, m, s, u (not g — see --all)")
511
517
  .option("--limit <n>", "stop after this many matches")
512
- .option("--json", "emit matches with the source revision")
518
+ .option("--at <revision>", "search the retained snapshot at this revision")
519
+ .option("--case-sensitive", "match case for a literal query (the default)")
520
+ .option("--no-case-sensitive", "ignore case for a literal query")
521
+ .option("--json", "emit matches with note, hash and the source revision")
513
522
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
514
523
  .action(async (query, opts) => { process.exitCode = await runNotesFind(query, opts); });
515
524
  strict(notes.command("toc"))
516
525
  .description("the note's outline, with line and character ranges")
517
526
  .option("--note <ref>", "the note: slug, id or exact title")
518
527
  .option("--html", "parse as HTML rather than Markdown")
519
- .option("--json", "emit entries with the source revision")
528
+ .option("--at <revision>", "outline the retained snapshot at this revision")
529
+ .option("--json", "emit entries with note, hash and the source revision")
520
530
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
521
531
  .action(async (opts) => { process.exitCode = await runNotesToc(opts); });
522
532
  strict(notes.command("replace"))
523
533
  .description("replace text; one match required unless --all or --count")
524
- .argument("[query]", "literal text to replace")
534
+ .argument("[query]", "literal text to replace (or the note ID when --lines/--address select the span)")
525
535
  .option("--note <ref>", "the note: slug, id or exact title")
526
536
  .option("--text <text>", "the replacement")
537
+ .option("--file <path>", "the replacement from a file ('-' for stdin), exact UTF-8")
538
+ .option("--lines <a:b>", "replace source lines a..b (1-based, inclusive)")
539
+ .option("--address <id>", "replace the full original span of this mapped element (e.g. s1.p2)")
527
540
  .option("--selector <css>", "scope the query to one HTML element")
528
541
  .option("--regex <pattern>", "match with a JavaScript regular expression")
529
542
  .option("--flags <flags>", "regex flags: i, m, s, u")
@@ -536,15 +549,21 @@ export function registerNotesCommand(program) {
536
549
  .option("--legacy", "use the retained ETag/body replacement replace")
537
550
  .option("--base-revision <revision>", "target this original retained source snapshot")
538
551
  .option("--exact", "require the original revision to remain current")
552
+ .option("--command-id <id>", "caller-stable id (8–128 chars of A-Za-z0-9._:-); a retry with the same id returns the same receipt")
539
553
  .option("--dry-run", "print what would be written and stop")
540
554
  .option("--json", "emit the new revision")
541
555
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
542
556
  .option("--html <markup>", "with --selector: replace the element's contents with markup (not escaped)")
543
557
  .action(async (query, opts) => { process.exitCode = await runNotesReplace(query, opts); });
544
558
  strict(notes.command("insert"))
545
- .description("insert text at a line or character position")
559
+ .description("insert text before/after a mapped element, at a cursor, or at a line")
560
+ .argument("[note]", "note id (alternative to --note)")
546
561
  .option("--note <ref>", "the note: slug, id or exact title")
547
- .option("--text <text>", "what to insert")
562
+ .option("--text <text>", "what to insert, verbatim")
563
+ .option("--file <path>", "what to insert from a file ('-' for stdin), exact UTF-8")
564
+ .option("--before <id>", "insert at the start of this mapped element's full original span")
565
+ .option("--after <id>", "insert at the end of this mapped element's full original span")
566
+ .option("--cursor <n>", "insert at this original code-point position (0-based)")
548
567
  .option("--line <n>", "insert before this line (1-based)")
549
568
  .option("--ind <n>", "insert at this character position (0-based code points)")
550
569
  .option("--if-match <etag>", "quoted ETag from notes read --legacy --json (not an rtc: revision)")
@@ -552,16 +571,20 @@ export function registerNotesCommand(program) {
552
571
  .option("--legacy", "use the retained ETag/body replacement insert")
553
572
  .option("--base-revision <revision>", "place text in this original retained source snapshot")
554
573
  .option("--exact", "require the original revision to remain current")
574
+ .option("--command-id <id>", "caller-stable id (8–128 chars of A-Za-z0-9._:-); a retry with the same id returns the same receipt")
555
575
  .option("--dry-run", "print what would be written and stop")
556
576
  .option("--json", "emit the new revision")
557
577
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
558
578
  .option("--selector <css>", "insert relative to this element instead of a line")
559
579
  .option("--position <where>", "with --selector: before | after | prepend | append", "append")
560
- .action(async (opts) => { process.exitCode = await runNotesInsert(opts); });
580
+ .action(async (note, opts) => { process.exitCode = await runNotesInsert(note, opts); });
561
581
  strict(notes.command("delete"))
562
- .description("remove text; one match required unless --all or --count")
563
- .argument("[query]", "literal text to remove")
582
+ .alias("remove")
583
+ .description("remove text (selected source, never the note); one match required unless --all or --count")
584
+ .argument("[query]", "literal text to remove (or the note ID when --lines/--address select the span)")
564
585
  .option("--note <ref>", "the note: slug, id or exact title")
586
+ .option("--lines <a:b>", "remove source lines a..b (1-based, inclusive)")
587
+ .option("--address <id>", "remove the full original span of this mapped element (e.g. s1.p2)")
565
588
  .option("--selector <css>", "scope the query to one HTML element")
566
589
  .option("--regex <pattern>", "match with a JavaScript regular expression")
567
590
  .option("--flags <flags>", "regex flags: i, m, s, u")
@@ -574,10 +597,18 @@ export function registerNotesCommand(program) {
574
597
  .option("--legacy", "use the retained ETag/body replacement delete")
575
598
  .option("--base-revision <revision>", "target this original retained source snapshot")
576
599
  .option("--exact", "require the original revision to remain current")
600
+ .option("--command-id <id>", "caller-stable id (8–128 chars of A-Za-z0-9._:-); a retry with the same id returns the same receipt")
577
601
  .option("--dry-run", "print what would be written and stop")
578
602
  .option("--json", "emit the new revision")
579
603
  .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
580
604
  .action(async (query, opts) => { process.exitCode = await runNotesDelete(query, opts); });
605
+ strict(notes.command("command-status"))
606
+ .argument("<note>", "note id, slug or name")
607
+ .argument("<command-id>", "the --command-id of an earlier write")
608
+ .description("the durable outcome of one identified write: pending, accepted, no-write or unknown")
609
+ .option("--namespace <slug>", "whose notes (default: your personal namespace, not an org's)")
610
+ .option("--json", "emit JSON")
611
+ .action(async (ref, commandId, opts) => { process.exitCode = await runNotesCommandStatus(ref, commandId, opts); });
581
612
  strict(notes.command("select"))
582
613
  .description("publish an agent selection with --text, or report one HTML element by CSS")
583
614
  .argument("[css]", "a CSS selector matching exactly one element (lookup only)")
@@ -606,6 +637,26 @@ export function registerNotesCommand(program) {
606
637
  .option("--json", "emit JSON")
607
638
  .option("--dry-run", "show the write that would be sent, and send nothing")
608
639
  .action(async (ref, anchor, opts) => { process.exitCode = await runNotesRmSection(ref, anchor, opts); });
640
+ addNamespaceAlias(notes);
641
+ }
642
+ /** `--ns` aliases `--namespace` on every Notes command that takes one (Notes API
643
+ * contract: both are source context, never a destination). Registered after the
644
+ * tree is complete so later-added subcommands are covered too. */
645
+ function addNamespaceAlias(group) {
646
+ for (const cmd of group.commands) {
647
+ if (cmd.options.some(o => o.long === "--namespace") && !cmd.options.some(o => o.long === "--ns")) {
648
+ cmd.option("--ns <slug>", "alias of --namespace: the source namespace to look in");
649
+ cmd.hook("preAction", thisCommand => {
650
+ const o = thisCommand.opts();
651
+ if (o.ns === undefined)
652
+ return;
653
+ if (o.namespace !== undefined && o.namespace !== o.ns)
654
+ thisCommand.error("--namespace and --ns name different namespaces; give one", { exitCode: 1 });
655
+ thisCommand.setOptionValue("namespace", o.ns);
656
+ });
657
+ }
658
+ addNamespaceAlias(cmd);
659
+ }
609
660
  }
610
661
  // ─── implementations ──────────────────────────────────────────────────────────
611
662
  export async function runNotesList(opts) {
@@ -615,7 +666,7 @@ export async function runNotesList(opts) {
615
666
  try {
616
667
  const rows = opts.shared
617
668
  ? (await requestJson(c.remote, "/me/notes/shared", { token: c.token, query: { includeArchived: opts.includeArchived } })).notes
618
- : (await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes?limit=${encodeURIComponent(opts.limit ?? "50")}${opts.includeArchived ? "&includeArchived=true" : ""}`, { token: c.token })).notes;
669
+ : (await requestJson(c.remote, `/namespaces/${seg(c.ns)}/notes?limit=${encodeURIComponent(opts.limit ?? "50")}${opts.offset !== undefined ? `&offset=${encodeURIComponent(opts.offset)}` : ""}${opts.includeArchived ? "&includeArchived=true" : ""}`, { token: c.token })).notes;
619
670
  if (opts.json)
620
671
  return emitJson({ notes: rows }), 0;
621
672
  if (rows.length === 0) {
@@ -823,8 +874,14 @@ export async function runNotesWrite(ref, opts) {
823
874
  fail("--section/--legacy/--force/--if-match cannot combine with --base-revision or --exact");
824
875
  return 1;
825
876
  }
877
+ if (opts.commandId !== undefined) {
878
+ fail("--command-id requires the v2 write; it cannot combine with --section, --legacy, --force or --if-match");
879
+ return 1;
880
+ }
826
881
  return runLegacyNotesWrite(ref, opts);
827
882
  }
883
+ if (!commandIdFlag(opts))
884
+ return 1;
828
885
  if (opts.baseRevision !== undefined && (!opts.baseRevision.trim() || opts.baseRevision === "*" || /[\r\n]/.test(opts.baseRevision))) {
829
886
  fail("--base-revision requires the original retained revision");
830
887
  return 1;
@@ -848,11 +905,7 @@ export async function runNotesWrite(ref, opts) {
848
905
  if (!id)
849
906
  return 1;
850
907
  const source = await readDocumentSnapshot(c, id, opts.baseRevision);
851
- const edits = characterDiff(source.content, text);
852
- const payload = documentEdits(source, edits.map(edit => ({ start: edit.start, end: edit.end, text: edit.replacementText })), opts.exact);
853
- if (edits.length > PATCH_LIMITS.maxEdits || Buffer.byteLength(payload.patch, "utf8") > PATCH_LIMITS.maxPatchBytes) {
854
- throw new NotePatchError("Generated source patch exceeds the edit/byte limit", "LIMIT_EXCEEDED");
855
- }
908
+ const payload = withCommandId(writePlan(source, text, opts.exact ? "exact" : "merge"), opts);
856
909
  if (opts.dryRun) {
857
910
  const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
858
911
  if (opts.json)
@@ -994,8 +1047,14 @@ export async function runNotesAppend(ref, opts) {
994
1047
  fail("--legacy/--force cannot combine with --base-revision or --exact");
995
1048
  return 1;
996
1049
  }
1050
+ if (opts.commandId !== undefined) {
1051
+ fail("--command-id requires the v2 write; it cannot combine with --legacy or --force");
1052
+ return 1;
1053
+ }
997
1054
  return runLegacyNotesAppend(ref, opts);
998
1055
  }
1056
+ if (!commandIdFlag(opts))
1057
+ return 1;
999
1058
  if (opts.baseRevision !== undefined && (!opts.baseRevision.trim() || opts.baseRevision === "*" || /[\r\n]/.test(opts.baseRevision))) {
1000
1059
  fail("--base-revision requires the original retained revision");
1001
1060
  return 1;
@@ -1006,16 +1065,18 @@ export async function runNotesAppend(ref, opts) {
1006
1065
  const addition = await bodyFrom(opts);
1007
1066
  if (addition === null)
1008
1067
  return 1;
1068
+ if (!canonicalInput(addition, "the text"))
1069
+ return 1;
1009
1070
  try {
1010
1071
  const id = await resolveNote(c, ref);
1011
1072
  if (!id)
1012
1073
  return 1;
1013
1074
  const current = await readDocumentSnapshot(c, id, opts.baseRevision);
1014
- const suffix = (current.content && !current.content.endsWith("\n") ? "\n" : "") + addition;
1015
1075
  const mode = opts.exact ? "exact" : "merge";
1076
+ const { suffix, request } = appendPlan(current, addition, mode);
1016
1077
  const headers = {};
1017
1078
  const path = `/namespaces/${seg(c.ns)}/notes/${seg(id)}/body`;
1018
- const payload = documentInsertion(current, Array.from(current.content).length, suffix, opts.exact);
1079
+ const payload = withCommandId(request, opts);
1019
1080
  if (opts.dryRun) {
1020
1081
  if (opts.json)
1021
1082
  emitJson({ dryRun: true, method: "PATCH", path, headers, payload, ...(suffix ? {} : { noChange: true }) });
@@ -1073,6 +1134,8 @@ async function runLegacyNotesAppend(ref, opts) {
1073
1134
  }
1074
1135
  }
1075
1136
  export async function runNotesCreate(name, opts) {
1137
+ // Notes API contract: the title is optional and an omitted one displays as Untitled.
1138
+ name ??= "Untitled";
1076
1139
  const c = await ctx(opts);
1077
1140
  if (!c)
1078
1141
  return 1;
@@ -1187,6 +1250,10 @@ export async function runNotesRmSection(ref, anchor, opts) {
1187
1250
  }
1188
1251
  /** Explicit compatibility keeps legacy body-only output and ETag semantics available. */
1189
1252
  export async function runNotesRead(ref, opts) {
1253
+ if (opts.lines !== undefined && (opts.legacy || opts.startLine !== undefined || opts.endLine !== undefined || opts.numbered || opts.linger || opts.version !== undefined)) {
1254
+ fail("--lines is the v2 line range of the live source; it cannot combine with --legacy, --start-line, --end-line, --numbered, --linger or --version");
1255
+ return 1;
1256
+ }
1190
1257
  if (opts.version !== undefined)
1191
1258
  return runSavedVersionRead(ref, opts);
1192
1259
  if (opts.linger)
@@ -1227,6 +1294,10 @@ export async function runNotesDiff(ref, opts) {
1227
1294
  return runDocumentRead(ref, opts);
1228
1295
  }
1229
1296
  export async function runNotesPatch(ref, opts) {
1297
+ if (opts.legacy && opts.commandId !== undefined) {
1298
+ fail("--command-id requires the v2 patch contract");
1299
+ return 1;
1300
+ }
1230
1301
  if (opts.legacy && (opts.baseRevision !== undefined || opts.exact)) {
1231
1302
  fail("--base-revision/--exact require the v2 patch contract");
1232
1303
  return 1;
@@ -1293,7 +1364,7 @@ export async function runNotesVisit(ref, opts) {
1293
1364
  export async function runNotesProjects(id, opts) {
1294
1365
  try {
1295
1366
  if (!/^[a-f0-9]{24}$/i.test(id) || !opts.namespace?.trim())
1296
- throw new Error('Use a stable Note ID and explicit --namespace');
1367
+ throw new Error('Use a stable Note ID and an explicit --namespace (or --ns)');
1297
1368
  const c = await ctx(opts);
1298
1369
  if (!c)
1299
1370
  return 1;
@@ -3,7 +3,11 @@ import { type ConnOpts } from "./index.js";
3
3
  export interface MoveOptions extends ConnOpts {
4
4
  toNamespace?: string;
5
5
  project?: string[];
6
+ /** Contract spelling of --project. */
7
+ toProject?: string[];
6
8
  folder?: string;
9
+ /** Contract spelling of --folder. */
10
+ toFolder?: string;
7
11
  dryRun?: boolean;
8
12
  json?: boolean;
9
13
  }
@@ -6,6 +6,11 @@ import { emitJson, fail } from "../helpers.js";
6
6
  import { resolveNote, seg } from "./index.js";
7
7
  /** Ownership changes never read or rewrite the collaborative body, nor retry a POST. */
8
8
  export async function runNotesMove(ref, opts) {
9
+ if (opts.folder !== undefined && opts.toFolder !== undefined && opts.folder !== opts.toFolder) {
10
+ fail("--folder and --to-folder name different folders; give one");
11
+ return 1;
12
+ }
13
+ opts = { ...opts, project: [...(opts.project ?? []), ...(opts.toProject ?? [])], folder: opts.folder ?? opts.toFolder };
9
14
  if (opts.folder !== undefined)
10
15
  return runNotesFolderMove(ref, opts);
11
16
  let attempted = false;
@@ -253,6 +258,8 @@ export function registerMoveCommand(notes) {
253
258
  .option("--namespace <slug>", "assert the source workspace; used for slug/title lookup")
254
259
  .option("--project <slug>", "destination project; repeat for multiple projects", (value, previous) => [...previous, value], [])
255
260
  .option("--folder <path>", "relocate the note within --project to this existing folder (e.g. a/b)")
261
+ .option("--to-project <slug>", "destination project (contract spelling of --project; repeatable)", (value, previous) => [...previous, value], [])
262
+ .option("--to-folder <path>", "destination folder (contract spelling of --folder)")
256
263
  .option("--dry-run", "validate on the server and preview access changes without writing")
257
264
  .option("--json", "emit the server move receipt as JSON")
258
265
  .action(async (note, opts) => { process.exitCode = await runNotesMove(note, opts); });
@@ -7,8 +7,9 @@ export function sessionContext(env = process.env) {
7
7
  const id = env.DREAMLAKE_TERMINAL_SESSION_ID, ns = env.DREAMLAKE_SESSION_NAMESPACE;
8
8
  if (id)
9
9
  return id && ns && objectId.test(id) && namespace.test(ns) ? { saved: { id, namespace: ns } } : null;
10
- // Never infer a native identity from arbitrary agent/presence labels.
11
- const codex = env.CODEX_THREAD_ID, claude = env.CLAUDE_SESSION_ID;
10
+ // Never infer a native identity from arbitrary agent/presence labels. Claude Code exports
11
+ // CLAUDE_CODE_SESSION_ID to its subprocesses; an explicit CLAUDE_SESSION_ID wins when both are set.
12
+ const codex = env.CODEX_THREAD_ID, claude = env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID;
12
13
  if (codex && claude)
13
14
  return null;
14
15
  if (codex && uuid.test(codex))
@@ -1,5 +1,16 @@
1
1
  import type { Command } from 'commander';
2
- import { type ResourceSessionRef } from '../session-affiliation.js';
2
+ import { type ResourceSessionRef, type SavedSessionRef } from '../session-affiliation.js';
3
+ /** The saved-session context `sessionContext()` reads first: a shell that sources this file links its
4
+ * note and artifact writes to the session without any native id in its environment. The assignments are
5
+ * `export`ed, because a plain `KEY=value` line only sets a shell variable that the `dreamlake` child
6
+ * process never receives. Private (0600). */
7
+ export declare function writeSessionEnvFile(path: string, session: SavedSessionRef): string;
8
+ /** Where the `/dreamlake` skill and the SessionStart hook keep the env file of a native session, so a hook
9
+ * that only knows the native id (Claude Code hands it over on stdin) can find the saved session. */
10
+ export declare const sessionEnvFilePath: (nativeId: string, home?: string) => string;
11
+ /** Read back exactly what `writeSessionEnvFile` wrote: the two exported, single-quoted assignments. Anything
12
+ * else — another shape, a value that is not a saved id or namespace, a missing file — is `null`, never a guess. */
13
+ export declare function readSessionEnvFile(path: string): SavedSessionRef | null;
3
14
  export declare function resourceFromOptions(opts: {
4
15
  note?: string;
5
16
  artifact?: string;
@@ -1,6 +1,43 @@
1
+ import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, join, resolve } from 'node:path';
1
4
  import { resolveHostNamespace } from '../hosts/inventory.js';
2
5
  import { affiliationPath } from '../session-affiliation.js';
3
6
  import { connection, requestJson, sessionPath } from './api.js';
7
+ /** POSIX single-quoting: safe for any value, and identical in sh, bash and zsh. */
8
+ const shellQuoted = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
9
+ /** The saved-session context `sessionContext()` reads first: a shell that sources this file links its
10
+ * note and artifact writes to the session without any native id in its environment. The assignments are
11
+ * `export`ed, because a plain `KEY=value` line only sets a shell variable that the `dreamlake` child
12
+ * process never receives. Private (0600). */
13
+ export function writeSessionEnvFile(path, session) {
14
+ if (!/^[a-f0-9]{24}$/.test(session.id) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(session.namespace))
15
+ throw new Error('Use an exact saved session ID and namespace for the env file');
16
+ const target = resolve(path);
17
+ mkdirSync(dirname(target), { recursive: true, mode: 0o700 });
18
+ writeFileSync(target, `export DREAMLAKE_TERMINAL_SESSION_ID=${shellQuoted(session.id)}\nexport DREAMLAKE_SESSION_NAMESPACE=${shellQuoted(session.namespace)}\n`, { mode: 0o600 });
19
+ chmodSync(target, 0o600);
20
+ return target;
21
+ }
22
+ /** Where the `/dreamlake` skill and the SessionStart hook keep the env file of a native session, so a hook
23
+ * that only knows the native id (Claude Code hands it over on stdin) can find the saved session. */
24
+ export const sessionEnvFilePath = (nativeId, home = homedir()) => join(home, '.dreamlake', 'sessions', `${nativeId.toLowerCase()}.env`);
25
+ /** Read back exactly what `writeSessionEnvFile` wrote: the two exported, single-quoted assignments. Anything
26
+ * else — another shape, a value that is not a saved id or namespace, a missing file — is `null`, never a guess. */
27
+ export function readSessionEnvFile(path) {
28
+ let text;
29
+ try {
30
+ text = readFileSync(path, 'utf8');
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ if (text.length > 4096)
36
+ return null;
37
+ const read = (key) => { const m = text.match(new RegExp(`^export ${key}='([^'\n]*)'$`, 'm')); return m ? m[1] : null; };
38
+ const id = read('DREAMLAKE_TERMINAL_SESSION_ID'), namespace = read('DREAMLAKE_SESSION_NAMESPACE');
39
+ return id && namespace && /^[a-f0-9]{24}$/.test(id) && /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(namespace) ? { id, namespace } : null;
40
+ }
4
41
  export function resourceFromOptions(opts) {
5
42
  if (Boolean(opts.note) === Boolean(opts.artifact))
6
43
  throw new Error('Choose exactly one --note NOTE_ID or --artifact ARTIFACT_ID');
@@ -3,4 +3,15 @@
3
3
  * over the TypeScript API (`src/api`), so behaviour, permissions and error
4
4
  * codes are identical in both. */
5
5
  import type { Command } from 'commander';
6
+ import { type PermissionLevel, type SessionsApi } from '../../api/index.js';
7
+ /** The raise rule, applied before anything is submitted. The server cannot tell a token holder from a
8
+ * person, so a raise carries `raise: true` only when a person asked: `--raise` on the command line AND a
9
+ * confirmation typed on a terminal. Without a terminal nobody can be asked, so a raise is refused: a script
10
+ * or an agent holding the token must not be able to widen a session on its own. Lowering or keeping the
11
+ * level sends no flag. */
12
+ export declare function raiseConfirmation(api: Pick<SessionsApi, 'get'>, sessionId: string, level: PermissionLevel, opts: {
13
+ raise?: boolean;
14
+ }, ask?: (message: string) => Promise<boolean>, interactive?: boolean): Promise<{
15
+ raise?: true;
16
+ }>;
6
17
  export declare function registerSessionControl(group: Command): void;
@@ -4,8 +4,9 @@ import { homedir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
  import { resolveHostNamespace } from '../hosts/inventory.js';
6
6
  import { resolveRemote, resolveToken } from '../config.js';
7
- import { ApiError, createClient, isObjectId } from '../../api/index.js';
7
+ import { ApiError, createClient, isObjectId, isPermissionRaise, PERMISSION_LEVELS } from '../../api/index.js';
8
8
  import { VERSION } from '../version.js';
9
+ import { confirm } from '../prompt.js';
9
10
  import { serve } from './runner/serve.js';
10
11
  function client() {
11
12
  const token = resolveToken();
@@ -29,10 +30,30 @@ const guard = async (opts, work) => {
29
30
  };
30
31
  const needId = (value) => { if (!isObjectId(value))
31
32
  throw new Error('Use the 24-hex session id from sessions list'); return value; };
33
+ const needLevel = (value, flag = '--permission') => { if (!PERMISSION_LEVELS.includes(String(value)))
34
+ throw new Error(`${flag} must be read-only, workspace-write or full-access`); return value; };
35
+ /** The raise rule, applied before anything is submitted. The server cannot tell a token holder from a
36
+ * person, so a raise carries `raise: true` only when a person asked: `--raise` on the command line AND a
37
+ * confirmation typed on a terminal. Without a terminal nobody can be asked, so a raise is refused: a script
38
+ * or an agent holding the token must not be able to widen a session on its own. Lowering or keeping the
39
+ * level sends no flag. */
40
+ export async function raiseConfirmation(api, sessionId, level, opts, ask = message => confirm(message, false), interactive = !!process.stdin.isTTY) {
41
+ const row = await api.get(sessionId), current = row.permissionLevel ?? null;
42
+ if (!isPermissionRaise(current, level))
43
+ return {};
44
+ const from = current ?? 'an unrecorded level';
45
+ if (!opts.raise)
46
+ throw new Error(`Raising ${from} to ${level} widens what the agent may do. Pass --raise to ask for it as the person responsible; the runner must have been started with --max-human-permission ${level} or higher.`);
47
+ if (!interactive)
48
+ throw new Error(`Raising ${from} to ${level} needs an interactive confirmation: run this on a terminal. A script or an agent cannot raise a session on its own.`);
49
+ if (!await ask(`Raise session ${sessionId} from ${from} to ${level}? The agent gets wider access from its next turn.`))
50
+ throw new Error('Raise not confirmed; nothing was changed');
51
+ return { raise: true };
52
+ }
32
53
  export function registerSessionControl(group) {
33
54
  const common = (c) => c.option('--namespace <namespace>', 'personal namespace (default: signed-in personal namespace)').option('--json', 'emit JSON');
34
55
  common(group.command('serve').description('run the session runner on this machine: executes start/resume/stop/send/sync/status/subagents commands for your sessions with the Codex/Claude CLIs (tmux when available, headless otherwise)'))
35
- .option('--allow-repo <path>', 'trusted repository for built-in-origin starts; repeat (default current directory)', (value, all) => [...all, value], []).option('--max-agent-permission <level>', 'maximum built-in-origin startup permission', 'workspace-write').option('--pod-config <file>', 'explicit Docker image, repository allowlist, credentials and resource limits').option('--once', 'handle at most one command, then exit').option('--poll <seconds>', 'long-poll length per claim, 1–25', '25')
56
+ .option('--allow-repo <path>', 'trusted repository for built-in-origin starts; repeat (default current directory)', (value, all) => [...all, value], []).option('--max-agent-permission <level>', 'maximum built-in-origin startup permission', 'workspace-write').option('--max-human-permission <level>', 'highest level a person may raise a session to on this runner (control restart --raise, sessions permission --raise); default: no raise above the start level').option('--pod-config <file>', 'explicit Docker image, repository allowlist, credentials and resource limits').option('--once', 'handle at most one command, then exit').option('--poll <seconds>', 'long-poll length per claim, 1–25', '25')
36
57
  .action(opts => guard(opts, async () => {
37
58
  const ns = await resolveHostNamespace(opts.namespace), abort = new AbortController();
38
59
  process.once('SIGINT', () => abort.abort());
@@ -42,7 +63,8 @@ export function registerSessionControl(group) {
42
63
  throw new Error('--poll must be 1–25 seconds');
43
64
  if (!['read-only', 'workspace-write', 'full-access'].includes(opts.maxAgentPermission))
44
65
  throw new Error('Invalid --max-agent-permission');
45
- const result = await serve({ client: client(), namespace: ns, version: VERSION, trustedRepositories: opts.allowRepo.length ? opts.allowRepo : undefined, maxAgentPermission: opts.maxAgentPermission, podConfig: opts.podConfig ? loadPodConfig(opts.podConfig) : undefined, once: !!opts.once, signal: abort.signal, pollSeconds: poll });
66
+ const maxHumanPermission = opts.maxHumanPermission === undefined ? undefined : needLevel(opts.maxHumanPermission, '--max-human-permission');
67
+ const result = await serve({ client: client(), namespace: ns, version: VERSION, trustedRepositories: opts.allowRepo.length ? opts.allowRepo : undefined, maxAgentPermission: opts.maxAgentPermission, maxHumanPermission, podConfig: opts.podConfig ? loadPodConfig(opts.podConfig) : undefined, once: !!opts.once, signal: abort.signal, pollSeconds: poll });
46
68
  if (opts.json)
47
69
  emit(result, true);
48
70
  }));
@@ -59,7 +81,7 @@ export function registerSessionControl(group) {
59
81
  const ns = await resolveHostNamespace(opts.namespace), runners = await client().sessions(ns).runners.list();
60
82
  if (opts.json)
61
83
  return emit({ namespace: ns, runners }, true);
62
- console.log(runners.map(r => `${r.id} ${r.hostname} ${r.unixUser} ${r.online ? 'online' : 'offline'} modes=${r.capabilities.modes.join('/')} seen ${r.lastSeenAt}`).join('\n') || 'No runners registered. Start one with: dreamlake sessions serve');
84
+ console.log(runners.map(r => `${r.id} ${r.hostname} ${r.unixUser} ${r.online ? 'online' : 'offline'} modes=${r.capabilities.modes.join('/')} human-cap=${r.capabilities.humanPermissionCap ?? 'none'} seen ${r.lastSeenAt}`).join('\n') || 'No runners registered. Start one with: dreamlake sessions serve');
63
85
  }));
64
86
  const control = group.command('control').description('durable session commands executed by your runner (dreamlake sessions serve)');
65
87
  const waitOption = (c) => c.option('--wait <seconds>', 'wait for the receipt (0 returns the pending command)', '60').option('--runner <id>', 'target an explicit runner id');
@@ -88,6 +110,17 @@ export function registerSessionControl(group) {
88
110
  throw new Error('--permission must be read-only, workspace-write or full-access'); return value === undefined ? {} : { permissionLevel: value }; };
89
111
  waitOption(common(control.command('resume <id>').description('resume a session on its runner, optionally with a prompt'))).option('--prompt <text>').option('--mode <mode>', 'tmux or headless').option('--permission <level>', 'permission ceiling for the new provider process (default: the level recorded at start)')
90
112
  .action((id, opts) => guard(opts, () => submit(opts, 'resume', { sessionId: needId(id), ...(opts.prompt ? { prompt: opts.prompt } : {}), ...(opts.mode ? { mode: opts.mode } : {}), ...level(opts.permission) })));
113
+ waitOption(common(control.command('restart <id>').description('stop the session process and resume the same conversation under a new recorded permission level; the receipt echoes the command line it ran')))
114
+ .requiredOption('--permission <level>', 'read-only, workspace-write or full-access; the level recorded for every later turn')
115
+ .option('--raise', 'ask, as the person responsible, to raise the level (needs a runner started with --max-human-permission; confirmed interactively on a terminal)')
116
+ .option('--prompt <text>', 'first prompt after the restart (headless mode runs one turn with it)').option('--mode <mode>', 'tmux or headless').option('--reason <text>', 'recorded in the permission history (1–200 characters)')
117
+ .action((id, opts) => guard(opts, async () => {
118
+ const level = needLevel(opts.permission), ns = await resolveHostNamespace(opts.namespace);
119
+ if (opts.reason !== undefined && (!String(opts.reason).trim() || String(opts.reason).length > 200))
120
+ throw new Error('--reason must be 1–200 characters');
121
+ const raise = await raiseConfirmation(client().sessions(ns), needId(id), level, opts);
122
+ return submit({ ...opts, namespace: ns }, 'restart', { sessionId: id, permissionLevel: level, ...(opts.prompt ? { prompt: opts.prompt } : {}), ...(opts.mode ? { mode: opts.mode } : {}), ...(opts.reason ? { reason: opts.reason } : {}), ...raise });
123
+ }));
91
124
  waitOption(common(control.command('stop <id>').description('stop the managed process of a session; descriptor and conversation are kept'))).option('--yes', 'confirm stopping the process')
92
125
  .action((id, opts) => guard(opts, () => { if (!opts.yes)
93
126
  throw new Error('Stopping ends the agent process. Pass --yes to confirm'); return submit(opts, 'stop', { sessionId: needId(id) }); }));
@@ -108,6 +141,18 @@ export function registerSessionControl(group) {
108
141
  common(control.command('list').description('list recent commands and their receipts')).option('--session <id>').option('--status <status>').option('--limit <n>', 'max 100', '25')
109
142
  .action(opts => guard(opts, async () => { const ns = await resolveHostNamespace(opts.namespace); emit({ namespace: ns, ...(await client().sessions(ns).commands.list({ ...(opts.session ? { sessionId: needId(opts.session) } : {}), ...(opts.status ? { status: opts.status } : {}), limit: Number(opts.limit) })) }, !!opts.json); }));
110
143
  common(group.command('children <id>').description('list managed child sessions; control each child by its stable session ID')).option('--cursor <cursor>').action((id, opts) => guard(opts, async () => { const ns = await resolveHostNamespace(opts.namespace); emit(await client().sessions(ns).list({ parentSessionId: needId(id), cursor: opts.cursor, archived: 'include' }), !!opts.json); }));
144
+ common(group.command('permission <id> <level>').description('move the recorded permission level of a session without a runner round-trip; the running process keeps its level until the next resume or restart'))
145
+ .option('--raise', 'ask, as the person responsible, to raise the level (needs a runner started with --max-human-permission; confirmed interactively on a terminal)').option('--reason <text>', 'recorded in the permission history (1–200 characters)')
146
+ .action((id, level, opts) => guard(opts, async () => {
147
+ const wanted = needLevel(level, 'level'), ns = await resolveHostNamespace(opts.namespace), api = client().sessions(ns);
148
+ if (opts.reason !== undefined && (!String(opts.reason).trim() || String(opts.reason).length > 200))
149
+ throw new Error('--reason must be 1–200 characters');
150
+ const raise = await raiseConfirmation(api, needId(id), wanted, opts);
151
+ const result = await api.permission(id, { permissionLevel: wanted, ...(opts.reason ? { reason: opts.reason } : {}), ...raise });
152
+ if (opts.json)
153
+ return emit({ namespace: ns, ...result }, true);
154
+ console.log(`${result.session.id} permission ${result.session.permissionLevel}${result.changed ? '' : ' (unchanged)'}${result.session.observedPermissionLevel && result.session.observedPermissionLevel !== result.session.permissionLevel ? ` (runner last ran under ${result.session.observedPermissionLevel}; applied on the next resume or restart)` : ''}`);
155
+ }));
111
156
  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); }));
112
157
  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); }));
113
158
  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); }));