quilltap 4.15.0-dev.2 → 4.16.0-dev.7
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 +26 -13
- package/bin/quilltap.js +88 -110
- package/lib/__tests__/docs-write-base64.test.js +155 -0
- package/lib/__tests__/file-verify-platform.test.js +31 -0
- package/lib/__tests__/find-mount-by-former-name.test.js +60 -0
- package/lib/__tests__/instances-default-json.test.js +18 -0
- package/lib/__tests__/logs-tail-flag.test.js +30 -0
- package/lib/__tests__/maintenance-orphan-sweep.test.js +84 -0
- package/lib/__tests__/migrations-source-ids.test.js +15 -1
- package/lib/db-commands.js +4 -4
- package/lib/db-helpers.js +31 -2
- package/lib/docs-commands.js +45 -11
- package/lib/file-verify-commands.js +20 -3
- package/lib/instances-commands.js +6 -2
- package/lib/instances.js +5 -0
- package/lib/lock-helpers.js +319 -120
- package/lib/logs-commands.js +14 -2
- package/lib/maintenance-commands.js +35 -6
- package/lib/migrations-commands.js +4 -83
- package/lib/migrations-source.js +109 -0
- package/lib/migrations.generated.js +1055 -0
- package/lib/sync-command.js +7 -0
- package/lib/theme-engine.generated.js +47 -47
- package/package.json +3 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI looks a document store up by name in SQL, so it mirrors the last
|
|
3
|
+
* step of the server's `matchStoreRef` itself: a store still answers to a name
|
|
4
|
+
* it used to carry (`doc_mount_points.formerNames`), so a script written
|
|
5
|
+
* before a rename keeps working. Never a guess: two claimants match neither,
|
|
6
|
+
* and a database from before the column existed has no former names.
|
|
7
|
+
*
|
|
8
|
+
* @jest-environment node
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
// The real driver: `better-sqlite3` is auto-mocked for unit tests.
|
|
16
|
+
const Database = require(path.join(process.cwd(), 'node_modules', 'better-sqlite3'));
|
|
17
|
+
const { findMountByFormerName } = require('../db-helpers');
|
|
18
|
+
|
|
19
|
+
let db;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
db = new Database(':memory:');
|
|
23
|
+
db.exec(`CREATE TABLE doc_mount_points (id TEXT PRIMARY KEY, name TEXT NOT NULL, formerNames TEXT NOT NULL DEFAULT '[]')`);
|
|
24
|
+
});
|
|
25
|
+
afterEach(() => db.close());
|
|
26
|
+
|
|
27
|
+
const insert = (id, name, formerNames) =>
|
|
28
|
+
db.prepare('INSERT INTO doc_mount_points (id, name, formerNames) VALUES (?, ?, ?)').run(id, name, formerNames);
|
|
29
|
+
|
|
30
|
+
it('finds the store that used to carry the name, ignoring case and surrounding space', () => {
|
|
31
|
+
insert('a', 'Novel', JSON.stringify(['Novel Drafts']));
|
|
32
|
+
insert('b', 'Lore', '[]');
|
|
33
|
+
expect(findMountByFormerName(db, ' novel drafts ')).toMatchObject({ id: 'a', name: 'Novel' });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('finds nothing for a name no store used to carry', () => {
|
|
37
|
+
insert('a', 'Novel', JSON.stringify(['Novel Drafts']));
|
|
38
|
+
expect(findMountByFormerName(db, 'Lore')).toBeNull();
|
|
39
|
+
expect(findMountByFormerName(db, '')).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('matches neither store when two claim one former name', () => {
|
|
43
|
+
insert('a', 'One', JSON.stringify(['Shared']));
|
|
44
|
+
insert('b', 'Two', JSON.stringify(['shared']));
|
|
45
|
+
expect(findMountByFormerName(db, 'Shared')).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('reads a malformed column as no former names', () => {
|
|
49
|
+
insert('a', 'Novel', 'not json');
|
|
50
|
+
insert('b', 'Lore', JSON.stringify({ not: 'an array' }));
|
|
51
|
+
expect(findMountByFormerName(db, 'Novel Drafts')).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('finds nothing in a database from before stores kept their former names', () => {
|
|
55
|
+
const old = new Database(':memory:');
|
|
56
|
+
old.exec('CREATE TABLE doc_mount_points (id TEXT PRIMARY KEY, name TEXT NOT NULL)');
|
|
57
|
+
old.prepare('INSERT INTO doc_mount_points (id, name) VALUES (?, ?)').run('a', 'Novel');
|
|
58
|
+
expect(findMountByFormerName(old, 'Novel Drafts')).toBeNull();
|
|
59
|
+
old.close();
|
|
60
|
+
});
|
|
@@ -84,6 +84,24 @@ describe('instances default --json', () => {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
describe('instances remove', () => {
|
|
88
|
+
it('clears the default when the default instance is removed (issue #360)', () => {
|
|
89
|
+
addInstance('Friday');
|
|
90
|
+
addInstance('Ignite');
|
|
91
|
+
run('default', 'Friday');
|
|
92
|
+
expect(run('remove', 'Friday')).toMatch(/default is now cleared/);
|
|
93
|
+
expect(run('default')).toBe('(none)');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('keeps the default when another instance is removed', () => {
|
|
97
|
+
addInstance('Friday');
|
|
98
|
+
addInstance('Ignite');
|
|
99
|
+
run('default', 'Friday');
|
|
100
|
+
expect(run('remove', 'Ignite')).not.toMatch(/default is now cleared/);
|
|
101
|
+
expect(run('default')).toBe('Friday');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
87
105
|
describe('instances list --json', () => {
|
|
88
106
|
it('emits the registry as an array', () => {
|
|
89
107
|
expect(JSON.parse(run('list', '--json'))).toEqual([]);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quilltap logs --tail 0` means the whole file (issue #361).
|
|
3
|
+
*
|
|
4
|
+
* The flag was parsed as `parseInt(value, 10) || 100`, and 0 is falsy, so the
|
|
5
|
+
* documented "0 = full file" became the default of 100 lines.
|
|
6
|
+
*
|
|
7
|
+
* @jest-environment node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const { parseFlags } = require('../logs-commands');
|
|
13
|
+
|
|
14
|
+
describe('logs --tail', () => {
|
|
15
|
+
it('defaults to 100 lines', () => {
|
|
16
|
+
expect(parseFlags([]).tail).toBe(100);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('keeps 0, which means the whole file', () => {
|
|
20
|
+
expect(parseFlags(['--tail', '0']).tail).toBe(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('takes a positive count', () => {
|
|
24
|
+
expect(parseFlags(['--tail', '250']).tail).toBe(250);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each(['abc', '-5', ''])('falls back to 100 for %p', (value) => {
|
|
28
|
+
expect(parseFlags(['--tail', value]).tail).toBe(100);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quilltap maintenance run`, step 3: the orphaned mount-index file sweep.
|
|
3
|
+
*
|
|
4
|
+
* A mount index whose tables came from the schema translator carries no
|
|
5
|
+
* foreign keys, so deleting a `doc_mount_files` row cascades to nothing. The
|
|
6
|
+
* sweep therefore deletes an orphan's document and blob payload itself, as the
|
|
7
|
+
* server's `gcOrphanedFileRow` does. A bare `DELETE FROM doc_mount_files`
|
|
8
|
+
* (what this step used to run) left that payload behind for good.
|
|
9
|
+
*
|
|
10
|
+
* @jest-environment node
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const path = require('path');
|
|
16
|
+
// The real driver, by absolute path: jest maps the bare specifier to a mock.
|
|
17
|
+
const Database = require(path.join(process.cwd(), 'node_modules', 'better-sqlite3'));
|
|
18
|
+
const { sweepOrphanedMountFiles } = require('../maintenance-commands');
|
|
19
|
+
|
|
20
|
+
// The tables as the schema translator creates them: no REFERENCES anywhere.
|
|
21
|
+
function createIndex({ withDocuments = true, withBlobs = true } = {}) {
|
|
22
|
+
const db = new Database(':memory:');
|
|
23
|
+
db.exec('CREATE TABLE doc_mount_files (id TEXT PRIMARY KEY, sha256 TEXT)');
|
|
24
|
+
db.exec('CREATE TABLE doc_mount_file_links (id TEXT PRIMARY KEY, fileId TEXT, mountPointId TEXT)');
|
|
25
|
+
if (withDocuments) db.exec('CREATE TABLE doc_mount_documents (id TEXT PRIMARY KEY, fileId TEXT, content TEXT)');
|
|
26
|
+
if (withBlobs) db.exec('CREATE TABLE doc_mount_blobs (id TEXT PRIMARY KEY, fileId TEXT, data BLOB)');
|
|
27
|
+
return db;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ids = (db, table, column = 'id') =>
|
|
31
|
+
db.prepare(`SELECT ${column} AS v FROM ${table} ORDER BY v`).all().map((row) => row.v);
|
|
32
|
+
|
|
33
|
+
describe('sweepOrphanedMountFiles', () => {
|
|
34
|
+
it('deletes an orphaned file row together with its document and blob payload', () => {
|
|
35
|
+
const db = createIndex();
|
|
36
|
+
db.exec(`
|
|
37
|
+
INSERT INTO doc_mount_files VALUES ('linked', 'a'), ('orphan-doc', 'b'), ('orphan-blob', 'c');
|
|
38
|
+
INSERT INTO doc_mount_file_links VALUES ('link-1', 'linked', 'mp-1');
|
|
39
|
+
INSERT INTO doc_mount_documents VALUES ('d-linked', 'linked', 'kept'), ('d-orphan', 'orphan-doc', 'gone');
|
|
40
|
+
INSERT INTO doc_mount_blobs VALUES ('b-linked', 'linked', x'01'), ('b-orphan', 'orphan-blob', x'02');
|
|
41
|
+
`);
|
|
42
|
+
|
|
43
|
+
expect(sweepOrphanedMountFiles(db)).toBe(2);
|
|
44
|
+
|
|
45
|
+
expect(ids(db, 'doc_mount_files')).toEqual(['linked']);
|
|
46
|
+
expect(ids(db, 'doc_mount_documents')).toEqual(['d-linked']);
|
|
47
|
+
expect(ids(db, 'doc_mount_blobs')).toEqual(['b-linked']);
|
|
48
|
+
expect(ids(db, 'doc_mount_file_links')).toEqual(['link-1']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('leaves content alone while any link, in any store, still references it', () => {
|
|
52
|
+
const db = createIndex();
|
|
53
|
+
db.exec(`
|
|
54
|
+
INSERT INTO doc_mount_files VALUES ('shared', 'a');
|
|
55
|
+
INSERT INTO doc_mount_file_links VALUES ('link-1', 'shared', 'mp-1'), ('link-2', 'shared', 'mp-2');
|
|
56
|
+
INSERT INTO doc_mount_documents VALUES ('d-shared', 'shared', 'kept');
|
|
57
|
+
`);
|
|
58
|
+
|
|
59
|
+
expect(sweepOrphanedMountFiles(db)).toBe(0);
|
|
60
|
+
expect(ids(db, 'doc_mount_files')).toEqual(['shared']);
|
|
61
|
+
expect(ids(db, 'doc_mount_documents')).toEqual(['d-shared']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('copes with an index that never created a payload table', () => {
|
|
65
|
+
// Both payload tables are minted lazily; a document-only index has no
|
|
66
|
+
// `doc_mount_blobs`, and deleting from a missing table would throw.
|
|
67
|
+
const db = createIndex({ withBlobs: false });
|
|
68
|
+
db.exec(`
|
|
69
|
+
INSERT INTO doc_mount_files VALUES ('orphan', 'a');
|
|
70
|
+
INSERT INTO doc_mount_documents VALUES ('d-orphan', 'orphan', 'gone');
|
|
71
|
+
`);
|
|
72
|
+
|
|
73
|
+
expect(sweepOrphanedMountFiles(db)).toBe(1);
|
|
74
|
+
expect(ids(db, 'doc_mount_documents')).toEqual([]);
|
|
75
|
+
|
|
76
|
+
const bare = createIndex({ withDocuments: false, withBlobs: false });
|
|
77
|
+
bare.exec("INSERT INTO doc_mount_files VALUES ('orphan', 'a')");
|
|
78
|
+
expect(sweepOrphanedMountFiles(bare)).toBe(1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('does nothing on a database with no mount-index tables', () => {
|
|
82
|
+
expect(sweepOrphanedMountFiles(new Database(':memory:'))).toBe(0);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
|
|
16
|
-
const { extractMigrationId } = require('../migrations-
|
|
16
|
+
const { extractMigrationId, extractMigrationsFromSource, loadMigrationList } = require('../migrations-source');
|
|
17
17
|
|
|
18
18
|
describe('extractMigrationId', () => {
|
|
19
19
|
it('reads a string-literal id', () => {
|
|
@@ -52,3 +52,17 @@ describe('every migration script yields an id', () => {
|
|
|
52
52
|
expect(missing).toEqual([]);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
describe('the migration list an npm-installed CLI reads (issue #362)', () => {
|
|
57
|
+
const scriptsDir = path.join(__dirname, '..', '..', '..', '..', 'migrations', 'scripts');
|
|
58
|
+
|
|
59
|
+
it('ships a generated list that matches the source', () => {
|
|
60
|
+
expect(require('../migrations.generated.js')).toEqual(extractMigrationsFromSource(scriptsDir));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('falls back to the generated list when there is no source folder', () => {
|
|
64
|
+
const list = loadMigrationList(path.join(__dirname, 'no-such-folder'));
|
|
65
|
+
expect(list).toBe(require('../migrations.generated.js'));
|
|
66
|
+
expect(list.length).toBeGreaterThan(100);
|
|
67
|
+
});
|
|
68
|
+
});
|
package/lib/db-commands.js
CHANGED
|
@@ -15,7 +15,7 @@ const {
|
|
|
15
15
|
resolveChat,
|
|
16
16
|
resolveProject,
|
|
17
17
|
} = require('./db-helpers');
|
|
18
|
-
const { getLockStatus } = require('./lock-helpers');
|
|
18
|
+
const { getLockStatus, HEARTBEAT_FRESH_MS } = require('./lock-helpers');
|
|
19
19
|
const { decodeText } = require('./text-codec');
|
|
20
20
|
|
|
21
21
|
// Tables grouped by domain for `db schema` (with-no-arg) overview, and for
|
|
@@ -1398,9 +1398,9 @@ function cmdOptimize(args, ctx) {
|
|
|
1398
1398
|
? `Database is currently in use — ${lockStatus.reason}.\n` +
|
|
1399
1399
|
`Stop the running Quilltap instance before optimizing, then try again.\n` +
|
|
1400
1400
|
`(See \`quilltap db --lock-status\` for details.)`
|
|
1401
|
-
: `
|
|
1402
|
-
`
|
|
1403
|
-
|
|
1401
|
+
: `Database lock looks suspect — ${lockStatus.reason}.\n` +
|
|
1402
|
+
`Its PID may have been reused since a crash. The lock is claimed automatically once its\n` +
|
|
1403
|
+
`heartbeat is ${Math.round(HEARTBEAT_FRESH_MS / 60000)} minutes old; try again then. (See \`quilltap db --lock-status\` for details.)`;
|
|
1404
1404
|
const err = new Error(msg);
|
|
1405
1405
|
err.locked = true;
|
|
1406
1406
|
throw err;
|
package/lib/db-helpers.js
CHANGED
|
@@ -31,8 +31,9 @@ function resolveDataDir(overrideDir) {
|
|
|
31
31
|
// Precedence order (highest to lowest):
|
|
32
32
|
// 1. --data-dir (explicit override)
|
|
33
33
|
// 2. --instance (explicit instance)
|
|
34
|
-
// 3.
|
|
35
|
-
//
|
|
34
|
+
// 3. QUILLTAP_DATA_DIR env var (an Ariel terminal sets it, so a bare
|
|
35
|
+
// `quilltap` there addresses the instance the terminal belongs to)
|
|
36
|
+
// 4. registered default instance
|
|
36
37
|
// 5. OS platform default
|
|
37
38
|
//
|
|
38
39
|
// Returns `usedPlatformDefault: true` only when falling back to the true
|
|
@@ -369,7 +370,35 @@ function resolveProject(db, query) {
|
|
|
369
370
|
return fuzzy[0];
|
|
370
371
|
}
|
|
371
372
|
|
|
373
|
+
/**
|
|
374
|
+
* The one document store that used to carry `spec` as its name, or null. A
|
|
375
|
+
* store keeps its former names (`doc_mount_points.formerNames`, JSON) so an
|
|
376
|
+
* address written before a rename still reaches it; this mirrors the last step
|
|
377
|
+
* of the server's `matchStoreRef`. Callers try the current name and the UUID
|
|
378
|
+
* first, since the holder of a name always wins it. Two stores claiming one
|
|
379
|
+
* former name match neither. A database from before the column existed has no
|
|
380
|
+
* former names.
|
|
381
|
+
*/
|
|
382
|
+
function findMountByFormerName(db, spec) {
|
|
383
|
+
const hasColumn = db
|
|
384
|
+
.prepare("SELECT 1 FROM pragma_table_info('doc_mount_points') WHERE name = 'formerNames'")
|
|
385
|
+
.get();
|
|
386
|
+
if (!hasColumn) return null;
|
|
387
|
+
const needle = String(spec).trim().toLowerCase();
|
|
388
|
+
if (!needle) return null;
|
|
389
|
+
const holders = db.prepare('SELECT * FROM doc_mount_points').all().filter((row) => {
|
|
390
|
+
try {
|
|
391
|
+
const former = JSON.parse(row.formerNames || '[]');
|
|
392
|
+
return Array.isArray(former) && former.some((name) => String(name).trim().toLowerCase() === needle);
|
|
393
|
+
} catch {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
return holders.length === 1 ? holders[0] : null;
|
|
398
|
+
}
|
|
399
|
+
|
|
372
400
|
module.exports = {
|
|
401
|
+
findMountByFormerName,
|
|
373
402
|
resolveDataDir,
|
|
374
403
|
resolveDataDirAndPassphrase,
|
|
375
404
|
printDefaultInstanceHint,
|
package/lib/docs-commands.js
CHANGED
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
printDefaultInstanceHint,
|
|
9
9
|
loadDbKey,
|
|
10
10
|
openMountIndexDb,
|
|
11
|
+
findMountByFormerName,
|
|
11
12
|
} = require('./db-helpers');
|
|
12
13
|
const { isQtapUri, parseQtapUri, formatDocStoreUri } = require('./qtap-uri');
|
|
13
14
|
|
|
@@ -22,6 +23,14 @@ const CYAN = '\x1b[36m';
|
|
|
22
23
|
const TEXT_FILE_TYPES = new Set(['markdown', 'txt', 'json', 'jsonl']);
|
|
23
24
|
const BINARY_FILE_TYPES = new Set(['pdf', 'docx', 'blob']);
|
|
24
25
|
|
|
26
|
+
// Where a link's bytes live, as the server's link projection reports it: a link
|
|
27
|
+
// in a database-backed store reads from the database whatever its content row
|
|
28
|
+
// says. A content row is shared by every link to the same bytes, and one
|
|
29
|
+
// written before 4.16 can say `filesystem` under a database store's link
|
|
30
|
+
// (#398), so `f.source` alone is not to be trusted.
|
|
31
|
+
const LINK_SOURCE_SQL = `(CASE WHEN (SELECT mp.mountType FROM doc_mount_points mp WHERE mp.id = l.mountPointId) = 'database'
|
|
32
|
+
THEN 'database' ELSE f.source END) AS source`;
|
|
33
|
+
|
|
25
34
|
// Single-character markers for the `ls` "text" column:
|
|
26
35
|
// = raw bytes are already textual (markdown/txt/json/jsonl)
|
|
27
36
|
// T separately-extracted plaintext is stored on the link row
|
|
@@ -93,7 +102,8 @@ Write subcommands (server required for database-backed mounts):
|
|
|
93
102
|
mvdir <mount> <fromPath> <toPath> Rename/move a folder (server-required)
|
|
94
103
|
|
|
95
104
|
<mount> may be a mount name or UUID. Names are case-insensitive; ambiguous
|
|
96
|
-
names print candidates and exit non-zero.
|
|
105
|
+
names print candidates and exit non-zero. A renamed store still answers to a
|
|
106
|
+
name it used to carry, until another store takes that name.
|
|
97
107
|
|
|
98
108
|
Addressing with qtap:// URIs: anywhere a <mount> <relativePath> pair is taken,
|
|
99
109
|
you may instead pass a single qtap:// URI in its place — e.g.
|
|
@@ -399,6 +409,12 @@ function requireMount(db, spec) {
|
|
|
399
409
|
ORDER BY name COLLATE NOCASE`
|
|
400
410
|
).all(spec);
|
|
401
411
|
if (rows.length === 0) {
|
|
412
|
+
// No store holds the name now; one may have carried it before a rename.
|
|
413
|
+
const renamed = findMountByFormerName(db, spec);
|
|
414
|
+
if (renamed) {
|
|
415
|
+
console.error(`Note: "${spec}" is a former name of "${renamed.name}".`);
|
|
416
|
+
return renamed;
|
|
417
|
+
}
|
|
402
418
|
console.error(`No mount point found with name "${spec}"`);
|
|
403
419
|
process.exit(1);
|
|
404
420
|
}
|
|
@@ -657,7 +673,7 @@ async function handleFiles(flags, id) {
|
|
|
657
673
|
if (flags.folder) {
|
|
658
674
|
const prefix = flags.folder.replace(/\/+$/, '') + '/';
|
|
659
675
|
rows = db.prepare(`
|
|
660
|
-
SELECT l.relativePath, f.fileType,
|
|
676
|
+
SELECT l.relativePath, f.fileType, ${LINK_SOURCE_SQL}, f.fileSizeBytes,
|
|
661
677
|
l.chunkCount, l.conversionStatus
|
|
662
678
|
FROM doc_mount_file_links l
|
|
663
679
|
JOIN doc_mount_files f ON f.id = l.fileId
|
|
@@ -666,7 +682,7 @@ async function handleFiles(flags, id) {
|
|
|
666
682
|
`).all(mount.id, prefix + '%');
|
|
667
683
|
} else {
|
|
668
684
|
rows = db.prepare(`
|
|
669
|
-
SELECT l.relativePath, f.fileType,
|
|
685
|
+
SELECT l.relativePath, f.fileType, ${LINK_SOURCE_SQL}, f.fileSizeBytes,
|
|
670
686
|
l.chunkCount, l.conversionStatus
|
|
671
687
|
FROM doc_mount_file_links l
|
|
672
688
|
JOIN doc_mount_files f ON f.id = l.fileId
|
|
@@ -753,7 +769,7 @@ function lsFileColumns(db) {
|
|
|
753
769
|
${linkGroupId} AS linkGroupId,
|
|
754
770
|
l.id AS linkId, l.fileId, l.relativePath, l.fileName, l.lastModified,
|
|
755
771
|
l.extractionStatus, l.extractedTextSha256, l.chunkCount,
|
|
756
|
-
f.fileType, f.fileSizeBytes,
|
|
772
|
+
f.fileType, f.fileSizeBytes, ${LINK_SOURCE_SQL}, f.sha256,
|
|
757
773
|
${linkCount} AS linkCount,
|
|
758
774
|
(SELECT COUNT(*) FROM doc_mount_chunks
|
|
759
775
|
WHERE linkId = l.id AND embedding IS NOT NULL) AS embeddedChunkCount
|
|
@@ -1380,7 +1396,7 @@ async function handleRead(flags, id, relativePath) {
|
|
|
1380
1396
|
|
|
1381
1397
|
function readRaw(db, mount, relativePath, flags) {
|
|
1382
1398
|
const file = db.prepare(`
|
|
1383
|
-
SELECT l.fileId,
|
|
1399
|
+
SELECT l.fileId, ${LINK_SOURCE_SQL}, f.fileType
|
|
1384
1400
|
FROM doc_mount_file_links l
|
|
1385
1401
|
JOIN doc_mount_files f ON f.id = l.fileId
|
|
1386
1402
|
WHERE l.mountPointId = ? AND l.relativePath = ?
|
|
@@ -1440,7 +1456,7 @@ function readRendered(db, mount, relativePath) {
|
|
|
1440
1456
|
// 1. Look up the link row (it carries extractedText now).
|
|
1441
1457
|
const file = db.prepare(`
|
|
1442
1458
|
SELECT l.id AS linkId, l.fileId, l.extractedText,
|
|
1443
|
-
|
|
1459
|
+
${LINK_SOURCE_SQL}, f.fileType
|
|
1444
1460
|
FROM doc_mount_file_links l
|
|
1445
1461
|
JOIN doc_mount_files f ON f.id = l.fileId
|
|
1446
1462
|
WHERE l.mountPointId = ? AND l.relativePath = ?
|
|
@@ -1521,7 +1537,7 @@ async function handleExport(flags, id, outputDir) {
|
|
|
1521
1537
|
const mount = requireMount(db, id);
|
|
1522
1538
|
|
|
1523
1539
|
const files = db.prepare(`
|
|
1524
|
-
SELECT l.fileId, l.relativePath,
|
|
1540
|
+
SELECT l.fileId, l.relativePath, ${LINK_SOURCE_SQL}, f.fileType
|
|
1525
1541
|
FROM doc_mount_file_links l
|
|
1526
1542
|
JOIN doc_mount_files f ON f.id = l.fileId
|
|
1527
1543
|
WHERE l.mountPointId = ?
|
|
@@ -1813,15 +1829,22 @@ async function handleWrite(flags, positional) {
|
|
|
1813
1829
|
process.exit(http.code === 'DEST_EXISTS' ? 2 : 1);
|
|
1814
1830
|
}
|
|
1815
1831
|
const r = http.result;
|
|
1816
|
-
|
|
1832
|
+
// A database-backed store transcodes bitmaps to WebP, so it reports a
|
|
1833
|
+
// different stored path and the sha256 of the stored bytes. That is the
|
|
1834
|
+
// store doing its job, not corruption: only a mismatch at the path we
|
|
1835
|
+
// asked for is one.
|
|
1836
|
+
const storedPath = r.relativePath ?? relativePath;
|
|
1837
|
+
const transcoded = storedPath.replace(/^\/+/, '') !== relativePath.replace(/^\/+/, '');
|
|
1838
|
+
if (r.sha256 !== sourceSha && !transcoded) {
|
|
1817
1839
|
console.error(`Checksum mismatch: source ${sourceSha} != dest ${r.sha256}`);
|
|
1818
1840
|
process.exit(1);
|
|
1819
1841
|
}
|
|
1820
1842
|
if (flags.json) {
|
|
1821
|
-
process.stdout.write(JSON.stringify({ ...r, sourceSha256: sourceSha }, null, 2) + '\n');
|
|
1843
|
+
process.stdout.write(JSON.stringify({ ...r, sourceSha256: sourceSha, transcoded }, null, 2) + '\n');
|
|
1822
1844
|
return;
|
|
1823
1845
|
}
|
|
1824
|
-
|
|
1846
|
+
const note = transcoded ? ` ${DIM}[stored as ${storedPath}; the store converted it]${RESET}` : '';
|
|
1847
|
+
console.log(`${GREEN}Wrote${RESET} ${mount.name}:${storedPath} (${formatBytes(r.sizeBytes)}, sha=${r.sha256.slice(0, 12)}…)${note}`);
|
|
1825
1848
|
return;
|
|
1826
1849
|
}
|
|
1827
1850
|
|
|
@@ -1916,6 +1939,17 @@ async function handleDelete(flags, positional) {
|
|
|
1916
1939
|
|
|
1917
1940
|
const http = await deleteViaHttp(flags.port, mount.id, relativePath);
|
|
1918
1941
|
if (http.reachable) {
|
|
1942
|
+
if (!http.ok && http.status === 404) {
|
|
1943
|
+
// The server answers 404 for a path that holds nothing; for the CLI that
|
|
1944
|
+
// is still the no-op it has always been.
|
|
1945
|
+
const r = { deleted: false, mountPointId: mount.id, path: relativePath };
|
|
1946
|
+
if (flags.json) {
|
|
1947
|
+
process.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
console.log(`${DIM}No-op${RESET} ${mount.name}:${relativePath} (did not exist)`);
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1919
1953
|
if (!http.ok) {
|
|
1920
1954
|
console.error(`Delete failed: ${http.error}`);
|
|
1921
1955
|
process.exit(1);
|
|
@@ -2622,7 +2656,7 @@ async function handleGrep(flags, positional) {
|
|
|
2622
2656
|
|
|
2623
2657
|
const linksByMount = db.prepare(`
|
|
2624
2658
|
SELECT l.id AS linkId, l.fileId, l.relativePath, l.extractedText,
|
|
2625
|
-
|
|
2659
|
+
${LINK_SOURCE_SQL}, f.fileType
|
|
2626
2660
|
FROM doc_mount_file_links l
|
|
2627
2661
|
JOIN doc_mount_files f ON f.id = l.fileId
|
|
2628
2662
|
WHERE l.mountPointId = ?
|
|
@@ -36,9 +36,15 @@ const STAT_BLOCK_BYTES = 512;
|
|
|
36
36
|
// and the partially-materialized file (blocks > 0 but blocks*512 < size) — the
|
|
37
37
|
// latter still fails SQLite open with "file is not a database". A fully-resident
|
|
38
38
|
// file always reports blocks*512 >= size (allocation rounds up), so this never
|
|
39
|
-
// flags a healthy file. Zero-byte files are never flagged. Other platforms
|
|
40
|
-
//
|
|
41
|
-
|
|
39
|
+
// flags a healthy file. Zero-byte files are never flagged. Other platforms are a
|
|
40
|
+
// no-op, as in the server's materializeCloudFiles: on Linux a sparse or
|
|
41
|
+
// compressed file would read as evicted, and Windows reports no block count.
|
|
42
|
+
function isDetectionSupported(platform = process.platform) {
|
|
43
|
+
return platform === 'darwin';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isDatalessStat(stat, platform = process.platform) {
|
|
47
|
+
if (!isDetectionSupported(platform)) return false;
|
|
42
48
|
return stat.size > 0 && stat.blocks * STAT_BLOCK_BYTES < stat.size;
|
|
43
49
|
}
|
|
44
50
|
|
|
@@ -166,11 +172,20 @@ async function fileVerifyCommand(args) {
|
|
|
166
172
|
// resolved.dataDir already points at the instance's data/ directory.
|
|
167
173
|
const targetDir = resolved.dataDir;
|
|
168
174
|
|
|
175
|
+
const supported = isDetectionSupported();
|
|
176
|
+
if (!supported && !flags.json) {
|
|
177
|
+
console.log(
|
|
178
|
+
'Evicted-file detection is supported on macOS only; on this platform no file is reported as evicted.' +
|
|
179
|
+
(flags.all ? '' : ' Pass --all to read every top-level file anyway.'),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
169
183
|
const files = listTopLevelFiles(targetDir);
|
|
170
184
|
const targets = flags.all ? files : files.filter((f) => f.dataless);
|
|
171
185
|
|
|
172
186
|
const summary = {
|
|
173
187
|
dataDir: targetDir,
|
|
188
|
+
detectionSupported: supported,
|
|
174
189
|
checked: files.length,
|
|
175
190
|
targeted: targets.length,
|
|
176
191
|
downloaded: 0,
|
|
@@ -226,4 +241,6 @@ async function fileVerifyCommand(args) {
|
|
|
226
241
|
|
|
227
242
|
module.exports = {
|
|
228
243
|
fileVerifyCommand,
|
|
244
|
+
isDatalessStat,
|
|
245
|
+
isDetectionSupported,
|
|
229
246
|
};
|
|
@@ -54,8 +54,8 @@ will also accept --instance <name>:
|
|
|
54
54
|
quilltap docs --instance Lebanon list
|
|
55
55
|
|
|
56
56
|
Default Instance:
|
|
57
|
-
When no --instance or --data-dir is specified, the CLI uses
|
|
58
|
-
|
|
57
|
+
When no --instance or --data-dir is specified, the CLI uses QUILLTAP_DATA_DIR
|
|
58
|
+
(if set), then the registered default (if one is set), then the OS platform
|
|
59
59
|
default. Marked with * in list output.
|
|
60
60
|
|
|
61
61
|
quilltap instances default Friday # set Friday as the default
|
|
@@ -223,8 +223,12 @@ function cmdRemove(args) {
|
|
|
223
223
|
console.error('Usage: quilltap instances remove <name>');
|
|
224
224
|
process.exit(1);
|
|
225
225
|
}
|
|
226
|
+
const defaultBefore = getDefaultInstance();
|
|
226
227
|
const key = removeInstance(name);
|
|
227
228
|
console.log(`Removed instance "${key}".`);
|
|
229
|
+
if (defaultBefore === key) {
|
|
230
|
+
console.log('It was the default instance; the default is now cleared.');
|
|
231
|
+
}
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
async function cmdSetPassphrase(args) {
|
package/lib/instances.js
CHANGED
|
@@ -198,6 +198,11 @@ function removeInstance(name) {
|
|
|
198
198
|
throw new Error(`Unknown instance "${name}".`);
|
|
199
199
|
}
|
|
200
200
|
delete registry.instances[key];
|
|
201
|
+
// A default that names a removed instance would send every flagless command
|
|
202
|
+
// to the platform default without a word (issue #360).
|
|
203
|
+
if (registry.defaultInstance === key) {
|
|
204
|
+
registry.defaultInstance = null;
|
|
205
|
+
}
|
|
201
206
|
writeInstances(registry);
|
|
202
207
|
return key;
|
|
203
208
|
}
|