@creator-notes/cnotes 0.147.0 → 0.149.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.147.0",
3
+ "version": "0.149.0",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
package/README.md CHANGED
@@ -216,7 +216,7 @@ The wrap form does begin → run-your-command → end automatically, even if you
216
216
 
217
217
  ### Declarative layout (`cnotes canvas place`)
218
218
 
219
- Most of the time you shouldn't be computing pixel coordinates by hand — agents and humans alike are bad at it. `cnotes canvas place` takes a layout document that describes **structure** (rows, columns, what's anchored to what) and the server measures every item, packs them with no overlaps, and inserts them in a single batch. The call is best-effort: per-item failures are reported in the response (HTTP 207) but successful items stay on the canvas.
219
+ Most of the time you shouldn't be computing pixel coordinates by hand — agents and humans alike are bad at it. `cnotes canvas place` takes a layout document that describes **structure** (rows, columns, what's anchored to what) and the server measures every item, packs them with no overlaps, and inserts them in a single batch. The call is best-effort: per-item failures are reported in the response (HTTP 207) but successful items stay on the canvas, and the command exits `3` (`PlacePartial` on stderr, each refused item under `failed`) so a refused card never reads as success.
220
220
 
221
221
  Four building blocks:
222
222
 
@@ -205,10 +205,10 @@ function reportPlacedNotes(data) {
205
205
  return createdRows;
206
206
  }
207
207
  /**
208
- * The server answers 207 with per-item results. Partial failure keeps exit 0
209
- * (the caller inspects items[].error, the documented contract), but when EVERY
210
- * item and edge failed, nothing was placed and exiting 0 would report success
211
- * to an agent that keys on the exit code.
208
+ * The server answers 207 with per-item results, and the exit code says how it
209
+ * went: 0 when everything landed, 3 when some items or edges were refused
210
+ * (placedSome), 1 when nothing was placed. An agent keys on the exit code,
211
+ * so a refused card must never exit 0.
212
212
  */
213
213
  function placedNothing(data) {
214
214
  const allItems = (data.items || []);
@@ -218,6 +218,144 @@ function placedNothing(data) {
218
218
  allItems.every((r) => !r.id || r.error) &&
219
219
  allEdges.every((e) => !e.id || e.error));
220
220
  }
