pi-x-ide 1.13.0 → 1.14.0

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 (52) hide show
  1. package/README.md +102 -32
  2. package/README.zh-CN.md +95 -32
  3. package/dist/package.json +6 -21
  4. package/dist/src/pi/connection.d.ts +8 -2
  5. package/dist/src/pi/connection.js +16 -7
  6. package/dist/src/pi/connection.js.map +1 -1
  7. package/dist/src/pi/discovery.d.ts +6 -1
  8. package/dist/src/pi/discovery.js +44 -9
  9. package/dist/src/pi/discovery.js.map +1 -1
  10. package/dist/src/pi/ide-host.d.ts +17 -0
  11. package/dist/src/pi/ide-host.js +72 -0
  12. package/dist/src/pi/ide-host.js.map +1 -0
  13. package/dist/src/pi/zed.d.ts +2 -1
  14. package/dist/src/pi/zed.js +8 -36
  15. package/dist/src/pi/zed.js.map +1 -1
  16. package/dist/src/shared/config-options.d.ts +4 -0
  17. package/dist/src/shared/config-options.js +4 -0
  18. package/dist/src/shared/config-options.js.map +1 -1
  19. package/dist/src/shared/format.d.ts +2 -0
  20. package/dist/src/shared/format.js +2 -2
  21. package/dist/src/shared/format.js.map +1 -1
  22. package/dist/src/shared/lock-file.d.ts +1 -0
  23. package/dist/src/shared/lock-file.js +1 -0
  24. package/dist/src/shared/lock-file.js.map +1 -1
  25. package/dist/src/shared/paths.d.ts +11 -3
  26. package/dist/src/shared/paths.js +52 -9
  27. package/dist/src/shared/paths.js.map +1 -1
  28. package/dist/src/shared/platform.d.ts +5 -0
  29. package/dist/src/shared/platform.js +77 -0
  30. package/dist/src/shared/platform.js.map +1 -0
  31. package/dist/src/shared/protocol.d.ts +2 -1
  32. package/dist/src/shared/protocol.js +2 -0
  33. package/dist/src/shared/protocol.js.map +1 -1
  34. package/dist/src/shared/schema.js +2 -1
  35. package/dist/src/shared/schema.js.map +1 -1
  36. package/dist/test/connection.test.js +104 -0
  37. package/dist/test/connection.test.js.map +1 -1
  38. package/dist/test/shared.test.js +275 -0
  39. package/dist/test/shared.test.js.map +1 -1
  40. package/package.json +6 -21
  41. package/schemas/config.json +4 -0
  42. package/src/pi/connection.ts +20 -6
  43. package/src/pi/discovery.ts +61 -9
  44. package/src/pi/ide-host.ts +82 -0
  45. package/src/pi/zed.ts +7 -33
  46. package/src/shared/config-options.ts +5 -0
  47. package/src/shared/format.ts +10 -4
  48. package/src/shared/lock-file.ts +2 -0
  49. package/src/shared/paths.ts +73 -9
  50. package/src/shared/platform.ts +79 -0
  51. package/src/shared/protocol.ts +4 -1
  52. package/src/shared/schema.ts +4 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Pi extension package for IDE selection context integration.
4
4
 
5
- Automatically attaches the currently opened or selected file and text range from VS Code, Zed, and Neovim to the Pi TUI, submitting them as conversation context to the LLM.
5
+ Automatically attaches the currently opened or selected file and text range from VS Code, Zed, Neovim, and JetBrains IDEs to the Pi TUI, submitting them as conversation context to the LLM.
6
6
 
7
7
  ---
8
8
 
@@ -14,8 +14,6 @@ Automatically attaches the currently opened or selected file and text range from
14
14
  pi install npm:pi-x-ide
15
15
  ```
16
16
 
17
- This installs `pi-x-ide` as a global Pi extension. Pi loads it automatically on startup — no flags needed.
18
-
19
17
  ### Install the IDE Extension
20
18
 
21
19
  #### VS Code / Cursor / Windsurf
@@ -51,16 +49,22 @@ SHA-256 digest before caching it. If the download or checksum verification fails
51
49
  or no binary matches your platform, the plugin falls back to the bundled Node.js
52
50
  sidecar — Node.js is then required on PATH.
53
51
 
54
- The binary is cached under `stdpath("cache")/pi-x-ide/` and reused on subsequent
55
- starts. Plugin updates trigger a one-time re-download.
52
+ Downloaded binaries are cached under `stdpath("cache")/pi-x-ide/` and reused on
53
+ subsequent starts. The optional lazy.nvim build hook uses the bundled binary when
54
+ present; otherwise it checks the release digest on install and update,
55
+ downloading only when the cached binary is missing or stale.
56
56
 
57
57
  **lazy.nvim:**
58
58
 
59
59
  ```lua
