@creator-notes/cnotes 0.113.0 → 0.113.2

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.113.0",
3
+ "version": "0.113.2",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
package/README.md CHANGED
@@ -56,6 +56,7 @@ cnotes search semantic "onboarding flow"
56
56
  | `cnotes types list\|create\|update` | `cnotes t` | Manage note types (supertags) |
57
57
  | `cnotes workspace list\|select\|current` | | Workspace management |
58
58
  | `cnotes config get-server\|set-server` | | CLI configuration |
59
+ | `cnotes config get-local-db\|set-local-db` | | Allow or refuse a local copy of workspace note metadata on this machine (off by default; off deletes the copies) |
59
60
  | `cnotes mcp setup` | | Print MCP server config for Claude |
60
61
 
61
62
  ## Global Flags
@@ -331,6 +332,8 @@ cp $(npm root -g)/@creator-notes/cnotes/skills/cnotes/SKILL.md .claude/skills/cn
331
332
 
332
333
  `cnotes query` keeps a SQLite copy of the workspace's note metadata (titles, types, tags, canvases, who made each note, judged answers; never a note body) under `~/.cnotes/local-db/`, syncs what changed since the last call, and answers from the copy in milliseconds. The web app's Query panel uses the same copy format, so the two never disagree.
333
334
 
335
+ A copy on disk is the person's decision, as it is in the web app: it is off until `cnotes config set-local-db on` (or `CNOTES_LOCAL_DB=on` in the environment). Until then `cnotes query`, and the `cnotes_query` MCP tool, refuse and say so. `set-local-db off` deletes every copy; `cnotes query --forget` deletes one workspace's.
336
+
334
337
  ```bash
335
338
  cnotes query pricing --type Decision,Insight # words in the title, AND across fields
336
339
  cnotes query --canvas CANVAS-12 --group-by tag # notes on one canvas, grouped by tag
@@ -1,4 +1,6 @@
1
- import { loadConfig, setCurrentServer } from "../lib/auth-store.js";
1
+ import { isLocalDbEnabled, loadConfig, setCurrentServer, setLocalDb } from "../lib/auth-store.js";
2
+ import { forgetLocalCopies } from "../lib/local-db-store.js";
3
+ import { ValidationError } from "../lib/errors.js";
2
4
  import { validateServerUrl, unofficialServerWarning } from "../lib/server-url.js";
3
5
  import { handleError } from "../lib/errors.js";
4
6
  import { outputJson } from "../lib/output.js";
@@ -50,4 +52,47 @@ export function registerConfigCommands(program) {
50
52
  handleError(error, json);
51
53
  }
52
54
  });
55
+ config
56
+ .command("set-local-db")
57
+ .description("Allow (on) or refuse (off) a local copy of workspace note metadata on this machine; off deletes every copy")
58
+ .argument("<on|off>", "on or off")
59
+ .action(async (value) => {
60
+ const json = program.opts().json ?? false;
61
+ try {
62
+ const setting = value.trim().toLowerCase();
63
+ if (setting !== "on" && setting !== "off")
64
+ throw new ValidationError(`set-local-db takes on or off, not "${value}".`);
65
+ const cfg = loadConfig();
66
+ setLocalDb(cfg, setting);
67
+ const forgot = setting === "off" ? forgetLocalCopies(null) : 0;
68
+ if (json) {
69
+ outputJson({ localDb: setting, forgot });
70
+ }
71
+ else if (setting === "on") {
72
+ console.log("Local copies allowed. `cnotes query` keeps each workspace's note metadata (never a body) under the cnotes config directory.");
73
+ }
74
+ else {
75
+ console.log(`Local copies refused${forgot ? `; deleted ${forgot} file${forgot === 1 ? "" : "s"}` : ""}.`);
76
+ }
77
+ }
78
+ catch (error) {
79
+ handleError(error, json);
80
+ }
81
+ });
82
+ config
83
+ .command("get-local-db")
84
+ .description("Show whether this machine may keep a local copy of workspace note metadata")
85
+ .action(async () => {
86
+ const json = program.opts().json ?? false;
87
+ try {
88
+ const enabled = isLocalDbEnabled();
89
+ if (json)
90
+ outputJson({ localDb: enabled ? "on" : "off" });
91
+ else
92
+ console.log(enabled ? "on" : "off");
93
+ }
94
+ catch (error) {
95
+ handleError(error, json);
96
+ }
97
+ });
53
98
  }
@@ -2,7 +2,7 @@ import { ApiClient } from "../lib/api-client.js";
2
2
  import { resolveConfig } from "../lib/config.js";
3
3
  import { ValidationError, handleError } from "../lib/errors.js";
4
4
  import { outputJson, timeAgo, truncate } from "../lib/output.js";
5
- import { openLocalCopy } from "../lib/local-db-store.js";
5
+ import { forgetLocalCopies, openLocalCopy } from "../lib/local-db-store.js";
6
6
  import { SCHEMA_HINT } from "../local-db/schema.js";
7
7
  import { UNJUDGED } from "../local-db/query.js";
8
8
  const GROUPS = {
@@ -150,8 +150,11 @@ export function renderSql(out) {
150
150
  }
151
151
  const SQL_MAX_ROWS = 500;
152
152
  /** Everything `cnotes query` and the MCP tool share: sync, ask, shape the answer. */
153
- export async function runQuery(api, workspaceId, words, opts, directory) {
154
- const opened = await openLocalCopy({ api, workspaceId, rebuild: opts.rebuild, directory });
153
+ export async function runQuery(api, workspaceId, words, opts, run = {}) {
154
+ if (opts.forget) {
155
+ return { kind: "forgot", files: forgetLocalCopies(workspaceId, run.directory) };
156
+ }
157
+ const opened = await openLocalCopy({ api, workspaceId, rebuild: opts.rebuild, directory: run.directory, enabled: run.enabled });
155
158
  try {
156
159
  if (opts.sql !== undefined) {
157
160
  if (opts.sql.trim().toLowerCase() === "tables") {
@@ -183,11 +186,16 @@ export function registerQueryCommands(program) {
183
186
  .option("--limit <n>", "Rows to return (default 100)")
184
187
  .option("--sql <select>", "Run one read-only SELECT against the copy; `tables` lists the tables")
185
188
  .option("--rebuild", "Drop this workspace's copy and copy it again")
189
+ .option("--forget", "Delete this workspace's copy from this machine and stop")
186
190
  .addHelpText("after", `
