difit 3.1.9 → 3.1.11
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.ja.md +30 -13
- package/README.ko.md +30 -13
- package/README.md +30 -13
- package/README.zh.md +30 -13
- package/dist/cli/index.js +56 -46
- package/dist/cli/index.test.js +143 -56
- package/dist/cli/utils.d.ts +4 -7
- package/dist/cli/utils.js +17 -98
- package/dist/client/assets/{index-B1Ye1njT.js → index-0eidGb4G.js} +30 -30
- package/dist/client/assets/{prism-csharp-Dv4F6oYg.js → prism-csharp-Bz_zphOC.js} +1 -1
- package/dist/client/assets/{prism-hcl-BKiQPDt1.js → prism-hcl-HO7lwwhc.js} +1 -1
- package/dist/client/assets/{prism-java-CsLA9BYF.js → prism-java-Dh0Q2eOX.js} +1 -1
- package/dist/client/assets/{prism-perl-CjbksjRr.js → prism-perl-D_qbRz8N.js} +1 -1
- package/dist/client/assets/{prism-php-Blls7Q4g.js → prism-php-Dgr7EUBn.js} +1 -1
- package/dist/client/assets/{prism-ruby-DVHs5uYA.js → prism-ruby-CaFchRnn.js} +1 -1
- package/dist/client/assets/{prism-solidity-BxgmEX2j.js → prism-solidity-CDfI790k.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/server/generated-file-check.d.ts +2 -1
- package/dist/server/git-diff.js +38 -22
- package/dist/server/server.d.ts +1 -0
- package/dist/server/server.js +17 -10
- package/dist/server/server.test.js +104 -0
- package/dist/tui/App.js +7 -10
- package/dist/tui/components/SideBySideDiffViewer.js +8 -8
- package/dist/tui/components/StatusBar.js +1 -5
- package/dist/types/diff.d.ts +1 -0
- package/dist/utils/commentFormatting.js +1 -3
- package/dist/utils/suggestionUtils.d.ts +2 -1
- package/package.json +39 -48
package/README.ja.md
CHANGED
|
@@ -25,6 +25,12 @@ npm install -g difit
|
|
|
25
25
|
difit # 最新コミットのdiffをWebUIで表示
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
AIエージェントから使えるようにする
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx skills add yoshiko-pg/difit # エージェントにスキルを追加
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
## 🚀 使い方
|
|
29
35
|
|
|
30
36
|
### 基本的な使い方
|
|
@@ -66,19 +72,19 @@ difit working # 未ステージ差分のみ
|
|
|
66
72
|
difit --pr https://github.com/owner/repo/pull/123
|
|
67
73
|
```
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
`--pr` モードでは、内部で `gh pr diff --patch` を実行してパッチを取得します。
|
|
76
|
+
|
|
77
|
+
認証は GitHub CLI が処理します:
|
|
70
78
|
|
|
71
|
-
1.
|
|
72
|
-
2.
|
|
73
|
-
3. **認証なし**:パブリックリポジトリは認証なしで動作(レート制限あり)
|
|
79
|
+
1. **一度ログイン**(推奨):`gh auth login`
|
|
80
|
+
2. **トークン認証**(CI/非対話環境):`GH_TOKEN` または `GITHUB_TOKEN` を設定
|
|
74
81
|
|
|
75
82
|
#### GitHub Enterprise Server
|
|
76
83
|
|
|
77
|
-
Enterprise ServerのPR
|
|
84
|
+
Enterprise Server の PR を表示する場合は、GitHub CLI を Enterprise ホスト向けに認証してください:
|
|
78
85
|
|
|
79
|
-
1. `
|
|
80
|
-
2.
|
|
81
|
-
3. `GITHUB_TOKEN`環境変数として設定
|
|
86
|
+
1. `gh auth login --hostname YOUR-ENTERPRISE-SERVER`
|
|
87
|
+
2. または `GH_HOST=YOUR-ENTERPRISE-SERVER` と `GH_TOKEN` / `GITHUB_TOKEN` を設定
|
|
82
88
|
|
|
83
89
|
### 標準入力
|
|
84
90
|
|
|
@@ -121,6 +127,7 @@ git diff --cached | difit -
|
|
|
121
127
|
| `--tui` | false | WebUIの代わりにターミナルUIを使用 |
|
|
122
128
|
| `--clean` | false | 起動時に既存コメントと閲覧済みファイルをすべてクリア |
|
|
123
129
|
| `--include-untracked` | false | diffにuntrackedファイルを自動的に含める(`.`または`working`のみ有効) |
|
|
130
|
+
| `--keep-alive` | false | ブラウザ切断後もサーバーを終了せず起動したままにする(Ctrl+Cで手動停止) |
|
|
124
131
|
|
|
125
132
|
## 💬 コメントシステム
|
|
126
133
|
|
|
@@ -146,6 +153,16 @@ src/components/Button.tsx:L42-L48 # この行が自動的に追加されます
|
|
|
146
153
|
この部分は不要です
|
|
147
154
|
```
|
|
148
155
|
|
|
156
|
+
## 🤖 エージェントからの呼び出し
|
|
157
|
+
|
|
158
|
+
difitを利用してユーザーにレビューを依頼するSkillを以下でインストールできます。
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
npx skills add yoshiko-pg/difit
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
エージェントがコードを編集したあと、difitサーバーを立ち上げるようになります。
|
|
165
|
+
|
|
149
166
|
## 🎨 シンタックスハイライト対応言語
|
|
150
167
|
|
|
151
168
|
- **JavaScript/TypeScript**:`.js`, `.jsx`, `.ts`, `.tsx`
|
|
@@ -201,10 +218,9 @@ pnpm run build
|
|
|
201
218
|
# テストの実行
|
|
202
219
|
pnpm test
|
|
203
220
|
|
|
204
|
-
#
|
|
205
|
-
pnpm run
|
|
221
|
+
# 型チェックとlintとフォーマット
|
|
222
|
+
pnpm run check
|
|
206
223
|
pnpm run format
|
|
207
|
-
pnpm run typecheck
|
|
208
224
|
```
|
|
209
225
|
|
|
210
226
|
### 開発ワークフロー
|
|
@@ -218,17 +234,18 @@ pnpm run typecheck
|
|
|
218
234
|
|
|
219
235
|
- **CLI**:包括的なバリデーションを備えたCommander.jsでの引数解析
|
|
220
236
|
- **バックエンド**:diff処理用のsimple-gitを備えたExpressサーバー
|
|
221
|
-
- **GitHub
|
|
237
|
+
- **GitHub統合**:GitHub CLI(`gh pr diff --patch`)によるPRパッチ取得
|
|
222
238
|
- **フロントエンド**:React 18 + TypeScript + Vite
|
|
223
239
|
- **スタイリング**:GitHubライクなダークテーマを備えたTailwind CSS v4
|
|
224
240
|
- **シンタックスハイライト**:動的言語ロードを備えたPrism.js
|
|
225
241
|
- **テスト**:同じ場所に配置されたテストファイルを使用したVitestユニットテスト
|
|
226
|
-
- **品質**:
|
|
242
|
+
- **品質**:oxlint、oxfmt、lefthookプリコミットフック
|
|
227
243
|
|
|
228
244
|
## 📋 要件
|
|
229
245
|
|
|
230
246
|
- Node.js ≥ 21.0.0
|
|
231
247
|
- レビューするコミットを含むGitリポジトリ
|
|
248
|
+
- `--pr` モード利用時は GitHub CLI(`gh`)
|
|
232
249
|
|
|
233
250
|
## 📄 ライセンス
|
|
234
251
|
|
package/README.ko.md
CHANGED
|
@@ -25,6 +25,12 @@ npm install -g difit
|
|
|
25
25
|
difit # WebUI에서 최신 커밋 diff 보기
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
AI 에이전트에서 사용할 수 있도록 설정
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx skills add yoshiko-pg/difit # 에이전트에 Skill 추가
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
## 🚀 사용법
|
|
29
35
|
|
|
30
36
|
### 기본 사용법
|
|
@@ -66,19 +72,19 @@ difit working # 미스테이징 변경 사항만
|
|
|
66
72
|
difit --pr https://github.com/owner/repo/pull/123
|
|
67
73
|
```
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
`--pr` 모드는 내부적으로 `gh pr diff --patch`를 실행해 패치를 가져옵니다.
|
|
76
|
+
|
|
77
|
+
인증은 GitHub CLI가 처리합니다:
|
|
70
78
|
|
|
71
|
-
1.
|
|
72
|
-
2.
|
|
73
|
-
3. **인증 없음**: 공개 저장소는 인증 없이 작동 (속도 제한 있음)
|
|
79
|
+
1. **한 번 로그인** (권장): `gh auth login`
|
|
80
|
+
2. **토큰 인증** (CI/비대화형 환경): `GH_TOKEN` 또는 `GITHUB_TOKEN` 설정
|
|
74
81
|
|
|
75
82
|
#### GitHub Enterprise Server
|
|
76
83
|
|
|
77
|
-
Enterprise Server PR의 경우
|
|
84
|
+
Enterprise Server PR의 경우 GitHub CLI를 Enterprise 호스트에 인증하세요:
|
|
78
85
|
|
|
79
|
-
1. `
|
|
80
|
-
2.
|
|
81
|
-
3. `GITHUB_TOKEN` 환경 변수로 설정
|
|
86
|
+
1. `gh auth login --hostname YOUR-ENTERPRISE-SERVER`
|
|
87
|
+
2. 또는 `GH_HOST=YOUR-ENTERPRISE-SERVER`와 `GH_TOKEN`/`GITHUB_TOKEN` 설정
|
|
82
88
|
|
|
83
89
|
### 표준 입력
|
|
84
90
|
|
|
@@ -121,6 +127,7 @@ git diff --cached | difit -
|
|
|
121
127
|
| `--tui` | false | WebUI 대신 터미널 UI 모드 사용 |
|
|
122
128
|
| `--clean` | false | 시작 시 모든 기존 코멘트와 열람된 파일 표시 초기화 |
|
|
123
129
|
| `--include-untracked` | false | diff에 untracked 파일 자동 포함 (`.` 또는 `working`에서만 유효) |
|
|
130
|
+
| `--keep-alive` | false | 브라우저 연결이 끊겨도 서버 유지 (Ctrl+C로 수동 종료) |
|
|
124
131
|
|
|
125
132
|
## 💬 코멘트 시스템
|
|
126
133
|
|
|
@@ -146,6 +153,16 @@ src/components/Button.tsx:L42-L48 # 이 줄은 자동으로 추가됩니다
|
|
|
146
153
|
이 부분은 불필요합니다
|
|
147
154
|
```
|
|
148
155
|
|
|
156
|
+
## 🤖 에이전트에서 호출
|
|
157
|
+
|
|
158
|
+
difit을 사용해 사용자에게 리뷰를 요청하는 Skill은 아래 명령으로 설치할 수 있습니다:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
npx skills add yoshiko-pg/difit
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
에이전트가 코드를 수정한 뒤에는 difit 서버를 실행합니다.
|
|
165
|
+
|
|
149
166
|
## 🎨 구문 강조 언어
|
|
150
167
|
|
|
151
168
|
- **JavaScript/TypeScript**: `.js`, `.jsx`, `.ts`, `.tsx`
|
|
@@ -201,10 +218,9 @@ pnpm run build
|
|
|
201
218
|
# 테스트 실행
|
|
202
219
|
pnpm test
|
|
203
220
|
|
|
204
|
-
#
|
|
205
|
-
pnpm run
|
|
221
|
+
# 타입체크와 lint와 포맷
|
|
222
|
+
pnpm run check
|
|
206
223
|
pnpm run format
|
|
207
|
-
pnpm run typecheck
|
|
208
224
|
```
|
|
209
225
|
|
|
210
226
|
### 개발 워크플로우
|
|
@@ -218,17 +234,18 @@ pnpm run typecheck
|
|
|
218
234
|
|
|
219
235
|
- **CLI**: 포괄적인 검증을 갖춘 Commander.js로 인수 구문 분석
|
|
220
236
|
- **백엔드**: diff 처리를 위한 simple-git이 포함된 Express 서버
|
|
221
|
-
- **GitHub 통합**:
|
|
237
|
+
- **GitHub 통합**: GitHub CLI(`gh pr diff --patch`) 기반 PR 패치 조회
|
|
222
238
|
- **프론트엔드**: React 18 + TypeScript + Vite
|
|
223
239
|
- **스타일링**: GitHub과 유사한 다크 테마를 갖춘 Tailwind CSS v4
|
|
224
240
|
- **구문 강조**: 동적 언어 로딩을 갖춘 Prism.js
|
|
225
241
|
- **테스트**: 동일 위치에 배치된 테스트 파일을 사용하는 Vitest 단위 테스트
|
|
226
|
-
- **품질**:
|
|
242
|
+
- **품질**: oxlint, oxfmt, lefthook 사전 커밋 훅
|
|
227
243
|
|
|
228
244
|
## 📋 요구 사항
|
|
229
245
|
|
|
230
246
|
- Node.js ≥ 21.0.0
|
|
231
247
|
- 검토할 커밋이 포함된 Git 저장소
|
|
248
|
+
- `--pr` 모드 사용 시 GitHub CLI(`gh`)
|
|
232
249
|
|
|
233
250
|
## 📄 라이선스
|
|
234
251
|
|
package/README.md
CHANGED
|
@@ -25,6 +25,12 @@ npm install -g difit
|
|
|
25
25
|
difit # View the latest commit diff in WebUI
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
Enable use from AI agents
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx skills add yoshiko-pg/difit # Add the Skill to your agent
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
## 🚀 Usage
|
|
29
35
|
|
|
30
36
|
### Basic Usage
|
|
@@ -66,19 +72,19 @@ difit working # Unstaged changes only
|
|
|
66
72
|
difit --pr https://github.com/owner/repo/pull/123
|
|
67
73
|
```
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
`--pr` mode fetches patches by running `gh pr diff --patch` under the hood.
|
|
76
|
+
|
|
77
|
+
Authentication is handled by GitHub CLI:
|
|
70
78
|
|
|
71
|
-
1. **
|
|
72
|
-
2. **
|
|
73
|
-
3. **No Authentication**: Public repositories work without authentication (rate-limited)
|
|
79
|
+
1. **Login once** (recommended): `gh auth login`
|
|
80
|
+
2. **Token-based auth** (CI/non-interactive): set `GH_TOKEN` or `GITHUB_TOKEN`
|
|
74
81
|
|
|
75
82
|
#### GitHub Enterprise Server
|
|
76
83
|
|
|
77
|
-
For Enterprise Server PRs,
|
|
84
|
+
For Enterprise Server PRs, authenticate GitHub CLI against your Enterprise host:
|
|
78
85
|
|
|
79
|
-
1.
|
|
80
|
-
2.
|
|
81
|
-
3. Set it as `GITHUB_TOKEN` environment variable
|
|
86
|
+
1. `gh auth login --hostname YOUR-ENTERPRISE-SERVER`
|
|
87
|
+
2. Or set `GH_HOST=YOUR-ENTERPRISE-SERVER` with `GH_TOKEN`/`GITHUB_TOKEN`
|
|
82
88
|
|
|
83
89
|
### Stdin
|
|
84
90
|
|
|
@@ -121,6 +127,7 @@ Stdin mode is selected with intent-first rules:
|
|
|
121
127
|
| `--tui` | false | Use terminal UI mode instead of WebUI |
|
|
122
128
|
| `--clean` | false | Clear all existing comments and viewed files on startup |
|
|
123
129
|
| `--include-untracked` | false | Automatically include untracked files in diff (only with `.` or `working`) |
|
|
130
|
+
| `--keep-alive` | false | Keep server running after browser disconnects (stop manually with Ctrl+C) |
|
|
124
131
|
|
|
125
132
|
## 💬 Comment System
|
|
126
133
|
|
|
@@ -146,6 +153,16 @@ src/components/Button.tsx:L42-L48 # This line is automatically added
|
|
|
146
153
|
This section is unnecessary
|
|
147
154
|
```
|
|
148
155
|
|
|
156
|
+
## 🤖 Calling from Agents
|
|
157
|
+
|
|
158
|
+
You can install the following Skill to request reviews from users with difit.
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
npx skills add yoshiko-pg/difit
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
After an agent edits code, it will start the difit server.
|
|
165
|
+
|
|
149
166
|
## 🎨 Syntax Highlighting Languages
|
|
150
167
|
|
|
151
168
|
- **JavaScript/TypeScript**: `.js`, `.jsx`, `.ts`, `.tsx`
|
|
@@ -201,10 +218,9 @@ pnpm run build
|
|
|
201
218
|
# Run tests
|
|
202
219
|
pnpm test
|
|
203
220
|
|
|
204
|
-
#
|
|
205
|
-
pnpm run
|
|
221
|
+
# Run typecheck, lint, and format
|
|
222
|
+
pnpm run check
|
|
206
223
|
pnpm run format
|
|
207
|
-
pnpm run typecheck
|
|
208
224
|
```
|
|
209
225
|
|
|
210
226
|
### Development Workflow
|
|
@@ -218,17 +234,18 @@ pnpm run typecheck
|
|
|
218
234
|
|
|
219
235
|
- **CLI**: Commander.js for argument parsing with comprehensive validation
|
|
220
236
|
- **Backend**: Express server with simple-git for diff processing
|
|
221
|
-
- **GitHub Integration**:
|
|
237
|
+
- **GitHub Integration**: GitHub CLI (`gh pr diff --patch`) for PR patch retrieval
|
|
222
238
|
- **Frontend**: React 18 + TypeScript + Vite
|
|
223
239
|
- **Styling**: Tailwind CSS v4 with GitHub-like dark theme
|
|
224
240
|
- **Syntax Highlighting**: Prism.js with dynamic language loading
|
|
225
241
|
- **Testing**: Vitest for unit tests with co-located test files
|
|
226
|
-
- **Quality**:
|
|
242
|
+
- **Quality**: oxlint, oxfmt, lefthook pre-commit hooks
|
|
227
243
|
|
|
228
244
|
## 📋 Requirements
|
|
229
245
|
|
|
230
246
|
- Node.js ≥ 21.0.0
|
|
231
247
|
- Git repository with commits to review
|
|
248
|
+
- GitHub CLI (`gh`) for `--pr` mode
|
|
232
249
|
|
|
233
250
|
## 📄 License
|
|
234
251
|
|
package/README.zh.md
CHANGED
|
@@ -25,6 +25,12 @@ npm install -g difit
|
|
|
25
25
|
difit # 在 WebUI 中查看最新提交的差异
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
使其可供 AI 代理使用
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx skills add yoshiko-pg/difit # 为代理添加 Skill
|
|
32
|
+
```
|
|
33
|
+
|
|
28
34
|
## 🚀 使用方法
|
|
29
35
|
|
|
30
36
|
### 基本用法
|
|
@@ -66,19 +72,19 @@ difit working # 仅未暂存的更改
|
|
|
66
72
|
difit --pr https://github.com/owner/repo/pull/123
|
|
67
73
|
```
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
`--pr` 模式会在内部执行 `gh pr diff --patch` 来获取补丁。
|
|
76
|
+
|
|
77
|
+
认证由 GitHub CLI 处理:
|
|
70
78
|
|
|
71
|
-
1.
|
|
72
|
-
2.
|
|
73
|
-
3. **无认证**:公共仓库无需认证即可工作(有速率限制)
|
|
79
|
+
1. **先登录一次**(推荐):`gh auth login`
|
|
80
|
+
2. **令牌认证**(CI/非交互环境):设置 `GH_TOKEN` 或 `GITHUB_TOKEN`
|
|
74
81
|
|
|
75
82
|
#### GitHub Enterprise Server
|
|
76
83
|
|
|
77
|
-
对于 Enterprise Server PR
|
|
84
|
+
对于 Enterprise Server PR,请先让 GitHub CLI 认证到 Enterprise 主机:
|
|
78
85
|
|
|
79
|
-
1.
|
|
80
|
-
2.
|
|
81
|
-
3. 将其设置为 `GITHUB_TOKEN` 环境变量
|
|
86
|
+
1. `gh auth login --hostname YOUR-ENTERPRISE-SERVER`
|
|
87
|
+
2. 或设置 `GH_HOST=YOUR-ENTERPRISE-SERVER`,并配置 `GH_TOKEN` / `GITHUB_TOKEN`
|
|
82
88
|
|
|
83
89
|
### 标准输入
|
|
84
90
|
|
|
@@ -121,6 +127,7 @@ git diff --cached | difit -
|
|
|
121
127
|
| `--tui` | false | 使用终端 UI 模式而不是 WebUI |
|
|
122
128
|
| `--clean` | false | 启动时清除所有现有评论和已查看的文件 |
|
|
123
129
|
| `--include-untracked` | false | 自动将 untracked 文件包含在 diff 中(仅在 `.` 或 `working` 时有效) |
|
|
130
|
+
| `--keep-alive` | false | 浏览器断开后保持服务器运行(使用 Ctrl+C 手动停止) |
|
|
124
131
|
|
|
125
132
|
## 💬 评论系统
|
|
126
133
|
|
|
@@ -146,6 +153,16 @@ src/components/Button.tsx:L42-L48 # 此行自动添加
|
|
|
146
153
|
此部分是不必要的
|
|
147
154
|
```
|
|
148
155
|
|
|
156
|
+
## 🤖 从代理调用
|
|
157
|
+
|
|
158
|
+
你可以通过以下命令安装 Skill,以便使用 difit 向用户请求审查:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
npx skills add yoshiko-pg/difit
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
代理编辑代码后,将会启动 difit 服务器。
|
|
165
|
+
|
|
149
166
|
## 🎨 语法高亮语言
|
|
150
167
|
|
|
151
168
|
- **JavaScript/TypeScript**:`.js`, `.jsx`, `.ts`, `.tsx`
|
|
@@ -201,10 +218,9 @@ pnpm run build
|
|
|
201
218
|
# 运行测试
|
|
202
219
|
pnpm test
|
|
203
220
|
|
|
204
|
-
#
|
|
205
|
-
pnpm run
|
|
221
|
+
# 运行 typecheck、lint 和格式化
|
|
222
|
+
pnpm run check
|
|
206
223
|
pnpm run format
|
|
207
|
-
pnpm run typecheck
|
|
208
224
|
```
|
|
209
225
|
|
|
210
226
|
### 开发工作流程
|
|
@@ -218,17 +234,18 @@ pnpm run typecheck
|
|
|
218
234
|
|
|
219
235
|
- **CLI**:使用 Commander.js 进行参数解析,具有全面的验证
|
|
220
236
|
- **后端**:Express 服务器配合 simple-git 进行差异处理
|
|
221
|
-
- **GitHub
|
|
237
|
+
- **GitHub 集成**:使用 GitHub CLI(`gh pr diff --patch`)获取 PR 补丁
|
|
222
238
|
- **前端**:React 18 + TypeScript + Vite
|
|
223
239
|
- **样式**:Tailwind CSS v4,带有类似 GitHub 的深色主题
|
|
224
240
|
- **语法高亮**:Prism.js 带动态语言加载
|
|
225
241
|
- **测试**:Vitest 用于单元测试,测试文件与源代码放在一起
|
|
226
|
-
- **质量**:
|
|
242
|
+
- **质量**:oxlint、oxfmt、lefthook 预提交钩子
|
|
227
243
|
|
|
228
244
|
## 📋 要求
|
|
229
245
|
|
|
230
246
|
- Node.js ≥ 21.0.0
|
|
231
247
|
- 包含要审查的提交的 Git 仓库
|
|
248
|
+
- 使用 `--pr` 模式时需要 GitHub CLI(`gh`)
|
|
232
249
|
|
|
233
250
|
## 📄 许可证
|
|
234
251
|
|
package/dist/cli/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import pkg from '../../package.json' with { type: 'json' };
|
|
|
6
6
|
import { startServer } from '../server/server.js';
|
|
7
7
|
import { DiffMode } from '../types/watch.js';
|
|
8
8
|
import { DEFAULT_DIFF_VIEW_MODE, normalizeDiffViewMode } from '../utils/diffMode.js';
|
|
9
|
-
import { shouldReadStdin, findUntrackedFiles, markFilesIntentToAdd, promptUser, validateDiffArguments,
|
|
9
|
+
import { shouldReadStdin, findUntrackedFiles, markFilesIntentToAdd, promptUser, validateDiffArguments, getPrPatch, getGitRoot, } from './utils.js';
|
|
10
10
|
function isSpecialArg(arg) {
|
|
11
11
|
return arg === 'working' || arg === 'staged' || arg === '.';
|
|
12
12
|
}
|
|
@@ -32,7 +32,7 @@ const program = new Command();
|
|
|
32
32
|
program
|
|
33
33
|
.name('difit')
|
|
34
34
|
.description('A lightweight Git diff viewer with GitHub-like interface')
|
|
35
|
-
.version(pkg.version)
|
|
35
|
+
.version(pkg.version, '-v, --version', 'output the version number')
|
|
36
36
|
.argument('[commit-ish]', 'Git commit, tag, branch, HEAD~n reference, or "working"/"staged"/"."', 'HEAD')
|
|
37
37
|
.argument('[compare-with]', 'Optional: Compare with this commit/branch (shows diff between commit-ish and compare-with)')
|
|
38
38
|
.option('--port <port>', 'preferred port (auto-assigned if occupied)', parseInt)
|
|
@@ -43,33 +43,62 @@ program
|
|
|
43
43
|
.option('--pr <url>', 'GitHub PR URL to review (e.g., https://github.com/owner/repo/pull/123)')
|
|
44
44
|
.option('--clean', 'start with a clean slate by clearing all existing comments')
|
|
45
45
|
.option('--include-untracked', 'automatically include untracked files in diff')
|
|
46
|
+
.option('--keep-alive', 'keep server running even after browser disconnects')
|
|
46
47
|
.action(async (commitish, compareWith, options) => {
|
|
47
48
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
hasTuiOption: Boolean(options.tui),
|
|
54
|
-
});
|
|
55
|
-
if (readFromStdin) {
|
|
56
|
-
// Read unified diff from stdin
|
|
57
|
-
const diffContent = await readStdin();
|
|
58
|
-
if (!diffContent.trim()) {
|
|
59
|
-
console.error('Error: No diff content received from stdin');
|
|
49
|
+
let stdinDiff;
|
|
50
|
+
let stdinReviewLabel = 'diff from stdin';
|
|
51
|
+
if (options.pr) {
|
|
52
|
+
if (commitish !== 'HEAD' || compareWith) {
|
|
53
|
+
console.error('Error: --pr option cannot be used with positional arguments');
|
|
60
54
|
process.exit(1);
|
|
61
55
|
}
|
|
62
|
-
|
|
56
|
+
if (options.tui) {
|
|
57
|
+
console.error('Error: --pr option cannot be used with --tui');
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
stdinDiff = getPrPatch(options.pr);
|
|
62
|
+
stdinReviewLabel = options.pr;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`Error resolving PR: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Check if we should read from stdin
|
|
71
|
+
const readFromStdin = shouldReadStdin({
|
|
72
|
+
commitish,
|
|
73
|
+
hasPositionalArgs: program.args.length > 0,
|
|
74
|
+
hasPrOption: false,
|
|
75
|
+
hasTuiOption: Boolean(options.tui),
|
|
76
|
+
});
|
|
77
|
+
if (readFromStdin) {
|
|
78
|
+
// Read unified diff from stdin
|
|
79
|
+
stdinDiff = await readStdin();
|
|
80
|
+
if (!stdinDiff.trim()) {
|
|
81
|
+
console.error('Error: No diff content received from stdin');
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (stdinDiff) {
|
|
87
|
+
// Start server with stdin diff (including --pr patch)
|
|
63
88
|
const { url } = await startServer({
|
|
64
|
-
stdinDiff
|
|
89
|
+
stdinDiff,
|
|
65
90
|
preferredPort: options.port,
|
|
66
91
|
host: options.host,
|
|
67
92
|
openBrowser: options.open,
|
|
68
93
|
mode: options.mode,
|
|
69
94
|
clearComments: options.clean,
|
|
95
|
+
keepAlive: options.keepAlive,
|
|
70
96
|
});
|
|
71
97
|
console.log(`\n🚀 difit server started on ${url}`);
|
|
72
|
-
console.log(`📋 Reviewing:
|
|
98
|
+
console.log(`📋 Reviewing: ${stdinReviewLabel}`);
|
|
99
|
+
if (options.keepAlive) {
|
|
100
|
+
console.log('🔒 Keep-alive mode: server will stay running after browser disconnects');
|
|
101
|
+
}
|
|
73
102
|
console.log('\nPress Ctrl+C to stop the server');
|
|
74
103
|
return;
|
|
75
104
|
}
|
|
@@ -85,26 +114,7 @@ program
|
|
|
85
114
|
// Determine target and base commitish
|
|
86
115
|
let targetCommitish = commitish;
|
|
87
116
|
let baseCommitish;
|
|
88
|
-
|
|
89
|
-
if (options.pr) {
|
|
90
|
-
if (commitish !== 'HEAD' || compareWith) {
|
|
91
|
-
console.error('Error: --pr option cannot be used with positional arguments');
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
const prCommits = await resolvePrCommits(options.pr);
|
|
96
|
-
targetCommitish = prCommits.targetCommitish;
|
|
97
|
-
baseCommitish = prCommits.baseCommitish;
|
|
98
|
-
console.log(`📋 Reviewing PR: ${options.pr}`);
|
|
99
|
-
console.log(`🎯 Target commit: ${targetCommitish.substring(0, 7)}`);
|
|
100
|
-
console.log(`📍 Base commit: ${baseCommitish.substring(0, 7)}`);
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
console.error(`Error resolving PR: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (compareWith) {
|
|
117
|
+
if (compareWith) {
|
|
108
118
|
// If compareWith is provided, use it as base
|
|
109
119
|
baseCommitish = compareWith;
|
|
110
120
|
}
|
|
@@ -143,15 +153,11 @@ program
|
|
|
143
153
|
}));
|
|
144
154
|
return;
|
|
145
155
|
}
|
|
146
|
-
|
|
147
|
-
if (!
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
console.error(`Error: ${validation.error}`);
|
|
151
|
-
process.exit(1);
|
|
152
|
-
}
|
|
156
|
+
const validation = validateDiffArguments(targetCommitish, compareWith);
|
|
157
|
+
if (!validation.valid) {
|
|
158
|
+
console.error(`Error: ${validation.error}`);
|
|
159
|
+
process.exit(1);
|
|
153
160
|
}
|
|
154
|
-
const diffMode = determineDiffMode(targetCommitish, compareWith);
|
|
155
161
|
const { url, port, isEmpty } = await startServer({
|
|
156
162
|
targetCommitish,
|
|
157
163
|
baseCommitish,
|
|
@@ -160,11 +166,15 @@ program
|
|
|
160
166
|
openBrowser: options.open,
|
|
161
167
|
mode: options.mode,
|
|
162
168
|
clearComments: options.clean,
|
|
163
|
-
|
|
169
|
+
keepAlive: options.keepAlive,
|
|
170
|
+
diffMode: determineDiffMode(targetCommitish, compareWith),
|
|
164
171
|
repoPath,
|
|
165
172
|
});
|
|
166
173
|
console.log(`\n🚀 difit server started on ${url}`);
|
|
167
174
|
console.log(`📋 Reviewing: ${targetCommitish}`);
|
|
175
|
+
if (options.keepAlive) {
|
|
176
|
+
console.log('🔒 Keep-alive mode: server will stay running after browser disconnects');
|
|
177
|
+
}
|
|
168
178
|
if (options.clean) {
|
|
169
179
|
console.log('🧹 Starting with a clean slate - all existing comments will be cleared');
|
|
170
180
|
}
|