@creator-notes/cnotes 0.147.0 → 0.148.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.
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
|
|
package/dist/commands/canvas.js
CHANGED
|
@@ -205,10 +205,10 @@ function reportPlacedNotes(data) {
|
|
|
205
205
|
return createdRows;
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
|
-
* The server answers 207 with per-item results
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
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,69 @@ 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
|
+
}
|
|
221
284
|
function reportNothingPlacedJson() {
|
|
222
285
|
console.error(JSON.stringify({
|
|
223
286
|
error: "placeLayout placed nothing: every item and edge failed",
|
|
@@ -1071,12 +1134,11 @@ spec and run the same command again.
|
|
|
1071
1134
|
}
|
|
1072
1135
|
const data = await api.post("/api/canvas", body);
|
|
1073
1136
|
const createdRows = data.layout ? reportPlacedNotes(data.layout) : [];
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
process.exitCode = EXIT_CODES.GENERIC;
|
|
1137
|
+
if (data.layout)
|
|
1138
|
+
setPlaceExitCode(data.layout);
|
|
1077
1139
|
printCreatedCanvas(cfg, name, data, createdRows);
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1140
|
+
if (data.layout)
|
|
1141
|
+
reportPlaceShortfall(data.layout, cfg.json);
|
|
1080
1142
|
}
|
|
1081
1143
|
catch (error) {
|
|
1082
1144
|
handleError(error, cfg.json);
|
|
@@ -1853,15 +1915,18 @@ Examples:
|
|
|
1853
1915
|
});
|
|
1854
1916
|
const link = await resolveCanvasLink(api, cfg, canvasId);
|
|
1855
1917
|
// The server answers 201/207 with per-item results
|
|
1856
|
-
// ({index, type, id, error?}).
|
|
1857
|
-
//
|
|
1858
|
-
//
|
|
1859
|
-
// success to an agent that keys on the exit code.
|
|
1918
|
+
// ({index, type, id, error?}). An agent keys on the exit code, so a
|
|
1919
|
+
// refused note never exits 0: 3 when some were refused, 1 when every
|
|
1920
|
+
// one was and nothing was added.
|
|
1860
1921
|
const results = (data.results || []);
|
|
1861
1922
|
const failedResults = results.filter((r) => !r.id || r.error);
|
|
1862
1923
|
const allFailed = results.length > 0 && failedResults.length === results.length;
|
|
1924
|
+
const someFailed = failedResults.length > 0 && !allFailed;
|
|
1863
1925
|
if (allFailed)
|
|
1864
1926
|
process.exitCode = EXIT_CODES.GENERIC;
|
|
1927
|
+
else if (someFailed)
|
|
1928
|
+
process.exitCode = EXIT_CODES.VALIDATION;
|
|
1929
|
+
const partialHint = "The rest were added. Re-run bulk-add with only the refused notes once each is fixed.";
|
|
1865
1930
|
if (cfg.json) {
|
|
1866
1931
|
if (link)
|
|
1867
1932
|
data.url = link;
|
|
@@ -1874,6 +1939,19 @@ Examples:
|
|
|
1874
1939
|
hint: "Inspect results[].error in the response above; fix the failing note refs and retry.",
|
|
1875
1940
|
}));
|
|
1876
1941
|
}
|
|
1942
|
+
else if (someFailed) {
|
|
1943
|
+
console.error(JSON.stringify({
|
|
1944
|
+
error: `bulk-add refused ${failedResults.length} of ${results.length} notes; the rest were added`,
|
|
1945
|
+
code: "BulkAddPartial",
|
|
1946
|
+
exitCode: EXIT_CODES.VALIDATION,
|
|
1947
|
+
failed: failedResults.map((r) => ({
|
|
1948
|
+
index: r.index,
|
|
1949
|
+
noteId: notes[typeof r.index === "number" ? r.index : -1]?.noteId,
|
|
1950
|
+
error: String(r.error ?? "not added"),
|
|
1951
|
+
})),
|
|
1952
|
+
hint: partialHint,
|
|
1953
|
+
}));
|
|
1954
|
+
}
|
|
1877
1955
|
}
|
|
1878
1956
|
else {
|
|
1879
1957
|
const added = results.length - failedResults.length;
|
|
@@ -1887,6 +1965,9 @@ Examples:
|
|
|
1887
1965
|
if (allFailed) {
|
|
1888
1966
|
console.error("Error: no notes were added — every item failed (see above).");
|
|
1889
1967
|
}
|
|
1968
|
+
else if (someFailed) {
|
|
1969
|
+
console.error(`Error: ${failedResults.length} of ${results.length} notes were not added (see above). ${partialHint}`);
|
|
1970
|
+
}
|
|
1890
1971
|
if (link)
|
|
1891
1972
|
console.log(`Link: ${link}`);
|
|
1892
1973
|
}
|
|
@@ -1958,15 +2039,12 @@ Placement (relative to nodes already on the canvas):
|
|
|
1958
2039
|
const link = opts.dryRun
|
|
1959
2040
|
? null
|
|
1960
2041
|
: await resolveCanvasLink(api, cfg, canvasId);
|
|
1961
|
-
|
|
1962
|
-
if (nothingPlaced)
|
|
1963
|
-
process.exitCode = EXIT_CODES.GENERIC;
|
|
2042
|
+
setPlaceExitCode(data);
|
|
1964
2043
|
if (cfg.json) {
|
|
1965
2044
|
if (link)
|
|
1966
2045
|
data.url = link;
|
|
1967
2046
|
outputJson(data);
|
|
1968
|
-
|
|
1969
|
-
reportNothingPlacedJson();
|
|
2047
|
+
reportPlaceShortfall(data, true);
|
|
1970
2048
|
}
|
|
1971
2049
|
else {
|
|
1972
2050
|
if (data.dryRun) {
|
|
@@ -1983,6 +2061,7 @@ Placement (relative to nodes already on the canvas):
|
|
|
1983
2061
|
printPlaceSummary(data, createdRows);
|
|
1984
2062
|
if (link)
|
|
1985
2063
|
console.log(`Link: ${link}`);
|
|
2064
|
+
reportPlaceShortfall(data, false);
|
|
1986
2065
|
}
|
|
1987
2066
|
}
|
|
1988
2067
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -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.
|
|
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):
|
|
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. 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
|