187
191
  The copy holds every note's metadata (title, type, tags, canvases, who made it,
188
192
  judged answers), never a note body. The first call copies the workspace; later
189
193
  calls sync only what changed, then answer in milliseconds.
190
194
 
195
+ A copy on this machine is the person's decision: it is off until
196
+ \`cnotes config set-local-db on\` (or CNOTES_LOCAL_DB=on). \`set-local-db off\`
197
+ deletes every copy; --forget deletes this workspace's.
198
+
191
199
  Examples:
192
200
  $ cnotes query pricing --type Decision,Insight
193
201
  $ cnotes query --canvas CANVAS-12 --group-by tag
@@ -201,6 +209,13 @@ Examples:
201
209
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
202
210
  try {
203
211
  const answer = await runQuery(api, cfg.workspaceId, words, opts);
212
+ if (answer.kind === "forgot") {
213
+ if (cfg.json)
214
+ outputJson({ forgot: answer.files }, cfg.fields);
215
+ else
216
+ console.log(answer.files === 0 ? "No local copy of this workspace on this machine." : `Deleted this workspace's local copy (${answer.files} file${answer.files === 1 ? "" : "s"}).`);
217
+ return;
218
+ }
204
219
  if (answer.kind === "tables") {
205
220
  if (cfg.json)
206
221
  outputJson({ tables: answer.tables, sync: answer.sync }, cfg.fields);
@@ -170,6 +170,22 @@ export function setCurrentServer(config, serverUrl) {
170
170
  config.currentServer = serverUrl;
171
171
  saveConfig(config);
172
172
  }
173
+ /**
174
+ * The local-copy switch: CNOTES_LOCAL_DB in the environment (an agent's
175
+ * harness the person configured) beats the saved setting; neither set is off.
176
+ */
177
+ export function isLocalDbEnabled(config = loadConfig()) {
178
+ const env = process.env.CNOTES_LOCAL_DB?.trim().toLowerCase();
179
+ if (env === "on" || env === "1" || env === "true")
180
+ return true;
181
+ if (env === "off" || env === "0" || env === "false")
182
+ return false;
183
+ return config.localDb === "on";
184
+ }
185
+ export function setLocalDb(config, value) {
186
+ config.localDb = value;
187
+ saveConfig(config);
188
+ }
173
189
  /**
174
190
  * Persist the active workspace for a server. Returns false (a no-op) when there
175
191
  * is no stored config entry for `serverUrl` — i.e. the token came from a flag or
@@ -19,7 +19,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
19
19
  */
20
20
  import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
21
21
  import { join } from "node:path";
22
- import { getConfigDir } from "./auth-store.js";
22
+ import { getConfigDir, isLocalDbEnabled } from "./auth-store.js";
23
23
  import { CliError, NotFoundError } from "./errors.js";
24
24
  import { createLocalDbOps, openCopy } from "../local-db/ops.js";
25
25
  import { workspaceFilePrefix } from "../local-db/protocol.js";
@@ -28,6 +28,10 @@ import { IDLE_STATUS, WorkspaceSync } from "../local-db/sync.js";
28
28
  export function localDbDirectory() {
29
29
  return join(getConfigDir(), "local-db");
30
30
  }
31
+ export const LOCAL_DB_OFF_MESSAGE = "A local copy of this workspace is not allowed on this machine yet.";
32
+ export const LOCAL_DB_OFF_HINT = "cnotes query keeps the workspace's note metadata (titles, types, tags, canvases, who made each note, judged answers; never a note body) " +
33
+ "in a SQLite file under the cnotes config directory. If the person agrees, they run `cnotes config set-local-db on`; " +
34
+ "until then, read notes with `cnotes notes list` and `cnotes notes get`.";
31
35
  export const NODE_SQLITE_HINT = "cnotes query keeps the workspace copy in node:sqlite, which needs Node.js 22.13 or newer. " +
32
36
  "Upgrade Node (https://nodejs.org), or use the cnotes binary, which carries its own runtime.";
33
37
  async function loadDatabase() {
@@ -176,7 +180,23 @@ export function fetchSyncHead(api, workspaceId) {
176
180
  // ---------------------------------------------------------------------------
177
181
  /** Inside this window a call pulls only what changed; past it, every note id is compared again. */
178
182
  export const RECONCILE_EVERY_MS = 60 * 60 * 1000;
183
+ /** Delete the copies on disk: one workspace's, or every workspace's when `workspaceId` is null. Returns how many files went. */
184
+ export function forgetLocalCopies(workspaceId, directory = localDbDirectory()) {
185
+ if (!existsSync(directory))
186
+ return 0;
187
+ const prefix = workspaceId ? workspaceFilePrefix(workspaceId).replace(/^\//, "") : "";
188
+ let removed = 0;
189
+ for (const name of readdirSync(directory)) {
190
+ if (!name.startsWith(prefix))
191
+ continue;
192
+ rmSync(join(directory, name), { force: true });
193
+ removed += 1;
194
+ }
195
+ return removed;
196
+ }
179
197
  export async function openLocalCopy(options) {
198
+ if (!(options.enabled ?? isLocalDbEnabled()))
199
+ throw new CliError(LOCAL_DB_OFF_MESSAGE, undefined, LOCAL_DB_OFF_HINT);
180
200
  const Database = await loadDatabase();
181
201
  const directory = options.directory ?? localDbDirectory();
182
202
  const store = new LocalCopyStore(Database, directory);
@@ -80,10 +80,63 @@ export function applyHead(db, head) {
80
80
  continue;
81
81
  db.run("DELETE FROM canvases WHERE id = ?", [id]);
82
82
  db.run("DELETE FROM placements WHERE canvas_id = ?", [id]);
83
+ clearLayout(db, id);
83
84
  }
84
85
  });
85
86
  return { canvasesToRefresh, dimensionsToRefresh };
86
87
  }
88
+ function clearLayout(db, canvasId) {
89
+ db.run("DELETE FROM layout_nodes WHERE canvas_id = ?", [canvasId]);
90
+ db.run("DELETE FROM layout_edges WHERE canvas_id = ?", [canvasId]);
91
+ }
92
+ /** Replace one board's layout rows (the workspace map's source). */
93
+ function writeLayout(db, canvasId, layout) {
94
+ clearLayout(db, canvasId);
95
+ const node = (id, kind, noteId, x, y, w, h, data) => db.run("INSERT OR REPLACE INTO layout_nodes (canvas_id, node_id, kind, note_id, x, y, w, h, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", [
96
+ canvasId,
97
+ id,
98
+ kind,
99
+ noteId,
100
+ x,
101
+ y,
102
+ w,
103
+ h,
104
+ JSON.stringify(data),
105
+ ]);
106
+ for (const c of layout.cards)
107
+ node(c.id, "card", c.noteId, c.x, c.y, c.w, c.h, { quoteStyle: c.quoteStyle, quoteSize: c.quoteSize });
108
+ for (const s of layout.sections)
109
+ node(s.id, "section", null, s.x, s.y, s.w, s.h, { name: s.name, displayId: s.displayId, colorHex: s.colorHex });
110
+ for (const t of layout.texts)
111
+ node(t.id, "text", null, t.x, t.y, t.w, t.h, { text: t.text, size: t.size, colorHex: t.colorHex });
112
+ for (const l of layout.lists)
113
+ node(l.id, "list", null, l.x, l.y, l.w, l.h, { name: l.name, description: l.description, colorHex: l.colorHex, items: l.items });
114
+ for (const l of layout.links)
115
+ node(l.id, "link", null, l.x, l.y, l.w, l.h, { linkedCanvasId: l.linkedCanvasId });
116
+ for (const e of layout.edges) {
117
+ db.run("INSERT INTO layout_edges (canvas_id, source, target, arrow_start, arrow_end, line_style) VALUES (?, ?, ?, ?, ?, ?)", [
118
+ canvasId,
119
+ e.source,
120
+ e.target,
121
+ e.arrowStart == null ? null : e.arrowStart ? 1 : 0,
122
+ e.arrowEnd == null ? null : e.arrowEnd ? 1 : 0,
123
+ e.lineStyle,
124
+ ]);
125
+ }
126
+ }
127
+ /** Every board's layout joined to its notes, for the workspace map. Branch drafts are left out. */
128
+ export function readWorkspaceLayout(db) {
129
+ const canvases = db.all("SELECT id, display_id AS displayId, name, updated_at AS updatedAt, branch_of AS branchOf, is_default AS isDefault FROM canvases WHERE branch_of IS NULL");
130
+ const nodes = db.all(`SELECT l.canvas_id AS canvasId, l.node_id AS nodeId, l.kind, l.note_id AS noteId, l.x, l.y, l.w, l.h, l.data,
131
+ n.display_id AS displayId, n.title, n.type, n.updated_at AS updatedAt
132
+ FROM layout_nodes l
133
+ JOIN canvases c ON c.id = l.canvas_id AND c.branch_of IS NULL
134
+ LEFT JOIN notes n ON n.id = l.note_id
135
+ WHERE l.kind != 'card' OR n.id IS NOT NULL`);
136
+ const edges = db.all(`SELECT e.canvas_id AS canvasId, e.source, e.target, e.arrow_start AS arrowStart, e.arrow_end AS arrowEnd, e.line_style AS lineStyle
137
+ FROM layout_edges e JOIN canvases c ON c.id = e.canvas_id AND c.branch_of IS NULL`);
138
+ return { canvases, nodes, edges };
139
+ }
87
140
  /** Replace each board's placements, and remember the board fields they were read at. */
88
141
  export function applyPlacements(db, rows) {
89
142
  db.transaction(() => {
@@ -91,8 +144,11 @@ export function applyPlacements(db, rows) {
91
144
  db.run("DELETE FROM placements WHERE canvas_id = ?", [row.canvasId]);
92
145
  if (row.removed) {
93
146
  db.run("DELETE FROM canvases WHERE id = ?", [row.canvasId]);
147
+ clearLayout(db, row.canvasId);
94
148
  continue;
95
149
  }
150
+ if (row.layout)
151
+ writeLayout(db, row.canvasId, row.layout);
96
152
  for (const noteId of row.cards) {
97
153
  db.run("INSERT OR IGNORE INTO placements (canvas_id, note_id, via) VALUES (?, ?, 'card')", [row.canvasId, noteId]);
98
154
  }
@@ -10,7 +10,7 @@
10
10
  * on `node:sqlite` under its config directory. Opening, forgetting and wiping
11
11
  * files stay with the storage, so they are not here.
12
12
  */
13
- import { applyAnswers, applyHead, applyNotes, applyPlacements, countRows, getMeta, reconcileNotes, setMeta } from "./apply.js";
13
+ import { applyAnswers, applyHead, applyNotes, applyPlacements, countRows, getMeta, readWorkspaceLayout, reconcileNotes, setMeta } from "./apply.js";
14
14
  import { buildCountQuery, buildFacetQuery, buildGroupCountsQuery, buildResultsQuery, checkReadOnlySql } from "./query.js";
15
15
  import { ensureSchema } from "./schema.js";
16
16
  export const NEWEST_KEY = "newest_note_updated_at";
@@ -88,6 +88,10 @@ export function createLocalDbOps(db) {
88
88
  const groups = groupBy === "none" ? [] : db.all(groupsQuery.sql, groupsQuery.params);
89
89
  return { rows, total, groups, ms: now() - start };
90
90
  },
91
+ workspaceLayout: () => {
92
+ const start = now();
93
+ return { ...readWorkspaceLayout(db), ms: now() - start };
94
+ },
91
95
  facets: ({ filter, fields, limit }) => {
92
96
  const start = now();
93
97
  const facets = {};
@@ -1,5 +1,5 @@
1
- export const SCHEMA_VERSION = 2;
2
- const TABLES = ["notes", "note_tags", "canvases", "placements", "members", "dimensions", "answers", "meta"];
1
+ export const SCHEMA_VERSION = 3;
2
+ const TABLES = ["notes", "note_tags", "canvases", "placements", "layout_nodes", "layout_edges", "members", "dimensions", "answers", "meta"];
3
3
  const CREATE = [
4
4
  `CREATE TABLE notes (
5
5
  id TEXT PRIMARY KEY,
@@ -29,6 +29,30 @@ const CREATE = [
29
29
  via TEXT NOT NULL,
30
30
  PRIMARY KEY (canvas_id, note_id, via)
31
31
  ) WITHOUT ROWID`,
32
+ // Where everything on each board sits, for the WebGL workspace map. `data`
33
+ // is the rest of the row as JSON (a frame's name and SECTION id, a text
34
+ // card's words, a quote card's look, a portal's target, a list's count).
35
+ `CREATE TABLE layout_nodes (
36
+ canvas_id TEXT NOT NULL,
37
+ node_id TEXT NOT NULL,
38
+ kind TEXT NOT NULL,
39
+ note_id TEXT,
40
+ x REAL NOT NULL,
41
+ y REAL NOT NULL,
42
+ w REAL,
43
+ h REAL,
44
+ data TEXT NOT NULL,
45
+ PRIMARY KEY (canvas_id, node_id)
46
+ ) WITHOUT ROWID`,
47
+ `CREATE TABLE layout_edges (
48
+ canvas_id TEXT NOT NULL,
49
+ source TEXT NOT NULL,
50
+ target TEXT NOT NULL,
51
+ arrow_start INTEGER,
52
+ arrow_end INTEGER,
53
+ line_style TEXT
54
+ )`,
55
+ `CREATE INDEX layout_edges_by_canvas ON layout_edges (canvas_id)`,
32
56
  `CREATE TABLE members (user_id TEXT PRIMARY KEY, name TEXT)`,
33
57
  `CREATE TABLE dimensions (
34
58
  type TEXT NOT NULL,
@@ -170,7 +170,11 @@ server.tool("cnotes_query", "Ask a workspace-wide question over every note's met
170
170
  limit: z.number().int().min(1).max(2000).optional().describe("Rows to return (default 100)"),
171
171
  sql: z.string().optional().describe("One read-only SELECT against the copy instead of a filter; 'tables' lists the tables"),
172
172
  rebuild: z.boolean().optional().describe("Drop the local copy and copy the workspace again"),
173
- }, async ({ text, types, canvases, tags, madeBy, by, groupBy, limit, sql, rebuild }) => withErrorHandling(async () => {
173
+ },
174
+ // The copy is the person's decision: when it is off the call fails with the
175
+ // command they run to allow it, and the agent relays that rather than
176
+ // working around it.
177
+ async ({ text, types, canvases, tags, madeBy, by, groupBy, limit, sql, rebuild }) => withErrorHandling(async () => {
174
178
  const answer = await runQuery(api, workspaceId, text ? [text] : [], {
175
179
  type: types?.join(","),
176
180
  canvas: canvases?.join(","),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.113.0",
3
+ "version": "0.113.2",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,7 +32,12 @@ cnotes query --sql tables # the tables and their colu
32
32
  `--json` returns `{ total, groups, rows, sync, ms }`; rows carry `displayId`,
33
33
  `title`, `type`, `updatedAt` and the group they fell in. `--sql` runs ONE
34
34
  read-only SELECT (a write is refused). `--rebuild` drops the copy and copies
35
- again. Needs Node.js 22.13 or newer.
35
+ again; `--forget` deletes this workspace's copy. Needs Node.js 22.13 or newer.
36
+
37
+ The copy is off until the PERSON allows it: `cnotes config set-local-db on`.
38
+ If `cnotes query` refuses with that hint, tell the user what the copy holds
39
+ (metadata, never a body) and ask them to run it; do not work around it with
40
+ `notes list`. `set-local-db off` deletes every copy on the machine.
36
41
 
37
42
  ## Focus plans (`cnotes focus`)
38
43
 
@@ -143,6 +148,8 @@ cnotes theme reset
143
148
  ```bash
144
149
  cnotes config get-server
145
150
  cnotes config set-server <url>
151
+ cnotes config get-local-db # on | off: may this machine keep a copy of workspace note metadata?
152
+ cnotes config set-local-db on|off # off deletes every copy under ~/.cnotes/local-db
146
153
  ```
147
154
 
148
155
  ## Feedback (`cnotes feedback`)