@minhduydev/mdpi 0.4.1 → 0.6.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 (41) hide show
  1. package/dist/index.js +4 -2
  2. package/dist/template/.pi/AGENTS.md +1 -1
  3. package/dist/template/.pi/README.md +2 -3
  4. package/dist/template/.pi/VERSION +1 -1
  5. package/dist/template/.pi/agents/explore.md +1 -1
  6. package/dist/template/.pi/agents/scout.md +1 -1
  7. package/dist/template/.pi/extensions/templates-injector.ts +35 -7
  8. package/dist/template/.pi/prompts/INDEX.md +3 -9
  9. package/dist/template/.pi/prompts/gc.md +2 -1
  10. package/dist/template/.pi/prompts/verify.md +24 -0
  11. package/dist/template/.pi/skills/INDEX.md +40 -8
  12. package/dist/template/.pi/skills/dcp-hygiene/SKILL.md +1 -1
  13. package/dist/template/.pi/skills/frontend-design/SKILL.md +1 -1
  14. package/dist/template/.pi/skills/frontend-design/references/animation/motion-advanced.md +88 -15
  15. package/dist/template/.pi/skills/frontend-design/references/animation/motion-core.md +148 -13
  16. package/dist/template/.pi/skills/frontend-design/references/shadcn/setup.md +127 -20
  17. package/dist/template/.pi/skills/nextjs-app-router/SKILL.md +334 -0
  18. package/dist/template/.pi/skills/nextjs-cache/SKILL.md +262 -0
  19. package/dist/template/.pi/skills/react-best-practices/SKILL.md +79 -1
  20. package/dist/template/.pi/skills/react-compiler/SKILL.md +237 -0
  21. package/dist/template/.pi/skills/react-hook-form/SKILL.md +374 -0
  22. package/dist/template/.pi/skills/react-server-actions/SKILL.md +299 -0
  23. package/dist/template/.pi/skills/shadcn-ui/SKILL.md +404 -0
  24. package/dist/template/.pi/skills/tanstack-query/SKILL.md +330 -0
  25. package/dist/template/.pi/skills/v0/SKILL.md +264 -0
  26. package/dist/template/.pi/skills/zustand/SKILL.md +333 -0
  27. package/package.json +1 -1
  28. package/dist/template/.pi/context/fallow.md +0 -137
  29. package/dist/template/.pi/prompts/loop-check.md +0 -87
  30. package/dist/template/.pi/prompts/loop-init.md +0 -157
  31. package/dist/template/.pi/prompts/loop-review.md +0 -90
  32. package/dist/template/.pi/skills/loop-audit/SKILL.md +0 -141
  33. package/dist/template/.pi/skills/loop-cost/SKILL.md +0 -130
  34. package/dist/template/.pi/skills/loop-engineering/SKILL.md +0 -175
  35. package/dist/template/.pi/templates/loop-github-action.yml +0 -162
  36. package/dist/template/.pi/templates/loop-orchestrator.sh +0 -514
  37. package/dist/template/.pi/templates/loop-orchestrator.test.ts +0 -332
  38. package/dist/template/.pi/templates/loop-orchestrator.ts +0 -936
  39. package/dist/template/.pi/templates/loop-state.json +0 -24
  40. package/dist/template/.pi/templates/loop-state.md +0 -98
  41. package/dist/template/.pi/templates/loop-vision.md +0 -110
