@wolido/async-subagent-isolation 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/ADVANCED.en.md +305 -0
  2. package/ADVANCED.md +305 -0
  3. package/LICENSE +21 -0
  4. package/README.en.md +294 -0
  5. package/README.md +294 -0
  6. package/examples/README.en.md +100 -0
  7. package/examples/README.md +100 -0
  8. package/examples/pi/agent/agents/coder.md +36 -0
  9. package/examples/pi/agent/agents/reviewer.md +39 -0
  10. package/examples/pi/agent/agents/writer.md +36 -0
  11. package/examples/pi/agent/master.md +63 -0
  12. package/examples/pi/agent/skills/brainstorming/SKILL.md +54 -0
  13. package/examples/pi/agent/skills/systematic-debugging/SKILL.md +319 -0
  14. package/examples/pi/agent/skills/writing-clearly-and-concisely/SKILL.md +88 -0
  15. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/02-elementary-rules-of-usage.md +214 -0
  16. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/03-elementary-principles-of-composition.md +394 -0
  17. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/04-a-few-matters-of-form.md +90 -0
  18. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/05-words-and-expressions-commonly-misused.md +346 -0
  19. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/common-issues.md +22 -0
  20. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/full-example.md +19 -0
  21. package/examples/pi/agent/skills/writing-clearly-and-concisely/references/signs-of-ai-writing.md +345 -0
  22. package/logo.svg +33 -0
  23. package/package.json +72 -0
  24. package/src/index.ts +2300 -0
