pi-x-ide 0.1.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 (55) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +138 -0
  3. package/README.zh.md +138 -0
  4. package/dist/src/pi/commands.d.ts +12 -0
  5. package/dist/src/pi/commands.js +96 -0
  6. package/dist/src/pi/commands.js.map +1 -0
  7. package/dist/src/pi/connection.d.ts +27 -0
  8. package/dist/src/pi/connection.js +136 -0
  9. package/dist/src/pi/connection.js.map +1 -0
  10. package/dist/src/pi/context.d.ts +8 -0
  11. package/dist/src/pi/context.js +66 -0
  12. package/dist/src/pi/context.js.map +1 -0
  13. package/dist/src/pi/discovery.d.ts +11 -0
  14. package/dist/src/pi/discovery.js +79 -0
  15. package/dist/src/pi/discovery.js.map +1 -0
  16. package/dist/src/pi/index.d.ts +4 -0
  17. package/dist/src/pi/index.js +182 -0
  18. package/dist/src/pi/index.js.map +1 -0
  19. package/dist/src/pi/state.d.ts +24 -0
  20. package/dist/src/pi/state.js +12 -0
  21. package/dist/src/pi/state.js.map +1 -0
  22. package/dist/src/pi/ui.d.ts +6 -0
  23. package/dist/src/pi/ui.js +84 -0
  24. package/dist/src/pi/ui.js.map +1 -0
  25. package/dist/src/shared/format.d.ts +23 -0
  26. package/dist/src/shared/format.js +84 -0
  27. package/dist/src/shared/format.js.map +1 -0
  28. package/dist/src/shared/paths.d.ts +5 -0
  29. package/dist/src/shared/paths.js +50 -0
  30. package/dist/src/shared/paths.js.map +1 -0
  31. package/dist/src/shared/protocol.d.ts +92 -0
  32. package/dist/src/shared/protocol.js +8 -0
  33. package/dist/src/shared/protocol.js.map +1 -0
  34. package/dist/src/shared/schema.d.ts +9 -0
  35. package/dist/src/shared/schema.js +94 -0
  36. package/dist/src/shared/schema.js.map +1 -0
  37. package/dist/src/shared/ws.d.ts +2 -0
  38. package/dist/src/shared/ws.js +12 -0
  39. package/dist/src/shared/ws.js.map +1 -0
  40. package/dist/test/shared.test.d.ts +1 -0
  41. package/dist/test/shared.test.js +101 -0
  42. package/dist/test/shared.test.js.map +1 -0
  43. package/package.json +55 -0
  44. package/src/pi/commands.ts +122 -0
  45. package/src/pi/connection.ts +155 -0
  46. package/src/pi/context.ts +82 -0
  47. package/src/pi/discovery.ts +88 -0
  48. package/src/pi/index.ts +190 -0
  49. package/src/pi/state.ts +29 -0
  50. package/src/pi/ui.ts +85 -0
  51. package/src/shared/format.ts +95 -0
  52. package/src/shared/paths.ts +47 -0
  53. package/src/shared/protocol.ts +107 -0
  54. package/src/shared/schema.ts +113 -0
  55. package/src/shared/ws.ts +8 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # Pi × IDE
