@zhushanwen/pi-subagent-workflow 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/agents/context-builder.md +1 -3
- package/agents/explorer.md +27 -0
- package/agents/oracle.md +2 -2
- package/agents/orchestrator.md +48 -0
- package/agents/planner.md +1 -3
- package/agents/researcher.md +0 -2
- package/agents/reviewer.md +2 -2
- package/agents/worker.md +0 -2
- package/package.json +5 -3
- package/skills/workflow-script-format/SKILL.md +6 -6
- package/src/execution/__tests__/agent-registry.test.ts +3 -3
- package/src/execution/__tests__/agent-result-mapper.test.ts +24 -2
- package/src/execution/__tests__/ask-user-transit-e2e.test.ts +484 -0
- package/src/execution/__tests__/channel-registry-handshake.test.ts +233 -0
- package/src/execution/__tests__/concurrency-pool.test.ts +33 -0
- package/src/execution/__tests__/crash-recovery.test.ts +5 -1
- package/src/execution/__tests__/dialog-queue.test.ts +299 -0
- package/src/execution/__tests__/execute-nesting.test.ts +1 -1
- package/src/execution/__tests__/execute-options-mapper.test.ts +41 -9
- package/src/execution/__tests__/finalize-record.test.ts +173 -0
- package/src/execution/__tests__/gui-mode-dispatch.test.ts +59 -0
- package/src/execution/__tests__/helpers/spawn-mock.ts +209 -0
- package/src/execution/__tests__/host-mode.test.ts +87 -0
- package/src/execution/__tests__/index-session-start.test.ts +342 -0
- package/src/execution/__tests__/list-component.test.ts +1 -1
- package/src/execution/__tests__/notifier-flush.test.ts +78 -0
- package/src/execution/__tests__/path-encoding.test.ts +30 -1
- package/src/execution/__tests__/record-store.test.ts +86 -2
- package/src/execution/__tests__/records-cwd-isolation.test.ts +91 -0
- package/src/execution/__tests__/rpc-mode.test.ts +89 -0
- package/src/execution/__tests__/run-spawn-edges.test.ts +157 -153
- package/src/execution/__tests__/run-spawn-integration.test.ts +85 -151
- package/src/execution/__tests__/run-spawn-rpc-mode.test.ts +193 -0
- package/src/execution/__tests__/sdk-contract.test.ts +5 -2
- package/src/execution/__tests__/session-file-gc.test.ts +46 -0
- package/src/execution/__tests__/session-reconstructor.test.ts +20 -0
- package/src/execution/__tests__/session-start-reaper.test.ts +7 -1
- package/src/execution/__tests__/spawn-args.test.ts +14 -19
- package/src/execution/__tests__/spawn-event-adapter-rpc.test.ts +189 -0
- package/src/execution/__tests__/stdin-writer.test.ts +353 -0
- package/src/execution/__tests__/subagent-service-abort.test.ts +60 -0
- package/src/execution/__tests__/subagent-service.test.ts +73 -3
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +72 -3
- package/src/execution/__tests__/tool-action.test.ts +27 -5
- package/src/execution/__tests__/ui-channels.test.ts +187 -0
- package/src/execution/__tests__/ui-interaction-model.test.ts +67 -0
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +166 -0
- package/src/execution/__tests__/ui-request-handler.test.ts +204 -0
- package/src/execution/__tests__/ui-request-observability.test.ts +101 -0
- package/src/execution/__tests__/ui-request-queue.test.ts +133 -0
- package/src/execution/__tests__/worktree-manager.test.ts +1 -1
- package/src/execution/agent-registry.ts +1 -1
- package/src/execution/agent-result-mapper.ts +4 -1
- package/src/execution/channel-registry-access.ts +138 -0
- package/src/execution/concurrency-pool.ts +38 -6
- package/src/execution/dialog-queue.ts +329 -0
- package/src/execution/execute-options-mapper.ts +21 -4
- package/src/execution/execution-record.ts +5 -0
- package/src/execution/finalize-record.ts +160 -0
- package/src/execution/get-state-handshake.ts +104 -0
- package/src/execution/host-mode.ts +52 -0
- package/src/execution/manifest-store.ts +206 -0
- package/src/execution/notifier.ts +5 -1
- package/src/execution/path-encoding.ts +18 -0
- package/src/execution/pi-invocation.ts +1 -1
- package/src/execution/record-store.ts +110 -2
- package/src/execution/session-file-gc.ts +25 -3
- package/src/execution/session-reconstructor.ts +11 -0
- package/src/execution/session-runner.ts +228 -32
- package/src/execution/spawn-event-adapter.ts +219 -6
- package/src/execution/stdin-writer.ts +106 -0
- package/src/execution/stream-sink.ts +83 -0
- package/src/execution/subagent-service.ts +230 -235
- package/src/execution/subprocess-agent-runner.ts +16 -4
- package/src/execution/types.ts +23 -3
- package/src/execution/ui-channels.ts +216 -0
- package/src/execution/ui-interaction-model.ts +48 -0
- package/src/execution/ui-request-handler-factory.ts +175 -0
- package/src/execution/ui-request-observability.ts +77 -0
- package/src/execution/ui-request-queue.ts +168 -0
- package/src/index.ts +101 -4
- package/src/interface/__tests__/subagent-tool-prompt.test.ts +84 -0
- package/src/interface/__tests__/workflow-state-file-exposure.test.ts +38 -0
- package/src/interface/__tests__/workflow-tool-prompt.test.ts +50 -0
- package/src/interface/command-actions.ts +77 -0
- package/src/interface/commands.ts +40 -4
- package/src/interface/format.ts +2 -0
- package/src/interface/gui-mappers.ts +83 -0
- package/src/interface/helpers.ts +52 -9
- package/src/interface/list-component.ts +3 -1
- package/src/interface/subagent-actions.ts +44 -24
- package/src/interface/subagent-tool.ts +56 -24
- package/src/interface/subagents.ts +45 -5
- package/src/interface/tool-render.ts +16 -5
- package/src/interface/tool-workflow-script.ts +113 -15
- package/src/interface/tool-workflow.ts +92 -34
- package/src/interface/views/WorkflowsView.ts +13 -4
- package/src/interface/views/__tests__/detail-content-session-file.test.ts +70 -0
- package/src/interface/views/detail-content.ts +20 -0
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +208 -0
- package/src/orchestration/__tests__/agent-call-stream.test.ts +157 -0
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +2 -0
- package/src/orchestration/__tests__/execute-agent-call.test.ts +171 -0
- package/src/orchestration/__tests__/jsonl-run-store-session-file.test.ts +177 -0
- package/src/orchestration/__tests__/worker-script-builder.test.ts +15 -0
- package/src/orchestration/agent-opts-resolver.ts +11 -2
- package/src/orchestration/error-recovery.ts +131 -23
- package/src/orchestration/execute-agent-call.ts +12 -3
- package/src/orchestration/jsonl-run-store.ts +10 -0
- package/src/orchestration/lifecycle.ts +1 -1
- package/src/orchestration/models/agent-call.ts +7 -0
- package/src/orchestration/models/ports.ts +15 -2
- package/src/orchestration/models/run-spec.ts +6 -0
- package/src/orchestration/models/trace.ts +1 -0
- package/src/orchestration/models/types.ts +19 -0
- package/src/orchestration/node-ops.ts +2 -0
- package/src/orchestration/worker-script-builder.ts +1 -0
- package/workflows/README.md +58 -0
- package/workflows/chain.js +107 -0
- package/workflows/map-reduce.js +142 -0
- package/workflows/parallel.js +131 -0
- package/workflows/scatter-gather.js +146 -0
- package/agents/scout.md +0 -17
- package/examples/README.md +0 -43
- package/examples/chain.example.js +0 -92
- package/examples/map-reduce.example.js +0 -99
- package/examples/parallel.example.js +0 -82
- package/examples/scatter-gather.example.js +0 -106
- package/src/interface/gui-adapter.ts +0 -136
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @zhushanwen/pi-subagent-workflow
|
|
2
|
+
|
|
3
|
+
Pi 的 subagent + workflow 合并包:任务委派 + 多 agent 编排(chain / parallel / scatter-gather / map-reduce),单包统一执行链 + 分层配额(ADR-030)。
|
|
4
|
+
|
|
5
|
+
## 内置 Agents
|
|
6
|
+
|
|
7
|
+
| Agent | 角色 | 是否执行 |
|
|
8
|
+
|-------|------|---------|
|
|
9
|
+
| `context-builder` | 模糊需求 → 可执行规格(meta-prompt) | 只写 what |
|
|
10
|
+
| `planner` | 已明确需求 → 有序实施步骤 | 只写 how |
|
|
11
|
+
| `explorer` | 代码库结构摸底(只读) | 不改文件 |
|
|
12
|
+
| `researcher` | 外部资料 / 竞品 / 文档调研 | 不改文件 |
|
|
13
|
+
| `worker` | 编码 / 修复 / 文件操作 | 可改文件 |
|
|
14
|
+
| `reviewer` | 代码质量审查、找 bug | 只读 |
|
|
15
|
+
| `oracle` | 需求对齐核验 | 只读 |
|
|
16
|
+
| `orchestrator` | **纯协调器**:拆解 + 委派,不直接执行 | 只协调 |
|
|
17
|
+
| `general-purpose` | 兜底,无角色假设 | 按需 |
|
|
18
|
+
|
|
19
|
+
## Orchestrator 协调器模式
|
|
20
|
+
|
|
21
|
+
主 agent 禁用 bash / read / write / edit 等执行工具,只保留协调类工具,被迫作为纯协调器:拆解任务 → 委派 subagent → 汇总结果。orchestrator agent 自身也可递归委派子 orchestrator,实现分层任务拆解(深度受 `Depth: N/10` 护栏保护)。
|
|
22
|
+
|
|
23
|
+
可用工具仅 4 个:`todo`、`goal_control`、`workflow`、`subagent`。
|
|
24
|
+
|
|
25
|
+
### 启动命令
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# 方式一:CLI 工具白名单(临时验证最快)
|
|
29
|
+
pi --tools todo,goal_control,workflow,subagent
|
|
30
|
+
|
|
31
|
+
# 方式二:白名单 + 注入 orchestrator 的 system prompt(推荐,主进程也具备协调器视角)
|
|
32
|
+
pi --tools todo,goal_control,workflow,subagent \
|
|
33
|
+
--append-system-prompt "$(cat ~/.pi/agent/npm/node_modules/@zhushanwen/pi-subagent-workflow/agents/orchestrator.md)"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> **依赖**:需先安装本包及相关扩展
|
|
37
|
+
> ```bash
|
|
38
|
+
> pi install npm:@zhushanwen/pi-subagent-workflow
|
|
39
|
+
> pi install npm:@zhushanwen/pi-todo
|
|
40
|
+
> pi install npm:@zhushanwen/pi-goal
|
|
41
|
+
> ```
|
|
42
|
+
> `--tools` 白名单按 tool 注册名匹配。注意 goal 扩展注册的 tool 名是 `goal_control`(非 `goal`)。
|
|
43
|
+
|
|
44
|
+
### 递归深度
|
|
45
|
+
|
|
46
|
+
系统内置 `n = 10` 深度护栏(fork 链 + 嵌套取 max),超过抛 `ForkDepthExceededError`。实测建议控制在 **3-4 层**以内——更深层会因上下文逐层压缩导致信息失真。
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pi install npm:@zhushanwen/pi-subagent-workflow
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
name: context-builder
|
|
3
3
|
description: 需求分析与元提示生成
|
|
4
4
|
tools: read
|
|
5
|
-
extensions: false
|
|
6
|
-
category: planning
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
You are a context builder. Your role is to analyze requirements and generate structured prompts (meta-prompts) that another agent can execute.
|
|
@@ -14,4 +12,4 @@ Do not implement the task yourself. Your job is to produce a meta-prompt that ca
|
|
|
14
12
|
|
|
15
13
|
Use absolute file paths only.
|
|
16
14
|
|
|
17
|
-
**Output:** Produce a structured meta-prompt: objective, requirements (numbered), constraints, success criteria, and relevant file paths. Do
|
|
15
|
+
**Output:** Produce a structured meta-prompt — a task description for another agent to execute. Structure: objective, requirements (numbered), constraints, success criteria, and relevant file paths. Do NOT write implementation code, and do NOT produce a step-by-step plan (that is the planner's domain). Write what needs to be done, not how to do it step by step.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explorer
|
|
3
|
+
description: 快速代码库侦查
|
|
4
|
+
tools: read, bash, grep
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You are a codebase recon agent. Your role is to explore structure and return compressed context.
|
|
8
|
+
|
|
9
|
+
Complete the recon fully — cover the areas you were asked to explore. Don't stop after listing the top-level directory if the task asks for deeper structure.
|
|
10
|
+
|
|
11
|
+
You are read-only — inspect, never mutate. Bash commands are restricted below:
|
|
12
|
+
|
|
13
|
+
NEVER run (state-changing):
|
|
14
|
+
- File writes/deletes: rm, mv, cp, touch, mkdir, chmod, chown
|
|
15
|
+
- Git mutations: git add, git commit, git push, git reset, git checkout, git switch, git rebase, git merge, git stash, git clean
|
|
16
|
+
- Package installs: npm install, npm ci, pnpm install, yarn install, pip install
|
|
17
|
+
- Shell redirection to files: any command with `>` or `>>`
|
|
18
|
+
- Network mutations: curl, wget (downloads create/modify files)
|
|
19
|
+
- Process control: kill, pkill
|
|
20
|
+
|
|
21
|
+
Free to run (read-only): ls, cat, head, tail, wc, tree, file, stat, grep, find, rg, git log, git diff, git show, git status, git branch (without -D), and pipes combining these.
|
|
22
|
+
|
|
23
|
+
If unsure whether a command changes state, do NOT run it — report that you need it instead.
|
|
24
|
+
|
|
25
|
+
Use absolute file paths only.
|
|
26
|
+
|
|
27
|
+
**Output:** Return a compressed map of the codebase: key files (with paths), their purpose, entry points, and notable patterns. Do not paste full file contents — extract only what matters. Prefix inferences (not directly observed) with "Inferred:".
|
package/agents/oracle.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
name: oracle
|
|
3
3
|
description: 高上下文决策一致性守护
|
|
4
4
|
tools: read
|
|
5
|
-
extensions: false
|
|
6
|
-
category: planning
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
You are a decision oracle. Your role is to verify that the current state matches the intended objective, and flag any drift.
|
|
@@ -12,6 +10,8 @@ Complete the verification fully — check every requirement in the objective aga
|
|
|
12
10
|
|
|
13
11
|
Do not implement fixes yourself. Your job is to detect and report drift, not correct it.
|
|
14
12
|
|
|
13
|
+
Scope: requirements alignment only — verifying the current state matches the objective. If you notice code-level bugs (logic errors, security issues), note them in one line and defer to a reviewer. Do not analyze the bug itself.
|
|
14
|
+
|
|
15
15
|
Use absolute file paths only.
|
|
16
16
|
|
|
17
17
|
**Output:** For each requirement: state whether it is DONE (with evidence), PARTIALLY DONE (what's missing), or NOT DONE. End with a single verdict: aligned or drifted, and the single most critical gap if drifted.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: orchestrator
|
|
3
|
+
description: "纯协调器 agent,只做任务拆解与委派,不直接执行读写或命令操作"
|
|
4
|
+
tools: todo, goal_control, workflow, subagent
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
你是一个纯协调器(orchestrator)。你的职责是理解目标、拆解任务、分配给合适的执行 agent、汇总结果、对齐决策。你不亲自读写文件、不亲自跑命令——这些由子 agent 完成。
|
|
8
|
+
|
|
9
|
+
## 可用工具
|
|
10
|
+
|
|
11
|
+
你只有以下 4 个工具,其余全部不可用:
|
|
12
|
+
|
|
13
|
+
- **todo** — 追踪任务清单(拆解后的子任务状态)
|
|
14
|
+
- **goal_control** — 目标驱动循环 + 预算控制(长任务用目标封装)
|
|
15
|
+
- **workflow** — 多 agent 编排(chain / parallel / scatter-gather / map-reduce)
|
|
16
|
+
- **subagent** — 委派单个子任务给执行 agent
|
|
17
|
+
|
|
18
|
+
没有 bash / read / write / edit / grep。不要尝试调用它们。
|
|
19
|
+
|
|
20
|
+
## 执行 agent 选择
|
|
21
|
+
|
|
22
|
+
通过 `subagent` 工具的 `agent` 字段指定角色:
|
|
23
|
+
|
|
24
|
+
| Agent | 适用场景 |
|
|
25
|
+
|-------|---------|
|
|
26
|
+
| `explorer` | 摸清代码库结构、找入口点、理解模块关系 |
|
|
27
|
+
| `researcher` | 外部资料、竞品、文档调研 |
|
|
28
|
+
| `planner` | 已明确需求的有序实施步骤 |
|
|
29
|
+
| `context-builder` | 模糊需求转成可执行规格 |
|
|
30
|
+
| `worker` | 编码、修复、文件操作 |
|
|
31
|
+
| `reviewer` | 代码质量审查、找 bug |
|
|
32
|
+
| `oracle` | 需求对齐核验 |
|
|
33
|
+
| `orchestrator` | 子任务仍过复杂时递归拆解(见下) |
|
|
34
|
+
|
|
35
|
+
## 派发原则
|
|
36
|
+
|
|
37
|
+
1. **无依赖则并发**:独立子任务用并发 subagent(同一消息多个 start),不要串行
|
|
38
|
+
2. **有依赖则串行**:后置任务依赖前置产出时,等前置完成再派
|
|
39
|
+
3. **禁止空泛委托**:每个子任务必须包含目标、输入文件路径(绝对路径)、预期产出、约束
|
|
40
|
+
4. **综合而非转述**:汇总子 agent 结果时做跨任务对齐与决策,不原样转发
|
|
41
|
+
|
|
42
|
+
## 递归与深度控制
|
|
43
|
+
|
|
44
|
+
你可以把过复杂的子任务委派给子 `orchestrator`。嵌套深度受系统护栏保护(环境块 `Depth: N/10`)。实测建议控制在 **3-4 层以内**——超过后上下文逐层压缩,原始信息(文件内容、命令输出)到不了顶层,出现"电话传话"式失真。接近上限时主动收敛,改用 worker 直接执行。
|
|
45
|
+
|
|
46
|
+
## 输出
|
|
47
|
+
|
|
48
|
+
汇报每个子任务的派发决策与汇总结论。不叙述推导过程。受阻要明说,不要静默跳过。
|
package/agents/planner.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
name: planner
|
|
3
3
|
description: 实施计划 agent
|
|
4
4
|
tools: read
|
|
5
|
-
extensions: false
|
|
6
|
-
category: planning
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
You are a planning agent. Your role is to break down tasks and create implementation plans.
|
|
@@ -14,4 +12,4 @@ Do not implement the plan yourself. Your job is to produce the plan, not execute
|
|
|
14
12
|
|
|
15
13
|
Use absolute file paths only.
|
|
16
14
|
|
|
17
|
-
**Output:** Provide a numbered, ordered implementation plan. Each step: what to do, which files it touches (absolute paths), and dependencies on prior steps. Do
|
|
15
|
+
**Output:** Provide a numbered, ordered implementation plan — an execution guide for a worker. Each step: what to do, which files it touches (absolute paths), and dependencies on prior steps. Do NOT write code, and do NOT produce a meta-prompt or requirements analysis (that is the context-builder's domain). Describe ordered steps, not objectives or constraints.
|
package/agents/researcher.md
CHANGED
package/agents/reviewer.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
name: reviewer
|
|
3
3
|
description: 代码审查 agent(diff 分析、问题发现)
|
|
4
4
|
tools: read
|
|
5
|
-
extensions: false
|
|
6
|
-
category: coding
|
|
7
5
|
---
|
|
8
6
|
|
|
9
7
|
You are a code reviewer. Your role is to find bugs, logic errors, and security issues.
|
|
@@ -12,6 +10,8 @@ Complete the review fully — cover all files you were asked to review. Don't sk
|
|
|
12
10
|
|
|
13
11
|
Do not fix issues yourself. Your job is to report them, not implement fixes.
|
|
14
12
|
|
|
13
|
+
Scope: code-level issues only — bugs, logic errors, security vulnerabilities, performance problems. If an entire requirement is unimplemented (no code exists for it), note it as "requirements gap" in one line and defer to an oracle or planner for analysis. Do not analyze the gap itself.
|
|
14
|
+
|
|
15
15
|
Use absolute file paths only.
|
|
16
16
|
|
|
17
17
|
**Output:** For each issue found, report: severity (critical/major/minor), file path + line number, what the problem is, and why it matters. Do not narrate your review process.
|
package/agents/worker.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-subagent-workflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"description": "Unified subagent execution and multi-agent workflow orchestration for Pi — spawned-process agent runtime with sync/background modes, stateful workflow management with persistence, state machine, and execution tracing.",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"index.ts",
|
|
22
22
|
"agents/",
|
|
23
23
|
"skills/",
|
|
24
|
-
"
|
|
24
|
+
"workflows/",
|
|
25
25
|
"src/index.ts",
|
|
26
26
|
"src/execution/",
|
|
27
27
|
"src/orchestration/",
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
"./agents"
|
|
40
40
|
]
|
|
41
41
|
},
|
|
42
|
-
"dependencies": {
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@xyz-agent/extension-protocol": "^0.2.0"
|
|
44
|
+
},
|
|
43
45
|
"peerDependencies": {
|
|
44
46
|
"@mariozechner/pi-coding-agent": "*",
|
|
45
47
|
"@mariozechner/pi-ai": "*",
|
|
@@ -112,8 +112,8 @@ const final = await pipeline([
|
|
|
112
112
|
// 对每个 file 依次跑 review → fix
|
|
113
113
|
await pipeline(
|
|
114
114
|
files, // items
|
|
115
|
-
(file) => agent({ prompt: `Review ${file}`, description:
|
|
116
|
-
(review, file) => agent({ prompt: `Fix ${file}: ${JSON.stringify(review)}`, description:
|
|
115
|
+
(file) => agent({ prompt: `Review ${file}`, description: 'review', schema: {...} }),
|
|
116
|
+
(review, file) => agent({ prompt: `Fix ${file}: ${JSON.stringify(review)}`, description: 'fix' }),
|
|
117
117
|
);
|
|
118
118
|
// stage 函数签名:(prevResult, currentItem) => result;第一个 stage 只收 currentItem
|
|
119
119
|
```
|
|
@@ -158,7 +158,7 @@ const results = await parallel(
|
|
|
158
158
|
);
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
>
|
|
161
|
+
> 内置通用编排 workflow(chain / parallel / scatter-gather / map-reduce,可直接 `workflow run`,用 `agent()` 自包含实现)见 `extensions/subagent-workflow/workflows/`。本段教 `workflow()` 嵌套 API,workflows 目录是开箱即用的通用编排工具(用 `agent()` 而非 `workflow()` 嵌套)。
|
|
162
162
|
|
|
163
163
|
### Other globals
|
|
164
164
|
|
|
@@ -224,7 +224,7 @@ while (round < MAX_ROUNDS) {
|
|
|
224
224
|
},
|
|
225
225
|
required: ['mustFix'],
|
|
226
226
|
},
|
|
227
|
-
description:
|
|
227
|
+
description: 'review',
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
// result is already a parsed object thanks to schema
|
|
@@ -286,7 +286,7 @@ const review = await agent({
|
|
|
286
286
|
},
|
|
287
287
|
required: ['findings'],
|
|
288
288
|
},
|
|
289
|
-
description:
|
|
289
|
+
description: 'review',
|
|
290
290
|
});
|
|
291
291
|
|
|
292
292
|
const verify = await agent({
|
|
@@ -301,7 +301,7 @@ Did the review cover: (1) all functions in the file, (2) at least 3 potential is
|
|
|
301
301
|
},
|
|
302
302
|
required: ['valid'],
|
|
303
303
|
},
|
|
304
|
-
description:
|
|
304
|
+
description: 'verify-review',
|
|
305
305
|
});
|
|
306
306
|
|
|
307
307
|
if (!verify.valid) {
|
|
@@ -147,13 +147,13 @@ describe("AgentRegistry.discoverAll", () => {
|
|
|
147
147
|
// ============================================================
|
|
148
148
|
|
|
149
149
|
describe("createPackageBuiltinRegistry", () => {
|
|
150
|
-
it("discovers packaged agents/*.md (worker, reviewer,
|
|
150
|
+
it("discovers packaged agents/*.md (worker, reviewer, explorer, etc.)", () => {
|
|
151
151
|
// [HISTORICAL] S6: 包内 agents/ 此前未被接通——discoverAll 从未调用,
|
|
152
152
|
// 导致 pi install 后包内 agent 定义开箱不可用。
|
|
153
153
|
const builtin = createPackageBuiltinRegistry();
|
|
154
154
|
const names = builtin.list();
|
|
155
|
-
// 包内至少有 worker/reviewer/
|
|
156
|
-
expect(names).toEqual(expect.arrayContaining(["worker", "reviewer", "
|
|
155
|
+
// 包内至少有 worker/reviewer/explorer 等核心 agent
|
|
156
|
+
expect(names).toEqual(expect.arrayContaining(["worker", "reviewer", "explorer", "researcher", "planner", "oracle", "context-builder"]));
|
|
157
157
|
// 每个 agent 都有 systemPrompt
|
|
158
158
|
for (const name of names) {
|
|
159
159
|
const cfg = builtin.get(name);
|
|
@@ -33,6 +33,23 @@ describe("mapToWorkflowAgentResult (D-A10)", () => {
|
|
|
33
33
|
expect(result.toolCalls).toEqual([]);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
// ── sessionFile 透传(方案 A:让 workflow 继承 subagent 的 session jsonl 路径)──
|
|
37
|
+
|
|
38
|
+
it("映射 sessionFile: subagents AgentResult.sessionFile → workflow AgentResult.sessionFile 透传", () => {
|
|
39
|
+
const r: SubagentsAgentResult = {
|
|
40
|
+
...minimalResult,
|
|
41
|
+
sessionFile: "/abs/path/.pi/agent/subagents/enc/sessions/2026-07-15T10-00-00-000Z_session-123.jsonl",
|
|
42
|
+
};
|
|
43
|
+
const result = mapToWorkflowAgentResult(r);
|
|
44
|
+
expect(result.sessionFile).toBe("/abs/path/.pi/agent/subagents/enc/sessions/2026-07-15T10-00-00-000Z_session-123.jsonl");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("映射 sessionFile: 无 sessionFile → workflow AgentResult.sessionFile undefined(窗口期/未回填)", () => {
|
|
48
|
+
const r: SubagentsAgentResult = { ...minimalResult, sessionFile: undefined };
|
|
49
|
+
const result = mapToWorkflowAgentResult(r);
|
|
50
|
+
expect(result.sessionFile).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
|
|
36
53
|
it("映射 parsedOutput 透传(structured-output 契约 BC-8)", () => {
|
|
37
54
|
const parsedData = { score: 0.95, label: "positive" };
|
|
38
55
|
const r: SubagentsAgentResult = { ...minimalResult, parsedOutput: parsedData };
|
|
@@ -49,10 +66,15 @@ describe("mapToWorkflowAgentResult (D-A10)", () => {
|
|
|
49
66
|
expect(result.content).toBe("Hello"); // content 仍保留(可能有部分输出)
|
|
50
67
|
});
|
|
51
68
|
|
|
52
|
-
it("映射失败: success=false 但无 error
|
|
69
|
+
it("映射失败: success=false 但无 error(abort 路径)→ error 填入 fallback 而非 undefined", () => {
|
|
70
|
+
// H4: session-runner.ts abort 时 success=false, error=undefined。
|
|
71
|
+
// 旧代码 error=undefined → executeAgentCall 误判 completed。
|
|
72
|
+
// 修复后应 synthesize fallback error。
|
|
53
73
|
const r: SubagentsAgentResult = { ...minimalResult, success: false };
|
|
54
74
|
const result = mapToWorkflowAgentResult(r);
|
|
55
|
-
expect(result.error).
|
|
75
|
+
expect(result.error).toBeDefined();
|
|
76
|
+
expect(typeof result.error).toBe("string");
|
|
77
|
+
expect(result.error.length).toBeGreaterThan(0);
|
|
56
78
|
});
|
|
57
79
|
|
|
58
80
|
it("映射成功: success=true 且 error 存在 → error=undefined(不误填)", () => {
|