221
+ /** The items and edges the server refused, each with its reason. */
222
+ function refusedRows(data) {
223
+ const allItems = (data.items || []);
224
+ const allEdges = (data.edges || []);
225
+ const reason = (r) => String(r.error ?? "not placed");
226
+ return {
227
+ items: allItems.filter((r) => !r.id || r.error).map((r) => ({ index: r.index, type: r.type, error: reason(r) })),
228
+ edges: allEdges.filter((e) => !e.id || e.error).map((e) => ({ from: e.from, to: e.to, error: reason(e) })),
229
+ total: allItems.length + allEdges.length,
230
+ };
231
+ }
232
+ /** True when some, not all, of a (non-dry-run) placeLayout's items and edges were refused. */
233
+ function placedSome(data) {
234
+ if (data.dryRun)
235
+ return false;
236
+ const refused = refusedRows(data);
237
+ const failed = refused.items.length + refused.edges.length;
238
+ return failed > 0 && failed < refused.total;
239
+ }
240
+ const PARTIAL_PLACE_HINT = "The rest were placed and any new notes exist: do not re-run the spec, it would duplicate them. " +
241
+ 'Fix each refused item on its own: a quote with `cnotes canvas add-quote <canvas> --note <id> --text "<words>" --title "<headline>"`, ' +
242
+ "an edge with `cnotes canvas add-edge`, anything else with `cnotes canvas place` holding only that item.";
243
+ function partialPlaceSummary(data) {
244
+ const refused = refusedRows(data);
245
+ const items = (data.items || []);
246
+ const edges = (data.edges || []);
247
+ const parts = [];
248
+ if (refused.items.length > 0)
249
+ parts.push(`${refused.items.length} of ${items.length} items`);
250
+ if (refused.edges.length > 0)
251
+ parts.push(`${refused.edges.length} of ${edges.length} edges`);
252
+ return parts.join(" and ");
253
+ }
254
+ function reportPartialPlaceJson(data) {
255
+ const refused = refusedRows(data);
256
+ console.error(JSON.stringify({
257
+ error: `placeLayout refused ${partialPlaceSummary(data)}; the rest were placed`,
258
+ code: "PlacePartial",
259
+ exitCode: EXIT_CODES.VALIDATION,
260
+ ...(refused.items.length > 0 ? { failed: refused.items } : {}),
261
+ ...(refused.edges.length > 0 ? { failedEdges: refused.edges } : {}),
262
+ hint: PARTIAL_PLACE_HINT,
263
+ }));
264
+ }
265
+ /** Set the exit code a placeLayout result earns: 1 when nothing was placed, 3 when some of it was refused. */
266
+ function setPlaceExitCode(data) {
267
+ if (placedNothing(data))
268
+ process.exitCode = EXIT_CODES.GENERIC;
269
+ else if (placedSome(data))
270
+ process.exitCode = EXIT_CODES.VALIDATION;
271
+ }
272
+ /** The stderr notice for a placeLayout that did not fully land, in the output mode in use. */
273
+ function reportPlaceShortfall(data, json) {
274
+ if (json) {
275
+ if (placedNothing(data))
276
+ reportNothingPlacedJson();
277
+ else if (placedSome(data))
278
+ reportPartialPlaceJson(data);
279
+ }
280
+ else if (placedSome(data)) {
281
+ console.error(`Error: ${partialPlaceSummary(data)} were not placed (see above). ${PARTIAL_PLACE_HINT}`);
282
+ }
283
+ }
284
+ function arrangeShortfall(data) {
285
+ if (data.dryRun)
286
+ return null;
287
+ const items = (data.items || []);
288
+ const failed = items
289
+ .filter((r) => !r.id || r.error)
290
+ .map((r) => ({ index: r.index, type: r.type, error: String(r.error ?? "not moved") }));
291
+ const ripple = data.ripple;
292
+ const arranged = data.arranged;
293
+ const rippleError = typeof ripple?.error === "string" ? ripple.error : undefined;
294
+ const keepError = typeof arranged?.error === "string" ? arranged.error : undefined;
295
+ const nothing = items.length > 0 && failed.length === items.length;
296
+ return {
297
+ nothing,
298
+ partial: !nothing && (failed.length > 0 || rippleError !== undefined),
299
+ failed,
300
+ total: items.length,
301
+ ...(rippleError !== undefined ? { rippleError } : {}),
302
+ ...(keepError !== undefined ? { keepError } : {}),
303
+ };
304
+ }
305
+ const ARRANGE_FAILED_HINT = "Nothing moved and the frame is as it was. Fix what each item under `failed` names " +
306
+ "(`cnotes canvas status <canvas>` lists the node ids) and run the same arrange again.";
307
+ const ARRANGE_PARTIAL_HINT = "The cards that moved stay moved. Arrange only moves cards already on the canvas, " +
308
+ "so it is safe to re-run the same command once the cause is fixed.";
309
+ function arrangePartialSummary(shortfall) {
310
+ const parts = [];
311
+ if (shortfall.failed.length > 0)
312
+ parts.push(`${shortfall.failed.length} of ${shortfall.total} items were refused`);
313
+ if (shortfall.rippleError !== undefined)
314
+ parts.push(`the band below was not pushed down (${shortfall.rippleError})`);
315
+ return parts.join(", and ");
316
+ }
317
+ /** Set arrange's exit code and print its shortfall on stderr, in the output mode in use. */
318
+ function reportArrangeShortfall(data, json) {
319
+ const shortfall = arrangeShortfall(data);
320
+ if (!shortfall)
321
+ return;
322
+ if (shortfall.keepError !== undefined) {
323
+ const section = String(data.targetSectionDisplayId ?? "The section");
324
+ console.error(`⚠ ${section} could not keep itself arranged: ${shortfall.keepError}. ` +
325
+ "The layout landed, but the frame will not re-lay itself as cards change.");
326
+ }
327
+ if (shortfall.nothing) {
328
+ process.exitCode = EXIT_CODES.GENERIC;
329
+ if (json) {
330
+ console.error(JSON.stringify({
331
+ error: "arrangeLayout moved nothing: every item failed",
332
+ code: "ArrangeFailed",
333
+ exitCode: EXIT_CODES.GENERIC,
334
+ failed: shortfall.failed,
335
+ hint: ARRANGE_FAILED_HINT,
336
+ }));
337
+ }
338
+ else {
339
+ console.error(`Error: nothing was arranged (see above). ${ARRANGE_FAILED_HINT}`);
340
+ }
341
+ }
342
+ else if (shortfall.partial) {
343
+ process.exitCode = EXIT_CODES.VALIDATION;
344
+ if (json) {
345
+ console.error(JSON.stringify({
346
+ error: `arrangeLayout landed only in part: ${arrangePartialSummary(shortfall)}`,
347
+ code: "ArrangePartial",
348
+ exitCode: EXIT_CODES.VALIDATION,
349
+ ...(shortfall.failed.length > 0 ? { failed: shortfall.failed } : {}),
350
+ ...(shortfall.rippleError !== undefined ? { rippleError: shortfall.rippleError } : {}),
351
+ hint: ARRANGE_PARTIAL_HINT,
352
+ }));
353
+ }
354
+ else {
355
+ console.error(`Error: the arrange landed only in part: ${arrangePartialSummary(shortfall)}. ${ARRANGE_PARTIAL_HINT}`);
356
+ }
357
+ }
358
+ }
221
359
  function reportNothingPlacedJson() {
222
360
  console.error(JSON.stringify({
223
361
  error: "placeLayout placed nothing: every item and edge failed",
@@ -1071,12 +1209,11 @@ spec and run the same command again.
1071
1209
  }
1072
1210
  const data = await api.post("/api/canvas", body);
1073
1211
  const createdRows = data.layout ? reportPlacedNotes(data.layout) : [];
1074
- const nothingPlaced = data.layout ? placedNothing(data.layout) : false;
1075
- if (nothingPlaced)
1076
- process.exitCode = EXIT_CODES.GENERIC;
1212
+ if (data.layout)
1213
+ setPlaceExitCode(data.layout);
1077
1214
  printCreatedCanvas(cfg, name, data, createdRows);
1078
- if (cfg.json && nothingPlaced)
1079
- reportNothingPlacedJson();
1215
+ if (data.layout)
1216
+ reportPlaceShortfall(data.layout, cfg.json);
1080
1217
  }
1081
1218
  catch (error) {
1082
1219
  handleError(error, cfg.json);
@@ -1853,15 +1990,18 @@ Examples:
1853
1990
  });
1854
1991
  const link = await resolveCanvasLink(api, cfg, canvasId);
1855
1992
  // The server answers 201/207 with per-item results
1856
- // ({index, type, id, error?}). Partial failure keeps exit 0 (the
1857
- // caller inspects results[].error — documented contract), but when
1858
- // EVERY item failed nothing was added and exiting 0 would report
1859
- // success to an agent that keys on the exit code.
1993
+ // ({index, type, id, error?}). An agent keys on the exit code, so a
1994
+ // refused note never exits 0: 3 when some were refused, 1 when every
1995
+ // one was and nothing was added.
1860
1996
  const results = (data.results || []);
1861
1997
  const failedResults = results.filter((r) => !r.id || r.error);
1862
1998
  const allFailed = results.length > 0 && failedResults.length === results.length;
1999
+ const someFailed = failedResults.length > 0 && !allFailed;
1863
2000
  if (allFailed)
1864
2001
  process.exitCode = EXIT_CODES.GENERIC;
2002
+ else if (someFailed)
2003
+ process.exitCode = EXIT_CODES.VALIDATION;
2004
+ const partialHint = "The rest were added. Re-run bulk-add with only the refused notes once each is fixed.";
1865
2005
  if (cfg.json) {
1866
2006
  if (link)
1867
2007
  data.url = link;
@@ -1874,6 +2014,19 @@ Examples:
1874
2014
  hint: "Inspect results[].error in the response above; fix the failing note refs and retry.",
1875
2015
  }));
