@tianhai/pi-workflow-kit 0.18.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.
Files changed (71) hide show
  1. package/README.md +79 -62
  2. package/agents/pwk-hazard-reviewer.md +24 -0
  3. package/agents/pwk-smell-reviewer.md +17 -0
  4. package/agents/pwk-spec-reviewer.md +14 -0
  5. package/agents/pwk-tracing-reviewer.md +14 -0
  6. package/docs/developer-usage-guide.md +38 -44
  7. package/docs/lessons.md +2 -7
  8. package/docs/oversight-model.md +18 -14
  9. package/docs/workflow-phases.md +52 -29
  10. package/extensions/workflow-guard.ts +190 -92
  11. package/package.json +18 -3
  12. package/skills/pwk-brainstorming/SKILL.md +19 -18
  13. package/skills/pwk-code-review/SKILL.md +46 -0
  14. package/skills/pwk-diagnose/SKILL.md +2 -1
  15. package/skills/pwk-executing-tasks/SKILL.md +102 -328
  16. package/skills/pwk-finalizing/SKILL.md +36 -84
  17. package/skills/pwk-status/SKILL.md +28 -0
  18. package/skills/pwk-writing-plans/SKILL.md +50 -325
  19. package/docs/plans/2026-06-03-karpathy-guidelines-ab-comparison.md +0 -166
  20. package/docs/plans/completed/2026-04-11-checkpoint-review-gates-design.md +0 -50
  21. package/docs/plans/completed/2026-04-11-checkpoint-review-gates-implementation.md +0 -98
  22. package/docs/plans/completed/2026-04-11-finalizing-merge-options-design.md +0 -33
  23. package/docs/plans/completed/2026-04-11-finalizing-merge-options-implementation.md +0 -75
  24. package/docs/plans/completed/2026-04-11-workspace-setup-design.md +0 -28
  25. package/docs/plans/completed/2026-04-11-workspace-setup-implementation.md +0 -57
  26. package/docs/plans/completed/2026-04-15-bash-guard-design.md +0 -39
  27. package/docs/plans/completed/2026-04-15-bash-guard-implementation.md +0 -229
  28. package/docs/plans/completed/2026-04-21-workflow-guard-safe-commands-design.md +0 -172
  29. package/docs/plans/completed/2026-04-21-workflow-guard-safe-commands-implementation.md +0 -168
  30. package/docs/plans/completed/2026-04-22-go-readonly-safe-commands-implementation.md +0 -54
  31. package/docs/plans/completed/2026-04-28-executing-tasks-redesign-design.md +0 -171
  32. package/docs/plans/completed/2026-04-28-executing-tasks-redesign-implementation.md +0 -208
  33. package/docs/plans/completed/2026-04-28-executing-tasks-redesign-progress.md +0 -14
  34. package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-design.md +0 -154
  35. package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-implementation.md +0 -315
  36. package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-progress.md +0 -15
  37. package/docs/plans/completed/2026-05-08-checkpoint-gates-design.md +0 -235
  38. package/docs/plans/completed/2026-05-08-checkpoint-gates-implementation.md +0 -83
  39. package/docs/plans/completed/2026-05-08-checkpoint-gates-progress.md +0 -11
  40. package/docs/plans/completed/2026-05-08-lessons-learned-design.md +0 -76
  41. package/docs/plans/completed/2026-05-08-lessons-learned-implementation.md +0 -219
  42. package/docs/plans/completed/2026-05-08-lessons-learned-progress.md +0 -15
  43. package/docs/plans/completed/2026-05-08-migrate-earendil-works-design.md +0 -39
  44. package/docs/plans/completed/2026-05-08-migrate-earendil-works-implementation.md +0 -45
  45. package/docs/plans/completed/2026-05-08-migrate-earendil-works-progress.md +0 -10
  46. package/docs/plans/completed/2026-05-08-worktree-handoff-design.md +0 -118
  47. package/docs/plans/completed/2026-05-08-worktree-handoff-implementation.md +0 -140
  48. package/docs/plans/completed/2026-05-08-worktree-handoff-progress.md +0 -10
  49. package/docs/plans/completed/2026-05-20-generic-lessons-design.md +0 -70
  50. package/docs/plans/completed/2026-05-20-generic-lessons-implementation.md +0 -114
  51. package/docs/plans/completed/2026-05-20-generic-lessons-progress.md +0 -11
  52. package/docs/plans/completed/2026-05-22-agentic-agile-enhancements-design.md +0 -77
  53. package/docs/plans/completed/2026-05-22-agentic-agile-enhancements-implementation.md +0 -473
  54. package/docs/plans/completed/2026-05-25-design-review-split-implementation.md +0 -622
  55. package/docs/plans/completed/2026-05-25-design-review-split-progress.md +0 -16
  56. package/docs/plans/completed/2026-05-25-pr5-improvements-implementation.md +0 -273
  57. package/docs/plans/completed/2026-05-25-pr5-improvements-progress.md +0 -17
  58. package/docs/plans/completed/2026-06-03-add-verify-skill-design.md +0 -51
  59. package/docs/plans/completed/2026-06-03-add-verify-skill-implementation.md +0 -111
  60. package/docs/plans/completed/2026-06-03-add-verify-skill-progress.md +0 -11
  61. package/docs/plans/completed/2026-06-03-verify-skill-design.md +0 -176
  62. package/docs/plans/completed/2026-06-09-code-review-fixes-implementation.md +0 -74
  63. package/docs/plans/completed/2026-06-09-code-review-fixes-progress.md +0 -14
  64. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-design.md +0 -186
  65. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-implementation.md +0 -675
  66. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-progress.md +0 -18
  67. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-verification-report.md +0 -81
  68. package/docs/plans/completed/2026-06-09-verification-fixes-implementation.md +0 -69
  69. package/docs/plans/completed/2026-06-09-verification-fixes-progress.md +0 -14
  70. package/skills/pwk-design-review/SKILL.md +0 -115
  71. package/skills/pwk-verify/SKILL.md +0 -170
