@unifan/pi-unifan-zh 1.0.34 → 1.0.35
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/AGENTS.md +18 -7
- package/README.md +80 -3
- package/README_zh.md +80 -3
- package/extensions/commit/package.json +1 -1
- package/extensions/review/package.json +1 -1
- package/extensions/workflow/README.md +50 -0
- package/extensions/workflow/index.ts +275 -0
- package/extensions/workflow/package.json +47 -0
- package/extensions/workflow/skills/00-next/SKILL.md +41 -0
- package/extensions/workflow/skills/01-brainstorm/SKILL.md +50 -0
- package/extensions/workflow/skills/02-plan/SKILL.md +47 -0
- package/extensions/workflow/skills/03-work/SKILL.md +60 -0
- package/extensions/workflow/skills/04-review/SKILL.md +41 -0
- package/extensions/workflow/skills/05-learn/SKILL.md +52 -0
- package/extensions/workflow/src/driver/work-loop-driver.ts +401 -0
- package/extensions/workflow/src/filters/bash-output-filter.ts +60 -0
- package/extensions/workflow/src/filters/read-output-filter.ts +87 -0
- package/extensions/workflow/src/tools/artifact-helper.ts +77 -0
- package/extensions/workflow/src/tools/session-checkpoint.ts +191 -0
- package/extensions/workflow/src/tools/workflow-state.ts +168 -0
- package/extensions/workflow/tests/workflow.test.mjs +454 -0
- package/package.json +18 -3
package/AGENTS.md
CHANGED
|
@@ -30,13 +30,19 @@ pi-unifan-zh/
|
|
|
30
30
|
│ │ │ ├── history-context.md # 历史上下文专家
|
|
31
31
|
│ │ │ └── code-comments.md # 注释检查专家
|
|
32
32
|
│ │ └── package.json # 独立子包: @unifan/pi-review-zh
|
|
33
|
-
│
|
|
34
|
-
│
|
|
33
|
+
│ ├── commit/ # ③ 智能 Git 提交助手 (/commit, /commit-push)
|
|
34
|
+
│ │ ├── index.ts # 一键提交与推流命令
|
|
35
|
+
│ │ ├── src/
|
|
36
|
+
│ │ │ ├── git.ts # Git 执行引擎 (含自动变基 pull --rebase)
|
|
37
|
+
│ │ │ └── prompt.ts # Conventional Commits 中文提示词
|
|
38
|
+
│ │ └── package.json # 独立子包: @unifan/pi-commit-zh
|
|
39
|
+
│ └── workflow/ # ④ 复合工程工作流引擎 (/workflow)
|
|
40
|
+
│ ├── index.ts # 工具与输出过滤器注册
|
|
35
41
|
│ ├── src/
|
|
36
|
-
│ │ ├──
|
|
37
|
-
│ │ └──
|
|
38
|
-
│ └── package.json # 独立子包: @unifan/pi-
|
|
39
|
-
└── skills/ # 内置专业技能集
|
|
42
|
+
│ │ ├── tools/ # workflow_state, artifact_helper, session_checkpoint
|
|
43
|
+
│ │ └── filters/ # bash_output_filter, read_output_filter
|
|
44
|
+
│ └── package.json # 独立子包: @unifan/pi-workflow-zh
|
|
45
|
+
└── skills/ # 内置专业技能集 (00-next ~ 05-learn)
|
|
40
46
|
```
|
|
41
47
|
|
|
42
48
|
---
|
|
@@ -128,7 +134,12 @@ cd D:\program\my\pi-unifan-zh\extensions\commit
|
|
|
128
134
|
npm version patch
|
|
129
135
|
npm publish --access public
|
|
130
136
|
|
|
131
|
-
# 4.
|
|
137
|
+
# 4. 升级并发布 workflow 子包 (@unifan/pi-workflow-zh)(如有修改)
|
|
138
|
+
cd D:\program\my\pi-unifan-zh\extensions\workflow
|
|
139
|
+
npm version patch
|
|
140
|
+
npm publish --access public
|
|
141
|
+
|
|
142
|
+
# 5. 提交版本号变更到 Git 远端
|
|
132
143
|
cd D:\program\my\pi-unifan-zh
|
|
133
144
|
git add .
|
|
134
145
|
git commit -m "chore(release): 升级版本号至 vX.Y.Z"
|
package/README.md
CHANGED
|
@@ -17,11 +17,18 @@ pi-unifan-zh/
|
|
|
17
17
|
├── AGENTS.md # Developer and AI agent guidelines
|
|
18
18
|
├── README.md # English Documentation
|
|
19
19
|
├── README_zh.md # Chinese Documentation
|
|
20
|
-
├── extensions/ # 📦
|
|
20
|
+
├── extensions/ # 📦 Extension Packages
|
|
21
21
|
│ ├── sessions/ # 📜 ① Dual-pane session manager with live preview (Chinese)
|
|
22
22
|
│ ├── review/ # 🔍 ② AI multi-agent code review suite (Daily/Lite/Perf/Full)
|
|
23
|
-
│
|
|
24
|
-
└──
|
|
23
|
+
│ ├── commit/ # 📦 ③ Intelligent Conventional Commits assistant (Chinese)
|
|
24
|
+
│ └── workflow/ # 🔄 ④ Compound Engineering Workflow engine (State/Checkpoints/Filters)
|
|
25
|
+
└── skills/ # 🎯 Compound Engineering Skills (00-next ~ 05-learn)
|
|
26
|
+
├── 00-next/ # 🚦 Router & orchestrator (inspects repo state, recommends next step)
|
|
27
|
+
├── 01-brainstorm/ # 💡 Discovery & flexible interactions (single/multi-select/custom text)
|
|
28
|
+
├── 02-plan/ # 📐 TDD architecture planning & Implementation Units
|
|
29
|
+
├── 03-work/ # 🛠️ Strict TDD coding execution & checkpoint resume
|
|
30
|
+
├── 04-review/ # 🧐 Code review, spec verification & regression testing
|
|
31
|
+
└── 05-learn/ # 📝 Lightweight solution cards & knowledge compounding
|
|
25
32
|
```
|
|
26
33
|
|
|
27
34
|
---
|
|
@@ -49,19 +56,44 @@ pi install D:/program/my/pi-unifan-zh
|
|
|
49
56
|
|
|
50
57
|
### Option B: Install Individual Extensions
|
|
51
58
|
|
|
59
|
+
Each extension is published as a standalone npm package and can be installed individually:
|
|
60
|
+
|
|
61
|
+
> 💡 **Note**: Pi CLI's `git:` source only supports cloning the entire repository root. For **installing individual extensions**, use the recommended `npm:` method or local paths.
|
|
62
|
+
|
|
52
63
|
#### 1. Install `sessions` (Session Manager with TUI Preview):
|
|
53
64
|
```bash
|
|
65
|
+
# Via npm
|
|
54
66
|
pi install npm:@unifan/pi-sessions-zh
|
|
67
|
+
# Or via local path
|
|
68
|
+
pi install D:/program/my/pi-unifan-zh/extensions/sessions
|
|
55
69
|
```
|
|
56
70
|
|
|
57
71
|
#### 2. Install `review` (AI Parallel Code Review Suite):
|
|
58
72
|
```bash
|
|
73
|
+
# Via npm
|
|
59
74
|
pi install npm:@unifan/pi-review-zh
|
|
75
|
+
# Or via local path
|
|
76
|
+
pi install D:/program/my/pi-unifan-zh/extensions/review
|
|
60
77
|
```
|
|
61
78
|
|
|
62
79
|
#### 3. Install `commit` (Intelligent Git Commit Assistant):
|
|
63
80
|
```bash
|
|
81
|
+
# Via npm
|
|
64
82
|
pi install npm:@unifan/pi-commit-zh
|
|
83
|
+
# Or via local path
|
|
84
|
+
pi install D:/program/my/pi-unifan-zh/extensions/commit
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### 4. Install `workflow` (Compound Engineering Engine & Skills):
|
|
88
|
+
> Includes `/workflow` command, checkpoint persistence, token filters, and all 6 workflow skills (`00-next` ~ `05-learn`).
|
|
89
|
+
```bash
|
|
90
|
+
# Via npm
|
|
91
|
+
pi install npm:@unifan/pi-workflow-zh
|
|
92
|
+
# Or via local path
|
|
93
|
+
pi install D:/program/my/pi-unifan-zh/extensions/workflow
|
|
94
|
+
|
|
95
|
+
# Recommended peer question UI extension:
|
|
96
|
+
pi install npm:@juicesharp/rpiv-ask-user-question
|
|
65
97
|
```
|
|
66
98
|
|
|
67
99
|
---
|
|
@@ -134,6 +166,51 @@ pi install npm:@unifan/pi-commit-zh
|
|
|
134
166
|
|
|
135
167
|
---
|
|
136
168
|
|
|
169
|
+
### 4. 🔄 `workflow` & Compound Engineering Workflow Suite
|
|
170
|
+
Turn your AI coding agent into a disciplined software engineer through an iterative stage-gated pipeline:
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
00-next ──> 01-brainstorm ──> 02-plan ──> 03-work ──> 04-review ──> 05-learn
|
|
174
|
+
(Router) (Discovery) (TDD Plan) (Execution) (Review) (Compounding)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- **Commands & Tools**:
|
|
178
|
+
- **`/workflow`**: Inspect current project stage, artifact counts, active autonomous driving loop progress, and recommended next skill.
|
|
179
|
+
- **`workflow_state` tool**: Automatically scans `docs/` and `.context/checkpoints/` state.
|
|
180
|
+
- **`artifact_helper` tool**: Resolves standardized artifact paths for requirements, plans, and solutions.
|
|
181
|
+
- **`session_checkpoint` tool**: Saves and restores execution breakpoints at the Implementation Unit level — resume right from where you left off.
|
|
182
|
+
- **6 Built-in Pipeline Skills**:
|
|
183
|
+
- **`00-next` (Router & Orchestrator)**: Say `continue` or type `/skill:00-next`, and it automatically guides you to the right next step.
|
|
184
|
+
- **`01-brainstorm` (Requirements Discovery)**: Clarifies scope and architecture decisions. **Pairs with `@juicesharp/rpiv-ask-user-question`** for flexible interactions: single-select (1-9 hotkeys) for mutually exclusive choices, multi-select checkboxes for feature lists, and custom text inputs.
|
|
185
|
+
- **`02-plan` (Architecture Planning)**: Decomposes requirements into TDD Implementation Units following The Ladder minimalism principles.
|
|
186
|
+
- **`03-work` (Autonomous Loop TDD Coding)** 🚀: **Built-in autonomous continuation engine similar to `goal`**. Directly invoking `/skill:03-work` starts a background cross-turn driver that sequentially executes Implementation Units with red-green-refactor, **never stopping until all planned units are 100% completed**! Supports checkpoint resumption and strict Stop-The-Line policy. Type `pause`, `stop`, or press `Esc` to pause anytime.
|
|
187
|
+
- **`04-review` (Quality & Spec Review)**: Verifies git diff, checks Spec contract compliance, and ensures clean regression tests.
|
|
188
|
+
- **`05-learn` (Knowledge Compounding)**: Lightweight, pragmatic pitfall compounding into `docs/solutions/` — zero noise, only non-trivial insights.
|
|
189
|
+
- **Context Optimizers (Token Savers)**:
|
|
190
|
+
- **`bash` smart filter**: Automatically summarizes verbose command outputs (`npm install`, verbose logs), saving 80%+ context tokens.
|
|
191
|
+
- **`read` smart filter**: Compresses oversized lockfiles (e.g. `package-lock.json`) and long logs into compact structural summaries.
|
|
192
|
+
|
|
193
|
+
### 🔄 How 03-work Autonomous Loop Works
|
|
194
|
+
|
|
195
|
+
Traditional AI coding tools stop after each turn, asking for user confirmation before doing the next step. `03-work` natively integrates the `WorkLoopDriver` engine:
|
|
196
|
+
1. **Lifecycle Event Hook**: Binds to Pi's `agent_settled` event to verify execution state immediately after each turn finishes.
|
|
197
|
+
2. **Bi-directional Checkpoint Sync**: Re-reads `.context/checkpoints/` and the active plan to ensure in-memory and disk states match.
|
|
198
|
+
3. **Autonomous Continuation**: If units remain, dispatches a follow-up turn (`deliverAs: "followUp"`), driving red-green-refactor cycles autonomously across turns until all units pass.
|
|
199
|
+
4. **Safety Valves**:
|
|
200
|
+
- **Stop-The-Line**: Automatically pauses upon 3 consecutive failures on the same unit, preserving exact error context.
|
|
201
|
+
- **50-Turn Safety Threshold**: Prevents runaway looping.
|
|
202
|
+
- **Interactive Pause**: Hit `Esc` or type `pause` / `stop` anytime to safely suspend.
|
|
203
|
+
5. **Auto-Handover**: Automatically cascades into `/skill:04-review` once all units are verified green.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 💡 Acknowledgments & References
|
|
208
|
+
|
|
209
|
+
The Compound Engineering workflow pipeline in this repository draws deep architectural inspiration and reference from:
|
|
210
|
+
- **[`@leing2021/super-pi`](https://github.com/leing2021/super-pi)**: Special thanks to `super-pi` for its pioneering design of Pi-native Compound Engineering pipelines, checkpoint resumes, and artifact management patterns. In this project, we re-architected the terminal interaction to unlock multi-select capabilities, introduced the **`00-next` router**, streamlined **`05-learn`**, and fully integrated **`@juicesharp/rpiv-ask-user-question`** for rich terminal UI dialogs.
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
137
214
|
## 📄 License
|
|
138
215
|
|
|
139
216
|
MIT License.
|
package/README_zh.md
CHANGED
|
@@ -15,11 +15,18 @@ pi-unifan-zh/
|
|
|
15
15
|
├── AGENTS.md # 开发者与智能体规范指南
|
|
16
16
|
├── README.md # English Documentation
|
|
17
17
|
├── README_zh.md # 中文说明文档
|
|
18
|
-
├── extensions/ # 📦
|
|
18
|
+
├── extensions/ # 📦 扩展插件集
|
|
19
19
|
│ ├── sessions/ # 📜 ① 历史会话管理器(双栏实时预览与恢复·中文增强版)
|
|
20
20
|
│ ├── review/ # 🔍 ② AI 代码审查套件(日常3专家 / 极速单兵 / 性能探针 / 全量会诊)
|
|
21
|
-
│
|
|
22
|
-
└──
|
|
21
|
+
│ ├── commit/ # 📦 ③ 智能 Git 提交助手(Conventional Commits 纯中文规范版)
|
|
22
|
+
│ └── workflow/ # 🔄 ④ 复合工程工作流引擎(状态感知 / 断点续跑 / 输出压缩)
|
|
23
|
+
└── skills/ # 🎯 复合工程流程技能库 (00-next ~ 05-learn)
|
|
24
|
+
├── 00-next/ # 🚦 流程导航调度器(自动分析仓库产物并推荐下一步)
|
|
25
|
+
├── 01-brainstorm/ # 💡 需求发现与交互对齐(单选/多选复选框/开放问答)
|
|
26
|
+
├── 02-plan/ # 📐 TDD 架构规划与 Implementation Units 拆解
|
|
27
|
+
├── 03-work/ # 🛠️ 严格 TDD 编码执行与断点持久化
|
|
28
|
+
├── 04-review/ # 🧐 代码审查与回归测试闭环
|
|
29
|
+
└── 05-learn/ # 📝 极简避坑指南与经验复利沉淀
|
|
23
30
|
```
|
|
24
31
|
|
|
25
32
|
---
|
|
@@ -47,19 +54,44 @@ pi install D:/program/my/pi-unifan-zh
|
|
|
47
54
|
|
|
48
55
|
### 模式 B:按需单独安装单个插件
|
|
49
56
|
|
|
57
|
+
每个插件均已独立打包并发布至 npm,可根据需要挑选单独安装(互不依赖,开箱即用):
|
|
58
|
+
|
|
59
|
+
> 💡 **提示**:Pi CLI 的 `git:` 方式仅支持安装整个仓库根目录;若需**按模块单独安装**,请使用推荐的 `npm:` 方式或本地绝对路径。
|
|
60
|
+
|
|
50
61
|
#### 1. 仅安装 `sessions`(历史会话管理器·中文版):
|
|
51
62
|
```bash
|
|
63
|
+
# npm 在线单独安装
|
|
52
64
|
pi install npm:@unifan/pi-sessions-zh
|
|
65
|
+
# 或本地路径安装
|
|
66
|
+
pi install D:/program/my/pi-unifan-zh/extensions/sessions
|
|
53
67
|
```
|
|
54
68
|
|
|
55
69
|
#### 2. 仅安装 `review`(AI 代码审查系统·中文版):
|
|
56
70
|
```bash
|
|
71
|
+
# npm 在线单独安装
|
|
57
72
|
pi install npm:@unifan/pi-review-zh
|
|
73
|
+
# 或本地路径安装
|
|
74
|
+
pi install D:/program/my/pi-unifan-zh/extensions/review
|
|
58
75
|
```
|
|
59
76
|
|
|
60
77
|
#### 3. 仅安装 `commit`(智能 Git 提交助手·中文版):
|
|
61
78
|
```bash
|
|
79
|
+
# npm 在线单独安装
|
|
62
80
|
pi install npm:@unifan/pi-commit-zh
|
|
81
|
+
# 或本地路径安装
|
|
82
|
+
pi install D:/program/my/pi-unifan-zh/extensions/commit
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### 4. 仅安装 `workflow`(复合工程工作流引擎与全套技能·中文版):
|
|
86
|
+
> 包含 `/workflow` 命令、断点续跑、Token压缩器以及完整的 6 大流程技能 (`00-next` ~ `05-learn`)。
|
|
87
|
+
```bash
|
|
88
|
+
# npm 在线单独安装
|
|
89
|
+
pi install npm:@unifan/pi-workflow-zh
|
|
90
|
+
# 或本地路径安装
|
|
91
|
+
pi install D:/program/my/pi-unifan-zh/extensions/workflow
|
|
92
|
+
|
|
93
|
+
# 推荐搭配安装交互提问工具(支持现代终端多选复选框与单选):
|
|
94
|
+
pi install npm:@juicesharp/rpiv-ask-user-question
|
|
63
95
|
```
|
|
64
96
|
|
|
65
97
|
---
|
|
@@ -139,6 +171,51 @@ pi install npm:@unifan/pi-commit-zh
|
|
|
139
171
|
|
|
140
172
|
---
|
|
141
173
|
|
|
174
|
+
### 4. 🔄 `workflow` 与复合工程流 (Compound Engineering)
|
|
175
|
+
本套件内嵌完整的 **Pi 原生复合工程流体系**,将 AI 辅助编程从“随性写代码”升级为“严格的工程流水线”:
|
|
176
|
+
|
|
177
|
+
```text
|
|
178
|
+
00-next ──> 01-brainstorm ──> 02-plan ──> 03-work ──> 04-review ──> 05-learn
|
|
179
|
+
(智能调度) (需求澄清) (TDD计划) (断点编码) (质量审查) (极简复盘)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- **核心命令与工具**:
|
|
183
|
+
- **`/workflow`**:快速在终端查看当前项目工作流阶段、各产物数量、当前自主循环进度与下一步推荐技能。
|
|
184
|
+
- **`workflow_state`** 工具:自动扫描 `docs/` 与 `.context/checkpoints/` 状态。
|
|
185
|
+
- **`artifact_helper`** 工具:规范化解析和建立需求、计划与避坑文档。
|
|
186
|
+
- **`session_checkpoint`** 工具:以 Implementation Unit 为粒度记录执行断点,**写一半中断后再次启动自动从断点续跑,绝不重头重来**。
|
|
187
|
+
- **6 大内置流程技能**:
|
|
188
|
+
- **`00-next`(智能路标)**:用户随口说 `continue`、`下一步` 或输入 `/skill:00-next`,自动探查当前进度并无缝引导至下一个环节。
|
|
189
|
+
- **`01-brainstorm`(需求发现)**:引导需求澄清,**灵活调用 `@juicesharp/rpiv-ask-user-question`**:互斥方案用单选(1-9直选)、模块清单用多选复选框、开放问题自由输入,自然对齐技术方案。
|
|
190
|
+
- **`02-plan`(计划拆解)**:将需求拆解为包含验证命令与改动清单的 Implementation Units,坚持极简阶梯(The Ladder)原则。
|
|
191
|
+
- **`03-work`(跨回合自主循环驱动编码)** 🚀:**原生内置类似 `goal` 的连续自动驱动引擎**。直接使用 `/skill:03-work`(或要求执行计划)启动后,后台引擎按计划中的 Implementation Units 逐单元跨回合自主推进“红-绿-重构”,**不做完规划任务绝不停机**!支持断点续跑与遇错即停(Stop-the-line)硬门禁;如需暂停,输入 `暂停`、`pause` 或按 `Esc` 即可。
|
|
192
|
+
- **`04-review`(审查闭环)**:全量代码审查、Spec 需求符合度核验、回归测试绿灯检查。
|
|
193
|
+
- **`05-learn`(极简知识复盘)**:价值门禁驱动,仅沉淀非平凡的疑难避坑卡片至 `docs/solutions/`,坚决不制造文档噪音。
|
|
194
|
+
- **内置上下文优化黑科技 (Token Saver)**:
|
|
195
|
+
- **`bash` 输出智能过滤器**:自动压缩长终端命令输出(如 `npm install`、长日志),保留首尾关键行,节省 80%+ 上下文 Token!
|
|
196
|
+
- **`read` 输出智能过滤器**:智能压缩 `package-lock.json` 等超大文件,只保留版本和依赖概览。
|
|
197
|
+
|
|
198
|
+
### 🔄 03-work 跨回合自主循环工作原理
|
|
199
|
+
|
|
200
|
+
传统 AI 编程助手往往在单个回合输出后便停下等待用户确认,导致长流程编码被频繁打断。`03-work` 原生集成了 `WorkLoopDriver` 跨回合自主驱动引擎:
|
|
201
|
+
1. **事件级生命周期监听**:挂载 Pi 的 `agent_settled` 事件,在每回合执行完毕且环境就绪时自动触发状态核验。
|
|
202
|
+
2. **磁盘断点双向校验**:实时扫描 `.context/checkpoints/` 与规划文件中的 Implementation Units,确保内存与磁盘状态强一致。
|
|
203
|
+
3. **自主连续推进**:若存在剩余未完成单元,驱动器防抖调度后续消息(`deliverAs: "followUp"`),实现跨回合无人值守自主编码与单测验证,**不做完计划绝不停机**。
|
|
204
|
+
4. **多重安全防护阀**:
|
|
205
|
+
- **Stop-The-Line 遇错即停**:同一单元若连续 3 次排查修复失败,强制停机并完整记录错误现场,杜绝无效死循环与 Token 浪费。
|
|
206
|
+
- **50 轮安全轮次上限**:防止异常任务无休止推进。
|
|
207
|
+
- **随时安全打断**:按下 `Esc` 或输入 `暂停` / `pause`,随时安全挂起循环。
|
|
208
|
+
5. **闭环自动流转**:全量单元绿灯通过后,自动交接调度 `/skill:04-review` 进行代码审查与回归验证。
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## 💡 致谢与参考 (Acknowledgments)
|
|
213
|
+
|
|
214
|
+
本扩展库中的复合工程工作流(Compound Engineering)模块深度参考并借鉴了以下优秀开源项目的架构思想:
|
|
215
|
+
- **[`@leing2021/super-pi`](https://github.com/leing2021/super-pi)**:特别致谢 `super-pi` 项目对复合工程流流水线、断点续传(Checkpoints)与产物治理模式的探索与启发。本项目在汲取其精髓的基础上,全面重构了终端交互体验,解除了只能单选的限制,引入了 **`00-next` 智能调度导航**、**极简避坑复盘 `05-learn`**,并深度打通了 **`@juicesharp/rpiv-ask-user-question`** 的现代多选复选框终端交互体系。
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
142
219
|
## 📄 开源许可证
|
|
143
220
|
|
|
144
221
|
本项目基于 [MIT License](./LICENSE) 协议开源。
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# 🔄 @unifan/pi-workflow-zh (复合工程工作流引擎·中文版)
|
|
2
|
+
|
|
3
|
+
专为 **Pi Coding Agent** 打造的复合工程工作流(Compound Engineering)引擎扩展。提供状态自动感知、执行断点持久化与长输出智能压缩。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✨ 核心特性
|
|
8
|
+
|
|
9
|
+
- **工作流状态感知**:自动识别项目当前处于需求、计划、编码还是复盘阶段,提供智能下一步建议。
|
|
10
|
+
- **执行断点恢复(Checkpoints)**:以 Implementation Unit 为粒度持久化执行状态,支持中断后无缝续跑。
|
|
11
|
+
- **产物目录标准化**:自动规范化 `docs/brainstorms/`、`docs/plans/`、`docs/solutions/` 与 `.context/checkpoints/`。
|
|
12
|
+
- **上下文 Token 压缩器**:内置 `bash` 与 `read` 智能过滤器,过滤冗余日志与超大 Lockfile,节省 80%+ Token。
|
|
13
|
+
- **与现代终端问答联动**:无缝协同 `@juicesharp/rpiv-ask-user-question` 终端多选/单选/自由输入组件。
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🚀 安装方式
|
|
18
|
+
|
|
19
|
+
### 1. 从 npm 在线安装:
|
|
20
|
+
```bash
|
|
21
|
+
pi install npm:@unifan/pi-workflow-zh
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. 本地路径单独安装:
|
|
25
|
+
```bash
|
|
26
|
+
pi install D:/program/my/pi-unifan-zh/extensions/workflow
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> **提示**:若需要终端弹窗多选复选框等高级问答交互,建议搭配安装:
|
|
30
|
+
> ```bash
|
|
31
|
+
> pi install npm:@juicesharp/rpiv-ask-user-question
|
|
32
|
+
> ```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🎮 使用方法
|
|
37
|
+
|
|
38
|
+
在 Pi 中输入命令查看工作流看板:
|
|
39
|
+
```text
|
|
40
|
+
/workflow
|
|
41
|
+
```
|
|
42
|
+
可查看当前项目工作流阶段状态、已归档产物清单与 03-work 自主循环进度。
|
|
43
|
+
|
|
44
|
+
### 6 大内置复合工程技能
|
|
45
|
+
- **`/skill:00-next`**:智能进度分析与路由推荐
|
|
46
|
+
- **`/skill:01-brainstorm`**:需求发现与边界澄清
|
|
47
|
+
- **`/skill:02-plan`**:TDD 架构规划与 Implementation Units 拆解
|
|
48
|
+
- **`/skill:03-work`** 🚀:**自主循环干活(不做完不停机)**。按计划顺序跨回合自动推进所有单元,完成全部规划前绝不停机,中途可随时输入“暂停”或按 Esc 挂起。
|
|
49
|
+
- **`/skill:04-review`**:全量代码审查与回归验证
|
|
50
|
+
- **`/skill:05-learn`**:极简疑难避坑卡片沉淀
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { resolveArtifactPath, type ArtifactType } from "./src/tools/artifact-helper.js";
|
|
4
|
+
import { detectWorkflowState } from "./src/tools/workflow-state.js";
|
|
5
|
+
import { executeSessionCheckpoint } from "./src/tools/session-checkpoint.js";
|
|
6
|
+
import { filterBashOutput } from "./src/filters/bash-output-filter.js";
|
|
7
|
+
import { filterReadOutput } from "./src/filters/read-output-filter.js";
|
|
8
|
+
import { WorkLoopDriver } from "./src/driver/work-loop-driver.js";
|
|
9
|
+
|
|
10
|
+
const workflowStateParams = Type.Object({
|
|
11
|
+
repoRoot: Type.String({ description: "Repository root path to scan for workflow artifacts" }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const artifactHelperParams = Type.Object({
|
|
15
|
+
repoRoot: Type.String({ description: "Repository root where workflow artifacts are stored" }),
|
|
16
|
+
artifactType: Type.Union(
|
|
17
|
+
[
|
|
18
|
+
Type.Literal("brainstorm"),
|
|
19
|
+
Type.Literal("plan"),
|
|
20
|
+
Type.Literal("solution"),
|
|
21
|
+
Type.Literal("checkpoint"),
|
|
22
|
+
],
|
|
23
|
+
{ description: "Target artifact category" },
|
|
24
|
+
),
|
|
25
|
+
topic: Type.Optional(Type.String({ description: "Topic or feature name for the artifact" })),
|
|
26
|
+
date: Type.Optional(Type.String({ description: "Date prefix formatted as YYYY-MM-DD" })),
|
|
27
|
+
ensureDir: Type.Optional(Type.Boolean({ description: "Whether to create directory if missing" })),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const sessionCheckpointParams = Type.Object({
|
|
31
|
+
operation: Type.Union(
|
|
32
|
+
[
|
|
33
|
+
Type.Literal("save"),
|
|
34
|
+
Type.Literal("load"),
|
|
35
|
+
Type.Literal("list"),
|
|
36
|
+
Type.Literal("fail"),
|
|
37
|
+
Type.Literal("retry"),
|
|
38
|
+
],
|
|
39
|
+
{ description: "Checkpoint action to execute" },
|
|
40
|
+
),
|
|
41
|
+
repoRoot: Type.String({ description: "Repository root path" }),
|
|
42
|
+
planPath: Type.Optional(Type.String({ description: "Path to the plan markdown artifact" })),
|
|
43
|
+
planSlug: Type.Optional(Type.String({ description: "Slug identifier for the execution plan" })),
|
|
44
|
+
completedUnits: Type.Optional(
|
|
45
|
+
Type.Array(Type.String(), { description: "List of completed unit names" }),
|
|
46
|
+
),
|
|
47
|
+
failedUnit: Type.Optional(Type.String({ description: "Unit name that encountered a failure" })),
|
|
48
|
+
error: Type.Optional(Type.String({ description: "Error description or failure details" })),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export default function workflowExtension(pi: ExtensionAPI) {
|
|
52
|
+
// 1. Register workflow_state tool (Core engine for 00-next)
|
|
53
|
+
pi.registerTool({
|
|
54
|
+
name: "workflow_state",
|
|
55
|
+
label: "Workflow State",
|
|
56
|
+
description:
|
|
57
|
+
"Scan repository artifacts (brainstorms, plans, checkpoints, solutions) and determine current stage and recommended next skill.",
|
|
58
|
+
parameters: workflowStateParams,
|
|
59
|
+
async execute(_toolCallId, params) {
|
|
60
|
+
const result = await detectWorkflowState(params.repoRoot);
|
|
61
|
+
return {
|
|
62
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
63
|
+
details: result,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// 2. Register artifact_helper tool
|
|
69
|
+
pi.registerTool({
|
|
70
|
+
name: "artifact_helper",
|
|
71
|
+
label: "Artifact Helper",
|
|
72
|
+
description:
|
|
73
|
+
"Resolve and optionally create standard Compound Engineering artifact paths under docs/ or .context/.",
|
|
74
|
+
parameters: artifactHelperParams,
|
|
75
|
+
async execute(_toolCallId, params) {
|
|
76
|
+
const result = await resolveArtifactPath({
|
|
77
|
+
repoRoot: params.repoRoot,
|
|
78
|
+
artifactType: params.artifactType as ArtifactType,
|
|
79
|
+
topic: params.topic,
|
|
80
|
+
date: params.date,
|
|
81
|
+
ensureDir: params.ensureDir,
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
content: [{ type: "text", text: result.path }],
|
|
85
|
+
details: result,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// 3. Register session_checkpoint tool
|
|
91
|
+
pi.registerTool({
|
|
92
|
+
name: "session_checkpoint",
|
|
93
|
+
label: "Session Checkpoint",
|
|
94
|
+
description:
|
|
95
|
+
"Manage plan execution checkpoints: save completed units, load breakpoints, record errors, and retry failed units.",
|
|
96
|
+
parameters: sessionCheckpointParams,
|
|
97
|
+
async execute(_toolCallId, params) {
|
|
98
|
+
const result = await executeSessionCheckpoint({
|
|
99
|
+
operation: params.operation,
|
|
100
|
+
repoRoot: params.repoRoot,
|
|
101
|
+
planPath: params.planPath,
|
|
102
|
+
planSlug: params.planSlug,
|
|
103
|
+
completedUnits: params.completedUnits,
|
|
104
|
+
failedUnit: params.failedUnit,
|
|
105
|
+
error: params.error,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
109
|
+
details: result,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// 4. Hook: Bash output smart filter (Reduce context waste from verbose commands)
|
|
115
|
+
pi.on("tool_result", async (event, _ctx) => {
|
|
116
|
+
if (event.toolName !== "bash") return undefined;
|
|
117
|
+
|
|
118
|
+
const command = (event.input as { command?: string })?.command ?? "";
|
|
119
|
+
if (!command) return undefined;
|
|
120
|
+
|
|
121
|
+
const textBlocks =
|
|
122
|
+
(event.content as Array<{ type: string; text?: string }>)?.filter(
|
|
123
|
+
(b) => b.type === "text",
|
|
124
|
+
) ?? [];
|
|
125
|
+
if (textBlocks.length === 0) return undefined;
|
|
126
|
+
|
|
127
|
+
const output = textBlocks.map((b) => b.text ?? "").join("");
|
|
128
|
+
const result = filterBashOutput({
|
|
129
|
+
command,
|
|
130
|
+
output,
|
|
131
|
+
isError: event.isError ?? false,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (!result.filtered) return undefined;
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
content: [{ type: "text", text: result.output }],
|
|
138
|
+
details: {
|
|
139
|
+
...(event.details && typeof event.details === "object" ? event.details : {}),
|
|
140
|
+
bashFilter: {
|
|
141
|
+
strategy: result.strategy,
|
|
142
|
+
originalBytes: result.originalBytes,
|
|
143
|
+
filteredBytes: result.filteredBytes,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// 5. Hook: Read output filter (Reduce context waste from large lockfiles and long texts)
|
|
150
|
+
pi.on("tool_result", async (event, _ctx) => {
|
|
151
|
+
if (event.toolName !== "read") return undefined;
|
|
152
|
+
|
|
153
|
+
const filePath = (event.input as { path?: string })?.path ?? "";
|
|
154
|
+
if (!filePath) return undefined;
|
|
155
|
+
|
|
156
|
+
const textBlocks =
|
|
157
|
+
(event.content as Array<{ type: string; text?: string }>)?.filter(
|
|
158
|
+
(b) => b.type === "text",
|
|
159
|
+
) ?? [];
|
|
160
|
+
if (textBlocks.length === 0) return undefined;
|
|
161
|
+
|
|
162
|
+
const output = textBlocks.map((b) => b.text ?? "").join("");
|
|
163
|
+
const isImage =
|
|
164
|
+
(event.content as Array<{ type: string }>)?.some((b) => b.type === "image") ?? false;
|
|
165
|
+
|
|
166
|
+
const result = filterReadOutput({
|
|
167
|
+
path: filePath,
|
|
168
|
+
output,
|
|
169
|
+
isError: event.isError ?? false,
|
|
170
|
+
isImage,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!result.filtered) return undefined;
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
content: [{ type: "text", text: result.output }],
|
|
177
|
+
details: {
|
|
178
|
+
...(event.details && typeof event.details === "object" ? event.details : {}),
|
|
179
|
+
readFilter: {
|
|
180
|
+
strategy: result.strategy,
|
|
181
|
+
originalBytes: result.originalBytes,
|
|
182
|
+
filteredBytes: result.filteredBytes,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// 6. User Command: /workflow (查看工作流总览与 03-work 自主循环状态)
|
|
189
|
+
pi.registerCommand("workflow", {
|
|
190
|
+
description: "查看当前项目的复合工程流状态与下一步推荐技能",
|
|
191
|
+
async handler(_args, ctx) {
|
|
192
|
+
const repoRoot = ctx.cwd || process.cwd();
|
|
193
|
+
const state = await detectWorkflowState(repoRoot);
|
|
194
|
+
const workStatus = workDriver.getStatus();
|
|
195
|
+
|
|
196
|
+
const msg = [
|
|
197
|
+
`🎯 **复合工程工作流状态 (Compound Engineering)**`,
|
|
198
|
+
`📁 仓库路径: \`${state.repoRoot}\``,
|
|
199
|
+
`📊 当前阶段: **${state.stage.toUpperCase()}**`,
|
|
200
|
+
`🚀 推荐下一步: \`/skill:${state.recommendedSkill}\``,
|
|
201
|
+
`💡 理由: ${state.recommendationReason}`,
|
|
202
|
+
``,
|
|
203
|
+
workStatus.isActive
|
|
204
|
+
? `⚡ **03-work 自主循环运行中**: [${workStatus.completedUnits.length}/${workStatus.allUnits.length}] 当前推进: **${workStatus.currentUnit || "全部完成"}**`
|
|
205
|
+
: `⚡ **03-work 自主循环状态**: ⚪ 空闲(调用 /skill:03-work 即可自动循环驱动)`,
|
|
206
|
+
``,
|
|
207
|
+
`📋 **产物概览**:`,
|
|
208
|
+
`- 需求文档 (Brainstorms): ${state.brainstorms.length} 个 ${state.latestBrainstorm ? `(最新: ${state.latestBrainstorm.filename})` : ""}`,
|
|
209
|
+
`- 执行计划 (Plans): ${state.plans.length} 个 ${state.latestPlan ? `(最新: ${state.latestPlan.filename})` : ""}`,
|
|
210
|
+
`- 运行断点 (Checkpoints): ${state.checkpoints.length} 个 ${state.activeCheckpoint ? `(已完成: ${state.activeCheckpoint.completedUnits.length} 单元)` : ""}`,
|
|
211
|
+
`- 避坑经验 (Solutions): ${state.solutions.length} 个 ${state.latestSolution ? `(最新: ${state.latestSolution.filename})` : ""}`,
|
|
212
|
+
].join("\n");
|
|
213
|
+
|
|
214
|
+
if (ctx.hasUI) {
|
|
215
|
+
ctx.ui.notify?.(msg, "info");
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// 7. 03-work 原生自主循环驱动引擎 (无须额外命令,直接在 03-work 中原生生效)
|
|
221
|
+
const workDriver = new WorkLoopDriver();
|
|
222
|
+
|
|
223
|
+
// 监听用户输入与技能启动:当调用 03-work 或请求恢复执行时,自动启动自主循环驱动
|
|
224
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
225
|
+
const promptLower = event.prompt.toLowerCase();
|
|
226
|
+
const is03Work =
|
|
227
|
+
event.prompt.includes("03-work") ||
|
|
228
|
+
event.systemPrompt.includes("03-work") ||
|
|
229
|
+
(promptLower.includes("03") &&
|
|
230
|
+
(promptLower.includes("work") ||
|
|
231
|
+
promptLower.includes("继续") ||
|
|
232
|
+
promptLower.includes("恢复") ||
|
|
233
|
+
promptLower.includes("resume") ||
|
|
234
|
+
promptLower.includes("干活")));
|
|
235
|
+
|
|
236
|
+
if (is03Work && !workDriver.getStatus().isActive) {
|
|
237
|
+
workDriver.setRepoRoot(ctx.cwd || process.cwd());
|
|
238
|
+
const res = await workDriver.start();
|
|
239
|
+
if (res.success && res.status.isActive) {
|
|
240
|
+
const nextUnit = res.status.currentUnit ? `下一个: ${res.status.currentUnit}` : "准备就绪";
|
|
241
|
+
ctx.ui?.setStatus?.(
|
|
242
|
+
"workflow",
|
|
243
|
+
`🔄 03-work 自主干活 [${res.status.completedUnits.length}/${res.status.allUnits.length}] ${nextUnit}`,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// 监听用户打断指令:用户若输入“暂停”或“停止”,自动安全挂起 03 自主循环
|
|
250
|
+
pi.on("input", async (event, ctx) => {
|
|
251
|
+
const text = event.text.trim().toLowerCase();
|
|
252
|
+
if (
|
|
253
|
+
workDriver.getStatus().isActive &&
|
|
254
|
+
(text === "暂停" || text === "停止" || text === "pause" || text === "stop")
|
|
255
|
+
) {
|
|
256
|
+
await workDriver.pause("用户手动输入暂停");
|
|
257
|
+
ctx.ui?.setStatus?.("workflow", undefined);
|
|
258
|
+
ctx.ui?.notify?.(
|
|
259
|
+
"⏸️ 03-work 自主循环已暂停。随时输入“继续”或调用 /skill:03-work 即可恢复。",
|
|
260
|
+
"info",
|
|
261
|
+
);
|
|
262
|
+
return { action: "handled" };
|
|
263
|
+
}
|
|
264
|
+
return { action: "continue" };
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// 核心事件循环:每个回合结束后,若仍有未完成单元,自动注入下一回合实现“不做完不停机”
|
|
268
|
+
pi.on("agent_settled", async (_event, ctx) => {
|
|
269
|
+
await workDriver.onAgentSettled(ctx, pi);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
pi.on("session_shutdown", async () => {
|
|
273
|
+
workDriver.cancelTimer();
|
|
274
|
+
});
|
|
275
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unifan/pi-workflow-zh",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Pi 复合工程工作流引擎(状态感知 / 断点续跑 / 输出压缩 / 自动化工具集)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"author": "821869798",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/821869798/pi-unifan-zh.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi-package",
|
|
15
|
+
"pi-extension",
|
|
16
|
+
"pi-coding-agent",
|
|
17
|
+
"workflow",
|
|
18
|
+
"compound-engineering",
|
|
19
|
+
"checkpoints",
|
|
20
|
+
"chinese"
|
|
21
|
+
],
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@earendil-works/pi-ai": ">=0.74.0 <1.0.0",
|
|
24
|
+
"@earendil-works/pi-coding-agent": ">=0.74.0 <1.0.0",
|
|
25
|
+
"@juicesharp/rpiv-ask-user-question": ">=0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"@juicesharp/rpiv-ask-user-question": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"index.ts",
|
|
34
|
+
"src",
|
|
35
|
+
"skills",
|
|
36
|
+
"README.md",
|
|
37
|
+
"package.json"
|
|
38
|
+
],
|
|
39
|
+
"pi": {
|
|
40
|
+
"extensions": [
|
|
41
|
+
"./index.ts"
|
|
42
|
+
],
|
|
43
|
+
"skills": [
|
|
44
|
+
"./skills"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
}
|