1876
2016
  }
2017
+ else if (someFailed) {
2018
+ console.error(JSON.stringify({
2019
+ error: `bulk-add refused ${failedResults.length} of ${results.length} notes; the rest were added`,
2020
+ code: "BulkAddPartial",
2021
+ exitCode: EXIT_CODES.VALIDATION,
2022
+ failed: failedResults.map((r) => ({
2023
+ index: r.index,
2024
+ noteId: notes[typeof r.index === "number" ? r.index : -1]?.noteId,
2025
+ error: String(r.error ?? "not added"),
2026
+ })),
2027
+ hint: partialHint,
2028
+ }));
2029
+ }
1877
2030
  }
1878
2031
  else {
1879
2032
  const added = results.length - failedResults.length;
@@ -1887,6 +2040,9 @@ Examples:
1887
2040
  if (allFailed) {
1888
2041
  console.error("Error: no notes were added — every item failed (see above).");
1889
2042
  }
2043
+ else if (someFailed) {
2044
+ console.error(`Error: ${failedResults.length} of ${results.length} notes were not added (see above). ${partialHint}`);
2045
+ }
1890
2046
  if (link)
1891
2047
  console.log(`Link: ${link}`);
1892
2048
  }
@@ -1958,15 +2114,12 @@ Placement (relative to nodes already on the canvas):
1958
2114
  const link = opts.dryRun
