pi-plans 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.
@@ -0,0 +1,137 @@
1
+ # State And Config
2
+
3
+ pi-plans stores all planning preferences and run state in the target workspace's git directory as `<git-common-dir>/pi_plans/` — in an ordinary repository this is simply `.git/pi_plans/` — resolving the git common dir with `git rev-parse --git-common-dir` from the workspace. Because the state lives inside the git dir, git never tracks it and no `.gitignore` entries are needed. The target workspace is the current working directory unless the user explicitly names another repository.
4
+
5
+ Do not store pi-plans preferences in Pi's own settings (`~/.pi/agent/settings.json`); pi-plans uses `.git/pi_plans/config.json` for its state.
6
+
7
+ ## State Root Resolution
8
+
9
+ - Git runs with `GIT_DIR`, `GIT_COMMON_DIR`, and `GIT_WORK_TREE` scrubbed from the environment, so leaked env vars cannot misdirect state into an unrelated repository. Relative results (`.git`, `../.git`) resolve against the workdir.
10
+ - Granularity is **per enclosing repository**: running from a subdirectory uses the enclosing repo's git dir (a one-line notice names that repo). Linked worktrees share one common dir; run directories are unique, but `active.json` may race across concurrent worktrees.
11
+ - State does not travel with clones: a fresh clone starts with empty state while committed `./docs/pi-plans/` artifacts persist in the repository.
12
+
13
+ ## Auto Git Init
14
+
15
+ When a mutating state action (`init`, `set-language`, `set-role`, `start-run`, record-*) runs in a workdir that is not a git repository, the helper auto-runs `git init` there (with a one-line notice) and then creates the state dir. It never creates commits. Auto-init runs only when ALL of the following hold:
16
+
17
+ - the workdir has no `.git` entry (a pre-existing `.git` file or directory that git cannot resolve is a fatal error, never a silent reinit);
18
+ - the workdir is not inside any git work tree (a subdirectory of a repo uses the enclosing repo instead);
19
+ - the workdir is neither the user's home directory nor the filesystem root.
20
+
21
+ Bare repositories are refused with a clear error. A missing `git` executable is a clear error. The `show` action is strictly read-only: it never auto-inits or writes.
22
+
23
+ ## Directory Layout
24
+
25
+ ```text
26
+ <git-common-dir>/pi_plans/
27
+ config.json
28
+ active.json
29
+ runs/
30
+ <run-id>/
31
+ run.json
32
+ decisions.jsonl
33
+ subagents.jsonl
34
+ refs.jsonl
35
+ tmp/
36
+ cache/
37
+ ```
38
+
39
+ `config.json` is stable workspace preference state. `active.json` and `runs/` are run state. Large external references stay outside the repository by default under `~/.cache/pi-plans/refs/`, with metadata recorded in the run state and public artifacts.
40
+
41
+ ## Config Schema
42
+
43
+ The default config is:
44
+
45
+ ```json
46
+ {
47
+ "schema": 1,
48
+ "language": { "tag": null, "source": "unset", "updated_at": null },
49
+ "reviewer": {
50
+ "mode": "delegated-subagent",
51
+ "model_selector": null,
52
+ "name_prefix": "pi-plans-reviewer",
53
+ "confirmed_at": null
54
+ },
55
+ "criticizer": {
56
+ "mode": "delegated-subagent",
57
+ "model_selector": null,
58
+ "name_prefix": "pi-plans-criticizer",
59
+ "confirmed_at": null
60
+ },
61
+ "artifact_root": "./docs/pi-plans",
62
+ "artifact_root_source": "unset",
63
+ "artifact_root_updated_at": null
64
+ }
65
+ ```
66
+
67
+ Rules:
68
+
69
+ - `schema` must be `1`.
70
+ - `language.tag` is a BCP47-style tag such as `zh-Hans`, `en`, or `zh-Hant`, or `null` before selection; `language.source` is `user`, `auto`, or `unset`.
71
+ - `reviewer.mode` and `criticizer.mode` are `delegated-subagent` or `current-session`.
72
+ - `model_selector` is `null` to inherit the dispatching session's model, or an exact `provider/model` selector matching Pi's model registry.
73
+ - `confirmed_at` is `null` until the user has confirmed the role's model at first use; see below.
74
+ - `artifact_root` is relative to the target workspace unless absolute.
75
+ - `artifact_root_source` is `user`, `auto`, or `unset`.
76
+ - `artifact_root_updated_at` is the selection timestamp or `null` before confirmation.
77
+ - There is intentionally no `effort` field: subagents inherit the dispatching session's model and thinking level unless an exact selector is stored. The real lever is the main session's thinking level at refine time.
78
+
79
+ ## Language Setting
80
+
81
+ Before the first product planning question, check the persisted config (`plans` action `show`). If `language.tag` is missing or invalid, ask exactly one `ask_choice` question:
82
+
83
+ 1. `zh-Hans` — recommended when more than 60 percent of the user's planning request is Simplified Chinese.
84
+ 2. `en` — recommended when the request is mostly English or mixed without a Chinese majority.
85
+ 3. `zh-Hant` — Traditional Chinese.
86
+ 4. `Other` — user provides a BCP47 tag.
87
+ 5. `Auto-complete` — select the recommended language.
88
+
89
+ Persist with `plans` (`set-language`, `languageSource: "user"`). Use the selected language for visible questions, choices, review summaries, criticizer questions, and Markdown artifacts. Keep IDs, file paths, command names, JSON keys, and protocol labels stable in English.
90
+
91
+ ## Planning Docs Location
92
+
93
+ Before the first product planning question, check the persisted config again. If `artifact_root_source` is missing or `unset`, ask exactly one `ask_choice` question:
94
+
95
+ 1. `./docs/pi-plans` — recommended; planning docs live in the repository and are public.
96
+ 2. `./.git/pi_plans/plans` — private to the repository; not published.
97
+ 3. `Other` — user provides a custom path.
98
+ 4. `Auto-complete` — select the recommended path.
99
+
100
+ Persist with `plans` (`set-artifact-root`, `artifactRoot: <selected path>`, `artifactRootSource: "user"` or `"auto"`). Use the selected path for the run's artifact directory root. This question does not count against the planning-question limit.
101
+
102
+
103
+ Before running a `refine` round, read the role setting from the persisted config.
104
+
105
+ If the role's `mode` is missing or invalid, ask exactly one `ask_choice` question and persist:
106
+
107
+ 1. `Delegated subagent` — recommended; read-only `pi` subprocess with isolated context.
108
+ 2. `Current session` — run the read-only pass in the current foreground session.
109
+ 3. `Other` / 4. `Auto-complete` — select the recommended delegated subagent.
110
+
111
+ Independently, each role's **model** is confirmed once, at that role's first actual use: when `confirmed_at` is `null` and a `refine` round is about to run, ask exactly one `ask_choice` question:
112
+
113
+ 1. `Inherit the main agent's model` — recommended; stores `model_selector: null`.
114
+ 2. `Choose a model` — pick from the models available in this Pi install (check `/model` or `ctx.scopedModels`); persist the exact `provider/model` selector; do not invent model names.
115
+ 3. `Other` / 4. `Auto-complete` — select inherit.
116
+
117
+ Persist with `plans` (`set-role`, `confirmed: true`, `modelSelector: <selector or "inherit">`). `confirmed_at` is set only by this confirmation flow; a mode-only edit never forges or discards a confirmation, and a confirmed inherit (`model_selector: null` plus a stamp) is distinguishable from never-confirmed.
118
+
119
+ If a spawn later fails because the stored selector is unavailable, reset the marker (`set-role`, `resetConfirmation: true`) and re-ask the confirmation question.
120
+
121
+ ## Subagent Spawning
122
+
123
+ When `mode` is `delegated-subagent`, the `refine` tool spawns a read-only `pi` subprocess (`--mode json -p --no-session --tools read,grep,find,ls`) whose system prompt comes from `agents/reviewer.md` or `agents/criticizer.md`. The subagent:
124
+
125
+ - performs read-only analysis and never edits files;
126
+ - receives the full plan text and a review/criticism brief;
127
+ - returns its findings as the tool result (recorded in `subagents.jsonl` with name and model).
128
+
129
+ The main agent consolidates the results, records dispositions, revises the plan, and asks the next refinement-mode question — all in the same turn.
130
+
131
+ ## Run State
132
+
133
+ One run directory per planning request: `<git-common-dir>/pi_plans/runs/<YYYYMMDDTHHMMSSZ-topic>/` (second-precision; `-2`, `-3` suffixes on collision).
134
+
135
+ `run.json` includes: run ID; skill name; original request; target workspace; artifact directory; language tag; status (`planning` → `accepted` → `executing` → `done`, with `stopped`/`abandoned` as exits); timestamps.
136
+
137
+ `decisions.jsonl` is appended automatically by `ask_choice` (question, options, answer, answer source). `subagents.jsonl` records reviewer/criticizer spawns. `refs.jsonl` records reference metadata via `plans` (`record-ref`).
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from "node:child_process";
4
+ import { existsSync, readdirSync } from "node:fs";
5
+ import { join, resolve } from "node:path";
6
+
7
+ const testDir = resolve("tests");
8
+ if (!existsSync(testDir)) {
9
+ console.error(`Missing test directory: ${testDir}`);
10
+ process.exit(1);
11
+ }
12
+
13
+ const tests = readdirSync(testDir)
14
+ .filter((entry) => entry.endsWith(".test.ts"))
15
+ .sort()
16
+ .map((entry) => join(testDir, entry));
17
+
18
+ if (tests.length === 0) {
19
+ console.error(`No test files found in ${testDir}`);
20
+ process.exit(1);
21
+ }
22
+
23
+ const result = spawnSync(process.execPath, ["--experimental-strip-types", "--test", ...tests], {
24
+ stdio: "inherit",
25
+ });
26
+
27
+ if (result.error) {
28
+ throw result.error;
29
+ }
30
+
31
+ process.exit(result.status ?? 1);
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ /** Validate the pi-plans extension structure. */
3
+
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ import * as url from "node:url";
7
+
8
+ const ROOT = path.dirname(path.dirname(url.fileURLToPath(import.meta.url)));
9
+ const SKILL_ROOT = path.join(ROOT, "skills");
10
+ const EXPECTED_SKILLS = new Set([
11
+ "planning",
12
+ "plan-small",
13
+ "plan-normal",
14
+ "plan-big",
15
+ "plan-with-refs",
16
+ "debug-and-plan",
17
+ ]);
18
+ const REQUIRED_REFERENCES = ["pi-planning-workflow.md", "plan-artifact-template.md", "state-and-config.md"];
19
+ const REQUIRED_AGENTS = ["reviewer.md", "criticizer.md"];
20
+ const REQUIRED_TOOL_FILES = [
21
+ "tools/plans.ts",
22
+ "tools/ask-choice.ts",
23
+ "tools/refine.ts",
24
+ "tools/execute-plan.ts",
25
+ "src/state.ts",
26
+ "src/guard.ts",
27
+ "src/plan.ts",
28
+ "src/subagent.ts",
29
+ "src/exec.ts",
30
+ ];
31
+
32
+ const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
33
+
34
+ function fail(message: string): never {
35
+ console.error(message);
36
+ process.exit(1);
37
+ }
38
+
39
+ function parseFrontmatter(text: string, file: string): Map<string, string> {
40
+ if (!text.startsWith("---\n")) fail(`${file}: missing opening frontmatter`);
41
+ const end = text.indexOf("\n---\n", 3);
42
+ if (end < 0) fail(`${file}: missing closing frontmatter`);
43
+ const data = new Map<string, string>();
44
+ for (const line of text.slice(4, end).split("\n")) {
45
+ if (!line.trim()) continue;
46
+ const sep = line.indexOf(":");
47
+ if (sep < 0) fail(`${file}: invalid frontmatter line ${line!}`);
48
+ data.set(line.slice(0, sep).trim(), line.slice(sep + 1).trim());
49
+ }
50
+ return data;
51
+ }
52
+
53
+ function validateSkill(dir: string): void {
54
+ const file = path.join(dir, "SKILL.md");
55
+ if (!fs.existsSync(file)) fail(`missing ${file}`);
56
+ const text = fs.readFileSync(file, "utf8");
57
+ const frontmatter = parseFrontmatter(text, file);
58
+ const name = frontmatter.get("name") ?? "";
59
+ const description = frontmatter.get("description") ?? "";
60
+
61
+ if (name !== path.basename(dir)) fail(`${file}: name ${name!} must match directory ${path.basename(dir)}`);
62
+ if (!NAME_RE.test(name) || name.length > 64) fail(`${file}: invalid skill name`);
63
+ if (!description || description.length > 1024) fail(`${file}: invalid description length`);
64
+ if (!/Use|MUST USE/.test(description)) fail(`${file}: description should include routing language`);
65
+
66
+ const requiredPhrases = ["Auto-complete", "ask_choice", "refine", "language", "reviewer", "criticizer", ".git/pi_plans"];
67
+ for (const phrase of requiredPhrases) {
68
+ if (!text.includes(phrase)) fail(`${file}: missing required phrase ${phrase!}`);
69
+ }
70
+ }
71
+
72
+ function validateDefaultConfig(): void {
73
+ const source = fs.readFileSync(path.join(ROOT, "src", "state.ts"), "utf8");
74
+ if (!source.includes('"pi-plans-reviewer"') || !source.includes('"pi-plans-criticizer"')) {
75
+ fail("src/state.ts: name_prefix defaults missing");
76
+ }
77
+ if (source.includes("effort")) fail("src/state.ts: per-role effort must not exist");
78
+ if (!source.includes('"delegated-subagent"')) fail("src/state.ts: delegated-subagent default missing");
79
+ if (!source.includes('artifact_root: DEFAULT_ARTIFACT_ROOT')) fail("src/state.ts: artifact_root default missing");
80
+ if (!source.includes('artifact_root_source: "unset"')) fail("src/state.ts: artifact_root_source default missing");
81
+ if (!source.includes('artifact_root_updated_at: null')) fail("src/state.ts: artifact_root_updated_at default missing");
82
+ }
83
+
84
+ interface PackageJson {
85
+ private?: boolean;
86
+ keywords?: unknown[];
87
+ publishConfig?: { access?: string };
88
+ pi?: { extensions?: unknown[]; skills?: unknown[] };
89
+ files?: unknown[];
90
+ engines?: { node?: string };
91
+ scripts?: { test?: string; prepack?: string };
92
+ license?: string;
93
+ }
94
+
95
+ function normalizePackageEntry(value: unknown): string {
96
+ return String(value).replace(/\/$/, "");
97
+ }
98
+
99
+ function validatePlansTool(): void {
100
+ const source = fs.readFileSync(path.join(ROOT, "tools", "plans.ts"), "utf8");
101
+ if (!source.includes('"set-artifact-root"')) fail("tools/plans.ts: set-artifact-root action missing");
102
+ if (!source.includes("artifactRootSource")) fail("tools/plans.ts: artifactRootSource parameter missing");
103
+ }
104
+
105
+ function validatePackageMetadata(): void {
106
+ const pkgPath = path.join(ROOT, "package.json");
107
+ let pkg: PackageJson;
108
+ try {
109
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")) as PackageJson;
110
+ } catch (error) {
111
+ fail(`package.json: invalid JSON: ${(error as Error).message}`);
112
+ }
113
+
114
+ if (pkg.private === true) fail("package.json: private must be removed or false for npm publish");
115
+ if (pkg.license !== "MIT") fail("package.json: license must be MIT");
116
+ if (pkg.publishConfig?.access !== "public") fail("package.json: publishConfig.access must be public");
117
+ if (!Array.isArray(pkg.keywords) || !pkg.keywords.map(String).includes("pi-package")) {
118
+ fail("package.json: missing pi-package keyword");
119
+ }
120
+
121
+ const pi = pkg.pi ?? {};
122
+ const extensions = new Set((pi.extensions ?? []).map(normalizePackageEntry));
123
+ const skills = new Set((pi.skills ?? []).map(normalizePackageEntry));
124
+ if (!extensions.has("./index.ts")) fail("package.json: pi.extensions must include ./index.ts");
125
+ if (!skills.has("./skills")) fail("package.json: pi.skills must include ./skills");
126
+
127
+ const files = new Set((pkg.files ?? []).map(normalizePackageEntry));
128
+ for (const required of ["README.md", "LICENSE", "index.ts", "agents", "references", "scripts", "skills", "src", "tests", "tools"]) {
129
+ if (!files.has(required)) fail(`package.json: files must include ${required}`);
130
+ }
131
+
132
+ if (pkg.engines?.node !== ">=22.6") fail("package.json: engines.node must be >=22.6");
133
+ if (pkg.scripts?.test !== "node --experimental-strip-types scripts/run-tests.ts") {
134
+ fail("package.json: test script must use scripts/run-tests.ts");
135
+ }
136
+ if (pkg.scripts?.prepack !== "npm run validate && npm test") {
137
+ fail("package.json: prepack must run validate and test");
138
+ }
139
+ }
140
+
141
+ function main(): void {
142
+ const found = new Set(
143
+ fs
144
+ .readdirSync(SKILL_ROOT, { withFileTypes: true })
145
+ .filter((entry) => entry.isDirectory())
146
+ .map((entry) => entry.name),
147
+ );
148
+ const missing = [...EXPECTED_SKILLS].filter((skill) => !found.has(skill));
149
+ const extra = [...found].filter((skill) => !EXPECTED_SKILLS.has(skill));
150
+ if (missing.length || extra.length) {
151
+ fail(`skill set mismatch; missing=${missing.join(",")} extra=${extra.join(",")}`);
152
+ }
153
+ for (const skill of [...EXPECTED_SKILLS].sort()) {
154
+ validateSkill(path.join(SKILL_ROOT, skill));
155
+ }
156
+
157
+ for (const ref of REQUIRED_REFERENCES) {
158
+ const file = path.join(ROOT, "references", ref);
159
+ if (!fs.existsSync(file)) fail(`missing reference ${ref}`);
160
+ if (!fs.readFileSync(file, "utf8").includes(".git/pi_plans")) {
161
+ fail(`${ref}: missing .git/pi_plans state location`);
162
+ }
163
+ }
164
+
165
+ for (const agent of REQUIRED_AGENTS) {
166
+ const file = path.join(ROOT, "agents", agent);
167
+ if (!fs.existsSync(file)) fail(`missing agent ${agent}`);
168
+ const text = fs.readFileSync(file, "utf8");
169
+ if (!/tools:\s*read/.test(text)) fail(`${agent}: must declare read-only tools`);
170
+ if (!text.includes("read-only")) fail(`${agent}: must state read-only contract`);
171
+ }
172
+
173
+ for (const tool of REQUIRED_TOOL_FILES) {
174
+ if (!fs.existsSync(path.join(ROOT, tool))) fail(`missing ${tool}`);
175
+ }
176
+
177
+ if (!fs.existsSync(path.join(ROOT, "index.ts"))) fail("missing index.ts");
178
+
179
+ validateDefaultConfig();
180
+ validatePlansTool();
181
+ validatePackageMetadata();
182
+ console.log(`validated ${EXPECTED_SKILLS.size} skills, ${REQUIRED_REFERENCES.length} references, ${REQUIRED_AGENTS.length} agents, ${REQUIRED_TOOL_FILES.length} tools`);
183
+ }
184
+
185
+ main();
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: debug-and-plan
3
+ description: Diagnose failures before creating a Pi plan. MUST USE for bugs, CI failures, test failures, regressions, incidents, broken behavior, root cause, RCA, or debug-why requests before deciding whether to plan; preserve language, reviewer, and criticizer settings in `.git/pi_plans/config.json`; exclude ordinary feature planning, direct implementation-only, factual/explanation, trivial command-only, or explicit no-plan requests.
4
+ ---
5
+
6
+ # Debug And Plan
7
+
8
+ Use this skill for problem or failure inputs that need diagnosis before planning.
9
+
10
+ ## Pi Setup
11
+
12
+ Read `../../references/pi-planning-workflow.md` and `../../references/state-and-config.md` — both normative — and follow their setup, state, `language`, and reviewer/criticizer rules. Initialize workspace state with the `plans` tool (`action: "init"`); state lives in `.git/pi_plans/`. Ask every question with the `ask_choice` tool; run refinement rounds with the `refine` tool.
13
+
14
+ ## Diagnostic Workflow
15
+
16
+ 1. Inspect available evidence first: repository files, logs, tests, command output, stack traces, recent diffs, CI output, environment details, and user-provided symptoms.
17
+ 2. Produce an in-message RCA summary before asking whether to plan. Use at most 5 Whys. Stop with `unknown` when evidence is insufficient; do not invent a cause.
18
+ 3. Ask one `ask_choice` question in the configured language whose preamble includes the RCA summary, with these options:
19
+ 1. `Create the scoped fix plan` — recommended when evidence supports a planning path.
20
+ 2. `Stop after RCA` — keep the diagnosis only.
21
+ 3. `Other` / 4. `Auto-complete` are added by the tool.
22
+ 4. On opt-out, stop after the summary; do not write `PROBLEM_ANALYSIS.md`.
23
+ 5. On opt-in (or `Auto-complete` choosing the recommendation), select the smallest fitting planning skill and follow that skill exactly: first-turn planning question, final scope confirmation, `PLAN_v1.md`, refinement, and the execution handoff (ask_choice with `autoComplete: false`, then the `execute_plan` tool).
24
+
25
+ ## Level Selection
26
+
27
+ - `plan-small`: clear root cause, obvious fix shape, few local files, limited risk.
28
+ - `plan-normal`: multi-file fix, external API or dependency behavior, compatibility concerns, or research needed.
29
+ - `plan-big`: cross-system failure, unclear root cause, redesign pressure, or high safety/recoverability risk.
30
+
31
+ Do not ask the user to choose the level unless the evidence supports two materially different planning depths and the tradeoff cannot be resolved from the repo.
32
+
33
+ ## PROBLEM_ANALYSIS.md
34
+
35
+ After opt-in, create the selected planning run's `.git/pi_plans` state and public artifact directory (`plans` action `start-run`), then write `PROBLEM_ANALYSIS.md` before `PLAN_v1.md`. Include: original problem; symptoms and reproduction status; evidence inspected; RCA summary and 5 Whys (ending early with `unknown` when evidence stops); suspected root cause and confidence; planning skill selected and why; language, reviewer, and criticizer settings used; open diagnostic gaps the plan must address. Pass the original problem, RCA summary, evidence, and `PROBLEM_ANALYSIS.md` path into the selected planning skill.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: plan-big
3
+ description: Create a large Pi plan before implementation. Use for open-ended or high-risk repo efforts needing 10 or more planning questions, web research, concurrent reviewer or criticizer refinement, and refinement until convergence; exclude direct implementation-only, factual/explanation, trivial command-only, or explicit no-plan requests.
4
+ ---
5
+
6
+ # Plan Big
7
+
8
+ Use this skill when the user wants a large, high-risk, or open-ended plan before a repository change.
9
+
10
+ ## Pi Setup
11
+
12
+ Read `../../references/pi-planning-workflow.md` and `../../references/state-and-config.md` — both normative — and follow their setup, state, `language`, and reviewer/criticizer rules. Initialize workspace state with the `plans` tool (`action: "init"`); state lives in `.git/pi_plans/`. Ask every question with the `ask_choice` tool; run refinement rounds with the `refine` tool.
13
+
14
+ ## Depth Contract
15
+
16
+ - Inspect the target Git repo read-only before the first product question.
17
+ - Ask at least 10 planning questions, one at a time; no maximum — stop only when the decision tree is genuinely resolved. Each via `ask_choice` (recommended option first; the tool adds `Other` second-last and `Auto-complete` last).
18
+ - Use web research during both brainstorming and refinement when outside facts, patterns, or ecosystem constraints matter, and cite sources in the plan.
19
+ - Ask the final scope confirmation, then write `PLAN_v1.md` per `../../references/plan-artifact-template.md`.
20
+ - After each plan version, ask the refinement-mode question via `ask_choice` — never run `refine` unless the user or `Auto-complete` selected it at that question. Default sequence: one `Reviewer` round as three concurrent independent reviewers (`refine` with `reviewers: 3`, consolidated by the main agent per the shared workflow), then one `Criticizer` round; afterwards the recommended option is `Accept plan for tracked execution`. Beyond the default sequence, refine until convergence on high-priority findings, unresolved questions, or evidence gaps; surface at most five per round. Then the execution handoff (ask_choice with `autoComplete: false`, then the `execute_plan` tool).
21
+
22
+ ## Fit
23
+
24
+ New systems, large feature surfaces, cross-repository or cross-service work, open-ended architecture, safety-sensitive changes, unclear user workflows, or plans whose shape is not yet known. Use `plan-with-refs` instead when external projects, papers, articles, or documentation must be downloaded and studied before planning choices are safe.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: plan-normal
3
+ description: Create a researched Pi plan before implementation. Use for broad or risky repo changes needing 5 to 10 planning questions, web research, reviewer or criticizer refinement, and bounded refinement; exclude direct implementation-only, factual/explanation, trivial command-only, or explicit no-plan requests.
4
+ ---
5
+
6
+ # Plan Normal
7
+
8
+ Use this skill when the user wants a substantive plan before a repository change.
9
+
10
+ ## Pi Setup
11
+
12
+ Read `../../references/pi-planning-workflow.md` and `../../references/state-and-config.md` — both normative — and follow their setup, state, `language`, and reviewer/criticizer rules. Initialize workspace state with the `plans` tool (`action: "init"`); state lives in `.git/pi_plans/`. Ask every question with the `ask_choice` tool; run refinement rounds with the `refine` tool.
13
+
14
+ ## Depth Contract
15
+
16
+ - Inspect the target Git repo read-only before the first product question.
17
+ - Ask 5 to 10 planning questions, one at a time, each via `ask_choice` (recommended option first; the tool adds `Other` second-last and `Auto-complete` last).
18
+ - Use web research whenever outside library behavior, ecosystem precedent, UX convention, protocol semantics, or compatibility affects the recommendation (websearch skill when installed; otherwise `curl`/`gh` via bash), and cite sources in the plan.
19
+ - Ask the final scope confirmation, then write `PLAN_v1.md` per `../../references/plan-artifact-template.md`.
20
+ - After each plan version, ask the refinement-mode question via `ask_choice` — never run `refine` unless the user or `Auto-complete` selected it at that question. Default sequence: one `Reviewer` round, then one `Criticizer` round; afterwards the recommended option is `Accept plan for tracked execution`. Up to five rounds total, continuing only for high-priority findings or unresolved criticizer questions; surface at most five per round. Then the execution handoff (ask_choice with `autoComplete: false`, then the `execute_plan` tool).
21
+
22
+ ## Fit
23
+
24
+ Multi-file changes, architecture boundaries, user-facing workflows, external APIs, dependency upgrades, compatibility risk, or web-evidence-shaped plans. Escalate to `plan-big` when open-ended, cross-system, strategically ambiguous, or likely beyond ten planning decisions.
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: plan-small
3
+ description: Create a small Pi plan before implementation. Use for small scoped repo changes needing 1 to 3 planning questions and one criticizer refinement pass; exclude direct implementation-only, factual/explanation, trivial command-only, or explicit no-plan requests.
4
+ ---
5
+
6
+ # Plan Small
7
+
8
+ Use this skill when the user wants a compact plan before a repository change.
9
+
10
+ ## Pi Setup
11
+
12
+ Read `../../references/pi-planning-workflow.md` and `../../references/state-and-config.md` — both normative — and follow their setup, state, `language`, and reviewer/criticizer rules. Initialize workspace state with the `plans` tool (`action: "init"`); state lives in `.git/pi_plans/`. Ask every question with the `ask_choice` tool; run the refinement round with the `refine` tool.
13
+
14
+ ## Depth Contract
15
+
16
+ - Inspect the target Git repo read-only before the first product question.
17
+ - Ask 1 to 3 planning questions, one at a time, each via `ask_choice` (recommended option first; the tool adds `Other` second-last and `Auto-complete` last).
18
+ - Ask the final scope confirmation, then write `PLAN_v1.md` under the artifact root (normally the configured workspace root, default `./docs/pi-plans/YYYY-MM-DD-topic/`) per `../../references/plan-artifact-template.md`.
19
+ - After each plan version, ask the refinement-mode question via `ask_choice` — never run `refine` unless the user or `Auto-complete` selected it at that question. Default: exactly one round, recommended mode `Criticizer`; afterwards the recommended option is `Accept plan for tracked execution`, then the execution handoff (ask_choice with `autoComplete: false`, then the `execute_plan` tool).
20
+
21
+ ## Fit
22
+
23
+ A few local files, clear ownership, low risk, focused verification. Escalate to `plan-normal` for external API semantics, dependency behavior, compatibility research, cross-module design, or more than three meaningful decisions.
@@ -0,0 +1,30 @@
1
+ ---
2
+ name: plan-with-refs
3
+ description: Research references before creating a Pi plan. Use when repo-change planning needs downloaded projects, articles, papers, docs, per-reference analysis, adoption questions, language settings, and reviewer or criticizer refinement; exclude direct implementation-only, factual/explanation, trivial command-only, or explicit no-plan requests.
4
+ ---
5
+
6
+ # Plan With Refs
7
+
8
+ Use this skill when external references must shape the plan before implementation.
9
+
10
+ ## Pi Setup
11
+
12
+ Read `../../references/pi-planning-workflow.md` and `../../references/state-and-config.md` — both normative — and follow their setup, state, `language`, and reviewer/criticizer rules. Initialize workspace state with the `plans` tool (`action: "init"`); state lives in `.git/pi_plans/`. Ask every question with the `ask_choice` tool; run refinement rounds with the `refine` tool.
13
+
14
+ ## Required Reference Flow
15
+
16
+ 1. Inspect the target Git repo read-only before external research so search terms match the actual codebase and constraints.
17
+ 2. Create the `.git/pi_plans` run state and planning artifact directory once the topic is clear (`plans` action `start-run`).
18
+ 3. Search proactively for related projects, articles, papers, docs, and prior art. Prefer a websearch skill when installed; otherwise use bash tools such as `curl` or `gh` when already available.
19
+ 4. Download or clone at least 3 credible references before writing `PLAN_v1.md`; store large downloads outside the target repo under `~/.cache/pi-plans/refs/<repo-slug>/<topic>/`. Landing pages, README-only snapshots, abstracts, package metadata, or curl-only fragments do not count when deeper source material is available.
20
+ 5. For every reference, record source metadata and local path in `REF_ANALYSIS.md` and in the run's `refs.jsonl` (via `plans` action `record-ref`): title, URL, kind, retrieval method, date accessed, local path, coverage, and evidence gaps.
21
+ 6. For every reference, produce a structured analysis artifact (manual structured read recorded in `REF_ANALYSIS.md`) before asking adoption questions.
22
+ 7. For every reference after analysis, ask at least 3 ref-specific adoption questions via `ask_choice` before using its ideas in `PLAN_v1.md`; each based on downloaded content, recommended option first, `Other` second-last, `Auto-complete` last (the tool appends both).
23
+ 8. Block rather than pad if fewer than 3 credible references exist, unless the user explicitly narrows the topic or waives the minimum. `Auto-complete` cannot grant this waiver.
24
+ 9. Continue with big-plan depth: at least 10 planning questions, required web research during brainstorming and refinement (`refine` `reviewers: 3` reviewer round, then a criticizer round), no refinement limit, at most five high-priority comments or questions per refinement round. Then the execution handoff (ask_choice with `autoComplete: false`, then the `execute_plan` tool).
25
+
26
+ ## REF_ANALYSIS.md
27
+
28
+ Include: original request and repo evidence that shaped the search; attempted queries and selection criteria; references selected and rejected; local download paths; structured analysis summaries; adoption questions and recorded answers; accepted ideas, rejected ideas, and reasons; evidence gaps and user-granted waivers; language, reviewer, and criticizer settings used.
29
+
30
+ Reference ideas are not eligible for `PLAN_v1.md` until their adoption question answers are recorded.
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: planning
3
+ description: General planning router for pi-plans. Use when the user asks for planning and you need to choose the narrowest specialist skill among plan-small, plan-normal, plan-big, debug-and-plan, and plan-with-refs.
4
+ ---
5
+
6
+ # Planning Router
7
+
8
+ Use this skill when a task is planning-related but the right specialist is not obvious yet.
9
+
10
+ ## Routing
11
+
12
+ 1. If the request is a bug, CI failure, regression, incident, or debug-why case, route to `debug-and-plan`.
13
+ 2. If the plan depends on external projects, articles, papers, or docs, route to `plan-with-refs`.
14
+ 3. If the work is open-ended, cross-system, high-risk, or likely beyond ten decisions, route to `plan-big`.
15
+ 4. If the work is broad or risky but bounded, route to `plan-normal`.
16
+ 5. Otherwise route to `plan-small`.
17
+ 6. If multiple skills fit, choose the smallest one that still covers the risk.
18
+ 7. Then follow that skill's instructions exactly.
19
+
20
+ ## Pi Setup
21
+
22
+ Use the same language, `ask_choice`, `refine`, reviewer, criticizer, Auto-complete, and `.git/pi_plans` rules as the selected specialist skill and the shared workflow.