@tianhai/pi-workflow-kit 0.17.1 → 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.
- package/README.md +91 -64
- package/agents/pwk-hazard-reviewer.md +24 -0
- package/agents/pwk-smell-reviewer.md +17 -0
- package/agents/pwk-spec-reviewer.md +14 -0
- package/agents/pwk-tracing-reviewer.md +14 -0
- package/docs/developer-usage-guide.md +49 -37
- package/docs/lessons.md +13 -0
- package/docs/oversight-model.md +19 -9
- package/docs/workflow-phases.md +58 -29
- package/extensions/workflow-guard.ts +190 -91
- package/package.json +19 -3
- package/skills/pwk-brainstorming/SKILL.md +60 -0
- package/skills/pwk-code-review/SKILL.md +46 -0
- package/skills/{diagnose → pwk-diagnose}/SKILL.md +3 -2
- package/skills/pwk-executing-tasks/SKILL.md +154 -0
- package/skills/pwk-finalizing/SKILL.md +78 -0
- package/skills/pwk-status/SKILL.md +28 -0
- package/skills/pwk-writing-plans/SKILL.md +83 -0
- package/docs/plans/2026-06-03-karpathy-guidelines-ab-comparison.md +0 -166
- package/docs/plans/completed/2026-04-11-checkpoint-review-gates-design.md +0 -50
- package/docs/plans/completed/2026-04-11-checkpoint-review-gates-implementation.md +0 -98
- package/docs/plans/completed/2026-04-11-finalizing-merge-options-design.md +0 -33
- package/docs/plans/completed/2026-04-11-finalizing-merge-options-implementation.md +0 -75
- package/docs/plans/completed/2026-04-11-workspace-setup-design.md +0 -28
- package/docs/plans/completed/2026-04-11-workspace-setup-implementation.md +0 -57
- package/docs/plans/completed/2026-04-15-bash-guard-design.md +0 -39
- package/docs/plans/completed/2026-04-15-bash-guard-implementation.md +0 -229
- package/docs/plans/completed/2026-04-21-workflow-guard-safe-commands-design.md +0 -172
- package/docs/plans/completed/2026-04-21-workflow-guard-safe-commands-implementation.md +0 -168
- package/docs/plans/completed/2026-04-22-go-readonly-safe-commands-implementation.md +0 -54
- package/docs/plans/completed/2026-04-28-executing-tasks-redesign-design.md +0 -171
- package/docs/plans/completed/2026-04-28-executing-tasks-redesign-implementation.md +0 -208
- package/docs/plans/completed/2026-04-28-executing-tasks-redesign-progress.md +0 -14
- package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-design.md +0 -154
- package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-implementation.md +0 -315
- package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-progress.md +0 -15
- package/docs/plans/completed/2026-05-08-checkpoint-gates-design.md +0 -235
- package/docs/plans/completed/2026-05-08-checkpoint-gates-implementation.md +0 -83
- package/docs/plans/completed/2026-05-08-checkpoint-gates-progress.md +0 -11
- package/docs/plans/completed/2026-05-08-lessons-learned-design.md +0 -76
- package/docs/plans/completed/2026-05-08-lessons-learned-implementation.md +0 -219
- package/docs/plans/completed/2026-05-08-lessons-learned-progress.md +0 -15
- package/docs/plans/completed/2026-05-08-migrate-earendil-works-design.md +0 -39
- package/docs/plans/completed/2026-05-08-migrate-earendil-works-implementation.md +0 -45
- package/docs/plans/completed/2026-05-08-migrate-earendil-works-progress.md +0 -10
- package/docs/plans/completed/2026-05-08-worktree-handoff-design.md +0 -118
- package/docs/plans/completed/2026-05-08-worktree-handoff-implementation.md +0 -140
- package/docs/plans/completed/2026-05-08-worktree-handoff-progress.md +0 -10
- package/docs/plans/completed/2026-05-20-generic-lessons-design.md +0 -70
- package/docs/plans/completed/2026-05-20-generic-lessons-implementation.md +0 -114
- package/docs/plans/completed/2026-05-20-generic-lessons-progress.md +0 -11
- package/docs/plans/completed/2026-05-22-agentic-agile-enhancements-design.md +0 -77
- package/docs/plans/completed/2026-05-22-agentic-agile-enhancements-implementation.md +0 -473
- package/docs/plans/completed/2026-05-25-design-review-split-implementation.md +0 -622
- package/docs/plans/completed/2026-05-25-design-review-split-progress.md +0 -16
- package/docs/plans/completed/2026-05-25-pr5-improvements-implementation.md +0 -273
- package/docs/plans/completed/2026-05-25-pr5-improvements-progress.md +0 -17
- package/docs/plans/completed/2026-06-03-add-verify-skill-design.md +0 -51
- package/docs/plans/completed/2026-06-03-add-verify-skill-implementation.md +0 -111
- package/docs/plans/completed/2026-06-03-add-verify-skill-progress.md +0 -11
- package/docs/plans/completed/2026-06-03-verify-skill-design.md +0 -176
- package/skills/brainstorming/SKILL.md +0 -48
- package/skills/design-review/SKILL.md +0 -113
- package/skills/executing-tasks/SKILL.md +0 -350
- package/skills/finalizing/SKILL.md +0 -119
- package/skills/verify/SKILL.md +0 -170
- package/skills/writing-plans/SKILL.md +0 -343
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# Checkpoint Review Gates: Implementation Plan
|
|
2
|
-
|
|
3
|
-
## Tasks
|
|
4
|
-
|
|
5
|
-
### Task 1: Update writing-plans/SKILL.md — add checkpoint field and agent guidance
|
|
6
|
-
|
|
7
|
-
**Scenario:** Trivial (docs)
|
|
8
|
-
|
|
9
|
-
**File:** `skills/writing-plans/SKILL.md`
|
|
10
|
-
|
|
11
|
-
Add a "Checkpoint labels" section after "TDD in the plan" with the optional `checkpoint` field, values, and agent guidance. Also update the TDD table to show how checkpoints interact with each scenario.
|
|
12
|
-
|
|
13
|
-
After the "TDD in the plan" section, add:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
## Checkpoint labels
|
|
17
|
-
|
|
18
|
-
Optionally label each task with a `checkpoint` to require human review before proceeding:
|
|
19
|
-
|
|
20
|
-
| Checkpoint | When to use | What happens during execution |
|
|
21
|
-
|---|---|---|
|
|
22
|
-
| *(none)* | Trivial tasks, well-understood changes | Auto-advance, no pause |
|
|
23
|
-
| **`checkpoint: test`** | Test design matters (API contracts, edge cases, complex behavior) | Pause after writing the failing test, before implementing |
|
|
24
|
-
| **`checkpoint: done`** | Implementation review matters (complex logic, security, performance) | Pause after implementation + tests pass, before committing |
|
|
25
|
-
|
|
26
|
-
Use judgment when assigning checkpoints. Prefer `checkpoint: test` for new features with non-obvious test design. Prefer `checkpoint: done` for tasks where the implementation approach is debatable. Most tasks should not need a checkpoint. The user can adjust checkpoints when reviewing the plan.
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Also update the "Task format" section — after the `git commit` bullet, add:
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
- Optional `checkpoint: test` or `checkpoint: done` label
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
**Commit:** `feat(writing-plans): add checkpoint labels for review gates`
|
|
36
|
-
|
|
37
|
-
### Task 2: Update executing-tasks/SKILL.md — handle checkpoints in per-task lifecycle
|
|
38
|
-
|
|
39
|
-
**Scenario:** Trivial (docs)
|
|
40
|
-
|
|
41
|
-
**File:** `skills/executing-tasks/SKILL.md`
|
|
42
|
-
|
|
43
|
-
Replace the "Per-task lifecycle" section with checkpoint-aware flows. Add a "Checkpoint review" section.
|
|
44
|
-
|
|
45
|
-
Replace the existing "Per-task lifecycle" section with:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
## Per-task lifecycle
|
|
49
|
-
|
|
50
|
-
Check each task for a `checkpoint` label and follow the appropriate flow:
|
|
51
|
-
|
|
52
|
-
### No checkpoint (auto-advance)
|
|
53
|
-
|
|
54
|
-
1. **Implement** — write the code as described in the plan
|
|
55
|
-
2. **Run tests** — verify the changes work
|
|
56
|
-
3. **Fix if needed** — if tests fail, debug and fix before moving on
|
|
57
|
-
4. **Commit** — `git add` the relevant files and commit with a clear message
|
|
58
|
-
|
|
59
|
-
### checkpoint: test
|
|
60
|
-
|
|
61
|
-
1. **Write the test** — follow the TDD scenario for the task
|
|
62
|
-
2. **Pause for review** — show what was done and the diff, then wait for human input
|
|
63
|
-
3. **Continue** — implement, run tests, fix if needed
|
|
64
|
-
4. **Commit** — `git add` the relevant files and commit with a clear message
|
|
65
|
-
|
|
66
|
-
### checkpoint: done
|
|
67
|
-
|
|
68
|
-
1. **Implement** — write the code as described in the plan
|
|
69
|
-
2. **Run tests** — verify the changes work
|
|
70
|
-
3. **Fix if needed** — if tests fail, debug and fix before moving on
|
|
71
|
-
4. **Pause for review** — show what was done and the diff, then wait for human input
|
|
72
|
-
5. **Commit** — `git add` the relevant files and commit with a clear message
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
After the "TDD discipline" section, add:
|
|
76
|
-
|
|
77
|
-
```
|
|
78
|
-
## Checkpoint review
|
|
79
|
-
|
|
80
|
-
When pausing at a checkpoint, present:
|
|
81
|
-
|
|
82
|
-
```
|
|
83
|
-
⏸ Paused at checkpoint: [test|done] for task [N]
|
|
84
|
-
|
|
85
|
-
**What was done:** [brief summary]
|
|
86
|
-
**Diff:** [show relevant diff]
|
|
87
|
-
|
|
88
|
-
Review and let me know how to proceed.
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Wait for the human to respond. They may:
|
|
92
|
-
- Approve and continue
|
|
93
|
-
- Request changes to the test or implementation
|
|
94
|
-
- Ask to revert the task
|
|
95
|
-
- Adjust the remaining plan
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
**Commit:** `feat(executing-tasks): add checkpoint review gates`
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Finalizing: Merge Strategy Options
|
|
2
|
-
|
|
3
|
-
## Problem
|
|
4
|
-
|
|
5
|
-
The finalizing skill hard-codes "Create PR" as the only shipping option. In practice, small features often don't need a PR — they can be merged directly back to the parent branch.
|
|
6
|
-
|
|
7
|
-
## Design
|
|
8
|
-
|
|
9
|
-
Add a merge strategy step after updating documentation. The human chooses one of four options:
|
|
10
|
-
|
|
11
|
-
1. **Create PR** — push and open a PR for external review via `gh pr create`
|
|
12
|
-
2. **Rebase & merge** (recommended) — rebase onto parent, fast-forward merge, push parent, delete feature branch. Preserves per-task commit history linearly.
|
|
13
|
-
3. **Squash & merge** — squash all commits into one on parent, push parent, delete feature branch. Clean single-commit history.
|
|
14
|
-
4. **Merge commit** — merge with `--no-ff`, push parent, delete feature branch. Preserves all commits and branch topology.
|
|
15
|
-
|
|
16
|
-
### Flow for options 2–4 (local merge)
|
|
17
|
-
|
|
18
|
-
1. Detect parent branch (compare `main` vs `master`, fall back to `git show-branch`)
|
|
19
|
-
2. Switch to parent branch and pull latest
|
|
20
|
-
3. Execute the chosen merge strategy:
|
|
21
|
-
- Rebase: `git rebase <parent>` on feature branch, then `git merge --ff-only <feature>` on parent
|
|
22
|
-
- Squash: `git merge --squash <feature>` on parent, then `git commit`
|
|
23
|
-
- Merge commit: `git merge --no-ff <feature>` on parent
|
|
24
|
-
4. Push parent to origin
|
|
25
|
-
5. Delete feature branch locally and remotely
|
|
26
|
-
|
|
27
|
-
### Prompting
|
|
28
|
-
|
|
29
|
-
The skill should ask the human which option they prefer, presenting rebase & merge as the default recommendation.
|
|
30
|
-
|
|
31
|
-
## Changes
|
|
32
|
-
|
|
33
|
-
- Update `skills/finalizing/SKILL.md` to replace the hard-coded PR step with the 4-option choice.
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Finalizing: Merge Strategy Options — Implementation Plan
|
|
2
|
-
|
|
3
|
-
## Context
|
|
4
|
-
|
|
5
|
-
Replace the hard-coded "Create PR" step in the finalizing skill with a 4-option merge strategy prompt (Create PR, Rebase & merge, Squash & merge, Merge commit).
|
|
6
|
-
|
|
7
|
-
Design doc: `docs/plans/2026-04-11-finalizing-merge-options-design.md`
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Task 1 — Replace the PR step with a merge strategy prompt
|
|
12
|
-
|
|
13
|
-
**TDD scenario:** Trivial (skill docs, no code to test)
|
|
14
|
-
|
|
15
|
-
**File:** `skills/finalizing/SKILL.md`
|
|
16
|
-
|
|
17
|
-
Replace step 3 ("Create PR") and step 4 ("Clean up") with the new merge strategy section. Keep steps 1 and 2 unchanged.
|
|
18
|
-
|
|
19
|
-
**New content for step 3 onwards:**
|
|
20
|
-
|
|
21
|
-
```markdown
|
|
22
|
-
3. **Choose a merge strategy** — ask the human which option they prefer:
|
|
23
|
-
|
|
24
|
-
1. **Create PR** — push and open a PR for external review:
|
|
25
|
-
```
|
|
26
|
-
git push origin <branch>
|
|
27
|
-
gh pr create --title "feat: <summary>" --body "<task summary>"
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
2. **Rebase & merge** *(recommended)* — rebase onto parent, fast-forward merge, push parent, delete branch:
|
|
31
|
-
```
|
|
32
|
-
parent=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v "$(git branch --show-current)" | head -1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
|
|
33
|
-
git checkout "$parent" && git pull
|
|
34
|
-
git checkout - && git rebase "$parent"
|
|
35
|
-
git checkout "$parent" && git merge --ff-only -
|
|
36
|
-
git push origin "$parent"
|
|
37
|
-
git branch -d - && git push origin --delete -
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
3. **Squash & merge** — squash all commits into one on parent, push parent, delete branch:
|
|
41
|
-
```
|
|
42
|
-
parent=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v "$(git branch --show-current)" | head -1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
|
|
43
|
-
git checkout "$parent" && git pull
|
|
44
|
-
git merge --squash -
|
|
45
|
-
git commit -m "feat: <summary>"
|
|
46
|
-
git push origin "$parent"
|
|
47
|
-
git branch -d - && git push origin --delete -
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
4. **Merge commit** — merge with `--no-ff`, push parent, delete branch:
|
|
51
|
-
```
|
|
52
|
-
parent=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v "$(git branch --show-current)" | head -1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
|
|
53
|
-
git checkout "$parent" && git pull
|
|
54
|
-
git merge --no-ff -m "Merge branch '<branch>'" -
|
|
55
|
-
git push origin "$parent"
|
|
56
|
-
git branch -d - && git push origin --delete -
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
For options 2–4, confirm the detected parent branch with the human before proceeding.
|
|
60
|
-
|
|
61
|
-
4. **Clean up** — if a worktree was used, remove it:
|
|
62
|
-
```
|
|
63
|
-
git worktree remove ../<repo>-<feature-name>
|
|
64
|
-
```
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
**Commit:** `feat: add merge strategy options to finalizing skill`
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
## Done
|
|
72
|
-
|
|
73
|
-
The finalizing skill now offers four merge strategies instead of only "Create PR". No code files changed — this is a skill-documentation update only.
|
|
74
|
-
|
|
75
|
-
To verify: read `skills/finalizing/SKILL.md` and confirm it contains all four options with correct commands.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Workspace Setup: Move Branch Creation to Brainstorming
|
|
2
|
-
|
|
3
|
-
## Problem
|
|
4
|
-
|
|
5
|
-
Brainstorming commits the design doc to whatever branch you're on (usually `main`), polluting it. If the idea is scrapped, you have to revert the commit. The implementation branch created later by writing-plans starts from a point after the design commit, which is messy.
|
|
6
|
-
|
|
7
|
-
## Design
|
|
8
|
-
|
|
9
|
-
Move branch/worktree creation from writing-plans into brainstorming. The design doc lands on the feature branch from the start, keeping `main` clean.
|
|
10
|
-
|
|
11
|
-
## Changes
|
|
12
|
-
|
|
13
|
-
### brainstorming/SKILL.md
|
|
14
|
-
|
|
15
|
-
Step 5 changes from writing + committing the design doc on the current branch to:
|
|
16
|
-
|
|
17
|
-
1. Create a feature branch (`git checkout -b <feature-name>`) or worktree (`git worktree add ../<repo>-<feature-name> -b <feature-name>`) for larger features
|
|
18
|
-
2. Write the design doc to `docs/plans/YYYY-MM-DD-<topic>-design.md`
|
|
19
|
-
3. Single commit on the new branch with the design doc
|
|
20
|
-
|
|
21
|
-
Feature name is derived from the topic slug in the design doc filename.
|
|
22
|
-
|
|
23
|
-
### writing-plans/SKILL.md
|
|
24
|
-
|
|
25
|
-
- Remove step 2 ("Set up workspace") entirely
|
|
26
|
-
- Step 1 expands to verify the feature branch/worktree context created by brainstorming
|
|
27
|
-
- Steps renumber: 1→2→3 becomes 1→2
|
|
28
|
-
- Fallback path (no design doc, brainstorming was skipped) still creates a branch itself so writing-plans works standalone
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# Workspace Setup: Implementation Plan
|
|
2
|
-
|
|
3
|
-
## Tasks
|
|
4
|
-
|
|
5
|
-
### Task 1: Update brainstorming/SKILL.md — add workspace setup to step 5
|
|
6
|
-
|
|
7
|
-
**Scenario:** Trivial (docs)
|
|
8
|
-
|
|
9
|
-
Replace step 5 with workspace creation + design doc commit.
|
|
10
|
-
|
|
11
|
-
**File:** `skills/brainstorming/SKILL.md`
|
|
12
|
-
|
|
13
|
-
Replace:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
5. **Write the design doc** — save to `docs/plans/YYYY-MM-DD-<topic>-design.md` and commit.
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
With:
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
5. **Set up workspace & write the design doc** — create a branch for this work. For larger features, use a git worktree for isolation:
|
|
23
|
-
```
|
|
24
|
-
git worktree add ../<repo>-<feature-name> -b <feature-name>
|
|
25
|
-
```
|
|
26
|
-
Save the design doc to `docs/plans/YYYY-MM-DD-<topic>-design.md` and commit on the new branch.
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
**Commit:** `refactor(brainstorming): move workspace setup into step 5`
|
|
30
|
-
|
|
31
|
-
### Task 2: Update writing-plans/SKILL.md — remove step 2, expand step 1
|
|
32
|
-
|
|
33
|
-
**Scenario:** Trivial (docs)
|
|
34
|
-
|
|
35
|
-
Remove step 2 ("Set up workspace") entirely. Expand step 1 to verify the feature branch context. Renumber step 3 → 2.
|
|
36
|
-
|
|
37
|
-
**File:** `skills/writing-plans/SKILL.md`
|
|
38
|
-
|
|
39
|
-
Replace:
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
1. **Check for a design doc** — look for `docs/plans/*-design.md`. If one exists, use it as the basis for the plan. If none exists, ask the user to describe what they want to build, read relevant code, and create the plan directly.
|
|
43
|
-
2. **Set up workspace** — create a branch for this work. For larger features, use a git worktree for isolation:
|
|
44
|
-
```
|
|
45
|
-
git worktree add ../<repo>-<feature-name> -b <feature-name>
|
|
46
|
-
```
|
|
47
|
-
3. **Write the implementation plan** — break the design into tasks. Save to `docs/plans/YYYY-MM-DD-<topic>-implementation.md`.
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
With:
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
1. **Check for a design doc & workspace** — look for `docs/plans/*-design.md`. If one exists, use it as the basis for the plan. Verify you're on the feature branch (or in its worktree) created during brainstorming. If no design doc exists, ask the user to describe what they want to build, read relevant code, create a branch, and create the plan directly.
|
|
54
|
-
2. **Write the implementation plan** — break the design into tasks. Save to `docs/plans/YYYY-MM-DD-<topic>-implementation.md`.
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**Commit:** `refactor(writing-plans): remove workspace setup, verify branch context`
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# Bash Guard for Workflow Guard Extension
|
|
2
|
-
|
|
3
|
-
## Problem
|
|
4
|
-
|
|
5
|
-
`workflow-guard.ts` blocks `write`/`edit` outside `docs/plans/` during brainstorm and plan phases, but ignores `bash` entirely. The LLM can mutate files via bash (e.g. `echo "..." > file.ts`, `sed -i`, `tee`, heredocs).
|
|
6
|
-
|
|
7
|
-
## Design
|
|
8
|
-
|
|
9
|
-
Adopt the `isSafeCommand()` approach from [pi-mono plan-mode example](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/examples/extensions/plan-mode/utils.ts).
|
|
10
|
-
|
|
11
|
-
### Approach
|
|
12
|
-
|
|
13
|
-
**No changes to `pi.setActiveTools()`** — `write`/`edit` remain active so the existing path-based `tool_call` guard continues to allow writes to `docs/plans/`.
|
|
14
|
-
|
|
15
|
-
**Add a bash guard** in the existing `tool_call` handler using `isSafeCommand()`:
|
|
16
|
-
- Copy SAFE_PATTERNS and DESTRUCTIVE_PATTERNS from the example's `utils.ts` as-is
|
|
17
|
-
- Copy `isSafeCommand()` logic as-is
|
|
18
|
-
- In the `tool_call` handler, when phase is set and tool is `bash`, check `isSafeCommand(event.input.command)`
|
|
19
|
-
- Block with reason if not safe
|
|
20
|
-
- Notify via `ctx.ui.notify()` when blocking
|
|
21
|
-
|
|
22
|
-
### Changes
|
|
23
|
-
|
|
24
|
-
1. **`extensions/workflow-guard.ts`**
|
|
25
|
-
- Add `isSafeCommand()` function (copied from example, with DESTRUCTIVE_PATTERNS and SAFE_PATTERNS)
|
|
26
|
-
- Extend `tool_call` handler to also intercept `bash` when phase is set
|
|
27
|
-
- Check `event.input.command` against `isSafeCommand()`
|
|
28
|
-
- Block and notify if unsafe
|
|
29
|
-
|
|
30
|
-
2. **`tests/workflow-guard.test.ts`**
|
|
31
|
-
- Add tests for bash guard: safe commands pass, destructive commands blocked, redirects blocked
|
|
32
|
-
- Import and test `isSafeCommand` directly (it's a pure function, easy to unit test)
|
|
33
|
-
|
|
34
|
-
### What stays the same
|
|
35
|
-
|
|
36
|
-
- Phase detection via `/skill:` commands (no change)
|
|
37
|
-
- `write`/`edit` path-based blocking for `docs/plans/` (no change)
|
|
38
|
-
- `docs/plans/` write exception (no change)
|
|
39
|
-
- No `pi.setActiveTools()` usage
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
# Bash Guard Implementation Plan
|
|
2
|
-
|
|
3
|
-
Based on `docs/plans/2026-04-15-bash-guard-design.md`.
|
|
4
|
-
|
|
5
|
-
## Task 1 — Add `isSafeCommand()` to workflow-guard.ts [new feature, checkpoint: test]
|
|
6
|
-
|
|
7
|
-
**File:** `extensions/workflow-guard.ts`
|
|
8
|
-
|
|
9
|
-
- Add `isSafeCommand` as a named export (so tests can import it directly)
|
|
10
|
-
- Copy `DESTRUCTIVE_PATTERNS` and `SAFE_PATTERNS` from [plan-mode utils.ts](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/examples/extensions/plan-mode/utils.ts) as-is
|
|
11
|
-
- Copy the `isSafeCommand()` logic as-is
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
// Destructive commands blocked in brainstorm/plan phases
|
|
15
|
-
const DESTRUCTIVE_PATTERNS = [
|
|
16
|
-
/\brm\b/i,
|
|
17
|
-
/\brmdir\b/i,
|
|
18
|
-
/\bmv\b/i,
|
|
19
|
-
/\bcp\b/i,
|
|
20
|
-
/\bmkdir\b/i,
|
|
21
|
-
/\btouch\b/i,
|
|
22
|
-
/\bchmod\b/i,
|
|
23
|
-
/\bchown\b/i,
|
|
24
|
-
/\bchgrp\b/i,
|
|
25
|
-
/\bln\b/i,
|
|
26
|
-
/\btee\b/i,
|
|
27
|
-
/\btruncate\b/i,
|
|
28
|
-
/\bdd\b/i,
|
|
29
|
-
/\bshred\b/i,
|
|
30
|
-
/(^|[^<])>(?!>)/,
|
|
31
|
-
/>>/,
|
|
32
|
-
/\bnpm\s+(install|uninstall|update|ci|link|publish)/i,
|
|
33
|
-
/\byarn\s+(add|remove|install|publish)/i,
|
|
34
|
-
/\bpnpm\s+(add|remove|install|publish)/i,
|
|
35
|
-
/\bpip\s+(install|uninstall)/i,
|
|
36
|
-
/\bapt(-get)?\s+(install|remove|purge|update|upgrade)/i,
|
|
37
|
-
/\bbrew\s+(install|uninstall|upgrade)/i,
|
|
38
|
-
/\bgit\s+(add|commit|push|pull|merge|rebase|reset|checkout|branch\s+-[dD]|stash|cherry-pick|revert|tag|init|clone)/i,
|
|
39
|
-
/\bsudo\b/i,
|
|
40
|
-
/\bsu\b/i,
|
|
41
|
-
/\bkill\b/i,
|
|
42
|
-
/\bpkill\b/i,
|
|
43
|
-
/\bkillall\b/i,
|
|
44
|
-
/\breboot\b/i,
|
|
45
|
-
/\bshutdown\b/i,
|
|
46
|
-
/\bsystemctl\s+(start|stop|restart|enable|disable)/i,
|
|
47
|
-
/\bservice\s+\S+\s+(start|stop|restart)/i,
|
|
48
|
-
/\b(vim?|nano|emacs|code|subl)\b/i,
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const SAFE_PATTERNS = [
|
|
52
|
-
/^\s*cat\b/,
|
|
53
|
-
/^\s*head\b/,
|
|
54
|
-
/^\s*tail\b/,
|
|
55
|
-
/^\s*less\b/,
|
|
56
|
-
/^\s*more\b/,
|
|
57
|
-
/^\s*grep\b/,
|
|
58
|
-
/^\s*find\b/,
|
|
59
|
-
/^\s*ls\b/,
|
|
60
|
-
/^\s*pwd\b/,
|
|
61
|
-
/^\s*echo\b/,
|
|
62
|
-
/^\s*printf\b/,
|
|
63
|
-
/^\s*wc\b/,
|
|
64
|
-
/^\s*sort\b/,
|
|
65
|
-
/^\s*uniq\b/,
|
|
66
|
-
/^\s*diff\b/,
|
|
67
|
-
/^\s*file\b/,
|
|
68
|
-
/^\s*stat\b/,
|
|
69
|
-
/^\s*du\b/,
|
|
70
|
-
/^\s*df\b/,
|
|
71
|
-
/^\s*tree\b/,
|
|
72
|
-
/^\s*which\b/,
|
|
73
|
-
/^\s*whereis\b/,
|
|
74
|
-
/^\s*type\b/,
|
|
75
|
-
/^\s*env\b/,
|
|
76
|
-
/^\s*printenv\b/,
|
|
77
|
-
/^\s*uname\b/,
|
|
78
|
-
/^\s*whoami\b/,
|
|
79
|
-
/^\s*id\b/,
|
|
80
|
-
/^\s*date\b/,
|
|
81
|
-
/^\s*cal\b/,
|
|
82
|
-
/^\s*uptime\b/,
|
|
83
|
-
/^\s*ps\b/,
|
|
84
|
-
/^\s*top\b/,
|
|
85
|
-
/^\s*htop\b/,
|
|
86
|
-
/^\s*free\b/,
|
|
87
|
-
/^\s*git\s+(status|log|diff|show|branch|remote|config\s+--get)/i,
|
|
88
|
-
/^\s*git\s+ls-/i,
|
|
89
|
-
/^\s*npm\s+(list|ls|view|info|search|outdated|audit)/i,
|
|
90
|
-
/^\s*yarn\s+(list|info|why|audit)/i,
|
|
91
|
-
/^\s*node\s+--version/i,
|
|
92
|
-
/^\s*python\s+--version/i,
|
|
93
|
-
/^\s*curl\s/i,
|
|
94
|
-
/^\s*wget\s+-O\s*-/i,
|
|
95
|
-
/^\s*jq\b/,
|
|
96
|
-
/^\s*sed\s+-n/i,
|
|
97
|
-
/^\s*awk\b/,
|
|
98
|
-
/^\s*rg\b/,
|
|
99
|
-
/^\s*fd\b/,
|
|
100
|
-
/^\s*bat\b/,
|
|
101
|
-
/^\s*eza\b/,
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
export function isSafeCommand(command: string): boolean {
|
|
105
|
-
const isDestructive = DESTRUCTIVE_PATTERNS.some((p) => p.test(command));
|
|
106
|
-
const isSafe = SAFE_PATTERNS.some((p) => p.test(command));
|
|
107
|
-
return !isDestructive && isSafe;
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
- Write failing tests in `tests/workflow-guard.test.ts` for `isSafeCommand`:
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
import { isSafeCommand } from "../extensions/workflow-guard";
|
|
115
|
-
|
|
116
|
-
describe("isSafeCommand", () => {
|
|
117
|
-
it("allows safe read-only commands", () => {
|
|
118
|
-
expect(isSafeCommand("cat file.ts")).toBe(true);
|
|
119
|
-
expect(isSafeCommand("grep -r 'foo' src/")).toBe(true);
|
|
120
|
-
expect(isSafeCommand("git status")).toBe(true);
|
|
121
|
-
expect(isSafeCommand("git log --oneline -5")).toBe(true);
|
|
122
|
-
expect(isSafeCommand("npm list")).toBe(true);
|
|
123
|
-
expect(isSafeCommand("ls -la")).toBe(true);
|
|
124
|
-
expect(isSafeCommand("curl https://example.com")).toBe(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("blocks destructive commands", () => {
|
|
128
|
-
expect(isSafeCommand("rm -rf node_modules")).toBe(false);
|
|
129
|
-
expect(isSafeCommand("touch newfile.ts")).toBe(false);
|
|
130
|
-
expect(isSafeCommand("mv old.ts new.ts")).toBe(false);
|
|
131
|
-
expect(isSafeCommand("mkdir src/components")).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("blocks file-writing bash patterns", () => {
|
|
135
|
-
expect(isSafeCommand("echo 'hello' > file.ts")).toBe(false);
|
|
136
|
-
expect(isSafeCommand("cat config > backup.txt")).toBe(false);
|
|
137
|
-
expect(isSafeCommand("echo 'log' >> output.log")).toBe(false);
|
|
138
|
-
expect(isSafeCommand("tee output.txt")).toBe(false);
|
|
139
|
-
expect(isSafeCommand("sed -i 's/old/new/g' file.ts")).toBe(false);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("blocks git mutations but allows read-only git", () => {
|
|
143
|
-
expect(isSafeCommand("git add .")).toBe(false);
|
|
144
|
-
expect(isSafeCommand("git commit -m 'msg'")).toBe(false);
|
|
145
|
-
expect(isSafeCommand("git push")).toBe(false);
|
|
146
|
-
expect(isSafeCommand("git checkout -b feature")).toBe(false);
|
|
147
|
-
expect(isSafeCommand("git status")).toBe(true);
|
|
148
|
-
expect(isSafeCommand("git log --oneline")).toBe(true);
|
|
149
|
-
expect(isSafeCommand("git diff")).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("blocks editors", () => {
|
|
153
|
-
expect(isSafeCommand("vim file.ts")).toBe(false);
|
|
154
|
-
expect(isSafeCommand("nano file.ts")).toBe(false);
|
|
155
|
-
expect(isSafeCommand("code .")).toBe(false);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("blocks sudo", () => {
|
|
159
|
-
expect(isSafeCommand("sudo apt install foo")).toBe(false);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("blocks npm installs but allows read-only npm", () => {
|
|
163
|
-
expect(isSafeCommand("npm install lodash")).toBe(false);
|
|
164
|
-
expect(isSafeCommand("npm list")).toBe(true);
|
|
165
|
-
expect(isSafeCommand("npm audit")).toBe(true);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
- Run: `npx vitest run tests/workflow-guard.test.ts`
|
|
171
|
-
- Verify: all new `isSafeCommand` tests fail (function doesn't exist yet)
|
|
172
|
-
- Implement `isSafeCommand()` in `extensions/workflow-guard.ts`
|
|
173
|
-
- Run: `npx vitest run tests/workflow-guard.test.ts`
|
|
174
|
-
- Verify: all tests pass
|
|
175
|
-
- `git add -A && git commit -m "feat: add isSafeCommand bash guard to workflow-guard"`
|
|
176
|
-
|
|
177
|
-
## Task 2 — Wire bash guard into tool_call handler [modifying tested code]
|
|
178
|
-
|
|
179
|
-
**File:** `extensions/workflow-guard.ts`
|
|
180
|
-
|
|
181
|
-
Replace the tool_call guard from:
|
|
182
|
-
```ts
|
|
183
|
-
if (event.toolName !== "write" && event.toolName !== "edit") return;
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
To:
|
|
187
|
-
```ts
|
|
188
|
-
if (event.toolName === "bash") {
|
|
189
|
-
const command = (event.input as { command?: string }).command ?? "";
|
|
190
|
-
if (!isSafeCommand(command)) {
|
|
191
|
-
if (ctx.hasUI) {
|
|
192
|
-
ctx.ui.notify(
|
|
193
|
-
`Blocked bash command during ${phase} phase: ${command}`,
|
|
194
|
-
"warning",
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
block: true,
|
|
199
|
-
reason: `⚠️ ${phase.toUpperCase()} PHASE: Bash command blocked (not allowlisted). Only read-only commands are permitted during brainstorming and planning.\nCommand: ${command}`,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (event.toolName !== "write" && event.toolName !== "edit") return;
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
- Run: `npx vitest run tests/workflow-guard.test.ts`
|
|
209
|
-
- Verify: existing tests pass (the "should allow bash" test needs updating — see Task 3)
|
|
210
|
-
- `git add -A && git commit -m "feat: wire bash guard into tool_call handler"`
|
|
211
|
-
|
|
212
|
-
## Task 3 — Update existing test for new bash behavior [modifying tested code]
|
|
213
|
-
|
|
214
|
-
**File:** `tests/workflow-guard.test.ts`
|
|
215
|
-
|
|
216
|
-
The test `"should allow bash regardless of phase"` is now incorrect — bash with unsafe commands should be blocked. Update it:
|
|
217
|
-
|
|
218
|
-
```ts
|
|
219
|
-
it("should block unsafe bash during brainstorm (safe bash tested via isSafeCommand)", () => {
|
|
220
|
-
// The tool_call handler now guards bash via isSafeCommand.
|
|
221
|
-
// Direct testing of safe/unsafe commands is in the isSafeCommand describe block.
|
|
222
|
-
// This just confirms bash is no longer blanket-allowed.
|
|
223
|
-
expect(isSafeCommand("rm -rf /")).toBe(false);
|
|
224
|
-
});
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
- Run: `npx vitest run tests/workflow-guard.test.ts`
|
|
228
|
-
- Verify: all tests pass
|
|
229
|
-
- `git add -A && git commit -m "test: update bash guard test for new blocking behavior"`
|