@creator-notes/cnotes 0.148.0 → 0.149.1
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/dist/commands/canvas.js
CHANGED
|
@@ -281,6 +281,81 @@ function reportPlaceShortfall(data, json) {
|
|
|
281
281
|
console.error(`Error: ${partialPlaceSummary(data)} were not placed (see above). ${PARTIAL_PLACE_HINT}`);
|
|
282
282
|
}
|
|
283
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 || keepError !== undefined),
|
|
299
|
+
failed,
|
|
300
|
+
total: items.length,
|
|
301
|
+
section: typeof data.targetSectionDisplayId === "string" ? data.targetSectionDisplayId : "the section",
|
|
302
|
+
...(rippleError !== undefined ? { rippleError } : {}),
|
|
303
|
+
...(keepError !== undefined ? { keepError } : {}),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
const ARRANGE_FAILED_HINT = "Nothing moved and the frame is as it was. Fix what each item under `failed` names " +
|
|
307
|
+
"(`cnotes canvas status <canvas>` lists the node ids) and run the same arrange again.";
|
|
308
|
+
const ARRANGE_PARTIAL_HINT = "The cards that moved stay moved. Arrange only moves cards already on the canvas, " +
|
|
309
|
+
"so it is safe to re-run the same command once the cause is fixed.";
|
|
310
|
+
function arrangePartialSummary(shortfall) {
|
|
311
|
+
const parts = [];
|
|
312
|
+
if (shortfall.failed.length > 0)
|
|
313
|
+
parts.push(`${shortfall.failed.length} of ${shortfall.total} items were refused`);
|
|
314
|
+
if (shortfall.rippleError !== undefined)
|
|
315
|
+
parts.push(`the band below was not pushed down (${shortfall.rippleError})`);
|
|
316
|
+
if (shortfall.keepError !== undefined) {
|
|
317
|
+
parts.push(`${shortfall.section} could not keep itself arranged (${shortfall.keepError}), so it will not re-lay itself as cards change`);
|
|
318
|
+
}
|
|
319
|
+
return parts.join(", and ");
|
|
320
|
+
}
|
|
321
|
+
/** Set arrange's exit code and print its shortfall on stderr, in the output mode in use. */
|
|
322
|
+
function reportArrangeShortfall(data, json) {
|
|
323
|
+
const shortfall = arrangeShortfall(data);
|
|
324
|
+
if (!shortfall)
|
|
325
|
+
return;
|
|
326
|
+
if (shortfall.nothing) {
|
|
327
|
+
process.exitCode = EXIT_CODES.GENERIC;
|
|
328
|
+
if (json) {
|
|
329
|
+
console.error(JSON.stringify({
|
|
330
|
+
error: "arrangeLayout moved nothing: every item failed",
|
|
331
|
+
code: "ArrangeFailed",
|
|
332
|
+
exitCode: EXIT_CODES.GENERIC,
|
|
333
|
+
failed: shortfall.failed,
|
|
334
|
+
hint: ARRANGE_FAILED_HINT,
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
console.error(`Error: nothing was arranged (see above). ${ARRANGE_FAILED_HINT}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else if (shortfall.partial) {
|
|
342
|
+
process.exitCode = EXIT_CODES.VALIDATION;
|
|
343
|
+
if (json) {
|
|
344
|
+
console.error(JSON.stringify({
|
|
345
|
+
error: `arrangeLayout landed only in part: ${arrangePartialSummary(shortfall)}`,
|
|
346
|
+
code: "ArrangePartial",
|
|
347
|
+
exitCode: EXIT_CODES.VALIDATION,
|
|
348
|
+
...(shortfall.failed.length > 0 ? { failed: shortfall.failed } : {}),
|
|
349
|
+
...(shortfall.rippleError !== undefined ? { rippleError: shortfall.rippleError } : {}),
|
|
350
|
+
...(shortfall.keepError !== undefined ? { keepError: shortfall.keepError } : {}),
|
|
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
|
+
}
|
|
284
359
|
function reportNothingPlacedJson() {
|
|
285
360
|
console.error(JSON.stringify({
|
|
286
361
|
error: "placeLayout placed nothing: every item and edge failed",
|
|
@@ -2275,6 +2350,7 @@ Examples:
|
|
|
2275
2350
|
if (link)
|
|
2276
2351
|
data.url = link;
|
|
2277
2352
|
outputJson(data);
|
|
2353
|
+
reportArrangeShortfall(data, true);
|
|
2278
2354
|
return;
|
|
2279
2355
|
}
|
|
2280
2356
|
const items = (data.items || []);
|
|
@@ -2309,6 +2385,7 @@ Examples:
|
|
|
2309
2385
|
}
|
|
2310
2386
|
if (link)
|
|
2311
2387
|
console.log(`Link: ${link}`);
|
|
2388
|
+
reportArrangeShortfall(data, false);
|
|
2312
2389
|
}
|
|
2313
2390
|
catch (error) {
|
|
2314
2391
|
handleError(error, cfg.json);
|
package/package.json
CHANGED
|
@@ -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): 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`.
|
|
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, the band below did not shift (`rippleError`) or the section could not keep itself arranged (`keepError`); an arrange is safe to re-run. 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
|