@andespindola/brainlink 0.1.0-beta.27 → 0.1.0-beta.28
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { access } from 'node:fs/promises';
|
|
3
3
|
import { basename, extname, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import { promisify } from 'node:util';
|
|
5
6
|
import { extractTags, extractWikiLinks } from '../domain/markdown.js';
|
|
6
7
|
import { sanitizeAgentId, sharedAgentId } from '../domain/agents.js';
|
|
@@ -42,9 +43,13 @@ const parseDelimitedRows = (rawOutput) => {
|
|
|
42
43
|
.map((row) => row.split(fieldSeparator));
|
|
43
44
|
};
|
|
44
45
|
const runSqliteQuery = async (databasePath, sql) => {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const baseArgs = ['-noheader', '-separator', fieldSeparator, '-newline', rowSeparator, '-cmd', '.timeout 5000'];
|
|
47
|
+
const runQuery = async (args) => {
|
|
48
|
+
const { stdout } = await execFileAsync('sqlite3', [...args, sql], { maxBuffer: 1024 * 1024 * 64 });
|
|
47
49
|
return parseDelimitedRows(stdout);
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
return await runQuery(['--readonly', ...baseArgs, databasePath]);
|
|
48
53
|
}
|
|
49
54
|
catch (error) {
|
|
50
55
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -52,6 +57,17 @@ const runSqliteQuery = async (databasePath, sql) => {
|
|
|
52
57
|
if (lower.includes('enoent') || lower.includes('not found')) {
|
|
53
58
|
throw new Error('sqlite3 CLI was not found. Install sqlite3 to use db-import.');
|
|
54
59
|
}
|
|
60
|
+
if (lower.includes('database is locked') || lower.includes('(5)')) {
|
|
61
|
+
try {
|
|
62
|
+
const uri = pathToFileURL(databasePath);
|
|
63
|
+
uri.search = 'mode=ro&immutable=1';
|
|
64
|
+
return await runQuery(['-uri', ...baseArgs, uri.toString()]);
|
|
65
|
+
}
|
|
66
|
+
catch (fallbackError) {
|
|
67
|
+
const fallbackMessage = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
68
|
+
throw new Error(`Unable to read SQLite database (locked). Close writers (server/watch/mcp) or rerun with DB idle. Details: ${fallbackMessage}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
55
71
|
throw new Error(`Unable to read SQLite database: ${message}`);
|
|
56
72
|
}
|
|
57
73
|
};
|
package/package.json
CHANGED