@minhduydev/mdpi 0.4.1 → 0.5.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 (34) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/template/.pi/VERSION +1 -1
  3. package/dist/template/.pi/extensions/templates-injector.ts +35 -7
  4. package/dist/template/.pi/prompts/INDEX.md +3 -9
  5. package/dist/template/.pi/skills/INDEX.md +39 -8
  6. package/dist/template/.pi/skills/dcp-hygiene/SKILL.md +1 -1
  7. package/dist/template/.pi/skills/frontend-design/SKILL.md +1 -1
  8. package/dist/template/.pi/skills/frontend-design/references/animation/motion-advanced.md +88 -15
  9. package/dist/template/.pi/skills/frontend-design/references/animation/motion-core.md +148 -13
  10. package/dist/template/.pi/skills/frontend-design/references/shadcn/setup.md +127 -20
  11. package/dist/template/.pi/skills/nextjs-app-router/SKILL.md +334 -0
  12. package/dist/template/.pi/skills/nextjs-cache/SKILL.md +262 -0
  13. package/dist/template/.pi/skills/react-best-practices/SKILL.md +79 -1
  14. package/dist/template/.pi/skills/react-compiler/SKILL.md +237 -0
  15. package/dist/template/.pi/skills/react-hook-form/SKILL.md +374 -0
  16. package/dist/template/.pi/skills/react-server-actions/SKILL.md +299 -0
  17. package/dist/template/.pi/skills/shadcn-ui/SKILL.md +404 -0
  18. package/dist/template/.pi/skills/tanstack-query/SKILL.md +330 -0
  19. package/dist/template/.pi/skills/v0/SKILL.md +264 -0
  20. package/dist/template/.pi/skills/zustand/SKILL.md +333 -0
  21. package/package.json +1 -1
  22. package/dist/template/.pi/prompts/loop-check.md +0 -87
  23. package/dist/template/.pi/prompts/loop-init.md +0 -157
  24. package/dist/template/.pi/prompts/loop-review.md +0 -90
  25. package/dist/template/.pi/skills/loop-audit/SKILL.md +0 -141
  26. package/dist/template/.pi/skills/loop-cost/SKILL.md +0 -130
  27. package/dist/template/.pi/skills/loop-engineering/SKILL.md +0 -175
  28. package/dist/template/.pi/templates/loop-github-action.yml +0 -162
  29. package/dist/template/.pi/templates/loop-orchestrator.sh +0 -514
  30. package/dist/template/.pi/templates/loop-orchestrator.test.ts +0 -332
  31. package/dist/template/.pi/templates/loop-orchestrator.ts +0 -936
  32. package/dist/template/.pi/templates/loop-state.json +0 -24
  33. package/dist/template/.pi/templates/loop-state.md +0 -98
  34. package/dist/template/.pi/templates/loop-vision.md +0 -110
