@georgewuw/pi-chat-navi 0.1.0 → 0.1.2
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/CHANGELOG.md +16 -16
- package/LICENSE +23 -23
- package/README.md +96 -92
- package/package.json +2 -2
- package/src/index.ts +149 -149
- package/src/jump.ts +229 -229
- package/src/logic.ts +333 -329
- package/src/panel.ts +534 -534
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
本项目的版本变更记录。Pi 在包升级后会读取本文件(`package.json` 的 `version` 增长时生效)。
|
|
4
|
-
|
|
5
|
-
## [0.1.0] - 2026-11-27
|
|
6
|
-
|
|
7
|
-
### Added
|
|
8
|
-
|
|
9
|
-
- `/questions` 命令:右上角浮动面板列出当前活动上下文里的用户提问,↑↓ 选择、回车跳转。
|
|
10
|
-
- 回合分析视图:→ 或 `d` 进入,展示思考、工具调用与输出;`t` 切换仅看思维链。
|
|
11
|
-
- 宽度记忆:`/questions 50`(列数)或 `/questions 60%`(百分比)。
|
|
12
|
-
- 跳转优先使用 transcript 的 OSC 133;A 标记,失败时退回文本匹配。
|
|
13
|
-
- 作为 npm 包直接发布 TypeScript 源码:`pi.extensions` 指向 `./src/index.ts`,pi 通过 jiti 加载,安装方无需构建。
|
|
14
|
-
- npm 包名使用 `@georgewuw/pi-chat-navi`,并设置 `publishConfig.access = "public"`。
|
|
15
|
-
- 契约测试与 `pnpm run test:compat` 版本矩阵,验证对 pi TUI 内部实现的假设。
|
|
16
|
-
- 开发与发布使用 pnpm,`packageManager` 固定版本,锁文件为 `pnpm-lock.yaml`。
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
本项目的版本变更记录。Pi 在包升级后会读取本文件(`package.json` 的 `version` 增长时生效)。
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-11-27
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `/questions` 命令:右上角浮动面板列出当前活动上下文里的用户提问,↑↓ 选择、回车跳转。
|
|
10
|
+
- 回合分析视图:→ 或 `d` 进入,展示思考、工具调用与输出;`t` 切换仅看思维链。
|
|
11
|
+
- 宽度记忆:`/questions 50`(列数)或 `/questions 60%`(百分比)。
|
|
12
|
+
- 跳转优先使用 transcript 的 OSC 133;A 标记,失败时退回文本匹配。
|
|
13
|
+
- 作为 npm 包直接发布 TypeScript 源码:`pi.extensions` 指向 `./src/index.ts`,pi 通过 jiti 加载,安装方无需构建。
|
|
14
|
+
- npm 包名使用 `@georgewuw/pi-chat-navi`,并设置 `publishConfig.access = "public"`。
|
|
15
|
+
- 契约测试与 `pnpm run test:compat` 版本矩阵,验证对 pi TUI 内部实现的假设。
|
|
16
|
+
- 开发与发布使用 pnpm,`packageManager` 固定版本,锁文件为 `pnpm-lock.yaml`。
|
package/LICENSE
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 pi-chat-navi contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
---
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pi-chat-navi contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
package/README.md
CHANGED
|
@@ -1,92 +1,96 @@
|
|
|
1
|
-
# pi-chat-navi
|
|
2
|
-
|
|
3
|
-
npm 包:`@georgewuw/pi-chat-navi`
|
|
4
|
-
|
|
5
|
-
[pi coding agent](https://github.com/earendil-works/pi-coding-agent) 扩展:在 TUI 里用 `/questions` 打开「用户提问列表」浮动面板,用键盘选择后回车即可跳回会话中的任意一次提问。
|
|
6
|
-
|
|
7
|
-
## 功能
|
|
8
|
-
|
|
9
|
-
- 面板停靠在右上角,列出**当前 transcript 实际显示**的用户提问(序号 + 摘要);被压缩掉的旧提问不会出现。列表放不下时,上下会显示 `↑ more` / `↓ more`
|
|
10
|
-
- 键盘:↑↓ 选择,回车(或空格)跳转,→ 或 `d` 进入该提问的「回合分析」,Esc 关闭(回合分析内 ←/Esc 先返回列表,`t` 切换仅看思维链)
|
|
11
|
-
- 鼠标仅支持回合分析详情区的滚轮(详情区右侧显示滚动条);单击/双击/悬停均无效果
|
|
12
|
-
- 宽度:默认 60%。`/questions 50` 指定列数,`/questions 60%` 指定百分比。设置在会话内记忆;面板已打开时带参数会以新宽度重开
|
|
13
|
-
|
|
14
|
-
## 安装
|
|
15
|
-
|
|
16
|
-
从 npm 安装(推荐):
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
pi install npm:@georgewuw/pi-chat-navi # 最新版
|
|
20
|
-
pi install npm:@georgewuw/pi-chat-navi@0.1.0 # 固定版本
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
也可以从 git 或本地路径安装:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
pi install git:github.com/georgewuw/pi-chat-navi
|
|
27
|
-
pi install ./pi-chat-navi
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
安装后重启 pi,在会话里输入 `/questions` 即可。
|
|
31
|
-
|
|
32
|
-
只试用一次、不写入设置:
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
pi -e npm:@georgewuw/pi-chat-navi
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### 本地开发
|
|
39
|
-
|
|
40
|
-
本仓库使用 pnpm(`package.json` 的 `packageManager` 已固定版本,lockfile 为 `pnpm-lock.yaml`):
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
corepack enable # 首次使用:让 corepack 按 packageManager 准备 pnpm
|
|
44
|
-
pnpm install
|
|
45
|
-
pi -ne -e . # pi 用 jiti 直接加载 src/index.ts,无需构建
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
`package.json` 的 `pi.extensions` 指向 `./src/index.ts`;修改 `src/` 后重新加载即可。
|
|
49
|
-
|
|
50
|
-
## 代码结构
|
|
51
|
-
|
|
52
|
-
| 文件 | 职责 |
|
|
53
|
-
|---|---|
|
|
54
|
-
| `src/index.ts` | 注册 `/questions`,解析宽度参数,把下面三部分接起来 |
|
|
55
|
-
| `src/logic.ts` | 纯逻辑:会话条目 → 提问列表、标记序号、回合分析。不依赖 pi |
|
|
56
|
-
| `src/jump.ts` | 跳转。**所有依赖 pi TUI 内部实现的代码都在这里** |
|
|
57
|
-
| `src/panel.ts` | 面板组件:状态、键鼠、渲染。不碰会话数据和 transcript |
|
|
58
|
-
|
|
59
|
-
入口就是 `src/index.ts`:pi 通过 jiti 直接执行 `.ts`,不需要编译产物。
|
|
60
|
-
|
|
61
|
-
## 测试
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
pnpm install # 首次需要:契约测试依赖 devDependencies 里的真实 pi 包
|
|
65
|
-
pnpm run typecheck # tsc
|
|
66
|
-
pnpm test # 逻辑单测 + 契约测试(针对 devDependencies 里装的 pi 版本)
|
|
67
|
-
pnpm run test:compat # 用 npm 上最新的 pi 版本跑契约测试
|
|
68
|
-
pnpm run test:compat -- 1.6.0 latest # 指定多个版本
|
|
69
|
-
pnpm run test:compat -- --keep 1.6.0 # 保留临时目录便于排查
|
|
70
|
-
pnpm run test:compat -- --verbose 1.6.0 # 失败时打印完整测试输出
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
- `test/logic.test.
|
|
74
|
-
- `test/contract.test.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
pi
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
# pi-chat-navi
|
|
2
|
+
|
|
3
|
+
npm 包:`@georgewuw/pi-chat-navi`
|
|
4
|
+
|
|
5
|
+
[pi coding agent](https://github.com/earendil-works/pi-coding-agent) 扩展:在 TUI 里用 `/questions` 打开「用户提问列表」浮动面板,用键盘选择后回车即可跳回会话中的任意一次提问。
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
- 面板停靠在右上角,列出**当前 transcript 实际显示**的用户提问(序号 + 摘要);被压缩掉的旧提问不会出现。列表放不下时,上下会显示 `↑ more` / `↓ more`
|
|
10
|
+
- 键盘:↑↓ 选择,回车(或空格)跳转,→ 或 `d` 进入该提问的「回合分析」,Esc 关闭(回合分析内 ←/Esc 先返回列表,`t` 切换仅看思维链)
|
|
11
|
+
- 鼠标仅支持回合分析详情区的滚轮(详情区右侧显示滚动条);单击/双击/悬停均无效果
|
|
12
|
+
- 宽度:默认 60%。`/questions 50` 指定列数,`/questions 60%` 指定百分比。设置在会话内记忆;面板已打开时带参数会以新宽度重开
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
从 npm 安装(推荐):
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
pi install npm:@georgewuw/pi-chat-navi # 最新版
|
|
20
|
+
pi install npm:@georgewuw/pi-chat-navi@0.1.0 # 固定版本
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
也可以从 git 或本地路径安装:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
pi install git:github.com/georgewuw/pi-chat-navi
|
|
27
|
+
pi install ./pi-chat-navi
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
安装后重启 pi,在会话里输入 `/questions` 即可。
|
|
31
|
+
|
|
32
|
+
只试用一次、不写入设置:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
pi -e npm:@georgewuw/pi-chat-navi
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 本地开发
|
|
39
|
+
|
|
40
|
+
本仓库使用 pnpm(`package.json` 的 `packageManager` 已固定版本,lockfile 为 `pnpm-lock.yaml`):
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
corepack enable # 首次使用:让 corepack 按 packageManager 准备 pnpm
|
|
44
|
+
pnpm install
|
|
45
|
+
pi -ne -e . # pi 用 jiti 直接加载 src/index.ts,无需构建
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`package.json` 的 `pi.extensions` 指向 `./src/index.ts`;修改 `src/` 后重新加载即可。
|
|
49
|
+
|
|
50
|
+
## 代码结构
|
|
51
|
+
|
|
52
|
+
| 文件 | 职责 |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `src/index.ts` | 注册 `/questions`,解析宽度参数,把下面三部分接起来 |
|
|
55
|
+
| `src/logic.ts` | 纯逻辑:会话条目 → 提问列表、标记序号、回合分析。不依赖 pi |
|
|
56
|
+
| `src/jump.ts` | 跳转。**所有依赖 pi TUI 内部实现的代码都在这里** |
|
|
57
|
+
| `src/panel.ts` | 面板组件:状态、键鼠、渲染。不碰会话数据和 transcript |
|
|
58
|
+
|
|
59
|
+
入口就是 `src/index.ts`:pi 通过 jiti 直接执行 `.ts`,不需要编译产物。
|
|
60
|
+
|
|
61
|
+
## 测试
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
pnpm install # 首次需要:契约测试依赖 devDependencies 里的真实 pi 包
|
|
65
|
+
pnpm run typecheck # tsc 类型检查(含 test/,tsconfig 的 include 覆盖 src 与 test)
|
|
66
|
+
pnpm test # 逻辑单测 + 契约测试(针对 devDependencies 里装的 pi 版本)
|
|
67
|
+
pnpm run test:compat # 用 npm 上最新的 pi 版本跑契约测试
|
|
68
|
+
pnpm run test:compat -- 1.6.0 latest # 指定多个版本
|
|
69
|
+
pnpm run test:compat -- --keep 1.6.0 # 保留临时目录便于排查
|
|
70
|
+
pnpm run test:compat -- --verbose 1.6.0 # 失败时打印完整测试输出
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- `test/logic.test.ts`:`logic.ts` 的纯函数。
|
|
74
|
+
- `test/contract.test.ts`:测试本身也是 TypeScript,用 `node --test` 直接跑(Node 22 原生类型剥离),
|
|
75
|
+
不依赖 ts-node/tsx,也不需要先构建;同时 `pnpm run typecheck` 会把它们一起检查,
|
|
76
|
+
所以 fixture 写错字段(例如构造会话条目时拼错 `stopReason`)会在编译期就报错。
|
|
77
|
+
内容上:按 pi 的挂载方式搭一段 transcript,验证 `jump.ts` 与 `logic.ts` 对 pi 的假设:布局字段是否存在、
|
|
78
|
+
OSC 133;A 标记数量与序号是否与推算一致、标记法和文本匹配兜底是否都落在正确行。
|
|
79
|
+
pi 改了内部实现时,失败信息会指出是哪个字段或规则变了。
|
|
80
|
+
(几处 `as unknown as` 是故意的:`findTranscript` 只暴露 `jump.ts` 需要的最小接口,测试要读 `ScrollView.scrollTop`
|
|
81
|
+
和 `TuiAltScreen.currentLayout` 这类内部字段,必须显式放宽类型。)
|
|
82
|
+
- 升级 pi 前后,运行 `pnpm run test:compat`;失败时先看失败信息指出的是哪条假设:跳转相关的改 `src/jump.ts`,
|
|
83
|
+
标记数量/顺序相关(OSC 133;A 由哪些消息写入)的改 `src/logic.ts` 里镜像 pi 渲染规则的部分
|
|
84
|
+
(`assistantWritesMarker`、`renderedUserText`)。
|
|
85
|
+
- `test:compat` 与 `scripts/` 仅在本仓库内可用,不随 npm 包发布。
|
|
86
|
+
- 契约测试能证明「逻辑上的假设仍成立」,不能代替在真实 pi 里手动按一次 `/questions` 回车。
|
|
87
|
+
|
|
88
|
+
## 说明
|
|
89
|
+
|
|
90
|
+
- 列表与标记序号基于 `sessionManager.buildContextEntries()`(压缩后的活动上下文),与 transcript 渲染一致;纯图片/空白的用户消息不会渲染组件,会被跳过。
|
|
91
|
+
- 跳转优先使用 transcript 里的 OSC 133;A 标记定位;标记失效(pi 改动标记规则)时自动退回文本匹配(遍历 `UserMessageComponent`,按归一化文本 + 渲染首行出现序定位)。
|
|
92
|
+
- 跳转仍依赖 pi TUI 的内部布局对象;pi 升级若改动这些内部实现,只有跳转会失效(会提示),面板本身不受影响。
|
|
93
|
+
|
|
94
|
+
## 许可
|
|
95
|
+
|
|
96
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@georgewuw/pi-chat-navi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "pnpm@12.15.0",
|
|
6
6
|
"description": "pi coding agent extension:TUI 提问跳转面板(/questions)",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"typecheck": "tsc -p .",
|
|
36
36
|
"test:compat": "node scripts/compat.mjs",
|
|
37
|
-
"test": "node --test test/logic.test.
|
|
37
|
+
"test": "node --test test/logic.test.ts test/contract.test.ts",
|
|
38
38
|
"check": "pnpm run typecheck && pnpm test",
|
|
39
39
|
"prepublishOnly": "pnpm run check"
|
|
40
40
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,149 +1,149 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* index.ts — 扩展入口
|
|
3
|
-
*
|
|
4
|
-
* `/questions [宽度]` 打开/关闭右上角的提问列表浮动面板:
|
|
5
|
-
* - 宽度:默认 60%;/questions 50(列数)或 /questions 60%(百分比),会话内记忆;
|
|
6
|
-
* 面板已打开时带参数会以新宽度重开
|
|
7
|
-
*
|
|
8
|
-
* 本文件把三部分接起来:logic.ts(会话数据)、panel.ts(面板 UI)、jump.ts(transcript 跳转)。
|
|
9
|
-
* 面板走公开 API:ctx.ui.custom(overlay) + Component.handleMouse。
|
|
10
|
-
*/
|
|
11
|
-
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
import type { SizeValue } from "@earendil-works/pi-tui";
|
|
13
|
-
import { jumpToQuestion } from "./jump.ts";
|
|
14
|
-
import {
|
|
15
|
-
activeContextEntries,
|
|
16
|
-
buildTurnFromEntries,
|
|
17
|
-
collectQuestionsFromEntries,
|
|
18
|
-
markerOrdinalFromEntries,
|
|
19
|
-
occurrenceOf,
|
|
20
|
-
remapQuestionIndex,
|
|
21
|
-
type SessionEntryLike,
|
|
22
|
-
} from "./logic.ts";
|
|
23
|
-
import { PANEL_HEIGHT_RATIO, QuestionPanelComponent } from "./panel.ts";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 当前 transcript 实际渲染的条目。
|
|
27
|
-
* pi 只渲染 buildContextEntries() 的结果;被压缩掉的旧消息不在屏幕上,
|
|
28
|
-
* 若仍按 getBranch() 统计,序号会从压缩点开始整体偏移(跳错位置)。
|
|
29
|
-
*/
|
|
30
|
-
function activeEntries(ctx: ExtensionCommandContext): SessionEntryLike[] {
|
|
31
|
-
try {
|
|
32
|
-
const entries = ctx.sessionManager.buildContextEntries();
|
|
33
|
-
if (Array.isArray(entries)) return entries as SessionEntryLike[];
|
|
34
|
-
} catch {
|
|
35
|
-
// 旧版 pi / 异常状态:退回当前分支 + 本地压缩过滤
|
|
36
|
-
}
|
|
37
|
-
return activeContextEntries(ctx.sessionManager.getBranch() as SessionEntryLike[]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** 解析宽度参数。null:未提供;false:非法(已 notify)。 */
|
|
41
|
-
export function parseWidthArg(args: string, notify: (msg: string) => void): SizeValue | null | false {
|
|
42
|
-
const t = args.trim();
|
|
43
|
-
if (!t) return null;
|
|
44
|
-
const m = /^(\d{1,3})(%?)$/.exec(t);
|
|
45
|
-
if (!m) {
|
|
46
|
-
notify("Invalid width; usage: /questions 50 (columns) or /questions 60% (percentage)");
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const n = Number(m[1]);
|
|
50
|
-
if (m[2]) {
|
|
51
|
-
if (n < 20 || n > 100) {
|
|
52
|
-
notify("Percentage width must be between 20 and 100");
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
return `${n}%` as SizeValue;
|
|
56
|
-
}
|
|
57
|
-
if (n < 30 || n > 500) {
|
|
58
|
-
notify("Column width must be between 30 and 500");
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
return n;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export default function (pi: ExtensionAPI) {
|
|
65
|
-
// 面板打开期间非空;此时 /questions 充当「关闭」
|
|
66
|
-
let closePanel: (() => void) | null = null;
|
|
67
|
-
// 面板宽度(会话内记忆)
|
|
68
|
-
let panelWidth: SizeValue = "60%";
|
|
69
|
-
|
|
70
|
-
pi.registerCommand("questions", {
|
|
71
|
-
description:
|
|
72
|
-
"Open/close the questions panel (↑↓ select, Enter jump, → analyze; /questions 50 or /questions 60% sets width)",
|
|
73
|
-
handler: async (args, ctx) => {
|
|
74
|
-
if (ctx.mode !== "tui") {
|
|
75
|
-
ctx.ui.notify("question-panel requires interactive (tui) mode", "error");
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const parsed = parseWidthArg(args ?? "", (msg) => ctx.ui.notify(msg, "warning"));
|
|
80
|
-
if (parsed === false) return;
|
|
81
|
-
if (parsed !== null) panelWidth = parsed;
|
|
82
|
-
|
|
83
|
-
if (closePanel) {
|
|
84
|
-
closePanel();
|
|
85
|
-
if (parsed === null) return; // 无参数:纯关闭;带参数:换宽度重开
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const questions = collectQuestionsFromEntries(activeEntries(ctx));
|
|
89
|
-
if (questions.length === 0) {
|
|
90
|
-
ctx.ui.notify("No user questions in this session yet", "info");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
await ctx.ui.custom<void>(
|
|
95
|
-
(tui, theme, _kb, done) => {
|
|
96
|
-
const panel = new QuestionPanelComponent(
|
|
97
|
-
tui,
|
|
98
|
-
theme,
|
|
99
|
-
questions,
|
|
100
|
-
(index) => {
|
|
101
|
-
// 面板开着时 agent 可能继续输出或压缩:每次跳转都按当前活动上下文重新推算
|
|
102
|
-
const entries = activeEntries(ctx);
|
|
103
|
-
const current = collectQuestionsFromEntries(entries);
|
|
104
|
-
const currentIndex = remapQuestionIndex(questions, index, current);
|
|
105
|
-
if (currentIndex < 0) {
|
|
106
|
-
ctx.ui.notify("Jump failed: this question is no longer in the active context", "warning");
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const item = current[currentIndex]!;
|
|
110
|
-
const ok = jumpToQuestion(tui, {
|
|
111
|
-
markerOrdinal: markerOrdinalFromEntries(entries, currentIndex),
|
|
112
|
-
text: item.text,
|
|
113
|
-
summary: item.summary,
|
|
114
|
-
occurrence: occurrenceOf(current, currentIndex),
|
|
115
|
-
});
|
|
116
|
-
if (!ok) {
|
|
117
|
-
ctx.ui.notify("Jump failed: cannot locate transcript (pi internals may have changed)", "warning");
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
(ordinal) => {
|
|
121
|
-
const entries = activeEntries(ctx);
|
|
122
|
-
const current = collectQuestionsFromEntries(entries);
|
|
123
|
-
const currentIndex = remapQuestionIndex(questions, ordinal, current);
|
|
124
|
-
const turn = currentIndex < 0 ? null : buildTurnFromEntries(entries, currentIndex);
|
|
125
|
-
if (!turn) ctx.ui.notify("Analysis unavailable: this question is no longer in the active context", "warning");
|
|
126
|
-
return turn;
|
|
127
|
-
},
|
|
128
|
-
() => {
|
|
129
|
-
closePanel = null;
|
|
130
|
-
done(undefined);
|
|
131
|
-
},
|
|
132
|
-
);
|
|
133
|
-
closePanel = () => panel.close();
|
|
134
|
-
return panel;
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
overlay: true,
|
|
138
|
-
overlayOptions: {
|
|
139
|
-
anchor: "top-right",
|
|
140
|
-
margin: 1,
|
|
141
|
-
width: panelWidth,
|
|
142
|
-
minWidth: 36,
|
|
143
|
-
maxHeight: `${Math.round(PANEL_HEIGHT_RATIO * 100)}%`,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
);
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* index.ts — 扩展入口
|
|
3
|
+
*
|
|
4
|
+
* `/questions [宽度]` 打开/关闭右上角的提问列表浮动面板:
|
|
5
|
+
* - 宽度:默认 60%;/questions 50(列数)或 /questions 60%(百分比),会话内记忆;
|
|
6
|
+
* 面板已打开时带参数会以新宽度重开
|
|
7
|
+
*
|
|
8
|
+
* 本文件把三部分接起来:logic.ts(会话数据)、panel.ts(面板 UI)、jump.ts(transcript 跳转)。
|
|
9
|
+
* 面板走公开 API:ctx.ui.custom(overlay) + Component.handleMouse。
|
|
10
|
+
*/
|
|
11
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
+
import type { SizeValue } from "@earendil-works/pi-tui";
|
|
13
|
+
import { jumpToQuestion } from "./jump.ts";
|
|
14
|
+
import {
|
|
15
|
+
activeContextEntries,
|
|
16
|
+
buildTurnFromEntries,
|
|
17
|
+
collectQuestionsFromEntries,
|
|
18
|
+
markerOrdinalFromEntries,
|
|
19
|
+
occurrenceOf,
|
|
20
|
+
remapQuestionIndex,
|
|
21
|
+
type SessionEntryLike,
|
|
22
|
+
} from "./logic.ts";
|
|
23
|
+
import { PANEL_HEIGHT_RATIO, QuestionPanelComponent } from "./panel.ts";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 当前 transcript 实际渲染的条目。
|
|
27
|
+
* pi 只渲染 buildContextEntries() 的结果;被压缩掉的旧消息不在屏幕上,
|
|
28
|
+
* 若仍按 getBranch() 统计,序号会从压缩点开始整体偏移(跳错位置)。
|
|
29
|
+
*/
|
|
30
|
+
function activeEntries(ctx: ExtensionCommandContext): SessionEntryLike[] {
|
|
31
|
+
try {
|
|
32
|
+
const entries = ctx.sessionManager.buildContextEntries();
|
|
33
|
+
if (Array.isArray(entries)) return entries as SessionEntryLike[];
|
|
34
|
+
} catch {
|
|
35
|
+
// 旧版 pi / 异常状态:退回当前分支 + 本地压缩过滤
|
|
36
|
+
}
|
|
37
|
+
return activeContextEntries(ctx.sessionManager.getBranch() as SessionEntryLike[]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 解析宽度参数。null:未提供;false:非法(已 notify)。 */
|
|
41
|
+
export function parseWidthArg(args: string, notify: (msg: string) => void): SizeValue | null | false {
|
|
42
|
+
const t = args.trim();
|
|
43
|
+
if (!t) return null;
|
|
44
|
+
const m = /^(\d{1,3})(%?)$/.exec(t);
|
|
45
|
+
if (!m) {
|
|
46
|
+
notify("Invalid width; usage: /questions 50 (columns) or /questions 60% (percentage)");
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const n = Number(m[1]);
|
|
50
|
+
if (m[2]) {
|
|
51
|
+
if (n < 20 || n > 100) {
|
|
52
|
+
notify("Percentage width must be between 20 and 100");
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return `${n}%` as SizeValue;
|
|
56
|
+
}
|
|
57
|
+
if (n < 30 || n > 500) {
|
|
58
|
+
notify("Column width must be between 30 and 500");
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return n;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default function (pi: ExtensionAPI) {
|
|
65
|
+
// 面板打开期间非空;此时 /questions 充当「关闭」
|
|
66
|
+
let closePanel: (() => void) | null = null;
|
|
67
|
+
// 面板宽度(会话内记忆)
|
|
68
|
+
let panelWidth: SizeValue = "60%";
|
|
69
|
+
|
|
70
|
+
pi.registerCommand("questions", {
|
|
71
|
+
description:
|
|
72
|
+
"Open/close the questions panel (↑↓ select, Enter jump, → analyze; /questions 50 or /questions 60% sets width)",
|
|
73
|
+
handler: async (args, ctx) => {
|
|
74
|
+
if (ctx.mode !== "tui") {
|
|
75
|
+
ctx.ui.notify("question-panel requires interactive (tui) mode", "error");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const parsed = parseWidthArg(args ?? "", (msg) => ctx.ui.notify(msg, "warning"));
|
|
80
|
+
if (parsed === false) return;
|
|
81
|
+
if (parsed !== null) panelWidth = parsed;
|
|
82
|
+
|
|
83
|
+
if (closePanel) {
|
|
84
|
+
closePanel();
|
|
85
|
+
if (parsed === null) return; // 无参数:纯关闭;带参数:换宽度重开
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const questions = collectQuestionsFromEntries(activeEntries(ctx));
|
|
89
|
+
if (questions.length === 0) {
|
|
90
|
+
ctx.ui.notify("No user questions in this session yet", "info");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await ctx.ui.custom<void>(
|
|
95
|
+
(tui, theme, _kb, done) => {
|
|
96
|
+
const panel = new QuestionPanelComponent(
|
|
97
|
+
tui,
|
|
98
|
+
theme,
|
|
99
|
+
questions,
|
|
100
|
+
(index) => {
|
|
101
|
+
// 面板开着时 agent 可能继续输出或压缩:每次跳转都按当前活动上下文重新推算
|
|
102
|
+
const entries = activeEntries(ctx);
|
|
103
|
+
const current = collectQuestionsFromEntries(entries);
|
|
104
|
+
const currentIndex = remapQuestionIndex(questions, index, current);
|
|
105
|
+
if (currentIndex < 0) {
|
|
106
|
+
ctx.ui.notify("Jump failed: this question is no longer in the active context", "warning");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const item = current[currentIndex]!;
|
|
110
|
+
const ok = jumpToQuestion(tui, {
|
|
111
|
+
markerOrdinal: markerOrdinalFromEntries(entries, currentIndex),
|
|
112
|
+
text: item.text,
|
|
113
|
+
summary: item.summary,
|
|
114
|
+
occurrence: occurrenceOf(current, currentIndex),
|
|
115
|
+
});
|
|
116
|
+
if (!ok) {
|
|
117
|
+
ctx.ui.notify("Jump failed: cannot locate transcript (pi internals may have changed)", "warning");
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
(ordinal) => {
|
|
121
|
+
const entries = activeEntries(ctx);
|
|
122
|
+
const current = collectQuestionsFromEntries(entries);
|
|
123
|
+
const currentIndex = remapQuestionIndex(questions, ordinal, current);
|
|
124
|
+
const turn = currentIndex < 0 ? null : buildTurnFromEntries(entries, currentIndex);
|
|
125
|
+
if (!turn) ctx.ui.notify("Analysis unavailable: this question is no longer in the active context", "warning");
|
|
126
|
+
return turn;
|
|
127
|
+
},
|
|
128
|
+
() => {
|
|
129
|
+
closePanel = null;
|
|
130
|
+
done(undefined);
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
closePanel = () => panel.close();
|
|
134
|
+
return panel;
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
overlay: true,
|
|
138
|
+
overlayOptions: {
|
|
139
|
+
anchor: "top-right",
|
|
140
|
+
margin: 1,
|
|
141
|
+
width: panelWidth,
|
|
142
|
+
minWidth: 36,
|
|
143
|
+
maxHeight: `${Math.round(PANEL_HEIGHT_RATIO * 100)}%`,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
}
|