@creator-notes/cnotes 0.113.1 → 0.113.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +4 -1
- package/dist/commands/config.js +46 -1
- package/dist/commands/query.js +30 -12
- package/dist/lib/auth-store.js +16 -0
- package/dist/lib/local-db-store.js +26 -2
- package/dist/mcp-server.js +5 -1
- package/package.json +1 -1
- package/skills/cnotes/references/more-commands.md +12 -4
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
|
|
@@ -329,7 +330,9 @@ cp $(npm root -g)/@creator-notes/cnotes/skills/cnotes/SKILL.md .claude/skills/cn
|
|
|
329
330
|
|
|
330
331
|
## Query the local copy (`cnotes query`)
|
|
331
332
|
|
|
332
|
-
`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
|
+
`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. The query itself runs in milliseconds; each call first reads the workspace head and what changed, a second or two on a 5,000-note workspace, and the first copy takes about a minute at that size. The web app's Query panel uses the same copy format, so the two never disagree.
|
|
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.
|
|
333
336
|
|
|
334
337
|
```bash
|
|
335
338
|
cnotes query pricing --type Decision,Insight # words in the title, AND across fields
|
package/dist/commands/config.js
CHANGED
|
@@ -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
|
}
|
package/dist/commands/query.js
CHANGED
|
@@ -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 = {
|
|
@@ -83,7 +83,7 @@ export function parseGroupBy(value, head) {
|
|
|
83
83
|
throw new ValidationError(`Unknown --group-by "${value}".`, `One of: ${choices.join(", ")}.`);
|
|
84
84
|
}
|
|
85
85
|
/** The JSON shape `--json` prints. */
|
|
86
|
-
export function toJsonResult(result, head, status) {
|
|
86
|
+
export function toJsonResult(result, head, status, firstCopy) {
|
|
87
87
|
const canvasNames = new Map(head.canvases.map((c) => [c.id, c.displayId ?? c.name]));
|
|
88
88
|
return {
|
|
89
89
|
total: result.total,
|
|
@@ -98,16 +98,17 @@ export function toJsonResult(result, head, status) {
|
|
|
98
98
|
})),
|
|
99
99
|
shown: result.rows.length,
|
|
100
100
|
ms: Math.round(result.ms * 10) / 10,
|
|
101
|
-
sync: syncSummary(status),
|
|
101
|
+
sync: syncSummary(status, firstCopy),
|
|
102
102
|
canvases: Object.fromEntries(canvasNames),
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
/** What this call's sync did: how much the copy holds, whether it was made from nothing, and how long the pass took. */
|
|
106
|
+
export function syncSummary(status, firstCopy) {
|
|
106
107
|
return {
|
|
107
108
|
notes: status.counts.notes,
|
|
108
109
|
canvases: status.counts.canvases,
|
|
109
110
|
bytes: status.counts.bytes,
|
|
110
|
-
firstCopy
|
|
111
|
+
firstCopy,
|
|
111
112
|
ms: status.lastPassMs == null ? null : Math.round(status.lastPassMs),
|
|
112
113
|
};
|
|
113
114
|
}
|
|
@@ -150,19 +151,22 @@ export function renderSql(out) {
|
|
|
150
151
|
}
|
|
151
152
|
const SQL_MAX_ROWS = 500;
|
|
152
153
|
/** Everything `cnotes query` and the MCP tool share: sync, ask, shape the answer. */
|
|
153
|
-
export async function runQuery(api, workspaceId, words, opts,
|
|
154
|
-
|
|
154
|
+
export async function runQuery(api, workspaceId, words, opts, run = {}) {
|
|
155
|
+
if (opts.forget) {
|
|
156
|
+
return { kind: "forgot", files: forgetLocalCopies(workspaceId, run.directory) };
|
|
157
|
+
}
|
|
158
|
+
const opened = await openLocalCopy({ api, workspaceId, rebuild: opts.rebuild, directory: run.directory, enabled: run.enabled });
|
|
155
159
|
try {
|
|
156
160
|
if (opts.sql !== undefined) {
|
|
157
161
|
if (opts.sql.trim().toLowerCase() === "tables") {
|
|
158
|
-
return { kind: "tables", tables: SCHEMA_HINT, sync: syncSummary(opened.status) };
|
|
162
|
+
return { kind: "tables", tables: SCHEMA_HINT, sync: syncSummary(opened.status, opened.store.fresh) };
|
|
159
163
|
}
|
|
160
164
|
const out = opened.store.db.sql({ sql: opts.sql, maxRows: SQL_MAX_ROWS });
|
|
161
|
-
return { kind: "sql", ...out, sync: syncSummary(opened.status) };
|
|
165
|
+
return { kind: "sql", ...out, sync: syncSummary(opened.status, opened.store.fresh) };
|
|
162
166
|
}
|
|
163
167
|
const { filter, groupBy, limit } = parseQuery(words, opts, opened.head);
|
|
164
168
|
const result = opened.store.db.query({ filter, groupBy, limit });
|
|
165
|
-
return { kind: "notes", result, groupBy, json: toJsonResult(result, opened.head, opened.status) };
|
|
169
|
+
return { kind: "notes", result, groupBy, json: toJsonResult(result, opened.head, opened.status, opened.store.fresh) };
|
|
166
170
|
}
|
|
167
171
|
finally {
|
|
168
172
|
opened.store.close();
|
|
@@ -183,10 +187,17 @@ export function registerQueryCommands(program) {
|
|
|
183
187
|
.option("--limit <n>", "Rows to return (default 100)")
|
|
184
188
|
.option("--sql <select>", "Run one read-only SELECT against the copy; `tables` lists the tables")
|
|
185
189
|
.option("--rebuild", "Drop this workspace's copy and copy it again")
|
|
190
|
+
.option("--forget", "Delete this workspace's copy from this machine and stop")
|
|
186
191
|
.addHelpText("after", `
|
|
187
192
|
The copy holds every note's metadata (title, type, tags, canvases, who made it,
|
|
188
|
-
judged answers), never a note body. The first call copies the workspace
|
|
189
|
-
calls
|
|
193
|
+
judged answers), never a note body. The first call copies the workspace (about
|
|
194
|
+
a minute for 5,000 notes); later calls read the workspace head and what changed
|
|
195
|
+
(a second or two on a workspace that size), then the query itself runs in
|
|
196
|
+
milliseconds.
|
|
197
|
+
|
|
198
|
+
A copy on this machine is the person's decision: it is off until
|
|
199
|
+
\`cnotes config set-local-db on\` (or CNOTES_LOCAL_DB=on). \`set-local-db off\`
|
|
200
|
+
deletes every copy; --forget deletes this workspace's.
|
|
190
201
|
|
|
191
202
|
Examples:
|
|
192
203
|
$ cnotes query pricing --type Decision,Insight
|
|
@@ -201,6 +212,13 @@ Examples:
|
|
|
201
212
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
202
213
|
try {
|
|
203
214
|
const answer = await runQuery(api, cfg.workspaceId, words, opts);
|
|
215
|
+
if (answer.kind === "forgot") {
|
|
216
|
+
if (cfg.json)
|
|
217
|
+
outputJson({ forgot: answer.files }, cfg.fields);
|
|
218
|
+
else
|
|
219
|
+
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"}).`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
204
222
|
if (answer.kind === "tables") {
|
|
205
223
|
if (cfg.json)
|
|
206
224
|
outputJson({ tables: answer.tables, sync: answer.sync }, cfg.fields);
|
package/dist/lib/auth-store.js
CHANGED
|
@@ -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() {
|
|
@@ -93,6 +97,8 @@ export class LocalCopyStore {
|
|
|
93
97
|
handle = null;
|
|
94
98
|
ops = null;
|
|
95
99
|
openPath = null;
|
|
100
|
+
/** True when the last open created the tables, so this call copied the workspace from nothing. */
|
|
101
|
+
fresh = false;
|
|
96
102
|
constructor(Database, directory) {
|
|
97
103
|
this.Database = Database;
|
|
98
104
|
this.directory = directory;
|
|
@@ -126,7 +132,9 @@ export class LocalCopyStore {
|
|
|
126
132
|
this.openPath = path;
|
|
127
133
|
const db = wrap(this.handle);
|
|
128
134
|
this.ops = createLocalDbOps(db);
|
|
129
|
-
|
|
135
|
+
const opened = openCopy(db, true);
|
|
136
|
+
this.fresh = opened.fresh;
|
|
137
|
+
return opened;
|
|
130
138
|
}
|
|
131
139
|
case "forget": {
|
|
132
140
|
const { workspaceId } = args;
|
|
@@ -176,7 +184,23 @@ export function fetchSyncHead(api, workspaceId) {
|
|
|
176
184
|
// ---------------------------------------------------------------------------
|
|
177
185
|
/** Inside this window a call pulls only what changed; past it, every note id is compared again. */
|
|
178
186
|
export const RECONCILE_EVERY_MS = 60 * 60 * 1000;
|
|
187
|
+
/** Delete the copies on disk: one workspace's, or every workspace's when `workspaceId` is null. Returns how many files went. */
|
|
188
|
+
export function forgetLocalCopies(workspaceId, directory = localDbDirectory()) {
|
|
189
|
+
if (!existsSync(directory))
|
|
190
|
+
return 0;
|
|
191
|
+
const prefix = workspaceId ? workspaceFilePrefix(workspaceId).replace(/^\//, "") : "";
|
|
192
|
+
let removed = 0;
|
|
193
|
+
for (const name of readdirSync(directory)) {
|
|
194
|
+
if (!name.startsWith(prefix))
|
|
195
|
+
continue;
|
|
196
|
+
rmSync(join(directory, name), { force: true });
|
|
197
|
+
removed += 1;
|
|
198
|
+
}
|
|
199
|
+
return removed;
|
|
200
|
+
}
|
|
179
201
|
export async function openLocalCopy(options) {
|
|
202
|
+
if (!(options.enabled ?? isLocalDbEnabled()))
|
|
203
|
+
throw new CliError(LOCAL_DB_OFF_MESSAGE, undefined, LOCAL_DB_OFF_HINT);
|
|
180
204
|
const Database = await loadDatabase();
|
|
181
205
|
const directory = options.directory ?? localDbDirectory();
|
|
182
206
|
const store = new LocalCopyStore(Database, directory);
|
package/dist/mcp-server.js
CHANGED
|
@@ -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
|
-
},
|
|
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
|
@@ -16,9 +16,10 @@ Focus plans, files and images, setup, theme, config, and sending feedback to the
|
|
|
16
16
|
## Query the workspace (`cnotes query`)
|
|
17
17
|
|
|
18
18
|
Workspace-wide questions over every note's metadata, answered from a local
|
|
19
|
-
SQLite copy
|
|
20
|
-
|
|
21
|
-
changed
|
|
19
|
+
SQLite copy instead of paged `notes list` reads. The first call copies the
|
|
20
|
+
workspace (about a minute for 5,000 notes); later calls read the head and
|
|
21
|
+
what changed (a second or two at that size), then the query runs in
|
|
22
|
+
milliseconds. Never a note body: read those with `cnotes notes get`.
|
|
22
23
|
|
|
23
24
|
```bash
|
|
24
25
|
cnotes query pricing --type Decision,Insight # words in the title; AND across fields
|
|
@@ -32,7 +33,12 @@ cnotes query --sql tables # the tables and their colu
|
|
|
32
33
|
`--json` returns `{ total, groups, rows, sync, ms }`; rows carry `displayId`,
|
|
33
34
|
`title`, `type`, `updatedAt` and the group they fell in. `--sql` runs ONE
|
|
34
35
|
read-only SELECT (a write is refused). `--rebuild` drops the copy and copies
|
|
35
|
-
again. Needs Node.js 22.13 or newer.
|
|
36
|
+
again; `--forget` deletes this workspace's copy. Needs Node.js 22.13 or newer.
|
|
37
|
+
|
|
38
|
+
The copy is off until the PERSON allows it: `cnotes config set-local-db on`.
|
|
39
|
+
If `cnotes query` refuses with that hint, tell the user what the copy holds
|
|
40
|
+
(metadata, never a body) and ask them to run it; do not work around it with
|
|
41
|
+
`notes list`. `set-local-db off` deletes every copy on the machine.
|
|
36
42
|
|
|
37
43
|
## Focus plans (`cnotes focus`)
|
|
38
44
|
|
|
@@ -143,6 +149,8 @@ cnotes theme reset
|
|
|
143
149
|
```bash
|
|
144
150
|
cnotes config get-server
|
|
145
151
|
cnotes config set-server <url>
|
|
152
|
+
cnotes config get-local-db # on | off: may this machine keep a copy of workspace note metadata?
|
|
153
|
+
cnotes config set-local-db on|off # off deletes every copy under ~/.cnotes/local-db
|
|
146
154
|
```
|
|
147
155
|
|
|
148
156
|
## Feedback (`cnotes feedback`)
|