@creator-notes/cnotes 0.113.1 → 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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +3 -0
- package/dist/commands/config.js +46 -1
- package/dist/commands/query.js +18 -3
- package/dist/lib/auth-store.js +16 -0
- package/dist/lib/local-db-store.js +21 -1
- package/dist/mcp-server.js +5 -1
- package/package.json +1 -1
- package/skills/cnotes/references/more-commands.md +8 -1
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
|
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 = {
|
|
@@ -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,
|
|
154
|
-
|
|
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);
|
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() {
|
|
@@ -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);
|
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
|
@@ -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`)
|