1959
2115
  ? null
1960
2116
  : await resolveCanvasLink(api, cfg, canvasId);
1961
- const nothingPlaced = placedNothing(data);
1962
- if (nothingPlaced)
1963
- process.exitCode = EXIT_CODES.GENERIC;
2117
+ setPlaceExitCode(data);
1964
2118
  if (cfg.json) {
1965
2119
  if (link)
1966
2120
  data.url = link;
1967
2121
  outputJson(data);
1968
- if (nothingPlaced)
1969
- reportNothingPlacedJson();
2122
+ reportPlaceShortfall(data, true);
1970
2123
  }
1971
2124
  else {
1972
2125
  if (data.dryRun) {
@@ -1983,6 +2136,7 @@ Placement (relative to nodes already on the canvas):
1983
2136
  printPlaceSummary(data, createdRows);
1984
2137
  if (link)
1985
2138
  console.log(`Link: ${link}`);
2139
+ reportPlaceShortfall(data, false);
1986
2140
  }
1987
2141
  }
1988
2142
  catch (error) {
@@ -2196,6 +2350,7 @@ Examples:
2196
2350
  if (link)
2197
2351
  data.url = link;
2198
2352
  outputJson(data);
2353
+ reportArrangeShortfall(data, true);
2199
2354
  return;
2200
2355
  }
2201
2356
  const items = (data.items || []);
@@ -2230,6 +2385,7 @@ Examples:
2230
2385
  }
2231
2386
  if (link)
2232
2387
  console.log(`Link: ${link}`);
2388
+ reportArrangeShortfall(data, false);
2233
2389
  }
