@creator-notes/cnotes 0.85.0 → 0.87.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.85.0",
3
+ "version": "0.87.0",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -1,3 +1,20 @@
1
1
  import { Command } from "commander";
2
+ import { ApiClient } from "../lib/api-client.js";
3
+ /**
4
+ * Click-through link for the canvas a write command named. A raw Convex id
5
+ * builds it directly; a CANVAS-<n> display id costs one read to find the
6
+ * Convex id, because `?canvasId=` resolves only Convex ids. Null when that
7
+ * read fails: the write already succeeded, so a missing link is not an error.
8
+ */
9
+ export declare function resolveCanvasLink(api: ApiClient, cfg: {
10
+ serverUrl: string;
11
+ workspaceId: string;
12
+ }, canvasRef: string): Promise<string | null>;
13
+ /**
14
+ * The canvas-node ids behind edge endpoints. A raw node id passes through; a
15
+ * display handle (SECTION-7, or NOTE-12 for that note's card) is looked up on
16
+ * the canvas, so an agent can wire an edge with the ids `canvas read` shows.
17
+ */
18
+ export declare function resolveNodeRefs(api: ApiClient, canvasId: string, workspaceId: string, refs: string[]): Promise<string[]>;
2
19
  export declare function registerCanvasCommands(program: Command): void;
3
20
  //# sourceMappingURL=canvas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/commands/canvas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AA2L5C,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2gG7D"}