60
60
  {
61
61
  "balaenis/pi-x-ide",
62
+ build = function(plugin)
63
+ vim.opt.rtp:prepend(plugin.dir .. "/ide-plugins/nvim")
64
+ require("pi_x_ide.download").run({ refresh = true })
65
+ end,
62
66
  init = function(plugin)
63
- vim.opt.rtp:prepend(plugin.dir .. "/nvim")
67
+ vim.opt.rtp:prepend(plugin.dir .. "/ide-plugins/nvim")
64
68
  end,
65
69
  main = "pi_x_ide",
66
70
  opts = {
@@ -69,17 +73,46 @@ starts. Plugin updates trigger a one-time re-download.
69
73
  }
70
74
  ```
71
75
 
72
- > **Note:** The `init` block manually adds the `nvim/` subdirectory to the runtime path to avoid a Lua module resolution issue with some lazy.nvim versions. The plugin options are passed through lazy.nvim's recommended `opts` field.
76
+ > **Note:** The `init` block manually adds the `ide-plugins/nvim/` subdirectory to the runtime path to avoid a Lua module resolution issue with some lazy.nvim versions. The plugin options are passed through lazy.nvim's recommended `opts` field.
77
+ >
78
+ > The optional `build` hook resolves the bundled sidecar binary when present;
79
+ > otherwise it checks the GitHub Release asset digest at install/update time
80
+ > (`:Lazy build pi-x-ide` to re-run) and downloads only when the cached binary is
81
+ > missing or stale. It is safe to omit: the plugin still downloads the binary
82
+ > lazily on first start and falls back to the Node.js sidecar if the download is
83
+ > unavailable.
73
84
 
74
85
  **Native package:**
75
86
 
76
87
  ```vim
77
- set runtimepath+=/path/to/pi-x-ide/nvim
88
+ set runtimepath+=/path/to/pi-x-ide/ide-plugins/nvim
78
89
  lua require("pi_x_ide").setup({ keymap = "<leader>pa" })
79
90
  ```
80
91
 
81
92
  See [Configuration Reference](#neovim-2) for full setup options, commands, and troubleshooting.
82
93
 
94
+ #### JetBrains IDEs
95
+
96
+ JetBrains support is provided by the plugin project under `ide-plugins/jetbrains`. The MVP is installed manually: build a local ZIP and install it through the IDE, or run it in a sandbox IDE for development.
97
+
98
+ Run a sandbox IDE:
99
+
100
+ ```bash
101
+ cd ide-plugins/jetbrains
102
+ ./gradlew runIde
103
+ ```
104
+
105
+ Build a plugin ZIP for manual installation:
106
+
107
+ ```bash
108
+ cd ide-plugins/jetbrains
109
+ ./gradlew buildPlugin
110
+ ```
111
+
112
+ The ZIP is written to `ide-plugins/jetbrains/build/distributions/`. Install it from **Settings | Plugins | ⚙ | Install Plugin from Disk...**.
113
+
114
+ JetBrains MVP support includes live active-file tracking, live selection tracking, `Ctrl+Alt+K` / **Pi x IDE: Attach Selection**, Pi-side `/ide auto`, and **Pi x IDE: Open Pi Terminal**. Diagnostic Quick Fix actions and Pi-side automatic JetBrains plugin installation are not part of the MVP.
115
+
83
116
  ### Connect Pi & Verify
84
117
 
85
118
  Start Pi in the **same project directory** as your IDE workspace:
@@ -88,7 +121,7 @@ Start Pi in the **same project directory** as your IDE workspace:
88
121
  pi
89
122
  ```
90
123
 
91
- Pi auto-loads `pi-x-ide` and connects to your IDE. The TUI should display `IDE: vscode ✓` in the footer and a widget showing the IDE name, workspace, current file, and selection range.
124
+ Pi auto-loads `pi-x-ide` and connects to your IDE. The TUI should display a connected IDE source such as `IDE: vscode ✓` or `IDE: jetbrains ✓` in the footer and a widget showing the IDE name, workspace, current file, and selection range.
92
125
 
93
126
  **Verify it works:**
94
127
 
@@ -98,11 +131,11 @@ Open a file in your IDE and select some text. The widget should update in real t
98
131
  IDE: vscode ✓ src/foo.ts#L10-L20 pending
99
132
  ```
100
133
 
101
- Attach the selection from either side: press `Ctrl+Alt+K` (Linux/Windows) or `Cmd+Alt+K` (macOS) in a VS Code-family IDE, or focus the Pi TUI and press `Ctrl+Alt+K` / run `/ide attach`. The Pi input box should insert `@src/foo.ts#L10-L20`.
134
+ Attach the selection from either side: press `Ctrl+Alt+K` (Linux/Windows) or `Cmd+Alt+K` (macOS) in a VS Code-family IDE, press `Ctrl+Alt+K` or run **Pi x IDE: Attach Selection** in JetBrains, use `:PiXIdeAttach` in Neovim, or focus the Pi TUI and press `Ctrl+Alt+K` / run `/ide attach`. The Pi input box should insert `@src/foo.ts#L10-L20`.
102
135
 
103
136
  Type a chat prompt in Pi and submit it. The selected text is injected as LLM context (does not persist in session history). After submission, the widget shows `sent`.
104
137
 
105
- For diagnostics in VS Code-family IDEs, connect Pi first, then place the cursor on an error or warning and open Quick Fix. The **Pi: Fix it** and **Pi: Send diagnostic** actions are shown only while at least one Pi client is connected. **Pi: Fix it** sends the diagnostic message, source range, nearby context lines, and related information to one connected Pi client and starts a diagnostic-analysis turn with a configurable prompt template (see [`fix_prompt`](#pi-side-configuration)). **Pi: Send diagnostic** sends the same context to one connected Pi client and pastes it into Pi's input box without starting a turn.
138
+ For diagnostics in VS Code-family IDEs, connect Pi first, then place the cursor on an error or warning and open Quick Fix. The **Pi: Fix it** and **Pi: Send diagnostic** actions are shown only while at least one Pi client is connected. **Pi: Fix it** sends the diagnostic message, source range, nearby context lines, and related information to one connected Pi client and starts a diagnostic-analysis turn with a configurable prompt template (see [`fix_prompt`](#pi-side-configuration)). **Pi: Send diagnostic** sends the same context to one connected Pi client and pastes it into Pi's input box without starting a turn. JetBrains does not provide diagnostic Quick Fix actions in the MVP.
106
139
 
107
140
  **If the connection doesn't appear:**
108
141
 
@@ -110,6 +143,19 @@ For diagnostics in VS Code-family IDEs, connect Pi first, then place the cursor
110
143
  - If the IDE was started after Pi, reload the IDE window and run `/ide auto` again.
111
144
  - Run `/ide` to manually select a connection from the list.
112
145
 
146
+ ### WSL2 IDE Discovery
147
+
148
+ VS Code Remote WSL works like a same-host setup: the extension host runs inside WSL, writes Linux-side lock files under `~/.pi/pi-x-ide/lock`, and binds the WebSocket server inside the WSL network namespace.
149
+
150
+ When Pi runs inside WSL2 and a native Windows IDE plugin is running on the Windows side, Pi also scans Windows user lock directories such as `/mnt/c/Users/<user>/.pi/pi-x-ide/lock`. New Windows-side lock files include `runningInWindows: true`; Pi uses that metadata to try the WSL default gateway before falling back to the lock file's `host` value. Windows and WSL UNC paths are normalized before workspace matching and before formatting `@file#Lx-Ly` mentions.
151
+
152
+ If your WSL networking mode, firewall, or endpoint security blocks the default gateway, set `PI_X_IDE_HOST_OVERRIDE`:
153
+
154
+ ```bash
155
+ PI_X_IDE_HOST_OVERRIDE=127.0.0.1 pi
156
+ PI_X_IDE_HOST_OVERRIDE=<windows-host-ip> pi
157
+ ```
158
+
113
159
  ### `/ide` Command Reference
114
160
 
115
161
  | Command | Behavior |
@@ -181,6 +227,7 @@ Pi-side variables can be set as real environment variables or in `~/.pi/pi-x-ide
181
227
  | ------------------------------- | ------------- | ----------------------------------------------------------------------------------- |
182
228
  | `PI_X_IDE_AUTO_INSTALL` | `1` | Auto-install VS Code extension on Pi startup |
183
229
  | `PI_X_IDE_ATTACH_SHORTCUT` | `ctrl+alt+k` | Pi TUI shortcut for `/ide attach`; set to `off`, `none`, `false`, or `0` to disable |
230
+ | `PI_X_IDE_HOST_OVERRIDE` | (unset) | Override the host Pi uses for IDE WebSocket lock files; useful for WSL2 networking |
184
231
  | `PI_X_IDE_ZED_DB` | (auto-detect) | Override path to Zed SQLite database |
185
232
  | `PI_X_IDE_ZED_POLL_INTERVAL_MS` | `1000` | Zed SQLite polling interval, clamped to 100-2000 ms |
186
233
 
@@ -194,14 +241,16 @@ See [schemas/config.json](schemas/config.json) for editor schema guidance. A [co
194
241
 
195
242
  ### Feature Parity
196
243
 
197
- | Feature | VS Code | Zed | Neovim |
198
- | ---------------------------------------------------- | ----------------------- | ---------- | ----------------------------- |
199
- | Live file tracking | ✅ Real-time push | ✅ polling | ✅ Real-time push via sidecar |
200
- | Live selection tracking | ✅ Real-time push | ✅ polling | ✅ Real-time push via sidecar |
201
- | IDE context attach shortcut | ✅ Default `Ctrl+Alt+K` | ❌ | ✅ Custom configured keymap |
202
- | Pi TUI context attach shortcut(default `Ctrl+Alt+K`) | ✅ | ✅ | ✅ |
203
- | LLM context injection | ✅ | ✅ | ✅ |
204
- | `/ide auto` | ✅ | ✅ | ✅ |
244
+ | Feature | VS Code | Zed | Neovim | JetBrains |
245
+ | ---------------------------------------------------- | ----------------------- | ---------- | ----------------------------- | ----------------------- |
246
+ | Live file tracking | ✅ Real-time push | ✅ polling | ✅ Real-time push via sidecar | ✅ Real-time push |
247
+ | Live selection tracking | ✅ Real-time push | ✅ polling | ✅ Real-time push via sidecar | ✅ Real-time push |
248
+ | IDE context attach shortcut | ✅ Default `Ctrl+Alt+K` | ❌ | ✅ Custom configured keymap | ✅ Default `Ctrl+Alt+K` |
249
+ | Pi TUI context attach shortcut(default `Ctrl+Alt+K`) | ✅ | ✅ | ✅ | ✅ |
250
+ | LLM context injection | ✅ | ✅ | ✅ | ✅ |
251
+ | `/ide auto` | ✅ | ✅ | ✅ | ✅ |
252
+ | Diagnostic Quick Fix | ✅ | ❌ | ❌ | ❌ |
253
+ | Auto-install | ✅ VS Code-family only | N/A | ❌ | ❌ |
205
254
 
206
255
  ### Lock File Protocol
207
256
 
@@ -221,6 +270,7 @@ See [docs/specs/ide-protocol.md](docs/specs/ide-protocol.md) for protocol detail
221
270
  - bun ≥ 1.3 (`packageManager` declared as `bun@1.3.14`)
222
271
  - VS Code ≥ 1.120.0 (VS Code extension only)
223
272
  - Neovim ≥ 0.9 (Neovim plugin only)
273
+ - JDK 21 (JetBrains plugin only; Gradle can download the toolchain automatically)
224
274
 
225
275
  ### Install & Build
226
276
 
@@ -229,8 +279,8 @@ Clone the repository, then build:
229
279
  ```bash
230
280
  git clone https://github.com/balaenis/pi-x-ide.git
231
281
  cd pi-x-ide
232
- bun install
233
- bun run build
282
+ mise run setup
283
+ mise run build
234
284
  ```
235
285
 
236
286
  To load the local build without installing globally:
@@ -239,15 +289,18 @@ To load the local build without installing globally:
239
289
  pi -e ./src/pi/index.ts
240
290
  ```
241
291
 
242
- All `bun run` commands have equivalent `mise run` tasks (see `mise.toml`):
292
+ All build and check commands are defined as `mise run` tasks (see `.mise/tasks/`):
243
293
 
244
- | Command | Description |
245
- | ----------------------------- | -------------------------------------------------------------------------------------------------- |
246
- | `bun run build` | Build Pi-side TypeScript → `dist/` + Neovim sidecar → `nvim/bin/` + VS Code bundle → `vscode/out/` |
247
- | `bun run typecheck` | Type-check only (no output files) |
248
- | `bun run test` | Build + run unit tests |
249
- | `bun run package:vsix` | Package VS Code extension as VSIX |
250
- | `bun run check:config-schema` | Verify `schemas/config.json` is in sync with the config registry |
294
+ | Command | Description |
295
+ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
296
+ | `mise run build` | Build Pi-side TypeScript → `dist/` + Neovim sidecar → `ide-plugins/nvim/bin/` + VS Code bundle → `ide-plugins/vscode/out/` |
297
+ | `mise run typecheck` | Type-check only (no output files) |
298
+ | `mise run test` | Build + run unit tests |
299
+ | `mise run package:vsix` | Package VS Code extension as VSIX |
300
+ | `mise run compile:jetbrains` | Compile and test the JetBrains plugin with Gradle |
301
+ | `mise run package:jetbrains` | Package the JetBrains plugin ZIP under `ide-plugins/jetbrains/build/distributions/` |
302
+ | `mise run verify:jetbrains` | Run IntelliJ Plugin Verifier for the configured target IDE |
303
+ | `mise run check:config-schema` | Verify `schemas/config.json` is in sync with the config registry |
251
304
 
252
305
  ### Testing the VS Code Extension Locally
253
306
 
@@ -257,14 +310,14 @@ All `bun run` commands have equivalent `mise run` tasks (see `mise.toml`):
257
310
  2. Go to the **Run and Debug** panel (`Ctrl+Shift+D`).
258
311
  3. Select **Run Pi x IDE VS Code Extension**.
259
312
  4. Press **F5**:
260
- - The `preLaunchTask` automatically runs `bun run build`.
313
+ - The `preLaunchTask` automatically runs `mise run build`.
261
314
  - A new VS Code window titled `[Extension Development Host]` opens.
262
315
 
263
316
  #### Option 2: Package VSIX and Install
264
317
 
265
318
  ```bash
266
- bun run package:vsix
267
- cd vscode && code --install-extension dist/pi-x-ide-$(node -p "require('./package.json').version").vsix
319
+ mise run package:vsix
320
+ cd ide-plugins/vscode && code --install-extension dist/pi-x-ide-$(node -p "require('./package.json').version").vsix
268
321
  ```
269
322
 
270
323
  The extension installed this way runs in all VS Code windows, independent of the F5 Extension Host.
@@ -277,6 +330,23 @@ ls -l ~/.pi/pi-x-ide/lock
277
330
 
278
331
  You should see a file like `vscode-12345-48123.lock`. If not, run **Developer: Reload Window** in VS Code.
279
332
 
333
+ ### Testing the JetBrains Plugin Locally
334
+
335
+ Run a sandbox IDE:
336
+
337
+ ```bash
338
+ cd ide-plugins/jetbrains
339
+ ./gradlew runIde
340
+ ```
341
+
342
+ Build the installable plugin ZIP:
343
+
344
+ ```bash
345
+ mise run package:jetbrains
346
+ ```
347
+
348
+ The ZIP is written under `ide-plugins/jetbrains/build/distributions/`. For a smoke test, open this repository in the sandbox IDE, start `pi` from the same directory, open and select text in a local file, then press `Ctrl+Alt+K` or run **Pi x IDE: Attach Selection**. Pi should receive an `@relative/path#Lx-Ly` mention.
349
+
280
350
  ### Release
281
351
 
282
352
  This project uses [Release Please](https://github.com/googleapis/release-please) with [Conventional Commits](https://www.conventionalcommits.org/) to automate versioning and publishing.
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 用于 IDE 选择上下文集成的 Pi 扩展包。
4
4
 
5
- 自动将 VS Code、Zed 和 Neovim 中当前打开或选中的文件与文本范围附加到 Pi TUI,并作为对话上下文提交给 LLM。
5
+ 自动将 VS Code、Zed、NeovimJetBrains IDE 中当前打开或选中的文件与文本范围附加到 Pi TUI,并作为对话上下文提交给 LLM。
6
6
 
7
7
  ---
8
8
 
@@ -14,8 +14,6 @@
14
14
  pi install npm:pi-x-ide
15
15
  ```
16
16
 
17
- 将 `pi-x-ide` 安装为全局 Pi 扩展,Pi 启动时自动加载,无需额外参数。
18
-
19
17
  ### 安装 IDE 扩展
20
18
 
21
19
  #### VS Code / Cursor / Windsurf
@@ -50,16 +48,20 @@ x64 或 arm64),并在写入缓存前用 release asset 的 SHA-256 digest 做
50
48
  或校验失败、或无匹配二进制时,插件降级到内置的 Node.js sidecar — 此时需要
51
49
  PATH 中有 Node.js。
52
50
 
53
- 二进制文件缓存在 `stdpath("cache")/pi-x-ide/` 目录,后续启动直接复用。插件
54
- 更新后会触发一次重新下载。
51
+ 下载的二进制文件缓存在 `stdpath("cache")/pi-x-ide/` 目录,后续启动直接复用。可选的
52
+ lazy.nvim build 钩子会优先使用插件包内的 bundled binary;如果不存在,则在安装和更新时检查 release digest,仅在缓存二进制缺失或过期时下载。
55
53
 
56
54
  **lazy.nvim:**
57
55
 
58
56
  ```lua
59
57
  {
60
58
  "balaenis/pi-x-ide",
59
+ build = function(plugin)
60
+ vim.opt.rtp:prepend(plugin.dir .. "/ide-plugins/nvim")
61
+ require("pi_x_ide.download").run({ refresh = true })
62
+ end,
61
63
  init = function(plugin)
62
- vim.opt.rtp:prepend(plugin.dir .. "/nvim")
64
+ vim.opt.rtp:prepend(plugin.dir .. "/ide-plugins/nvim")
63
65
  end,
64
66
  main = "pi_x_ide",
65
67
  opts = {
@@ -68,17 +70,41 @@ PATH 中有 Node.js。
68
70
  }
69
71
  ```
70
72
 
71
- > **注意:** `init` 块手动将 `nvim/` 子目录加入 runtime path,以规避部分版本 lazy.nvim 的 Lua 模块解析兼容性问题。插件选项通过 lazy.nvim 推荐的 `opts` 字段传入。
73
+ > **注意:** `init` 块手动将 `ide-plugins/nvim/` 子目录加入 runtime path,以规避部分版本 lazy.nvim 的 Lua 模块解析兼容性问题。插件选项通过 lazy.nvim 推荐的 `opts` 字段传入。
74
+ >
75
+ > 可选的 `build` 钩子会优先使用插件包内的 bundled sidecar 二进制;如果不存在,则在安装/更新时检查 GitHub Release asset digest(用 `:Lazy build pi-x-ide` 可重新触发),仅在缓存二进制缺失或过期时下载。该钩子可以省略:插件仍会在首次启动时按需下载二进制,下载不可用时回退到 Node.js sidecar。
72
76
 
73
77
  **原生 package:**
74
78
 
75
79
  ```vim
76
- set runtimepath+=/path/to/pi-x-ide/nvim
80
+ set runtimepath+=/path/to/pi-x-ide/ide-plugins/nvim
77
81
  lua require("pi_x_ide").setup({ keymap = "<leader>pa" })
78
82
  ```
79
83
 
80
84
  完整配置选项、命令和故障排查见 [配置参考](#neovim-2)。
81
85
 
86
+ #### JetBrains IDE
87
+
88
+ JetBrains 支持由 `ide-plugins/jetbrains` 下的插件项目提供。MVP 需要手动安装:可以构建本地 ZIP 后从 IDE 安装,也可以在开发用 sandbox IDE 中运行。
89
+
90
+ 运行 sandbox IDE:
91
+
92
+ ```bash
93
+ cd ide-plugins/jetbrains
94
+ ./gradlew runIde
95
+ ```
96
+
97
+ 构建用于手动安装的插件 ZIP:
98
+
99
+ ```bash
100
+ cd ide-plugins/jetbrains
101
+ ./gradlew buildPlugin
102
+ ```
103
+
104
+ ZIP 会输出到 `ide-plugins/jetbrains/build/distributions/`。在 JetBrains IDE 中通过 **Settings | Plugins | ⚙ | Install Plugin from Disk...** 安装。
105
+
106
+ JetBrains MVP 支持实时活跃文件追踪、实时选区追踪、`Ctrl+Alt+K` / **Pi x IDE: Attach Selection**、Pi 侧 `/ide auto`,以及 **Pi x IDE: Open Pi Terminal**。诊断 Quick Fix 和 Pi 侧自动安装 JetBrains 插件不属于 MVP 范围。
107
+
82
108
  ### 连接 Pi 并验证
83
109
 
84
110
  在 IDE workspace **同一项目目录** 启动 Pi:
@@ -87,7 +113,7 @@ lua require("pi_x_ide").setup({ keymap = "<leader>pa" })
87
113
  pi
88
114
  ```
89
115
 
90
- Pi 自动加载 `pi-x-ide` 并连接 IDE。TUI 底部应显示 `IDE: vscode ✓`,输入框下方 widget 显示 IDE 名称、workspace、当前文件和选区范围。
116
+ Pi 自动加载 `pi-x-ide` 并连接 IDE。TUI 底部应显示类似 `IDE: vscode ✓` 或 `IDE: jetbrains ✓` 的已连接 IDE source,输入框下方 widget 显示 IDE 名称、workspace、当前文件和选区范围。
91
117
 
92
118
  **验证是否正常:**
93
119
 
@@ -97,11 +123,11 @@ Pi 自动加载 `pi-x-ide` 并连接 IDE。TUI 底部应显示 `IDE: vscode ✓`
97
123
  IDE: vscode ✓ src/foo.ts#L10-L20 pending
98
124
  ```
99
125
 
100
- 可以从任一侧附加选区:在 VS Code 系列 IDE 中按 `Ctrl+Alt+K`(Linux/Windows)或 `Cmd+Alt+K`(macOS),或聚焦 Pi TUI 后按 `Ctrl+Alt+K` / 运行 `/ide attach`。Pi 输入框应插入 `@src/foo.ts#L10-L20`。
126
+ 可以从任一侧附加选区:在 VS Code 系列 IDE 中按 `Ctrl+Alt+K`(Linux/Windows)或 `Cmd+Alt+K`(macOS),在 JetBrains 中按 `Ctrl+Alt+K` 或运行 **Pi x IDE: Attach Selection**,在 Neovim 中使用 `:PiXIdeAttach`,或聚焦 Pi TUI 后按 `Ctrl+Alt+K` / 运行 `/ide attach`。Pi 输入框应插入 `@src/foo.ts#L10-L20`。
101
127
 
102
128
  在 Pi 中输入对话提示并提交,选中文本会作为 LLM 上下文注入(不写入 session 历史)。提交后 widget 显示 `sent`。
103
129
 
104
- 对于 VS Code 系列 IDE 中的诊断信息,先连接 Pi,再把光标放在 error 或 warning 上并打开 Quick Fix。只有至少一个 Pi 客户端已连接时,才会显示 **Pi: Fix it** 和 **Pi: Send diagnostic**。**Pi: Fix it** 会把诊断消息、源码范围、附近上下文行和 related information 发送给一个已连接的 Pi 客户端,并用可自定义的 prompt 模板自动开始诊断分析(参见 [`fix_prompt`](#pi-侧配置))。**Pi: Send diagnostic** 会把相同上下文发送给一个已连接的 Pi 客户端并粘贴到 Pi 输入框,不会自动开始一轮对话。
130
+ 对于 VS Code 系列 IDE 中的诊断信息,先连接 Pi,再把光标放在 error 或 warning 上并打开 Quick Fix。只有至少一个 Pi 客户端已连接时,才会显示 **Pi: Fix it** 和 **Pi: Send diagnostic**。**Pi: Fix it** 会把诊断消息、源码范围、附近上下文行和 related information 发送给一个已连接的 Pi 客户端,并用可自定义的 prompt 模板自动开始诊断分析(参见 [`fix_prompt`](#pi-侧配置))。**Pi: Send diagnostic** 会把相同上下文发送给一个已连接的 Pi 客户端并粘贴到 Pi 输入框,不会自动开始一轮对话。JetBrains MVP 不提供诊断 Quick Fix。
105
131
 
106
132
  **如果连接未出现:**
107
133
 
@@ -109,6 +135,19 @@ IDE: vscode ✓ src/foo.ts#L10-L20 pending
109
135
  - 如果 IDE 在 Pi 之后启动,reload IDE 窗口后再次运行 `/ide auto`
110
136
  - 运行 `/ide` 手动从列表中选择连接
111
137
 
138
+ ### WSL2 IDE 发现
139
+
140
+ VS Code Remote WSL 的行为等同于同主机连接:扩展宿主运行在 WSL 内部,在 Linux 侧的 `~/.pi/pi-x-ide/lock` 写入 lock file,并在 WSL 网络命名空间中绑定 WebSocket server。
141
+
142
+ 当 Pi 运行在 WSL2 中,而原生 Windows IDE 插件运行在 Windows 侧时,Pi 也会扫描 Windows 用户 lock 目录,例如 `/mnt/c/Users/<user>/.pi/pi-x-ide/lock`。新的 Windows 侧 lock file 会包含 `runningInWindows: true`;Pi 会使用该元数据优先尝试 WSL 默认网关,再回退到 lock file 中的 `host`。Windows 路径和 WSL UNC 路径会在 workspace 匹配以及格式化 `@file#Lx-Ly` mention 前规范化。
143
+
144
+ 如果你的 WSL 网络模式、防火墙或终端安全策略阻止默认网关访问,可设置 `PI_X_IDE_HOST_OVERRIDE`:
145
+
146
+ ```bash
147
+ PI_X_IDE_HOST_OVERRIDE=127.0.0.1 pi
148
+ PI_X_IDE_HOST_OVERRIDE=<windows-host-ip> pi
149
+ ```
150
+
112
151
  ### `/ide` 命令参考
113
152
 
114
153
  | 命令 | 行为 |
@@ -179,6 +218,7 @@ Pi 侧变量可设为真实环境变量或写入 `~/.pi/pi-x-ide/config.json`
179
218
  | ------------------------------- | ------------ | ------------------------------------------------------------------------- |
180
219
  | `PI_X_IDE_AUTO_INSTALL` | `1` | Pi 启动时自动安装 VS Code 扩展 |
181
220
  | `PI_X_IDE_ATTACH_SHORTCUT` | `ctrl+alt+k` | Pi TUI 的 `/ide attach` 快捷键;设为 `off`、`none`、`false` 或 `0` 可禁用 |
221
+ | `PI_X_IDE_HOST_OVERRIDE` | (未设置) | 覆盖 Pi 连接 IDE WebSocket lock file 时使用的 host;适用于 WSL2 网络场景 |
182
222
  | `PI_X_IDE_ZED_DB` | (自动检测) | 覆盖 Zed SQLite 数据库路径 |
183
223
  | `PI_X_IDE_ZED_POLL_INTERVAL_MS` | `1000` | Zed SQLite 轮询间隔,会被限制在 100-2000 ms 范围 |
184
224
 
@@ -192,14 +232,16 @@ Pi 侧变量可设为真实环境变量或写入 `~/.pi/pi-x-ide/config.json`
192
232
 
193
233
  ### 功能对比
194
234
 
195
- | 功能 | VS Code | Zed | Neovim |
196
- | ------------------------------------------------ | -------------------- | ----------- | ------------------------ |
197
- | 实时文件追踪 | ✅ 实时推送 | ✅ 1 秒轮询 | ✅ 通过 sidecar 实时推送 |
198
- | 实时选区追踪 | ✅ 实时推送 | ✅ 1 秒轮询 | ✅ 通过 sidecar 实时推送 |
199
- | IDE 上下文 attach 快捷键 | ✅ 默认 `Ctrl+Alt+K` | ❌ | ✅ 自定义快捷键 keymap |
200
- | Pi TUI 上下文 attach 快捷键(默认 `Ctrl+Alt+K`) | ✅ | ✅ | ✅ |
201
- | LLM 上下文注入 | ✅ | ✅ | ✅ |
202
- | `/ide auto` | ✅ | ✅ | ✅ |
235
+ | 功能 | VS Code | Zed | Neovim | JetBrains |
236
+ | ------------------------------------------------ | -------------------- | ----------- | ------------------------ | -------------------- |
237
+ | 实时文件追踪 | ✅ 实时推送 | ✅ 1 秒轮询 | ✅ 通过 sidecar 实时推送 | ✅ 实时推送 |
238
+ | 实时选区追踪 | ✅ 实时推送 | ✅ 1 秒轮询 | ✅ 通过 sidecar 实时推送 | ✅ 实时推送 |
239
+ | IDE 上下文 attach 快捷键 | ✅ 默认 `Ctrl+Alt+K` | ❌ | ✅ 自定义快捷键 keymap | ✅ 默认 `Ctrl+Alt+K` |
240
+ | Pi TUI 上下文 attach 快捷键(默认 `Ctrl+Alt+K`) | ✅ | ✅ | ✅ | ✅ |
241
+ | LLM 上下文注入 | ✅ | ✅ | ✅ | ✅ |
242
+ | `/ide auto` | ✅ | ✅ | ✅ | ✅ |
243
+ | 诊断 Quick Fix | ✅ | ❌ | ❌ | ❌ |
244
+ | 自动安装 | ✅ 仅 VS Code 系列 | N/A | ❌ | ❌ |
203
245
 
204
246
  ### Lock File 协议
205
247
 
@@ -219,6 +261,7 @@ Pi 通过 `ctx.cwd` 与 lock file 中的 `workspaceFolders` 做最长路径匹
219
261
  - bun ≥ 1.3(`packageManager` 声明为 `bun@1.3.14`)
220
262
  - VS Code ≥ 1.120.0(仅 VS Code 扩展需要)
221
263
  - Neovim ≥ 0.9(仅 Neovim 插件需要)
264
+ - JDK 21(仅 JetBrains 插件需要;Gradle 可自动下载 toolchain)
222
265
 
223
266
  ### 安装与构建
224
267
 
@@ -227,8 +270,8 @@ Clone 仓库后构建:
227
270
  ```bash
228
271
  git clone https://github.com/balaenis/pi-x-ide.git
229
272
  cd pi-x-ide
230
- bun install
231
- bun run build
273
+ mise run setup
274
+ mise run build
232
275
  ```
233
276
 
234
277
  加载本地构建(无需全局安装):
@@ -237,15 +280,18 @@ bun run build
237
280
  pi -e ./src/pi/index.ts
238
281
  ```
239
282
 
240
- 所有 `bun run` 命令都有等效的 `mise run` 任务(见 `mise.toml`):
283
+ 所有构建与检查命令都定义为 `mise run` 任务(见 `.mise/tasks/`):
241
284
 
242
- | 命令 | 说明 |
243
- | ----------------------------- | ----------------------------------------------------------------------------------------------- |
244
- | `bun run build` | 编译 Pi 侧 TypeScript → `dist/` + Neovim sidecar → `nvim/bin/` + VS Code bundle → `vscode/out/` |
245
- | `bun run typecheck` | 类型检查(不产出文件) |
246
- | `bun run test` | 编译 + 运行单元测试 |
247
- | `bun run package:vsix` | 打包 VS Code 扩展为 VSIX |
248
- | `bun run check:config-schema` | 验证 `schemas/config.json` 与配置注册表是否同步 |
285
+ | 命令 | 说明 |
286
+ | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
287
+ | `mise run build` | 编译 Pi 侧 TypeScript → `dist/` + Neovim sidecar → `ide-plugins/nvim/bin/` + VS Code bundle → `ide-plugins/vscode/out/` |
288
+ | `mise run typecheck` | 类型检查(不产出文件) |
289
+ | `mise run test` | 编译 + 运行单元测试 |
290
+ | `mise run package:vsix` | 打包 VS Code 扩展为 VSIX |
291
+ | `mise run compile:jetbrains` | Gradle 编译并测试 JetBrains 插件 |
292
+ | `mise run package:jetbrains` | 将 JetBrains 插件打包为 `ide-plugins/jetbrains/build/distributions/` 下的 ZIP |
293
+ | `mise run verify:jetbrains` | 对配置的目标 IDE 运行 IntelliJ Plugin Verifier |
294
+ | `mise run check:config-schema` | 验证 `schemas/config.json` 与配置注册表是否同步 |
249
295
 
250
296
  ### 本地测试 VS Code 扩展
251
297
 
@@ -255,14 +301,14 @@ pi -e ./src/pi/index.ts
255
301
  2. 进入 **Run and Debug** 面板(`Ctrl+Shift+D`)。
256
302
  3. 选择 **Run Pi x IDE VS Code Extension**。
257
303
  4. 按 **F5**:
258
- - preLaunchTask 会自动执行 `bun run build`。
304
+ - preLaunchTask 会自动执行 `mise run build`。
259
305
  - 打开一个标题包含 `[Extension Development Host]` 的新 VS Code 窗口。
260
306
 
261
307
  #### 方式二:打包 VSIX 后安装
262
308
 
263
309
  ```bash
264
- bun run package:vsix
265
- cd vscode && code --install-extension dist/pi-x-ide-$(node -p "require('./package.json').version").vsix
310
+ mise run package:vsix
311
+ cd ide-plugins/vscode && code --install-extension dist/pi-x-ide-$(node -p "require('./package.json').version").vsix
266
312
  ```
267
313
 
268
314
  这样安装的扩展在所有 VS Code 窗口中运行,不依赖 F5 Extension Host。
@@ -275,6 +321,23 @@ ls -l ~/.pi/pi-x-ide/lock
275
321
 
276
322
  应看到类似 `vscode-12345-48123.lock` 的文件。如果没有,在 VS Code 中执行 **Developer: Reload Window**。
277
323
 
324
+ ### 本地测试 JetBrains 插件
325
+
326
+ 运行 sandbox IDE:
327
+
328
+ ```bash
329
+ cd ide-plugins/jetbrains
330
+ ./gradlew runIde
331
+ ```
332
+
333
+ 构建可安装的插件 ZIP:
334
+
335
+ ```bash
336
+ mise run package:jetbrains
337
+ ```
338
+
339
+ ZIP 会输出到 `ide-plugins/jetbrains/build/distributions/`。Smoke test:在 sandbox IDE 中打开本仓库,从同一目录启动 `pi`,打开并选择一个本地文件中的文本,然后按 `Ctrl+Alt+K` 或运行 **Pi x IDE: Attach Selection**。Pi 应收到 `@relative/path#Lx-Ly` mention。
340
+
278
341
  ### 发布
279
342
 
280
343
  本项目使用 [Release Please](https://github.com/googleapis/release-please) 和 [Conventional Commits](https://www.conventionalcommits.org/) 来自动化版本管理和发布流程。
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-x-ide",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Pi extension package for IDE selection context integration.",
5
5
  "files": [
6
6
  "dist",
@@ -14,7 +14,10 @@
14
14
  "vscode",
15
15
  "zed",
16
16
  "neovim",
17
- "nvim"
17
+ "nvim",
18
+ "jetbrains",
19
+ "intellij",
20
+ "idea"
18
21
  ],
19
22
  "license": "Apache-2.0",
20
23
  "repository": {
@@ -26,7 +29,7 @@
26
29
  },
27
30
  "homepage": "https://github.com/balaenis/pi-x-ide#readme",
28
31
  "workspaces": [
29
- "vscode"
32
+ "ide-plugins/vscode"
30
33
  ],
31
34
  "packageManager": "bun@1.3.14",
32
35
  "engines": {
@@ -34,24 +37,6 @@
34
37
  },
35
38
  "type": "commonjs",
36
39
  "main": "./dist/src/pi/index.js",
37
- "scripts": {
38
- "typecheck": "tsc -p tsconfig.json --noEmit && bun run --filter './vscode' typecheck",
39
- "generate:config-schema": "bun run scripts/generate-config-schema.cjs",
40
- "check:config-schema": "bun run scripts/generate-config-schema.cjs --check",
41
- "test": "bun run check:config-schema && bun run compile && node --test dist/test/*.test.js",
42
- "lint": "eslint .",
43
- "lint:fix": "eslint . --fix",
44
- "format": "prettier --write .",
45
- "format:check": "prettier --check .",
46
- "compile": "tsc -p tsconfig.json",
47
- "compile:vsix": "bun run --filter './vscode' compile",
48
- "sync:vsix-assets": "bun run --filter './vscode' sync:assets",
49
- "package:vsix": "bun run --filter './vscode' package",
50
- "package:nvim-sidecar": "bun run scripts/build-nvim-sidecar.mjs --production",
51
- "package:nvim-sidecar:all": "bun run scripts/build-nvim-sidecar.mjs --production --target=all",
52
- "build": "bun run compile && bun run compile:vsix && bun run package:nvim-sidecar",
53
- "build:all": "bun run compile && bun run compile:vsix && bun run package:nvim-sidecar:all"
54
- },
55
40
  "dependencies": {
56
41
  "ws": "^8.21.0"
57
42
  },
@@ -2,7 +2,8 @@ import { type DiagnosticFixRequestedParams, type AtMentionedParams, type EditorS
2
2
  export declare const IDE_CONNECT_TIMEOUT_MS = 5000;
3
3
  export declare class IdeConnectionTimeoutError extends Error {
4
4
  readonly candidate: LockFileCandidate;
5
- constructor(candidate: LockFileCandidate);
5
+ readonly host: string;
6
+ constructor(candidate: LockFileCandidate, host?: string);
6
7
  }
7
8
  export interface IdeConnectionCallbacks {
8
9
  onConnected?: (server: {
@@ -17,14 +18,19 @@ export interface IdeConnectionCallbacks {
17
18
  onDiagnosticFixRequested?: (params: DiagnosticFixRequestedParams) => void;
18
19
  onError?: (error: Error) => void;
19
20
  }
21
+ export interface IdeConnectionOptions {
22
+ resolveHost?: (lock: LockFileCandidate["lock"]) => Promise<string>;
23
+ env?: NodeJS.ProcessEnv;
24
+ }
20
25
  export declare class IdeConnection {
21
26
  readonly candidate: LockFileCandidate;
22
27
  private readonly cwd;
23
28
  private readonly callbacks;
29
+ private readonly options;
24
30
  private socket?;
25
31
  private nextId;
26
32
  private closedByUser;
27
- constructor(candidate: LockFileCandidate, cwd: string, callbacks: IdeConnectionCallbacks);
33
+ constructor(candidate: LockFileCandidate, cwd: string, callbacks: IdeConnectionCallbacks, options?: IdeConnectionOptions);
28
34
  get isOpen(): boolean;
29
35
  connect(timeoutMs?: number): Promise<void>;
30
36
  disconnect(): void;