@gfgghgftgffg/rpiv-todo-lean 0.0.0-stage → 0.1.4
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/LICENSE +21 -0
- package/MAINTENANCE.md +136 -0
- package/README.md +96 -2
- package/README.zh-CN.md +86 -0
- package/index.ts +422 -0
- package/package.json +69 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kunkun9527
|
|
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.
|
package/MAINTENANCE.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# MAINTENANCE — rpiv-todo-lean
|
|
2
|
+
|
|
3
|
+
本文件记录本包与原 lean 基线的差异、锁定的上游版本、依赖的上游内部细节、升级步骤与已知限制。
|
|
4
|
+
|
|
5
|
+
## 来源与基线
|
|
6
|
+
|
|
7
|
+
- 上游扩展:`@juicesharp/rpiv-todo`(npm),作者 juicesharp,仓库
|
|
8
|
+
<https://github.com/juicesharp/rpiv-mono>(`packages/rpiv-todo`),MIT。
|
|
9
|
+
- 本包代码基线:kunkun9527 的 lean 仓库 <https://github.com/kunkun9527/rpiv-todo-lean>,
|
|
10
|
+
基线 commit `ec463cd90fbae962122fff2e0619955a8f17df1a`(tracked 文件整体复制,未复制上游代码)。
|
|
11
|
+
- 机器可读记录:仓库根 `maintenance/manifest.json`(`id: rpiv-todo-lean`)。
|
|
12
|
+
|
|
13
|
+
## 锁定的上游版本
|
|
14
|
+
|
|
15
|
+
- `@juicesharp/rpiv-todo@2.13.8`(精确固定;`dependencies`;此前为 2.13.5)。
|
|
16
|
+
- `@juicesharp/rpiv-i18n@2.13.8`(精确固定;上游仍为可选 peer,保留安装以维持本地化 UI)。
|
|
17
|
+
- 上游 2.13.8 自带传递依赖 `@juicesharp/rpiv-config@^2.13.8`(此前为 ^2.13.5;由 npm 解析,不显式固定)。
|
|
18
|
+
- Pi 宿主 peer:`@earendil-works/pi-ai`、`@earendil-works/pi-coding-agent`、`@earendil-works/pi-tui`
|
|
19
|
+
均为 `>=1.1.0`,`typebox` 为 `*`。
|
|
20
|
+
- 当前候选开发/测试依赖:Pi 1.1.0、typebox 1.3.36、jiti 2.7.0、TypeScript 7.0.2
|
|
21
|
+
(由规划阶段暂存,独立任务验证;此前为 typebox 1.3.27 / TypeScript 5.9.3)。
|
|
22
|
+
|
|
23
|
+
## 相对基线的精确改动(最小适配)
|
|
24
|
+
|
|
25
|
+
| 位置 | 改动 |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `index.ts` | 在原有 RPC/会话/覆盖层逻辑上做 Pi 1.1 宿主适配:`isStaleCtxError` 同时识别旧消息 `Session is no longer valid` 与 Pi 1.1 的 `stale after session replacement`;新增 `ctxKind`/`rpcUiContext` 保护各事件、快捷键与 `/todos` 命令的预备 `ctx.mode`/`ctx.hasUI`/`ctx.ui` 读取(真实 invalidated ctx 上这些 getter 会抛 stale);`/todos` 命令包装改为 async,在 guard 内 `await` 真实上游 handler(非 RPC 委派同样等待到完成),仅吞没识别出的 stale 拒绝(不再逃逸为 unhandled rejection),其余异步异常原样抛给宿主/调用方;RPC 覆盖层刷新排在上游完成之后。`getOrCreateRpcEntry` 改为接收已读出的 ui;`session_shutdown`/`agent_start` 及 UI 回调的兜底 catch 只忽略识别出的 stale 错误,其余异常照旧抛出。任务状态隔离、命令参数与既有委派行为不变。 |
|
|
28
|
+
| `package.json` | 改名 `@gfgghgftgffg/rpiv-todo-lean`、版本 `0.1.0`、仓库 `directory`、contributors 归属上游作者、依赖升级到 2.13.5、peer 下限改 1.1.0、devDeps 对齐;新增 `MAINTENANCE.md` 到 `files`。 |
|
|
29
|
+
| `tests/*.test.mjs` | 原有 6 个测试与断言全部保留;`wrapper`/`rpc-sessions` 顶部增加 `PI_CODING_AGENT_DIR`/session 目录隔离(不改断言)。新增 `tests/upstream-integration.test.mjs`:真实 2.13.5 reducer、`rpiv-todo-state` 持久化条目、Schema 枚举/字段与上游一致;`tests/stale-ctx.test.mjs`:真实 Pi 1.1 invalidated ctx、新旧 stale 消息在各事件处理器上的吞没、快捷键/命令行为,以及非 stale 错误的继续抛出;命令断言改为 await/`assert.rejects`,并新增真实 Pi 1.1 invalidated command ctx 上已注册 `/todos` 命令的等待结算(无 unhandled rejection)、上游异步非 stale 异常向调用方拒绝、成功路径上游先于 RPC 覆盖层刷新及非 RPC 委派等待的回归。 |
|
|
30
|
+
| `README*.md` | 重写为单仓说明、重新测量的字符代理数据与新版本号。 |
|
|
31
|
+
| `LICENSE` | 原样保留。 |
|
|
32
|
+
| `package-lock.json` | 删除;版本由单仓根 `package-lock.json` 统一锁定。 |
|
|
33
|
+
| `tsconfig.json` | 未改动(仍直接对真实上游源码做 typecheck)。 |
|
|
34
|
+
|
|
35
|
+
## 依赖的上游内部细节
|
|
36
|
+
|
|
37
|
+
- `@juicesharp/rpiv-todo` 默认导出 `(pi) => void`;工具名 `todo`(`TOOL_NAME`),操作枚举
|
|
38
|
+
`create|update|list|get|delete|clear`,字段名/`required` 与上游 `TodoParamsSchema` 一致(仅去除
|
|
39
|
+
`description` 文本)。
|
|
40
|
+
- 通过 `pi.registerTool` 拦截,`prepareArguments` 推断逻辑包装在原始 `prepareArguments` 之外。
|
|
41
|
+
- RPC 覆盖层直接使用 `@juicesharp/rpiv-todo/todo-overlay.js` 的 `TodoOverlay`,并读取/替换其
|
|
42
|
+
`lastNextId`、`completedTaskIdsPendingHide`、`hiddenCompletedTaskIds`、`getSnapshot()`、
|
|
43
|
+
`resetCompletedDisplayState()`、`setUICtx()`、`update()`、`isRegistered()`、`toggleCollapse()`、
|
|
44
|
+
`dispose()`。
|
|
45
|
+
- 会话状态使用 `@juicesharp/rpiv-todo/state/store.js` 的 `sid`/`getState`/`replaceState`/`evictSession`
|
|
46
|
+
与 `state/replay.js` 的 `replayFromBranch`。
|
|
47
|
+
- 事件与注册面:`session_start`、`tool_execution_end`、`session_compact`、`session_tree`、
|
|
48
|
+
`session_shutdown`、`agent_start`;命令 `todos`;折叠快捷键。
|
|
49
|
+
- 2.13.5 新增:状态变更时写入 `appendEntry("rpiv-todo-state", details)`,回放优先使用该自定义条目
|
|
50
|
+
(`STATE_ENTRY_TYPE`)。本包透传 `appendEntry`,无需适配。
|
|
51
|
+
- 2.13.5 起 `@juicesharp/rpiv-i18n` 为可选 peer,`index.ts` 动态导入其 `/loader`;缺失时回退英文。
|
|
52
|
+
|
|
53
|
+
## 本次审查:2.13.5 → 2.13.8
|
|
54
|
+
|
|
55
|
+
- 审查 npm 发布源码(含相关 rpiv-i18n 目录):
|
|
56
|
+
`e516242c51adace38b8dd0a3c70495d24a6e9b79` →
|
|
57
|
+
`afc21bc25f7d07cae9fb3103dc309240a16b9f49`,不是远端 HEAD
|
|
58
|
+
`2d88b79c08ce19ffeecbe85d5ee1071046b708c0`。依据为收集的 `sources.json`、新旧
|
|
59
|
+
`package.json`、两个包的 CHANGELOG 和下述新旧源码。
|
|
60
|
+
- CHANGELOG 的 2.13.6/7/8 均为空条目;核对 `tool/types.ts`、`todo.ts`、`index.ts`、
|
|
61
|
+
`todo-overlay.ts`、`config.ts`、`state/store.ts`、`state/replay.ts`、
|
|
62
|
+
`state/state-reducer.ts`、`state/i18n-bridge.ts`,这些审查面源码一致。
|
|
63
|
+
- 工具仍只有 todo;action 为 create/update/list/get/delete/clear。字段仍为 action、
|
|
64
|
+
subject、description、activeForm、status、blockedBy、addBlockedBy、removeBlockedBy、
|
|
65
|
+
owner、metadata、id、includeDeleted。required 仍为 action;create 默认 pending,
|
|
66
|
+
list 默认 includeDeleted=false,clear 重置 nextId=1。没有新增/删除工具或参数、默认值变化。
|
|
67
|
+
- 执行仍为 execute(callId, params, signal, onUpdate, ctx)。真实上游工具仍没有
|
|
68
|
+
prepareArguments;facade 的可选 hook 委派与缺省 action 推断继续成立,原始 hook 返回后
|
|
69
|
+
才做本地推断。原地去 description 不改变字段、枚举或 required。
|
|
70
|
+
- 覆盖层 lastNextId、completedTaskIdsPendingHide、hiddenCompletedTaskIds、getSnapshot
|
|
71
|
+
仍为普通 TypeScript private 而非 #private;全部依赖的方法、会话 store 函数、事件、
|
|
72
|
+
/todos 命令与折叠快捷键保持不变。持久化条目仍为 rpiv-todo-state,回放仍优先使用这些
|
|
73
|
+
自定义条目,无条目时兼容历史 todo toolResult。
|
|
74
|
+
- 相关 i18n 的 index.ts、loader.ts 和 todo 的 bridge 不变:registerLocalesFromDir 从
|
|
75
|
+
调用包的 locales 加载;scope 在 render 时读取当前语言;缺失 SDK 回退英文。
|
|
76
|
+
config.ts 对 rpiv-config 的调用签名未变;本次源码材料未包含 rpiv-config 本体,
|
|
77
|
+
传递依赖的安装与真实配置行为仍须由独立验证覆盖。
|
|
78
|
+
- 最小适配结论:仅消费规划阶段暂存的 todo/i18n 精确版本;`index.ts` 前后完全相同,
|
|
79
|
+
不改 schema、prompt、execute、RPC 会话补丁或工具身份。lean 作者 commit 前后同为
|
|
80
|
+
`ec463cd90fbae962122fff2e0619955a8f17df1a`,无新作者改动可复用或拒绝。
|
|
81
|
+
- 没有改变 API/行为,因此没有增加重复实现的测试;所有既有 schema、reducer、持久化、
|
|
82
|
+
RPC 隔离和 stale ctx 断言保留。测试名称中的 2.13.5 是原始编写基线,实际加载当前固定版本。
|
|
83
|
+
- 本阶段未运行 npm ci、npm run check、npm run contracts、npm run contracts:check、
|
|
84
|
+
node scripts/verify-production-install.mjs 或字符统计。README 保留 2.13.5 历史测量并标明
|
|
85
|
+
基线;独立任务生成新统计/快照/包装版本,manifest 的目标版本/revision 已由规划阶段暂存。
|
|
86
|
+
|
|
87
|
+
## 本次 lean 作者更新审查(引擎仍为 2.13.8)
|
|
88
|
+
|
|
89
|
+
- 精确作者入口:`ec463cd90fbae962122fff2e0619955a8f17df1a` →
|
|
90
|
+
`6c748317321725563c803504283f0f036de385e3`,两版 index.ts 完整阅读并与本地入口比较。
|
|
91
|
+
- 唯一新增执行功能为 withHostPlan:RPC create/update/delete 后读取 getState(sid(ctx)),
|
|
92
|
+
把 pending/in_progress/completed 的全量快照追加为 Plan checklist;过滤 deleted,空列表不追加。
|
|
93
|
+
clear 不在触发集合内;所有 RPC host 都会收到这些模型可见 content 文本,不仅 Codex Desktop。
|
|
94
|
+
本次不复用这项 host 专用输出扩展:它不是当前依赖兼容所需,且新增的 await 后 ctx.mode/sid 读取
|
|
95
|
+
未防失效上下文。本地保留既有 Pi 1.1 stale guard、异步命令等待和原始结果委派。
|
|
96
|
+
- 原有 schema 去描述、action 推断、RPC session map、overlay 私有字段访问、事件/命令逻辑在
|
|
97
|
+
作者两版入口中未变;本地已有更完整 stale 修复,不整体替换作者入口。无工具/字段/默认值变化。
|
|
98
|
+
- 审查作者 package.json:2.12.1 → 2.13.10,todo/i18n pins → 2.13.8;这些引擎 pins 本仓已有。
|
|
99
|
+
作者移除 files 中中文 README、改用 README_zh-CN.md、增加 RPC host plan 文档与更新 Pi 1.2
|
|
100
|
+
字符代理,不复用其打包清单、包装版本、锁文件或测量。阅读作者 wrapper 测试,已有 schema/
|
|
101
|
+
action/envelope/预算断言由本仓基线保留,不引入重复测试。
|
|
102
|
+
- npm stable gitHead 仍为 `afc21bc25f7d07cae9fb3103dc309240a16b9f49`,较新远端
|
|
103
|
+
`1ffa165c224b5489fb5774a6652ef2e1c3bc6b2a` 不替代发布源码。本次库存没有 todo 引擎
|
|
104
|
+
before/after,故不声称重审了远端引擎;已记录的内部依赖由当前 pin 与既有真实集成回归验证。
|
|
105
|
+
- check 执行本候选类型/测试/契约、生产安装、审计与字符代理;结果以工具输出为准,历史未运行
|
|
106
|
+
说明仅对应历史阶段。没有本次门面变化,不新增 todo 测试。
|
|
107
|
+
|
|
108
|
+
## 本次 lean-only 审查:基准环境文档更新
|
|
109
|
+
|
|
110
|
+
- 精确作者 before/after:`6c748317321725563c803504283f0f036de385e3` →
|
|
111
|
+
`50e485d82809009213e21c93c564f4eaf33a650c`。完整对比 index.ts、package.json 和中英文 README;
|
|
112
|
+
入口及包元数据一致,README 仅将测量环境 Pi 1.2.0 改为 1.3.0,数值未变。
|
|
113
|
+
- 无工具、参数、默认值或行为变化;schema 去描述、action 推断和 RPC overlay 内部依赖继续适用。
|
|
114
|
+
withHostPlan 在两版均已存在,先前不复用该输出扩展的决定保留;本地 stale guard 与命令等待不变。
|
|
115
|
+
- todo/i18n 仍为 2.13.8 / `afc21bc25f7d07cae9fb3103dc309240a16b9f49`;远端
|
|
116
|
+
`fc951b8d2628ccbd5dc706d07df329e85daf1edd` 未采用。本次库存仅有 lean 源码,不声称重审远端引擎。
|
|
117
|
+
- 不复制作者基准或改变宿主要求;本仓字符代理由 check 重新捕获,不宣称已验证 Pi 1.3。
|
|
118
|
+
无门面变化,不新增测试;check 实际执行既有回归、契约、类型、生产安装与审计,结果以输出为准。
|
|
119
|
+
|
|
120
|
+
## 升级步骤
|
|
121
|
+
|
|
122
|
+
1. `npm view @juicesharp/rpiv-todo version`,对比 2.12.0 基线与目标版本源码(`tool/types.ts`、
|
|
123
|
+
`todo.ts`、`todo-overlay.ts`、`index.ts`、`state/*`)。
|
|
124
|
+
2. 更新两个工作区/根 `package.json` 中的精确依赖(含 `rpiv-i18n`),`npm install --ignore-scripts` 刷新 lockfile。
|
|
125
|
+
3. 检查是否有新 action/字段:如有,确认 `prepareTodoArguments` 的推断字段表与描述仍准确;检查
|
|
126
|
+
`TodoOverlay` 的私有字段是否改名为 `#private`(会破坏覆盖层补丁);检查 `STATE_ENTRY_TYPE` 与回放格式。
|
|
127
|
+
4. `npm run contracts` 重建快照,`npm test`、`npm run typecheck`、`npm run contracts:check`、
|
|
128
|
+
`node scripts/verify-production-install.mjs`。
|
|
129
|
+
5. 更新本文件与 README 的版本号/字符代理数字;同步 `maintenance/manifest.json`。
|
|
130
|
+
|
|
131
|
+
## 已知限制
|
|
132
|
+
|
|
133
|
+
- RPC 覆盖层依赖上游 `TodoOverlay` 的非公开字段与方法;上游若改为真正 `#private` 或重命名,需要重写该适配。
|
|
134
|
+
- facade 的扁平 Schema 去除了全部字段描述,模型只能依赖字段名与枚举;如有歧义仍需 `action` 显式给出。
|
|
135
|
+
- i18n 语言包来自上游 `locales/`,本包不再单独固定其内容版本。
|
|
136
|
+
- 字符代理值 `ceil(chars / 4)` 只用于横向比较,不代表真实模型计费 token。
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gfgghgftgffg/rpiv-todo-lean
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Part of the [`amox-pi-extensions-lean`](../../README.md) monorepo. A lightweight Pi facade for
|
|
4
|
+
[`@juicesharp/rpiv-todo`](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo): the
|
|
5
|
+
complete task-management engine with a compact flat schema, preserved RPC/session/overlay behavior,
|
|
6
|
+
and per-session isolated overlays.
|
|
7
|
+
|
|
8
|
+
Original lean facade by [kunkun9527](https://github.com/kunkun9527/rpiv-todo-lean); upstream extension
|
|
9
|
+
by [juicesharp](https://github.com/juicesharp/rpiv-mono). Both are MIT-licensed; the original `LICENSE`
|
|
10
|
+
is preserved in this package.
|
|
11
|
+
|
|
12
|
+
## Core features
|
|
13
|
+
|
|
14
|
+
* Full task lifecycle: `create`, `update`, `list`, `get`, `delete`, `clear`, status transitions,
|
|
15
|
+
`blockedBy` dependencies, metadata, `/todos` command, and branch replay.
|
|
16
|
+
* Compact provider-facing schema: the native flat schema is kept; verbose field descriptions are
|
|
17
|
+
stripped and the prompt guidelines are compressed to a single line.
|
|
18
|
+
* Upstream persistence preserved: every state-changing call still appends upstream's
|
|
19
|
+
`rpiv-todo-state` custom entry so replay survives codemode-style calls.
|
|
20
|
+
* RPC/session behavior preserved: per-session state slots, per-session overlays, stale-context
|
|
21
|
+
handling, and the shortcut/command wrappers from the original lean facade are retained.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Install only this extension from the repository root (clone as shown in the root README):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
node scripts/install-extension.mjs rpiv-todo-lean
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Once published to npm, `pi install npm:@gfgghgftgffg/rpiv-todo-lean` is also available. Choose one installation method; do not load another `rpiv-todo` wrapper alongside it.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
The model sees one tool, `todo`, with actions `create`, `update`, `list`, `get`, `delete`, `clear`.
|
|
36
|
+
`action` is normally required; when it is omitted the facade infers `create` from `subject` or
|
|
37
|
+
`update` from `id` plus a mutable field, and otherwise lets upstream report the error.
|
|
38
|
+
|
|
39
|
+
## Reviewed upgrade: 2.13.5 → 2.13.8
|
|
40
|
+
|
|
41
|
+
Upstream's 2.13.6–2.13.8 changelog entries contain no tool or behavior changes. The reviewed tool
|
|
42
|
+
schema, registration/execute path, reducer, replay/store, overlay private fields, configuration
|
|
43
|
+
adapter, and i18n loader/bridge are unchanged. The lean entry remains unchanged: one `todo` tool,
|
|
44
|
+
six actions, the same action inference, and the same per-session RPC overlays. Create still defaults
|
|
45
|
+
to `pending`; list excludes tombstones unless `includeDeleted: true`; clear resets task IDs to 1.
|
|
46
|
+
The persistence key remains `rpiv-todo-state`, with legacy tool-result replay retained.
|
|
47
|
+
|
|
48
|
+
The coupled i18n pin advances to 2.13.8; upstream's transitive rpiv-config range advances to
|
|
49
|
+
`^2.13.8`. See [MAINTENANCE.md](MAINTENANCE.md) for source revisions and review limits. All existing
|
|
50
|
+
regression assertions are preserved. The current candidate check runs installation, tests, contract capture,
|
|
51
|
+
production-install verification and audits; its output is the validation record. Release requires human review.
|
|
52
|
+
|
|
53
|
+
The new lean-author RPC plan-output feature was reviewed and not adopted: it appends full task snapshots
|
|
54
|
+
to model-visible results for all RPC hosts and adds unguarded context reads after execution. The existing
|
|
55
|
+
Pi 1.1 stale guards, command ordering, result envelope and overlays are retained. Pins remain 2.13.8;
|
|
56
|
+
unpublished engine HEAD changes are not consumed. See the itemized review in MAINTENANCE.md.
|
|
57
|
+
|
|
58
|
+
## Latest lean-author review
|
|
59
|
+
|
|
60
|
+
Reviewed author revisions `6c74831` → `50e485d`. The complete adapter and package metadata are identical;
|
|
61
|
+
only the bilingual benchmark environment changes from Pi 1.2.0 to 1.3.0, with the same estimates.
|
|
62
|
+
No tools, parameters, defaults or runtime behavior change. Our todo/i18n pins stay 2.13.8 and our own
|
|
63
|
+
character measurements are refreshed by the candidate check; this does not establish Pi 1.3 compatibility.
|
|
64
|
+
The plan-output decision above is from the previous review and remains applicable to both snapshots.
|
|
65
|
+
Exact source evidence is in [MAINTENANCE.md](MAINTENANCE.md).
|
|
66
|
+
|
|
67
|
+
## Context footprint (character proxy)
|
|
68
|
+
|
|
69
|
+
<!-- amox-measurement:start -->
|
|
70
|
+
| Package | Version | Registered character proxy |
|
|
71
|
+
| --- | --- | ---: |
|
|
72
|
+
| @gfgghgftgffg/rpiv-todo-lean | 0.1.4 | 247 |
|
|
73
|
+
| @juicesharp/rpiv-todo | 2.13.8 | 882 |
|
|
74
|
+
|
|
75
|
+
Fixed ceil(characters / 4), not provider billing tokens.
|
|
76
|
+
<!-- amox-measurement:end -->
|
|
77
|
+
|
|
78
|
+
## Versions
|
|
79
|
+
|
|
80
|
+
* Wrapper: `0.1.4`
|
|
81
|
+
* Upstream runtime: pinned to `@juicesharp/rpiv-todo@2.13.8` and `@juicesharp/rpiv-i18n@2.13.8` (exact)
|
|
82
|
+
* Previous baseline testing used Pi `1.1.0`, Node `22.22.1`; candidate validation is pending in the independent job.
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
Run from the repository root: `npm ci`, `npm run check`, `npm run contracts:check`.
|
|
87
|
+
|
|
88
|
+
## Maintenance
|
|
89
|
+
|
|
90
|
+
Adaptation points, pinned upstream metadata, upgrade steps, and limitations live in
|
|
91
|
+
[MAINTENANCE.md](MAINTENANCE.md).
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT. This package wraps the MIT-licensed
|
|
96
|
+
[`@juicesharp/rpiv-todo`](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo);
|
|
97
|
+
upstream code is consumed as a pinned npm dependency and is never copied into this repository.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @gfgghgftgffg/rpiv-todo-lean
|
|
2
|
+
|
|
3
|
+
隶属于 [`amox-pi-extensions-lean`](../../README.md) 单仓。基于
|
|
4
|
+
[`@juicesharp/rpiv-todo`](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo) 的精简封装:
|
|
5
|
+
保留完整任务管理引擎,使用紧凑扁平 Schema,并保留原 lean 封装的 RPC/会话/覆盖层行为与逐会话隔离。
|
|
6
|
+
|
|
7
|
+
原 lean 封装作者 [kunkun9527](https://github.com/kunkun9527/rpiv-todo-lean),上游扩展作者
|
|
8
|
+
[juicesharp](https://github.com/juicesharp/rpiv-mono)。两者均为 MIT 协议,本包保留原始 `LICENSE`。
|
|
9
|
+
|
|
10
|
+
## 核心特性
|
|
11
|
+
|
|
12
|
+
* 完整任务生命周期:`create`、`update`、`list`、`get`、`delete`、`clear`,状态流转、`blockedBy`
|
|
13
|
+
依赖、元数据、`/todos` 命令与分支回放全部沿用上游。
|
|
14
|
+
* 精简模型侧 Schema:保留原生扁平 Schema,仅去除冗长字段描述,将 Prompt 指南压缩为一行。
|
|
15
|
+
* 保留上游持久化:每次改变状态仍写入上游的 `rpiv-todo-state` 自定义条目,codemode 等路径下的回放不受影响。
|
|
16
|
+
* 保留 RPC/会话行为:逐会话状态槽、逐会话覆盖层、失效上下文处理及快捷键/命令包装均与原 lean 封装一致。
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
从仓库根目录只安装本扩展(先按根 README 克隆仓库):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
node scripts/install-extension.mjs rpiv-todo-lean
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
已发布到 npm 后,也可用 `pi install npm:@gfgghgftgffg/rpiv-todo-lean`。两种方式只选一种,请勿与其它 `rpiv-todo` 包装扩展同时加载。
|
|
27
|
+
|
|
28
|
+
## 使用方法
|
|
29
|
+
|
|
30
|
+
模型仅看到一个 `todo` 工具,操作包括 `create`、`update`、`list`、`get`、`delete`、`clear`。
|
|
31
|
+
通常需要显式传入 `action`;省略时封装会依据 `subject` 推断 `create`,或依据 `id` 加可变字段推断
|
|
32
|
+
`update`,其余情况交由上游报错。
|
|
33
|
+
|
|
34
|
+
## 本次审查:2.13.5 → 2.13.8
|
|
35
|
+
|
|
36
|
+
上游 2.13.6–2.13.8 的 CHANGELOG 条目没有列出工具或行为变化。核对工具 Schema、注册/执行路径、
|
|
37
|
+
reducer、回放/store、覆盖层私有字段、配置适配器和 i18n loader/bridge 后,这些审查面源码保持一致。
|
|
38
|
+
lean 入口无需修改:仍为一个 `todo` 工具、六个 action、同样的 action 推断与逐会话 RPC 覆盖层。
|
|
39
|
+
create 仍默认 `pending`;list 默认排除 deleted tombstone,`includeDeleted: true` 可包含;clear 重置 ID 为 1。
|
|
40
|
+
持久化键仍为 `rpiv-todo-state`,继续兼容历史 toolResult 回放。
|
|
41
|
+
|
|
42
|
+
配套 i18n 固定版本同步到 2.13.8,上游传递依赖 rpiv-config 范围同步到 `^2.13.8`。
|
|
43
|
+
源码 revision 与审查边界见 [MAINTENANCE.md](MAINTENANCE.md),既有回归断言全部保留。
|
|
44
|
+
本次候选 check 实际执行安装、测试、契约捕获、生产安装与审计,结果以工具输出为准;发版仍需人工审查。
|
|
45
|
+
|
|
46
|
+
已审查作者新增 RPC Plan 输出但未复用:它向所有 RPC host 的模型可见结果追加全量任务快照,且在执行后
|
|
47
|
+
新增未保护的上下文读取。本仓保留 Pi 1.1 stale guard、命令等待顺序、结果封装与覆盖层。
|
|
48
|
+
引擎 pins 仍为 2.13.8,不消费未发布的远端 HEAD;逐项决定见 MAINTENANCE.md。
|
|
49
|
+
|
|
50
|
+
## 最新 lean 作者审查
|
|
51
|
+
|
|
52
|
+
已审查作者 `6c74831` → `50e485d`:完整入口和包元数据一致,中英文基准文档仅将 Pi 1.2.0
|
|
53
|
+
改为 1.3.0,估算数值未变。无工具、参数、默认值或运行行为变化;todo/i18n 仍锁定 2.13.8。
|
|
54
|
+
上文 Plan 输出决定属于此前审查,两版均已包含该实现。本仓字符代理由候选 check 重新统计,
|
|
55
|
+
这不代表已验证 Pi 1.3 兼容性;精确源码证据见 [MAINTENANCE.md](MAINTENANCE.md)。
|
|
56
|
+
|
|
57
|
+
## 上下文占用(字符代理)
|
|
58
|
+
|
|
59
|
+
<!-- amox-measurement:start -->
|
|
60
|
+
| Package | Version | Registered character proxy |
|
|
61
|
+
| --- | --- | ---: |
|
|
62
|
+
| @gfgghgftgffg/rpiv-todo-lean | 0.1.4 | 247 |
|
|
63
|
+
| @juicesharp/rpiv-todo | 2.13.8 | 882 |
|
|
64
|
+
|
|
65
|
+
Fixed ceil(characters / 4), not provider billing tokens.
|
|
66
|
+
<!-- amox-measurement:end -->
|
|
67
|
+
|
|
68
|
+
## 版本
|
|
69
|
+
|
|
70
|
+
* 包装层:`0.1.4`
|
|
71
|
+
* 上游运行时:锁定 `@juicesharp/rpiv-todo@2.13.8` 与 `@juicesharp/rpiv-i18n@2.13.8`(精确版本)
|
|
72
|
+
* 此前基线测试使用 Pi `1.1.0`、Node `22.22.1`;本次候选等待独立任务验证。
|
|
73
|
+
|
|
74
|
+
## 开发
|
|
75
|
+
|
|
76
|
+
在仓库根目录运行:`npm ci`、`npm run check`、`npm run contracts:check`。
|
|
77
|
+
|
|
78
|
+
## 维护说明
|
|
79
|
+
|
|
80
|
+
适配点、上游元数据、升级步骤与限制见 [MAINTENANCE.md](MAINTENANCE.md)。
|
|
81
|
+
|
|
82
|
+
## 协议与致谢
|
|
83
|
+
|
|
84
|
+
MIT。本项目封装 MIT 协议的
|
|
85
|
+
[`@juicesharp/rpiv-todo`](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo);
|
|
86
|
+
上游代码以固定 npm 依赖方式使用,未复制进本仓库。
|
package/index.ts
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import todo from "@juicesharp/rpiv-todo";
|
|
3
|
+
import { replayFromBranch } from "@juicesharp/rpiv-todo/state/replay.js";
|
|
4
|
+
import { evictSession, getState, replaceState, sid } from "@juicesharp/rpiv-todo/state/store.js";
|
|
5
|
+
import { TOOL_NAME } from "@juicesharp/rpiv-todo/todo.js";
|
|
6
|
+
import { TodoOverlay } from "@juicesharp/rpiv-todo/todo-overlay.js";
|
|
7
|
+
|
|
8
|
+
const COLLAPSED_DISPLAY_SERVICE = Symbol.for(
|
|
9
|
+
"@local/pi-collapsed-tools.display-service.v1",
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
type CollapsedDisplayTool = { name: string };
|
|
13
|
+
type CollapsedDisplayService = {
|
|
14
|
+
readonly version: 1;
|
|
15
|
+
decorate<T extends CollapsedDisplayTool>(tool: T): T;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function decorateWithCollapsedDisplay<T extends CollapsedDisplayTool>(tool: T): T {
|
|
19
|
+
const services = globalThis as unknown as Record<PropertyKey, unknown>;
|
|
20
|
+
const candidate = services[COLLAPSED_DISPLAY_SERVICE];
|
|
21
|
+
if (!candidate || typeof candidate !== "object") return tool;
|
|
22
|
+
const service = candidate as Partial<CollapsedDisplayService>;
|
|
23
|
+
return service.version === 1 && typeof service.decorate === "function"
|
|
24
|
+
? service.decorate(tool)
|
|
25
|
+
: tool;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const TOOL_DESCRIPTION = "Task tracker. action is required: create|update|list|get|delete|clear; create needs subject; update/get/delete need id.";
|
|
29
|
+
const PROMPT_SNIPPET = "";
|
|
30
|
+
const PROMPT_GUIDELINES = [
|
|
31
|
+
"todo: Use for multi-step tasks. update needs changed fields; list accepts status/includeDeleted; clear removes all; create supports blockedBy; update supports addBlockedBy/removeBlockedBy; keep one in_progress and complete tasks promptly.",
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
function prepareTodoArguments(args: unknown): unknown {
|
|
35
|
+
if (!args || typeof args !== "object" || Array.isArray(args)) return args;
|
|
36
|
+
const input = { ...(args as Record<string, unknown>) };
|
|
37
|
+
if (input.action !== undefined) return input;
|
|
38
|
+
const mutableFields = [
|
|
39
|
+
"subject", "description", "activeForm", "status", "owner", "metadata", "addBlockedBy", "removeBlockedBy",
|
|
40
|
+
];
|
|
41
|
+
if (input.id !== undefined && mutableFields.some((field) => field in input)) input.action = "update";
|
|
42
|
+
else if (typeof input.subject === "string") input.action = "create";
|
|
43
|
+
return input;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function removeSchemaDescriptions(value: unknown, seen = new Set<object>(), isPropertiesMap = false): void {
|
|
47
|
+
if (value === null || typeof value !== "object" || seen.has(value)) return;
|
|
48
|
+
seen.add(value);
|
|
49
|
+
if (!isPropertiesMap) delete (value as Record<string, unknown>).description;
|
|
50
|
+
for (const [key, child] of Object.entries(value)) {
|
|
51
|
+
removeSchemaDescriptions(child, seen, key === "properties");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Pi 1.1 invalidates the extension runner and throws this exact phrase from a
|
|
56
|
+
// dead ctx proxy; older Pi hosts used the shorter message. Match the stable
|
|
57
|
+
// substrings so unrelated replay bugs still propagate instead of being swallowed.
|
|
58
|
+
function isStaleCtxError(e: unknown): boolean {
|
|
59
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
60
|
+
return message.includes("Session is no longer valid")
|
|
61
|
+
|| message.includes("stale after session replacement");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Classify a ctx without letting a recognized stale error escape. */
|
|
65
|
+
function ctxKind(ctx: ExtensionContext | undefined): "rpc" | "other" | "stale" {
|
|
66
|
+
if (!ctx) return "other";
|
|
67
|
+
try {
|
|
68
|
+
return ctx.mode === "rpc" ? "rpc" : "other";
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (!isStaleCtxError(e)) throw e;
|
|
71
|
+
return "stale";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `ctx.hasUI ? ctx.ui : undefined`, tolerant of a recognized stale ctx. */
|
|
76
|
+
function rpcUiContext(ctx: ExtensionContext): ExtensionUIContext | undefined {
|
|
77
|
+
try {
|
|
78
|
+
return ctx.hasUI ? ctx.ui : undefined;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (!isStaleCtxError(e)) throw e;
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface RpcSessionEntry {
|
|
86
|
+
sessionId: string;
|
|
87
|
+
uiCtx: ExtensionUIContext | undefined;
|
|
88
|
+
overlay: TodoOverlay;
|
|
89
|
+
generation: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const rpcSessions = new Map<string, RpcSessionEntry>();
|
|
93
|
+
|
|
94
|
+
export function __resetRpcSessions(): void {
|
|
95
|
+
rpcSessions.clear();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function createRpcSessionOverlay(sessionId: string): TodoOverlay {
|
|
99
|
+
const overlay = new TodoOverlay();
|
|
100
|
+
const host = overlay as unknown as {
|
|
101
|
+
lastNextId?: number;
|
|
102
|
+
resetCompletedDisplayState(): void;
|
|
103
|
+
completedTaskIdsPendingHide: Set<number>;
|
|
104
|
+
hiddenCompletedTaskIds: Set<number>;
|
|
105
|
+
getSnapshot(): { tasks: any[]; nextId: number };
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
host.getSnapshot = function () {
|
|
109
|
+
const state = getState(sessionId);
|
|
110
|
+
if (this.lastNextId !== undefined && state.nextId < this.lastNextId) {
|
|
111
|
+
this.resetCompletedDisplayState();
|
|
112
|
+
}
|
|
113
|
+
this.lastNextId = state.nextId;
|
|
114
|
+
const completedTaskIds = new Set(
|
|
115
|
+
state.tasks.filter((task: any) => task.status === "completed").map((task: any) => task.id),
|
|
116
|
+
);
|
|
117
|
+
for (const taskId of this.completedTaskIdsPendingHide) {
|
|
118
|
+
if (!completedTaskIds.has(taskId)) this.completedTaskIdsPendingHide.delete(taskId);
|
|
119
|
+
}
|
|
120
|
+
for (const taskId of this.hiddenCompletedTaskIds) {
|
|
121
|
+
if (!completedTaskIds.has(taskId)) this.hiddenCompletedTaskIds.delete(taskId);
|
|
122
|
+
}
|
|
123
|
+
return { tasks: [...state.tasks], nextId: state.nextId };
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return overlay;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getOrCreateRpcEntry(id: string, ui: ExtensionUIContext): RpcSessionEntry {
|
|
130
|
+
let entry = rpcSessions.get(id);
|
|
131
|
+
if (!entry) {
|
|
132
|
+
entry = {
|
|
133
|
+
sessionId: id,
|
|
134
|
+
uiCtx: ui,
|
|
135
|
+
overlay: createRpcSessionOverlay(id),
|
|
136
|
+
generation: 0,
|
|
137
|
+
};
|
|
138
|
+
rpcSessions.set(id, entry);
|
|
139
|
+
}
|
|
140
|
+
if (entry.uiCtx !== ui) {
|
|
141
|
+
entry.uiCtx = ui;
|
|
142
|
+
entry.overlay.setUICtx(ui);
|
|
143
|
+
}
|
|
144
|
+
return entry;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function handleSessionStart(
|
|
148
|
+
event: unknown,
|
|
149
|
+
ctx: ExtensionContext,
|
|
150
|
+
upstreamHandler?: (event: unknown, ctx: ExtensionContext) => unknown,
|
|
151
|
+
): Promise<void> {
|
|
152
|
+
const kind = ctxKind(ctx);
|
|
153
|
+
if (kind !== "rpc") {
|
|
154
|
+
if (kind === "other") await upstreamHandler?.(event, ctx);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let id: string;
|
|
159
|
+
try {
|
|
160
|
+
id = sid(ctx);
|
|
161
|
+
replaceState(id, replayFromBranch(ctx as never));
|
|
162
|
+
} catch (e) {
|
|
163
|
+
if (!isStaleCtxError(e)) throw e;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const ui = rpcUiContext(ctx);
|
|
168
|
+
if (!ui) return;
|
|
169
|
+
|
|
170
|
+
const entry = getOrCreateRpcEntry(id, ui);
|
|
171
|
+
entry.overlay.setUICtx(ui);
|
|
172
|
+
entry.overlay.resetCompletedDisplayState();
|
|
173
|
+
entry.generation++;
|
|
174
|
+
entry.overlay.update();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function handleToolExecutionEnd(
|
|
178
|
+
event: any,
|
|
179
|
+
ctx: ExtensionContext,
|
|
180
|
+
upstreamHandler?: (event: unknown, ctx: ExtensionContext) => unknown,
|
|
181
|
+
): Promise<void> {
|
|
182
|
+
const kind = ctxKind(ctx);
|
|
183
|
+
if (kind !== "rpc") {
|
|
184
|
+
if (kind === "other") await upstreamHandler?.(event, ctx);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (event?.toolName !== TOOL_NAME || event?.isError) return;
|
|
189
|
+
|
|
190
|
+
let id: string;
|
|
191
|
+
try {
|
|
192
|
+
id = sid(ctx);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
if (!isStaleCtxError(e)) throw e;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const ui = rpcUiContext(ctx);
|
|
199
|
+
if (!ui) return;
|
|
200
|
+
|
|
201
|
+
const entry = getOrCreateRpcEntry(id, ui);
|
|
202
|
+
entry.overlay.setUICtx(ui);
|
|
203
|
+
entry.overlay.update();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function handleSessionCompact(
|
|
207
|
+
event: unknown,
|
|
208
|
+
ctx: ExtensionContext,
|
|
209
|
+
upstreamHandler?: (event: unknown, ctx: ExtensionContext) => unknown,
|
|
210
|
+
): Promise<void> {
|
|
211
|
+
const kind = ctxKind(ctx);
|
|
212
|
+
if (kind !== "rpc") {
|
|
213
|
+
if (kind === "other") await upstreamHandler?.(event, ctx);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let id: string;
|
|
218
|
+
try {
|
|
219
|
+
id = sid(ctx);
|
|
220
|
+
replaceState(id, replayFromBranch(ctx as never));
|
|
221
|
+
} catch (e) {
|
|
222
|
+
if (!isStaleCtxError(e)) throw e;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const entry = rpcSessions.get(id);
|
|
227
|
+
if (entry) {
|
|
228
|
+
entry.overlay.resetCompletedDisplayState();
|
|
229
|
+
entry.overlay.update();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function handleSessionTree(
|
|
234
|
+
event: unknown,
|
|
235
|
+
ctx: ExtensionContext,
|
|
236
|
+
upstreamHandler?: (event: unknown, ctx: ExtensionContext) => unknown,
|
|
237
|
+
): Promise<void> {
|
|
238
|
+
const kind = ctxKind(ctx);
|
|
239
|
+
if (kind !== "rpc") {
|
|
240
|
+
if (kind === "other") await upstreamHandler?.(event, ctx);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let id: string;
|
|
245
|
+
try {
|
|
246
|
+
id = sid(ctx);
|
|
247
|
+
replaceState(id, replayFromBranch(ctx as never));
|
|
248
|
+
} catch (e) {
|
|
249
|
+
if (!isStaleCtxError(e)) throw e;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const entry = rpcSessions.get(id);
|
|
254
|
+
if (entry) {
|
|
255
|
+
entry.overlay.resetCompletedDisplayState();
|
|
256
|
+
entry.overlay.update();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async function handleSessionShutdown(
|
|
261
|
+
event: unknown,
|
|
262
|
+
ctx: ExtensionContext,
|
|
263
|
+
upstreamHandler?: (event: unknown, ctx: ExtensionContext) => unknown,
|
|
264
|
+
): Promise<void> {
|
|
265
|
+
const kind = ctxKind(ctx);
|
|
266
|
+
if (kind !== "rpc") {
|
|
267
|
+
if (kind === "other") await upstreamHandler?.(event, ctx);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let id: string;
|
|
272
|
+
try {
|
|
273
|
+
id = sid(ctx);
|
|
274
|
+
} catch (e) {
|
|
275
|
+
if (!isStaleCtxError(e)) throw e;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
evictSession(id);
|
|
280
|
+
const entry = rpcSessions.get(id);
|
|
281
|
+
if (entry) {
|
|
282
|
+
entry.overlay.dispose();
|
|
283
|
+
rpcSessions.delete(id);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async function handleAgentStart(
|
|
288
|
+
event: unknown,
|
|
289
|
+
ctx: ExtensionContext,
|
|
290
|
+
upstreamHandler?: (event: unknown, ctx: ExtensionContext) => unknown,
|
|
291
|
+
): Promise<void> {
|
|
292
|
+
const kind = ctxKind(ctx);
|
|
293
|
+
if (kind !== "rpc") {
|
|
294
|
+
if (kind === "other") await upstreamHandler?.(event, ctx);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
let id: string;
|
|
299
|
+
try {
|
|
300
|
+
id = sid(ctx);
|
|
301
|
+
} catch (e) {
|
|
302
|
+
if (!isStaleCtxError(e)) throw e;
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const entry = rpcSessions.get(id);
|
|
307
|
+
entry?.overlay.hideCompletedTasksFromPreviousTurn();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function handleShortcut(
|
|
311
|
+
ctx: ExtensionContext,
|
|
312
|
+
upstreamHandler?: (ctx: ExtensionContext) => unknown,
|
|
313
|
+
): void {
|
|
314
|
+
const kind = ctxKind(ctx);
|
|
315
|
+
if (kind === "other") {
|
|
316
|
+
upstreamHandler?.(ctx);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (kind === "stale") return;
|
|
320
|
+
|
|
321
|
+
if (!rpcUiContext(ctx)) return;
|
|
322
|
+
let id: string;
|
|
323
|
+
try {
|
|
324
|
+
id = sid(ctx);
|
|
325
|
+
} catch (e) {
|
|
326
|
+
if (!isStaleCtxError(e)) throw e;
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const entry = rpcSessions.get(id);
|
|
331
|
+
if (entry?.overlay.isRegistered()) {
|
|
332
|
+
entry.overlay.toggleCollapse();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export default function (pi: ExtensionAPI): void {
|
|
337
|
+
const leanPi = new Proxy(pi, {
|
|
338
|
+
get(target, property) {
|
|
339
|
+
if (property === "registerTool") {
|
|
340
|
+
return (tool: Parameters<ExtensionAPI["registerTool"]>[0]) => {
|
|
341
|
+
if (tool.name === "todo") {
|
|
342
|
+
removeSchemaDescriptions(tool.parameters);
|
|
343
|
+
return target.registerTool(decorateWithCollapsedDisplay({
|
|
344
|
+
...tool,
|
|
345
|
+
description: TOOL_DESCRIPTION,
|
|
346
|
+
promptSnippet: PROMPT_SNIPPET,
|
|
347
|
+
promptGuidelines: PROMPT_GUIDELINES,
|
|
348
|
+
prepareArguments: (args) => prepareTodoArguments(tool.prepareArguments?.(args) ?? args) as never,
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
return target.registerTool(decorateWithCollapsedDisplay(tool));
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (property === "on") {
|
|
356
|
+
return (event: string, handler: (event: unknown, ctx: ExtensionContext) => unknown) => {
|
|
357
|
+
switch (event) {
|
|
358
|
+
case "session_start":
|
|
359
|
+
return target.on("session_start", (e, ctx) => handleSessionStart(e, ctx, handler));
|
|
360
|
+
case "tool_execution_end":
|
|
361
|
+
return target.on("tool_execution_end", (e, ctx) => handleToolExecutionEnd(e, ctx, handler));
|
|
362
|
+
case "session_compact":
|
|
363
|
+
return target.on("session_compact", (e, ctx) => handleSessionCompact(e, ctx, handler));
|
|
364
|
+
case "session_tree":
|
|
365
|
+
return target.on("session_tree", (e, ctx) => handleSessionTree(e, ctx, handler));
|
|
366
|
+
case "session_shutdown":
|
|
367
|
+
return target.on("session_shutdown", (e, ctx) => handleSessionShutdown(e, ctx, handler));
|
|
368
|
+
case "agent_start":
|
|
369
|
+
return target.on("agent_start", (e, ctx) => handleAgentStart(e, ctx, handler));
|
|
370
|
+
default:
|
|
371
|
+
return target.on(event as never, handler as never);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (property === "registerShortcut") {
|
|
377
|
+
return (key: string, shortcut: { description?: string; handler: (ctx: ExtensionContext) => unknown }) => {
|
|
378
|
+
const wrappedShortcut = {
|
|
379
|
+
...shortcut,
|
|
380
|
+
handler: (ctx: ExtensionContext) => handleShortcut(ctx, shortcut.handler),
|
|
381
|
+
};
|
|
382
|
+
return target.registerShortcut(key as never, wrappedShortcut as never);
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (property === "registerCommand") {
|
|
387
|
+
return (name: string, command: { description?: string; handler: (args: string, ctx: ExtensionContext) => unknown }) => {
|
|
388
|
+
if (name === "todos") {
|
|
389
|
+
const wrappedCommand = {
|
|
390
|
+
...command,
|
|
391
|
+
handler: async (args: string, ctx: ExtensionContext) => {
|
|
392
|
+
const kind = ctxKind(ctx);
|
|
393
|
+
try {
|
|
394
|
+
// Await the real upstream command inside the guard: a recognized
|
|
395
|
+
// stale rejection settles here instead of escaping as an unhandled
|
|
396
|
+
// rejection, unrelated async failures still reach the caller, and the
|
|
397
|
+
// RPC overlay refresh stays ordered after upstream completion.
|
|
398
|
+
await command.handler(args, ctx);
|
|
399
|
+
if (kind !== "rpc") return;
|
|
400
|
+
const ui = rpcUiContext(ctx);
|
|
401
|
+
if (!ui) return;
|
|
402
|
+
const id = sid(ctx);
|
|
403
|
+
const entry = getOrCreateRpcEntry(id, ui);
|
|
404
|
+
entry.overlay.update();
|
|
405
|
+
} catch (e) {
|
|
406
|
+
if (!isStaleCtxError(e)) throw e;
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
return target.registerCommand(name, wrappedCommand as never);
|
|
411
|
+
}
|
|
412
|
+
return target.registerCommand(name, command as never);
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const member = Reflect.get(target, property, target);
|
|
417
|
+
return typeof member === "function" ? member.bind(target) : member;
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
todo(leanPi);
|
|
422
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfgghgftgffg/rpiv-todo-lean",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Lean Pi todo extension: the full @juicesharp/rpiv-todo runtime with a compact flat schema and per-session RPC overlay handling preserved.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"author": "kunkun9527",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "juicesharp",
|
|
14
|
+
"url": "https://github.com/juicesharp/rpiv-mono"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/gfgghgftgffg/amox_pi_extensions_lean.git",
|
|
20
|
+
"directory": "packages/rpiv-todo-lean"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/gfgghgftgffg/amox_pi_extensions_lean/tree/main/packages/rpiv-todo-lean#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/gfgghgftgffg/amox_pi_extensions_lean/issues"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"pi-package",
|
|
28
|
+
"pi-extension",
|
|
29
|
+
"rpiv",
|
|
30
|
+
"todo",
|
|
31
|
+
"token-efficient"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"index.ts",
|
|
35
|
+
"README.md",
|
|
36
|
+
"README.zh-CN.md",
|
|
37
|
+
"MAINTENANCE.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.19.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "node --test tests/*.test.mjs",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
46
|
+
"check": "npm run typecheck && npm test"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@juicesharp/rpiv-i18n": "2.13.8",
|
|
50
|
+
"@juicesharp/rpiv-todo": "2.13.8"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@earendil-works/pi-ai": ">=1.1.0",
|
|
54
|
+
"@earendil-works/pi-coding-agent": ">=1.1.0",
|
|
55
|
+
"@earendil-works/pi-tui": ">=1.1.0",
|
|
56
|
+
"typebox": "*"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@earendil-works/pi-ai": "1.1.0",
|
|
60
|
+
"@earendil-works/pi-coding-agent": "1.1.0",
|
|
61
|
+
"@earendil-works/pi-tui": "1.1.0",
|
|
62
|
+
"jiti": "2.7.0",
|
|
63
|
+
"typebox": "1.3.36",
|
|
64
|
+
"typescript": "7.0.2"
|
|
65
|
+
},
|
|
66
|
+
"pi": {
|
|
67
|
+
"extensions": [
|
|
68
|
+
"./index.ts"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|