@ftrdotdev/pi-qrspi 0.1.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 +151 -0
- package/extensions/qrspi-artifacts.ts +331 -0
- package/package.json +53 -0
- package/prompts/qrspi-design.md +68 -0
- package/prompts/qrspi-iterate.md +65 -0
- package/prompts/qrspi-plan.md +105 -0
- package/prompts/qrspi-research.md +65 -0
- package/prompts/qrspi-structure.md +62 -0
- package/prompts/qrspi.md +54 -0
- package/skills/planning-workflow/SKILL.md +77 -0
- package/skills/planning-workflow/templates/design-concept.md +100 -0
- package/skills/planning-workflow/templates/iterate.md +42 -0
- package/skills/planning-workflow/templates/outline.md +79 -0
- package/skills/planning-workflow/templates/plan.md +194 -0
- package/skills/planning-workflow/templates/research.md +88 -0
- package/skills/planning-workflow/templates/session-summary.md +21 -0
- package/skills/tdd/SKILL.md +178 -0
- package/skills/tdd/assets/test-template.md +199 -0
- package/skills/tdd/references/dependency-injection.md +183 -0
- package/skills/tdd/references/test-doubles.md +172 -0
- package/skills/tdd/references/test-patterns.md +215 -0
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# pi-qrspi
|
|
2
|
+
|
|
3
|
+
A planning workflow for [Pi](https://pi.dev) coding agents. The agent works in six phases. You approve each phase before the next one starts. Nothing gets implemented until you approve the plan.
|
|
4
|
+
|
|
5
|
+
## The problem
|
|
6
|
+
|
|
7
|
+
AI agents plan badly when they plan alone. They rush to code. Their designs disappear when the session ends. Their plans drift from the code they describe.
|
|
8
|
+
|
|
9
|
+
QRSPI fixes this. It keeps you in the loop at every step. It writes each phase to a file you can review and commit.
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
QRSPI stands for **Q**uestions → **R**esearch → **D**esign → **S**tructure → **P**lan → **I**terate.
|
|
14
|
+
|
|
15
|
+
Each phase produces an artifact: a file under `.qrspi/` in your project. The next phase reads the artifact from the previous phase.
|
|
16
|
+
|
|
17
|
+
The agent pauses at every checkpoint and asks for your approval. It does not advance until you approve. If you request changes, the agent revises the phase output and shows it to you again. You never approve blind: after each phase writes its artifact, the orchestrator reads the file back and shows you the full content — stamped frontmatter included — before asking for approval.
|
|
18
|
+
|
|
19
|
+
This package is the Pi version of the [opencode-qrspi](https://github.com/felixnorden/skills/tree/main/packages/opencode-qrspi) plugin for OpenCode. Both tools use the same `.qrspi/` artifact format, so you can switch between them without losing your research or plans.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install from npm, git, or a local path:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pi install npm:@ftrdotdev/pi-qrspi
|
|
27
|
+
pi install git:github.com/felixnorden/skills # installs the whole skills repo
|
|
28
|
+
pi install /absolute/path/to/packages/pi-qrspi
|
|
29
|
+
pi install ./packages/pi-qrspi # local checkout
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Install with npm
|
|
33
|
+
|
|
34
|
+
The package is published on the npm registry. If your project already manages dependencies with npm, you can pin the version in your `package.json` and lockfile:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install --save-dev @ftrdotdev/pi-qrspi
|
|
38
|
+
pi install -l ./node_modules/@ftrdotdev/pi-qrspi # run from the project root
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The `pi install -l` command registers the npm-managed copy in your project's `.pi/settings.json`. Pi then loads the prompts, skills, and extension from your project's `node_modules`. Pi asks you to trust the project the first time it loads project packages.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Full workflow
|
|
46
|
+
|
|
47
|
+
Run the complete workflow with one command:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
/qrspi add-payment-flow "Implement Stripe payment processing"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Phase | Command | What it does | Artifact |
|
|
54
|
+
| ----------------- | ------------------ | --------------------------------------------------------------------- | --------------------------- |
|
|
55
|
+
| **Q** — Questions | `/qrspi` | Gathers goals, constraints, and out-of-scope items | none — inline |
|
|
56
|
+
| **R** — Research | `/qrspi-research` | Maps the codebase; documents existing implementations | `.qrspi/research/{slug}.md` |
|
|
57
|
+
| **D** — Design | `/qrspi-design` | Evaluates options; produces a design concept | `.qrspi/designs/{slug}.md` |
|
|
58
|
+
| **S** — Structure | `/qrspi-structure` | Produces a component-level outline | `.qrspi/outlines/{slug}.md` |
|
|
59
|
+
| **P** — Plan | `/qrspi-plan` | Produces a TDD-aligned implementation plan | `.qrspi/plans/{slug}.md` |
|
|
60
|
+
| **I** — Iterate | `/qrspi-iterate` | Revises the plan from your feedback; updates only the affected slices | updates the plan file |
|
|
61
|
+
|
|
62
|
+
### Orchestrated flow
|
|
63
|
+
|
|
64
|
+
`/qrspi` is an orchestrator. It does not draft artifacts itself; each phase runs in a **separate fresh-context subagent**, so exploration and drafting stay out of your main session's context. The orchestrator owns the session: the Q phase, launching one phase agent at a time, relaying your answers to the Design phase, reading each artifact back and presenting it in full at every checkpoint, and producing the session summary.
|
|
65
|
+
|
|
66
|
+
Each phase agent is told exactly what to do: which template to follow, which prior artifacts to read, where to write (`.qrspi/<kind>/<slug>.md`), and what to return (the inline summary plus any open questions). Phase agents never ask you questions directly — they return questions and design options to the orchestrator, which relays them to you.
|
|
67
|
+
|
|
68
|
+
If no subagent capability is available in your environment, `/qrspi` falls back to running phases inline.
|
|
69
|
+
|
|
70
|
+
### Individual phases
|
|
71
|
+
|
|
72
|
+
You can run each phase separately. Arguments are positional:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Research only
|
|
76
|
+
/qrspi-research "Authentication system" auth-refactor
|
|
77
|
+
|
|
78
|
+
# Design from research
|
|
79
|
+
/qrspi-design .qrspi/research/auth-refactor.md auth-refactor
|
|
80
|
+
|
|
81
|
+
# Structure from design
|
|
82
|
+
/qrspi-structure .qrspi/designs/20260101-auth-refactor.md .qrspi/research/auth-refactor.md
|
|
83
|
+
|
|
84
|
+
# Plan from outline and research
|
|
85
|
+
/qrspi-plan .qrspi/outlines/20260101-auth-refactor.md .qrspi/research/auth-refactor.md
|
|
86
|
+
|
|
87
|
+
# Iterate on an existing plan
|
|
88
|
+
/qrspi-iterate .qrspi/plans/20260101-auth-refactor.md "Add OAuth2 support"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The OpenCode plugin uses flags (`--slug`, `--research`, `--design`, `--outline`, `--plan`, `--scope`, `--ticket`) instead of positional arguments.
|
|
92
|
+
|
|
93
|
+
## What's included
|
|
94
|
+
|
|
95
|
+
### Prompt templates
|
|
96
|
+
|
|
97
|
+
Six prompt templates in `prompts/`, one per phase:
|
|
98
|
+
|
|
99
|
+
| Template | Command |
|
|
100
|
+
| ---------------------------- | ------------------------ |
|
|
101
|
+
| `prompts/qrspi.md` | `/qrspi` (full workflow) |
|
|
102
|
+
| `prompts/qrspi-research.md` | `/qrspi-research` |
|
|
103
|
+
| `prompts/qrspi-design.md` | `/qrspi-design` |
|
|
104
|
+
| `prompts/qrspi-structure.md` | `/qrspi-structure` |
|
|
105
|
+
| `prompts/qrspi-plan.md` | `/qrspi-plan` |
|
|
106
|
+
| `prompts/qrspi-iterate.md` | `/qrspi-iterate` |
|
|
107
|
+
|
|
108
|
+
The `/qrspi` orchestrator runs each phase in a fresh subagent session, so earlier phases do not clutter your main session's context. After each phase, the orchestrator reads the artifact back from disk and presents the full content before the checkpoint — what you approve is exactly what was written, including the extension-stamped frontmatter. The phase prompts double as standalone commands; when run standalone they keep their interactive steps (clarify, options, completion gate), and when invoked by the orchestrator they run in orchestrated mode (no direct user interaction; questions relayed through the orchestrator).
|
|
109
|
+
|
|
110
|
+
### Extension
|
|
111
|
+
|
|
112
|
+
`extensions/qrspi-artifacts.ts` keeps artifact names consistent. It intercepts every `write` and `edit` call that targets a path under `.qrspi/`:
|
|
113
|
+
|
|
114
|
+
- **Adds the date** — a filename without a `YYYYMMDD-` prefix gets today's date from the host clock. Write to `.qrspi/plans/add-payment-flow.md` and you get `.qrspi/plans/20260101-add-payment-flow.md`
|
|
115
|
+
- **Fills frontmatter dates** — a `date:` key in the YAML frontmatter of a new artifact is set to the real ISO datetime
|
|
116
|
+
- **Fills git metadata** — `git_commit`, `branch`, and `repository` keys are filled from the repository at `cwd` (the research template requires them)
|
|
117
|
+
- **Slugifies** — `Add Payment Flow.md` becomes `20260101-add-payment-flow.md`; malformed date prefixes (`2026-1-1-…`) are replaced with the canonical form
|
|
118
|
+
- **Keeps existing files** — writes to an existing artifact path are left untouched (used by iterate)
|
|
119
|
+
- **Blocks traversal** — paths that escape `.qrspi/` with `..` are rejected
|
|
120
|
+
|
|
121
|
+
### Skills
|
|
122
|
+
|
|
123
|
+
- **`planning-workflow`** — templates for each phase (research, design-concept, outline, plan, iterate). Enforces two rules: no implementation detail in the design phase, no design decisions in the plan phase.
|
|
124
|
+
- **`tdd`** — test-driven development guidance: red-green-refactor workflow, test doubles, dependency injection, and London/Chicago school mock boundaries.
|
|
125
|
+
|
|
126
|
+
## Artifacts
|
|
127
|
+
|
|
128
|
+
All artifacts live under `.qrspi/` in your project:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
.qrspi/research/ # R
|
|
132
|
+
.qrspi/designs/ # D
|
|
133
|
+
.qrspi/outlines/ # S
|
|
134
|
+
.qrspi/plans/ # P
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Commit these files. Research and plans are project knowledge, not temporary state. Unlike OpenCode's `.opencode/` directory, `.qrspi/` is meant to be shared.
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
The package bundles shared skills from the repo root (`skills/planning-workflow`, `skills/tdd`) through a symlink during development. `npm pack` and `bun pm pack` skip symlinks, so the `prepack` script copies the real skill directories into the tarball. The `postpack` script restores the symlink.
|
|
142
|
+
|
|
143
|
+
The git metadata cache resolves lazily on the first artifact write and caches per working directory for 60 seconds. The orchestrator session and its subagents share the cache, so later writes never re-run git. A bash command that changes git state (`commit`, `checkout`, `rebase`, `pull`, …) resets the cache.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
bun run pack # or: npm pack — builds the tarball into dist/
|
|
147
|
+
bun test # extension + prompt template tests
|
|
148
|
+
bun run typecheck # tsc --noEmit
|
|
149
|
+
bun run lint # oxlint
|
|
150
|
+
bun run fmt:check # oxfmt --check (run bun run fmt to write)
|
|
151
|
+
```
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QRSPI Artifact Enforcement
|
|
3
|
+
*
|
|
4
|
+
* Guards the `.qrspi/` artifact convention at the tool layer, for every
|
|
5
|
+
* `write`/`edit`/`bash` call from the orchestrator session or any subagent:
|
|
6
|
+
*
|
|
7
|
+
* - Paths: `.qrspi/<artifact-dir>/<basename>` is normalized to the canonical
|
|
8
|
+
* `YYYYMMDD-{slug}.md` naming convention, using the host clock so agents
|
|
9
|
+
* cannot hallucinate timestamps. Writes that escape the `.qrspi/` namespace
|
|
10
|
+
* are blocked.
|
|
11
|
+
* - Frontmatter: NEW artifacts get their `date:` and git keys
|
|
12
|
+
* (`git_commit`, `branch`, `repository`) stamped with real values from the
|
|
13
|
+
* host repository. Re-writing an existing artifact (iterate-overwrite)
|
|
14
|
+
* keeps its original date and provenance.
|
|
15
|
+
* - Git metadata is resolved lazily and cached per working directory, so the
|
|
16
|
+
* orchestrator and its subagents share one resolution per session. Bash
|
|
17
|
+
* commands that mutate git state invalidate the cache.
|
|
18
|
+
*
|
|
19
|
+
* Installed as part of the pi-qrspi package via `pi.extensions`.
|
|
20
|
+
*
|
|
21
|
+
* Run `bun test` to exercise the logic (see test/artifact-path.test.ts,
|
|
22
|
+
* test/wiring.test.ts).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { execFile } from "node:child_process";
|
|
26
|
+
import { existsSync } from "node:fs";
|
|
27
|
+
import { resolve } from "node:path";
|
|
28
|
+
import { promisify } from "node:util";
|
|
29
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
30
|
+
|
|
31
|
+
const execFileAsync = promisify(execFile);
|
|
32
|
+
const GIT_TIMEOUT_MS = 3000;
|
|
33
|
+
const GIT_CACHE_TTL_MS = 60_000;
|
|
34
|
+
|
|
35
|
+
/** Artifact subdirectories under `.qrspi/`. */
|
|
36
|
+
const ARTIFACT_DIRS = ["research", "designs", "outlines", "plans"] as const;
|
|
37
|
+
|
|
38
|
+
/** Matches `.qrspi/<artifact-dir>/<basename>` anywhere in a path. */
|
|
39
|
+
const ARTIFACT_PATH_RE = new RegExp(
|
|
40
|
+
`(^|.*[\\\\/])\\.qrspi/(${ARTIFACT_DIRS.join("|")})/([^/\\\\]+)$`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/** Canonical artifact filename: YYYYMMDD-slug.md */
|
|
44
|
+
const CANONICAL_RE = /^\d{8}-[a-z0-9-]+\.md$/;
|
|
45
|
+
|
|
46
|
+
/** Compact date prefix, e.g. 20260101 (7-8 digits, padded or not) */
|
|
47
|
+
const COMPACT_DATE_RE = /^\d{7,8}/;
|
|
48
|
+
|
|
49
|
+
/** Dashed date prefix, e.g. 2026-08-14 or 2026-8-14 */
|
|
50
|
+
const DASHED_DATE_RE = /^\d{4}-\d{1,2}-\d{1,2}/;
|
|
51
|
+
|
|
52
|
+
/** Local-time date stamp in YYYYMMDD form. */
|
|
53
|
+
export function dateStamp(now: Date): string {
|
|
54
|
+
const y = now.getFullYear();
|
|
55
|
+
const m = String(now.getMonth() + 1).padStart(2, "0");
|
|
56
|
+
const d = String(now.getDate()).padStart(2, "0");
|
|
57
|
+
return `${y}${m}${d}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Replace the `date:` value in a leading YAML frontmatter block with the real
|
|
62
|
+
* ISO datetime from the host clock. Only touches an existing `date:` key at
|
|
63
|
+
* line start; content without frontmatter or without a `date:` key is unchanged.
|
|
64
|
+
*/
|
|
65
|
+
export function fixFrontmatterDate(content: string, now: Date): string {
|
|
66
|
+
const fm = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
67
|
+
if (!fm) return content;
|
|
68
|
+
const block = fm[1] ?? "";
|
|
69
|
+
if (!/^date:/m.test(block)) return content;
|
|
70
|
+
const iso = now.toISOString();
|
|
71
|
+
return content.replace(block, block.replace(/^date:.*$/m, `date: ${iso}`));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* True when the content has a YAML frontmatter block containing any of the
|
|
76
|
+
* given line-start keys. Used to avoid spawning git for content that does not
|
|
77
|
+
* carry git metadata keys.
|
|
78
|
+
*/
|
|
79
|
+
export function hasFrontmatterKey(content: string, keys: readonly string[]): boolean {
|
|
80
|
+
const fm = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
81
|
+
if (!fm) return false;
|
|
82
|
+
const block = fm[1] ?? "";
|
|
83
|
+
const pattern = new RegExp(`^(${keys.join("|")}):`, "m");
|
|
84
|
+
return pattern.test(block);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Replace git metadata key values in a leading YAML frontmatter block with
|
|
89
|
+
* real values resolved from the host repository. Only touches existing keys
|
|
90
|
+
* at line start; missing keys are left alone (the template declares them).
|
|
91
|
+
*/
|
|
92
|
+
export function fixFrontmatterGit(content: string, git: GitMetadata): string {
|
|
93
|
+
const fm = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
94
|
+
if (!fm) return content;
|
|
95
|
+
const block = fm[1] ?? "";
|
|
96
|
+
let out = block;
|
|
97
|
+
for (const { prop, key } of FRONTMATTER_GIT_KEYS) {
|
|
98
|
+
const value = git[prop];
|
|
99
|
+
if (value === undefined) continue;
|
|
100
|
+
if (!new RegExp(`^${key}:`, "m").test(out)) continue;
|
|
101
|
+
out = out.replace(new RegExp(`^${key}:.*$`, "m"), `${key}: ${value}`);
|
|
102
|
+
}
|
|
103
|
+
return out === block ? content : content.replace(block, out);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Git metadata for artifact frontmatter, resolved from the host repository. */
|
|
107
|
+
export interface GitMetadata {
|
|
108
|
+
commit?: string;
|
|
109
|
+
branch?: string;
|
|
110
|
+
repository?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** GitMetadata property → YAML frontmatter key (`commit` is `git_commit` in the templates). */
|
|
114
|
+
const FRONTMATTER_GIT_KEYS = [
|
|
115
|
+
{ prop: "commit", key: "git_commit" },
|
|
116
|
+
{ prop: "branch", key: "branch" },
|
|
117
|
+
{ prop: "repository", key: "repository" },
|
|
118
|
+
] as const;
|
|
119
|
+
|
|
120
|
+
async function runGit(cwd: string, args: string[]): Promise<string | undefined> {
|
|
121
|
+
try {
|
|
122
|
+
const { stdout } = await execFileAsync("git", args, {
|
|
123
|
+
cwd,
|
|
124
|
+
timeout: GIT_TIMEOUT_MS,
|
|
125
|
+
});
|
|
126
|
+
return stdout.trim();
|
|
127
|
+
} catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Derive a repo name from a remote URL (e.g. github.com/user/repo.git → repo). */
|
|
133
|
+
export function repositoryNameFromUrl(url: string): string | undefined {
|
|
134
|
+
const cleaned = url.replace(/\.git$/, "").replace(/\/$/, "");
|
|
135
|
+
const name = cleaned.split(/[/:]/).pop();
|
|
136
|
+
return name || undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Resolve real git metadata from the repository at `cwd` (best effort). */
|
|
140
|
+
export async function readGitMetadata(cwd: string): Promise<GitMetadata> {
|
|
141
|
+
const [commit, branch, remoteUrl] = await Promise.all([
|
|
142
|
+
runGit(cwd, ["rev-parse", "HEAD"]),
|
|
143
|
+
runGit(cwd, ["branch", "--show-current"]),
|
|
144
|
+
runGit(cwd, ["remote", "get-url", "origin"]),
|
|
145
|
+
]);
|
|
146
|
+
return {
|
|
147
|
+
commit,
|
|
148
|
+
branch: branch || undefined,
|
|
149
|
+
repository: remoteUrl ? repositoryNameFromUrl(remoteUrl) : undefined,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Per-cwd cache of resolved git metadata.
|
|
155
|
+
*
|
|
156
|
+
* The extension process is shared by the orchestrator session and every
|
|
157
|
+
* subagent it spawns, and `tool_call` carries the writer's own `ctx.cwd`.
|
|
158
|
+
* So the first `.qrspi/` artifact write anywhere in a session populates the
|
|
159
|
+
* cache, and all later writes — including from subagents — reuse it without
|
|
160
|
+
* re-spawning git. Values are fetched lazily on first use.
|
|
161
|
+
*/
|
|
162
|
+
const gitMetadataCache = new Map<string, { meta: GitMetadata; at: number }>();
|
|
163
|
+
|
|
164
|
+
/** Invalidate the cached metadata for one working directory. */
|
|
165
|
+
export function invalidateGitMetadata(cwd: string): void {
|
|
166
|
+
gitMetadataCache.delete(cwd);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Resolve git metadata for `cwd`, using the per-cwd cache within its TTL.
|
|
171
|
+
* Exposed for tests: pass `now` and `fetch` to control time and the fetcher.
|
|
172
|
+
*/
|
|
173
|
+
export async function cachedGitMetadata(
|
|
174
|
+
cwd: string,
|
|
175
|
+
now: () => number = Date.now,
|
|
176
|
+
fetch: (dir: string) => Promise<GitMetadata> = readGitMetadata,
|
|
177
|
+
): Promise<GitMetadata> {
|
|
178
|
+
const at = now();
|
|
179
|
+
const hit = gitMetadataCache.get(cwd);
|
|
180
|
+
if (hit && at - hit.at < GIT_CACHE_TTL_MS) return hit.meta;
|
|
181
|
+
const meta = await fetch(cwd);
|
|
182
|
+
gitMetadataCache.set(cwd, { meta, at });
|
|
183
|
+
return meta;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* git subcommands that can change branch, HEAD, or remote state. Read-only
|
|
188
|
+
* matches are harmless — they only force one re-fetch of the metadata cache.
|
|
189
|
+
*/
|
|
190
|
+
const GIT_MUTATING_VERBS = [
|
|
191
|
+
"commit",
|
|
192
|
+
"merge",
|
|
193
|
+
"rebase",
|
|
194
|
+
"pull",
|
|
195
|
+
"push",
|
|
196
|
+
"fetch",
|
|
197
|
+
"checkout",
|
|
198
|
+
"switch",
|
|
199
|
+
"reset",
|
|
200
|
+
"restore",
|
|
201
|
+
"revert",
|
|
202
|
+
"cherry-pick",
|
|
203
|
+
"tag",
|
|
204
|
+
"stash",
|
|
205
|
+
"clean",
|
|
206
|
+
"gc",
|
|
207
|
+
"remote",
|
|
208
|
+
"submodule",
|
|
209
|
+
"update-ref",
|
|
210
|
+
// `git branch` mutates (create/delete/rename); read-only listings excluded
|
|
211
|
+
"branch(?!\\s*--(?:show-current|list))",
|
|
212
|
+
] as const;
|
|
213
|
+
|
|
214
|
+
const GIT_MUTATION_RE = new RegExp(`\\bgit\\s+(${GIT_MUTATING_VERBS.join("|")})`);
|
|
215
|
+
|
|
216
|
+
/** Lowercase kebab-case slug. */
|
|
217
|
+
export function slugify(input: string): string {
|
|
218
|
+
return input
|
|
219
|
+
.toLowerCase()
|
|
220
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
221
|
+
.replace(/^-+|-+$/g, "");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface NormalizeResult {
|
|
225
|
+
/** Replacement path, when the filename was normalized. */
|
|
226
|
+
path?: string;
|
|
227
|
+
/** Block reason, when the path escapes the `.qrspi/` namespace. */
|
|
228
|
+
block?: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Normalize a file path to the canonical artifact naming convention when it
|
|
233
|
+
* targets `.qrspi/<artifact-dir>/`.
|
|
234
|
+
*
|
|
235
|
+
* Rules:
|
|
236
|
+
* - Non-`.qrspi/` paths, unknown artifact dirs, and non-`.md` files are untouched.
|
|
237
|
+
* - Canonical names (`YYYYMMDD-slug.md`) are untouched.
|
|
238
|
+
* - Existing files are never renamed — iterate-overwrite writes in place.
|
|
239
|
+
* - Missing files get today's date stamp (host clock, local time) and a
|
|
240
|
+
* slugified name, replacing any malformed date prefix the agent invented.
|
|
241
|
+
* - Paths containing `..` inside the `.qrspi/` namespace are blocked.
|
|
242
|
+
*/
|
|
243
|
+
export function normalizeArtifactPath(
|
|
244
|
+
rawPath: string,
|
|
245
|
+
now: Date,
|
|
246
|
+
exists: (path: string) => boolean,
|
|
247
|
+
): NormalizeResult {
|
|
248
|
+
if (rawPath.includes(".qrspi") && rawPath.split(/[\\/]/).includes("..")) {
|
|
249
|
+
return {
|
|
250
|
+
block: `QRSPI artifact path must not traverse outside .qrspi/: ${rawPath}`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const match = rawPath.match(ARTIFACT_PATH_RE);
|
|
255
|
+
if (!match) return {};
|
|
256
|
+
const prefix = match[1] ?? "";
|
|
257
|
+
const kind = match[2] ?? "";
|
|
258
|
+
const basename = match[3] ?? "";
|
|
259
|
+
|
|
260
|
+
if (CANONICAL_RE.test(basename)) return {};
|
|
261
|
+
if (!basename.endsWith(".md")) return {};
|
|
262
|
+
if (exists(rawPath)) return {};
|
|
263
|
+
|
|
264
|
+
const stem = basename
|
|
265
|
+
.replace(/\.md$/, "")
|
|
266
|
+
.replace(COMPACT_DATE_RE, "")
|
|
267
|
+
.replace(DASHED_DATE_RE, "");
|
|
268
|
+
const slug = slugify(stem);
|
|
269
|
+
if (!slug) return {};
|
|
270
|
+
|
|
271
|
+
return { path: `${prefix}.qrspi/${kind}/${dateStamp(now)}-${slug}.md` };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Frontmatter keys the hook stamps with real values on new artifact writes. */
|
|
275
|
+
const FRONTMATTER_STAMP_KEYS = ["date", "git_commit", "branch", "repository"] as const;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Stamp a new artifact's frontmatter in place with the real date and git
|
|
279
|
+
* metadata. Does nothing when the content has no stampable keys.
|
|
280
|
+
*/
|
|
281
|
+
async function stampFrontmatter(input: { content?: unknown }, cwd: string): Promise<void> {
|
|
282
|
+
const content = input.content;
|
|
283
|
+
if (typeof content !== "string") return;
|
|
284
|
+
if (!hasFrontmatterKey(content, FRONTMATTER_STAMP_KEYS)) return;
|
|
285
|
+
const now = new Date();
|
|
286
|
+
const git = await cachedGitMetadata(cwd);
|
|
287
|
+
const fixed = fixFrontmatterGit(fixFrontmatterDate(content, now), git);
|
|
288
|
+
if (fixed !== content) {
|
|
289
|
+
input.content = fixed;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export default function (pi: ExtensionAPI) {
|
|
294
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
295
|
+
// A git-mutating bash command invalidates the cached metadata for this
|
|
296
|
+
// cwd, so the next artifact write re-resolves branch/commit/remote state.
|
|
297
|
+
if (event.toolName === "bash") {
|
|
298
|
+
const command = (event.input as { command?: unknown }).command;
|
|
299
|
+
if (typeof command === "string" && GIT_MUTATION_RE.test(command)) {
|
|
300
|
+
invalidateGitMetadata(ctx.cwd);
|
|
301
|
+
}
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
if (event.toolName !== "write" && event.toolName !== "edit") return undefined;
|
|
305
|
+
|
|
306
|
+
const input = event.input as { path?: unknown; content?: unknown };
|
|
307
|
+
if (typeof input.path !== "string") return undefined;
|
|
308
|
+
const rawPath = input.path;
|
|
309
|
+
|
|
310
|
+
const exists = (p: string) => existsSync(resolve(ctx.cwd, p));
|
|
311
|
+
const result = normalizeArtifactPath(rawPath, new Date(), exists);
|
|
312
|
+
|
|
313
|
+
if (result.block) {
|
|
314
|
+
if (ctx.hasUI) ctx.ui.notify(result.block, "warning");
|
|
315
|
+
return { block: true, reason: result.block };
|
|
316
|
+
}
|
|
317
|
+
if (result.path && result.path !== rawPath) {
|
|
318
|
+
input.path = result.path; // mutate in place — the tool executes with the canonical path
|
|
319
|
+
}
|
|
320
|
+
// Stamp the frontmatter only when creating a NEW .qrspi artifact.
|
|
321
|
+
// Re-writing an existing file (iterate-overwrite) keeps its original
|
|
322
|
+
// date and provenance. `rawPath` is the pre-normalization path — both
|
|
323
|
+
// forms match ARTIFACT_PATH_RE, so the test is valid either way.
|
|
324
|
+
const isNewArtifact =
|
|
325
|
+
event.toolName === "write" && ARTIFACT_PATH_RE.test(rawPath) && !exists(rawPath);
|
|
326
|
+
if (isNewArtifact) {
|
|
327
|
+
await stampFrontmatter(input, ctx.cwd);
|
|
328
|
+
}
|
|
329
|
+
return undefined;
|
|
330
|
+
});
|
|
331
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ftrdotdev/pi-qrspi",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"homepage": "https://github.com/felixnorden/skills/blob/main/packages/pi-qrspi/README.md",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/felixnorden/skills/issues"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/felixnorden/skills.git",
|
|
12
|
+
"path": "packages/pi-qrspi"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"prompts",
|
|
16
|
+
"extensions",
|
|
17
|
+
"skills/planning-workflow",
|
|
18
|
+
"skills/tdd"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"prepack": "rm -rf ./skills && mkdir -p ./skills && cp -R ../../skills/planning-workflow ./skills/ && cp -R ../../skills/tdd ./skills/ && rm -rf ./skills/planning-workflow/skills",
|
|
23
|
+
"postpack": "rm -rf ./skills && ln -s ../../skills ./skills",
|
|
24
|
+
"pack": "bun pm pack --destination ./dist",
|
|
25
|
+
"test": "bun test",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"lint": "oxlint -c oxlint.config.ts",
|
|
28
|
+
"lint:fix": "oxlint -c oxlint.config.ts --fix",
|
|
29
|
+
"fmt": "oxfmt -c oxfmt.config.ts",
|
|
30
|
+
"fmt:check": "oxfmt -c oxfmt.config.ts --check"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"oxfmt": "^0.63.0",
|
|
35
|
+
"oxlint": "^1.78.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@earendil-works/pi-coding-agent": "0.84.1",
|
|
39
|
+
"typescript": ">=6.0.2"
|
|
40
|
+
},
|
|
41
|
+
"pi": {
|
|
42
|
+
"prompts": [
|
|
43
|
+
"./prompts"
|
|
44
|
+
],
|
|
45
|
+
"skills": [
|
|
46
|
+
"./skills/planning-workflow",
|
|
47
|
+
"./skills/tdd"
|
|
48
|
+
],
|
|
49
|
+
"extensions": [
|
|
50
|
+
"./extensions"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: QRSPI Design phase. Turns the research document into a solution design concept with evaluated options, written to `.qrspi/designs/`.
|
|
3
|
+
argument-hint: "<research-path> [slug] [scope-path]"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Load the `planning-workflow` skill → `templates/design-concept.md`.
|
|
7
|
+
|
|
8
|
+
## Arguments
|
|
9
|
+
|
|
10
|
+
- `$1` — research path: path to the research document from the R phase (required).
|
|
11
|
+
- `${2:-}` — slug: session identifier for artifact naming (optional; derive from the research document if absent).
|
|
12
|
+
- `${3:-}` — scope path: path to the scope document (optional; only needed if the research document lacks a scope summary).
|
|
13
|
+
|
|
14
|
+
If `$1` is not provided, ask the user for it before proceeding.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Orchestrated Mode
|
|
19
|
+
|
|
20
|
+
When invoked as a QRSPI phase subagent from `/qrspi`: do not ask the user directly. Return your clarifying questions and the 2–3 design options in your final output; the orchestrator relays the user's direction before you write. Skip the Direction Checkpoint and Completion Gate interactions — the orchestrator runs those. Interactive steps apply only when run standalone.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Role
|
|
25
|
+
|
|
26
|
+
Facilitate solution design discussion, evaluate options, and produce a design concept document. **Architecture and boundaries only — no implementation detail. No file paths, no function names, no pseudo-code, no code blocks.**
|
|
27
|
+
|
|
28
|
+
## Workflow
|
|
29
|
+
|
|
30
|
+
### 1 — Clarify
|
|
31
|
+
|
|
32
|
+
If any requirement is ambiguous, ask the user before proceeding. State the ambiguity, list interpretations, give your recommended interpretation, and ask specific questions. Never assume.
|
|
33
|
+
|
|
34
|
+
### 2 — Read Research Silently
|
|
35
|
+
|
|
36
|
+
Read the research document silently. Do not summarise it back.
|
|
37
|
+
|
|
38
|
+
### 3 — Resolve Ambiguity
|
|
39
|
+
|
|
40
|
+
Identify what is still ambiguous about the solution shape. Ask the user — maximum 3 questions at once. Do not proceed until ambiguities are resolved.
|
|
41
|
+
|
|
42
|
+
### 4 — Evaluate Options
|
|
43
|
+
|
|
44
|
+
Present 2–3 distinct design options. For each state: what it optimises for, what it gives up, and which constraints from the scope it satisfies.
|
|
45
|
+
|
|
46
|
+
### 5 — Direction Checkpoint
|
|
47
|
+
|
|
48
|
+
Ask the user: "Does this direction feel right, or should we adjust?"
|
|
49
|
+
|
|
50
|
+
### 6 — Produce the Design Concept
|
|
51
|
+
|
|
52
|
+
Once direction is agreed, follow `templates/design-concept.md` from the `planning-workflow` skill:
|
|
53
|
+
|
|
54
|
+
- Usually 150–250 lines — no hard minimum or maximum; completeness matters, not length
|
|
55
|
+
- Status remains `draft` until the user confirms approval
|
|
56
|
+
|
|
57
|
+
Write to `<worktree-root>/.qrspi/designs/{slug}.md` (the package extension stamps the `YYYYMMDD-` prefix).
|
|
58
|
+
|
|
59
|
+
### 7 — Completion Gate
|
|
60
|
+
|
|
61
|
+
Ask the user to confirm the design concept is sufficient before proceeding.
|
|
62
|
+
|
|
63
|
+
- If confirmed: finalize and save the document.
|
|
64
|
+
- If not confirmed: revise according to the requested changes, then re-present for confirmation.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
Return the artifact path and a one-paragraph summary of the chosen direction.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: QRSPI Iterate phase. Surgically revises an existing plan based on feedback, updating only the slices the feedback implicates.
|
|
3
|
+
argument-hint: '<plan-path> "<feedback>"'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Load the `planning-workflow` skill → `templates/iterate.md`. Load the `tdd` skill.
|
|
7
|
+
|
|
8
|
+
## Arguments
|
|
9
|
+
|
|
10
|
+
- `$1` — plan path: path to the existing plan to revise (required).
|
|
11
|
+
- `${@:2}` — feedback: the feedback string describing what needs to change (required). Everything after the plan path is joined as one feedback string; quoting is optional but recommended.
|
|
12
|
+
|
|
13
|
+
If `$1` is not provided, ask the user for it.
|
|
14
|
+
If no feedback string is present, ask the user: "What needs to change in the plan?"
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Orchestrated Mode
|
|
19
|
+
|
|
20
|
+
When invoked as a QRSPI phase subagent from `/qrspi`: the feedback arrives in the orchestrator's task, not from the user. Skip Step 1 (Clarify) and the interactive gate — state any assumption explicitly in the revision note and return the revision summary. Interactive steps apply only when run standalone.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Role
|
|
25
|
+
|
|
26
|
+
Surgically revise an existing plan based on feedback. **Update only affected slices — never regenerate the full plan for a partial change.**
|
|
27
|
+
|
|
28
|
+
## Workflow
|
|
29
|
+
|
|
30
|
+
### 1 — Clarify
|
|
31
|
+
|
|
32
|
+
If the plan path or feedback is ambiguous, ask the user before proceeding. Never assume.
|
|
33
|
+
|
|
34
|
+
### 2 — Read Inputs Silently
|
|
35
|
+
|
|
36
|
+
Read the existing plan, outline, and research documents silently. Identify which slices the feedback implicates. State them explicitly before making any changes.
|
|
37
|
+
|
|
38
|
+
### 3 — Design Escalation Check
|
|
39
|
+
|
|
40
|
+
Check whether the feedback implies a **design change** — a change to solution shape, component boundaries, or technology choices. If it does, stop and return:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
This feedback requires a design change. Return to the D phase before revising the plan.
|
|
44
|
+
Reason: {specific design decision affected}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 4 — Revise
|
|
48
|
+
|
|
49
|
+
For each implicated slice, rewrite it completely following `templates/iterate.md` from the `planning-workflow` skill. Leave all other slices verbatim.
|
|
50
|
+
|
|
51
|
+
- If the feedback requires a new slice, add it; do not repurpose an existing slice to absorb new behavior
|
|
52
|
+
- Re-verify any Quality Gate for all modified slices before saving
|
|
53
|
+
- If two or more rounds of iteration have been applied to the same slice, flag it: repeated revision signals a design ambiguity that should be resolved at the D or S phase rather than patched incrementally
|
|
54
|
+
|
|
55
|
+
Add a revision note to the plan header:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Revised: {YYYY-MM-DD} — {one-line summary of what changed}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Write the revised plan to the same path, overwriting the original.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
Return the revision summary and plan path.
|