difit 0.0.3 → 0.0.5

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.
Files changed (46) hide show
  1. package/README.md +3 -1
  2. package/dist/cli/index.js +0 -0
  3. package/dist/client/assets/index-W2UC55JC.css +1 -0
  4. package/dist/client/assets/index-hiGBtmpa.js +142 -0
  5. package/dist/client/index.html +2 -2
  6. package/dist/server/comment-store.js +85 -8
  7. package/dist/server/git-diff.js +3 -1
  8. package/dist/server/server.js +10 -0
  9. package/package.json +4 -4
  10. package/dist/cli/index.d.ts +0 -2
  11. package/dist/cli/index.test.d.ts +0 -1
  12. package/dist/cli/index.test.js +0 -676
  13. package/dist/cli/utils.d.ts +0 -1
  14. package/dist/cli/utils.test.d.ts +0 -1
  15. package/dist/cli/utils.test.js +0 -214
  16. package/dist/client/assets/index-CSJzfcU-.css +0 -1
  17. package/dist/client/assets/index-IxkylgHX.js +0 -53
  18. package/dist/client/assets/prism-css-Bpx-unsJ.js +0 -1
  19. package/dist/client/assets/prism-json-xwnKirkR.js +0 -1
  20. package/dist/client/assets/prism-typescript-B2PMeEx1.js +0 -1
  21. package/dist/server/comment-store.d.ts +0 -13
  22. package/dist/server/git-diff-tui.d.ts +0 -2
  23. package/dist/server/git-diff-tui.js +0 -95
  24. package/dist/server/git-diff.d.ts +0 -10
  25. package/dist/server/git-diff.test.d.ts +0 -1
  26. package/dist/server/git-diff.test.js +0 -292
  27. package/dist/server/server.d.ts +0 -11
  28. package/dist/server/server.test.d.ts +0 -1
  29. package/dist/server/server.test.js +0 -382
  30. package/dist/tui/App.d.ts +0 -8
  31. package/dist/tui/App.js +0 -92
  32. package/dist/tui/App.test.d.ts +0 -1
  33. package/dist/tui/App.test.js +0 -31
  34. package/dist/tui/components/DiffViewer.d.ts +0 -9
  35. package/dist/tui/components/DiffViewer.js +0 -88
  36. package/dist/tui/components/FileList.d.ts +0 -8
  37. package/dist/tui/components/FileList.js +0 -48
  38. package/dist/tui/components/SideBySideDiffViewer.d.ts +0 -9
  39. package/dist/tui/components/SideBySideDiffViewer.js +0 -237
  40. package/dist/tui/components/StatusBar.d.ts +0 -8
  41. package/dist/tui/components/StatusBar.js +0 -23
  42. package/dist/tui/utils/parseDiff.d.ts +0 -2
  43. package/dist/tui/utils/parseDiff.js +0 -68
  44. package/dist/types/diff.d.ts +0 -33
  45. package/dist/utils/fileUtils.d.ts +0 -12
  46. package/dist/utils/fileUtils.js +0 -21
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>ReviewIt - Git Diff Viewer</title>
8
- <script type="module" crossorigin src="/assets/index-IxkylgHX.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index-CSJzfcU-.css">
8
+ <script type="module" crossorigin src="/assets/index-hiGBtmpa.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-W2UC55JC.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
@@ -26,17 +26,94 @@ export class CommentStore {
26
26
  }
27
27
  generatePrompt(comment, diffContent) {
28
28
  const lines = diffContent.split('\n');
29
- const contextStart = Math.max(0, comment.line - 3);
30
- const contextEnd = Math.min(lines.length, comment.line + 3);
31
- const context = lines.slice(contextStart, contextEnd + 1).join('\n');
29
+ // Find the relevant code context around the commented line
30
+ let relevantLines = [];
31
+ let foundTargetLine = false;
32
+ for (let i = 0; i < lines.length; i++) {
33
+ const line = lines[i];
34
+ // Skip chunk headers (start with @@)
35
+ if (line.startsWith('@@'))
36
+ continue;
37
+ // Extract line numbers and content
38
+ const addMatch = line.match(/^\+(\d+)/);
39
+ const delMatch = line.match(/^-(\d+)/);
40
+ const normalMatch = line.match(/^ /);
41
+ if (addMatch || delMatch || normalMatch) {
42
+ const lineNumber = addMatch
43
+ ? parseInt(addMatch[1])
44
+ : delMatch
45
+ ? parseInt(delMatch[1])
46
+ : null;
47
+ // Include lines around the target line (±5 lines context)
48
+ if (lineNumber && Math.abs(lineNumber - comment.line) <= 5) {
49
+ relevantLines.push(line);
50
+ if (lineNumber === comment.line) {
51
+ foundTargetLine = true;
52
+ }
53
+ }
54
+ else if (!lineNumber && relevantLines.length > 0 && relevantLines.length < 15) {
55
+ // Include context lines without line numbers if we're building context
56
+ relevantLines.push(line);
57
+ }
58
+ }
59
+ }
60
+ // If we didn't find the exact line, include more general context
61
+ if (!foundTargetLine && relevantLines.length === 0) {
62
+ const contextStart = Math.max(0, comment.line - 5);
63
+ const contextEnd = Math.min(lines.length, comment.line + 5);
64
+ relevantLines = lines.slice(contextStart, contextEnd);
65
+ }
66
+ const codeContext = relevantLines.join('\n');
32
67
  return [
33
- `📄 ${comment.file} L${comment.line}`,
34
- '----',
35
- context,
36
- '----',
37
- `Comment: "${comment.body}"`,
68
+ `File: ${comment.file}`,
69
+ `Line: ${comment.line}`,
70
+ '',
71
+ 'Code Context:',
72
+ '```',
73
+ codeContext,
74
+ '```',
75
+ '',
76
+ `Comment: ${comment.body}`,
38
77
  ].join('\n');
39
78
  }
