@in-the-loop-labs/pair-review 3.1.4 → 3.2.1

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/src/server.js CHANGED
@@ -312,6 +312,8 @@ async function startServer(sharedDb = null) {
312
312
  const chatRoutes = require('./routes/chat');
313
313
  const contextFilesRoutes = require('./routes/context-files');
314
314
  const githubCollectionsRoutes = require('./routes/github-collections');
315
+ const stackAnalysisRoutes = require('./routes/stack-analysis');
316
+ const { createSoundRouter } = require('./routes/sound');
315
317
 
316
318
  // Initialize chat session manager
317
319
  const ChatSessionManager = require('./chat/session-manager');
@@ -330,6 +332,8 @@ async function startServer(sharedDb = null) {
330
332
  app.use('/', setupRoutes);
331
333
  app.use('/', mcpRoutes);
332
334
  app.use('/', githubCollectionsRoutes);
335
+ app.use('/', stackAnalysisRoutes);
336
+ app.use('/', createSoundRouter());
333
337
  app.use('/', prRoutes);
334
338
 
335
339
  // Error handling middleware
@@ -0,0 +1,77 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Stack PR Setup Utility
4
+ *
5
+ * Lightweight setup for individual PRs during stack analysis.
6
+ * Fetches PR data (or accepts pre-fetched data), generates diffs,
7
+ * and stores metadata via storePRData().
8
+ */
9
+
10
+ const { storePRData } = require('./pr-setup');
11
+ const { GitHubClient } = require('../github/client');
12
+ const logger = require('../utils/logger');
13
+
14
+ /**
15
+ * Set up a single PR within a stack analysis context.
16
+ *
17
+ * Fetches PR data from GitHub (or uses pre-fetched data when provided),
18
+ * generates a diff in the worktree, and stores everything in the database
19
+ * via storePRData().
20
+ *
21
+ * @param {Object} params
22
+ * @param {Object} params.db - Database instance
23
+ * @param {string} params.owner - Repository owner
24
+ * @param {string} params.repo - Repository name
25
+ * @param {number} params.prNumber - Pull request number
26
+ * @param {string} params.githubToken - GitHub personal access token
27
+ * @param {string} params.worktreePath - Path to the per-PR worktree
28
+ * @param {import('../git/worktree').GitWorktreeManager} params.worktreeManager - Worktree manager instance
29
+ * @param {Object} [params.prData] - Pre-fetched PR data from GitHub (skips API call when provided)
30
+ * @returns {Promise<{ reviewId: number, prMetadata: Object, prData: Object, isNew: boolean }>}
31
+ */
32
+ async function setupStackPR({ db, owner, repo, prNumber, githubToken, worktreePath, worktreeManager, prData: prefetchedPRData }) {
33
+ logger.info(`Setting up stack PR #${prNumber} for ${owner}/${repo}`);
34
+
35
+ // 1. Fetch PR data from GitHub (or use pre-fetched data)
36
+ const githubClient = new GitHubClient(githubToken);
37
+ let prData;
38
+ if (prefetchedPRData) {
39
+ prData = prefetchedPRData;
40
+ } else {
41
+ prData = await githubClient.fetchPullRequest(owner, repo, prNumber);
42
+ }
43
+ logger.info(`Fetched PR #${prNumber}: "${prData.title}"`);
44
+
45
+ // 2. Fetch changed files list from GitHub API
46
+ const prFiles = await githubClient.fetchPullRequestFiles(owner, repo, prNumber);
47
+ logger.info(`PR #${prNumber} has ${prFiles.length} changed files`);
48
+
49
+ // 3. Generate diff in the worktree (SHA-based, works after checkout)
50
+ const diff = await worktreeManager.generateUnifiedDiff(worktreePath, prData);
51
+
52
+ // 4. Get changed files with stats
53
+ const changedFiles = await worktreeManager.getChangedFiles(worktreePath, prData);
54
+
55
+ // 5. Store via storePRData (creates/updates pr_metadata, reviews, worktrees records)
56
+ const prInfo = { owner, repo, number: prNumber };
57
+ const { isNewReview, reviewId } = await storePRData(db, prInfo, prData, diff, changedFiles, worktreePath);
58
+
59
+ logger.info(`Stack PR #${prNumber} setup complete (reviewId: ${reviewId}, new: ${isNewReview})`);
60
+
61
+ return {
62
+ reviewId,
63
+ prMetadata: {
64
+ owner,
65
+ repo,
66
+ number: prNumber,
67
+ title: prData.title,
68
+ author: prData.author,
69
+ base_branch: prData.base_branch,
70
+ head_branch: prData.head_branch,
71
+ },
72
+ prData,
73
+ isNew: isNewReview,
74
+ };
75
+ }
76
+
77
+ module.exports = { setupStackPR };