@creator-notes/cnotes 0.121.10 → 0.124.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 +1 -1
- package/dist/commands/draft.js +8 -2
- package/dist/commands/notes-import.js +129 -0
- package/dist/commands/notes.js +2 -0
- package/dist/commands/quality.js +55 -4
- package/dist/commands/skills.js +27 -5
- package/dist/lib/install-skill.js +62 -11
- package/dist/lib/intent-run.js +1 -0
- package/dist/lib/note-import.js +128 -0
- package/dist/lib/quality.js +43 -0
- package/dist/mcp-server.js +5 -5
- package/package.json +1 -1
- package/skills/attention-planner/SKILL.md +3 -1
- package/skills/attention-planner/references/attention-type.md +5 -3
- package/skills/cnotes/SKILL.md +45 -62
- package/skills/cnotes/references/agents-together.md +1 -1
- package/skills/cnotes/references/billing.md +8 -8
- package/skills/cnotes/references/canvas-elements.md +20 -20
- package/skills/cnotes/references/canvas-layout.md +37 -29
- package/skills/cnotes/references/canvas.md +4 -2
- package/skills/cnotes/references/drafts.md +7 -5
- package/skills/cnotes/references/humanizer.md +31 -31
- package/skills/cnotes/references/more-commands.md +9 -9
- package/skills/cnotes/references/notes.md +17 -14
- package/skills/cnotes/references/operations.md +13 -12
- package/skills/cnotes/references/output.md +23 -0
- package/skills/cnotes/references/relationships.md +11 -11
- package/skills/fat-marker-flows/SKILL.md +10 -13
- package/skills/goal-tree/SKILL.md +2 -2
- package/skills/howto-filmstrips/SKILL.md +10 -10
- package/skills/teach-workspace/SKILL.md +5 -2
- package/skills/transcript-timeline/SKILL.md +7 -7
- package/skills/transcript-timeline/references/layout.md +6 -6
- package/skills/wayfind/SKILL.md +36 -33
package/dist/commands/canvas.js
CHANGED
|
@@ -1370,7 +1370,7 @@ Examples:
|
|
|
1370
1370
|
.command(name)
|
|
1371
1371
|
.description(description)
|
|
1372
1372
|
.argument("<canvasId>", "Canvas ID")
|
|
1373
|
-
.option("--content <content>", "Text content inline (markdown — headings, bold, links;
|
|
1373
|
+
.option("--content <content>", "Text content inline (markdown — headings, bold, links; a mention such as [NOTE-12: Title](relationship:verb) renders as a chip, a bare display id is a defect)")
|
|
1374
1374
|
.option("--content-file <path>", "Read text content (markdown) from a file")
|
|
1375
1375
|
.addOption(new Option("--size <size>", "Display size: small (560px), medium (1120px), large (1680px billboard)").choices(["small", "medium", "large"]))
|
|
1376
1376
|
.option("--color <hex>", "Background tint — DEFAULT IS NO BACKGROUND. Pass a ROLE hex: #3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people. Any other hex is snapped to the nearest of these at render, so an off-palette color just picks a role imprecisely. Reuse one role per meaning; omit it entirely unless the tint means something.")
|
package/dist/commands/draft.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import { Option } from "commander";
|
|
2
3
|
import { ApiClient } from "../lib/api-client.js";
|
|
3
4
|
import { liveWorkspaceId, resolveBaseConfig, resolveConfig } from "../lib/config.js";
|
|
4
5
|
import { clearProposalById, loadConfig, setActiveProposal } from "../lib/auth-store.js";
|
|
@@ -149,7 +150,8 @@ Examples:
|
|
|
149
150
|
.description("Open a private draft of the active workspace and work in it; --from-canvas branches a shared board into it")
|
|
150
151
|
.argument("[name]", "What the draft is called (optional with --from-canvas: \"<board name> V2\")")
|
|
151
152
|
.option("--from-canvas <canvas>", "Branch this board of the active workspace (CANVAS-n): the draft holds your working copy, and a person accepts it as the board's next version")
|
|
152
|
-
.option("--
|
|
153
|
+
.option("--why <text>", "The problem it answers, in the person's words, not the task: shown to them as Why. Never opens with a verb (unlike every --intent, which is a past-tense headline)")
|
|
154
|
+
.addOption(new Option("--intent <text>", "Alias of --why, kept for older scripts").hideHelp())
|
|
153
155
|
.option("--answers <ids>", "Shared notes it answers, comma-separated (QUESTION-12,PROBLEM-3): the why, as links the person can open")
|
|
154
156
|
.option("--no-switch", "Open it without working in it (commands keep working live)")
|
|
155
157
|
.addHelpText("after", `
|
|
@@ -162,7 +164,7 @@ change until a person accepts the copy as its next version.
|
|
|
162
164
|
--json adds branch { canvasId, displayId, sourceCanvasId, sourceDisplayId,
|
|
163
165
|
sourceName, baseLabel, copied } for a branch.
|
|
164
166
|
|
|
165
|
-
Say why when you open it. --
|
|
167
|
+
Say why when you open it. --why is the problem the draft answers, in the
|
|
166
168
|
person's words, never the task: "Reviewers read IBD and controlled money as
|
|
167
169
|
two things", not "Add a glossary". The person reads it as Why, above the
|
|
168
170
|
runs, and the server refuses one that opens with a verb. --answers names the
|
|
@@ -174,6 +176,10 @@ out, so the work keeps its direction.
|
|
|
174
176
|
const cfg = resolveConfig(program.opts());
|
|
175
177
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
176
178
|
try {
|
|
179
|
+
if (opts.why !== undefined && opts.intent !== undefined) {
|
|
180
|
+
throw new ValidationError("Pass --why once; --intent is its older name.");
|
|
181
|
+
}
|
|
182
|
+
opts.intent = opts.why ?? opts.intent;
|
|
177
183
|
if (!name?.trim() && !opts.fromCanvas?.trim()) {
|
|
178
184
|
throw new ValidationError("Name the draft, or branch a board", 'Run `cnotes draft open "<name>"`, or `cnotes draft open --from-canvas CANVAS-n`');
|
|
179
185
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/api-client.js";
|
|
2
|
+
import { resolveConfig } from "../lib/config.js";
|
|
3
|
+
import { handleError, ValidationError } from "../lib/errors.js";
|
|
4
|
+
import { outputJson, outputQuiet } from "../lib/output.js";
|
|
5
|
+
import { setIntentPreflight } from "../lib/intent-run.js";
|
|
6
|
+
import { buildImportItems, chunk, collectMarkdownFiles, DEFAULT_IMPORT_BATCH, MAX_IMPORT_BATCH, } from "../lib/note-import.js";
|
|
7
|
+
function collectTag(value, previous) {
|
|
8
|
+
return [...previous, value];
|
|
9
|
+
}
|
|
10
|
+
export function registerNotesImport(notes, program) {
|
|
11
|
+
const importCmd = notes
|
|
12
|
+
.command("import")
|
|
13
|
+
.description("Import published text (a newsletter archive, a blog) as notes: one note per markdown file.\n" +
|
|
14
|
+
" Each file names its published page in frontmatter (`source: <url>`). The note keeps the\n" +
|
|
15
|
+
" author's own title, unchecked by the headline rule, and stores the source, so importing\n" +
|
|
16
|
+
" the same folder again adds only the files that are new.")
|
|
17
|
+
.argument("<paths...>", "Folders of .md files (read recursively, in name order) or the files themselves")
|
|
18
|
+
.option("--type <type>", "Type for files whose frontmatter names none (an existing type, e.g. Essay)")
|
|
19
|
+
.option("--tag <tag>", "Tag every imported note (repeatable)", collectTag, [])
|
|
20
|
+
.option("--batch-size <n>", `Notes per request (default ${DEFAULT_IMPORT_BATCH}, at most ${MAX_IMPORT_BATCH})`)
|
|
21
|
+
.option("--dry-run", "Read and check every file, print what would be imported, and write nothing")
|
|
22
|
+
.addHelpText("after", `
|
|
23
|
+
File shape:
|
|
24
|
+
---
|
|
25
|
+
type: Essay
|
|
26
|
+
tags: [2024, strategy]
|
|
27
|
+
source: https://cutlefish.substack.com/p/tbm-383-maximizers-vs-focusers
|
|
28
|
+
---
|
|
29
|
+
# TBM 383: Maximizers vs. Focusers
|
|
30
|
+
|
|
31
|
+
The post as published.
|
|
32
|
+
|
|
33
|
+
The title is the file's # h1. \`tags\` also takes \`a, b\` or one \`- a\` line each;
|
|
34
|
+
\`sourceUrl\` and \`url\` are read as \`source\`. A file without a source is refused:
|
|
35
|
+
for notes of your own, use \`cnotes notes create\`.
|
|
36
|
+
|
|
37
|
+
Re-running:
|
|
38
|
+
A source the workspace already holds is returned as alreadyImported and not
|
|
39
|
+
written again, so a stopped import is finished by running it again, and next
|
|
40
|
+
week's posts are added by importing the whole folder again.
|
|
41
|
+
|
|
42
|
+
Examples:
|
|
43
|
+
$ cnotes notes import ./posts --type Essay --dry-run
|
|
44
|
+
$ cnotes notes import ./posts --type Essay --tag newsletter --intent "Imported The Beautiful Mess archive"
|
|
45
|
+
|
|
46
|
+
Output (--json):
|
|
47
|
+
{ files, imported: [{ key, displayId, title }], alreadyImported: [...] }. key is
|
|
48
|
+
the file's path relative to the current directory.
|
|
49
|
+
`)
|
|
50
|
+
.action(async (paths, opts) => {
|
|
51
|
+
const cfg = resolveConfig(program.opts());
|
|
52
|
+
try {
|
|
53
|
+
const size = opts.batchSize === undefined ? DEFAULT_IMPORT_BATCH : Number(opts.batchSize);
|
|
54
|
+
if (!Number.isInteger(size) || size < 1 || size > MAX_IMPORT_BATCH) {
|
|
55
|
+
throw new ValidationError(`--batch-size must be a whole number from 1 to ${MAX_IMPORT_BATCH}`);
|
|
56
|
+
}
|
|
57
|
+
const files = collectMarkdownFiles(paths);
|
|
58
|
+
if (files.length === 0) {
|
|
59
|
+
throw new ValidationError(`No .md files under ${paths.join(", ")}`);
|
|
60
|
+
}
|
|
61
|
+
const items = buildImportItems(files, { type: opts.type, tags: opts.tag });
|
|
62
|
+
if (opts.dryRun) {
|
|
63
|
+
if (cfg.json) {
|
|
64
|
+
outputJson({ files: files.length, dryRun: true, items: items.map(({ markdown, ...rest }) => ({ ...rest, chars: markdown.length })) });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.log(`${items.length} file${items.length === 1 ? "" : "s"} ready to import; nothing was written.`);
|
|
68
|
+
for (const item of items)
|
|
69
|
+
console.log(` ${item.key} · ${item.type} · ${item.sourceUrl}`);
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
74
|
+
const imported = [];
|
|
75
|
+
const already = [];
|
|
76
|
+
const batches = chunk(items, size);
|
|
77
|
+
for (const [i, batch] of batches.entries()) {
|
|
78
|
+
let data;
|
|
79
|
+
try {
|
|
80
|
+
data = await api.post("/api/notes/bulk", {
|
|
81
|
+
action: "bulkCreate",
|
|
82
|
+
workspaceId: cfg.workspaceId,
|
|
83
|
+
notes: batch,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
// Every earlier batch is in; the same command run again skips
|
|
88
|
+
// them by their sources and carries on from here.
|
|
89
|
+
if (imported.length + already.length > 0) {
|
|
90
|
+
console.error(`Stopped at batch ${i + 1} of ${batches.length} (${batch[0].key} onward). ` +
|
|
91
|
+
`${imported.length} notes were imported before it. Run the same command again: ` +
|
|
92
|
+
"the notes already in are skipped, not copied.");
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
for (const result of data.results ?? []) {
|
|
97
|
+
(result.alreadyImported ? already : imported).push(result);
|
|
98
|
+
}
|
|
99
|
+
if (!cfg.json && !cfg.quiet && batches.length > 1) {
|
|
100
|
+
console.error(` batch ${i + 1}/${batches.length}: ${imported.length} imported, ${already.length} already in`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (cfg.quiet) {
|
|
104
|
+
imported.forEach((r) => outputQuiet(r.displayId));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const brief = (r) => ({ key: r.key, displayId: r.displayId, title: r.title });
|
|
108
|
+
if (cfg.json) {
|
|
109
|
+
outputJson({ files: files.length, imported: imported.map(brief), alreadyImported: already.map(brief) });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log(`Imported ${imported.length} note${imported.length === 1 ? "" : "s"}` +
|
|
113
|
+
(already.length > 0 ? `; ${already.length} already in the workspace, not copied` : ""));
|
|
114
|
+
for (const r of imported)
|
|
115
|
+
console.log(` ${r.displayId}: ${r.title || "(untitled)"}`);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
handleError(error, cfg.json);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
// Under --intent the run opens before the command runs: a folder that
|
|
122
|
+
// cannot be imported is refused here first, so it leaves no empty run.
|
|
123
|
+
setIntentPreflight(importCmd, (opts) => {
|
|
124
|
+
buildImportItems(collectMarkdownFiles(importCmd.args), {
|
|
125
|
+
type: opts.type,
|
|
126
|
+
tags: opts.tag,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
package/dist/commands/notes.js
CHANGED
|
@@ -13,11 +13,13 @@ import { noteBatchIdempotencyKey, resolveNoteBatchItems } from "../lib/note-batc
|
|
|
13
13
|
import { describeUnresolvedMentions, lintNarratedVerbMentions, lintPlainTextDisplayIdsBatch, hasGenericMention, fetchRelationshipTypeOptions, } from "../lib/mention-lint.js";
|
|
14
14
|
import { attachRubricsToResults, loadRubricMap, rubricsForTypes, } from "../lib/rubrics.js";
|
|
15
15
|
import { DECISION_CARD_RULE, } from "../lib/decision-citation.js";
|
|
16
|
+
import { registerNotesImport } from "./notes-import.js";
|
|
16
17
|
export function registerNotesCommands(program) {
|
|
17
18
|
const notes = program
|
|
18
19
|
.command("notes")
|
|
19
20
|
.alias("n")
|
|
20
21
|
.description("Manage notes");
|
|
22
|
+
registerNotesImport(notes, program);
|
|
21
23
|
notes
|
|
22
24
|
.command("list")
|
|
23
25
|
.description("List notes in the current workspace")
|
package/dist/commands/quality.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { ApiClient } from "../lib/api-client.js";
|
|
2
3
|
import { resolveConfig } from "../lib/config.js";
|
|
3
4
|
import { CliError, EXIT_CODES, handleError, ValidationError } from "../lib/errors.js";
|
|
4
5
|
import { outputJson, truncate } from "../lib/output.js";
|
|
5
6
|
import { lintPlainTextDisplayIdsBatch } from "../lib/mention-lint.js";
|
|
6
|
-
import { LADDER_LABELS, LADDER_TOP, MIN_BODY_CHARS, QUALITY_CREDIT_COST, gradeFromStored, gradeRequestFor, itemFails, parseGradeSubmission, structuralIssues, toQualityNote, typeCatalogFrom, } from "../lib/quality.js";
|
|
7
|
+
import { LADDER_LABELS, LADDER_TOP, MIN_BODY_CHARS, QUALITY_CREDIT_COST, gradeFromStored, gradeRequestFor, itemFails, parseGradeBatch, parseGradeSubmission, structuralIssues, toQualityNote, typeCatalogFrom, } from "../lib/quality.js";
|
|
7
8
|
const MAX_NOTES = 200;
|
|
8
9
|
/**
|
|
9
10
|
* `cnotes quality`: structural checks plus a hand-off so the calling agent
|
|
@@ -134,9 +135,11 @@ Examples:
|
|
|
134
135
|
quality
|
|
135
136
|
.command("record")
|
|
136
137
|
.description("Record your grade for a note (level and a reason per criterion). Free: this does not spend credits. gradedBy is the open agent run, or the agent when no run is open.")
|
|
137
|
-
.argument("
|
|
138
|
-
.
|
|
139
|
-
.
|
|
138
|
+
.argument("[displayId]", "Note display ID (e.g. INSIGHT-12). Omit it with --grades / --grades-file.")
|
|
139
|
+
.option("--level <n>", "Ladder rung 1-4")
|
|
140
|
+
.option("--criteria <json>", 'JSON array of {"criterion","reason"}. "name" is accepted as an alias for criterion.')
|
|
141
|
+
.option("--grades <json>", 'Several grades in one call: a JSON array of {"displayId","level","criteria","feedback"?,"nextStep"?,"gradedVersion"?}. Each is recorded in turn; a bad entry is reported and the rest still land.')
|
|
142
|
+
.option("--grades-file <path>", "The same array, read from a file")
|
|
140
143
|
.option("--feedback <text>", "One sentence: where the note sits")
|
|
141
144
|
.option("--next-step <text>", "The single next move. Required below 4. Empty at 4.")
|
|
142
145
|
.option("--suggestion <text>", "A further improvement (repeatable)", (value, previous) => previous.concat([value]), [])
|
|
@@ -146,11 +149,59 @@ Examples:
|
|
|
146
149
|
Examples:
|
|
147
150
|
$ cnotes quality record INSIGHT-12 --graded-version 4 --level 3 --criteria '[{"criterion":"Evidence","reason":"Grounded in two tickets."}]' --feedback "The pattern is named." --next-step "Say what would falsify it."
|
|
148
151
|
$ cnotes quality record DECISION-4 --level 4 --criteria '[{"criterion":"Revisit","reason":"Names the trigger."}]' --next-step ""
|
|
152
|
+
$ cnotes quality record --grades-file ./grades.json # every note of a board in one call
|
|
149
153
|
`)
|
|
150
154
|
.action(async (displayId, opts) => {
|
|
151
155
|
const cfg = resolveConfig(program.opts());
|
|
152
156
|
const api = new ApiClient(cfg.serverUrl, cfg.token);
|
|
153
157
|
try {
|
|
158
|
+
if (opts.grades !== undefined || opts.gradesFile !== undefined) {
|
|
159
|
+
if (displayId || opts.level !== undefined || opts.criteria !== undefined) {
|
|
160
|
+
throw new ValidationError("--grades carries every grade: pass no display id, --level or --criteria beside it.");
|
|
161
|
+
}
|
|
162
|
+
const raw = opts.gradesFile !== undefined ? readFileSync(String(opts.gradesFile), "utf8") : String(opts.grades);
|
|
163
|
+
const batch = parseGradeBatch(raw);
|
|
164
|
+
if (!batch.ok)
|
|
165
|
+
throw new ValidationError(batch.message);
|
|
166
|
+
const results = [];
|
|
167
|
+
for (const entry of batch.entries) {
|
|
168
|
+
if (!entry.ok) {
|
|
169
|
+
results.push({ displayId: entry.displayId, error: entry.message });
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const body = await api.post(`/api/notes/${encodeURIComponent(entry.displayId)}/grade?workspaceId=${encodeURIComponent(cfg.workspaceId)}`, { ...entry.value });
|
|
174
|
+
results.push({ displayId: entry.displayId, ...body });
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
results.push({ displayId: entry.displayId, error: error instanceof Error ? error.message : String(error) });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const failed = results.filter((r) => r.error);
|
|
181
|
+
if (cfg.json) {
|
|
182
|
+
outputJson({ results, recorded: results.length - failed.length, failed: failed.length });
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
for (const r of results) {
|
|
186
|
+
if (r.error)
|
|
187
|
+
console.log(`✗ ${r.displayId}: ${r.error}`);
|
|
188
|
+
else {
|
|
189
|
+
const level = typeof r.level === "number" ? r.level : "?";
|
|
190
|
+
console.log(`Recorded ${r.displayId} at ${level}/${LADDER_TOP} ${LADDER_LABELS[Number(level)] ?? ""}`.trimEnd());
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
console.log(`${results.length - failed.length} of ${results.length} grades recorded. No credits spent.`);
|
|
194
|
+
}
|
|
195
|
+
if (failed.length > 0)
|
|
196
|
+
process.exitCode = EXIT_CODES.VALIDATION;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (!displayId) {
|
|
200
|
+
throw new ValidationError("Pass a note display id, or --grades / --grades-file for several at once.");
|
|
201
|
+
}
|
|
202
|
+
if (opts.level === undefined || opts.criteria === undefined) {
|
|
203
|
+
throw new ValidationError("--level and --criteria are required for a single grade.");
|
|
204
|
+
}
|
|
154
205
|
const parsed = parseGradeSubmission({
|
|
155
206
|
level: opts.level,
|
|
156
207
|
criteria: opts.criteria,
|
package/dist/commands/skills.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveBaseConfig } from "../lib/config.js";
|
|
2
|
-
import { handleError, ValidationError } from "../lib/errors.js";
|
|
2
|
+
import { EXIT_CODES, handleError, ValidationError } from "../lib/errors.js";
|
|
3
3
|
import { outputJson } from "../lib/output.js";
|
|
4
|
-
import { SKILL_CATALOG, SKILL_TARGETS, resolveCatalogSkill, hasAgentConfigDir, installSkillFolder, skillTargetLabel, } from "../lib/install-skill.js";
|
|
4
|
+
import { SKILL_CATALOG, SKILL_TARGETS, resolveCatalogSkill, hasAgentConfigDir, installSkillFolder, installedSkillState, skillTargetLabel, } from "../lib/install-skill.js";
|
|
5
5
|
/**
|
|
6
6
|
* Decide which agents to install for. An explicit `--agent` wins; otherwise
|
|
7
7
|
* install for every agent the user already uses (its config dir exists), and
|
|
@@ -27,9 +27,11 @@ export function registerSkillsCommands(program) {
|
|
|
27
27
|
.description("Install bundled agent skills (e.g. fat-marker flows, how-to filmstrips, wayfind, goal tree, shaping, attention planner, transcript timeline, teach a workspace) into Claude Code, Codex, or Cursor");
|
|
28
28
|
skills
|
|
29
29
|
.command("list")
|
|
30
|
-
.description("List the skills this CLI can install")
|
|
30
|
+
.description("List the skills this CLI can install, and whether each agent's copy is current")
|
|
31
31
|
.action(() => {
|
|
32
32
|
const cfg = resolveBaseConfig(program.opts());
|
|
33
|
+
const agents = SKILL_TARGETS.filter(hasAgentConfigDir);
|
|
34
|
+
const states = (name) => agents.map((target) => ({ target, state: installedSkillState(name, target) }));
|
|
33
35
|
if (cfg.json) {
|
|
34
36
|
outputJson(SKILL_CATALOG.map((s) => ({
|
|
35
37
|
name: s.name,
|
|
@@ -37,16 +39,26 @@ export function registerSkillsCommands(program) {
|
|
|
37
39
|
label: s.label,
|
|
38
40
|
description: s.description,
|
|
39
41
|
auto: s.auto,
|
|
42
|
+
installs: states(s.name),
|
|
40
43
|
})));
|
|
41
44
|
return;
|
|
42
45
|
}
|
|
43
46
|
console.log("Installable skills:\n");
|
|
47
|
+
const wording = {
|
|
48
|
+
"not-installed": "not installed",
|
|
49
|
+
"up-to-date": "installed, current",
|
|
50
|
+
stale: "installed, older than this CLI (refreshes on the next cnotes command)",
|
|
51
|
+
foreign: "a different skill of this name is installed; `cnotes skills install <name> --force` replaces it",
|
|
52
|
+
};
|
|
44
53
|
for (const s of SKILL_CATALOG) {
|
|
45
54
|
const aka = s.aliases.length ? ` (aka ${s.aliases.join(", ")})` : "";
|
|
46
55
|
console.log(` ${s.name}${aka}`);
|
|
47
56
|
console.log(` ${s.description}`);
|
|
48
57
|
if (s.auto)
|
|
49
58
|
console.log(" auto-installed by `cnotes init`");
|
|
59
|
+
for (const { target, state } of states(s.name)) {
|
|
60
|
+
console.log(` ${skillTargetLabel(target)}: ${wording[state]}`);
|
|
61
|
+
}
|
|
50
62
|
console.log("");
|
|
51
63
|
}
|
|
52
64
|
console.log("Install one with: cnotes skills install <name>");
|
|
@@ -55,6 +67,7 @@ export function registerSkillsCommands(program) {
|
|
|
55
67
|
.command("install <name>")
|
|
56
68
|
.description("Install a bundled skill into your agent's skills dir")
|
|
57
69
|
.option("--agent <agent>", "Which agent to install for: claude, codex, cursor, or all (default: auto-detect)")
|
|
70
|
+
.option("--force", "Replace a folder of the same name that is not a cnotes skill (by default it is left alone)")
|
|
58
71
|
.addHelpText("after", `
|
|
59
72
|
Examples:
|
|
60
73
|
$ cnotes skills install fat-marker
|
|
@@ -74,20 +87,29 @@ Examples:
|
|
|
74
87
|
throw new ValidationError(`Unknown skill "${name}". Available: ${known}.`);
|
|
75
88
|
}
|
|
76
89
|
const targets = resolveTargets(options.agent);
|
|
77
|
-
const results = targets.map((t) => installSkillFolder(skill.name, t));
|
|
90
|
+
const results = targets.map((t) => installSkillFolder(skill.name, t, { force: options.force }));
|
|
91
|
+
const refused = results.filter((r) => r.refused);
|
|
78
92
|
if (cfg.json) {
|
|
79
93
|
outputJson({ skill: skill.name, results });
|
|
94
|
+
if (refused.length > 0)
|
|
95
|
+
process.exitCode = EXIT_CODES.CONFLICT;
|
|
80
96
|
return;
|
|
81
97
|
}
|
|
82
98
|
for (const r of results) {
|
|
83
99
|
const label = skillTargetLabel(r.target);
|
|
84
|
-
if (r.
|
|
100
|
+
if (r.refused) {
|
|
101
|
+
console.log(`✗ ${label}: ${r.destPath} holds a different skill named "${skill.name}" (not a cnotes skill), so it was left alone. ` +
|
|
102
|
+
`Re-run with --force to replace it.`);
|
|
103
|
+
}
|
|
104
|
+
else if (r.alreadyUpToDate) {
|
|
85
105
|
console.log(`✓ ${skill.label} already up to date for ${label} (${r.destPath})`);
|
|
86
106
|
}
|
|
87
107
|
else {
|
|
88
108
|
console.log(`✓ Installed ${skill.label} for ${label} → ${r.destPath}`);
|
|
89
109
|
}
|
|
90
110
|
}
|
|
111
|
+
if (refused.length > 0)
|
|
112
|
+
process.exitCode = EXIT_CODES.CONFLICT;
|
|
91
113
|
// Filmstrip skills also need an authed workspace to place canvases.
|
|
92
114
|
if (skill.name === "fat-marker-flows") {
|
|
93
115
|
console.log("");
|
|
@@ -215,19 +215,53 @@ function bundledSkillDir(name) {
|
|
|
215
215
|
function skillFolderDest(name, target) {
|
|
216
216
|
return resolve(agentConfigDir(target), "skills", name);
|
|
217
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Whether a skill folder in an agent's skills dir is one of ours. A catalog
|
|
220
|
+
* name is a plain word (`shaping`, `teach`), and a third-party skill of the
|
|
221
|
+
* same name may already sit there: a user had another shaping skill under
|
|
222
|
+
* ~/.claude/skills/shaping, and an install would have copied over it with no
|
|
223
|
+
* warning. Ours say both `cnotes` and `CreatorNotes` in SKILL.md (every
|
|
224
|
+
* bundled skill runs through the CLI and names the product); a stale copy
|
|
225
|
+
* from any earlier version does too, so it still refreshes.
|
|
226
|
+
*/
|
|
227
|
+
export function isOurSkillFolder(dir) {
|
|
228
|
+
try {
|
|
229
|
+
const md = readFileSync(resolve(dir, "SKILL.md"), "utf8");
|
|
230
|
+
return md.includes("cnotes") && md.includes("CreatorNotes");
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
export function installedSkillState(name, target) {
|
|
237
|
+
const dest = skillFolderDest(name, target);
|
|
238
|
+
if (!existsSync(resolve(dest, "SKILL.md")))
|
|
239
|
+
return "not-installed";
|
|
240
|
+
if (!isOurSkillFolder(dest))
|
|
241
|
+
return "foreign";
|
|
242
|
+
const source = bundledSkillDir(name);
|
|
243
|
+
if (!existsSync(source))
|
|
244
|
+
return "stale";
|
|
245
|
+
return skillTreeUpToDate(source, dest) ? "up-to-date" : "stale";
|
|
246
|
+
}
|
|
218
247
|
/**
|
|
219
248
|
* Copy a bundled skill *folder* (SKILL.md plus any assets) into a target
|
|
220
|
-
* agent's skills dir. Overwrites an existing copy so re-running
|
|
221
|
-
*
|
|
222
|
-
*
|
|
249
|
+
* agent's skills dir. Overwrites an existing copy of OURS so re-running
|
|
250
|
+
* upgrades it; a folder that is not ours is left alone unless `force` says
|
|
251
|
+
* otherwise, and the result says so (`refused`). "Up to date" compares every
|
|
252
|
+
* bundled file, so a changed reference refreshes too.
|
|
223
253
|
*/
|
|
224
|
-
export function installSkillFolder(name, target) {
|
|
254
|
+
export function installSkillFolder(name, target, options = {}) {
|
|
225
255
|
const source = bundledSkillDir(name);
|
|
226
256
|
if (!existsSync(source)) {
|
|
227
257
|
throw new Error(`Bundled skill "${name}" not found at ${source}`);
|
|
228
258
|
}
|
|
229
259
|
const dest = skillFolderDest(name, target);
|
|
230
|
-
const
|
|
260
|
+
const present = existsSync(resolve(dest, "SKILL.md"));
|
|
261
|
+
if (present && !options.force && !isOurSkillFolder(dest)) {
|
|
262
|
+
return { target, installed: false, destPath: dest, refused: "foreign" };
|
|
263
|
+
}
|
|
264
|
+
const upToDate = present && skillTreeUpToDate(source, dest);
|
|
231
265
|
if (!upToDate) {
|
|
232
266
|
mkdirSync(dirname(dest), { recursive: true });
|
|
233
267
|
cpSync(source, dest, { recursive: true });
|
|
@@ -237,12 +271,17 @@ export function installSkillFolder(name, target) {
|
|
|
237
271
|
/**
|
|
238
272
|
* Refresh ALREADY-installed skill copies if the bundled copy has changed.
|
|
239
273
|
*
|
|
240
|
-
* Runs on every CLI invocation (cheap: one file compare per
|
|
241
|
-
* installs for an agent the user hasn't opted into — it
|
|
242
|
-
* that already exists, so a plain `npm update -g
|
|
243
|
-
* to get the latest
|
|
244
|
-
*
|
|
245
|
-
*
|
|
274
|
+
* Runs on every CLI invocation (cheap: one file compare per installed skill
|
|
275
|
+
* per target). It never installs for an agent the user hasn't opted into — it
|
|
276
|
+
* only updates a skill that already exists, so a plain `npm update -g
|
|
277
|
+
* @creator-notes/cnotes` is enough to get the latest skills for Claude, Codex
|
|
278
|
+
* and Cursor without re-running `cnotes init` or `cnotes skills install`.
|
|
279
|
+
* Every catalog skill is refreshed, not only the core one: the catalog copies
|
|
280
|
+
* used to be installed once and never again, so an agent could run a wayfind
|
|
281
|
+
* or attention-planner from months earlier that taught a rule the core had
|
|
282
|
+
* since reversed. A folder that is not ours (a third-party skill of the same
|
|
283
|
+
* name) is never touched. Best-effort: per-skill errors are swallowed so skill
|
|
284
|
+
* maintenance can never break a command.
|
|
246
285
|
*/
|
|
247
286
|
export function refreshInstalledSkills() {
|
|
248
287
|
const results = [];
|
|
@@ -257,6 +296,18 @@ export function refreshInstalledSkills() {
|
|
|
257
296
|
catch {
|
|
258
297
|
/* ignore this target — keep refreshing the others */
|
|
259
298
|
}
|
|
299
|
+
for (const skill of SKILL_CATALOG) {
|
|
300
|
+
if (skill.auto)
|
|
301
|
+
continue;
|
|
302
|
+
try {
|
|
303
|
+
if (installedSkillState(skill.name, target) === "stale") {
|
|
304
|
+
results.push(installSkillFolder(skill.name, target));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
/* ignore this skill — keep refreshing the others */
|
|
309
|
+
}
|
|
310
|
+
}
|
|
260
311
|
}
|
|
261
312
|
return results;
|
|
262
313
|
}
|
package/dist/lib/intent-run.js
CHANGED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
import { ValidationError } from "./errors.js";
|
|
4
|
+
import { readFileSafe } from "./fs-utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* `cnotes notes import`: published text (a newsletter archive, a blog) read
|
|
7
|
+
* from markdown files, one note per file. Each file names where it was
|
|
8
|
+
* published (`source:` in its frontmatter), which is what lets the server
|
|
9
|
+
* keep the author's own title and create each source once.
|
|
10
|
+
*/
|
|
11
|
+
/** The server takes at most 50 notes per batch; 25 keeps a batch of long posts well under a request's size. */
|
|
12
|
+
export const DEFAULT_IMPORT_BATCH = 25;
|
|
13
|
+
export const MAX_IMPORT_BATCH = 50;
|
|
14
|
+
const MARKDOWN_FILE = /\.(md|markdown)$/i;
|
|
15
|
+
/** Every markdown file under the given paths, sorted, so dated file names import oldest first. */
|
|
16
|
+
export function collectMarkdownFiles(paths) {
|
|
17
|
+
const files = [];
|
|
18
|
+
const walk = (path) => {
|
|
19
|
+
const stat = statSync(path);
|
|
20
|
+
if (stat.isDirectory()) {
|
|
21
|
+
for (const entry of readdirSync(path)) {
|
|
22
|
+
if (entry.startsWith("."))
|
|
23
|
+
continue;
|
|
24
|
+
walk(join(path, entry));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (MARKDOWN_FILE.test(path)) {
|
|
28
|
+
files.push(path);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
for (const path of paths) {
|
|
32
|
+
try {
|
|
33
|
+
walk(resolve(path));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new ValidationError(`Cannot read ${path}: give a folder of .md files or the files themselves`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return Array.from(new Set(files)).sort();
|
|
40
|
+
}
|
|
41
|
+
function unquote(value) {
|
|
42
|
+
const v = value.trim();
|
|
43
|
+
if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'")))
|
|
44
|
+
return v.slice(1, -1);
|
|
45
|
+
return v;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The frontmatter a markdown file opens with, as flat fields, and the body
|
|
49
|
+
* after it. Lists are `[a, b]`, `a, b`, or `- a` lines under the key.
|
|
50
|
+
*/
|
|
51
|
+
export function parseFrontmatter(text) {
|
|
52
|
+
const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(text);
|
|
53
|
+
if (!match)
|
|
54
|
+
return { fields: {}, body: text };
|
|
55
|
+
const fields = {};
|
|
56
|
+
let listKey;
|
|
57
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
58
|
+
const item = /^\s*-\s+(.*)$/.exec(line);
|
|
59
|
+
if (item && listKey) {
|
|
60
|
+
const current = fields[listKey];
|
|
61
|
+
fields[listKey] = [...(Array.isArray(current) ? current : []), unquote(item[1])];
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const pair = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/.exec(line);
|
|
65
|
+
if (!pair)
|
|
66
|
+
continue;
|
|
67
|
+
const [, key, raw] = pair;
|
|
68
|
+
const value = raw.trim();
|
|
69
|
+
listKey = value === "" ? key : undefined;
|
|
70
|
+
if (value === "")
|
|
71
|
+
continue;
|
|
72
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
73
|
+
fields[key] = value.slice(1, -1).split(",").map(unquote).filter(Boolean);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
fields[key] = unquote(value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { fields, body: text.slice(match[0].length) };
|
|
80
|
+
}
|
|
81
|
+
function asList(value) {
|
|
82
|
+
if (value === undefined)
|
|
83
|
+
return [];
|
|
84
|
+
return (Array.isArray(value) ? value : value.split(",")).map((t) => t.trim()).filter(Boolean);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* One import item per file, or every problem across all files at once so the
|
|
88
|
+
* whole folder is fixed in one pass before anything is written.
|
|
89
|
+
*/
|
|
90
|
+
export function buildImportItems(files, opts) {
|
|
91
|
+
const root = opts.root ?? process.cwd();
|
|
92
|
+
const errors = [];
|
|
93
|
+
const items = [];
|
|
94
|
+
for (const file of files) {
|
|
95
|
+
const name = relative(root, file) || file;
|
|
96
|
+
const { fields, body } = parseFrontmatter(readFileSafe(file));
|
|
97
|
+
const type = (typeof fields.type === "string" ? fields.type : opts.type ?? "").trim();
|
|
98
|
+
const rawSource = fields.source ?? fields.sourceUrl ?? fields.url;
|
|
99
|
+
const sourceUrl = typeof rawSource === "string" ? rawSource.trim() : "";
|
|
100
|
+
const markdown = body.trim();
|
|
101
|
+
if (!type)
|
|
102
|
+
errors.push({ file: name, field: "type", message: "no type: add `type: <Type>` to its frontmatter or pass --type" });
|
|
103
|
+
if (!sourceUrl) {
|
|
104
|
+
errors.push({
|
|
105
|
+
file: name,
|
|
106
|
+
field: "source",
|
|
107
|
+
message: "no source: add `source: <url of the published page>` to its frontmatter (for notes of your own, use `cnotes notes create`)",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (!markdown)
|
|
111
|
+
errors.push({ file: name, field: "markdown", message: "the file has no text after its frontmatter" });
|
|
112
|
+
if (!type || !sourceUrl || !markdown)
|
|
113
|
+
continue;
|
|
114
|
+
const tags = Array.from(new Set([...asList(fields.tags), ...(opts.tags ?? [])]));
|
|
115
|
+
items.push({ key: name, type, markdown, sourceUrl, ...(tags.length > 0 ? { tags } : {}) });
|
|
116
|
+
}
|
|
117
|
+
if (errors.length > 0) {
|
|
118
|
+
const lines = errors.map((e) => ` - ${e.file}: ${e.message}`);
|
|
119
|
+
throw new ValidationError(`${new Set(errors.map((e) => e.file)).size} of ${files.length} file${files.length === 1 ? "" : "s"} cannot be imported; nothing was sent\n${lines.join("\n")}`, undefined, { files: errors });
|
|
120
|
+
}
|
|
121
|
+
return items;
|
|
122
|
+
}
|
|
123
|
+
export function chunk(items, size) {
|
|
124
|
+
const out = [];
|
|
125
|
+
for (let i = 0; i < items.length; i += size)
|
|
126
|
+
out.push(items.slice(i, i + size));
|
|
127
|
+
return out;
|
|
128
|
+
}
|