@@ -1,175 +0,0 @@
1
- ---
2
- name: loop-engineering
3
- description: Use when designing, qualifying, or running unattended coding loops (nightly CI triage, dependency bumps, doc sync, PR babysitting). Encodes the 2-condition test, the 5 building blocks, the VISION/state anti-drift contract, failure modes (Ralph Wiggum), confidence-gated action, and the honest ceiling.
4
- ---
5
-
6
- # Loop Engineering
7
-
8
- Methodology for designing systems that prompt an agent on a schedule, rather than hand-prompting it every turn. Composes native pi capabilities — never ships a daemon, never rebuilds scheduling/subagent/worktree. A loop is **qualified before it runs**, **gated by exit code before it ships**, **bound by a contract before it drifts**, and **budget-capped before it bankrupts you**.
9
-
10
- ## When to Use
11
-
12
- - You are asked to "automate", "schedule", or "run nightly/unattended" a coding task.
13
- - You are about to let an agent act repeatedly without you watching every turn.
14
- - A task is being proposed for an orchestrator (`loop-orchestrator.ts`/`.sh`) or a GitHub Actions `on: schedule` run.
15
- - You need to qualify, contract, score, review, or budget a loop before it ships anything.
16
-
17
- ## When NOT to Use
18
-
19
- - A single interactive change with a human in the loop and a clear exit (no schedule, no repetition).
20
- - Tasks that cannot pass the 2-condition test (see below) — those are NO-GO; do not loop them.
21
-
22
- ## The 2-Condition Test
23
-
24
- Before any loop is allowed to run, **both** conditions must hold. If either fails, refuse (NO-GO) and cite which one:
25
-
26
- 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.
27
- 2. **The token budget absorbs the waste.** The cost of one wasted run (gate fails, no-op, early-exit) is small enough that running the loop on its scheduled cadence does not blow the budget. Estimate it with `loop-cost` first; set a per-run cap.
28
-
29
- Refuse-list (immediate NO-GO, no further test): **auth, payments, architecture.** These need human judgement a loop cannot provide. `/loop-check` codifies this gate.
30
-
31
- > **Example (GO):** "triage failing CI nightly" with `npm test` as gate → verification automated, no-op early-exit <5k tokens → GO, citing "verification automated + budget absorbs waste".
32
- > **Example (NO-GO):** "rewrite auth module" → refuse-list hit → NO-GO, citing "architecture refused".
33
-
34
- ## The 5 Building Blocks
35
-
36
- Every loop is built from exactly five components. Missing any one is a NO-GO.
37
-
38
- | # | Block | What it is | Where it lives |
39
- |---|---|---|---|
40
- | 1 | **VISION** | The contract: Goal, Scope, Out-of-scope, Definition-of-done, Gate (exact command, pass = exit 0), Hard stops, Human-approval-required. Reread at the start of every run. | `loop-vision.md` (template → `.pi/loops/<name>/VISION.md`) |
41
- | 2 | **State** | Dedup ledger + working memory: Last run, In progress, Completed, Escalated, Lessons, **Processed items** keyed by stable IDs (CI run IDs, PR numbers, `package@version`, commit SHAs), Stop conditions. | `loop-state.md` + `loop-state.json` (machine ledger) |
42
- | 3 | **Gate** | The exact command the orchestrator runs via bash and reads the exit code of. Ships only on exit 0; on non-zero, logs + records failure + cleans up. | The `Gate` section of `VISION.md` |
43
- | 4 | **Qualification** | The NO-GO gate applied before the loop is ever scheduled (`/loop-check`): refuse-list + 2-condition test + 30-second checklist (objective gate exists, hard stop exists, human approves merge/deploy/deps). | `/loop-check` prompt |
44
- | 5 | **Readiness** | A scored measure of whether this project is actually loop-ready: 0-100 + L0/L1/L2/L3 from signals (state file, verifier, gate, loop skills, safety docs, GH workflows, MCP, worktree, cost observability, **real loop activity**). L3 is capped at L2 until a real cycle is run and committed. | `loop-audit` skill |
45
-
46
- The maker (the `pi -p` invocation that does the work) is **not** a building block — it is structurally deprived of ship tools (`--tools read,edit,write,bash,grep,find`). It can only stage work; the orchestrator ships **after** the gate passes. Capability-deprivation is structural, not behavioural.
47
-
48
- ## VISION/State Pattern (Anti Goal-Drift Contract)
49
-
50
- Goal drift kills loops. Context summarization silently drops constraints mid-run; the agent then acts outside the original boundaries. The VISION/state pattern is the contract that prevents this.
51
-
52
- - **Reread VISION.md at the start of every run.** Boundaries are re-derived from disk, not from context. When context summarization drops a hard stop, VISION.md restores it.
53
- - **The loop must not act outside VISION.md.** Out-of-scope is as binding as in-scope. If a run discovers work that looks useful but is not in scope, escalate (write it to state's `Escalated`), do not do it.
54
- - **State dedup makes re-runs idempotent.** `STATE.json.processed[]` is keyed by stable IDs. The orchestrator skips already-processed items; deleting `STATE.json` reprocesses everything. This is what makes scheduling safe — a duplicate trigger is harmless.
55
- - **Hard stops are non-negotiable.** If a hard stop fires (gate fails repeatedly, budget cap hit, forbidden path touched), the loop records the stop in state and exits; it does not improvise a workaround.
56
-
57
- ## Failure Modes
58
-
59
- ### The Ralph Wiggum Loop
60
-
61
- > _"I'm helping! I'm helping!"_ — shipping on LLM opinion instead of an exit code.
62
-
63
- The canonical failure: the maker claims the work is done ("tests pass", "it works"), the loop ships it, and nobody ran the gate. The LLM self-approves. The result is broken work merged to main on the strength of a confident sentence.
64
-
65
- **Prevention:** the stop condition is the gate's exit code, full stop. The orchestrator runs the gate via bash and reads `$?`. The maker's opinion is not evidence. `/loop-review` (maker/checker) defaults to REJECT when uncertain and cites the exact exit code in its evidence block. **Never let "I think it passes" substitute for `exit 0`.**
66
-
67
- ### Acting Without Confidence
68
-
69
- The companion failure: the agent fixes a CI failure it cannot reproduce, on a hunch, and ships the fix. The gate may even pass — but the fix is a guess, not a diagnosis.
70
-
71
- **Prevention:** confidence-gated action (next section). No local reproduction → no fix; write diagnosis-only and escalate.
72
-
73
- ### Other failure modes
74
-
75
- - **Context drop** → mitigated by VISION.md reread (above).
76
- - **Cost runaway** → mitigated by the 2-condition test (budget absorbs waste) + `loop-cost` estimate + per-run cap in the orchestrator.
77
- - **Stray ship to main** → mitigated structurally: always ship to `loop/<name>/<ts>` branch + PR; human approves merge; `--tools` omits ship tools; never-do rules block auth/payments/architecture.
78
- - **Gaming the gate** (maker edits the test/gate file to force a pass) → mitigated by Phase C path protection (`loop-guard.ts` blocks edits to `VISION.md`, `package.json`, lockfiles, the gate script). This is **not** eliminated — see Honest Ceiling.
79
-
80
- ## Confidence-Gated Action
81
-
82
- When the maker is classifying a CI failure (or any observed anomaly) and deciding whether to act, run this decision procedure — do not fix on a hunch.
83
-
84
- 1. **Classify** the failure into one of: `flaky`, `infra`, `unknown`, `logic`, `regression`, `dependency`, `docs`, `test-only`. (Extend the taxonomy in the loop's `SKILL.md` as patterns emerge.)
85
- 2. **Estimate confidence** 0.0–1.0 from the evidence available to the maker *right now* (logs, diff, reproducer, prior `STATE.json.lessons`).
86
- 3. **Reproduce locally** if the class is reproducible. If you **cannot reproduce** the failure locally, **lower confidence and abort the fix** — write a diagnosis-only entry to state and escalate.
87
- 4. **Act only if** `confidence > threshold` **AND** `class ∉ {flaky, infra, unknown}`. Otherwise: **diagnosis-only**, no code change. Record the diagnosis in `STATE.json.failures[]` / `lessons[]` so the next run starts warmer.
88
-
89
- ```
90
- if class in {flaky, infra, unknown}:
91
- → diagnosis-only (no fix)
92
- elif not reproducible_locally:
93
- → lower confidence, abort fix, diagnosis-only
94
- elif confidence > threshold:
95
- → act (fix), then run the gate
96
- else:
97
- → diagnosis-only
98
- ```
99
-
100
- The threshold is set per-loop in `VISION.md` (default `0.7`). Flaky/infra/unknown are **never** auto-fixed — they are noise that a loop must not chase, because chasing them is how the Ralph Wiggum loop starts (shipping a guess to make the gate green).
101
-
102
- ## Security Checklist
103
-
104
- Before a loop is allowed to run unattended, confirm every item. A miss is a NO-GO.
105
-
106
- - [ ] **Maker is capability-deprived.** `pi -p --tools read,edit,write,bash,grep,find` — no `push`/`pr`/`slack` in the allowlist. Audit the `--mode json` log: zero ship-tool calls recorded.
107
- - [ ] **Gate is the only ship signal.** Exit 0 → push `loop/<name>/<ts>` branch + PR. Non-zero → no ship, record failure. Never ship to `main`.
108
- - [ ] **Human approves merge/deploy/dependency changes.** The loop opens PRs; a human merges them. Never auto-merge.
109
- - [ ] **Never-do rules enforced.** `loop-guard.ts` blocks bash matching auth/payments/architecture patterns, and protects `VISION.md`, `package.json`, lockfiles, and the gate script from edits.
110
- - [ ] **Dangerous commands blocked when unattended.** `rm -rf`, `sudo`, `chmod 777` are blocked when `!ctx.hasUI` (no UI to confirm).
111
- - [ ] **No secrets in the repo.** API keys via env/CI secrets (`PI_API_KEY`, `GH_TOKEN`), never committed.
112
- - [ ] **Logs sanitized in unattended runs.** No secrets, tokens, or PII in per-run log files.
113
- - [ ] **Idempotent + isolated.** `git worktree` per run (no file collision between parallel loops); `STATE.json.processed[]` skips duplicates; cleanup on pass *and* fail.
114
- - [ ] **Graceful degradation.** Bash orchestrator uses `set -uo pipefail` (NOT `-e`); SDK orchestrator wraps each step in try/catch. A failing loop logs + records + the scheduler moves on — a loop never crashes the scheduler.
115
- - [ ] **Permissions re-audited periodically.** Loop permissions drift; re-check never-do lists and protected paths on a cadence.
116
-
117
- ## The Honest Ceiling
118
-
119
- What loops can and cannot do — stated plainly, because overselling the gate is how loops ship broken work to main.
120
-
121
- - **The exit-code gate does not verify semantic correctness.** It verifies that a command exited 0. A test suite that passes can still encode wrong behaviour (Martin Fowler's "behaviour harness" gap — industry-unsolved). The gate is only as good as the test suite behind it.
122
- - **Structural gaming is mitigated, not eliminated.** `loop-guard.ts` blocks edits to test/gate files, but cannot catch all semantic gaming (e.g. weakening an assertion without touching the gate file). An optional advisory LLM verifier can flag suspicious diffs, but the binding decision remains the exit code.
123
- - **A loop cannot provide judgement it was not given.** Auth, payments, architecture, and "is this the right product decision" stay human. The refuse-list is the honest acknowledgment that some questions are not computable from the project's current state.
124
- - **No live TUI/dashboard.** Observability is logs + `STATE.json` + PR history + `loop-audit` scores. A daemon with a dashboard is explicitly out of scope — compose external schedulers (cron/launchd/GitHub Actions) instead.
125
- - **One loop per orchestrator invocation.** Concurrency is the scheduler's job, not the orchestrator's. Run multiple schedulers for multiple loops.
126
-
127
- If a stakeholder asks "can the loop guarantee the work is correct?", the honest answer is: **no — it guarantees the gate passed, on a branch, reviewed by a human before merge.** That is the contract. Do not promise more.
128
-
129
- ## Verification
130
-
131
- Before claiming a loop is engineered (not just scripted):
132
-
133
- - [ ] `/loop-check <task>` returns GO with a cited condition (or NO-GO with a reason). Refuse-list tasks return NO-GO.
134
- - [ ] `.pi/loops/<name>/VISION.md` has Goal, Scope, Out-of-scope, DoD, Gate, Hard stops, Human-approval-required.
135
- - [ ] `.pi/loops/<name>/STATE.json` is valid JSON with `processed`, `in_progress`, `completed`, `escalated`, `failures`, `lessons`, `metrics`, `last_run`, `stop_conditions_met`.
136
- - [ ] The gate command from `VISION.md` runs via bash and its exit code is the ship signal (parse the `--mode json` log; assert no `push`/`pr`/`slack` tool calls).
137
- - [ ] Failing gate → no PR + `STATE.json` records `failed`; second run on the same item → skipped (idempotent).
138
- - [ ] `loop-audit` returns a numeric score + L0-L3 + ≥1 recommendation; L3 only if a proven committed run exists.
139
- - [ ] Cost: `loop-cost` estimate is within the daily cap; per-run cap in the orchestrator kills an over-budget loop and records the kill in state.
140
-
141
- ## See Also
142
-
143
- | Companion | Role |
144
- |---|---|
145
- | `/loop-check` | NO-GO qualification gate (refuse-list + 2-condition test + 30s checklist) |
146
- | `/loop-init` | Scaffold `.pi/loops/<name>/` from templates |
147
- | `/loop-review` | Maker/checker — verifier runs the gate, cites exit code, defaults to REJECT |
148
- | `loop-audit` | Readiness scoring (0-100 + L0-L3, L3 gated on proven run) |
149
- | `loop-cost` | Token-cost estimation (cadence × blend per level + daily cap + early-exit) |
150
- | `loop-vision.md` / `loop-state.md` / `loop-state.json` | Contract + working memory + dedup ledger templates |
151
- | `loop-orchestrator.ts` / `loop-orchestrator.sh` | Unattended runtime (worktree → restricted maker → gate → ship-on-pass → state → cleanup) |
152
- | `loop-github-action.yml` | CI unattended scheduling (`on: schedule: cron`) |
153
- | `loop-guard.ts` | `tool_call` defense-in-depth (never-do bash + path protection + dangerous-cmd block when `!ctx.hasUI`) |
154
- | `behavioral-kernel` | Re-center on smallest-working-change discipline when authoring loop procedures |
155
- | `defense-in-depth` | Layered-validation patterns the security checklist draws from |
156
-
157
- ## Common Rationalizations
158
-
159
- | Rationalization | Reality |
160
- |---|---|
161
- | "The maker said tests pass" | Opinion is not evidence. Run the gate; read the exit code. |
162
- | "It's just one flaky test, I'll fix it" | Flaky/infra/unknown → diagnosis-only. Chasing noise is the Ralph Wiggum loop. |
163
- | "The loop can probably handle auth if I prompt it well" | Refuse-list. Judgement a loop cannot provide stays human. |
164
- | "We can skip the budget cap, it's a cheap model" | Cost runaway is the second most common loop failure. Estimate with `loop-cost` first. |
165
- | "The gate passing means the work is correct" | The gate means the gate passed. Semantic correctness is the test suite's job, and that gap is industry-unsolved. |
166
-
167
- ## Red Flags
168
-
169
- - A loop that ships on LLM opinion instead of exit code (Ralph Wiggum).
170
- - A loop with no `VISION.md`, or one that isn't reread each run (goal drift incoming).
171
- - A maker with ship tools in its allowlist (capability-deprivation broken).
172
- - A loop that auto-merges PRs (human approval removed).
173
- - A loop fixing flaky/infra/unknown classes (acting without confidence).
174
- - A loop with no budget cap, or one that exceeded cap and wasn't killed.
175
- - An L3 readiness score with no proven committed run (capped at L2 until proven).
@@ -1,162 +0,0 @@
1
- # =============================================================================
2
- # loop-github-action.yml — GitHub Actions workflow for unattended pi loop runs.
3
- #
4
- # Implements FR11 (Scheduling — unattended): a scheduled trigger fires the
5
- # loop-engineering orchestrator headless. The orchestrator runs the MAKER phase
6
- # (`pi -p` with capability-deprivation, --approve/-a auto-trusts project files
7
- # for non-interactive runs, --offline prevents phone-home), an exit-code GATE,
8
- # and ships-on-pass (push `loop/<name>/<ts>` + `gh pr create`).
9
- #
10
- # Self-contained: this workflow uses raw `pi -p` via the shipped orchestrators
11
- # (.pi/templates/loop-orchestrator.ts [T9] or loop-orchestrator.sh [T10]). It
12
- # does NOT hard-depend on any third-party GitHub Action. An optional compose
13
- # with the pi-coding-agent action is documented at the bottom of this file —
14
- # use it only if you prefer the maintained action wrapper over the raw CLI.
15
- #
16
- # PARAMETERIZATION:
17
- # - loop_name (workflow_dispatch input): which loop to run
18
- # (the .pi/loops/<loop_name>/ directory). Defaults to `ci-triage`.
19
- # - cron (workflow_dispatch input): overrides the placeholder schedule
20
- # below for manual/ad-hoc runs. NOTE: workflow_dispatch inputs cannot
21
- # change the `on.schedule` cron of an already-registered workflow — the
22
- # schedule cron is fixed at registration time. To run a different cadence,
23
- # copy this file, change the `on.schedule` cron placeholder, and register
24
- # the new workflow. The `cron` input is documented for clarity and is
25
- # consumed by the run step as `${{ inputs.cron }}` when you wire it into a
26
- # wrapper; here it is surfaced in the step env for downstream tooling.
27
- #
28
- # CRON PLACEHOLDER:
29
- # on.schedule.cron is set to "0 3 * * *" (03:00 UTC daily). Edit this value
30
- # to match the loop's cadence (see .pi/loops/<name>/VISION.md cadence field).
31
- # GitHub Actions cron is UTC and has a best-effort (not exact) fire time.
32
- #
33
- # Secrets required (repo → Settings → Secrets and variables → Actions):
34
- # - PI_API_KEY — the pi API key (provider key). Injected as env PI_API_KEY.
35
- # - GH_TOKEN — (optional) a GitHub PAT with repo + pull-requests scopes.
36
- # If unset, the workflow falls back to the auto-provided
37
- # `GITHUB_TOKEN` (permissions block below grants write).
38
- #
39
- # Requires (installed in the job): Node 24, pi CLI (global), git, gh.
40
- # =============================================================================
41
-
42
- name: loop-run
43
-
44
- # -----------------------------------------------------------------------------
45
- # Triggers
46
- # -----------------------------------------------------------------------------
47
- # schedule.cron is a PLACEHOLDER — edit to match the loop's cadence.
48
- # GitHub Actions cron is UTC, best-effort (may lag minutes).
49
- # workflow_dispatch inputs parameterize loop_name + cron for ad-hoc/manual runs.
50
- on:
51
- schedule:
52
- - cron: "0 3 * * *"
53
- workflow_dispatch:
54
- inputs:
55
- loop_name:
56
- description: "Loop name (the .pi/loops/<loop_name>/ directory to run, e.g. ci-triage)"
57
- required: true
58
- default: "ci-triage"
59
- type: string
60
- cron:
61
- description: "Cadence hint (informational; schedule cron is fixed at registration — copy this file to change cadence). Example: '0 3 * * *'"
62
- required: false
63
- default: "0 3 * * *"
64
- type: string
65
-
66
- # -----------------------------------------------------------------------------
67
- # Permissions — grant write so the orchestrator can push branches + open PRs.
68
- # (FR11 ship-on-pass: push loop/<name>/<ts> + gh pr create.)
69
- # -----------------------------------------------------------------------------
70
- permissions:
71
- contents: write
72
- pull-requests: write
73
-
74
- # A single run per loop at a time — avoid overlap/collision (FR8 worktree
75
- # isolation is per-invocation, but we still avoid duplicate scheduled runs).
76
- concurrency:
77
- group: loop-run-${{ github.event.inputs.loop_name || 'ci-triage' }}
78
- cancel-in-progress: false
79
-
80
- jobs:
81
- loop:
82
- runs-on: ubuntu-latest
83
- timeout-minutes: 30
84
- env:
85
- # Resolve loop name: workflow_dispatch input wins; scheduled runs default.
86
- LOOP_NAME: ${{ github.event.inputs.loop_name || 'ci-triage' }}
87
- PI_API_KEY: ${{ secrets.PI_API_KEY }}
88
- # Prefer a dedicated GH_TOKEN secret if provided; else use GITHUB_TOKEN.
89
- GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
90
- # Surface the cron hint for downstream tooling/logging.
91
- LOOP_CRON: ${{ github.event.inputs.cron || '0 3 * * *' }}
92
- steps:
93
- - name: Checkout
94
- uses: actions/checkout@v4
95
- with:
96
- fetch-depth: 0 # full history for branch + worktree ops
97
-
98
- - name: Setup Node
99
- uses: actions/setup-node@v4
100
- with:
101
- node-version: "24"
102
- # No cache: pi is installed globally, not from package.json.
103
-
104
- - name: Install pi globally
105
- run: npm i -g @earendil-works/pi-coding-agent
106
-
107
- - name: Configure gh CLI auth
108
- env:
109
- GH_TOKEN: ${{ env.GH_TOKEN }}
110
- run: |
111
- # If GH_TOKEN secret was set, use it; otherwise rely on the
112
- # auto-provided GITHUB_TOKEN (permissions block grants write).
113
- if [ -n "$GH_TOKEN" ]; then
114
- echo "$GH_TOKEN" | gh auth login --with-token
115
- else
116
- echo "GH_TOKEN empty — relying on auto-provided GITHUB_TOKEN"
117
- fi
118
- gh auth status || true
119
-
120
- - name: Run loop orchestrator (run-once)
121
- env:
122
- PI_API_KEY: ${{ env.PI_API_KEY }}
123
- GH_TOKEN: ${{ env.GH_TOKEN }}
124
- run: |
125
- set -uo pipefail
126
- echo "::group::loop run-once ${LOOP_NAME} (cadence=${LOOP_CRON})"
127
- # Primary: Node SDK orchestrator (T9) via tsx (plain `node` cannot
128
- # execute TypeScript). Fallback to the portable bash orchestrator
129
- # (T10) if tsx/node module resolution fails.
130
- # --approve/-a auto-trusts project files (required non-interactive).
131
- # --offline prevents phone-home.
132
- if command -v npx >/dev/null 2>&1; then
133
- echo "Running Node orchestrator (loop-orchestrator.ts) via tsx..."
134
- npx --yes tsx .pi/templates/loop-orchestrator.ts run-once "${LOOP_NAME}" . \
135
- || echo "::warning::Node orchestrator exited non-zero (FR10: recorded, not fatal)"
136
- else
137
- echo "npx not found — running bash orchestrator (loop-orchestrator.sh)..."
138
- bash .pi/templates/loop-orchestrator.sh run-once "${LOOP_NAME}" . \
139
- || echo "::warning::Bash orchestrator exited non-zero (FR10: recorded, not fatal)"
140
- fi
141
- echo "::endgroup::"
142
-
143
- # =============================================================================
144
- # OPTIONAL COMPOSE (do NOT hard-depend — kept as a comment only).
145
- # -----------------------------------------------------------------------------
146
- # If you prefer the maintained action wrapper over raw `pi -p`, you can replace
147
- # the "Install pi globally" + "Run loop orchestrator" steps with:
148
- #
149
- # - name: Run pi loop (via action)
150
- # uses: shaftoe/pi-coding-agent-action@v1
151
- # with:
152
- # loop-name: ${{ env.LOOP_NAME }}
153
- # approve: true # -a: auto-trust project files (non-interactive)
154
- # offline: true # --offline: prevent phone-home
155
- # api-key: ${{ secrets.PI_API_KEY }}
156
- # gh-token: ${{ secrets.GH_TOKEN || github.token }}
157
- # run-command: "node .pi/templates/loop-orchestrator.ts run-once ${{ env.LOOP_NAME }} ."
158
- #
159
- # This workflow stays self-contained with raw `pi -p` so it has zero external
160
- # action dependency. Use the compose above only if you accept the external
161
- # dependency and pin a version.
162
- # =============================================================================