@@ -0,0 +1,333 @@
1
+ ---
2
+ name: zustand
3
+ description: Use when implementing global or shared state management in React with Zustand v5. Covers store creation, slices pattern, middleware, selective subscriptions, React 19 + SSR integration. MUST load before any state management implementation.
4
+ ---
5
+
6
+ # Zustand v5
7
+
8
+ ## When to Use
9
+
10
+ - Managing global or shared client-side state in React
11
+ - Replacing Redux, Jotai, or Context for state management
12
+ - Creating stores that are used across multiple components
13
+ - Implementing slices for domain-separated state
14
+ - Persisting state to localStorage or sessionStorage
15
+ - Using middleware (immer, devtools, persist)
16
+
17
+ ## When NOT to Use
18
+
19
+ - Server state (use TanStack Query or Server Components)
20
+ - Form state (use React Hook Form or Server Actions)
21
+ - Single-component local state (use `useState` or `useReducer`)
22
+ - Server Components (Zustand is client-only)
23
+
24
+ ## Setup
25
+
26
+ ```bash
27
+ npm install zustand
28
+ ```
29
+
30
+ ## Basic Store
31
+
32
+ ```tsx
33
+ // stores/counter.ts
34
+ import { create } from 'zustand'
35
+
36
+ interface CounterState {
37
+ count: number
38
+ increment: () => void
39
+ decrement: () => void
40
+ reset: () => void
41
+ }
42
+
43
+ export const useCounterStore = create<CounterState>((set) => ({
44
+ count: 0,
45
+ increment: () => set((state) => ({ count: state.count + 1 })),
46
+ decrement: () => set((state) => ({ count: state.count - 1 })),
47
+ reset: () => set({ count: 0 }),
48
+ }))
49
+ ```
50
+
51
+ ```tsx
52
+ // components/Counter.tsx
53
+ 'use client'
54
+
55
+ import { useCounterStore } from '@/stores/counter'
56
+
57
+ export function Counter() {
58
+ const { count, increment, decrement } = useCounterStore()
59
+
60
+ return (
61
+ <div>
62
+ <p>Count: {count}</p>
63
+ <button onClick={increment}>+</button>
64
+ <button onClick={decrement}>-</button>
65
+ </div>
66
+ )
67
+ }
68
+ ```
69
+
70
+ ## Slices Pattern
71
+
72
+ Split store into domain slices:
73
+
74
+ ```tsx
75
+ // stores/index.ts
76
+ import { create } from 'zustand'
77
+ import { createAuthSlice, type AuthSlice } from './slices/auth'
78
+ import { createCartSlice, type CartSlice } from './slices/cart'
79
+
80
+ type Store = AuthSlice & CartSlice
81
+
82
+ export const useStore = create<Store>()((...args) => ({
83
+ ...createAuthSlice(...args),
84
+ ...createCartSlice(...args),
85
+ }))
86
+ ```
87
+
88
+ ```tsx
89
+ // stores/slices/auth.ts
90
+ import type { StateCreator } from 'zustand'
91
+
92
+ export interface AuthSlice {
93
+ user: User | null
94
+ login: (credentials: Credentials) => Promise<void>
95
+ logout: () => void
96
+ }
97
+
98
+ export const createAuthSlice: StateCreator<AuthSlice, [], [], AuthSlice> = (set) => ({
99
+ user: null,
100
+ login: async (credentials) => {
101
+ const user = await api.login(credentials)
102
+ set({ user })
103
+ },
104
+ logout: () => set({ user: null }),
105
+ })
106
+ ```
107
+
108
+ ## Selective Subscriptions
109
+
110
+ Zustand re-renders only when **used** state changes:
111
+
112
+ ```tsx
113
+ // ❌ Whole store — re-renders on any change
114
+ const { count, name } = useStore()
115
+
116
+ // ✅ Selective — re-renders only when count changes
117
+ const count = useStore((state) => state.count)
118
+ const increment = useStore((state) => state.increment) // Stable reference
119
+
120
+ // ✅ Multiple values — useShallow for objects
121
+ import { useShallow } from 'zustand/react/shallow'
122
+
123
+ const { name, email } = useStore(
124
+ useShallow((state) => ({ name: state.user.name, email: state.user.email }))
125
+ )
126
+ ```
127
+
128
+ `useShallow` does shallow equality — avoids re-render when both values are the same.
129
+
130
+ ## Middleware
131
+
132
+ ### Persist (localStorage)
133
+
134
+ ```tsx
135
+ import { create } from 'zustand'
136
+ import { persist } from 'zustand/middleware'
137
+
138
+ export const useSettingsStore = create(
139
+ persist(
140
+ (set) => ({
141
+ theme: 'light',
142
+ setTheme: (theme: 'light' | 'dark') => set({ theme }),
143
+ }),
144
+ {
145
+ name: 'app-settings', // localStorage key
146
+ partialize: (state) => ({ theme: state.theme }), // Only persist theme
147
+ }
148
+ )
149
+ )
150
+ ```
151
+
152
+ ### Immer (Immutable Updates)
153
+
154
+ ```tsx
155
+ import { create } from 'zustand'
156
+ import { immer } from 'zustand/middleware/immer'
157
+
158
+ export const useTodoStore = create(
159
+ immer((set) => ({
160
+ todos: [] as Todo[],
161
+ addTodo: (text: string) =>
162
+ set((state) => {
163
+ state.todos.push({ id: crypto.randomUUID(), text, done: false })
164
+ }),
165
+ toggleTodo: (id: string) =>
166
+ set((state) => {
167
+ const todo = state.todos.find((t) => t.id === id)
168
+ if (todo) todo.done = !todo.done
169
+ }),
170
+ }))
171
+ )
172
+ ```
173
+
174
+ ### DevTools
175
+
176
+ ```tsx
177
+ import { create } from 'zustand'
178
+ import { devtools } from 'zustand/middleware'
179
+
180
+ export const useStore = create(
181
+ devtools(
182
+ (set) => ({
183
+ count: 0,
184
+ increment: () => set((s) => ({ count: s.count + 1 }), false, 'increment'),
185
+ }),
186
+ { name: 'AppStore' } // Name in Redux DevTools
187
+ )
188
+ )
189
+ ```
190
+
191
+ ### Combining Multiple Middleware
192
+
193
+ ```tsx
194
+ import { create } from 'zustand'
195
+ import { devtools, persist, immer } from 'zustand/middleware'
196
+
197
+ export const useStore = create(
198
+ devtools(
199
+ persist(
200
+ immer((set) => ({
201
+ // store...
202
+ })),
203
+ { name: 'app-storage' }
204
+ ),
205
+ { name: 'AppStore' }
206
+ )
207
+ )
208
+ ```
209
+
210
+ ## React 19 + Server Components
211
+
212
+ Zustand is **client-only**. Pattern for Next.js App Router:
213
+
214
+ ```tsx
215
+ // stores/useStore.ts
216
+ import { create } from 'zustand'
217
+
218
+ export const useStore = create<Store>((set) => ({
219
+ // ...
220
+ }))
221
+ ```
222
+
223
+ ```tsx
224
+ // components/ClientWrapper.tsx
225
+ 'use client'
226
+
227
+ import { useStore } from '@/stores/useStore'
228
+
229
+ export function ClientWrapper({ children }) {
230
+ const data = useStore((s) => s.data)
231
+
232
+ return <div>{children}</div>
233
+ }
234
+ ```
235
+
236
+ **Rules**:
237
+ - Stores are defined outside components (module scope)
238
+ - Store consumers must be in `'use client'` components
239
+ - Server Components can import the store type but cannot `useStore()`
240
+ - Use React Context to provide a store instance if you need SSR hydration
241
+
242
+ ## SSR Hydration Pattern
243
+
244
+ ```tsx
245
+ // app/providers.tsx
246
+ 'use client'
247
+
248
+ import { type ReactNode, createContext, useContext, useRef } from 'react'
249
+ import { type StoreApi, useStore } from 'zustand'
250
+
251
+ // Create context for store
252
+ const StoreContext = createContext<StoreApi<AppStore> | null>(null)
253
+
254
+ export function StoreProvider({ children }: { children: ReactNode }) {
255
+ const storeRef = useRef<StoreApi<AppStore>>()
256
+
257
+ if (!storeRef.current) {
258
+ storeRef.current = createAppStore()
259
+ }
260
+
261
+ return (
262
+ <StoreContext.Provider value={storeRef.current}>
263
+ {children}
264
+ </StoreContext.Provider>
265
+ )
266
+ }
267
+
268
+ // Hook to use the store
269
+ export function useAppStore<T>(selector: (state: AppStore) => T): T {
270
+ const store = useContext(StoreContext)
271
+ if (!store) throw new Error('Missing StoreProvider')
272
+ return useStore(store, selector)
273
+ }
274
+ ```
275
+
276
+ ## Async Actions
277
+
278
+ ```tsx
279
+ // Async actions are just async functions in the store:
280
+ interface UserStore {
281
+ user: User | null
282
+ loading: boolean
283
+ error: Error | null
284
+ fetchUser: (id: string) => Promise<void>
285
+ }
286
+
287
+ export const useUserStore = create<UserStore>((set) => ({
288
+ user: null,
289
+ loading: false,
290
+ error: null,
291
+ fetchUser: async (id) => {
292
+ set({ loading: true, error: null })
293
+ try {
294
+ const user = await api.getUser(id)
295
+ set({ user, loading: false })
296
+ } catch (error) {
297
+ set({ error: error as Error, loading: false })
298
+ }
299
+ },
300
+ }))
301
+ ```
302
+
303
+ ## When to Use Zustand vs Context vs TanStack Query
304
+
305
+ | Tool | Best for |
306
+ |------|----------|
307
+ | **Zustand** | Global client state: theme, auth, cart, UI preferences |
308
+ | **React Context** | Dependency injection, theming, auth provider — static values that rarely change |
309
+ | **TanStack Query** | Server state: data fetching, caching, mutations |
310
+ | **useState/useReducer** | Local component state |
311
+
312
+ ## Common Pitfalls
313
+
314
+ | Pitfall | Fix |
315
+ |---------|-----|
316
+ | Using Zustand for server state | Use TanStack Query for fetched data — Zustand for client-only state |
317
+ | `useStore()` without selector — re-renders on any change | Always use selectors: `useStore(s => s.count)` |
318
+ | Multiple values returned as new object every render | Use `useShallow` for object selectors |
319
+ | Store in Server Component | Move store usage to `'use client'` |
320
+ | `getState()` in render | `getState()` is for callbacks/outside React, not render |
321
+ | Large stores with everything in one file | Use slices pattern to separate domains |
322
+ | Recreating store on every render | Define store outside component or use `useRef` for context pattern |
323
+
324
+ ## Verification
325
+
326
+ - [ ] Store defined outside component (module scope) or via `useRef` in provider
327
+ - [ ] All store consumers are in `'use client'` components
328
+ - [ ] Selectors used for granular subscriptions — no destructured `useStore()`
329
+ - [ ] `useShallow` used for multi-value object selectors
330
+ - [ ] Server state (fetched data) managed by TanStack Query, not Zustand
331
+ - [ ] Slices pattern used for stores with multiple domains
332
+ - [ ] `persist` middleware configured with `partialize` to avoid storing sensitive data
333
+ - [ ] DevTools middleware enabled (development only)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minhduydev/mdpi",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "CLI to scaffold and manage a Pi coding-agent kit (.pi/) in any repo",
5
5
  "keywords": [
6
6
  "pi",
@@ -1,87 +0,0 @@
1
- ---
2
- description: NO-GO qualification gate — decide whether a task is safe to run as an unattended loop
3
- argument-hint: "<task description> [--help]"
4
- ---
5
-
6
- # Loop-Check: $ARGUMENTS
7
-
8
- Qualify a task before it is ever scheduled as an unattended loop. Emit a single GO/NO-GO verdict with the cited condition that produced it. This prompt is the gate *before* the gate — it refuses work a loop cannot honestly judge.
9
-
10
- > Refuse first, test second, checklist last. Never let "looks automatable" override the refuse-list.
11
-
12
- ## Parse Arguments
13
-
14
- | Argument | Default | Description |
15
- | ------------- | -------- | ------------------------------------------------ |
16
- | `<task>` | required | The task proposed for unattended looping |
17
- | `--help` | false | Show this usage |
18
-
19
- ## Step 1 — Refuse-List (Immediate NO-GO)
20
-
21
- If the task touches any of these, **stop here** and emit NO-GO. Do not proceed to the 2-condition test.
22
-
23
- - **auth** — login, sessions, tokens, permissions, auth flows, auth module rewrites
24
- - **payments** — billing, checkout, refunds, subscriptions, payment provider integration
25
- - **architecture** — framework/library switches, schema migrations, new DB tables, new services, breaking API changes
26
-
27
- > Rationale: these need human judgement a loop cannot provide. The refuse-list is the honest ceiling, not a configurable preference.
28
-
29
- If a refuse-list category is hit → `CONDITION: <refused category> refused` (e.g. `CONDITION: architecture refused`).
30
-
31
- ## Step 2 — The 2-Condition Test
32
-
33
- Both conditions must hold. If either fails, emit NO-GO citing the failed condition.
34
-
35
- 1. **Verification is automated.** There exists an objective command whose **exit code** decides pass/fail — `npm test`, `tsc --noEmit`, `eslint`, a custom gate script. The stop condition is computational (exit code), never an LLM's opinion. If the only "check" is "the agent says it looks good" → FAIL.
36
- 2. **The token budget absorbs the waste.** The cost of one wasted run (gate fails, no-op, early-exit) is small enough that running on the scheduled cadence does not blow the budget. If a single failed run is expensive (large model, long context, many turns) and there is no per-run cap → FAIL.
37
-
38
- If condition 1 fails → `CONDITION: verification not automated (no exit-code gate)`.
39
- If condition 2 fails → `CONDITION: budget does not absorb waste (uncapped/expensive failed run)`.
40
-
41
- ## Step 3 — 30-Second Checklist
42
-
43
- Confirm every item. Any miss → NO-GO citing the missing item.
44
-
45
- - [ ] **Objective gate exists** — a named command with a pass = exit 0 contract (write it down; "tests" without a command is not a gate).
46
- - [ ] **Hard stop exists** — a non-negotiable exit condition: repeated gate failure, budget cap hit, or forbidden path touched. The loop exits; it does not improvise.
47
- - [ ] **Human approves merge/deploy/dependency changes** — the loop may open PRs and stage work; a human merges, deploys, and changes deps. No auto-merge.
48
-
49
- Missing gate → `CONDITION: no objective gate`.
50
- Missing hard stop → `CONDITION: no hard stop`.
51
- No human-approval boundary → `CONDITION: no human-approval boundary on merge/deploy/deps`.
52
-
53
- ## Step 4 — Emit Verdict
54
-
55
- Output **exactly** these two lines and nothing else as the decision:
56
-
57
- ```
58
- VERDICT: GO
59
- CONDITION: verification automated + budget absorbs waste
60
- ```
61
-
62
- or
63
-
64
- ```
65
- VERDICT: NO-GO
66
- CONDITION: <cited condition from Step 1, 2, or 3>
67
- ```
68
-
69
- - `VERDICT` is `GO` or `NO-GO` — no other values.
70
- - `CONDITION` cites the specific condition that produced the verdict. For GO, cite both passing conditions. For NO-GO, cite the first failing condition (Step 1 overrides Step 2 overrides Step 3).
71
- - Do not add rationale, recommendations, or next steps after the verdict lines. The verdict is the contract.
72
-
73
- ## Worked Examples
74
-
75
- - **"triage failing CI nightly"** with `npm test` gate, no-op early-exit <5k tokens → `VERDICT: GO` / `CONDITION: verification automated + budget absorbs waste`
76
- - **"rewrite auth module"** → `VERDICT: NO-GO` / `CONDITION: auth refused`
77
- - **"migrate from REST to GraphQL"** → `VERDICT: NO-GO` / `CONDITION: architecture refused`
78
- - **"keep docs in sync with code weekly"** with no gate command → `VERDICT: NO-GO` / `CONDITION: verification not automated (no exit-code gate)`
79
-
80
- ## Related
81
-
82
- | Companion | Role |
83
- |---|---|
84
- | `loop-engineering` skill | The 2-condition test, refuse-list, and 5 building blocks this gate codifies |
85
- | `/loop-init` | Scaffold `.pi/loops/<name>/` once a task is GO |
86
- | `/loop-review` | Maker/checker verification — the gate *during* a run |
87
- | `loop-audit` | Readiness scoring (L0-L3) for an already-GO loop |
@@ -1,157 +0,0 @@
1
- ---
2
- description: Scaffold a new unattended loop at .pi/loops/<name>/ with VISION, STATE, and a per-loop SKILL stub
3
- argument-hint: "<name> [--help]"
4
- ---
5
-
6
- # Loop Init: $ARGUMENTS
7
-
8
- Scaffold a new loop-engineering harness at `.pi/loops/<name>/` from the templates shipped in `.pi/templates/`. Run once per loop. The scaffold is the contract + ledger + procedure the orchestrator (T9/T10) drives unattended.
9
-
10
- > **Prerequisite:** `/loop-check <task>` returned GO. If not, refuse and tell the user to qualify the task first.
11
-
12
- ## Parse Arguments
13
-
14
- | Argument | Default | Description |
15
- | -------- | --------- | -------------------------------------------- |
16
- | `<name>` | required | Loop slug; used as directory name `loop/<name>/<ts>` branch prefix |
17
- | `--help` | false | Show this usage |
18
-
19
- **Validation:** `<name>` must be a filesystem-safe slug (`^[a-z0-9][a-z0-9-]*$`, lowercase). Reject names containing `/`, spaces, or upper-case. Trim surrounding whitespace before use.
20
-
21
- ## When to Use
22
-
23
- - You want to start a new unattended loop (nightly CI triage, dependency bumps, doc sync, PR babysitting).
24
- - `/loop-check <task>` already returned GO (verification automated + token budget absorbs waste + human approves merge/deploy/deps).
25
- - You need the contract (VISION.md), dedup ledger (STATE.json + STATE.md), and per-loop procedure (SKILL.md) that the orchestrator will drive.
26
-
27
- Do NOT use for:
28
- - One-off tasks (use `/create` or `/fix`).
29
- - Tasks `/loop-check` refused (auth, payments, architecture) — refuse here too.
30
-
31
- ## The Scaffold Steps
32
-
33
- ### 1. Create the loop directory
34
-
35
- Create `.pi/loops/<name>/` (parent `.pi/loops/` may not exist yet — create it).
36
-
37
- ### 2. Copy the four artifacts
38
-
39
- Copy map (exact source → destination):
40
-
41
- | Source (template) | Destination | Purpose |
42
- | ----------------------------------------- | ------------------------------------ | ----------------------------------------- |
43
- | `.pi/templates/loop-vision.md` | `.pi/loops/<name>/VISION.md` | Anti goal-drift contract (FR2) |
44
- | `.pi/templates/loop-state.md` | `.pi/loops/<name>/STATE.md` | Human-readable state mirror (FR3) |
45
- | `.pi/templates/loop-state.json` | `.pi/loops/<name>/STATE.json` | Machine dedup ledger (FR3, authoritative) |
46
- | (new stub) | `.pi/loops/<name>/SKILL.md` | Per-loop procedure (classification + fix patterns) |
47
-
48
- Copy the three templates byte-for-byte first (placeholders intact), then fill placeholders in the copied files. The `SKILL.md` stub is not a template — write a minimal seed:
49
-
50
- ```markdown
51
- ---
52
- name: <name>
53
- description: Per-loop procedure for <name> — classify, fix, escalate
54
- ---
55
-
56
- # Loop Procedure: <name>
57
-
58
- Reread `VISION.md` at the start of every run. Do not act outside it.
59
-
60
- ## Procedure
61
-
62
- 1. Reread `VISION.md` (boundaries authoritative).
63
- 2. Read `STATE.json` — build the dedup set from `processed[]`.
64
- 3. Fetch candidate items (per the loop's source: CI runs, PRs, packages, commits).
65
- 4. For each item: skip if in `processed[]`; else classify → fix / escalate / reject.
66
- 5. Run the Gate command (the ```bash block directly under `## Gate` in VISION.md); ship only on exit 0.
67
- 6. Append to `STATE.json.processed[]`, `completed[]`, `escalated[]`, or `failures[]`.
68
- 7. Enforce hard stops (see VISION.md "Hard stops").
69
-
70
- ## Classification rubric
71
-
72
- <!-- Fill by hand after supervising the first manual runs. -->
73
-
74
- ## Fix patterns
75
-
76
- <!-- Fill by hand as repeatable fixes are discovered. -->
77
- ```
78
-
79
- ### 3. Fill `<name>` placeholders
80
-
81
- In the copied `VISION.md`, `STATE.md`, and `STATE.json`, replace every placeholder occurrence with the actual loop name:
82
-
83
- - `<loop-name>` → `<name>`
84
- - Leave human-fill placeholders (`[Owner]`, `[Date]`, `[cron expression or "manual"]`, `[Allowed action 1]`, `<GATE_COMMAND>`, etc.) as bracketed prompts for the user to edit by hand — do NOT invent values.
85
-
86
- Tell the user explicitly which placeholders still need their input.
87
-
88
- ### 4. Print the rollout order
89
-
90
- After scaffolding, print this rollout order so the user knows the path from scaffold to unattended run:
91
-
92
- ```
93
- Rollout order:
94
- 1. check — /loop-check <task> (already GO; re-run if scope changes)
95
- 2. init — /loop-init <name> (this step — scaffold created)
96
- 3. supervise — run the loop's SKILL.md manually in a session; refine classification/fix patterns
97
- 4. wire — copy loop-orchestrator.ts/.sh + loop-github-action.yml; set cadence + gate + scope
98
- 5. run — schedule cron/launchd (local) or GitHub Actions `on: schedule` (CI); loop runs unattended
99
- 6. review — /loop-review <name> for interactive maker/checker verify
100
- 7. audit/cost — loop-audit scores readiness (L0-L3); track cost-per-accepted-change; kill if acceptance < 50%
101
- ```
102
-
103
- ## Idempotency Guard
104
-
105
- Before writing anything:
106
-
107
- 1. Check whether `.pi/loops/<name>/` already exists.
108
- 2. **If it exists:** STOP. Do not overwrite. Ask the user:
109
- > `.pi/loops/<name>/` already exists. Overwrite all files (VISION.md, STATE.md, STATE.json, SKILL.md)? This destroys any hand-edited contract/state. (y/N)
110
- 3. **Refuse overwrite without explicit confirmation.** On `N` or no answer, abort and report the existing tree without modifying it.
111
- 4. **If it does not exist:** proceed with the scaffold.
112
-
113
- This guard protects hand-edited VISION.md contracts and STATE.json dedup ledgers from being clobbered by a re-run.
114
-
115
- ## Output
116
-
117
- Print:
118
-
119
- 1. **Created tree** (e.g.):
120
- ```
121
- .pi/loops/<name>/
122
- ├── VISION.md (contract — fill [Owner], [Date], cadence, Scope, Gate)
123
- ├── STATE.md (human-readable state mirror)
124
- ├── STATE.json (machine dedup ledger — authoritative)
125
- └── SKILL.md (per-loop procedure — fill classification + fix patterns by hand)
126
- ```
127
- 2. **Rollout order** (the 7-step block above).
128
- 3. **Placeholders still needing input** (list each `[...]` / `<GATE_COMMAND>` the user must fill by hand, with file:line where useful).
129
- 4. **Next step:** `supervise` — run the loop's `SKILL.md` manually in a session and refine classification/fix patterns before wiring the orchestrator.
130
-
131
- ## Failure Handling
132
-
133
- | Scenario | Action |
134
- | ------------------------------------- | ------------------------------------------------------------ |
135
- | `<name>` missing or invalid slug | Abort with the validation regex and an example |
136
- | `.pi/loops/<name>/` exists, no confirm| Abort, print existing tree, do not modify |
137
- | Template missing from `.pi/templates/`| Abort, list which template is missing (T2 must be shipped first) |
138
- | `<name>` would collide with a reserved path | Abort, suggest an alternate slug |
139
-
140
- ## Stop Conditions
141
-
142
- - `<name>` invalid → stop, report the regex.
143
- - Directory exists and user declines overwrite → stop, report existing tree.
144
- - Any of the three templates missing → stop, report (T2 prerequisite unmet).
145
-
146
- ## Related Commands
147
-
148
- | Need | Command |
149
- | ------------------------ | ----------------- |
150
- | Qualify a task first | `/loop-check` |
151
- | Review a running loop | `/loop-review` |
152
- | Audit loop readiness | `loop-audit` |
153
-
154
- ## Related Skills
155
-
156
- - `loop-engineering` — 2-condition test, 5 building blocks, VISION/state contract, failure modes
157
- - `planning-and-task-breakdown` — decompose the loop's procedure into verifiable steps
@@ -1,90 +0,0 @@
1
- ---
2
- description: Maker/checker review for a loop — spawns a verifier subagent that runs the gate and inspects the diff, then emits ACCEPT/REJECT with evidence
3
- argument-hint: "<loop-name> [--help]"
4
- ---
5
-
6
- # Loop Review: $ARGUMENTS
7
-
8
- Run the maker/checker gate for `<loop-name>`: dispatch an independent **verifier subagent** that runs the `## Gate` command from the loop's `VISION.md` via bash and reads the exit code, inspect the working-tree diff for scope creep and forbidden touches, then emit exactly `DECISION: ACCEPT|REJECT` plus `EVIDENCE:`. The maker never self-approves — default to **REJECT** on any uncertainty.
9
-
10
- ## When to Use
11
-
12
- - After a loop's maker (the `pi -p` capability-deprived agent) reports its work done and before the orchestrator ships.
13
- - Interactive `/loop-review <loop-name>` to manually gate a loop cycle.
14
- - Whenever you need an independent, computational gate decision — never trust the maker's self-report.
15
- - Do **not** use for the orchestrator's own gate run (FR7); this prompt is the interactive maker/checker wrapper around the same gate-parse contract.
16
-
17
- ## The Verifier Subagent
18
-
19
- Dispatch a **verifier** as an independent subagent so the maker cannot influence or self-approve the decision. The verifier's sole job: run the gate, read the exit code, collect diff findings, return raw evidence.
20
-
21
- ### Dispatch
22
-
23
- Use the `subagent` tool with **type `review`**. Pass a prompt that instructs the verifier to:
24
-
25
- 1. Read `.pi/loops/<loop-name>/VISION.md` (or wherever the loop's VISION lives for this run) from disk — do not trust context-supplied copies.
26
- 2. Extract the gate command using the **exact gate-parse contract** below.
27
- 3. Run the gate via bash and capture the **exit code** (the computational signal — never an opinion).
28
- 4. Inspect the working-tree/staged diff for scope creep and forbidden paths (see The Diff Check).
29
- 5. Return raw evidence only: exit code, gate command run, diff findings (paths touched, any forbidden hits). **No verdict** — the maker (this agent) issues the verdict.
30
-
31
- ### Gate-parse contract (must match T2 exactly)
32
-
33
- Extract the gate command from `VISION.md` as: **the SINGLE fenced ```bash block located directly under the `## Gate` heading** — require **EXACTLY ONE** such block directly under `## Gate` (zero or more-than-one → REJECT / hard fail). Take that single block's content, strip trailing whitespace, run it via `bash -c "<command>"`, and read the exit code.
34
-
35
- - `exit 0` → PASS → ship (orchestrator pushes `loop/<name>/<ts>` + opens PR)
36
- - non-zero → FAIL → no ship; record failure in `STATE.json.failures[]`; cleanup worktree
37
-
38
- The gate decision is **computational (exit code), never an LLM's opinion**. If `## Gate` is missing, the fenced block is empty, or the block count under `## Gate` is not exactly one (zero or more-than-one), treat that as a hard fail: emit `DECISION: REJECT` with `EVIDENCE: gate not parseable` and do not run anything.
39
-
40
- ### Evidence to collect from the verifier
41
-
42
- - The exact gate command extracted (verbatim, after whitespace strip).
43
- - The bash exit code (integer).
44
- - stdout/stderr tail (last ~20 lines) — enough to cite a concrete failure.
45
- - List of paths touched in the diff (added/modified/deleted).
46
- - Any forbidden-path hits (see The Diff Check).
47
-
48
- ## The Diff Check
49
-
50
- Independently of the verifier (or have the verifier report and you confirm), inspect the diff against the loop's declared boundaries.
51
-
52
- ### Scope creep
53
-
54
- Compare every path in the diff to `## Scope` and `## Out-of-scope` in `VISION.md`. Any touched path that is not clearly inside `## Scope` is scope creep → REJECT. When a path is ambiguous (not explicitly listed in either section), treat it as out-of-scope and escalate, do not approve.
55
-
56
- ### Forbidden touches (always REJECT)
57
-
58
- Regardless of scope wording, REJECT immediately if the diff touches any of:
59
-
60
- - `VISION.md` (the loop contract itself — protected path).
61
- - The gate command / gate script referenced by `## Gate`.
62
- - `package.json`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, or any lockfile.
63
- - Any path under `## Out-of-scope` in `VISION.md`.
64
- - Auth, payments, or architectural-decision files (per `## Human-approval-required`).
65
-
66
- Cite the offending path verbatim in `EVIDENCE:`.
67
-
68
- ## Output Contract
69
-
70
- Emit exactly two lines (no prose around them, no extra fields):
71
-
72
- ```
73
- DECISION: ACCEPT|REJECT
74
- EVIDENCE: <exit code + diff findings>
75
- ```
76
-
77
- - `DECISION: ACCEPT` only when the verifier reports **exit code 0** AND the diff has zero scope-creep and zero forbidden-touch findings.
78
- - `DECISION: REJECT` otherwise. `EVIDENCE:` must cite the concrete signal — e.g. `gate exit 1: npm test failed (see stderr tail)` or `forbidden touch: package.json` or `scope creep: src/auth/* not in VISION.md Scope`.
79
- - The orchestrator consumes these two lines machine-readably; do not decorate them with markdown, prefixes, or commentary.
80
-
81
- ## Default-Reject Rule
82
-
83
- **The maker never self-approves.** The verdict is issued here (the maker/checker prompt), but the *evidence* comes from the independent verifier subagent — never from the maker's own self-report. On any uncertainty — gate not parseable, exit code unreadable, diff not inspectable, scope ambiguous, verifier subagent failed to return — emit:
84
-
85
- ```
86
- DECISION: REJECT
87
- EVIDENCE: <what was uncertain — e.g. "verifier did not return exit code" / "scope ambiguous for src/foo.ts">
88
- ```
89
-
90
- Default-reject is the safe state; the orchestrator records it and retries or escalates. Never substitute opinion for the computational exit-code signal.