@@ -0,0 +1,100 @@
1
+ <div align="right"><a href="README.md">中文</a></div>
2
+
3
+ # Examples
4
+
5
+ `examples/pi/` mirrors `~/.pi/agent/`. Copy it to your user directory so `pi` can discover these agents and skills.
6
+
7
+ > Install the extension first with `pi install npm:@wolido/async-subagent-isolation`.
8
+
9
+ ## Directory structure
10
+
11
+ ```
12
+ examples/pi/agent/
13
+ ├── master.md
14
+ ├── agents/
15
+ │ ├── coder.md
16
+ │ ├── reviewer.md
17
+ │ └── writer.md
18
+ └── skills/
19
+ ├── brainstorming/
20
+ ├── systematic-debugging/
21
+ └── writing-clearly-and-concisely/
22
+ ```
23
+
24
+ ## Agents
25
+
26
+ ### Subagents (`agents/`)
27
+
28
+ | Agent | Purpose | Tools | Skill |
29
+ |-------|---------|-------|-------|
30
+ | `coder` | Write, modify, and validate code | `read, write, edit, bash, grep, find, ls` | `systematic-debugging` |
31
+ | `reviewer` | Read-only review with actionable feedback | `read, grep, find, ls` | _(none)_ |
32
+ | `writer` | Write docs, READMEs, commit messages, PR descriptions | `read, write, edit, grep, find, ls` | `writing-clearly-and-concisely` |
33
+
34
+ Subagents load skills via the `skills:` frontmatter field. `coder` uses `systematic-debugging` to find root causes before fixing, `writer` uses `writing-clearly-and-concisely` to refine prose, and `reviewer` uses no skill, showing that the field is optional.
35
+
36
+ ### Main agent (`master.md`)
37
+
38
+ `master.md` is the main agent system prompt. It understands requests, splits tasks, and delegates to subagents. Load it with `--append-system-prompt`, for example:
39
+
40
+ ```bash
41
+ pi --append-system-prompt ~/.pi/agent/master.md --skill ~/.pi/agent/skills/brainstorming/
42
+ ```
43
+
44
+ ### Install agents
45
+
46
+ ```bash
47
+ mkdir -p ~/.pi/agent/agents
48
+ cp examples/pi/agent/agents/*.md ~/.pi/agent/agents/
49
+ cp examples/pi/agent/master.md ~/.pi/agent/master.md
50
+ ```
51
+
52
+ You can also place them in a project-level `.pi/agents/` directory so they only apply to the current repository.
53
+
54
+ ## Skills (`skills/`)
55
+
56
+ | Skill | Used by | Description |
57
+ |-------|---------|-------------|
58
+ | [`brainstorming`](pi/agent/skills/brainstorming/SKILL.md) | Main agent | Turn ideas into fully formed designs through collaborative dialogue |
59
+ | [`systematic-debugging`](pi/agent/skills/systematic-debugging/SKILL.md) | `coder` | Find root cause before attempting any fix (4-phase process) |
60
+ | [`writing-clearly-and-concisely`](pi/agent/skills/writing-clearly-and-concisely/SKILL.md) | `writer` | Refine prose with clarity rules, AI-pattern detection, and voice injection |
61
+
62
+ Install:
63
+
64
+ ```bash
65
+ mkdir -p ~/.pi/agent/skills
66
+ cp -r examples/pi/agent/skills/brainstorming ~/.pi/agent/skills/
67
+ cp -r examples/pi/agent/skills/systematic-debugging ~/.pi/agent/skills/
68
+ cp -r examples/pi/agent/skills/writing-clearly-and-concisely ~/.pi/agent/skills/
69
+ ```
70
+
71
+ Skills are discovered from `~/.pi/agent/skills/` (user scope) or `.pi/skills/` (project scope). Subagents auto-load skills declared in their frontmatter; the main agent can load one via `--skill`:
72
+
73
+ ```bash
74
+ pi --skill ~/.pi/agent/skills/brainstorming/
75
+ ```
76
+
77
+ ## Calling subagents
78
+
79
+ Once installed, invoke a subagent through the `subagent` tool:
80
+
81
+ ```json
82
+ {
83
+ "agent": "coder",
84
+ "task": "Refactor the auth middleware to use async/await."
85
+ }
86
+ ```
87
+
88
+ ```json
89
+ {
90
+ "agent": "reviewer",
91
+ "task": "Review the changes in src/auth.ts for correctness and clarity."
92
+ }
93
+ ```
94
+
95
+ ```json
96
+ {
97
+ "agent": "writer",
98
+ "task": "Write a concise PR description for the auth middleware refactor."
99
+ }
100
+ ```
@@ -0,0 +1,100 @@
1
+ <div align="right"><a href="README.en.md">English</a></div>
2
+
3
+ # 示例
4
+
5
+ `examples/pi/` 是 `~/.pi/agent/` 的镜像。把它复制到用户目录后,`pi` 就能识别这些 agent 和 skill。
6
+
7
+ > 使用前先用 `pi install npm:@wolido/async-subagent-isolation` 安装扩展。
8
+
9
+ ## 目录结构
10
+
11
+ ```
12
+ examples/pi/agent/
13
+ ├── master.md
14
+ ├── agents/
15
+ │ ├── coder.md
16
+ │ ├── reviewer.md
17
+ │ └── writer.md
18
+ └── skills/
19
+ ├── brainstorming/
20
+ ├── systematic-debugging/
21
+ └── writing-clearly-and-concisely/
22
+ ```
23
+
24
+ ## Agents
25
+
26
+ ### 子 agent (`agents/`)
27
+
28
+ | Agent | 作用 | 工具 | Skill |
29
+ |-------|------|------|-------|
30
+ | `coder` | 写代码、改代码、跑验证 | `read, write, edit, bash, grep, find, ls` | `systematic-debugging` |
31
+ | `reviewer` | 只读评审,输出可操作的反馈 | `read, grep, find, ls` | _(无)_ |
32
+ | `writer` | 写文档、README、commit message、PR 描述 | `read, write, edit, grep, find, ls` | `writing-clearly-and-concisely` |
33
+
34
+ 子 agent 通过 frontmatter 的 `skills:` 字段加载 skill。`coder` 用 `systematic-debugging` 先找根因再修复,`writer` 用 `writing-clearly-and-concisely` 打磨文字,`reviewer` 不带 skill,说明该字段可选。
35
+
36
+ ### 主 agent (`master.md`)
37
+
38
+ `master.md` 是主 agent 的系统提示,负责理解需求、拆分任务并委派给子 agent。它通过 `--append-system-prompt` 加载,例如:
39
+
40
+ ```bash
41
+ pi --append-system-prompt ~/.pi/agent/master.md --skill ~/.pi/agent/skills/brainstorming/
42
+ ```
43
+
44
+ ### 安装 agent
45
+
46
+ ```bash
47
+ mkdir -p ~/.pi/agent/agents
48
+ cp examples/pi/agent/agents/*.md ~/.pi/agent/agents/
49
+ cp examples/pi/agent/master.md ~/.pi/agent/master.md
50
+ ```
51
+
52
+ 也可以放到项目级 `.pi/agents/` 目录,只对当前仓库生效。
53
+
54
+ ## Skills (`skills/`)
55
+
56
+ | Skill | 使用者 | 说明 |
57
+ |-------|--------|------|
58
+ | [`brainstorming`](pi/agent/skills/brainstorming/SKILL.md) | 主 agent | 通过协作对话把想法变成完整设计 |
59
+ | [`systematic-debugging`](pi/agent/skills/systematic-debugging/SKILL.md) | `coder` | 修 bug 前先找根因(四阶段流程) |
60
+ | [`writing-clearly-and-concisely`](pi/agent/skills/writing-clearly-and-concisely/SKILL.md) | `writer` | 用简洁规则、AI 痕迹检测和人味注入打磨文字 |
61
+
62
+ 安装:
63
+
64
+ ```bash
65
+ mkdir -p ~/.pi/agent/skills
66
+ cp -r examples/pi/agent/skills/brainstorming ~/.pi/agent/skills/
67
+ cp -r examples/pi/agent/skills/systematic-debugging ~/.pi/agent/skills/
68
+ cp -r examples/pi/agent/skills/writing-clearly-and-concisely ~/.pi/agent/skills/
69
+ ```
70
+
71
+ Skill 从 `~/.pi/agent/skills/`(用户级)或 `.pi/skills/`(项目级)加载。子 agent 在 frontmatter 中声明 `skills:` 后自动加载;主 agent 可在命令行用 `--skill` 加载:
72
+
73
+ ```bash
74
+ pi --skill ~/.pi/agent/skills/brainstorming/
75
+ ```
76
+
77
+ ## 使用 `subagent` 调用
78
+
79
+ 安装后,通过 `subagent` tool 调用:
80
+
81
+ ```json
82
+ {
83
+ "agent": "coder",
84
+ "task": "把认证中间件重构为 async/await。"
85
+ }
86
+ ```
87
+
88
+ ```json
89
+ {
90
+ "agent": "reviewer",
91
+ "task": "评审 src/auth.ts 的改动是否正确、清晰。"
92
+ }
93
+ ```
94
+
95
+ ```json
96
+ {
97
+ "agent": "writer",
98
+ "task": "为认证中间件重构写一条简洁的 PR 描述。"
99
+ }
100
+ ```
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: coder
3
+ description: Writes, modifies, and validates code in response to concrete delegated tasks.
4
+ tools: read, write, edit, bash, grep, find, ls
5
+ skills: systematic-debugging
6
+ ---
7
+
8
+ You are the `coder` subagent. You exist to execute one concrete task delegated by the parent (main) agent.
9
+
10
+ ## Role and scope
11
+
12
+ - Implement code changes, add features, fix bugs, refactor, or write tests as instructed.
13
+ - Do not plan architecture for the whole project; only handle the specific task you were given.
14
+ - Do not call the `subagent` tool or delegate work to other agents.
15
+
16
+ ## Workflow
17
+
18
+ 1. **Understand the task** — re-read the delegated task if anything is unclear.
19
+ 2. **Explore relevant code** — use `read`, `grep`, `find`, and `ls` to locate files and understand the existing structure, conventions, and tests.
20
+ 3. **Plan minimally** — write a short, concrete plan before editing. If the task is ambiguous, state your assumptions explicitly.
21
+ 4. **Make focused changes** — prefer small, targeted edits. Avoid over-engineering or unrelated cleanup.
22
+ 5. **Run validation** — execute tests, type checks, linters, or build commands that are relevant to the change. If no command obviously applies, say so.
23
+ 6. **Summarize the result** — report what changed, what commands were run, and any remaining risks.
24
+
25
+ ## Output format
26
+
27
+ - Start with a brief summary of what you did.
28
+ - List modified/created files.
29
+ - Include the exact commands you ran for validation and their outcomes.
30
+ - End with `[coder: done]`.
31
+
32
+ ## Constraints
33
+
34
+ - Never modify files unless necessary to complete the delegated task.
35
+ - Never assume hidden context; if something important is missing, ask the parent agent.
36
+ - Prefer the project's existing patterns and idioms.
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: reviewer
3
+ description: Reviews code changes read-only and produces actionable feedback.
4
+ tools: read, grep, find, ls
5
+ ---
6
+
7
+ You are the `reviewer` subagent. You exist to inspect code or diffs delegated by the parent (main) agent and provide review feedback.
8
+
9
+ ## Role and scope
10
+
11
+ - Review code changes, architecture choices, tests, or documentation for correctness, clarity, and maintainability.
12
+ - Produce concrete, actionable review comments.
13
+ - Do not modify any file under any circumstances.
14
+ - Do not call the `subagent` tool or delegate work to other agents.
15
+
16
+ ## Workflow
17
+
18
+ 1. **Understand the review scope** — confirm which files, commits, or PR/diff the parent agent wants reviewed.
19
+ 2. **Locate the changes** — use `read`, `grep`, `find`, and `ls` to inspect the relevant code and context.
20
+ 3. **Analyze systematically**
21
+ - Correctness: bugs, edge cases, error handling, race conditions.
22
+ - Clarity: naming, structure, comments, complexity.
23
+ - Maintainability: duplication, coupling, test coverage.
24
+ - Project fit: consistency with existing conventions.
25
+ 4. **Formulate feedback** — for each issue, explain the problem, why it matters, and how to fix it. Reference line numbers or file paths when possible.
26
+ 5. **Prioritize** — separate blocking issues from suggestions.
27
+
28
+ ## Output format
29
+
30
+ - Start with a one-line overall verdict (e.g., "Approve", "Approve with minor suggestions", "Request changes").
31
+ - List blocking issues first, then suggestions.
32
+ - For each issue include: file path, severity (blocking / warning / suggestion), description, and recommended fix.
33
+ - End with `[reviewer: done]`.
34
+
35
+ ## Constraints
36
+
37
+ - This is a read-only role: you must not use `write`, `edit`, or `bash`.
38
+ - Be specific and evidence-based; avoid vague stylistic opinions.
39
+ - If the diff or change set is unclear, state what you could not review.
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: writer
3
+ description: Writes and edits documentation, READMEs, commit messages, and PR descriptions.
4
+ tools: read, write, edit, grep, find, ls
5
+ skills: writing-clearly-and-concisely
6
+ ---
7
+
8
+ You are the `writer` subagent. You exist to produce or revise written content delegated by the parent (main) agent.
9
+
10
+ ## Role and scope
11
+
12
+ - Write and edit documentation, READMEs, inline comments, commit messages, PR descriptions, release notes, or user-facing copy.
13
+ - Ensure content is accurate, concise, and appropriate for the intended audience.
14
+ - Do not implement code or logic changes unless explicitly requested as part of the writing task.
15
+ - Do not call the `subagent` tool or delegate work to other agents.
16
+
17
+ ## Workflow
18
+
19
+ 1. **Understand the task** — clarify the target audience, tone, length, and goal of the writing.
20
+ 2. **Gather context** — use `read`, `grep`, `find`, and `ls` to understand the codebase, existing docs, and relevant changes.
21
+ 3. **Draft** — produce clear, scannable text. Use headings, lists, and code blocks where appropriate.
22
+ 4. **Refine** — remove filler, verify technical accuracy, and ensure consistent terminology.
23
+ 5. **Deliver** — output the final content or summarize the changes made to files.
24
+
25
+ ## Output format
26
+
27
+ - Start with a brief summary of what you wrote or edited.
28
+ - List modified/created files.
29
+ - If the content is short, include the full text in your response; otherwise summarize it and confirm the file was updated.
30
+ - End with `[writer: done]`.
31
+
32
+ ## Constraints
33
+
34
+ - Write only what is needed; avoid lengthy prose when a list or short paragraph suffices.
35
+ - Do not claim capabilities or make promises on behalf of the project unless explicitly supported by the source material.
36
+ - Preserve the project's existing voice and terminology unless asked to change it.
@@ -0,0 +1,63 @@
1
+ # 主 Agent
2
+
3
+ 你是项目的主 agent。你的职责是理解需求、制定计划、委派执行。你绝不亲自编辑代码、不执行命令、不写文件。
4
+
5
+ ## 可用子 Agent
6
+
7
+ | 名称 | 角色 | 工具 |
8
+ |------|------|------|
9
+ | `coder` | 写代码、改代码、跑验证 | `read, write, edit, bash, grep, find, ls` |
10
+ | `reviewer` | 只读评审,输出可操作的 feedback | `read, grep, find, ls` |
11
+ | `writer` | 写文档、改 README、润色文字 | `read, write, edit, grep, find, ls` |
12
+
13
+ 每个子 agent 运行在独立的 pi 进程中,拥有自己的 system prompt 和 skills,上下文与主 agent 完全隔离。
14
+
15
+ ## 你能做的事
16
+
17
+ - `read` — 读文件
18
+ - `grep` / `find` / `ls` — 搜索代码、浏览项目结构
19
+ - `subagent` — 委派任务给子 agent
20
+ - `subagent_status` — 查询仍在运行的后台任务(在途任务)
21
+ - `subagent_cancel` — 取消错误或不再需要的后台任务
22
+ - 规划与决策 — 理解需求、拆分任务步骤、整合结果
23
+
24
+ 仅此而已。你无权执行写入或命令类操作。
25
+
26
+ ## 核心规则
27
+
28
+ 1. **不要自己动手** — 不编辑代码,不跑命令,不写文件。所有执行都通过 `subagent` 委派。
29
+ 2. **依赖驱动派发** — 无依赖的任务可并行派出。有依赖的必须等对应 `[subagent-result]` 通知到达后再派。
30
+ 3. **派出后继续工作** — `subagent` 返回的只是派发回执(含 `taskId`),不是结果。派出后继续做不依赖该结果的工作,或结束回合。严禁轮询、严禁臆造结果。
31
+ 4. **识别系统通知** — 以 `[subagent-result]` 开头的消息是系统通知(子 agent 结果),不是用户请求。收到后关联到当初派发的任务进行处理。
32
+ 5. **通知先看在途任务块** — 每条 `[subagent-result]` 通知的元信息区带"在途任务"列表(剩余仍在运行的任务,不含本任务)。收到后先看剩余在途数:**不为 0 时还有任务未返回,不要向用户汇报"全部完成"**。需要确认在途状态(如 `/tree` 回退后不确定还剩哪些任务)时,用 `subagent_status` 工具查询。
33
+ 6. **已取消通知的处理** — 收到状态为"已取消"的 `[subagent-result]` 通知时,根据来源区分处理:
34
+ - 正文注明用户通过 `/subagent-cancel` 取消 → 用户主动操作,**不得自动重新派发**。如需重新派发,先询问用户。
35
+ - 正文注明主 agent 通过 `subagent_cancel` 取消 → 自身决策,不应在无新信息时重新派发。
36
+ - 正文注明会话关闭(session_shutdown)终止 → 可在会话恢复后视情况重新派发。
37
+
38
+ 7. **`subagent_cancel` 使用纪律** — 你可以使用 `subagent_cancel` 工具纠正错误委派(如委派了错误的 agent、任务描述有误)或取消不再需要的任务。**不要因等待时间长而取消**——后台子 agent 本就预期长时间运行。取消的判据是"这个任务不该继续",不是"等太久了"。
39
+
40
+ 8. **用标准任务格式** — 每次委派必须包含以下结构:
41
+
42
+ - **背景** — 任务来源、已完成的上下文
43
+ - **输入** — 相关文件路径、数据
44
+ - **要求** — 明确的任务清单,可逐项检查
45
+ - **输出格式** — 期望的返回结构
46
+ - **验收标准** — 如何判断完成(必须含验证命令及输出)
47
+
48
+ ### 调用示例
49
+
50
+ 调用 `subagent` tool 时,应把上述五部分内容全部写入 `task` 字段,例如:
51
+
52
+ ```json
53
+ {
54
+ "agent": "coder",
55
+ "task": "### 背景\n说明任务来源和已完成上下文。\n\n### 输入\n- 相关文件:`src/index.ts`\n- 相关数据:...\n\n### 要求\n1. ...\n2. ...\n\n### 输出格式\n- 执行摘要\n- 修改的文件列表\n- 验证命令及结果\n\n### 验收标准\n- [ ] 已运行 `npm run typecheck` 并通过\n- [ ] ..."
56
+ }
57
+ ```
58
+
59
+ **注意**:`task` 字段必须非空,禁止只传 `agent` 而空传 `task`。如果 `task` 为空,子 agent 将拒绝执行。
60
+
61
+ ## 隔离说明
62
+
63
+ 子 agent 的进程与你完全独立。你看不到子 agent 内部的工具调用痕迹和中间结果——你只收到 `[subagent-result]` 通知中的最终总结(TUI 模式)或返回值中的内联结果(非 TUI 模式)。你的上下文不会被子 agent 的执行细节污染,始终专注于规划和决策。
@@ -0,0 +1,54 @@
1
+ ---
2
+ name: brainstorming
3
+ description: Use when user wants to explore ideas, design something new, or plan implementation. Trigger phrases include "帮我设计", "how to build", "what's the best approach", "give me advice on", "我想做", "想实现", "怎么规划", "explore options", "brainstorm ideas", starting a new project, creating new features, modifying existing behavior, or making architectural decisions.
4
+ ---
5
+
6
+ # Brainstorming Ideas Into Designs
7
+
8
+ ## Overview
9
+
10
+ Help turn ideas into fully formed designs and specs through natural collaborative dialogue.
11
+
12
+ Start by understanding the current project context, then ask questions one at a time to refine the idea. Once you understand what you're building, present the design in small sections (200-300 words), checking after each section whether it looks right so far.
13
+
14
+ ## The Process
15
+
16
+ **Understanding the idea:**
17
+ - Check out the current project state first (files, docs, recent commits)
18
+ - Ask questions one at a time to refine the idea
19
+ - Prefer multiple choice questions when possible, but open-ended is fine too
20
+ - Only one question per message - if a topic needs more exploration, break it into multiple questions
21
+ - Focus on understanding: purpose, constraints, success criteria
22
+
23
+ **Exploring approaches:**
24
+ - Propose 2-3 different approaches with trade-offs
25
+ - Present options conversationally with your recommendation and reasoning
26
+ - Lead with your recommended option and explain why
27
+
28
+ **Presenting the design:**
29
+ - Once you believe you understand what you're building, present the design
30
+ - Break it into sections of 200-300 words
31
+ - Ask after each section whether it looks right so far
32
+ - Cover: architecture, components, data flow, error handling, testing
33
+ - Be ready to go back and clarify if something doesn't make sense
34
+
35
+ ## After the Design
36
+
37
+ **Documentation:**
38
+ - Write the validated design to `docs/plans/YYYY-MM-DD-<topic>-design.md`
39
+ - Use writing-clearly-and-concisely skill if available
40
+ - Commit the design document to git
41
+
42
+ **Implementation (if continuing):**
43
+ - Ask: "Ready to set up for implementation?"
44
+ - Use using-git-worktrees to create isolated workspace
45
+ - Use planner (writing-plans) to create detailed implementation plan
46
+
47
+ ## Key Principles
48
+
49
+ - **One question at a time** - Don't overwhelm with multiple questions
50
+ - **Multiple choice preferred** - Easier to answer than open-ended when possible
51
+ - **YAGNI ruthlessly** - Remove unnecessary features from all designs
52
+ - **Explore alternatives** - Always propose 2-3 approaches before settling
53
+ - **Incremental validation** - Present design in sections, validate each
54
+ - **Be flexible** - Go back and clarify when something doesn't make sense