@in-the-loop-labs/pair-review 5.4.0 → 5.4.2
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 +3 -3
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/public/index.html +4 -0
- package/public/js/components/AdvancedConfigTab.js +18 -108
- package/public/js/components/VoiceCentricConfigTab.js +18 -108
- package/public/js/index.js +47 -5
- package/public/js/modules/diff-renderer.js +7 -6
- package/public/js/utils/council-timeout.js +203 -0
- package/public/local.html +4 -0
- package/public/pr.html +4 -0
- package/src/ai/antigravity-provider.js +76 -35
- package/src/ai/claude-provider.js +115 -39
- package/src/ai/codex-provider.js +19 -24
- package/src/ai/copilot-provider.js +59 -48
- package/src/ai/cursor-agent-provider.js +95 -133
- package/src/ai/opencode-provider.js +21 -2
- package/src/ai/provider.js +3 -3
- package/src/chat/session-manager.js +1 -1
- package/src/database.js +240 -59
- package/src/git/worktree-pool-lifecycle.js +152 -33
- package/src/git/worktree-pool-usage.js +20 -0
- package/src/git/worktree.js +14 -5
- package/src/main.js +25 -9
- package/src/routes/bulk-analysis-configs.js +1 -1
- package/src/routes/pr.js +11 -14
- package/src/routes/reviews.js +8 -30
- package/src/routes/setup.js +22 -9
- package/src/setup/pr-setup.js +12 -3
- package/src/utils/diff-file-content.js +62 -25
- package/src/utils/json-extractor.js +267 -13
- package/src/utils/pr-file-blob-cache.js +134 -0
- package/src/utils/process-liveness.js +64 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Per-PR cache of the blob info the PR-mode file-content endpoints need.
|
|
4
|
+
*
|
|
5
|
+
* `pr_metadata.pr_data` holds the whole PR diff, and the file-content
|
|
6
|
+
* endpoints are hit on every lazy file body, gap expansion, context file and
|
|
7
|
+
* chat snippet. Parsing the row and scanning the diff on each request is
|
|
8
|
+
* wasteful on large PRs, so this module parses it once per PR into a
|
|
9
|
+
* path -> blob info index plus the base SHA, and serves lookups from that.
|
|
10
|
+
*
|
|
11
|
+
* Staleness guards (every one must hold for a cache hit):
|
|
12
|
+
* - Writers of `pr_data` on this connection call invalidatePRFileBlobCache().
|
|
13
|
+
* - The row's `(id, updated_at)` must match. These columns precede `pr_data`
|
|
14
|
+
* in the row, so reading them does not load the diff. A deleted row serves
|
|
15
|
+
* no specs; a recreated row has a new id.
|
|
16
|
+
* - `PRAGMA data_version` must be unchanged. SQLite bumps it whenever another
|
|
17
|
+
* connection (e.g. a `--headless --no-server` CLI run sharing the database
|
|
18
|
+
* file) commits, which an in-process invalidation cannot see and which a
|
|
19
|
+
* 1-second `updated_at` can miss.
|
|
20
|
+
*
|
|
21
|
+
* The lookup runs synchronously (better-sqlite3), so no write can interleave
|
|
22
|
+
* between reading the row and storing the index.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const logger = require('./logger');
|
|
26
|
+
const { safeParseJson } = require('./safe-parse-json');
|
|
27
|
+
const { buildFileBlobIndex, buildOriginalFileContentSpecs } = require('./diff-file-content');
|
|
28
|
+
|
|
29
|
+
// Upper bound on cached PRs per database, evicted least recently used.
|
|
30
|
+
const MAX_CACHED_PRS = 50;
|
|
31
|
+
|
|
32
|
+
// Keyed by database handle so separate databases (and tests) never share entries.
|
|
33
|
+
const cachesByDb = new WeakMap();
|
|
34
|
+
|
|
35
|
+
function cacheKey(repository, prNumber) {
|
|
36
|
+
return `${String(repository).toLowerCase()}#${Number(prNumber)}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getDbCache(db) {
|
|
40
|
+
let cache = cachesByDb.get(db);
|
|
41
|
+
if (!cache) {
|
|
42
|
+
cache = new Map();
|
|
43
|
+
cachesByDb.set(db, cache);
|
|
44
|
+
}
|
|
45
|
+
return cache;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function loadEntry(db, row, dataVersion) {
|
|
49
|
+
const record = db.prepare('SELECT pr_data FROM pr_metadata WHERE id = ?').get(row.id);
|
|
50
|
+
const prData = safeParseJson(record?.pr_data, null);
|
|
51
|
+
if (record?.pr_data && !prData) {
|
|
52
|
+
logger.warn('Could not parse pr_data for file-content route');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const isObject = prData && typeof prData === 'object';
|
|
56
|
+
return {
|
|
57
|
+
id: row.id,
|
|
58
|
+
updatedAt: row.updated_at,
|
|
59
|
+
dataVersion,
|
|
60
|
+
hasPrData: Boolean(isObject),
|
|
61
|
+
baseSha: isObject ? prData.base_sha || null : null,
|
|
62
|
+
blobIndex: isObject ? buildFileBlobIndex(prData.diff) : new Map()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the ordered git specs for a file's original content in a PR:
|
|
68
|
+
* exact diff blob, then base_sha. An empty array means the caller should read
|
|
69
|
+
* the worktree (no stored PR data, or the file has neither source).
|
|
70
|
+
*
|
|
71
|
+
* @param {Database} db - better-sqlite3 database handle
|
|
72
|
+
* @param {string} repository - Repository in owner/repo form
|
|
73
|
+
* @param {number} prNumber - Pull request number
|
|
74
|
+
* @param {string} fileName - Path to resolve (old or new path in the diff)
|
|
75
|
+
* @returns {Array<{gitSpec: string, source: string}>}
|
|
76
|
+
*/
|
|
77
|
+
function getPRFileContentSpecs(db, repository, prNumber, fileName) {
|
|
78
|
+
const row = db.prepare(`
|
|
79
|
+
SELECT id, updated_at FROM pr_metadata
|
|
80
|
+
WHERE pr_number = ? AND repository = ? COLLATE NOCASE
|
|
81
|
+
`).get(prNumber, repository);
|
|
82
|
+
|
|
83
|
+
const cache = getDbCache(db);
|
|
84
|
+
const key = cacheKey(repository, prNumber);
|
|
85
|
+
|
|
86
|
+
if (!row) {
|
|
87
|
+
cache.delete(key);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const dataVersion = db.pragma('data_version', { simple: true });
|
|
92
|
+
let entry = cache.get(key);
|
|
93
|
+
const fresh = entry
|
|
94
|
+
&& entry.id === row.id
|
|
95
|
+
&& entry.updatedAt === row.updated_at
|
|
96
|
+
&& entry.dataVersion === dataVersion;
|
|
97
|
+
|
|
98
|
+
if (fresh) {
|
|
99
|
+
// Re-insert to mark as most recently used.
|
|
100
|
+
cache.delete(key);
|
|
101
|
+
} else {
|
|
102
|
+
entry = loadEntry(db, row, dataVersion);
|
|
103
|
+
}
|
|
104
|
+
cache.set(key, entry);
|
|
105
|
+
|
|
106
|
+
if (cache.size > MAX_CACHED_PRS) {
|
|
107
|
+
cache.delete(cache.keys().next().value);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!entry.hasPrData) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const blobInfo = entry.blobIndex.get(fileName) ?? null;
|
|
115
|
+
return buildOriginalFileContentSpecs(blobInfo, entry.baseSha, fileName);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Drop the cached blob info for a PR. Call after every write to its
|
|
120
|
+
* `pr_metadata.pr_data`.
|
|
121
|
+
*
|
|
122
|
+
* @param {Database} db - better-sqlite3 database handle the write used
|
|
123
|
+
* @param {string} repository - Repository in owner/repo form
|
|
124
|
+
* @param {number} prNumber - Pull request number
|
|
125
|
+
*/
|
|
126
|
+
function invalidatePRFileBlobCache(db, repository, prNumber) {
|
|
127
|
+
cachesByDb.get(db)?.delete(cacheKey(repository, prNumber));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
getPRFileContentSpecs,
|
|
132
|
+
invalidatePRFileBlobCache,
|
|
133
|
+
MAX_CACHED_PRS
|
|
134
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Process liveness helpers.
|
|
6
|
+
*
|
|
7
|
+
* Used to decide whether a pair-review process recorded as the holder of a
|
|
8
|
+
* shared resource (e.g. a worktree_pool row) is still running. Every
|
|
9
|
+
* uncertain answer errs toward "alive": wrongly treating a live holder as
|
|
10
|
+
* dead lets this process reclaim a worktree another process is using, which
|
|
11
|
+
* is far worse than leaving a dead holder's worktree parked until the next
|
|
12
|
+
* startup.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const os = require('os');
|
|
16
|
+
|
|
17
|
+
const defaults = {
|
|
18
|
+
kill: (pid, signal) => process.kill(pid, signal),
|
|
19
|
+
now: () => Date.now(),
|
|
20
|
+
uptime: () => os.uptime(),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return whether a process with the given PID currently exists.
|
|
25
|
+
*
|
|
26
|
+
* Uses signal 0, which performs the existence/permission check without
|
|
27
|
+
* delivering a signal.
|
|
28
|
+
*
|
|
29
|
+
* @param {number} pid - Process ID to probe
|
|
30
|
+
* @param {Object} [_deps] - Dependency overrides for testing ({ kill })
|
|
31
|
+
* @returns {boolean} false for an invalid PID or ESRCH; true otherwise
|
|
32
|
+
* (success, EPERM — exists but owned by another user — and any other error,
|
|
33
|
+
* so an unexpected failure never causes a live holder to be treated as dead)
|
|
34
|
+
*/
|
|
35
|
+
function isProcessAlive(pid, _deps = {}) {
|
|
36
|
+
const deps = { ...defaults, ..._deps };
|
|
37
|
+
if (pid == null || !Number.isInteger(pid) || pid <= 0) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
deps.kill(pid, 0);
|
|
42
|
+
return true;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err && err.code === 'ESRCH') return false;
|
|
45
|
+
// EPERM: the process exists but we may not signal it.
|
|
46
|
+
// Anything else: unknown — fail safe and treat the holder as alive.
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Approximate wall-clock time (ms since epoch) at which the OS booted.
|
|
53
|
+
* A holder claim stamped before this moment cannot belong to a process that
|
|
54
|
+
* is running now, regardless of what PID it recorded.
|
|
55
|
+
*
|
|
56
|
+
* @param {Object} [_deps] - Dependency overrides for testing ({ now, uptime })
|
|
57
|
+
* @returns {number}
|
|
58
|
+
*/
|
|
59
|
+
function getBootTimeMs(_deps = {}) {
|
|
60
|
+
const deps = { ...defaults, ..._deps };
|
|
61
|
+
return deps.now() - deps.uptime() * 1000;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { isProcessAlive, getBootTimeMs };
|