2
+
3
+ Pi extension package for IDE selection context integration.
4
+
5
+ Automatically pushes the currently opened or selected file and text range in VS Code to the Pi TUI, submitting them as conversation context to the LLM.
6
+
7
+ ## Prerequisites
8
+
9
+ - Node.js ≥ 20
10
+ - pnpm ≥ 11 (declared as `pnpm@11.5.2` in `packageManager`)
11
+ - VS Code ≥ 1.90 (VS Code extension only)
12
+ - Pi CLI (`@earendil-works/pi-coding-agent ≥ 0.79`)
13
+
14
+ ## Install & Build
15
+
16
+ ```bash
17
+ pnpm install
18
+ pnpm build
19
+ ```
20
+
21
+ Common commands:
22
+
23
+ | Command | Description |
24
+ | --------------------- | -------------------------------------------------------------------------------- |
25
+ | `pnpm build` | Build Pi-side TypeScript → `dist/` + VS Code-side esbuild bundle → `vscode/out/` |
26
+ | `pnpm typecheck` | Type-check only (no output files) |
27
+ | `pnpm test` | Build + run unit tests |
28
+ | `pnpm package:vscode` | Package VS Code extension as VSIX |
29
+ | `pnpm vsix` | Alias for `pnpm package:vscode` |
30
+
31
+ ## Testing the VS Code Extension Locally
32
+
33
+ ### Option 1: F5 Extension Development Host (Recommended)
34
+
35
+ 1. Open the **project root** in VS Code.
36
+ 2. Go to the **Run and Debug** panel (`Ctrl+Shift+D`).
37
+ 3. Select **Run Pi x IDE VS Code Extension**.
38
+ 4. Press **F5**:
39
+ - The `preLaunchTask` will automatically run `pnpm build`.
40
+ - A new VS Code window titled `[Extension Development Host]` opens.
41
+
42
+ ### Option 2: Package VSIX and Install
43
+
44
+ ```bash
45
+ pnpm package:vscode
46
+ code --install-extension pi-x-ide-vscode-0.1.0.vsix
47
+ ```
48
+
49
+ The extension installed this way runs in all VS Code windows, independent of the F5 Extension Host.
50
+
51
+ ### Verify the Extension is Running
52
+
53
+ ```bash
54
+ ls -l ~/.pi/pi-x-ide
55
+ ```
56
+
57
+ You should see a file like `vscode-12345-48123.lock`.
58
+
59
+ If not, run **Developer: Reload Window** in VS Code.
60
+
61
+ ## Connecting to Pi
62
+
63
+ Start Pi in the **same project directory**:
64
+
65
+ ```bash
66
+ pi -e ./src/pi/index.ts
67
+ ```
68
+
69
+ The Pi TUI should display:
70
+
71
+ - Footer: `IDE: vscode ✓`
72
+ - A widget below the input box showing: IDE name, workspace, current file, selection range, and `pending/sent` status
73
+
74
+ If VS Code was started after Pi, run the following in Pi:
75
+
76
+ ```
77
+ /ide auto
78
+ ```
79
+
80
+ ## Feature Verification
81
+
82
+ ### Live Selection
83
+
84
+ Open a file in VS Code and select some text. The Pi TUI widget should update in real time:
85
+
86
+ ```
87
+ IDE: vscode ✓ src/foo.ts#L10,20 pending
88
+ ```
89
+
90
+ ### Manual Keyboard Shortcut
91
+
92
+ Select text in VS Code and press:
93
+
94
+ - Linux/Windows: `Ctrl+Alt+K`
95
+ - macOS: `Cmd+Alt+K`
96
+
97
+ The Pi input box should insert:
98
+
99
+ ```
100
+ @src/foo.ts#L10,20
101
+ ```
102
+
103
+ ### LLM Context Injection
104
+
105
+ Type a normal chat prompt in Pi. When you submit it to the LLM, the currently `pending` selected text is temporarily injected as a `context` event — it does not persist in the session history.
106
+
107
+ After submission, the TUI displays `sent`.
108
+
109
+ ## `/ide` Command Reference
110
+
111
+ | Command | Behavior |
112
+ | ------------- | ------------------------------------------------------------- |
113
+ | `/ide` | Open the TUI selector to list available IDE connections |
114
+ | `/ide status` | Show current connection, workspace, and most recent selection |
115
+ | `/ide list` | List candidate connections from the lock directory |
116
+ | `/ide auto` | Re-attempt automatic matching by `cwd` and connect |
117
+ | `/ide off` | Disconnect and disable automatic context attachment |
118
+ | `/ide attach` | Manually insert the latest selection range into the input box |
119
+
120
+ ## Lock File Protocol
121
+
122
+ After the IDE WebSocket server starts, connection information is written to `~/.pi/pi-x-ide/`.
123
+
124
+ Pi uses `ctx.cwd` to find the longest path match against `workspaceFolders` in the lock files, selecting the best-matching and most recent IDE connection.
125
+
126
+ See [docs/specs/ide-protocol.md](docs/specs/ide-protocol.md) for protocol details.
127
+
128
+ ## Release
129
+
130
+ This project uses [Release Please](https://github.com/googleapis/release-please) with [Conventional Commits](https://www.conventionalcommits.org/) to automate versioning and publishing.
131
+
132
+ See [RELEASE.md](RELEASE.md) for the full release guide.
133
+
134
+ ## VS Code Configuration
135
+
136
+ | Key | Type | Default | Description |
137
+ | -------------------- | --------------------- | --------- | --------------------------------------------- |
138
+ | `piXIde.rangeFormat` | `"comma"` \| `"dash"` | `"comma"` | File reference format for the manual shortcut |
package/README.zh.md ADDED
@@ -0,0 +1,138 @@
1
+ # Pi × IDE
2
+
3
+ Pi extension package for IDE selection context integration.
4
+
5
+ VS Code 中打开或选中的文件和文本范围,自动推送到 Pi TUI,并作为对话上下文提交给 LLM。
6
+
7
+ ## 环境依赖
8
+
9
+ - Node.js ≥ 20
10
+ - pnpm ≥ 11(`packageManager` 声明为 `pnpm@11.5.2`)
11
+ - VS Code ≥ 1.90(仅 VS Code 扩展需要)
12
+ - Pi CLI(`@earendil-works/pi-coding-agent ≥ 0.79`)
13
+
14
+ ## 安装与构建
15
+
16
+ ```bash
17
+ pnpm install
18
+ pnpm build
19
+ ```
20
+
21
+ 常用命令:
22
+
23
+ | 命令 | 说明 |
24
+ | --------------------- | --------------------------------------------------------------------------- |
25
+ | `pnpm build` | 编译 Pi 侧 TypeScript → `dist/` + VS Code 侧 esbuild bundle → `vscode/out/` |
26
+ | `pnpm typecheck` | 类型检查(不产出文件) |
27
+ | `pnpm test` | 编译 + 运行单元测试 |
28
+ | `pnpm package:vscode` | 打包 VS Code 扩展为 VSIX |
29
+ | `pnpm vsix` | `pnpm package:vscode` 的别名 |
30
+
31
+ ## 本地测试 VS Code 扩展
32
+
33
+ ### 方式一:F5 启动 Extension Development Host(推荐)
34
+
35
+ 1. 用 VS Code 打开 **项目根目录**。
36
+ 2. 进入 **Run and Debug** 面板(`Ctrl+Shift+D`)。
37
+ 3. 选择 **Run Pi x IDE VS Code Extension**。
38
+ 4. 按 **F5**:
39
+ - preLaunchTask 会自动执行 `pnpm build`。
40
+ - 打开一个标题包含 `[Extension Development Host]` 的新 VS Code 窗口。
41
+
42
+ ### 方式二:打包 VSIX 后安装
43
+
44
+ ```bash
45
+ pnpm package:vscode
46
+ code --install-extension pi-x-ide-vscode-0.1.0.vsix
47
+ ```
48
+
49
+ 这样安装的扩展在所有 VS Code 窗口中运行,不依赖 F5 Extension Host。
50
+
51
+ ### 验证扩展是否运行
52
+
53
+ ```bash
54
+ ls -l ~/.pi/pi-x-ide
55
+ ```
56
+
57
+ 应看到类似 `vscode-12345-48123.lock` 的文件。
58
+
59
+ 如果没有,在 VS Code 中执行 **Developer: Reload Window**。
60
+
61
+ ## 连接 Pi
62
+
63
+ 在 **同一个项目目录** 启动 Pi:
64
+
65
+ ```bash
66
+ pi -e ./src/pi/index.ts
67
+ ```
68
+
69
+ Pi TUI 应显示:
70
+
71
+ - Footer:`IDE: vscode ✓`
72
+ - 输入框下方 widget:IDE 名称、workspace、当前文件、选区范围、`pending/sent` 状态
73
+
74
+ 如果 VS Code 后启动,在 Pi 里执行:
75
+
76
+ ```text
77
+ /ide auto
78
+ ```
79
+
80
+ ## 功能验证
81
+
82
+ ### 实时选区
83
+
84
+ 在 VS Code 中打开文件并选中文本,Pi TUI widget 应实时显示:
85
+
86
+ ```text
87
+ IDE: vscode ✓ src/foo.ts#L10,20 pending
88
+ ```
89
+
90
+ ### 手动快捷键
91
+
92
+ 在 VS Code 中选中文本后按:
93
+
94
+ - Linux/Windows:`Ctrl+Alt+K`
95
+ - macOS:`Cmd+Alt+K`
96
+
97
+ Pi 输入框应插入:
98
+
99
+ ```text
100
+ @src/foo.ts#L10,20
101
+ ```
102
+
103
+ ### LLM 上下文注入
104
+
105
+ 在 Pi 中输入普通对话提示,提交后进行 LLM 调用时,当前 `pending` 的选中文本会临时注入 `context` 事件,不写入 session 历史。
106
+
107
+ 提交完成后 TUI 显示 `sent`。
108
+
109
+ ## `/ide` 命令参考
110
+
111
+ | 命令 | 行为 |
112
+ | ------------- | --------------------------------------- |
113
+ | `/ide` | 打开 TUI 选择器,列出可用 IDE 连接 |
114
+ | `/ide status` | 显示当前连接、workspace、最近 selection |
115
+ | `/ide list` | 列出 lock 目录中的候选连接 |
116
+ | `/ide auto` | 重新按 cwd 自动匹配并连接 |
117
+ | `/ide off` | 断开并关闭自动上下文附加 |
118
+ | `/ide attach` | 手动把最新 selection range 插入输入框 |
119
+
120
+ ## Lock file 协议
121
+
122
+ IDE WebSocket server 启动后将连接信息写入 `~/.pi/pi-x-ide/`.
123
+
124
+ Pi 通过 `ctx.cwd` 与 lock file 中的 `workspaceFolders` 做最长路径匹配,选中最匹配且最新的 IDE 连接。
125
+
126
+ 协议详情见 [docs/specs/ide-protocol.md](docs/specs/ide-protocol.md)。
127
+
128
+ ## 发布
129
+
130
+ 本项目使用 [Release Please](https://github.com/googleapis/release-please) 和 [Conventional Commits](https://www.conventionalcommits.org/) 来自动化版本管理和发布流程。
131
+
132
+ 详见 [RELEASE.md](RELEASE.md)。
133
+
134
+ ## VS Code 配置项
135
+
136
+ | 键 | 类型 | 默认值 | 说明 |
137
+ | -------------------- | --------------------- | --------- | ---------------------------- |
138
+ | `piXIde.rangeFormat` | `"comma"` \| `"dash"` | `"comma"` | 手动快捷键生成的文件引用格式 |
@@ -0,0 +1,12 @@
1
+ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent" with {
2
+ "resolution-mode": "import"
3
+ };
4
+ import type { LockFileCandidate } from "../shared/protocol";
5
+ import type { PiIdeRuntime } from "./state";
6
+ export interface IdeCommandActions {
7
+ refreshCandidates: (ctx: ExtensionCommandContext) => Promise<LockFileCandidate[]>;
8
+ connectAuto: (ctx: ExtensionCommandContext) => Promise<void>;
9
+ connectCandidate: (candidate: LockFileCandidate, ctx: ExtensionCommandContext) => Promise<void>;
10
+ disconnect: (ctx: ExtensionCommandContext, disabled?: boolean) => void;
11
+ }
12
+ export declare function registerIdeCommand(pi: ExtensionAPI, runtime: PiIdeRuntime, actions: IdeCommandActions): void;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerIdeCommand = registerIdeCommand;
4
+ const format_1 = require("../shared/format");
5
+ const ui_1 = require("./ui");
6
+ function registerIdeCommand(pi, runtime, actions) {
7
+ pi.registerCommand("ide", {
8
+ description: "Manage IDE connection and editor selection context",
9
+ getArgumentCompletions: (argumentPrefix) => {
10
+ const subcommands = [
11
+ { value: "status", label: "status", description: "Show IDE connection status" },
12
+ { value: "list", label: "list", description: "List available IDE connections" },
13
+ { value: "auto", label: "auto", description: "Auto-connect to the most recent IDE" },
14
+ { value: "off", label: "off", description: "Disable IDE integration" },
15
+ { value: "attach", label: "attach", description: "Attach latest IDE selection to the prompt" },
16
+ ];
17
+ const filtered = subcommands.filter((s) => s.value.startsWith(argumentPrefix));
18
+ return filtered.length > 0 ? filtered : null;
19
+ },
20
+ handler: async (args, ctx) => {
21
+ runtime.ctx = ctx;
22
+ const [subcommand] = args.trim().split(/\s+/, 1);
23
+ switch (subcommand || "") {
24
+ case "":
25
+ await showPicker(runtime, actions, ctx);
26
+ return;
27
+ case "status":
28
+ showStatus(runtime, ctx);
29
+ return;
30
+ case "list":
31
+ await listCandidates(actions, ctx);
32
+ return;
33
+ case "auto":
34
+ runtime.enabled = true;
35
+ await actions.connectAuto(ctx);
36
+ return;
37
+ case "off":
38
+ actions.disconnect(ctx, true);
39
+ return;
40
+ case "attach":
41
+ attachLatest(runtime, ctx);
42
+ return;
43
+ default:
44
+ ctx.ui.notify("Usage: /ide [status|list|auto|off|attach]", "warning");
45
+ }
46
+ },
47
+ });
48
+ }
49
+ async function showPicker(runtime, actions, ctx) {
50
+ const candidates = await actions.refreshCandidates(ctx);
51
+ if (candidates.length === 0) {
52
+ ctx.ui.notify("No matching IDE connections found.", "warning");
53
+ return;
54
+ }
55
+ const labels = candidates.map((candidate, index) => `${index + 1}. ${candidate.lock.name} — ${candidate.workspaceFolder}`);
56
+ labels.push("Disable IDE integration");
57
+ const choice = await ctx.ui.select("Select IDE connection", labels);
58
+ if (!choice)
59
+ return;
60
+ if (choice === "Disable IDE integration") {
61
+ actions.disconnect(ctx, true);
62
+ return;
63
+ }
64
+ const index = labels.indexOf(choice);
65
+ const candidate = candidates[index];
66
+ if (candidate) {
67
+ runtime.enabled = true;
68
+ await actions.connectCandidate(candidate, ctx);
69
+ }
70
+ }
71
+ function showStatus(runtime, ctx) {
72
+ const lines = (0, ui_1.buildWidget)(runtime, ctx.cwd) ?? ["IDE: disconnected"];
73
+ ctx.ui.notify(lines.join("\n"), runtime.connectionStatus === "error" ? "error" : "info");
74
+ }
75
+ async function listCandidates(actions, ctx) {
76
+ const candidates = await actions.refreshCandidates(ctx);
77
+ if (candidates.length === 0) {
78
+ ctx.ui.notify("No matching IDE lock files found.", "info");
79
+ return;
80
+ }
81
+ ctx.ui.notify(candidates
82
+ .map((candidate, index) => `${index + 1}. ${candidate.lock.name} ${candidate.lock.host}:${candidate.lock.port}\n ${candidate.workspaceFolder}\n ${candidate.path}`)
83
+ .join("\n"), "info");
84
+ }
85
+ function attachLatest(runtime, ctx) {
86
+ if (!runtime.latestSelection) {
87
+ ctx.ui.notify("No IDE selection is available.", "warning");
88
+ return;
89
+ }
90
+ const mention = (0, format_1.formatRangeMention)(runtime.latestSelection, { cwd: ctx.cwd });
91
+ ctx.ui.pasteToEditor(mention);
92
+ runtime.attachState = "pending";
93
+ (0, ui_1.updateIdeUi)(runtime, ctx);
94
+ ctx.ui.notify(`Attached ${mention}`, "info");
95
+ }
96
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/pi/commands.ts"],"names":[],"mappings":";;AAeA,gDA0CC;AAtDD,6CAAsD;AAGtD,6BAAgD;AAShD,SAAgB,kBAAkB,CAAC,EAAgB,EAAE,OAAqB,EAAE,OAA0B;IACpG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE;QACxB,WAAW,EAAE,oDAAoD;QACjE,sBAAsB,EAAE,CAAC,cAAsB,EAAE,EAAE;YACjD,MAAM,WAAW,GAAG;gBAClB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,4BAA4B,EAAE;gBAC/E,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,gCAAgC,EAAE;gBAC/E,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,qCAAqC,EAAE;gBACpF,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE;gBACtE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,2CAA2C,EAAE;aAC/F,CAAC;YACF,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;YAC/E,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CA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edParams, type EditorSelectionSnapshot, type LockFileCandidate, type SelectionClearedParams } from "../shared/protocol";
2
+ export interface IdeConnectionCallbacks {
3
+ onConnected?: (server: {
4
+ name: string;
5
+ version?: string;
6
+ ide?: string;
7
+ }) => void;
8
+ onDisconnected?: (reason: string) => void;
9
+ onSelectionChanged?: (snapshot: EditorSelectionSnapshot) => void;
10
+ onSelectionCleared?: (params: SelectionClearedParams) => void;
11
+ onAtMentioned?: (params: AtMentionedParams) => void;
12
+ onError?: (error: Error) => void;
13
+ }
14
+ export declare class IdeConnection {
15
+ readonly candidate: LockFileCandidate;
16
+ private readonly cwd;
17
+ private readonly callbacks;
18
+ private socket?;
19
+ private nextId;
20
+ private closedByUser;
21
+ constructor(candidate: LockFileCandidate, cwd: string, callbacks: IdeConnectionCallbacks);
22
+ get isOpen(): boolean;
23
+ connect(): Promise<void>;
24
+ disconnect(): void;
25
+ private sendInitialize;
26
+ private handleMessage;
27
+ }