@creator-notes/cnotes 0.149.1 → 0.150.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 +41 -12
- package/dist/commands/init.js +15 -3
- package/dist/commands/skills.js +46 -2
- package/dist/lib/install-skill.js +25 -0
- package/package.json +1 -1
- package/skills/cnotes/references/canvas-layout.md +1 -1
- package/skills/cnotes/references/output.md +1 -1
package/dist/commands/canvas.js
CHANGED
|
@@ -218,24 +218,36 @@ function placedNothing(data) {
|
|
|
218
218
|
allItems.every((r) => !r.id || r.error) &&
|
|
219
219
|
allEdges.every((e) => !e.id || e.error));
|
|
220
220
|
}
|
|
221
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* The items and edges the server refused, each with its reason, and the
|
|
223
|
+
* sections that could not arrange themselves after the placement. A failed
|
|
224
|
+
* section names only its raw id: the route gives a display id on success.
|
|
225
|
+
*/
|
|
222
226
|
function refusedRows(data) {
|
|
223
227
|
const allItems = (data.items || []);
|
|
224
228
|
const allEdges = (data.edges || []);
|
|
229
|
+
const arranged = (data.arrangedSections || []);
|
|
225
230
|
const reason = (r) => String(r.error ?? "not placed");
|
|
226
231
|
return {
|
|
227
232
|
items: allItems.filter((r) => !r.id || r.error).map((r) => ({ index: r.index, type: r.type, error: reason(r) })),
|
|
228
233
|
edges: allEdges.filter((e) => !e.id || e.error).map((e) => ({ from: e.from, to: e.to, error: reason(e) })),
|
|
234
|
+
sections: arranged
|
|
235
|
+
.filter((a) => a.error)
|
|
236
|
+
.map((a) => ({ sectionId: String(a.displayId ?? a.sectionId), error: String(a.error) })),
|
|
229
237
|
total: allItems.length + allEdges.length,
|
|
230
238
|
};
|
|
231
239
|
}
|
|
232
|
-
/**
|
|
240
|
+
/**
|
|
241
|
+
* True when a (non-dry-run) placeLayout landed only in part: some, not all,
|
|
242
|
+
* of its items and edges were refused, or a section it framed or placed into
|
|
243
|
+
* could not arrange itself (a framed one will not re-lay itself as cards
|
|
244
|
+
* change; one placed INTO leaves the new cards outside it).
|
|
245
|
+
*/
|
|
233
246
|
function placedSome(data) {
|
|
234
|
-
if (data.dryRun)
|
|
247
|
+
if (data.dryRun || placedNothing(data))
|
|
235
248
|
return false;
|
|
236
249
|
const refused = refusedRows(data);
|
|
237
|
-
|
|
238
|
-
return failed > 0 && failed < refused.total;
|
|
250
|
+
return refused.items.length + refused.edges.length > 0 || refused.sections.length > 0;
|
|
239
251
|
}
|
|
240
252
|
const PARTIAL_PLACE_HINT = "The rest were placed and any new notes exist: do not re-run the spec, it would duplicate them. " +
|
|
241
253
|
'Fix each refused item on its own: a quote with `cnotes canvas add-quote <canvas> --note <id> --text "<words>" --title "<headline>"`, ' +
|
|
@@ -246,23 +258,40 @@ function partialPlaceSummary(data) {
|
|
|
246
258
|
const edges = (data.edges || []);
|
|
247
259
|
const parts = [];
|
|
248
260
|
if (refused.items.length > 0)
|
|
249
|
-
parts.push(`${refused.items.length} of ${items.length} items`);
|
|
261
|
+
parts.push(`${refused.items.length} of ${items.length} items were refused`);
|
|
250
262
|
if (refused.edges.length > 0)
|
|
251
|
-
parts.push(`${refused.edges.length} of ${edges.length} edges`);
|
|
252
|
-
|
|
263
|
+
parts.push(`${refused.edges.length} of ${edges.length} edges were refused`);
|
|
264
|
+
for (const section of refused.sections) {
|
|
265
|
+
parts.push(`section ${section.sectionId} could not arrange itself (${section.error})`);
|
|
266
|
+
}
|
|
267
|
+
return parts.join(", and ");
|
|
268
|
+
}
|
|
269
|
+
/** The fix for this shortfall: the refused items one by one, each unarranged section by arrange. */
|
|
270
|
+
function partialPlaceHint(data) {
|
|
271
|
+
const refused = refusedRows(data);
|
|
272
|
+
const parts = [];
|
|
273
|
+
if (refused.items.length + refused.edges.length > 0)
|
|
274
|
+
parts.push(PARTIAL_PLACE_HINT);
|
|
275
|
+
else
|
|
276
|
+
parts.push("Every card landed: do not re-run the spec, it would duplicate them.");
|
|
277
|
+
for (const section of refused.sections) {
|
|
278
|
+
parts.push(`Arrange ${section.sectionId} with \`cnotes canvas arrange <canvas> --section ${section.sectionId}\` once the cause is fixed.`);
|
|
279
|
+
}
|
|
280
|
+
return parts.join(" ");
|
|
253
281
|
}
|
|
254
282
|
function reportPartialPlaceJson(data) {
|
|
255
283
|
const refused = refusedRows(data);
|
|
256
284
|
console.error(JSON.stringify({
|
|
257
|
-
error: `placeLayout
|
|
285
|
+
error: `placeLayout landed only in part: ${partialPlaceSummary(data)}`,
|
|
258
286
|
code: "PlacePartial",
|
|
259
287
|
exitCode: EXIT_CODES.VALIDATION,
|
|
260
288
|
...(refused.items.length > 0 ? { failed: refused.items } : {}),
|
|
261
289
|
...(refused.edges.length > 0 ? { failedEdges: refused.edges } : {}),
|
|
262
|
-
|
|
290
|
+
...(refused.sections.length > 0 ? { failedSections: refused.sections } : {}),
|
|
291
|
+
hint: partialPlaceHint(data),
|
|
263
292
|
}));
|
|
264
293
|
}
|
|
265
|
-
/** Set the exit code a placeLayout result earns: 1 when nothing was placed, 3 when
|
|
294
|
+
/** Set the exit code a placeLayout result earns: 1 when nothing was placed, 3 when it landed only in part. */
|
|
266
295
|
function setPlaceExitCode(data) {
|
|
267
296
|
if (placedNothing(data))
|
|
268
297
|
process.exitCode = EXIT_CODES.GENERIC;
|
|
@@ -278,7 +307,7 @@ function reportPlaceShortfall(data, json) {
|
|
|
278
307
|
reportPartialPlaceJson(data);
|
|
279
308
|
}
|
|
280
309
|
else if (placedSome(data)) {
|
|
281
|
-
console.error(`Error: ${partialPlaceSummary(data)}
|
|
310
|
+
console.error(`Error: the layout landed only in part: ${partialPlaceSummary(data)} (see above). ${partialPlaceHint(data)}`);
|
|
282
311
|
}
|
|
283
312
|
}
|
|
284
313
|
function arrangeShortfall(data) {
|
package/dist/commands/init.js
CHANGED
|
@@ -9,7 +9,7 @@ import { canWrite, chooseWorkspace, firstWriteLines, workspaceId, workspaceName
|
|
|
9
9
|
import { buildClaudeConfig } from "./mcp.js";
|
|
10
10
|
import { bold, dim, green, cyan, CHECK, ARROW, WARN } from "../lib/style.js";
|
|
11
11
|
import { installMcpConfig, getConfigPath } from "../lib/install-mcp.js";
|
|
12
|
-
import { hasAgentConfigDir, installSkill, getSkillDestPath, skillTargetLabel, SKILL_TARGETS, } from "../lib/install-skill.js";
|
|
12
|
+
import { hasAgentConfigDir, installSkill, getSkillDestPath, noAgentFolderLines, skillTargetLabel, SKILL_TARGETS, } from "../lib/install-skill.js";
|
|
13
13
|
import { installClaudeSessionHook, isClaudeSessionHookInstalled, SESSION_HOOK_COMMAND, SESSION_HOOK_COMMAND_NPX, } from "../lib/install-hook.js";
|
|
14
14
|
function printBanner(version) {
|
|
15
15
|
const width = 41; // inner width of the box
|
|
@@ -407,9 +407,12 @@ async function runInitNonInteractive() {
|
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
// ── Install the agent skill(s) (best-effort, no prompt) ──
|
|
410
|
-
|
|
410
|
+
const skillTargets = SKILL_TARGETS.filter(hasAgentConfigDir);
|
|
411
|
+
for (const target of skillTargets) {
|
|
411
412
|
installSkillForTarget(target);
|
|
412
413
|
}
|
|
414
|
+
if (skillTargets.length === 0)
|
|
415
|
+
sayNoAgentFolder(cli);
|
|
413
416
|
// ── Conversation capture (Claude Code SessionStart hook) ──
|
|
414
417
|
// Best-effort + silent on failure: the env-var fallback still works, and a
|
|
415
418
|
// headless run must never fail setup over an optional capture hook.
|
|
@@ -441,8 +444,10 @@ async function runInitNonInteractive() {
|
|
|
441
444
|
async function maybeInstallSkill() {
|
|
442
445
|
// Install for whichever agents the user actually has (Claude Code, Codex, Cursor, Grok).
|
|
443
446
|
const targets = SKILL_TARGETS.filter(hasAgentConfigDir);
|
|
444
|
-
if (targets.length === 0)
|
|
447
|
+
if (targets.length === 0) {
|
|
448
|
+
sayNoAgentFolder(detectCnCommand());
|
|
445
449
|
return;
|
|
450
|
+
}
|
|
446
451
|
const labels = targets.map(skillTargetLabel).join(" and ");
|
|
447
452
|
console.log();
|
|
448
453
|
const { confirm } = await import("@inquirer/prompts");
|
|
@@ -456,6 +461,13 @@ async function maybeInstallSkill() {
|
|
|
456
461
|
installSkillForTarget(target);
|
|
457
462
|
}
|
|
458
463
|
}
|
|
464
|
+
/** No agent folder to install into: name the command that prints the instructions. */
|
|
465
|
+
function sayNoAgentFolder(cli) {
|
|
466
|
+
const [first, ...rest] = noAgentFolderLines(cli);
|
|
467
|
+
console.log(` ${WARN} ${first}`);
|
|
468
|
+
for (const line of rest)
|
|
469
|
+
console.log(` ${line.replace(`${cli} skills show`, cyan(`${cli} skills show`))}`);
|
|
470
|
+
}
|
|
459
471
|
/** Install (or refresh) the bundled skill for one agent, reporting the result. */
|
|
460
472
|
function installSkillForTarget(target) {
|
|
461
473
|
const label = skillTargetLabel(target);
|
package/dist/commands/skills.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
1
3
|
import { resolveBaseConfig } from "../lib/config.js";
|
|
2
|
-
import { EXIT_CODES, handleError, ValidationError } from "../lib/errors.js";
|
|
4
|
+
import { CliError, EXIT_CODES, handleError, ValidationError } from "../lib/errors.js";
|
|
3
5
|
import { outputJson } from "../lib/output.js";
|
|
4
|
-
import { SKILL_CATALOG, SKILL_TARGETS, resolveCatalogSkill, hasAgentConfigDir, installSkillFolder, installedSkillState, skillTargetLabel, } from "../lib/install-skill.js";
|
|
6
|
+
import { bundledSkillMdPath, SKILL_CATALOG, SKILL_TARGETS, resolveCatalogSkill, hasAgentConfigDir, installSkillFolder, installedSkillState, skillTargetLabel, } from "../lib/install-skill.js";
|
|
5
7
|
/**
|
|
6
8
|
* Decide which agents to install for. An explicit `--agent` wins; otherwise
|
|
7
9
|
* install for every agent the user already uses (its config dir exists), and
|
|
@@ -132,4 +134,46 @@ Examples:
|
|
|
132
134
|
handleError(error, cfg.json);
|
|
133
135
|
}
|
|
134
136
|
});
|
|
137
|
+
skills
|
|
138
|
+
.command("show [name]")
|
|
139
|
+
.description("Print a bundled skill's SKILL.md (default: cnotes, the core instructions), for an agent with no skills folder")
|
|
140
|
+
.addHelpText("after", `
|
|
141
|
+
Prints the file exactly, so it can also be saved where your agent reads its instructions.
|
|
142
|
+
Where its references/ files are goes to stderr.
|
|
143
|
+
|
|
144
|
+
Examples:
|
|
145
|
+
$ cnotes skills show
|
|
146
|
+
$ cnotes skills show wayfind
|
|
147
|
+
$ cnotes skills show > AGENTS.md`)
|
|
148
|
+
.action((name) => {
|
|
149
|
+
const cfg = resolveBaseConfig(program.opts());
|
|
150
|
+
try {
|
|
151
|
+
const found = bundledSkillMdPath(name ?? "cnotes");
|
|
152
|
+
if (!found) {
|
|
153
|
+
const known = SKILL_CATALOG.map((s) => s.name).join(", ");
|
|
154
|
+
throw new ValidationError(`Unknown skill "${name}". Available: ${known}.`);
|
|
155
|
+
}
|
|
156
|
+
if (!existsSync(found.path)) {
|
|
157
|
+
throw new CliError(`Bundled skill not found at ${found.path}.`, EXIT_CODES.GENERIC, "Reinstall the CLI: npm install -g @creator-notes/cnotes@latest");
|
|
158
|
+
}
|
|
159
|
+
const markdown = readFileSync(found.path, "utf8");
|
|
160
|
+
const refDir = join(dirname(found.path), "references");
|
|
161
|
+
const references = existsSync(refDir)
|
|
162
|
+
? readdirSync(refDir).filter((f) => f.endsWith(".md")).sort().map((f) => join(refDir, f))
|
|
163
|
+
: [];
|
|
164
|
+
// The file is the answer, so it prints as markdown even when piped
|
|
165
|
+
// (every other command turns to JSON there); JSON only when asked.
|
|
166
|
+
if (program.opts().json || process.env.CNOTES_JSON === "1") {
|
|
167
|
+
outputJson({ name: found.name, path: found.path, markdown, references });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
process.stdout.write(markdown);
|
|
171
|
+
if (references.length > 0) {
|
|
172
|
+
process.stderr.write(`\nThe references/ files this skill points to are in ${refDir}: read one when SKILL.md names it.\n`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
handleError(error, cfg.json);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
135
179
|
}
|
|
@@ -221,6 +221,31 @@ function bundledSkillDir(name) {
|
|
|
221
221
|
return resolve(homedir(), ".cnotes", "bundled-skills", "missing", name);
|
|
222
222
|
return resolve(root, name);
|
|
223
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* The SKILL.md of a bundled skill in this install: `cnotes` (the core skill,
|
|
226
|
+
* the default) or a catalog name or alias. Null for a name this CLI does not
|
|
227
|
+
* ship. `cnotes skills show` prints it.
|
|
228
|
+
*/
|
|
229
|
+
export function bundledSkillMdPath(name = "cnotes") {
|
|
230
|
+
const q = name.trim().toLowerCase();
|
|
231
|
+
if (q === "cnotes" || q === "cn")
|
|
232
|
+
return { name: "cnotes", path: getBundledSkillPath() };
|
|
233
|
+
const skill = resolveCatalogSkill(q);
|
|
234
|
+
return skill ? { name: skill.name, path: resolve(bundledSkillDir(skill.name), "SKILL.md") } : null;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* What init says when this home holds none of the agent folders it installs
|
|
238
|
+
* into: an agent it does not know, or a Grok Bot computer without ~/.grok.
|
|
239
|
+
* Without it the agent starts its first write knowing only `--help`.
|
|
240
|
+
*/
|
|
241
|
+
export function noAgentFolderLines(cli) {
|
|
242
|
+
const agents = SKILL_TARGETS.map(skillTargetLabel);
|
|
243
|
+
const named = `${agents.slice(0, -1).join(", ")} or ${agents[agents.length - 1]}`;
|
|
244
|
+
return [
|
|
245
|
+
`No ${named} folder in this home directory, so no skill file was installed.`,
|
|
246
|
+
` Read the instructions before the first write: ${cli} skills show`,
|
|
247
|
+
];
|
|
248
|
+
}
|
|
224
249
|
/** Where a skill folder should be copied for a given agent. */
|
|
225
250
|
function skillFolderDest(name, target) {
|
|
226
251
|
return resolve(agentConfigDir(target), "skills", name);
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ Read this before putting more than one item on a canvas. Describe structure; the
|
|
|
20
20
|
|
|
21
21
|
The server measures every item, packs them into a no-overlap layout, and inserts them in a single batch. You describe **structure** (rows, columns, what's near what), the server resolves pixels. This is what `cnotes canvas place` is for, and you should reach for it whenever you're adding more than one item.
|
|
22
22
|
|
|
23
|
-
The call is **best-effort, not transactional**: per-item failures are reported in the response (HTTP 207) but the items that succeeded stay on the canvas. The exit code says which happened: `0` everything landed, `3` some items or edges were refused (stderr carries `code: "PlacePartial"
|
|
23
|
+
The call is **best-effort, not transactional**: per-item failures are reported in the response (HTTP 207) but the items that succeeded stay on the canvas. The exit code says which happened: `0` everything landed, `3` it landed only in part: some items or edges were refused, or a section it framed or placed into could not arrange itself (stderr carries `code: "PlacePartial"`, each refused item under `failed`, each such section under `failedSections`), `1` nothing was placed. On `3`, never re-run the spec, since the notes it made already exist: fix each refused item on its own (`canvas add-quote` for a face, `canvas add-edge` for an edge, a one-item `place` for the rest, `canvas arrange <canvas> --section <id>` for a section that did not arrange itself).
|
|
24
24
|
|
|
25
25
|
**You don't have to find a free coordinate.** `place` is collision-aware against content already on the canvas. By default (`placement: "auto"`) it drops your layout in a clear band **below everything that's already there**, and if you do pass an `origin` that would overlap, it slides the whole block straight down until it's clear. So appending a new section to a non-empty canvas Just Works, no need to read existing positions and guess a safe `origin` first. Use `--placement append` to force "below everything", or `--placement exact` (or `"placement": "exact"` in the doc) to honor your `origin` verbatim for pixel-perfect templates.
|
|
26
26
|
|
|
@@ -7,7 +7,7 @@ The one contract every command follows is in the core skill (the flag table and
|
|
|
7
7
|
- `notes list`, `notes get` and `notes search` emit a bare array, so one note is `.[0]`. `notes get --expand` is the exception: an object `{ notes, linked, truncated, cap, omitted, notice }` (notes.md).
|
|
8
8
|
- `notes create` returns `{ results, relationshipsCreated, rubrics?, hints? }`; read new notes from `results`. Each row carries `type`, `url`, and `quality` where the workspace grades on save; each used type's rubric is in `rubrics`, once.
|
|
9
9
|
- `canvas create` returns `{ canvas: { id, displayId, url } }` with `id`, `displayId` and `url` mirrored at the top level; after `create --spec` the placement is under `layout`, and `displayId` can still be null until `canvas get` reads it.
|
|
10
|
-
- `canvas place` returns `{ items, edges, bbox, successCount, notes?, arrangedSections? }`. It is best-effort, not transactional (HTTP 207): exit `3` means some items or edges were refused
|
|
10
|
+
- `canvas place` returns `{ items, edges, bbox, successCount, notes?, arrangedSections? }`. It is best-effort, not transactional (HTTP 207): exit `3` means it landed only in part: some items or edges were refused, or a section could not arrange itself; stderr's `PlacePartial` error lists each under `failed` / `failedEdges` / `failedSections`. `canvas create --spec` and `canvas bulk-add` (`BulkAddPartial`) exit the same way. `canvas arrange` exits `1` (`ArrangeFailed`) when no card moved and `3` (`ArrangePartial`) when the cards moved but the frame did not resize, the band below did not shift (`rippleError`) or the section could not keep itself arranged (`keepError`); an arrange is safe to re-run. A `quote` item adds `quoteNoteDisplayId`, `noteDisplayId`, `versionNumber` and `placed`.
|
|
11
11
|
- A note body comes back under `markdown` from `canvas read` and under `content` from `notes get --json`; read the key for the command you ran. A `canvas read` whose JSON starts with `level: "cards"` or `"frames"` is a map of a long board: each frame lists its cards under `lines`, with no bodies; `next` names the commands that open a frame, chosen notes or (`--full`) every body. `notes get --content-only` prints the raw markdown with no envelope, the right read for a transcript.
|
|
12
12
|
|
|
13
13
|
## Errors and notices go to stderr
|