@creator-notes/cnotes 0.108.0 → 0.109.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/.claude-plugin/plugin.json +1 -1
- package/dist/commands/canvas.js +51 -0
- package/dist/commands/notes.js +4 -92
- package/dist/lib/note-batch.js +106 -0
- package/dist/mcp-server.js +14 -2
- package/package.json +1 -1
- package/skills/cnotes/SKILL.md +19 -1
- package/skills/cnotes/references/canvas-layout.md +2 -0
package/dist/commands/canvas.js
CHANGED
|
@@ -19,6 +19,8 @@ import { CANVAS_GOAL_DESCRIPTION } from "../lib/canvas-goal.js";
|
|
|
19
19
|
import { canvasActionPath, commentsListPath, parseCommentStatus, } from "../lib/canvas-paths.js";
|
|
20
20
|
import { registerCanvasMilestoneCommands } from "./canvas-milestone.js";
|
|
21
21
|
import { DISPLAY_ID_CORE } from "../lib/display-id.js";
|
|
22
|
+
import { resolveNoteBatchItems } from "../lib/note-batch.js";
|
|
23
|
+
import { describeUnresolvedMentions } from "../lib/mention-lint.js";
|
|
22
24
|
/** A node handle the agent reads off `canvas read`: NOTE-12, SECTION-7, … */
|
|
23
25
|
const NODE_DISPLAY_REF_RE = new RegExp(String.raw `^${DISPLAY_ID_CORE}$`);
|
|
24
26
|
/**
|
|
@@ -1684,6 +1686,19 @@ Examples:
|
|
|
1684
1686
|
$ echo '{"root":{"type":"stack","items":[...]}}' | cnotes canvas place <canvasId> --spec-stdin
|
|
1685
1687
|
$ cnotes canvas place <canvasId> --spec ./layout.json --dry-run --json
|
|
1686
1688
|
|
|
1689
|
+
New notes in the same call: give the spec a "notes" array in the notes create
|
|
1690
|
+
shape ({key, type, markdown|markdownFile, tags?}) and place each one with a note
|
|
1691
|
+
leaf {"kind":"item","type":"note","noteId":"@<key>"}. Bodies cross-link with
|
|
1692
|
+
[@<key>: Title](relationship:<verb>); edges and anchors say "@<key>". The notes
|
|
1693
|
+
are created only if the layout solves, need an open run (operations begin), and
|
|
1694
|
+
come back under "notes" in the notes create response shape. A dry run creates
|
|
1695
|
+
nothing.
|
|
1696
|
+
{"notes":[{"key":"A","type":"Insight","markdown":"# Reviews wait on one person"}],
|
|
1697
|
+
"root":{"kind":"stack","axis":"horizontal","items":[
|
|
1698
|
+
{"kind":"item","type":"note","noteId":"@A"},
|
|
1699
|
+
{"kind":"item","type":"note","noteId":"DECISION-12"}]},
|
|
1700
|
+
"edges":[{"from":"@A","to":"DECISION-12","label":"grounds"}]}
|
|
1701
|
+
|
|
1687
1702
|
Sections: a section container in the spec ({"kind":"section","name":…,"child":…})
|
|
1688
1703
|
creates an ARRANGED section. It keeps its cards laid out as they are added, edited
|
|
1689
1704
|
or removed, until someone moves a card by hand. Put more cards in it later with
|
|
@@ -1738,12 +1753,44 @@ Placement (relative to nodes already on the canvas):
|
|
|
1738
1753
|
doc.placement = opts.placement;
|
|
1739
1754
|
}
|
|
1740
1755
|
warnLayoutListMisuse(doc);
|
|
1756
|
+
// New notes ride in the spec's own `notes` array (the `notes create`
|
|
1757
|
+
// batch shape), checked here exactly as `notes create` checks them,
|
|
1758
|
+
// and go to the server beside the layout document.
|
|
1759
|
+
let notes;
|
|
1760
|
+
if (doc && typeof doc === "object" && !Array.isArray(doc) && "notes" in doc) {
|
|
1761
|
+
const { notes: rawNotes, ...layout } = doc;
|
|
1762
|
+
if (!Array.isArray(rawNotes) || rawNotes.length === 0) {
|
|
1763
|
+
throw new ValidationError('"notes" must be a non-empty array of {key, type, markdown|markdownFile}');
|
|
1764
|
+
}
|
|
1765
|
+
notes = resolveNoteBatchItems(rawNotes);
|
|
1766
|
+
doc = layout;
|
|
1767
|
+
}
|
|
1741
1768
|
const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
|
|
1742
1769
|
action: "placeLayout",
|
|
1743
1770
|
doc,
|
|
1771
|
+
...(notes ? { notes } : {}),
|
|
1744
1772
|
...(opts.into ? { intoSection: opts.into } : {}),
|
|
1745
1773
|
...(opts.dryRun ? { dryRun: true } : {}),
|
|
1746
1774
|
});
|
|
1775
|
+
// The notes exist once the call returns, even when placing failed:
|
|
1776
|
+
// never re-run a spec with notes to retry, it duplicates them.
|
|
1777
|
+
const createdNotes = data.notes;
|
|
1778
|
+
const createdRows = (createdNotes?.results || []);
|
|
1779
|
+
if (createdNotes) {
|
|
1780
|
+
for (const row of createdRows) {
|
|
1781
|
+
reportHeadlineWarnings(readHeadlineWarnings(row), typeof row.displayId === "string" ? row.displayId : undefined);
|
|
1782
|
+
if (typeof row.hint === "string" && row.hint.trim())
|
|
1783
|
+
console.error(`Hint: ${row.hint.trim()}`);
|
|
1784
|
+
}
|
|
1785
|
+
const unresolved = describeUnresolvedMentions(createdNotes.unresolvedMentions);
|
|
1786
|
+
if (unresolved) {
|
|
1787
|
+
console.error(`\n⚠ Some relationship mentions did not resolve. The ${createdRows.length} note(s) ` +
|
|
1788
|
+
`were CREATED but carry broken links:\n${unresolved}\n` +
|
|
1789
|
+
`Fix forward: cnotes versions create <id> --markdown-file <fixed.md>. ` +
|
|
1790
|
+
`Do NOT re-run place — it would duplicate the notes.`);
|
|
1791
|
+
process.exitCode = EXIT_CODES.VALIDATION;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1747
1794
|
// No canvas was mutated on a dry run, so don't surface a "here's what I
|
|
1748
1795
|
// built" link for it.
|
|
1749
1796
|
const link = opts.dryRun
|
|
@@ -1786,6 +1833,10 @@ Placement (relative to nodes already on the canvas):
|
|
|
1786
1833
|
}
|
|
1787
1834
|
return;
|
|
1788
1835
|
}
|
|
1836
|
+
if (createdRows.length > 0) {
|
|
1837
|
+
console.log(`Created ${createdRows.length} note${createdRows.length === 1 ? "" : "s"}: ` +
|
|
1838
|
+
createdRows.map((r) => `${r.key} → ${r.displayId}`).join(", "));
|
|
1839
|
+
}
|
|
1789
1840
|
const placed = items.filter((r) => r.id && !r.error).length;
|
|
1790
1841
|
const failed = items.filter((r) => !r.id || r.error).length;
|
|
1791
1842
|
const edgesAdded = edges.filter((e) => e.id && !e.error).length;
|
package/dist/commands/notes.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ApiClient } from "../lib/api-client.js";
|
|
2
2
|
import { resolveConfig } from "../lib/config.js";
|
|
3
3
|
import { handleError, NotFoundError, ValidationError, EXIT_CODES } from "../lib/errors.js";
|
|
4
|
-
import { parseJsonOption
|
|
4
|
+
import { parseJsonOption } from "../lib/fs-utils.js";
|
|
5
5
|
import { outputJson, outputTable, outputQuiet, timeAgo, truncate } from "../lib/output.js";
|
|
6
6
|
import { readHeadlineWarnings, reportHeadlineWarnings } from "../lib/headline-warnings.js";
|
|
7
7
|
import { resolveNoteId } from "../lib/resolve-note.js";
|
|
8
8
|
import { formatNoteDimensionLines, parseDimensionFilter, readNoteDimensions } from "../lib/note-dimensions.js";
|
|
9
9
|
import { formatLinkedItemHeading, groupLinkedByRelation, parseExpandArgs, projectExpandPayload, renderExpandContentOnly, } from "../lib/expand-notes.js";
|
|
10
|
-
import {
|
|
10
|
+
import { resolveNoteBatchItems } from "../lib/note-batch.js";
|
|
11
|
+
import { describeUnresolvedMentions, lintNarratedVerbMentions, lintPlainTextDisplayIdsBatch, hasGenericMention, fetchRelationshipTypeOptions, } from "../lib/mention-lint.js";
|
|
11
12
|
import { attachRubricsToResults, loadRubricMap, rubricsForTypes, } from "../lib/rubrics.js";
|
|
12
13
|
import { DECISION_CARD_RULE, } from "../lib/decision-citation.js";
|
|
13
14
|
export function registerNotesCommands(program) {
|
|
@@ -623,96 +624,7 @@ Output (--json):
|
|
|
623
624
|
if (items.length === 0) {
|
|
624
625
|
throw new ValidationError("--notes must contain at least one item (object or non-empty array)");
|
|
625
626
|
}
|
|
626
|
-
const
|
|
627
|
-
const notes = [];
|
|
628
|
-
items.forEach((raw, index) => {
|
|
629
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
630
|
-
localErrors.push({ index, field: "item", message: "Item must be a JSON object" });
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
const obj = raw;
|
|
634
|
-
const key = typeof obj.key === "string" ? obj.key.trim() : "";
|
|
635
|
-
const type = typeof obj.type === "string" ? obj.type.trim() : "";
|
|
636
|
-
const markdownInline = typeof obj.markdown === "string" ? obj.markdown : undefined;
|
|
637
|
-
const markdownFile = typeof obj.markdownFile === "string" ? obj.markdownFile : undefined;
|
|
638
|
-
if (!key) {
|
|
639
|
-
localErrors.push({ index, field: "key", message: "key is required (non-empty string used to cross-reference items in this batch)" });
|
|
640
|
-
}
|
|
641
|
-
if (!type) {
|
|
642
|
-
localErrors.push({ index, key: key || undefined, field: "type", message: "type is required (e.g. \"Insight\", \"Meeting\")" });
|
|
643
|
-
}
|
|
644
|
-
let markdown = markdownInline;
|
|
645
|
-
if (!markdown && markdownFile) {
|
|
646
|
-
try {
|
|
647
|
-
markdown = readFileSafe(markdownFile);
|
|
648
|
-
}
|
|
649
|
-
catch (e) {
|
|
650
|
-
const reason = e instanceof Error ? e.message : "could not read file";
|
|
651
|
-
localErrors.push({ index, key: key || undefined, field: "markdownFile", message: reason });
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (!markdown) {
|
|
655
|
-
localErrors.push({ index, key: key || undefined, field: "markdown", message: "markdown or markdownFile is required" });
|
|
656
|
-
}
|
|
657
|
-
let tags;
|
|
658
|
-
if (obj.tags !== undefined && obj.tags !== null) {
|
|
659
|
-
if (!Array.isArray(obj.tags) || !obj.tags.every((t) => typeof t === "string")) {
|
|
660
|
-
localErrors.push({ index, key: key || undefined, field: "tags", message: "tags must be an array of strings" });
|
|
661
|
-
}
|
|
662
|
-
else {
|
|
663
|
-
tags = obj.tags;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
let changeDescription;
|
|
667
|
-
if (obj.changeDescription !== undefined && obj.changeDescription !== null) {
|
|
668
|
-
if (typeof obj.changeDescription !== "string") {
|
|
669
|
-
localErrors.push({
|
|
670
|
-
index,
|
|
671
|
-
key: key || undefined,
|
|
672
|
-
field: "changeDescription",
|
|
673
|
-
message: "changeDescription must be a string",
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
const trimmed = obj.changeDescription.trim();
|
|
678
|
-
if (trimmed)
|
|
679
|
-
changeDescription = trimmed;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
if (markdown) {
|
|
683
|
-
// Pre-send mention lint: catch malformed relationship mentions
|
|
684
|
-
// (verb-as-link-text, prose-as-target) BEFORE anything is created,
|
|
685
|
-
// so the fix is free — nothing to undo, safe to re-run. @key is
|
|
686
|
-
// allowed here because batch placeholders resolve server-side.
|
|
687
|
-
for (const issue of lintMentionMarkdown(markdown, true)) {
|
|
688
|
-
localErrors.push({
|
|
689
|
-
index,
|
|
690
|
-
key: key || undefined,
|
|
691
|
-
field: "markdown",
|
|
692
|
-
message: `bad relationship mention ${issue.raw}: ${issue.message}`,
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
if (key && type && markdown) {
|
|
697
|
-
notes.push({
|
|
698
|
-
key,
|
|
699
|
-
type,
|
|
700
|
-
markdown,
|
|
701
|
-
tags,
|
|
702
|
-
...(changeDescription ? { changeDescription } : {}),
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
if (localErrors.length > 0) {
|
|
707
|
-
const summary = `${localErrors.length} of ${items.length} item${items.length === 1 ? "" : "s"} invalid`;
|
|
708
|
-
const lines = localErrors.map((e) => ` - item ${e.index} (${e.key ?? "?"}): ${e.field}: ${e.message}`);
|
|
709
|
-
// Attach the structured per-item errors as `details` in the same
|
|
710
|
-
// `{ items: [...] }` shape the server's batch-error contract uses,
|
|
711
|
-
// so --json callers can branch on index/key/field without parsing prose.
|
|
712
|
-
throw new ValidationError(`${summary}\n${lines.join("\n")}`, undefined, {
|
|
713
|
-
items: localErrors,
|
|
714
|
-
});
|
|
715
|
-
}
|
|
627
|
+
const notes = resolveNoteBatchItems(items);
|
|
716
628
|
// Narrated-verb lint (warn-only, computed pre-send): prose like
|
|
717
629
|
// "Blocks [[CLAIM-6G2]]" files a plain `references` edge the graph
|
|
718
630
|
// can't distinguish from a citation. Never blocks the write — types
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ValidationError } from "./errors.js";
|
|
2
|
+
import { readFileSafe } from "./fs-utils.js";
|
|
3
|
+
import { lintMentionMarkdown } from "./mention-lint.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolve and check a batch of notes before anything is sent: `notes create
|
|
6
|
+
* --notes` and the `notes` array of a `canvas place` spec. Reads markdownFile
|
|
7
|
+
* into markdown and lints relationship mentions. Collects ALL errors so an
|
|
8
|
+
* agent can fix the whole batch in one shot rather than one item at a time,
|
|
9
|
+
* and throws them as one ValidationError with `details.items`.
|
|
10
|
+
*
|
|
11
|
+
* Mirror of validateBulkCreateItem in lib/api/note-batch.ts. Keep field shape
|
|
12
|
+
* and messages in sync with the route.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveNoteBatchItems(items) {
|
|
15
|
+
const localErrors = [];
|
|
16
|
+
const notes = [];
|
|
17
|
+
items.forEach((raw, index) => {
|
|
18
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
19
|
+
localErrors.push({ index, field: "item", message: "Item must be a JSON object" });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const obj = raw;
|
|
23
|
+
const key = typeof obj.key === "string" ? obj.key.trim() : "";
|
|
24
|
+
const type = typeof obj.type === "string" ? obj.type.trim() : "";
|
|
25
|
+
const markdownInline = typeof obj.markdown === "string" ? obj.markdown : undefined;
|
|
26
|
+
const markdownFile = typeof obj.markdownFile === "string" ? obj.markdownFile : undefined;
|
|
27
|
+
if (!key) {
|
|
28
|
+
localErrors.push({ index, field: "key", message: "key is required (non-empty string used to cross-reference items in this batch)" });
|
|
29
|
+
}
|
|
30
|
+
if (!type) {
|
|
31
|
+
localErrors.push({ index, key: key || undefined, field: "type", message: "type is required (e.g. \"Insight\", \"Meeting\")" });
|
|
32
|
+
}
|
|
33
|
+
let markdown = markdownInline;
|
|
34
|
+
if (!markdown && markdownFile) {
|
|
35
|
+
try {
|
|
36
|
+
markdown = readFileSafe(markdownFile);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
const reason = e instanceof Error ? e.message : "could not read file";
|
|
40
|
+
localErrors.push({ index, key: key || undefined, field: "markdownFile", message: reason });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!markdown) {
|
|
44
|
+
localErrors.push({ index, key: key || undefined, field: "markdown", message: "markdown or markdownFile is required" });
|
|
45
|
+
}
|
|
46
|
+
let tags;
|
|
47
|
+
if (obj.tags !== undefined && obj.tags !== null) {
|
|
48
|
+
if (!Array.isArray(obj.tags) || !obj.tags.every((t) => typeof t === "string")) {
|
|
49
|
+
localErrors.push({ index, key: key || undefined, field: "tags", message: "tags must be an array of strings" });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
tags = obj.tags;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let changeDescription;
|
|
56
|
+
if (obj.changeDescription !== undefined && obj.changeDescription !== null) {
|
|
57
|
+
if (typeof obj.changeDescription !== "string") {
|
|
58
|
+
localErrors.push({
|
|
59
|
+
index,
|
|
60
|
+
key: key || undefined,
|
|
61
|
+
field: "changeDescription",
|
|
62
|
+
message: "changeDescription must be a string",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const trimmed = obj.changeDescription.trim();
|
|
67
|
+
if (trimmed)
|
|
68
|
+
changeDescription = trimmed;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (markdown) {
|
|
72
|
+
// Pre-send mention lint: catch malformed relationship mentions
|
|
73
|
+
// (verb-as-link-text, prose-as-target) BEFORE anything is created,
|
|
74
|
+
// so the fix is free — nothing to undo, safe to re-run. @key is
|
|
75
|
+
// allowed here because batch placeholders resolve server-side.
|
|
76
|
+
for (const issue of lintMentionMarkdown(markdown, true)) {
|
|
77
|
+
localErrors.push({
|
|
78
|
+
index,
|
|
79
|
+
key: key || undefined,
|
|
80
|
+
field: "markdown",
|
|
81
|
+
message: `bad relationship mention ${issue.raw}: ${issue.message}`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (key && type && markdown) {
|
|
86
|
+
notes.push({
|
|
87
|
+
key,
|
|
88
|
+
type,
|
|
89
|
+
markdown,
|
|
90
|
+
tags,
|
|
91
|
+
...(changeDescription ? { changeDescription } : {}),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (localErrors.length > 0) {
|
|
96
|
+
const summary = `${localErrors.length} of ${items.length} item${items.length === 1 ? "" : "s"} invalid`;
|
|
97
|
+
const lines = localErrors.map((e) => ` - item ${e.index} (${e.key ?? "?"}): ${e.field}: ${e.message}`);
|
|
98
|
+
// Attach the structured per-item errors as `details` in the same
|
|
99
|
+
// `{ items: [...] }` shape the server's batch-error contract uses,
|
|
100
|
+
// so --json callers can branch on index/key/field without parsing prose.
|
|
101
|
+
throw new ValidationError(`${summary}\n${lines.join("\n")}`, undefined, {
|
|
102
|
+
items: localErrors,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return notes;
|
|
106
|
+
}
|
package/dist/mcp-server.js
CHANGED
|
@@ -610,7 +610,7 @@ server.tool("cnotes_canvas_bulk_add", "LOW-LEVEL: add items at raw x/y that YOU
|
|
|
610
610
|
items: allItems,
|
|
611
611
|
});
|
|
612
612
|
}));
|
|
613
|
-
server.tool("cnotes_canvas_place", "Place items on a canvas using a DECLARATIVE LAYOUT (no x/y math). The server measures every item, packs them with no overlaps, and inserts them in a single batch. PREFER THIS over cnotes_canvas_bulk_add whenever you can express the layout as stacks/grids/anchors — which is almost always. The agent should describe STRUCTURE (rows, columns, what's near what), not pixel coordinates.\n\nELEMENT CHOICE: default content to typed NOTES (the only versioned, searchable tier agents can read back); richtext = the Text element, card-sized framing only (a heading is just content '# Title', untinted), section = a named region frame, list = member notes behind a one-line frame, edges connect notes only.\n\nThe call is best-effort, NOT atomic: 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` in the response.\n\nThe `doc` argument is a layout document:\n { root: <LayoutNode>, edges?: [{from, to, label?}], origin?: {x, y} }\n\n<LayoutNode> is one of:\n • { kind: 'stack', axis: 'vertical'|'horizontal', gap?: 'tight'|'medium'|'spacious'|<px>, align?: 'start'|'center'|'end', items: [<LayoutNode>...] }\n • { kind: 'grid', columns: <n>, gap?: ..., items: [<LayoutNode>...] }\n • { kind: 'anchor', to: '<displayId or canvas node id>', direction: 'right'|'left'|'above'|'below', gap?: ..., child: <LayoutNode> }\n • { kind: 'item', type: 'note'|'richtext'|'list'|'canvas'|'section', key?: '<name>', ...item-specific fields }\n\nLeaf item shapes (no x/y!):\n note: { kind:'item', type:'note', noteId:'NOTE-3', key?:'a' }\n richtext: { kind:'item', type:'richtext', content:'# Markdown OK', size?:'small'|'medium'|'large', colorHex?:'<role hex>' } // the Text element: card-sized framing only; a heading is just content '# Title' with no colorHex; colorHex is a ROLE tint (#3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people — anything else snaps to the nearest), default untinted; plain markdown, NO [NOTE-X](relationship:...) mention syntax (corrupts the card); knowledge worth keeping = a note\n list: { kind:'item', type:'list', description:'One-line frame — first paragraph becomes the title', noteIds?:['NOTE-1','NOTE-2'], viewMode?:'list'|'grid' } // description is REQUIRED and is a frame, never the content: N distinct things = N notes in noteIds\n canvas: { kind:'item', type:'canvas', linkedCanvasId:'<id>' }\n\nEdges reference endpoints by, in priority order: `@<key>` (any item with a `key` placed in the same call), the original noteId/displayId of a note placed in this call (e.g. 'NOTE-7'), or the displayId / convex id of a node already on the canvas.\n\nExample (a SWOT-like quadrant):\n {\n root: {\n kind:'stack', axis:'vertical', gap:'spacious',\n items:[\n { kind:'stack', axis:'horizontal', gap:'spacious', items:[\n { kind:'grid', columns:2, items:[\n { kind:'item', type:'note', noteId:'STR-1' },\n { kind:'item', type:'note', noteId:'STR-2' },\n ]},\n { kind:'grid', columns:2, items:[\n { kind:'item', type:'note', noteId:'WEAK-1' },\n ]},\n ]},\n { kind:'stack', axis:'horizontal', gap:'spacious', items:[ /* opportunities + threats */ ]},\n ],\n },\n }", {
|
|
613
|
+
server.tool("cnotes_canvas_place", "Place items on a canvas using a DECLARATIVE LAYOUT (no x/y math). The server measures every item, packs them with no overlaps, and inserts them in a single batch. PREFER THIS over cnotes_canvas_bulk_add whenever you can express the layout as stacks/grids/anchors — which is almost always. The agent should describe STRUCTURE (rows, columns, what's near what), not pixel coordinates.\n\nELEMENT CHOICE: default content to typed NOTES (the only versioned, searchable tier agents can read back); richtext = the Text element, card-sized framing only (a heading is just content '# Title', untinted), section = a named region frame, list = member notes behind a one-line frame, edges connect notes only.\n\nThe call is best-effort, NOT atomic: 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` in the response.\n\nThe `doc` argument is a layout document:\n { root: <LayoutNode>, edges?: [{from, to, label?}], origin?: {x, y} }\n\n<LayoutNode> is one of:\n • { kind: 'stack', axis: 'vertical'|'horizontal', gap?: 'tight'|'medium'|'spacious'|<px>, align?: 'start'|'center'|'end', items: [<LayoutNode>...] }\n • { kind: 'grid', columns: <n>, gap?: ..., items: [<LayoutNode>...] }\n • { kind: 'anchor', to: '<displayId or canvas node id>', direction: 'right'|'left'|'above'|'below', gap?: ..., child: <LayoutNode> }\n • { kind: 'item', type: 'note'|'richtext'|'list'|'canvas'|'section', key?: '<name>', ...item-specific fields }\n\nLeaf item shapes (no x/y!):\n note: { kind:'item', type:'note', noteId:'NOTE-3', key?:'a' }\n richtext: { kind:'item', type:'richtext', content:'# Markdown OK', size?:'small'|'medium'|'large', colorHex?:'<role hex>' } // the Text element: card-sized framing only; a heading is just content '# Title' with no colorHex; colorHex is a ROLE tint (#3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people — anything else snaps to the nearest), default untinted; plain markdown, NO [NOTE-X](relationship:...) mention syntax (corrupts the card); knowledge worth keeping = a note\n list: { kind:'item', type:'list', description:'One-line frame — first paragraph becomes the title', noteIds?:['NOTE-1','NOTE-2'], viewMode?:'list'|'grid' } // description is REQUIRED and is a frame, never the content: N distinct things = N notes in noteIds\n canvas: { kind:'item', type:'canvas', linkedCanvasId:'<id>' }\n\nEdges reference endpoints by, in priority order: `@<key>` (any item with a `key` placed in the same call), the original noteId/displayId of a note placed in this call (e.g. 'NOTE-7'), or the displayId / convex id of a node already on the canvas.\n\nNEW NOTES IN THE SAME CALL: pass `notes` (the cnotes_notes_create item shape) and place each with a note leaf whose noteId is '@<key>'. Bodies cross-link with [@<key>: Title](relationship:<verb>); edges and anchors say '@<key>'. One call replaces notes_create then place, inside the same open operation. The notes are created only if the layout solves, and come back under `notes`.\n\nExample (a SWOT-like quadrant):\n {\n root: {\n kind:'stack', axis:'vertical', gap:'spacious',\n items:[\n { kind:'stack', axis:'horizontal', gap:'spacious', items:[\n { kind:'grid', columns:2, items:[\n { kind:'item', type:'note', noteId:'STR-1' },\n { kind:'item', type:'note', noteId:'STR-2' },\n ]},\n { kind:'grid', columns:2, items:[\n { kind:'item', type:'note', noteId:'WEAK-1' },\n ]},\n ]},\n { kind:'stack', axis:'horizontal', gap:'spacious', items:[ /* opportunities + threats */ ]},\n ],\n },\n }", {
|
|
614
614
|
canvasId: z.string().describe("Canvas ID"),
|
|
615
615
|
doc: z
|
|
616
616
|
.object({
|
|
@@ -636,10 +636,22 @@ server.tool("cnotes_canvas_place", "Place items on a canvas using a DECLARATIVE
|
|
|
636
636
|
.string()
|
|
637
637
|
.optional()
|
|
638
638
|
.describe("SECTION-<n> to put the items INTO: appended to its layout (end of its shortest column, or the next grid cell); the section re-arranges and resizes. A section container in the doc creates an ARRANGED section that keeps its cards laid out until a card is moved by hand; add to it later with intoSection, never by aiming origin inside the frame. The doc may not contain sections when intoSection is set."),
|
|
639
|
-
|
|
639
|
+
notes: z
|
|
640
|
+
.array(z.object({
|
|
641
|
+
key: z.string(),
|
|
642
|
+
type: z.string(),
|
|
643
|
+
markdown: z.string(),
|
|
644
|
+
tags: z.array(z.string()).optional(),
|
|
645
|
+
changeDescription: z.string().optional(),
|
|
646
|
+
}))
|
|
647
|
+
.min(1)
|
|
648
|
+
.optional()
|
|
649
|
+
.describe("Notes to create and place in this call (cnotes_notes_create item shape); a note leaf places one with noteId '@<key>'"),
|
|
650
|
+
}, async ({ canvasId, doc, intoSection, notes }) => withErrorHandling(() => api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURIComponent(workspaceId)}`, {
|
|
640
651
|
action: "placeLayout",
|
|
641
652
|
doc,
|
|
642
653
|
...(intoSection ? { intoSection } : {}),
|
|
654
|
+
...(notes ? { notes } : {}),
|
|
643
655
|
})));
|
|
644
656
|
server.tool("cnotes_canvas_arrange", "Reflow EXISTING canvas nodes with the layout solver (no x/y math). Unlike cnotes_canvas_place (create-only), this MOVES nodes already on the canvas — mixed kinds welcome (note, canvas-link, richtext, list, legacy text). Prefer this over cnotes_canvas_bulk_move whenever you are reorganizing existing content into a grid/stack/section.\n\nLeaves in `doc` must be `{ kind:'item', type:'existing', nodeId:'<id or NOTE-n>', nodeType:'note'|'text'|'richtext'|'list'|'canvas' }`. Wrap them in a section container and pass `targetSectionId` (SECTION-<n>) to pack into that frame and auto-resize it in place — the SECTION-<n> id stays stable (never delete+re-add).\n\nConvenience shape for a section reflow:\n {\n targetSectionId: 'SECTION-90',\n autoResize: true,\n doc: {\n root: {\n kind: 'section', name: '<current name>', key: 'frame',\n child: {\n kind: 'grid', columns: 4, gap: 'medium',\n items: [\n { kind:'item', type:'existing', nodeId:'…', nodeType:'canvas' },\n { kind:'item', type:'existing', nodeId:'NOTE-3', nodeType:'note' }\n ]\n }\n }\n }\n }\n\nWhen targetSectionId is set and origin/placement are omitted, the server pins the layout to the frame's current origin (placement exact).", {
|
|
645
657
|
canvasId: z.string().describe("Canvas ID"),
|
package/package.json
CHANGED
package/skills/cnotes/SKILL.md
CHANGED
|
@@ -17,13 +17,31 @@ metadata:
|
|
|
17
17
|
4. **Write to the type's rubric.** Pick the type, run `cnotes types show <Type>`, and author to its rubric. Audience-facing prose (note bodies, banners, pre-reads) goes through [references/humanizer.md](references/humanizer.md) first; transcripts, quotes and other raw capture are stored verbatim.
|
|
18
18
|
5. **Create notes in one batch.** `cnotes notes create --notes '[{"key":"A","type":"Insight","markdownFile":"./a.md"}, ...]'`. Each body starts with a `# h1` (the title). Cross-link inside the batch with `[@A: Title](relationship:<verb>)`. Detail: [references/notes.md](references/notes.md).
|
|
19
19
|
6. **Grade what you wrote.** `cnotes quality <displayIds...> --fail-below 4`, then revise weak notes with `cnotes versions create <id> --description "<what changed>" --markdown-file <path>`.
|
|
20
|
-
7. **Lay out the canvas.** `cnotes canvas place <canvasId> --spec layout.json` packs items without overlap. Read [references/canvas-elements.md](references/canvas-elements.md) before choosing elements and [references/canvas-layout.md](references/canvas-layout.md) before writing the spec.
|
|
20
|
+
7. **Lay out the canvas.** `cnotes canvas place <canvasId> --spec layout.json` packs items without overlap. A spec can carry the notes too (see the fast path below), which folds steps 5 and 7 into one call. Read [references/canvas-elements.md](references/canvas-elements.md) before choosing elements and [references/canvas-layout.md](references/canvas-layout.md) before writing the spec.
|
|
21
21
|
8. **Read it back.** `cnotes canvas read <canvasId>`: every claim must appear in a note with a display ID, and the banner must make sense to someone who was not in the session.
|
|
22
22
|
9. **Close the run.** `cnotes operations end`.
|
|
23
23
|
10. **Link the result.** End your reply with the canvas link (see [Surfacing the canvas link](#surfacing-the-canvas-link)).
|
|
24
24
|
|
|
25
25
|
Reads, and a single metadata change (`notes update`), need no run.
|
|
26
26
|
|
|
27
|
+
## Fast path: a routine canvas change
|
|
28
|
+
|
|
29
|
+
Adding cards, filling or tidying a section, or linking two cards takes three steps. Each extra call costs the user a model round trip, so batch and run independent calls together.
|
|
30
|
+
|
|
31
|
+
1. **Read and open the run at once** (two calls, in parallel): `cnotes canvas read <canvasId>` (or `cnotes canvas read-section SECTION-n` when the request names one), and `cnotes operations begin --prompt "<headline>" --json`. The begin response already carries `typeRubrics` and a brief, so skip `brief` and `types show`.
|
|
32
|
+
2. **Create and place in one call.** Put the new notes in the spec's `notes` array (the `notes create` shape) and place each with `{"kind":"item","type":"note","noteId":"@<key>"}`; edges and anchors say `@<key>` too. Add `--into SECTION-n` to append to an existing frame. Each result comes back under `notes`, graded when the workspace grades: revise only notes below 4.
|
|
33
|
+
```json
|
|
34
|
+
{"notes":[{"key":"A","type":"Insight","markdown":"# Reviews wait on one person\n..."},
|
|
35
|
+
{"key":"B","type":"Decision","markdown":"# Add a second reviewer\nRests on [@A: Reviews wait on one person](relationship:depends-on)."}],
|
|
36
|
+
"root":{"kind":"stack","axis":"horizontal","items":[
|
|
37
|
+
{"kind":"item","type":"note","noteId":"@A"},{"kind":"item","type":"note","noteId":"@B"}]},
|
|
38
|
+
"edges":[{"from":"@B","to":"@A","label":"depends on"}]}
|
|
39
|
+
```
|
|
40
|
+
`cnotes canvas place <canvasId> --spec spec.json && cnotes operations end`
|
|
41
|
+
3. **Link the canvas** from the `Link:` line.
|
|
42
|
+
|
|
43
|
+
Rearranging existing cards needs no new notes: `cnotes canvas agent-run wrap --canvas <canvasId> --prompt "<headline>" -- cnotes canvas arrange <canvasId> --section SECTION-n`. Open [references/canvas-layout.md](references/canvas-layout.md) only when the layout needs anchors, origins or several sections; the rules above and step 7 below cover the rest.
|
|
44
|
+
|
|
27
45
|
## Rules that hold on every task
|
|
28
46
|
|
|
29
47
|
1. **The exit code is the verdict.** `0` is success. Never decide success from the body, and never re-run a write because a key looked empty: a second `notes create` duplicates the batch.
|
|
@@ -66,6 +66,8 @@ The schema is strict: an unknown or typo'd key anywhere in the doc (e.g. `gapp`,
|
|
|
66
66
|
|
|
67
67
|
`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.
|
|
68
68
|
|
|
69
|
+
**New notes in the same call.** A spec can carry a top-level `notes` array in the `notes create` shape (`{key, type, markdown|markdownFile, tags?, changeDescription?}`). A note leaf places one with `"noteId": "@<key>"` and takes `<key>` as its own key, so edges and anchors say `@<key>`; bodies cross-link with `[@<key>: Title](relationship:<verb>)`. The notes are checked before anything is written, created only if the layout solves, need an open run, and come back under `notes` in the `notes create` response shape. A dry run creates nothing. If placing then fails, the notes still exist: fix forward, never re-run the spec.
|
|
70
|
+
|
|
69
71
|
Leaf enums (exact values): richtext `size` = `small` | `medium` | `large`, `colorHex` = a saturated hex (omit for no background); list `viewMode` = `list` | `grid`, list `size` = `sm` | `md` | `lg` | `xl`.
|
|
70
72
|
|
|
71
73
|
A richtext `size` is not a hint — it IS the width the card paints: `small` 560px, `medium` 1120px, `large` 1680px, with the height following the content. `place` measures that box for you, which is the whole reason to prefer it over hand-picked coordinates: pitch a row of columns for `small` and then send `medium` items and every card runs 460px into its neighbour.
|