@creator-notes/cnotes 0.114.0 → 0.115.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.114.0",
3
+ "version": "0.115.0",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -58,9 +58,18 @@ Examples:
58
58
  }
59
59
  }
60
60
  console.log("");
61
- console.log("Relationship slugs (free-form; these are conventions, not an enum):");
62
- for (const slug of STATIC_SCHEMA.relationships.common) {
63
- console.log(` - ${slug}`);
61
+ const { usage, counted, common } = schema.relationships;
62
+ if (usage && usage.length > 0) {
63
+ console.log("Relationship slugs this workspace writes, most-linked first (free-form; reuse before coining):");
64
+ outputTable(["SLUG", "LINKS"], usage.map((u) => [u.slug, String(u.links)]));
65
+ if (counted)
66
+ console.log(` (${counted})`);
67
+ }
68
+ else {
69
+ console.log("Relationship slugs (the server's built-ins; free-form, not an enum):");
70
+ for (const slug of common) {
71
+ console.log(` - ${slug}`);
72
+ }
64
73
  }
65
74
  console.log("");
66
75
  console.log("Cross-reference syntax inside markdown:");
@@ -57,6 +57,19 @@ function renderImagesSection(section) {
57
57
  ]);
58
58
  outputTable(["ID", "FILE", "SCORE", "SEEN"], rows);
59
59
  }