1
+ {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/commands/canvas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AA2CxE;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,SAAS,EACd,GAAG,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAC/C,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,SAAS,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CAuBnB;AAqJD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA8iG7D"}
@@ -16,6 +16,52 @@ import { findOverlaps, layoutItemsFrom, parseSize, resolveAnchor, suggestFreeSpo
16
16
  import { canvasUrl, canvasLinkForRef } from "../lib/urls.js";
17
17
  import { canvasActionPath, commentsListPath, parseCommentStatus, } from "../lib/canvas-paths.js";
18
18
  import { registerCanvasMilestoneCommands } from "./canvas-milestone.js";
19
+ import { DISPLAY_ID_CORE } from "../lib/display-id.js";
20
+ /** A node handle the agent reads off `canvas read`: NOTE-12, SECTION-7, … */
21
+ const NODE_DISPLAY_REF_RE = new RegExp(String.raw `^${DISPLAY_ID_CORE}$`);
22
+ /**
23
+ * Click-through link for the canvas a write command named. A raw Convex id
24
+ * builds it directly; a CANVAS-<n> display id costs one read to find the
25
+ * Convex id, because `?canvasId=` resolves only Convex ids. Null when that
26
+ * read fails: the write already succeeded, so a missing link is not an error.
27
+ */
28
+ export async function resolveCanvasLink(api, cfg, canvasRef) {
29
+ const direct = canvasLinkForRef(cfg.serverUrl, cfg.workspaceId, canvasRef);
30
+ if (direct || !canvasRef)
31
+ return direct;
32
+ try {
33
+ const data = await api.get(canvasActionPath(canvasRef, cfg.workspaceId));
34
+ return data.canvas?.id ? canvasUrl(cfg.serverUrl, cfg.workspaceId, data.canvas.id) : null;
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ /**
41
+ * The canvas-node ids behind edge endpoints. A raw node id passes through; a
42
+ * display handle (SECTION-7, or NOTE-12 for that note's card) is looked up on
43
+ * the canvas, so an agent can wire an edge with the ids `canvas read` shows.
44
+ */
45
+ export async function resolveNodeRefs(api, canvasId, workspaceId, refs) {
46
+ const isRef = (r) => NODE_DISPLAY_REF_RE.test(r.trim().toUpperCase());
47
+ if (!refs.some(isRef))
48
+ return refs;
49
+ const canvas = await api.get(canvasActionPath(canvasId, workspaceId));
50
+ // allNodes is the occupancy view and leaves frames out; sections are separate.
51
+ const handles = [...(canvas.allNodes ?? []), ...(canvas.sectionNodes ?? [])];
52
+ return refs.map((ref) => {
53
+ if (!isRef(ref))
54
+ return ref;
55
+ const want = ref.trim().toUpperCase();
56
+ const hits = handles.filter((n) => n.displayId?.toUpperCase() === want);
57
+ if (hits.length === 1)
58
+ return hits[0].id;
59
+ if (hits.length === 0) {
60
+ throw new ValidationError(`${ref} is not on this canvas. Run \`cnotes canvas read ${canvasId}\` to see the handles it holds.`);
61
+ }
62
+ throw new ValidationError(`${ref} has ${hits.length} cards on this canvas. Pass one node id from \`cnotes canvas get ${canvasId} --json\` (allNodes[].id).`);
63
+ });
64
+ }
19
65
  /**
20
66
  * A list item is a *collection of member notes* with a short markdown description
21
67
  * that frames them — not a place to dump prose. When a description carries several
@@ -438,10 +484,24 @@ Examples:
438
484
  .command("digest")
439
485
  .description("Get the AI-generated digest (summary) of a canvas")
440
486
  .argument("<canvasId>", "Canvas ID")
441
- .action(async (canvasId) => {
487
+ .option("--refresh", "Queue a fresh narrative instead of reading the current one (a write; needs Pro). The notes list is current without it.")
488
+ .action(async (canvasId, opts) => {
442
489
  const cfg = resolveConfig(program.opts());
443
490
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
444
491
  try {
492
+ if (opts.refresh) {
493
+ const queued = await api.post(`/api/canvas/${encodeURIComponent(canvasId)}/digest?workspaceId=${encodeURIComponent(cfg.workspaceId)}`, {});
494
+ if (!queued.queued) {
495
+ throw new ValidationError(`Digest not queued: ${queued.reason || "unknown reason"}`);
496
+ }
497
+ if (cfg.json) {
498
+ outputJson(queued);
499
+ }
500
+ else {
501
+ console.log(`Queued a fresh digest (${queued.status}). Run \`cnotes canvas digest ${canvasId}\` again in a minute.`);
502
+ }
503
+ return;
504
+ }
445
505
  const data = await api.get(`/api/canvas/${encodeURIComponent(canvasId)}/digest?workspaceId=${encodeURIComponent(cfg.workspaceId)}`);
446
506
  if (cfg.json) {
447
507
  outputJson(data);
@@ -828,7 +888,7 @@ Examples:
828
888
  outputQuiet(String(data.nodeId || data._id || ""));
829
889
  return;
830
890
  }
831
- const link = canvasLinkForRef(cfg.serverUrl, cfg.workspaceId, canvasId);
891
+ const link = await resolveCanvasLink(api, cfg, canvasId);
832
892
  if (cfg.json) {
833
893
  if (link)
834
894
  data.url = link;
@@ -1227,7 +1287,7 @@ Examples:
1227
1287
  action: "bulkAddNodes",
1228
1288
  notes,
1229
1289
  });
1230
- const link = canvasLinkForRef(cfg.serverUrl, cfg.workspaceId, canvasId);
1290
+ const link = await resolveCanvasLink(api, cfg, canvasId);
1231
1291
  // The server answers 201/207 with per-item results
1232
1292
  // ({index, type, id, error?}). Partial failure keeps exit 0 (the
1233
1293
  // caller inspects results[].error — documented contract), but when
@@ -1345,7 +1405,7 @@ Placement (relative to nodes already on the canvas):
1345
1405
  // built" link for it.
1346
1406
  const link = opts.dryRun
1347
1407
  ? null
1348
- : canvasLinkForRef(cfg.serverUrl, cfg.workspaceId, canvasId);
1408
+ : await resolveCanvasLink(api, cfg, canvasId);
1349
1409
  // The server answers 207 with per-item results. Partial failure keeps
1350
1410
  // exit 0 (the caller inspects items[].error — documented contract),
1351
1411
  // but when EVERY item and edge failed, nothing was placed and exiting
@@ -1577,7 +1637,7 @@ Examples:
1577
1637
  });
1578
1638
  const link = opts.dryRun
1579
1639
  ? null
1580
- : canvasLinkForRef(cfg.serverUrl, cfg.workspaceId, canvasId);
1640
+ : await resolveCanvasLink(api, cfg, canvasId);
1581
1641
  if (cfg.json) {
1582
1642
  if (link)
1583
1643
  data.url = link;
@@ -1751,8 +1811,8 @@ Examples:
1751
1811
  .command("add-edge")
1752
1812
  .description("Connect two nodes on a canvas (any node type: note, text, list, richtext, canvas-link, section)")
1753
1813
  .argument("<canvasId>", "Canvas ID")
1754
- .requiredOption("--source <nodeId>", "Source node ID (any node type on the canvas)")
1755
- .requiredOption("--target <nodeId>", "Target node ID (any node type on the canvas)")
1814
+ .requiredOption("--source <ref>", "Source: a node id, a SECTION-<n>, or a note display id for its card on this canvas")
1815
+ .requiredOption("--target <ref>", "Target: a node id, a SECTION-<n>, or a note display id for its card on this canvas")
1756
1816
  .option("--label <text>", "Edge label")
1757
1817
  .option("--arrow <mode>", "Arrow direction: end (default), start, both, none", "end")
1758
1818
  .option("--line-style <style>", "Line style: solid (default) | dashed", "solid")
@@ -1762,10 +1822,11 @@ Examples:
1762
1822
  try {
1763
1823
  const { arrowStart, arrowEnd } = parseArrowMode(opts.arrow);
1764
1824
  const lineStyle = parseLineStyle(opts.lineStyle);
1825
+ const [sourceNodeId, targetNodeId] = await resolveNodeRefs(api, canvasId, cfg.workspaceId, [String(opts.source), String(opts.target)]);
1765
1826
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
1766
1827
  action: "addEdge",
1767
- sourceNodeId: opts.source,
1768
- targetNodeId: opts.target,
1828
+ sourceNodeId,
1829
+ targetNodeId,
1769
1830
  label: opts.label,
1770
1831
  arrowStart,
1771
1832
  arrowEnd,
@@ -2048,17 +2109,28 @@ Examples:
2048
2109
  });
2049
2110
  canvas
2050
2111
  .command("remove-node")
2051
- .description("Remove a node from a canvas")
2112
+ .description("Remove a node from a canvas. The note behind a card keeps its content and stays on other canvases.")
2052
2113
  .argument("<canvasId>", "Canvas ID")
2053
- .requiredOption("--node <nodeId>", "Canvas node ID")
2114
+ .requiredOption("--node <ref>", "A node id, a SECTION-<n>, or a note display id naming that note's card on this canvas")
2054
2115
  .action(async (canvasId, opts) => {
2055
2116
  const cfg = resolveConfig(program.opts());
2056
2117
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2057
2118
  try {
2058
- await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2059
- action: "removeNode",
2060
- nodeId: opts.node,
2061
- });
2119
+ if (NODE_DISPLAY_REF_RE.test(String(opts.node).trim().toUpperCase())) {
2120
+ // A display handle needs this canvas to resolve against; the bulk
2121
+ // action resolves SECTION-<n> and note display ids server-side.
2122
+ const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), { action: "bulkRemoveNodes", nodeIds: [String(opts.node)], edgeIds: [] });
2123
+ const row = data.results?.[0];
2124
+ if (row?.status !== "deleted") {
2125
+ throw new ValidationError(`${opts.node} was not removed: ${row?.error || "not found on this canvas"}. Run \`cnotes canvas read ${canvasId}\` to see its handles.`);
2126
+ }
2127
+ }
2128
+ else {
2129
+ await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2130
+ action: "removeNode",
2131
+ nodeId: opts.node,
2132
+ });
2133
+ }
2062
2134
  if (cfg.json) {
2063
2135
  outputJson({ success: true, nodeId: opts.node });
2064
2136
  }