79
+ generateAllCommentsPrompt(comments, diffFiles) {
80
+ if (comments.length === 0) {
81
+ return 'No comments available.';
82
+ }
83
+ const prompts = comments.map((comment, index) => {
84
+ const targetFile = diffFiles.find((f) => f.path === comment.file);
85
+ if (!targetFile) {
86
+ return [
87
+ `## Comment ${index + 1}`,
88
+ `File: ${comment.file}`,
89
+ `Line: ${comment.line}`,
90
+ '',
91
+ 'Code Context:',
92
+ '```',
93
+ 'File not found in diff',
94
+ '```',
95
+ '',
96
+ `Comment: ${comment.body}`,
97
+ ].join('\n');
98
+ }
99
+ let diffContent = '';
100
+ for (const chunk of targetFile.chunks) {
101
+ diffContent += chunk.header + '\n';
102
+ for (const line of chunk.lines) {
103
+ const prefix = line.type === 'add' ? '+' : line.type === 'delete' ? '-' : ' ';
104
+ diffContent += prefix + line.content + '\n';
105
+ }
106
+ }
107
+ const individualPrompt = this.generatePrompt(comment, diffContent);
108
+ return [`## Comment ${index + 1}`, individualPrompt].join('\n');
109
+ });
110
+ return [
111
+ `All Code Review Comments (${comments.length} total)`,
112
+ '='.repeat(50),
113
+ '',
114
+ ...prompts,
115
+ ].join('\n\n');
116
+ }
40
117
  async saveToFile() {
41
118
  try {
42
119
  await fs.mkdir(dirname(this.filePath), { recursive: true });
@@ -5,11 +5,13 @@ export class GitDiffParser {
5
5
  }
6
6
  async parseDiff(commitish) {
7
7
  try {
8
+ // Resolve commitish to actual commit hash
9
+ const resolvedCommit = await this.git.revparse([commitish]);
8
10
  const diffSummary = await this.git.diffSummary([`${commitish}^`, commitish]);
9
11
  const diffRaw = await this.git.diff([`${commitish}^`, commitish]);
10
12
  const files = await this.parseUnifiedDiff(diffRaw, diffSummary.files);
11
13
  return {
12
- commit: commitish,
14
+ commit: resolvedCommit,
13
15
  files,
14
16
  };
15
17
  }
@@ -70,6 +70,16 @@ export async function startServer(options) {
70
70
  res.status(500).json({ error: 'Failed to generate prompt' });
71
71
  }
72
72
  });
73
+ app.post('/api/comments/all/prompt', async (_, res) => {
74
+ try {
75
+ const comments = await commentStore.getComments();
76
+ const prompt = commentStore.generateAllCommentsPrompt(comments, diffData.files);
77
+ res.json({ prompt });
78
+ }
79
+ catch (error) {
80
+ res.status(500).json({ error: 'Failed to generate all comments prompt' });
81
+ }
82
+ });
73
83
  // Always runs in production mode when distributed as a CLI tool
74
84
  const isProduction = process.env.NODE_ENV === 'production' || process.env.NODE_ENV !== 'development';
75
85
  if (isProduction) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "difit",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "A lightweight command-line tool that spins up a local web server to display Git commit diffs in a GitHub-like Files changed view",
5
5
  "type": "module",
6
6
  "engines": {
@@ -19,7 +19,7 @@
19
19
  "url": "https://github.com/yoshiko-pg/difit/issues"
20
20
  },
21
21
  "scripts": {
22
- "dev": "concurrently \"pnpm run dev:cli HEAD --no-open\" \"sleep 1 && vite --open\"",
22
+ "dev": "node scripts/dev.js",
23
23
  "dev:cli": "tsc --project tsconfig.cli.json && NODE_ENV=development node dist/cli/index.js",
24
24
  "build": "tsc && vite build",
25
25
  "build:cli": "tsc --project tsconfig.cli.json",
@@ -36,6 +36,7 @@
36
36
  "dependencies": {
37
37
  "commander": "^11.1.0",
38
38
  "express": "^4.18.2",
39
+ "lucide-react": "^0.525.0",
39
40
  "open": "^10.0.3",
40
41
  "prism-react-renderer": "^2.4.1",
41
42
  "prismjs": "^1.30.0",
@@ -57,7 +58,6 @@
57
58
  "@typescript-eslint/parser": "^6.15.0",
58
59
  "@vitejs/plugin-react": "^4.2.1",
59
60
  "autoprefixer": "^10.4.21",
60
- "concurrently": "^9.2.0",
61
61
  "eslint": "^8.56.0",
62
62
  "eslint-plugin-react": "^7.33.2",
63
63
  "eslint-plugin-react-hooks": "^4.6.0",
@@ -89,5 +89,5 @@
89
89
  "publishConfig": {
90
90
  "access": "public"
91
91
  },
92
- "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
92
+ "packageManager": "pnpm@10.10.0"
93
93
  }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1 +0,0 @@
1
- export {};