@creator-notes/cnotes 0.113.2 → 0.113.4
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/README.md
CHANGED
|
@@ -330,14 +330,14 @@ cp $(npm root -g)/@creator-notes/cnotes/skills/cnotes/SKILL.md .claude/skills/cn
|
|
|
330
330
|
|
|
331
331
|
## Query the local copy (`cnotes query`)
|
|
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
|
+
`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
334
|
|
|
335
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
336
|
|
|
337
337
|
```bash
|
|
338
338
|
cnotes query pricing --type Decision,Insight # words in the title, AND across fields
|
|
339
339
|
cnotes query --canvas CANVAS-12 --group-by tag # notes on one canvas, grouped by tag
|
|
340
|
-
cnotes query --made-by
|
|
340
|
+
cnotes query --made-by api --group-by month # what agents wrote through a cn_ key, by month
|
|
341
341
|
cnotes query --sql "SELECT type, COUNT(*) AS n FROM notes GROUP BY type ORDER BY n DESC"
|
|
342
342
|
cnotes query --rebuild # drop this workspace's copy and copy it again
|
|
343
343
|
```
|
package/dist/commands/query.js
CHANGED
|
@@ -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
|
}
|
|
@@ -158,14 +159,14 @@ export async function runQuery(api, workspaceId, words, opts, run = {}) {
|
|
|
158
159
|
try {
|
|
159
160
|
if (opts.sql !== undefined) {
|
|
160
161
|
if (opts.sql.trim().toLowerCase() === "tables") {
|
|
161
|
-
return { kind: "tables", tables: SCHEMA_HINT, sync: syncSummary(opened.status) };
|
|
162
|
+
return { kind: "tables", tables: SCHEMA_HINT, sync: syncSummary(opened.status, opened.store.fresh) };
|
|
162
163
|
}
|
|
163
164
|
const out = opened.store.db.sql({ sql: opts.sql, maxRows: SQL_MAX_ROWS });
|
|
164
|
-
return { kind: "sql", ...out, sync: syncSummary(opened.status) };
|
|
165
|
+
return { kind: "sql", ...out, sync: syncSummary(opened.status, opened.store.fresh) };
|
|
165
166
|
}
|
|
166
167
|
const { filter, groupBy, limit } = parseQuery(words, opts, opened.head);
|
|
167
168
|
const result = opened.store.db.query({ filter, groupBy, limit });
|
|
168
|
-
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) };
|
|
169
170
|
}
|
|
170
171
|
finally {
|
|
171
172
|
opened.store.close();
|
|
@@ -180,7 +181,7 @@ export function registerQueryCommands(program) {
|
|
|
180
181
|
.option("--type <types>", "Note types, comma-separated (Decision,Insight)")
|
|
181
182
|
.option("--canvas <refs>", "Canvases by CANVAS-<n> or name, comma-separated")
|
|
182
183
|
.option("--tag <tags>", "Tags, comma-separated")
|
|
183
|
-
.option("--made-by <sources>", "human, agent, api or import, comma-separated")
|
|
184
|
+
.option("--made-by <sources>", "human, agent, api or import, comma-separated; notes written with a cn_ key (this CLI, MCP) are api")
|
|
184
185
|
.option("--by <name>", "Notes made by a member whose name contains this")
|
|
185
186
|
.option("--group-by <field>", "type (default), canvas, tag, month, person, made-by, none, or <Type>:<dimension>")
|
|
186
187
|
.option("--limit <n>", "Rows to return (default 100)")
|
|
@@ -189,8 +190,10 @@ export function registerQueryCommands(program) {
|
|
|
189
190
|
.option("--forget", "Delete this workspace's copy from this machine and stop")
|
|
190
191
|
.addHelpText("after", `
|
|
191
192
|
The copy holds every note's metadata (title, type, tags, canvases, who made it,
|
|
192
|
-
judged answers), never a note body. The first call copies the workspace
|
|
193
|
-
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.
|
|
194
197
|
|
|
195
198
|
A copy on this machine is the person's decision: it is off until
|
|
196
199
|
\`cnotes config set-local-db on\` (or CNOTES_LOCAL_DB=on). \`set-local-db off\`
|
|
@@ -199,7 +202,7 @@ deletes every copy; --forget deletes this workspace's.
|
|
|
199
202
|
Examples:
|
|
200
203
|
$ cnotes query pricing --type Decision,Insight
|
|
201
204
|
$ cnotes query --canvas CANVAS-12 --group-by tag
|
|
202
|
-
$ cnotes query --made-by
|
|
205
|
+
$ cnotes query --made-by api --group-by month --json # what agents wrote through a key, by month
|
|
203
206
|
$ cnotes query --group-by Risk:status # the state '${UNJUDGED}' is a group too
|
|
204
207
|
$ cnotes query --sql "SELECT type, COUNT(*) AS n FROM notes GROUP BY type ORDER BY n DESC"
|
|
205
208
|
$ cnotes query --sql tables
|
|
@@ -97,6 +97,8 @@ export class LocalCopyStore {
|
|
|
97
97
|
handle = null;
|
|
98
98
|
ops = null;
|
|
99
99
|
openPath = null;
|
|
100
|
+
/** True when the last open created the tables, so this call copied the workspace from nothing. */
|
|
101
|
+
fresh = false;
|
|
100
102
|
constructor(Database, directory) {
|
|
101
103
|
this.Database = Database;
|
|
102
104
|
this.directory = directory;
|
|
@@ -130,7 +132,9 @@ export class LocalCopyStore {
|
|
|
130
132
|
this.openPath = path;
|
|
131
133
|
const db = wrap(this.handle);
|
|
132
134
|
this.ops = createLocalDbOps(db);
|
|
133
|
-
|
|
135
|
+
const opened = openCopy(db, true);
|
|
136
|
+
this.fresh = opened.fresh;
|
|
137
|
+
return opened;
|
|
134
138
|
}
|
|
135
139
|
case "forget": {
|
|
136
140
|
const { workspaceId } = args;
|
package/dist/mcp-server.js
CHANGED
|
@@ -161,7 +161,7 @@ server.tool("cnotes_query", "Ask a workspace-wide question over every note's met
|
|
|
161
161
|
types: z.array(z.string()).optional().describe("Note types, e.g. ['Decision','Insight']"),
|
|
162
162
|
canvases: z.array(z.string()).optional().describe("Canvases by CANVAS-<n> display id or name"),
|
|
163
163
|
tags: z.array(z.string()).optional(),
|
|
164
|
-
madeBy: z.array(z.enum(["human", "agent", "api", "import"])).optional().describe("How the notes were made"),
|
|
164
|
+
madeBy: z.array(z.enum(["human", "agent", "api", "import"])).optional().describe("How the notes were made; notes written with a cn_ key (the CLI, this MCP server) are api"),
|
|
165
165
|
by: z.string().optional().describe("A member whose name contains this"),
|
|
166
166
|
groupBy: z
|
|
167
167
|
.string()
|
package/package.json
CHANGED
|
@@ -16,14 +16,15 @@ 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
|
|
25
26
|
cnotes query --canvas CANVAS-12 --group-by tag # notes on one canvas, by tag
|
|
26
|
-
cnotes query --made-by
|
|
27
|
+
cnotes query --made-by api --group-by month --json # notes written with a cn_ key (CLI, MCP) are api
|
|
27
28
|
cnotes query --group-by Risk:status # a judged dimension; `unjudged` is a group
|
|
28
29
|
cnotes query --sql "SELECT type, COUNT(*) AS n FROM notes GROUP BY type ORDER BY n DESC"
|
|
29
30
|
cnotes query --sql tables # the tables and their columns
|