@creator-notes/cnotes 0.113.2 → 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/README.md
CHANGED
|
@@ -330,7 +330,7 @@ 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
|
|
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();
|
|
@@ -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\`
|
|
@@ -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/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
|