@@ -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"`
@@ -1,172 +0,0 @@
1
- # Workflow Guard: Safe Commands Expansion
2
-
3
- **Date:** 2026-04-21
4
- **Status:** Draft
5
-
6
- ## Problem
7
-
8
- The workflow guard blocks several read-only bash commands that are genuinely needed during brainstorm and plan phases. Two specific user reports:
9
-
10
- 1. `cd /path && git remote -v 2>/dev/null; echo "---"; ls` — blocked due to `cd` not being allowlisted and `2>/dev/null` caught by the stdout-redirect pattern.
11
- 2. `gh pr view 1564 --json ... 2>/dev/null || echo "gh failed"` — blocked because `gh` is not allowlisted at all.
12
-
13
- Additionally, `git status --short` is blocked because the safe regex only allows `git status` without flags.
14
-
15
- ## Design
16
-
17
- ### 1. Harmless redirect stripping
18
-
19
- Add a `stripHarmlessRedirects(cmd)` helper that removes `2>/dev/null` and `2>&1` before pattern matching. These are purely cosmetic (suppress stderr noise) and have no side effects.
20
-
21
- ```ts
22
- function stripHarmlessRedirects(cmd: string): string {
23
- return cmd.replace(/\s*2\s*>\s*(\/dev\/null|&1)\b/g, "");
24
- }
25
- ```
26
-
27
- Apply it inside `isSafeCommand` on each sub-command before checking DESTRUCTIVE and SAFE patterns. This fixes `2>/dev/null` without loosening the redirect catch (which still blocks real writes).
28
-
29
- ### 2. New SAFE_PATTERNS entries
30
-
31
- | Pattern | Rationale |
32
- |---------|-----------|
33
- | `/^\s*cd\b/` | Directory navigation — zero side effects |
34
- | `/^\s*gh\s+pr\s+(view\|list\|diff\|checks\|status)\b/i` | Read-only PR inspection |
35
- | `/^\s*gh\s+issue\s+(view\|list)\b/i` | Read-only issue inspection |
36
- | `/^\s*gh\s+repo\s+(view\|fork\|list)\b/i` | Read-only repo metadata |
37
- | `/^\s*gh\s+release\s+(view\|list\|download)\b/i` | Read-only release inspection |
38
- | `/^\s*gh\s+run\s+(view\|list)\b/i` | Read-only CI run inspection |
39
- | `/^\s*git\s+blame\b/` | Read-only file annotation |
40
- | `/^\s*git\s+shortlog\b/` | Read-only commit summary |
41
- | `/^\s*git\s+stash\s+list\b/i` | Read-only stash listing |
42
- | `/^\s*git\s+tag\s+(-l\|--list)\b/i` | Read-only tag listing |
43
- | `/^\s*git\s+describe\b/` | Read-only version info |
44
-
45
- ### 3. Fix: `git status` flag handling
46
-
47
- Current regex `/^\s*git\s+(status|log|...)/i` doesn't allow common flags like `--short`, `--oneline`, `--format=...`. Refine all git safe patterns to optionally accept trailing flags and args:
48
-
49
- ```ts
50
- /^\s*git\s+status\b/i,
51
- /^\s*git\s+log\b/i,
52
- /^\s*git\s+diff\b/i,
53
- /^\s*git\s+show\b/i,
54
- /^\s*git\s+blame\b/i,
55
- // etc.
56
- ```
57
-
58
- The existing patterns already anchor to `^\s*git\s+<subcommand>` — the issue was that `git status --short` didn't match because some patterns had more restrictive anchoring. Reviewing the code: the patterns use `\b` word boundaries which should allow flags. The actual issue with `git status --short && git log --oneline -5` is that the `git log --oneline -5` part is safe, but `git status --short` — let me verify: `/^\s*git\s+(status|log|diff|show|branch|remote|config\s+--get)/i` — `git status` has a `\b` after the group? No, there's no trailing `\b`. So `git status --short` **should** match since the pattern doesn't require end-of-string. The real blocker for that compound command was the `&&` splitting — `git log --oneline -5` — `-5` shouldn't be an issue either.
59
-
60
- **Conclusion on item 3:** The `git status --short` case was a false alarm caused by compound command parsing combined with the `2>/dev/null` redirect in the user's actual commands, not a pattern bug. No change needed here beyond the redirect fix.
61
-
62
- ### 4. What we're NOT adding (YAGNI)
63
-
64
- - `sed -i` (in-place editing) — correctly destructive
65
- - `gh pr create/merge/close` — write operations
66
- - `curl -o file` (output to file) — the redirect catch blocks this
67
- - `cut`, `tr`, `column`, `base64` — rarely needed; can add later on demand
68
- - `gh api` — too broad; can be used for mutations. Require specific subcommands.
69
-
70
- ## Data flow
71
-
72
- No new data flow. The changes are purely additive to the pattern-matching logic in `isSafeCommand`.
73
-
74
- ## Error handling
75
-
76
- No new error paths. The existing block-and-warn behavior remains unchanged.
77
-
78
- ## Testing
79
-
80
- Manual verification with the exact commands that were blocked:
81
-
82
- 1. `cd /some/path && git remote -v 2>/dev/null; echo "---"; ls` → allowed
83
- 2. `gh pr view 1564 --repo owner/repo --json title,body,files 2>/dev/null || echo "gh failed"` → allowed
84
- 3. `git stash list` → allowed
85
- 4. `git tag -l` → allowed
86
- 5. `rm -rf /` → still blocked ✓
87
- 6. `git push origin main` → still blocked ✓
88
-
89
- ## Tests
90
-
91
- Add the following test cases to the existing `tests/workflow-guard.test.ts` `isSafeCommand` describe block:
92
-
93
- ### New: `cd` navigation
94
- ```ts
95
- it("allows cd", () => {
96
- expect(isSafeCommand("cd /some/path")).toBe(true);
97
- expect(isSafeCommand("cd src && ls")).toBe(true);
98
- });
99
- ```
100
-
101
- ### New: GitHub CLI read-only subcommands
102
- ```ts
103
- it("allows gh read-only subcommands", () => {
104
- expect(isSafeCommand("gh pr view 1564 --json title,body")).toBe(true);
105
- expect(isSafeCommand("gh pr list --repo owner/repo")).toBe(true);
106
- expect(isSafeCommand("gh pr diff 1564")).toBe(true);
107
- expect(isSafeCommand("gh issue view 42")).toBe(true);
108
- expect(isSafeCommand("gh issue list --label bug")).toBe(true);
109
- expect(isSafeCommand("gh repo view owner/repo")).toBe(true);
110
- expect(isSafeCommand("gh run view 12345")).toBe(true);
111
- });
112
-
113
- it("blocks gh write subcommands", () => {
114
- expect(isSafeCommand("gh pr create --title 'fix'")).toBe(false);
115
- expect(isSafeCommand("gh pr merge 1564")).toBe(false);
116
- expect(isSafeCommand("gh issue close 42")).toBe(false);
117
- expect(isSafeCommand("gh release create v1.0")).toBe(false);
118
- });
119
- ```
120
-
121
- ### New: Git read-only subcommands
122
- ```ts
123
- it("allows git read-only subcommands (new additions)", () => {
124
- expect(isSafeCommand("git blame src/index.ts")).toBe(true);
125
- expect(isSafeCommand("git shortlog -sn")).toBe(true);
126
- expect(isSafeCommand("git stash list")).toBe(true);
127
- expect(isSafeCommand("git tag -l")).toBe(true);
128
- expect(isSafeCommand("git tag --list 'v*'")).toBe(true);
129
- expect(isSafeCommand("git describe --tags")).toBe(true);
130
- });
131
-
132
- it("still blocks git stash mutations", () => {
133
- expect(isSafeCommand("git stash push -m 'wip'")).toBe(false);
134
- expect(isSafeCommand("git stash pop")).toBe(false);
135
- });
136
- ```
137
-
138
- ### New: Harmless stderr redirect stripping
139
- ```ts
140
- it("allows 2>/dev/null on safe commands", () => {
141
- expect(isSafeCommand("git remote -v 2>/dev/null")).toBe(true);
142
- expect(isSafeCommand("gh pr view 1564 2>/dev/null")).toBe(true);
143
- expect(isSafeCommand("npm list 2>/dev/null")).toBe(true);
144
- });
145
-
146
- it("allows 2>&1 on safe commands", () => {
147
- expect(isSafeCommand("git log 2>&1")).toBe(true);
148
- });
149
-
150
- it("still blocks stdout redirects even with stderr redirect present", () => {
151
- expect(isSafeCommand("echo 'hello' > file.ts 2>/dev/null")).toBe(false);
152
- expect(isSafeCommand("cat config > backup.txt 2>/dev/null")).toBe(false);
153
- });
154
- ```
155
-
156
- ### New: Compound commands from real user scenarios
157
- ```ts
158
- it("allows the exact user-reported blocked commands", () => {
159
- // Scenario 1: directory navigation + git remote + ls
160
- expect(isSafeCommand("cd /Users/u/partying/pt-room && git remote -v 2>/dev/null; echo '---'; ls")).toBe(true);
161
- // Scenario 2: gh pr view with fallback
162
- expect(isSafeCommand("gh pr view 1564 --repo olachat/pt-partying --json title,body,files,additions,deletions 2>/dev/null || echo 'gh failed'")).toBe(true);
163
- });
164
- ```
165
-
166
- ## Summary
167
-
168
- | Change | Location | Size |
169
- |--------|----------|------|
170
- | Add `stripHarmlessRedirects()` | Above `isSafeCommand` | ~3 lines |
171
- | Call it in `isSafeCommand` loop body | Inside `isSafeCommand` | 1 line changed |
172
- | Add 10 new SAFE_PATTERNS entries | `SAFE_PATTERNS` array | ~10 lines |
@@ -1,168 +0,0 @@
1
- # Workflow Guard: Safe Commands Expansion — Implementation Plan
2
-
3
- **Design:** `docs/plans/2026-04-21-workflow-guard-safe-commands-design.md`
4
- **Date:** 2026-04-21
5
-
6
- ---
7
-
8
- ## Task 1: Add `stripHarmlessRedirects` helper and wire it into `isSafeCommand`
9
-
10
- **Scenario:** Modifying tested code
11
- **File:** `extensions/workflow-guard.ts`
12
-
13
- 1. Run existing tests to confirm baseline:
14
- ```bash
15
- npx vitest run tests/workflow-guard.test.ts
16
- ```
17
- Expected: all pass.
18
-
19
- 2. Add `stripHarmlessRedirects` function above `isSafeCommand`:
20
- ```ts
21
- /** Strip stderr redirects that are purely cosmetic (no side effects). */
22
- function stripHarmlessRedirects(cmd: string): string {
23
- return cmd.replace(/\s*2\s*>\s*(\/dev\/null|&1)\b/g, "");
24
- }
25
- ```
26
-
27
- 3. Wire it into `isSafeCommand` — apply `stripHarmlessRedirects` to each part before pattern matching:
28
- ```ts
29
- export function isSafeCommand(command: string): boolean {
30
- const parts = splitCompoundCommand(command);
31
- return parts.every((part) => {
32
- const cleaned = stripHarmlessRedirects(part);
33
- const isDestructive = DESTRUCTIVE_PATTERNS.some((p) => p.test(cleaned));
34
- const isSafe = SAFE_PATTERNS.some((p) => p.test(cleaned));
35
- return !isDestructive && isSafe;
36
- });
37
- }
38
- ```
39
-
40
- 4. Run tests:
41
- ```bash
42
- npx vitest run tests/workflow-guard.test.ts
43
- ```
44
- Expected: all existing tests still pass (no behavior change yet since no new SAFE_PATTERNS).
45
-
46
- 5. Commit:
47
- ```bash
48
- git add extensions/workflow-guard.ts
49
- git commit -m "feat(workflow-guard): add stripHarmlessRedirects helper"
50
- ```
51
-
52
- ---
53
-
54
- ## Task 2: Add new SAFE_PATTERNS entries
55
-
56
- **Scenario:** Modifying tested code
57
- **File:** `extensions/workflow-guard.ts`
58
-
59
- 1. Add the following entries to the `SAFE_PATTERNS` array (after the existing `gh`-related area or at end):
60
-
61
- ```ts
62
- /^\s*cd\b/,
63
- /^\s*gh\s+pr\s+(view|list|diff|checks|status)\b/i,
64
- /^\s*gh\s+issue\s+(view|list)\b/i,
65
- /^\s*gh\s+repo\s+(view|fork|list)\b/i,
66
- /^\s*gh\s+release\s+(view|list|download)\b/i,
67
- /^\s*gh\s+run\s+(view|list)\b/i,
68
- /^\s*git\s+blame\b/,
69
- /^\s*git\s+shortlog\b/,
70
- /^\s*git\s+stash\s+list\b/i,
71
- /^\s*git\s+tag\s+(-l|--list)\b/i,
72
- /^\s*git\s+describe\b/,
73
- ```
74
-
75
- 2. Run tests:
76
- ```bash
77
- npx vitest run tests/workflow-guard.test.ts
78
- ```
79
- Expected: all existing tests pass.
80
-
81
- 3. Commit:
82
- ```bash
83
- git add extensions/workflow-guard.ts
84
- git commit -m "feat(workflow-guard): add safe patterns for cd, gh, and git read-only subcommands"
85
- ```
86
-
87
- ---
88
-
89
- ## Task 3: Add tests for `cd`, `gh`, git new subcommands, and redirect stripping
90
-
91
- **Scenario:** New feature (test-first)
92
- **File:** `tests/workflow-guard.test.ts`
93
-
94
- **checkpoint: test** — pause after writing failing tests, before implementation.
95
-
96
- > Note: Implementation was already done in Tasks 1–2. These tests should all pass immediately. The checkpoint label is kept for review purposes in case the user wants to verify test design.
97
-
98
- 1. Add the following test blocks inside the `describe("isSafeCommand", ...)` block, after the existing tests:
99
-
100
- ```ts
101
- it("allows cd", () => {
102
- expect(isSafeCommand("cd /some/path")).toBe(true);
103
- expect(isSafeCommand("cd src && ls")).toBe(true);
104
- });
105
-
106
- it("allows gh read-only subcommands", () => {
107
- expect(isSafeCommand("gh pr view 1564 --json title,body")).toBe(true);
108
- expect(isSafeCommand("gh pr list --repo owner/repo")).toBe(true);
109
- expect(isSafeCommand("gh pr diff 1564")).toBe(true);
110
- expect(isSafeCommand("gh issue view 42")).toBe(true);
111
- expect(isSafeCommand("gh issue list --label bug")).toBe(true);
112
- expect(isSafeCommand("gh repo view owner/repo")).toBe(true);
113
- expect(isSafeCommand("gh run view 12345")).toBe(true);
114
- });
115
-
116
- it("blocks gh write subcommands", () => {
117
- expect(isSafeCommand("gh pr create --title 'fix'")).toBe(false);
118
- expect(isSafeCommand("gh pr merge 1564")).toBe(false);
119
- expect(isSafeCommand("gh issue close 42")).toBe(false);
120
- expect(isSafeCommand("gh release create v1.0")).toBe(false);
121
- });
122
-
123
- it("allows git read-only subcommands (new additions)", () => {
124
- expect(isSafeCommand("git blame src/index.ts")).toBe(true);
125
- expect(isSafeCommand("git shortlog -sn")).toBe(true);
126
- expect(isSafeCommand("git stash list")).toBe(true);
127
- expect(isSafeCommand("git tag -l")).toBe(true);
128
- expect(isSafeCommand("git tag --list 'v*'")).toBe(true);
129
- expect(isSafeCommand("git describe --tags")).toBe(true);
130
- });
131
-
132
- it("still blocks git stash mutations", () => {
133
- expect(isSafeCommand("git stash push -m 'wip'")).toBe(false);
134
- expect(isSafeCommand("git stash pop")).toBe(false);
135
- });
136
-
137
- it("allows 2>/dev/null on safe commands", () => {
138
- expect(isSafeCommand("git remote -v 2>/dev/null")).toBe(true);
139
- expect(isSafeCommand("gh pr view 1564 2>/dev/null")).toBe(true);
140
- expect(isSafeCommand("npm list 2>/dev/null")).toBe(true);
141
- });
142
-
143
- it("allows 2>&1 on safe commands", () => {
144
- expect(isSafeCommand("git log 2>&1")).toBe(true);
145
- });
146
-
147
- it("still blocks stdout redirects even with stderr redirect present", () => {
148
- expect(isSafeCommand("echo 'hello' > file.ts 2>/dev/null")).toBe(false);
149
- expect(isSafeCommand("cat config > backup.txt 2>/dev/null")).toBe(false);
150
- });
151
-
152
- it("allows the exact user-reported blocked commands", () => {
153
- expect(isSafeCommand("cd /Users/u/partying/pt-room && git remote -v 2>/dev/null; echo '---'; ls")).toBe(true);
154
- expect(isSafeCommand("gh pr view 1564 --repo olachat/pt-partying --json title,body,files,additions,deletions 2>/dev/null || echo 'gh failed'")).toBe(true);
155
- });
156
- ```
157
-
158
- 2. Run tests:
159
- ```bash
160
- npx vitest run tests/workflow-guard.test.ts
161
- ```
162
- Expected: all tests pass (including new ones).
163
-
164
- 3. Commit:
165
- ```bash
166
- git add tests/workflow-guard.test.ts
167
- git commit -m "test(workflow-guard): add tests for cd, gh, git read-only subcommands, and redirect stripping"
168
- ```
@@ -1,54 +0,0 @@
1
- # Add Go read-only commands to workflow-guard safe list
2
-
3
- ## Context
4
-
5
- Go toolchain read-only commands (`go doc`, `go list`, `go version`, `go env`) are blocked during brainstorm/plan phases because they're not in `SAFE_PATTERNS`. These are purely read-only with no side effects and are commonly needed during code exploration.
6
-
7
- ## Tasks
8
-
9
- ### 1 — Add Go safe patterns [Modifying tested code]
10
-
11
- **File:** `extensions/workflow-guard.ts`
12
-
13
- Add four entries to `SAFE_PATTERNS`, after the `git describe` entry:
14
-
15
- ```ts
16
- /^\s*go\s+doc\b/,
17
- /^\s*go\s+list\b/,
18
- /^\s*go\s+version\b/,
19
- /^\s*go\s+env\b/,
20
- ```
21
-
22
- **Verify:** run `npx vitest run tests/workflow-guard.test.ts` — all existing tests should pass.
23
-
24
- **Commit:** `feat(workflow-guard): add Go read-only commands to safe list`
25
-
26
- ### 2 — Add tests for Go safe commands [New feature]
27
-
28
- **File:** `tests/workflow-guard.test.ts`
29
-
30
- Add a new `it` block inside the `describe("isSafeCommand", ...)` suite:
31
-
32
- ```ts
33
- it("allows go read-only subcommands", () => {
34
- expect(isSafeCommand("go doc go.opentelemetry.io/otel/label")).toBe(true);
35
- expect(isSafeCommand("go doc go.opentelemetry.io/otel/codes 2>&1 | head -20")).toBe(true);
36
- expect(isSafeCommand("go list -m -versions go.opentelemetry.io/otel 2>&1 | tr ' ' '\\n' | grep -E '^v1\\\\.(2[89]|[3-9][0-9])' | head -20")).toBe(true);
37
- expect(isSafeCommand("go version")).toBe(true);
38
- expect(isSafeCommand("go env GOOS GOARCH")).toBe(true);
39
- });
40
- ```
41
-
42
- Also add a `go build` block test to ensure write-oriented Go commands stay blocked:
43
-
44
- ```ts
45
- it("blocks go write subcommands", () => {
46
- expect(isSafeCommand("go build ./...")).toBe(false);
47
- expect(isSafeCommand("go install golang.org/x/tools/gopls@latest")).toBe(false);
48
- expect(isSafeCommand("go mod tidy")).toBe(false);
49
- });
50
- ```
51
-
52
- **Verify:** run `npx vitest run tests/workflow-guard.test.ts` — all tests pass.
53
-
54
- **Commit:** `test(workflow-guard): add tests for Go read-only safe commands`