60
+ /**
61
+ * A flag `search semantic` shares with its parent. Commander hands a flag to
62
+ * the parent `search` wherever it appears on the line, so semantic's own copy
63
+ * only ever held its default: `--canvas` and `--limit` were dropped with exit
64
+ * 0. Take the value from whichever command actually parsed it.
65
+ */
66
+ function sharedFlag(cmd, key) {
67
+ for (const c of [cmd, cmd.parent]) {
68
+ if (c?.getOptionValueSource(key) === "cli")
69
+ return c.getOptionValue(key);
70
+ }
71
+ return cmd.getOptionValue(key);
72
+ }
60
73
  export function registerSearchCommands(program) {
61
74
  const search = program
62
75
  .command("search")
@@ -156,15 +169,16 @@ Examples:
156
169
  $ cnotes search semantic "user retention"
157
170
  $ cnotes search semantic "checkout flow" --canvas <canvasId> --limit 20 --json
158
171
  `)
159
- .action(async (query, opts) => {
172
+ .action(async (query, _opts, cmd) => {
160
173
  const cfg = resolveConfig(program.opts());
161
174
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
175
+ const canvas = sharedFlag(cmd, "canvas");
162
176
  try {
163
177
  const data = await api.post("/api/semantic-search", {
164
178
  query,
165
179
  workspaceId: cfg.workspaceId,
166
- limit: parseInt(opts.limit, 10),
167
- ...(opts.canvas ? { canvasId: opts.canvas } : {}),
180
+ limit: parseInt(sharedFlag(cmd, "limit") ?? "10", 10) || 10,
181
+ ...(canvas ? { canvasId: canvas } : {}),
168
182
  });
169
183
  const results = data.results || data;
170
184
  if (cfg.json) {
@@ -6,25 +6,41 @@
6
6
  * slugs, resource field shapes, exit codes, and env vars. One source of truth
7
7
  * so the CLI and MCP surfaces never drift.
8
8
  */
9
+ /**
10
+ * The server's built-in relationship slugs, spelled as it seeds them
11
+ * (lib/constants/relationship-types.ts; build-schema.test.ts keeps the two in
12
+ * step). The schema falls back to these only when the workspace's own ranking
13
+ * cannot be read or the workspace has no links yet. A hand-written list used to
14
+ * stand here and sent agents to near-twins of what workspaces write
15
+ * (derives_from beside derived-from, related beside related-to), which split
16
+ * their backlinks.
17
+ */
18
+ export const BUILT_IN_RELATIONSHIP_SLUGS = [
19
+ "references",
20
+ "blocks",
21
+ "contradicts",
22
+ "depends-on",
23
+ "derived-from",
24
+ "duplicates",
25
+ "extends",
26
+ "implements",
27
+ "invalidates",
28
+ "part-of",
29
+ "related-to",
30
+ "supersedes",
31
+ "validates",
32
+ ];
9
33
  export const STATIC_SCHEMA = {
10
34
  relationships: {
11
- note: "Relationship slugs are free-form strings. The values below are common conventions, not an enum — the server accepts any string.",
12
- common: [
13
- "references",
14
- "supports",
15
- "blocks",
16
- "derives_from",
17
- "contradicts",
18
- "triggers",
19
- "related",
20
- ],
35
+ note: "Relationship slugs are free-form strings, not an enum: the server accepts any string. `common` is this workspace's own vocabulary, most-linked first (`usage` has the counts); reuse one of these spellings before coining a near-twin.",
36
+ common: [...BUILT_IN_RELATIONSHIP_SLUGS],
21
37
  },
22
38
  syntax: {
23
39
  noteMention: "[NOTE-12: Title](relationship:<type>)",
24
40
  batchPlaceholder: "[@key: Title](relationship:<type>) — '@key' is replaced with the new display ID after batch create",
25
41
  rules: [
26
42
  "`: Title` after the ID is optional. The server stamps the linked note's current title onto the chip when it saves; `[[<type>::NOTE-12]]` is the same link in wiki form.",
27
- "Pick the relationship slug from the verb your own prose uses: 'blocks X' → relationship:blocks, 'depends on X' → relationship:depends-on. Slugs are free-form (unknown ones auto-create); `cnotes rel types` lists the workspace vocabulary — reuse before coining.",
43
+ "Pick the relationship slug from the verb your own prose uses: 'blocks X' → relationship:blocks, 'depends on X' → relationship:depends-on. Slugs are free-form (unknown ones auto-create); `relationships.common` is the workspace's vocabulary, most-linked first, and `cnotes rel types` lists every slug — reuse before coining.",
28
44
  "Reserve `references` for pure citations. A verb narrated in prose around a `references` chip is invisible to backlinks and `rel list` — create/version responses flag these as `mentionWarnings`; treat each as a retype instruction.",
29
45
  ],
30
46
  },
@@ -72,6 +88,8 @@ export const STATIC_SCHEMA = {
72
88
  "5": "conflict (state collision)",
73
89
  "6": "rate-limited",
74
90
  "7": "permission denied",
91
+ "8": "subscription required or billing lockout (the JSON error carries upgradeUrl)",
92
+ "9": "network: the server could not be reached or the connection dropped (the hint says whether a write may have landed)",
75
93
  },
76
94
  env: {
77
95
  CNOTES_SERVER: "Override server URL",
@@ -86,19 +104,43 @@ export const STATIC_SCHEMA = {
86
104
  CLAUDE_CODE_SESSION_ID: "Auto-detected by Claude Code; stamped as agentSession kind=claude-code",
87
105
  },
88
106
  agentRun: {
89
- note: "Wrap multi-step canvas mutations in an agent-run so they show up as one revertable unit in the UI history.",
107
+ note: "Open a run before writing: `cnotes operations begin` brackets everything that follows (notes and canvases) as one entry in History, and a note create with a key outside a run is refused (422 operation_required). `canvas agent-run wrap` brackets one command's canvas mutations.",
108
+ begin: "cnotes operations begin --prompt \"<intent>\" …writes… cnotes operations end",
90
109
  wrap: "cnotes canvas agent-run wrap --canvas <id> --prompt \"<intent>\" -- <command>",
91
110
  },
92
111
  };
112
+ /**
113
+ * The relationships block: the workspace's own ranking when it has one, the
114
+ * server's built-in spellings when it has no links yet or the ranking could
115
+ * not be read.
116
+ */
117
+ function relationshipsFrom(usage) {
118
+ const ranked = (usage?.types ?? []).filter((t) => t.name && t.links > 0);
119
+ if (ranked.length === 0) {
120
+ return {
121
+ ...STATIC_SCHEMA.relationships,
122
+ note: "Relationship slugs are free-form strings, not an enum: the server accepts any string. `common` is the server's built-in vocabulary, because this workspace's own could not be read or it has no links yet; `cnotes rel types` lists every slug. Reuse one of these spellings before coining a near-twin.",
123
+ };
124
+ }
125
+ return {
126
+ note: STATIC_SCHEMA.relationships.note,
127
+ common: ranked.map((t) => t.name),
128
+ usage: ranked.map((t) => ({ slug: t.name, links: t.links })),
129
+ counted: usage?.complete
130
+ ? `distinct links per slug across all ${usage.linksRead ?? 0} link rows in this workspace`
131
+ : `distinct links per slug among the newest ${usage?.linksRead ?? 0} link rows in this workspace`,
132
+ };
133
+ }
93
134
  /**
94
135
  * Build the full schema document. The static metadata (exit codes, syntax,
95
- * resource shapes) is always present; the dynamic bits (workspace + types)
96
- * are fetched and any failures are reported in `dynamicFetchErrors` so callers
97
- * never treat a partial schema as authoritative.
136
+ * resource shapes) is always present; the dynamic bits (workspace, types and
137
+ * the relationship vocabulary) are fetched and any failures are reported in
138
+ * `dynamicFetchErrors` so callers never treat a partial schema as
139
+ * authoritative.
98
140
  */
99
141
  export async function buildSchema(api, workspaceId) {
100
142
  const dynamicFetchErrors = [];
101
- const [workspaceData, supertags] = await Promise.all([
143
+ const [workspaceData, supertags, relationshipUsage] = await Promise.all([
102
144
  api
103
145
  .get(`/api/workspaces/${workspaceId}`)
104
146
  .catch((err) => {
@@ -117,6 +159,15 @@ export async function buildSchema(api, workspaceId) {
117
159
  });
118
160
  return [];
119
161
  }),
162
+ api
163
+ .get("/api/relationship-types/usage", { workspaceId })
164
+ .catch((err) => {
165
+ dynamicFetchErrors.push({
166
+ resource: "relationships",
167
+ error: err instanceof Error ? err.message : String(err),
168
+ });
169
+ return null;
170
+ }),
120
171
  ]);
121
172
  const workspaceRecord = workspaceData
122
173
  ? (workspaceData.workspace ??
@@ -147,5 +198,6 @@ export async function buildSchema(api, workspaceId) {
147
198
  types,
148
199
  ...(dynamicFetchErrors.length > 0 ? { dynamicFetchErrors } : {}),
149
200
  ...STATIC_SCHEMA,
201
+ relationships: relationshipsFrom(relationshipUsage),
150
202
  };
151
203
  }
@@ -12,8 +12,27 @@ export function setOutputMode(next) {
12
12
  /** Envelope keys that hold a response's rows, in the order we look for them. */
13
13
  const ROW_KEYS = ["results", "items", "comments", "plans", "drafts", "all", "keys"];
14
14
  /**
15
- * Find the rows in a response: the array itself, or the array inside a known
16
- * envelope key (`notes create` → results, `comments list` → comments, …).
15
+ * The sections of a sectioned envelope (`search` →
16
+ * `{ sections: { notes: { results }, canvases: { results } } }`), whose rows
17
+ * sit one level down. A section that failed carries `error` and no results.
18
+ */
19
+ function sectionsOf(data) {
20
+ if (!data || typeof data !== "object" || Array.isArray(data))
21
+ return null;
22
+ const sections = data.sections;
23
+ if (!sections || typeof sections !== "object" || Array.isArray(sections))
24
+ return null;
25
+ const values = Object.values(sections);
26
+ if (!values.every((s) => s && typeof s === "object" && !Array.isArray(s)))
27
+ return null;
28
+ if (!values.some((s) => Array.isArray(s.results)))
29
+ return null;
30
+ return sections;
31
+ }
32
+ /**
33
+ * Find the rows in a response: the array itself, the array inside a known
34
+ * envelope key (`notes create` → results, `comments list` → comments, …), or
35
+ * every section's results in order (`search`).
17
36
  */
18
37
  function findRows(data) {
19
38
  if (Array.isArray(data))
@@ -25,6 +44,10 @@ function findRows(data) {
25
44
  if (Array.isArray(rec[key]))
26
45
  return { rows: rec[key], key };
27
46
  }
47
+ const sections = sectionsOf(data);
48
+ if (sections) {
49
+ return { rows: Object.values(sections).flatMap((s) => (Array.isArray(s.results) ? s.results : [])) };
50
+ }
28
51
  return null;
29
52
  }
30
53
  /**
@@ -33,7 +56,8 @@ function findRows(data) {
33
56
  * just the keys they need (e.g. `--fields displayId,title`) instead of paying
34
57
  * for the full record in their context window. When none of the fields sit on
35
58
  * an envelope itself, they are applied to its rows instead, so
36
- * `notes create --fields key,displayId` trims `.results[]`.
59
+ * `notes create --fields key,displayId` trims `.results[]` and
60
+ * `search --fields displayId,title` trims each section's results.
37
61
  */
38
62
  export function projectFields(data, fields) {
39
63
  if (!fields || fields.length === 0)
@@ -53,6 +77,14 @@ export function projectFields(data, fields) {
53
77
  return data.map(pick);
54
78
  const found = findRows(data);
55
79
  const rec = data;
80
+ const sections = sectionsOf(data);
81
+ if (sections && rec && !fields.some((f) => f in rec)) {
82
+ const trimmed = {};
83
+ for (const [name, s] of Object.entries(sections)) {
84
+ trimmed[name] = Array.isArray(s.results) ? { ...s, results: s.results.map(pick) } : s;
85
+ }
86
+ return { ...rec, sections: trimmed };
87
+ }
56
88
  if (found?.key && rec && !fields.some((f) => f in rec)) {
57
89
  return { ...rec, [found.key]: found.rows.map(pick) };
58
90
  }
package/dist/program.js CHANGED
@@ -100,6 +100,7 @@ Examples:
100
100
  Exit codes:
101
101
  0 ok 1 generic 2 auth 3 validation
102
102
  4 not-found 5 conflict 6 rate-limit 7 permission
103
+ 8 subscription/billing 9 network
103
104
 
104
105
  Env vars:
105
106
  CNOTES_SERVER, CNOTES_TOKEN, CNOTES_WORKSPACE, CNOTES_JSON=1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.114.0",
3
+ "version": "0.115.0",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -60,7 +60,7 @@ Other writes that belong together (notes on two canvases, a change that needs se
60
60
 
61
61
  1. **The exit code is the verdict.** `0` is success. Never decide success from the body, and never re-run a write because a key looked empty: a second `notes create` duplicates the batch.
62
62
  2. **Knowledge lives in typed notes.** Text cards, lists, section frames, edges and portals arrange and label; they are unversioned, unsearchable and uncitable. If a future reader needs to find, cite or trust it, it is a note. A text card holds at most three sentences (the orientation banner: four short lines).
63
- 3. **Name notes with titled, typed mentions.** `[NOTE-12: Title](relationship:<verb>)`, with the verb your sentence uses (`blocks`, `depends-on`, `answered-by`). A bare `NOTE-12` in prose creates no link and is a defect, in note bodies and on canvas cards. `references` is for pure citation only. Reuse the workspace's types (`cnotes rel types`) before coining one.
63
+ 3. **Name notes with titled, typed mentions.** `[NOTE-12: Title](relationship:<verb>)`, with the verb your sentence uses (`blocks`, `depends-on`, `answered-by`). A bare `NOTE-12` in prose creates no link and is a defect, in note bodies and on canvas cards. `references` is for pure citation only. Reuse the workspace's types (`cnotes schema` ranks them by use; `cnotes rel types` lists all) before coining one.
64
64
  4. **Edges are local to one canvas.** When an edge connects two notes, write the same relationship as a mention in a note body, or it exists nowhere off that canvas.
65
65
  5. **Place declaratively, edit in place.** Use `canvas place` / `canvas arrange`, never hand-computed x/y. Add to a section with `place --into SECTION-n` (or `--section` on a single add); tidy one with `arrange --section SECTION-n`. Change a text card with `canvas update-text` and a frame with `canvas update-section`. Deleting and re-adding mints new ids and drops edges and `[[SECTION-n]]` mentions.
66
66
  6. **Content changes are versions.** `cnotes versions create` changes a note's body (the `# h1` is its title); fetch the current body first and edit that, since people edit between sessions. `notes update` changes metadata only (type, tags, pin, archive).
@@ -269,7 +269,7 @@ each note is judged again; a new label alone keeps them.
269
269
  > — from [[quotes::TRANSCRIPT-4@v5]] v5, 12 Oct 2026, 4:55 pm
270
270
  ```
271
271
  It is a hard copy: the version never changes, so the block never goes stale, and saving it records a `quotes` relationship pinned to v5. Say what the quote means in your own sentences around it.
272
- - **Reuse an existing relationship type before inventing one.** Run `cnotes rel types` (or read the list printed by `cnotes workspace current`) and pick the closest existing label. The type slot is free-form, so an unknown label is auto-created as a custom workspace type rather than dropped — but that means a typo or a needless synonym (`support` vs `supports`, `relates-to` vs `related-to`) silently pollutes the workspace's type vocabulary forever. Only coin a new type when nothing existing fits.
272
+ - **Reuse an existing relationship type before inventing one.** `cnotes schema` lists the workspace's slugs most-linked first (`cnotes rel types` lists every one); pick the closest existing label. The type slot is free-form, so an unknown label is auto-created as a custom workspace type rather than dropped — but that means a typo or a needless synonym (`support` vs `supports`, `relates-to` vs `related-to`) silently pollutes the workspace's type vocabulary forever. Only coin a new type when nothing existing fits.
273
273
  - Names are normalized to lowercase + hyphens, so `Depends On`, `depends on`, and `depends-on` all resolve to the same type. When `cnotes notes create` does create new types, it reports them (`+ created N new relationship types: …`) — treat that line as a prompt to double-check you didn't mean an existing one.
274
274
  - Common built-in types to reach for first:
275
275
  - `depends-on` / `blocks` — dependency ordering between notes