2234
2390
  catch (error) {
2235
2391
  handleError(error, cfg.json);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.147.0",
3
+ "version": "0.149.0",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,7 @@ Read this before putting more than one item on a canvas. Describe structure; the
20
20
 
21
21
  The server measures every item, packs them into a no-overlap layout, and inserts them in a single batch. You describe **structure** (rows, columns, what's near what), the server resolves pixels. This is what `cnotes canvas place` is for, and you should reach for it whenever you're adding more than one item.
22
22
 
23
- The call is **best-effort, not transactional**: per-item failures are reported in the response (HTTP 207) but the items that succeeded stay on the canvas. Always inspect `items[].error` and `edges[].error` before assuming success.
23
+ The call is **best-effort, not transactional**: per-item failures are reported in the response (HTTP 207) but the items that succeeded stay on the canvas. The exit code says which happened: `0` everything landed, `3` some items or edges were refused (stderr carries `code: "PlacePartial"` and each refused one under `failed`), `1` nothing was placed. On `3`, never re-run the spec, since the notes it made already exist: fix each refused item on its own (`canvas add-quote` for a face, `canvas add-edge` for an edge, a one-item `place` for the rest).
24
24
 
25
25
  **You don't have to find a free coordinate.** `place` is collision-aware against content already on the canvas. By default (`placement: "auto"`) it drops your layout in a clear band **below everything that's already there**, and if you do pass an `origin` that would overlap, it slides the whole block straight down until it's clear. So appending a new section to a non-empty canvas Just Works, no need to read existing positions and guess a safe `origin` first. Use `--placement append` to force "below everything", or `--placement exact` (or `"placement": "exact"` in the doc) to honor your `origin` verbatim for pixel-perfect templates.
26
26
 
@@ -66,7 +66,7 @@ The schema is strict: an unknown or typo'd key anywhere in the doc (e.g. `gapp`,
66
66
  { "kind": "item", "type": "section", "name": "Open Questions", "width": 800, "height": 500 }
67
67
  ```
68
68
 
69
- A `quote` leaf is a note's face (canvas-elements.md rules 4 and 8): `text` is the exact words from the note's saved version, `noteId` a display id or the `@<key>` of a note the same call creates, `style` (`pull` default, `highlight`, `evidence`), `size` (`small` default, `medium`, `large`), `colorHex` a role hex, `title` your own words for why the line matters. The server makes or reuses the Quote note (`QUOTE-<n>`, the same one `canvas add-quote` would make) and places its card where the solver put the leaf, inside its frame, measured from its words. The response item carries `quoteNoteDisplayId`, `noteDisplayId` and `versionNumber`; `placed: false` means that quote was already on the board. Put the face under or beside its note in the same stack; an edge may name it by `@<key>`. `add-quote` is for a board that already exists.
69
+ A `quote` leaf is a note's face (canvas-elements.md rules 4 and 8): `text` is the exact words from the note's saved version, `noteId` a display id or the `@<key>` of a note the same call creates, `style` (`pull` default, `highlight`, `evidence`), `size` (`small` default, `medium`, `large`), `colorHex` a role hex, `title` your own words for why the line matters. Without a `title` the Quote note is titled with the quoted words up to their first full stop, semicolon or consequence clause, so a claim sentence passes the title rule; words that still fail it (a banned word, a display id) are refused until you pass a `title`. The server makes or reuses the Quote note (`QUOTE-<n>`, the same one `canvas add-quote` would make) and places its card where the solver put the leaf, inside its frame, measured from its words. The response item carries `quoteNoteDisplayId`, `noteDisplayId` and `versionNumber`; `placed: false` means that quote was already on the board. Put the face under or beside its note in the same stack; an edge may name it by `@<key>`. `add-quote` is for a board that already exists.
70
70
 
71
71
  `richtext` IS the **text** element (the CLI's `add-text`), the only free-form text leaf. A heading is a `richtext` leaf whose content is `"# Title"` with no `colorHex`. There is no `"type": "text"` leaf: the old heading node kind is retired and the layout engine rejects it.
72
72
 
@@ -221,7 +221,7 @@ What makes a board readable at fit zoom:
221
221
  { "kind": "stack", "axis": "vertical", "gap": 20, "items": [
222
222
  { "kind": "item", "type": "richtext", "content": "# 1 · What goes wrong" },
223
223
  { "kind": "item", "type": "note", "noteId": "@problem" },
224
- { "kind": "item", "type": "quote", "noteId": "@problem", "text": "Every review waits on Ana", "size": "medium", "key": "f1" },
224
+ { "kind": "item", "type": "quote", "noteId": "@problem", "text": "Every review waits on Ana", "title": "One reviewer gates every ship", "size": "medium", "key": "f1" },
225
225
  { "kind": "item", "type": "richtext", "size": "small", "key": "c1",
226
226
  "content": "Four late ships in one month is the cost of one reviewer, not of slow reviewers. So the fix is who reviews, not how fast." }
227
227
  ] },
@@ -7,7 +7,7 @@ The one contract every command follows is in the core skill (the flag table and
7
7
  - `notes list`, `notes get` and `notes search` emit a bare array, so one note is `.[0]`. `notes get --expand` is the exception: an object `{ notes, linked, truncated, cap, omitted, notice }` (notes.md).
8
8
  - `notes create` returns `{ results, relationshipsCreated, rubrics?, hints? }`; read new notes from `results`. Each row carries `type`, `url`, and `quality` where the workspace grades on save; each used type's rubric is in `rubrics`, once.
9
9
  - `canvas create` returns `{ canvas: { id, displayId, url } }` with `id`, `displayId` and `url` mirrored at the top level; after `create --spec` the placement is under `layout`, and `displayId` can still be null until `canvas get` reads it.
10
- - `canvas place` returns `{ items, edges, bbox, successCount, notes?, arrangedSections? }`. It is best-effort, not transactional (HTTP 207): read `items[].error` and `edges[].error` before assuming success. A `quote` item adds `quoteNoteDisplayId`, `noteDisplayId`, `versionNumber` and `placed`.
10
+ - `canvas place` returns `{ items, edges, bbox, successCount, notes?, arrangedSections? }`. It is best-effort, not transactional (HTTP 207): exit `3` means some items or edges were refused and the rest landed; stderr's `PlacePartial` error lists each under `failed` / `failedEdges`. `canvas create --spec` and `canvas bulk-add` (`BulkAddPartial`) exit the same way. `canvas arrange` exits `1` (`ArrangeFailed`) when no card moved and `3` (`ArrangePartial`) when the cards moved but the frame did not resize or the band below did not shift (`rippleError`); an arrange is safe to re-run. A section that could not keep itself arranged afterwards is a `⚠` line on stderr, exit `0`. A `quote` item adds `quoteNoteDisplayId`, `noteDisplayId`, `versionNumber` and `placed`.
11
11
  - A note body comes back under `markdown` from `canvas read` and under `content` from `notes get --json`; read the key for the command you ran. A `canvas read` whose JSON starts with `level: "cards"` or `"frames"` is a map of a long board: each frame lists its cards under `lines`, with no bodies; `next` names the commands that open a frame, chosen notes or (`--full`) every body. `notes get --content-only` prints the raw markdown with no envelope, the right read for a transcript.
12
12
 
13
13
  ## Errors and notices go to stderr