@threadbase-sh/scanner 0.9.1 → 0.9.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/dist/cli.js +61 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +60 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +60 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Command } from "commander";
|
|
|
5
5
|
import pino2 from "pino";
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "0.9.
|
|
8
|
+
var version = "0.9.3";
|
|
9
9
|
|
|
10
10
|
// src/logger.ts
|
|
11
11
|
import pino from "pino";
|
|
@@ -1704,6 +1704,19 @@ var ConversationFilesRepo = class {
|
|
|
1704
1704
|
const rows = this.db.prepare("SELECT absolute_path FROM conversation_files WHERE status != 'deleted'").all();
|
|
1705
1705
|
return rows.map((r) => r.absolute_path);
|
|
1706
1706
|
}
|
|
1707
|
+
// Active file paths belonging to any of the given accounts. Backs the
|
|
1708
|
+
// deletion-reconcile so a scan that covered only some accounts can't mark
|
|
1709
|
+
// another account's files deleted (they live in the same shared index.db but
|
|
1710
|
+
// a different profile owns them). Returns [] for an empty account list.
|
|
1711
|
+
activePathsByAccounts(accounts) {
|
|
1712
|
+
if (accounts.length === 0) return [];
|
|
1713
|
+
const placeholders = accounts.map(() => "?").join(", ");
|
|
1714
|
+
const rows = this.db.prepare(
|
|
1715
|
+
`SELECT absolute_path FROM conversation_files
|
|
1716
|
+
WHERE status != 'deleted' AND account IN (${placeholders})`
|
|
1717
|
+
).all(...accounts);
|
|
1718
|
+
return rows.map((r) => r.absolute_path);
|
|
1719
|
+
}
|
|
1707
1720
|
// Active files whose immediate parent is exactly parentDir (no nested
|
|
1708
1721
|
// subdirectories). Backs the dir-mtime gate's reuse path: a project dir with
|
|
1709
1722
|
// an unchanged mtime and no nested files can skip the glob entirely.
|
|
@@ -2109,8 +2122,15 @@ var PersistentEngine = class {
|
|
|
2109
2122
|
scanned += batch.length;
|
|
2110
2123
|
options.onProgress?.(scanned, discovered.length);
|
|
2111
2124
|
}
|
|
2125
|
+
const coveredAccounts = /* @__PURE__ */ new Set();
|
|
2126
|
+
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
2127
|
+
for (const p of activeProfiles) coveredAccounts.add(p.id);
|
|
2128
|
+
}
|
|
2129
|
+
if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
|
|
2130
|
+
coveredAccounts.add("codex");
|
|
2131
|
+
}
|
|
2112
2132
|
const seen = new Set(discovered.map((d) => d.filePath));
|
|
2113
|
-
for (const path of this.files.
|
|
2133
|
+
for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
|
|
2114
2134
|
if (!seen.has(path)) this.markDeleted(path);
|
|
2115
2135
|
}
|
|
2116
2136
|
log.info({ scanned, indexed: this.conversations.count() }, "persistent: indexAll complete");
|
|
@@ -2456,10 +2476,21 @@ var ConversationScanner = class {
|
|
|
2456
2476
|
dbPath;
|
|
2457
2477
|
sidecarEnabled;
|
|
2458
2478
|
engineInstance = null;
|
|
2479
|
+
// The most recent scan()'s promise while it is still running, or null when
|
|
2480
|
+
// idle. close() awaits it before closing the SQLite handle so a fire-and-
|
|
2481
|
+
// forget scan can't have its DB shut mid-indexAll ("database connection is
|
|
2482
|
+
// not open"). Tracks the latest scan only — concurrent scans on one instance
|
|
2483
|
+
// aren't a supported pattern (a single writer DB), and the latest resolving
|
|
2484
|
+
// implies earlier ones already settled in practice.
|
|
2485
|
+
inFlightScan = null;
|
|
2459
2486
|
emitter = new EventEmitter();
|
|
2460
2487
|
watcher = null;
|
|
2461
2488
|
queue = null;
|
|
2462
2489
|
periodicTimer = null;
|
|
2490
|
+
// The in-flight periodicReconcile() job, if one is mid-run. unwatch() awaits
|
|
2491
|
+
// it before dropping the queue/engine so its post-await engine.files access
|
|
2492
|
+
// can't hit a closed DB (the watch-mode half of Bug #4).
|
|
2493
|
+
inFlightReconcile = null;
|
|
2463
2494
|
constructor(options) {
|
|
2464
2495
|
this.conversationLRU = new LRUCache(options?.conversationCacheSize ?? 5);
|
|
2465
2496
|
if (options?.persistent === false) {
|
|
@@ -2482,14 +2513,31 @@ var ConversationScanner = class {
|
|
|
2482
2513
|
return this.engineInstance;
|
|
2483
2514
|
}
|
|
2484
2515
|
// Release the SQLite connection. No-op in legacy mode. Safe to call
|
|
2485
|
-
// repeatedly.
|
|
2486
|
-
//
|
|
2487
|
-
close()
|
|
2488
|
-
|
|
2516
|
+
// repeatedly. Awaits watcher teardown AND any in-flight scan before closing
|
|
2517
|
+
// the DB handle, so a fire-and-forget scan() can never have its connection
|
|
2518
|
+
// shut mid-indexAll() ("database connection is not open"). This is why close()
|
|
2519
|
+
// is async — callers should await it during shutdown. (Scanner review Bug #4.)
|
|
2520
|
+
async close() {
|
|
2521
|
+
if (this.watcher || this.queue || this.periodicTimer) await this.unwatch();
|
|
2522
|
+
if (this.inFlightScan) {
|
|
2523
|
+
try {
|
|
2524
|
+
await this.inFlightScan;
|
|
2525
|
+
} catch {
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2489
2528
|
this.engineInstance?.close();
|
|
2490
2529
|
this.engineInstance = null;
|
|
2491
2530
|
}
|
|
2492
2531
|
async scan(options = {}) {
|
|
2532
|
+
const promise = this.runScan(options);
|
|
2533
|
+
this.inFlightScan = promise;
|
|
2534
|
+
try {
|
|
2535
|
+
return await promise;
|
|
2536
|
+
} finally {
|
|
2537
|
+
if (this.inFlightScan === promise) this.inFlightScan = null;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
async runScan(options) {
|
|
2493
2541
|
const profiles = await this.resolveProfiles(options.profiles);
|
|
2494
2542
|
const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
|
|
2495
2543
|
this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
@@ -2925,7 +2973,10 @@ var ConversationScanner = class {
|
|
|
2925
2973
|
const periodicMs = options.periodicMs ?? 6e4;
|
|
2926
2974
|
if (periodicMs > 0) {
|
|
2927
2975
|
this.periodicTimer = setInterval(() => {
|
|
2928
|
-
|
|
2976
|
+
const job = this.periodicReconcile(activeProfiles).finally(() => {
|
|
2977
|
+
if (this.inFlightReconcile === job) this.inFlightReconcile = null;
|
|
2978
|
+
});
|
|
2979
|
+
this.inFlightReconcile = job;
|
|
2929
2980
|
}, periodicMs);
|
|
2930
2981
|
this.periodicTimer.unref?.();
|
|
2931
2982
|
}
|
|
@@ -2969,6 +3020,9 @@ var ConversationScanner = class {
|
|
|
2969
3020
|
clearInterval(this.periodicTimer);
|
|
2970
3021
|
this.periodicTimer = null;
|
|
2971
3022
|
}
|
|
3023
|
+
if (this.inFlightReconcile) {
|
|
3024
|
+
await this.inFlightReconcile;
|
|
3025
|
+
}
|
|
2972
3026
|
if (this.watcher) {
|
|
2973
3027
|
await this.watcher.stop();
|
|
2974
3028
|
this.watcher = null;
|