@creator-notes/cnotes 0.125.6 → 0.126.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/README.md +1 -1
- package/dist/commands/brief.js +6 -3
- package/dist/commands/canvas.js +29 -15
- package/dist/commands/notes.js +3 -9
- package/dist/commands/operations.js +14 -3
- package/dist/lib/board-checks.js +149 -0
- package/dist/lib/mcp-spec.js +636 -0
- package/dist/lib/section-update.js +9 -46
- package/dist/lib/session-brief.js +12 -0
- package/dist/mcp-server.js +96 -320
- package/package.json +1 -1
- package/skills/cnotes/SKILL.md +7 -5
- package/skills/cnotes/references/canvas-elements.md +1 -1
- package/skills/cnotes/references/canvas-layout.md +24 -0
- package/skills/cnotes/references/canvas.md +8 -1
- package/skills/cnotes/references/notes.md +11 -0
- package/skills/cnotes/references/operations.md +14 -0
- package/skills/cnotes/references/output.md +1 -0
- package/skills/cnotes/references/situations.md +108 -0
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ cnotes search semantic "onboarding flow"
|
|
|
53
53
|
| `cnotes query` | `cnotes q` | Filter, group or run a SELECT over every note's metadata from a local SQLite copy of the workspace, synced on each call |
|
|
54
54
|
| `cnotes timeline` | `cnotes tl` | Recent activity feed |
|
|
55
55
|
| `cnotes relationships list` | `cnotes rel` | Note relationships |
|
|
56
|
-
| `cnotes brief` | | What the workspace already knows about a task: the most relevant notes, canvases and recent changes, with what earlier runs made of each note |
|
|
56
|
+
| `cnotes brief` | | What the workspace already knows about a task: the most relevant notes, canvases and recent changes, with what earlier runs made of each note; ends on one line that says to name the kind of request before writing |
|
|
57
57
|
| `cnotes lessons record\|list` | | Say whether the notes you read were useful, a dead end or corrected (also `operations end --useful`); the next run's brief starts from them |
|
|
58
58
|
| `cnotes types list\|create\|update` | `cnotes t` | Manage note types (supertags) |
|
|
59
59
|
| `cnotes workspace list\|select\|current` | | Workspace management |
|
package/dist/commands/brief.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ApiClient } from "../lib/api-client.js";
|
|
|
2
2
|
import { resolveConfig } from "../lib/config.js";
|
|
3
3
|
import { handleError, ValidationError } from "../lib/errors.js";
|
|
4
4
|
import { outputJson } from "../lib/output.js";
|
|
5
|
-
import { briefIsEmpty, loadSessionBrief, renderBrief } from "../lib/session-brief.js";
|
|
5
|
+
import { BEFORE_WRITING, briefIsEmpty, loadSessionBrief, renderBrief } from "../lib/session-brief.js";
|
|
6
6
|
/**
|
|
7
7
|
* `cnotes brief "<task>"`: what the workspace already knows about a task,
|
|
8
8
|
* before you act on it. The same brief `operations begin --prompt` returns,
|
|
@@ -18,7 +18,8 @@ export function registerBriefCommand(program) {
|
|
|
18
18
|
.argument("<task...>", "The task, in plain words")
|
|
19
19
|
.addHelpText("after", `
|
|
20
20
|
Read-only and free of credits. \`operations begin --prompt\` includes the same
|
|
21
|
-
brief, so you only need this when you are not opening a run.
|
|
21
|
+
brief, so you only need this when you are not opening a run. The brief ends on
|
|
22
|
+
one line, beforeWriting in --json: name the kind of request before you write.
|
|
22
23
|
|
|
23
24
|
Examples:
|
|
24
25
|
$ cnotes brief "set the Amplitude API key in production"
|
|
@@ -34,15 +35,17 @@ Examples:
|
|
|
34
35
|
const brief = await loadSessionBrief(api, cfg.workspaceId, task);
|
|
35
36
|
const result = brief ?? { query: task, notes: [], canvases: [], changes: [] };
|
|
36
37
|
if (cfg.json) {
|
|
37
|
-
outputJson(result);
|
|
38
|
+
outputJson({ ...result, beforeWriting: BEFORE_WRITING });
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
41
|
if (briefIsEmpty(result)) {
|
|
41
42
|
console.log(`Nothing in this workspace matches "${task}" yet.`);
|
|
43
|
+
console.log(`\n${BEFORE_WRITING}`);
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
console.log(renderBrief(result));
|
|
45
47
|
console.log("\nOpen a note with `cnotes notes get <id>`, a canvas with `cnotes canvas read <id>`.");
|
|
48
|
+
console.log(BEFORE_WRITING);
|
|
46
49
|
}
|
|
47
50
|
catch (error) {
|
|
48
51
|
handleError(error, cfg.json);
|
package/dist/commands/canvas.js
CHANGED
|
@@ -15,9 +15,11 @@ import { resolveHostAgentSession } from "../lib/claude-session.js";
|
|
|
15
15
|
import { WARN, dim } from "../lib/style.js";
|
|
16
16
|
import { findOverlaps, findFrameSpills, layoutItemsFrom, parseSize, resolveAnchor, suggestFreeSpot, } from "../lib/canvas-layout.js";
|
|
17
17
|
import { canvasUrl, canvasLinkForRef } from "../lib/urls.js";
|
|
18
|
+
import { boardChecks, renderBoardChecks } from "../lib/board-checks.js";
|
|
18
19
|
import { CANVAS_GOAL_DESCRIPTION } from "../lib/canvas-goal.js";
|
|
19
20
|
import { canvasActionPath, commentsListPath, parseCommentStatus, } from "../lib/canvas-paths.js";
|
|
20
21
|
import { buildSectionUpdateRequest, CLI_SECTION_WORDING } from "../lib/section-update.js";
|
|
22
|
+
import { arrowToMarkers } from "../lib/mcp-spec.js";
|
|
21
23
|
import { registerCanvasMilestoneCommands } from "./canvas-milestone.js";
|
|
22
24
|
import { DISPLAY_ID_CORE } from "../lib/display-id.js";
|
|
23
25
|
import { resolveNoteBatchItems } from "../lib/note-batch.js";
|
|
@@ -359,19 +361,13 @@ function printRippleSummary(ripple, dryRun = false) {
|
|
|
359
361
|
console.error(`Warning: the grown frame now overlaps ${r.blocked.length} straddling item(s) that could not shift without breaking their own context: ${names}. Reflow them (arrange / bulk-move) and re-check with canvas get.`);
|
|
360
362
|
}
|
|
361
363
|
}
|
|
364
|
+
const ARROW_MODES = ["end", "start", "both", "none"];
|
|
365
|
+
/** `--arrow` as arrowStart/arrowEnd, the same mapping the MCP tools use (lib/mcp-spec.ts). */
|
|
362
366
|
function parseArrowMode(mode) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return { arrowStart: false, arrowEnd: true };
|
|
366
|
-
case "start":
|
|
367
|
-
return { arrowStart: true, arrowEnd: false };
|
|
368
|
-
case "both":
|
|
369
|
-
return { arrowStart: true, arrowEnd: true };
|
|
370
|
-
case "none":
|
|
371
|
-
return { arrowStart: false, arrowEnd: false };
|
|
372
|
-
default:
|
|
373
|
-
throw new ValidationError(`Invalid --arrow value "${mode}". Expected one of: end, start, both, none.`);
|
|
367
|
+
if (!ARROW_MODES.includes(mode)) {
|
|
368
|
+
throw new ValidationError(`Invalid --arrow value "${mode}". Expected one of: end, start, both, none.`);
|
|
374
369
|
}
|
|
370
|
+
return arrowToMarkers(mode);
|
|
375
371
|
}
|
|
376
372
|
function parseLineStyle(style) {
|
|
377
373
|
if (style === "solid" || style === "dashed")
|
|
@@ -612,14 +608,23 @@ Examples:
|
|
|
612
608
|
canvas
|
|
613
609
|
.command("status")
|
|
614
610
|
.description("See a canvas's whole layout before you move anything: every item (cards, text, lists, portals, " +
|
|
615
|
-
"sections) as one list of rectangles, the items that overlap, and with --near a free spot next to an anchor."
|
|
611
|
+
"sections) as one list of rectangles, the items that overlap, and with --near a free spot next to an anchor. " +
|
|
612
|
+
"Also checks the board as an agent reads it: the size of the read, and links that have gone stale.")
|
|
616
613
|
.argument("<canvasId>", "Canvas ID")
|
|
617
614
|
.option("--near <ref>", "Suggest a free spot next to this item (display id or node id) or point (x,y)")
|
|
618
615
|
.option("--size <WxH>", "Box to find room for with --near (default: a note card, 340x130)", "340x130")
|
|
616
|
+
.option("--no-checks", "Skip the read and link checks (they cost one more read of the canvas)")
|
|
619
617
|
.addHelpText("after", `
|
|
620
618
|
Sections are containers: they are listed, but a card inside one is not an
|
|
621
619
|
overlap. Read-only.
|
|
622
620
|
|
|
621
|
+
The read check says how many characters \`cnotes canvas read\` returns for this
|
|
622
|
+
board and whether that fits one tool result (100,000 characters). The link
|
|
623
|
+
check lists mentions that show a title their note no longer has, quote cards
|
|
624
|
+
pinned to a version their note has moved past, arrows between two notes that no
|
|
625
|
+
note body records, and mentions with no relationship type. Each comes with its
|
|
626
|
+
fix. --json carries them as read and links.
|
|
627
|
+
|
|
623
628
|
Examples:
|
|
624
629
|
$ cnotes canvas status CANVAS-361
|
|
625
630
|
$ cnotes canvas status CANVAS-361 --near DECISION-6KJ # where can this card go?
|
|
@@ -632,9 +637,15 @@ Examples:
|
|
|
632
637
|
const size = parseSize(opts.size);
|
|
633
638
|
if (!size)
|
|
634
639
|
throw new ValidationError(`--size must look like 340x130 (got "${opts.size}")`);
|
|
635
|
-
const data = await
|
|
636
|
-
|
|
637
|
-
|
|
640
|
+
const [data, read] = await Promise.all([
|
|
641
|
+
api.get(`/api/canvas/${encodeURIComponent(canvasId)}`, {
|
|
642
|
+
workspaceId: cfg.workspaceId,
|
|
643
|
+
}),
|
|
644
|
+
opts.checks === false
|
|
645
|
+
? Promise.resolve(null)
|
|
646
|
+
: api.get("/api/canvas/read", { canvas: canvasId, workspaceId: cfg.workspaceId }),
|
|
647
|
+
]);
|
|
648
|
+
const checks = read ? boardChecks(read.result) : null;
|
|
638
649
|
const items = layoutItemsFrom(data);
|
|
639
650
|
const overlaps = findOverlaps(items);
|
|
640
651
|
const spills = findFrameSpills(items);
|
|
@@ -653,6 +664,7 @@ Examples:
|
|
|
653
664
|
items,
|
|
654
665
|
overlaps: overlaps.map((o) => ({ a: o.a.ref, b: o.b.ref, area: o.area })),
|
|
655
666
|
spills: spills.map((s) => ({ item: s.item.ref, section: s.section.ref, overhang: s.overhang })),
|
|
667
|
+
...(checks ?? {}),
|
|
656
668
|
...(opts.near ? { freeSpot } : {}),
|
|
657
669
|
});
|
|
658
670
|
return;
|
|
@@ -685,6 +697,8 @@ Examples:
|
|
|
685
697
|
}
|
|
686
698
|
console.log(" Fix with `canvas arrange <canvas> --section <SECTION-n>`: it lays the section out and sizes the frame to fit.");
|
|
687
699
|
}
|
|
700
|
+
if (checks)
|
|
701
|
+
console.log(`\n${renderBoardChecks(checks, WARN)}`);
|
|
688
702
|
if (opts.near) {
|
|
689
703
|
if (freeSpot) {
|
|
690
704
|
console.log(`\nFree ${size.width}x${size.height} spot near ${opts.near}: x=${freeSpot.x} y=${freeSpot.y}`);
|
package/dist/commands/notes.js
CHANGED
|
@@ -14,6 +14,7 @@ import { describeUnresolvedMentions, lintNarratedVerbMentions, lintPlainTextDisp
|
|
|
14
14
|
import { attachRubricsToResults, loadRubricMap, rubricsForTypes, } from "../lib/rubrics.js";
|
|
15
15
|
import { DECISION_CARD_RULE, } from "../lib/decision-citation.js";
|
|
16
16
|
import { registerNotesImport } from "./notes-import.js";
|
|
17
|
+
import { orderByDisplayId } from "../lib/mcp-spec.js";
|
|
17
18
|
export function registerNotesCommands(program) {
|
|
18
19
|
const notes = program
|
|
19
20
|
.command("notes")
|
|
@@ -182,13 +183,8 @@ paragraph after headings and chip-only lines. JSON is an object
|
|
|
182
183
|
exact_ids: ids.join(","),
|
|
183
184
|
format: "markdown",
|
|
184
185
|
});
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
for (const n of found) {
|
|
188
|
-
if (typeof n.displayId === "string")
|
|
189
|
-
byDisplayId.set(n.displayId, n);
|
|
190
|
-
}
|
|
191
|
-
const missing = ids.filter((id) => !byDisplayId.has(id));
|
|
186
|
+
// In input order, so callers can index by position.
|
|
187
|
+
const { ordered, missing } = orderByDisplayId(ids, notesList);
|
|
192
188
|
if (missing.length > 0) {
|
|
193
189
|
// A note written in one of your drafts has its id from the start but
|
|
194
190
|
// lives in the draft until it lands: say which proposal holds it.
|
|
@@ -207,8 +203,6 @@ paragraph after headings and chip-only lines. JSON is an object
|
|
|
207
203
|
}
|
|
208
204
|
throw new NotFoundError(`Notes not found: ${missing.join(", ")}`, "Run `cnotes notes list` to see valid display IDs in this workspace.");
|
|
209
205
|
}
|
|
210
|
-
// Preserve input order so callers can index by position.
|
|
211
|
-
const ordered = ids.map((id) => byDisplayId.get(id));
|
|
212
206
|
if (opts.contentOnly) {
|
|
213
207
|
// Raw markdown only — no JSON envelope, no chrome. When several notes
|
|
214
208
|
// are requested, delimit each with an HTML comment (valid markdown,
|
|
@@ -8,7 +8,7 @@ import { parseDateInput } from "./timeline.js";
|
|
|
8
8
|
import { loadConfig, setActiveAgentRunId, registerAgentRun, unregisterAgentRun, isOwnedAgentRun, } from "../lib/auth-store.js";
|
|
9
9
|
import { resolveHostAgentSession } from "../lib/claude-session.js";
|
|
10
10
|
import { allWorkspaceRubrics, loadRubricMap } from "../lib/rubrics.js";
|
|
11
|
-
import { briefIsEmpty, loadSessionBrief, renderBrief } from "../lib/session-brief.js";
|
|
11
|
+
import { BEFORE_STOPPING, BEFORE_WRITING, briefIsEmpty, loadSessionBrief, renderBrief } from "../lib/session-brief.js";
|
|
12
12
|
import { hasLessonFlags, lessonsFromFlags, postLessons, renderRecorded } from "../lib/lessons.js";
|
|
13
13
|
import { renderProposalsForCaller } from "../lib/waiting-proposals.js";
|
|
14
14
|
/**
|
|
@@ -82,7 +82,8 @@ about the task: the most relevant notes (decisions, guides, metrics, findings),
|
|
|
82
82
|
canvases matched by meaning through their digests, and recent changes on the
|
|
83
83
|
topic from the change log. Read it BEFORE suggesting or doing anything; a note
|
|
84
84
|
may already settle the question. --json carries it as brief.{notes,canvases,
|
|
85
|
-
changes}
|
|
85
|
+
changes}, and beforeWriting, the one line that says to name the kind of request
|
|
86
|
+
before you write. \`cnotes brief "<task>"\` gives the same brief without opening a run.
|
|
86
87
|
|
|
87
88
|
If a previous run was never ended, begin asks the server about it first:
|
|
88
89
|
a run that is no longer running there (the bot crashed, the reaper marked
|
|
@@ -175,6 +176,7 @@ start fresh, or --detached to open your own run alongside it.
|
|
|
175
176
|
detached: Boolean(opts.detached),
|
|
176
177
|
typeRubrics,
|
|
177
178
|
...(brief ? { brief } : {}),
|
|
179
|
+
...(opts.brief === false ? {} : { beforeWriting: BEFORE_WRITING }),
|
|
178
180
|
});
|
|
179
181
|
return;
|
|
180
182
|
}
|
|
@@ -207,6 +209,10 @@ start fresh, or --detached to open your own run alongside it.
|
|
|
207
209
|
console.log("Open a note with `cnotes notes get <id>`, a canvas with `cnotes canvas read <id>`.");
|
|
208
210
|
console.log("");
|
|
209
211
|
}
|
|
212
|
+
if (opts.brief !== false) {
|
|
213
|
+
console.log(BEFORE_WRITING);
|
|
214
|
+
console.log("");
|
|
215
|
+
}
|
|
210
216
|
if (opts.detached) {
|
|
211
217
|
console.log(`Run \`cnotes operations end --agent-run-id ${result.agentRunId}\` when done.`);
|
|
212
218
|
}
|
|
@@ -319,7 +325,11 @@ code 5. Pass --force to end such a run anyway.
|
|
|
319
325
|
return;
|
|
320
326
|
}
|
|
321
327
|
if (cfg.json) {
|
|
322
|
-
outputJson({
|
|
328
|
+
outputJson({
|
|
329
|
+
...result,
|
|
330
|
+
...(lessons ? { lessons } : {}),
|
|
331
|
+
...(result.idempotent ? {} : { beforeStopping: BEFORE_STOPPING }),
|
|
332
|
+
});
|
|
323
333
|
return;
|
|
324
334
|
}
|
|
325
335
|
if (result.idempotent) {
|
|
@@ -338,6 +348,7 @@ code 5. Pass --force to end such a run anyway.
|
|
|
338
348
|
}
|
|
339
349
|
if (lessons)
|
|
340
350
|
console.log(renderRecorded(lessons));
|
|
351
|
+
console.log(`\n${BEFORE_STOPPING}`);
|
|
341
352
|
}
|
|
342
353
|
catch (error) {
|
|
343
354
|
handleError(error, cfg.json);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two checks on a board as an agent reads it, computed from the structure
|
|
3
|
+
* `cnotes canvas read --json` prints. `cnotes canvas status` reports them.
|
|
4
|
+
*
|
|
5
|
+
* Read: how much an agent pays to read the board. A read over ONE_RESULT_CHARS
|
|
6
|
+
* does not fit one tool result, so the agent pages a file to get at it; on the
|
|
7
|
+
* board this was first measured on, five source reports placed whole made the
|
|
8
|
+
* read 210,757 characters and three fifths of it backing material.
|
|
9
|
+
*
|
|
10
|
+
* Links: whether a correction could travel. A mention that still shows a
|
|
11
|
+
* retitled note's old title, a quote card pinned to a version its note has
|
|
12
|
+
* moved past, a mention with no relationship type, and an arrow between two
|
|
13
|
+
* notes that no note body records are each a place where the board and the
|
|
14
|
+
* notes behind it have drifted apart.
|
|
15
|
+
*
|
|
16
|
+
* Only what this board holds can be checked: a mention of a note that is not on
|
|
17
|
+
* the board is skipped, since its current title is not in the read.
|
|
18
|
+
*/
|
|
19
|
+
/** What one tool result holds, in characters (about 25,000 tokens). */
|
|
20
|
+
export const ONE_RESULT_CHARS = 100_000;
|
|
21
|
+
const str = (v) => (typeof v === "string" ? v : "");
|
|
22
|
+
/** A text card has no id a person would know, so it is named by its first words. */
|
|
23
|
+
function labelOf(el) {
|
|
24
|
+
if (el.displayId)
|
|
25
|
+
return el.displayId;
|
|
26
|
+
const words = str(el.markdown).replace(/^#+\s*/, "").replace(/\s+/g, " ").trim();
|
|
27
|
+
return `text card "${words.length > 32 ? `${words.slice(0, 32)}…` : words}"`;
|
|
28
|
+
}
|
|
29
|
+
/** `[TARGET: shown](relationship:verb)`, with an optional `@v3` pin on the target. */
|
|
30
|
+
const TITLED_MENTION = /\[([^\]\[:]+?)(@v\d+)?: ([^\]]+)\]\(relationship:[a-z0-9-]+\)/g;
|
|
31
|
+
/** `[[TARGET]]`: a mention with no relationship type. `[[verb::TARGET]]` carries `::` and is typed. */
|
|
32
|
+
const BARE_MENTION = /\[\[([^\]\[|:]+)\]\]/g;
|
|
33
|
+
export function boardChecks(result) {
|
|
34
|
+
const root = (result ?? {});
|
|
35
|
+
const elements = (Array.isArray(root.elements) ? root.elements : []);
|
|
36
|
+
const edges = (Array.isArray(root.edges) ? root.edges : []);
|
|
37
|
+
const chars = JSON.stringify(result ?? {}, null, 2).length;
|
|
38
|
+
const sized = elements.map((el) => ({ ref: labelOf(el), chars: JSON.stringify(el, null, 2).length, el }));
|
|
39
|
+
const quoteChars = sized.filter((s) => s.el.type === "Quote").reduce((sum, s) => sum + s.chars, 0);
|
|
40
|
+
const largest = [...sized]
|
|
41
|
+
.sort((a, b) => b.chars - a.chars)
|
|
42
|
+
.slice(0, 3)
|
|
43
|
+
.map((s) => ({ ref: s.ref, chars: s.chars, share: chars > 0 ? Math.round((s.chars / chars) * 100) / 100 : 0 }));
|
|
44
|
+
const notes = new Map();
|
|
45
|
+
for (const el of elements)
|
|
46
|
+
if (el.kind === "note" && el.displayId)
|
|
47
|
+
notes.set(el.displayId, el);
|
|
48
|
+
const staleTitles = [];
|
|
49
|
+
const untypedMentions = [];
|
|
50
|
+
const stalePins = [];
|
|
51
|
+
for (const el of elements) {
|
|
52
|
+
const md = str(el.markdown);
|
|
53
|
+
if (!md)
|
|
54
|
+
continue;
|
|
55
|
+
const here = labelOf(el);
|
|
56
|
+
if (el.type === "Quote") {
|
|
57
|
+
// A quote card names the version it was cut from; that title is history, not a stale stamp.
|
|
58
|
+
const pin = /\[([^\]\[:]+?)@v(\d+): /.exec(md);
|
|
59
|
+
const source = pin ? notes.get(pin[1]) : undefined;
|
|
60
|
+
if (pin && source && typeof source.version === "number" && source.version > Number(pin[2])) {
|
|
61
|
+
const words = /^>\s?(.+)$/m.exec(md)?.[1]?.trim() ?? "";
|
|
62
|
+
stalePins.push({
|
|
63
|
+
quote: here,
|
|
64
|
+
source: pin[1],
|
|
65
|
+
pinned: Number(pin[2]),
|
|
66
|
+
current: source.version,
|
|
67
|
+
wordsKept: words.length > 0 && str(source.markdown).includes(words),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
for (const m of md.matchAll(TITLED_MENTION)) {
|
|
73
|
+
const [, target, pinned, shown] = m;
|
|
74
|
+
const current = notes.get(target)?.title;
|
|
75
|
+
if (pinned || !current || shown === current)
|
|
76
|
+
continue;
|
|
77
|
+
staleTitles.push({ in: here, target, shown, current });
|
|
78
|
+
}
|
|
79
|
+
for (const m of md.matchAll(BARE_MENTION)) {
|
|
80
|
+
if (notes.has(m[1]))
|
|
81
|
+
untypedMentions.push({ in: here, target: m[1] });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// An arrow is local to this canvas. Between two notes it must also be a
|
|
85
|
+
// mention in one of the bodies, or the relationship exists nowhere else.
|
|
86
|
+
// Arrows to text cards and quote cards are the board's own and mirror nothing.
|
|
87
|
+
const unmirroredArrows = [];
|
|
88
|
+
for (const edge of edges) {
|
|
89
|
+
const from = notes.get(str(edge.from));
|
|
90
|
+
const to = notes.get(str(edge.to));
|
|
91
|
+
if (!from || !to || from.type === "Quote" || to.type === "Quote")
|
|
92
|
+
continue;
|
|
93
|
+
const a = str(from.displayId);
|
|
94
|
+
const b = str(to.displayId);
|
|
95
|
+
if (str(from.markdown).includes(b) || str(to.markdown).includes(a))
|
|
96
|
+
continue;
|
|
97
|
+
unmirroredArrows.push({ from: a, to: b, label: typeof edge.label === "string" ? edge.label : null });
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
read: { chars, approxTokens: Math.round(chars / 4), fitsOneResult: chars <= ONE_RESULT_CHARS, quoteChars, largest },
|
|
101
|
+
links: { staleTitles, stalePins, untypedMentions, unmirroredArrows },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
105
|
+
/** The text `cnotes canvas status` prints under the layout; each finding carries its fix. */
|
|
106
|
+
export function renderBoardChecks(checks, warn = "!") {
|
|
107
|
+
const lines = [];
|
|
108
|
+
const { read, links } = checks;
|
|
109
|
+
const size = `${read.chars.toLocaleString("en-US")} characters (about ${read.approxTokens.toLocaleString("en-US")} tokens)`;
|
|
110
|
+
if (read.fitsOneResult) {
|
|
111
|
+
lines.push(`Read: ${size}, which fits one tool result.`);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
lines.push(`${warn} Read: ${size}, over the ${ONE_RESULT_CHARS.toLocaleString("en-US")} one tool result holds.`);
|
|
115
|
+
lines.push(` Largest: ${read.largest.map((l) => `${l.ref} ${Math.round(l.share * 100)}%`).join(", ")}.`);
|
|
116
|
+
lines.push(" Sources a reader opens on demand belong in a list card (`canvas add-list`), which reads back as titles only.");
|
|
117
|
+
}
|
|
118
|
+
const found = links.staleTitles.length + links.stalePins.length + links.untypedMentions.length + links.unmirroredArrows.length;
|
|
119
|
+
if (found === 0) {
|
|
120
|
+
lines.push("Links: no stale titles, stale quote cards, untyped mentions or unmirrored arrows.");
|
|
121
|
+
return lines.join("\n");
|
|
122
|
+
}
|
|
123
|
+
if (links.staleTitles.length > 0) {
|
|
124
|
+
lines.push(`${warn} ${count(links.staleTitles.length, "mention shows", "mentions show")} a title its note no longer has:`);
|
|
125
|
+
for (const s of links.staleTitles)
|
|
126
|
+
lines.push(` ${s.in} shows "${s.shown}" for ${s.target}, now "${s.current}"`);
|
|
127
|
+
lines.push(" Save the mentioning note again (`versions create` with its current body), or `canvas update-text` for a text card.");
|
|
128
|
+
}
|
|
129
|
+
if (links.stalePins.length > 0) {
|
|
130
|
+
lines.push(`${warn} ${count(links.stalePins.length, "quote card is", "quote cards are")} pinned to a version its note has moved past:`);
|
|
131
|
+
for (const p of links.stalePins) {
|
|
132
|
+
lines.push(` ${p.quote} quotes v${p.pinned} of ${p.source}, now v${p.current} (${p.wordsKept ? "the words are still there" : "the words are gone"})`);
|
|
133
|
+
}
|
|
134
|
+
lines.push(" Remove the card and `canvas add-quote` the sentence again.");
|
|
135
|
+
}
|
|
136
|
+
if (links.unmirroredArrows.length > 0) {
|
|
137
|
+
lines.push(`${warn} ${count(links.unmirroredArrows.length, "arrow exists", "arrows exist")} on this canvas only:`);
|
|
138
|
+
for (const a of links.unmirroredArrows)
|
|
139
|
+
lines.push(` ${a.from} -> ${a.to}${a.label ? ` "${a.label}"` : ""}`);
|
|
140
|
+
lines.push(" Write the same relationship as a mention in one of the two note bodies.");
|
|
141
|
+
}
|
|
142
|
+
if (links.untypedMentions.length > 0) {
|
|
143
|
+
lines.push(`${warn} ${count(links.untypedMentions.length, "mention has", "mentions have")} no relationship type:`);
|
|
144
|
+
for (const u of links.untypedMentions)
|
|
145
|
+
lines.push(` ${u.in} names ${u.target} as [[${u.target}]]`);
|
|
146
|
+
lines.push(" Say what the link is: [[depends-on::NOTE-12]].");
|
|
147
|
+
}
|
|
148
|
+
return lines.join("\n");
|
|
149
|
+
}
|