@creator-notes/cnotes 0.108.0 → 0.110.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/intent-run.js +64 -0
- package/dist/lib/intent-runner.js +115 -0
- package/dist/lib/note-batch.js +106 -0
- package/dist/mcp-server.js +14 -2
- package/dist/program.js +5 -0
- package/package.json +1 -1
- package/skills/cnotes/SKILL.md +22 -2
- package/skills/cnotes/references/canvas-layout.md +2 -0
- package/skills/cnotes/references/operations.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,64 @@
|
|
|
1
|
+
/** "<group> <command>" → bracket. Group names, not aliases. */
|
|
2
|
+
export const INTENT_COMMANDS = {
|
|
3
|
+
"notes create": "workspace",
|
|
4
|
+
"versions create": "workspace",
|
|
5
|
+
"canvas create": "workspace",
|
|
6
|
+
"canvas update": "workspace",
|
|
7
|
+
"canvas place": "workspace",
|
|
8
|
+
"canvas arrange": "workspace",
|
|
9
|
+
"canvas add-node": "workspace",
|
|
10
|
+
"canvas add-text": "workspace",
|
|
11
|
+
"canvas add-section": "workspace",
|
|
12
|
+
"canvas add-list": "workspace",
|
|
13
|
+
"canvas add-link": "workspace",
|
|
14
|
+
"canvas add-quote": "workspace",
|
|
15
|
+
"canvas style-quote": "workspace",
|
|
16
|
+
"canvas bulk-add": "workspace",
|
|
17
|
+
"canvas bulk-move": "workspace",
|
|
18
|
+
"canvas move-node": "workspace",
|
|
19
|
+
"canvas add-edge": "workspace",
|
|
20
|
+
"canvas update-edge": "workspace",
|
|
21
|
+
"canvas update-section": "workspace",
|
|
22
|
+
"canvas update-text": "workspace",
|
|
23
|
+
"canvas bulk-remove": "canvas",
|
|
24
|
+
"canvas remove-node": "canvas",
|
|
25
|
+
"canvas remove-edge": "canvas",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Set on the re-run of the command inside the run intent-runner opened, so
|
|
29
|
+
* that process writes under the run instead of opening another.
|
|
30
|
+
*/
|
|
31
|
+
export const INTENT_CHILD_ENV = "CNOTES_INTENT_CHILD";
|
|
32
|
+
export const INTENT_OPTION_DESCRIPTION = "Timeline headline for this change: opens an agent run for this one command and closes it after, " +
|
|
33
|
+
"so no `operations begin`/`end` is needed. Verb-first, at most 110 characters " +
|
|
34
|
+
'("Added the pricing risks to the Q1 roadmap"). When a run is already open, the write joins it instead.';
|
|
35
|
+
const brackets = new WeakMap();
|
|
36
|
+
/** Add `--intent` to every command in INTENT_COMMANDS. Call after all commands are registered. */
|
|
37
|
+
export function applyIntentOptions(program) {
|
|
38
|
+
for (const group of program.commands) {
|
|
39
|
+
for (const cmd of group.commands) {
|
|
40
|
+
const bracket = INTENT_COMMANDS[`${group.name()} ${cmd.name()}`];
|
|
41
|
+
if (!bracket)
|
|
42
|
+
continue;
|
|
43
|
+
cmd.option("--intent <headline>", INTENT_OPTION_DESCRIPTION);
|
|
44
|
+
brackets.set(cmd, bracket);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function intentBracketFor(cmd) {
|
|
49
|
+
return brackets.get(cmd);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* What `--intent` should do for this invocation. A canvas bracket needs the
|
|
53
|
+
* canvas the command names; without one it falls back to a workspace run.
|
|
54
|
+
*/
|
|
55
|
+
export function decideIntentRun(input) {
|
|
56
|
+
if (!input.intent?.trim() || !input.bracket || input.isChild)
|
|
57
|
+
return { kind: "none" };
|
|
58
|
+
if (input.attachedRunId)
|
|
59
|
+
return { kind: "join", agentRunId: input.attachedRunId };
|
|
60
|
+
if (input.bracket === "canvas" && input.canvasRef) {
|
|
61
|
+
return { kind: "open", bracket: "canvas", canvasRef: input.canvasRef };
|
|
62
|
+
}
|
|
63
|
+
return { kind: "open", bracket: "workspace" };
|
|
64
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { ApiClient, resolveActiveAgentRun } from "./api-client.js";
|
|
3
|
+
import { resolveConfig } from "./config.js";
|
|
4
|
+
import { loadConfig, registerAgentRun, unregisterAgentRun } from "./auth-store.js";
|
|
5
|
+
import { resolveHostAgentSession } from "./claude-session.js";
|
|
6
|
+
import { readHeadlineWarnings, reportHeadlineWarnings } from "./headline-warnings.js";
|
|
7
|
+
import { canvasActionPath } from "./canvas-paths.js";
|
|
8
|
+
import { handleError } from "./errors.js";
|
|
9
|
+
import { decideIntentRun, intentBracketFor, INTENT_CHILD_ENV } from "./intent-run.js";
|
|
10
|
+
/**
|
|
11
|
+
* Root preAction hook: when the command carries `--intent`, open a run, re-run
|
|
12
|
+
* this same command line as a child with the run in its environment, close the
|
|
13
|
+
* run, and exit with the child's code. The command never runs in this process.
|
|
14
|
+
*
|
|
15
|
+
* A child process rather than a postAction hook because commands exit through
|
|
16
|
+
* handleError → process.exit, and a run must close even when its write fails
|
|
17
|
+
* (same reasoning as `canvas agent-run wrap`). An unclosed run is reaped as
|
|
18
|
+
* abandoned, which still keeps its writes attributed, but leaves no after
|
|
19
|
+
* snapshot.
|
|
20
|
+
*/
|
|
21
|
+
export async function runUnderIntent(program, actionCommand) {
|
|
22
|
+
const bracket = intentBracketFor(actionCommand);
|
|
23
|
+
const intent = actionCommand.opts().intent;
|
|
24
|
+
if (!bracket || !intent)
|
|
25
|
+
return;
|
|
26
|
+
const cfg = resolveConfig(program.opts());
|
|
27
|
+
const decision = decideIntentRun({
|
|
28
|
+
intent,
|
|
29
|
+
bracket,
|
|
30
|
+
canvasRef: actionCommand.processedArgs[0],
|
|
31
|
+
attachedRunId: resolveActiveAgentRun(cfg.serverUrl)?.agentRunId,
|
|
32
|
+
isChild: process.env[INTENT_CHILD_ENV] === "1",
|
|
33
|
+
});
|
|
34
|
+
if (decision.kind === "none")
|
|
35
|
+
return;
|
|
36
|
+
if (decision.kind === "join") {
|
|
37
|
+
console.error(`# joined the open run ${decision.agentRunId}; --intent is not its headline`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
41
|
+
const agentSession = await resolveHostAgentSession();
|
|
42
|
+
const canvasPath = decision.canvasRef ? canvasActionPath(decision.canvasRef, cfg.workspaceId) : null;
|
|
43
|
+
let agentRunId;
|
|
44
|
+
let beforeSnapshotId;
|
|
45
|
+
try {
|
|
46
|
+
if (canvasPath) {
|
|
47
|
+
const begin = await api.post(canvasPath, {
|
|
48
|
+
action: "agentRunBegin",
|
|
49
|
+
prompt: intent,
|
|
50
|
+
...(agentSession ? { agentSession } : {}),
|
|
51
|
+
});
|
|
52
|
+
agentRunId = begin.agentRunId;
|
|
53
|
+
beforeSnapshotId = begin.beforeCheckpointId;
|
|
54
|
+
reportHeadlineWarnings(readHeadlineWarnings(begin));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const begin = await api.post("/api/operations", {
|
|
58
|
+
action: "begin",
|
|
59
|
+
workspaceId: cfg.workspaceId,
|
|
60
|
+
prompt: intent,
|
|
61
|
+
...(agentSession ? { agentSession } : {}),
|
|
62
|
+
});
|
|
63
|
+
agentRunId = begin.agentRunId;
|
|
64
|
+
reportHeadlineWarnings(readHeadlineWarnings(begin));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
handleError(error, cfg.json);
|
|
69
|
+
}
|
|
70
|
+
// In the registry only, never the active pointer: the run is scoped to the
|
|
71
|
+
// child by its environment, and `operations end` recognises it as ours if the
|
|
72
|
+
// close below fails and the user follows the printed advice.
|
|
73
|
+
registerAgentRun(loadConfig(), cfg.serverUrl, agentRunId, {
|
|
74
|
+
startedAt: Date.now(),
|
|
75
|
+
detached: true,
|
|
76
|
+
...(beforeSnapshotId ? { beforeSnapshotId, canvasId: decision.canvasRef } : {}),
|
|
77
|
+
});
|
|
78
|
+
// Ctrl-C reaches the child through the shared terminal; this process stays
|
|
79
|
+
// alive to close the run once the child is gone.
|
|
80
|
+
const ignoreSigint = () => { };
|
|
81
|
+
process.on("SIGINT", ignoreSigint);
|
|
82
|
+
const child = spawn(process.execPath, [...process.execArgv, ...process.argv.slice(1)], {
|
|
83
|
+
stdio: "inherit",
|
|
84
|
+
env: {
|
|
85
|
+
...process.env,
|
|
86
|
+
[INTENT_CHILD_ENV]: "1",
|
|
87
|
+
CNOTES_AGENT_RUN_ID: agentRunId,
|
|
88
|
+
...(beforeSnapshotId ? { CNOTES_AGENT_BEFORE_SNAPSHOT_ID: beforeSnapshotId } : {}),
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const exitCode = await new Promise((resolve) => {
|
|
92
|
+
child.on("exit", (code, signal) => resolve(signal ? 128 : (code ?? 1)));
|
|
93
|
+
child.on("error", (err) => {
|
|
94
|
+
console.error(`# could not re-run the command under its run: ${err.message}`);
|
|
95
|
+
resolve(1);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
process.off("SIGINT", ignoreSigint);
|
|
99
|
+
try {
|
|
100
|
+
if (canvasPath) {
|
|
101
|
+
await api.post(canvasPath, { action: "agentRunEnd", agentRunId });
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await api.post("/api/operations", { action: "end", agentRunId });
|
|
105
|
+
}
|
|
106
|
+
unregisterAgentRun(loadConfig(), cfg.serverUrl, agentRunId);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error(`# WARNING: the run for --intent did not close: ${error instanceof Error ? error.message : error}`);
|
|
110
|
+
console.error(canvasPath
|
|
111
|
+
? `# close it with: cnotes canvas agent-run end --canvas ${decision.canvasRef} --run-id ${agentRunId}`
|
|
112
|
+
: `# close it with: cnotes operations end --agent-run-id ${agentRunId}`);
|
|
113
|
+
}
|
|
114
|
+
process.exit(exitCode);
|
|
115
|
+
}
|
|
@@ -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/dist/program.js
CHANGED
|
@@ -35,6 +35,8 @@ import { registerClaudeHookCommand } from "./commands/claude-hook.js";
|
|
|
35
35
|
import { loadConfig, getServerConfig } from "./lib/auth-store.js";
|
|
36
36
|
import { parseFields } from "./lib/config.js";
|
|
37
37
|
import { setOutputMode } from "./lib/output.js";
|
|
38
|
+
import { applyIntentOptions } from "./lib/intent-run.js";
|
|
39
|
+
import { runUnderIntent } from "./lib/intent-runner.js";
|
|
38
40
|
/**
|
|
39
41
|
* Appended to Commander's own error text. Agents read stderr, and both errors
|
|
40
42
|
* below used to cost them a wrong conclusion rather than a retry.
|
|
@@ -133,6 +135,9 @@ Env vars:
|
|
|
133
135
|
registerFeedbackCommands(program);
|
|
134
136
|
registerSkillsCommands(program);
|
|
135
137
|
registerClaudeHookCommand(program);
|
|
138
|
+
// `--intent` on a write command brackets it in its own agent run.
|
|
139
|
+
applyIntentOptions(program);
|
|
140
|
+
program.hook("preAction", (_root, actionCommand) => runUnderIntent(program, actionCommand));
|
|
136
141
|
// The root alone keeps excess arguments: an unknown top-level word arrives
|
|
137
142
|
// here as an operand, and the action below reports it as an unknown command
|
|
138
143
|
// (with the version hint) instead of Commander's "too many arguments".
|
package/package.json
CHANGED
package/skills/cnotes/SKILL.md
CHANGED
|
@@ -17,12 +17,32 @@ 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
|
-
Reads, and a single metadata change (`notes update`), need no run.
|
|
25
|
+
Reads, and a single metadata change (`notes update`), need no run. A task that is ONE write needs no `begin`/`end` either: pass `--intent "<headline>"` on that command (see the fast path).
|
|
26
|
+
|
|
27
|
+
## Fast path: a routine canvas change
|
|
28
|
+
|
|
29
|
+
Adding cards, filling or tidying a section, linking two cards or removing one takes two rounds. Each extra call costs the user a model round trip, so batch, and send independent calls together.
|
|
30
|
+
|
|
31
|
+
1. **Read, in parallel:** `cnotes canvas read <canvasId>` (or `cnotes canvas read-section SECTION-n` when the request names one), plus `cnotes types show <Type>` for each type you will write.
|
|
32
|
+
2. **Make the change in one call, with `--intent`.** `--intent "<headline>"` opens an agent run for that one command and closes it after, so the change lands on the timeline as one revertable run with no `operations begin`/`end`. A removal gets a before snapshot automatically, so it can be undone. When a run is already open, the write joins it. To add cards, create and place them together:
|
|
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
|
+
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.
|
|
41
|
+
`cnotes canvas place <canvasId> --spec spec.json --intent "Added the reviewer bottleneck to the Q1 roadmap"`
|
|
42
|
+
Other single changes take the same flag: `cnotes canvas arrange <canvasId> --section SECTION-7 --intent "Tidied the Risks section"`, `cnotes canvas bulk-remove <canvasId> --nodes '["NOTE-4"]' --intent "Removed the duplicate risk card"`.
|
|
43
|
+
3. **Link the canvas** from the `Link:` line, in the same reply.
|
|
44
|
+
|
|
45
|
+
Several writes that belong together (a new canvas and its first layout, notes on two canvases) still go in one `operations begin`/`end` run, so the timeline shows one change. 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.
|
|
26
46
|
|
|
27
47
|
## Rules that hold on every task
|
|
28
48
|
|
|
@@ -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.
|
|
@@ -26,6 +26,8 @@ When an AI agent is doing a **batch of work** — creating notes, modifying 2+ e
|
|
|
26
26
|
| Two or more writes that belong to one intent (multi-note batch, canvas build-out, multi-step refactor) | **Yes** |
|
|
27
27
|
| Canvas mutations done as part of an agent task | **Yes** — even one canvas command, if it's part of a larger batch |
|
|
28
28
|
|
|
29
|
+
**One write is its own run with `--intent`.** When the whole task is a single write command (`notes create`, `versions create`, `canvas create`, `place`, `arrange`, an `add-*`, `update-*`, `move-*` or `remove-*` canvas command), pass `--intent "<headline>"` on it instead of bracketing it: the CLI opens a run with that headline, runs the command under it, and closes the run even when the command fails. Removals (`bulk-remove`, `remove-node`, `remove-edge`) get a canvas run with a before snapshot, the same as `canvas agent-run wrap`, so they can be undone. When a run is already open, the write joins it and `--intent` is not used as a headline. `cnotes <command> --help` lists the flag on every command that takes it.
|
|
30
|
+
|
|
29
31
|
## The pattern
|
|
30
32
|
|
|
31
33
|
`cnotes operations begin` opens a run; **every subsequent cnotes write on this server attaches to it automatically**, across any shell, until you call `cnotes operations end`. No env var to export, no eval trick — the active run is persisted in `~/.cnotes/config.json` per server, so stateless callers (separate Bash invocations, disjoint tool calls) all attach correctly.
|