A Pi Coding Agent extension that enforces, by code and in strict sequence, an iterative idea-refinement workflow.
Think of it as autoresearch — inspired by the concept Andrej Karpathy popularized — but without the GPU cluster. Instead of training a model, the extension trains the agent itself while it analyzes an idea proposal or problem solution. Each loop forces the agent to develop, critique, and learn from its own output, progressively sharpening its understanding of the problem space.
While it is designed to refine raw ideas into actionable plans, it works just as powerfully for intelligent and convincing problem solving: feed it a bug, an architectural tension, a product decision, or a research question, and the workflow will dissect it, propose alternatives, evaluate them with epistemic rigor, and deliver a prioritized checklist of next steps.
A practical note for users: this procedure is intentionally methodical, so it can take a while depending on the number of loops and the complexity of the subject. It is worth approaching it with a bit of patience — the extension is not trying to answer quickly, but to answer better.
Release 1.11.0 focuses on automatic error recovery and self-healing workflow behavior.
Highlights:
- Provider reasoning field auto-recovery:
runManagedStage()detects when an LLM provider rejects thereasoningfield in messages (common withopencode-goand similar providers), retries the stage with--thinking off, and keeps thinking disabled for the rest of the run. No user intervention required. - Final-stage heading validation retry:
runFinalStages()retries report and checklist generation up to 3 times when required headings are missing. On each retry, the prompt is reinforced with the explicit list of missing headings to guide the LLM toward compliant output. - Stage reset support: Added
markStagePending()tolib/manifest.tsfor clean stage reset during retry flows.
See CHANGELOG.md for full history.
pi install npm:@apolosan/idea-refinementOr for local project installation:
pi install -l npm:@apolosan/idea-refinementnpm install -g @apolosan/idea-refinementThen add it to your Pi settings.json:
{
"packages": ["npm:@apolosan/idea-refinement"]
}- Node.js ≥ 22 (uses
--experimental-strip-types)
- Linux and macOS: Full support, including pause/resume of the Pi subprocess via
SIGSTOP/SIGCONTwhen the runtime exposes POSIX job control to Node child processes. - Windows: POSIX
SIGSTOP/SIGCONTare generally unavailable for Node child processes. Pause/resume shortcuts may not actually suspend the subprocess; prefer letting stages finish or using stop.
This package declares a tested peer range for @mariozechner/pi-coding-agent (>=0.72.0 <1.0.0). Versions outside that range might work, but they are not part of the compatibility promise.
With the /idea-refine command, the extension:
- captures your idea;
- asks how many development loops to run, applying confirmation for runs above 20 loops and refusing values above the hard operational ceiling (1000);
- reuses the current Pi session model and forwards the current thinking level into every workflow subprocess;
- generates the initial artifacts:
DIRECTIVE.mdLEARNING.mdCRITERIA.mdDIAGNOSIS.mdMETRICS.mdBACKLOG.md
- executes, for each loop:
- idea development →
RESPONSE.md - combined critical evaluation + learning update →
FEEDBACK.md,LEARNING.md,BACKLOG.md
- idea development →
- after all loops, consolidates →
REPORT.mdandCHECKLIST.md - stores everything in an isolated directory per invocation;
- displays real-time workflow progress through multiple persistent UI channels:
- console/chat notifications for start, stage transitions, loop completion, pause/resume, stop, and failures;
- current loop and total loops;
- textual loop progress bar;
- current workflow stage;
- active tool being executed;
- total elapsed time;
- animated status spinner maintained by the extension itself.
In Pi, run:
/idea-refine
Or, for a short idea:
/idea-refine I want to validate a platform for AI-assisted technical interviews.
After that, the extension will ask for the number of loops.
Recommendation: choose the loop count with realism in mind. More loops usually mean better refinement, but they also mean more processing time. The extension now asks for explicit confirmation on unusually large loop counts and refuses values above the hard safety limit.
While a workflow is running:
Ctrl+Alt+P→ pause / resume the workflowCtrl+Alt+X→ stop the workflow
Equivalent commands are also available:
/idea-refine-pause/idea-refine-stop/idea-refine-resume
Use:
/idea-refine-resume
or pass the execution index/path directly:
/idea-refine-resume 4
/idea-refine-resume docs/idea_refinement/artifacts_call_04
The resume flow will:
- inspect the failed run and identify the last consistent loop;
- detect the failure category and whether bootstrap artifacts can be reused;
- ask for the new final loop target;
- open an editor prefilled with contextual analysis so you can provide workaround instructions;
- start a new resumed run seeded from the last consistent state.
The standard /idea-refine workflow is not modified by this resume flow.
During execution, the extension:
- publishes important events to the Pi console/chat (
workflow_started, stage start/end, loop completion, pause/resume, stop, failures); - updates a summarized
statusin the footer/working message; - keeps a persistent widget with a checklist of bootstrap, development, evaluation, and learning stages;
- displays the
current toolin use by the invoked subprocess; - shows a textual progress bar of completed loops;
- shows total elapsed runtime;
- maintains an animated spinner in the extension status/widget even while subprocess agents are working.
These messages are emitted through distinct Pi UI channels (setStatus, setWidget, setWorkingMessage, and notify) so that status information remains visible and is not pruned by the agent interface.
Each run creates an exclusive directory:
docs/idea_refinement/artifacts_call_01/
docs/idea_refinement/artifacts_call_02/
...
Generated structure:
docs/idea_refinement/artifacts_call_NN/
├── IDEA.md
├── DIRECTIVE.md
├── LEARNING.md
├── CRITERIA.md
├── DIAGNOSIS.md
├── METRICS.md
├── BACKLOG.md
├── RESPONSE.md # latest version
├── FEEDBACK.md # latest version
├── REPORT.md # final consolidated report
├── CHECKLIST.md # actionable checklist
├── validator-check-output.md # epistemic validation result
├── run.json # structured execution manifest
├── RESUME_CONTEXT.md # present on resumed runs
├── logs/
│ ├── bootstrap.jsonl
│ ├── loop_01_develop.jsonl
│ ├── loop_01_evaluate.jsonl
│ ├── report.jsonl
│ ├── checklist.jsonl
│ └── guard-denials.jsonl
└── loops/
├── loop_01/
│ ├── RESPONSE.md
│ ├── FEEDBACK.md
│ ├── LEARNING.md
│ └── BACKLOG.md
└── loop_02/
└── ...
The extension does not rely on the current agent to orchestrate the process.
It itself:
- generates non-deterministic random numbers via Web Crypto API (CSPRNG with rejection sampling) to guide the workflow;
- uses a virtual/simplified Epsilon-greedy exploration/exploitation strategy (roughly 80/20 optimization vs. exploration) inside a run, using score feedback as a reward signal without claiming persisted local reinforcement-learning state across runs;
- reuses the active Pi model and forwards the current session thinking level into each subprocess invocation;
- spawns its own
pisubprocesses in sequence; - injects stage-specific system prompts;
- captures the final text of each subprocess;
- writes artifacts by code;
- updates
run.jsonthroughout execution; - enforces inactivity timeouts instead of absolute stage deadlines;
- allows pause/resume and stop control for the whole workflow.
The C3 validator now treats ## Minimum alternatives matrix as the only valid scope for alternatives counting. Pipe-formatted rows outside that section no longer satisfy the matrix requirement.
To reduce raw prompt exposure in subprocess argv, the extension sends workflow user prompts through stdin in all stages. This keeps the stage contracts unchanged while making prompt transport lighter and more uniform.
This environment variable is used internally by the extension to protect artifact directories during workflow execution. The artifact-guard.ts constrains subprocess agents to read, bash, and edit, blocks out-of-project reads, blocks absolute-path or out-of-scope ls/tree, blocks historical edits outside the active call, and persists denial audit records in logs/guard-denials.jsonl.
No manual configuration is required — the extension sets it automatically when starting each subprocess.
DIRECTIVE.mdis created once and never overwritten.DIAGNOSIS.md,METRICS.md, andBACKLOG.mdmake refinement more observable, comparable, and auditable.- Each stage subprocess receives an auxiliary extension (
artifact-guard.ts) that blocks directwrite, restricts directory inspection tols/treeinside the active call workspace, blocks historical artifact edits, and records blocked attempts inlogs/guard-denials.jsonl. - Final artifact content is persisted only by the main extension.
- Each loop keeps its own snapshots in
loops/loop_NN/.
- The active session model is reused across all stages.
- The real-time monitor is fed by structured events (
message_update,tool_execution_start,tool_execution_end) emitted by eachpi --mode jsonsubprocess. - Status animation is driven by the parent extension with its own heartbeat instead of depending only on Pi's default working indicator.
- Stage execution uses inactivity timeouts (default 5 minutes) rather than absolute wall-clock deadlines.
- Subprocess agents operate in read-only mode for the project source and can only inspect directories via
bash ls/bash tree. - The initial random number only defines the primary active policy in
DIRECTIVE.md:1-80→OPTIMIZATION81-100→CREATIVITY/EXPLORATION
DIRECTIVE.mdalways includes both policies (OPTIMIZATIONandCREATIVITY/EXPLORATION); the draw only sets which one is marked inSelected Policy.- Each loop's random number is forwarded to the development agent as a contextual seed, without the ability to overwrite the directive.
- The extension is kept modular to facilitate maintenance and testing.
Run local checks with Node 22+:
npm run typecheck
npm test
npm run test:ci
npm run release:checkTests cover:
- loop count parsing;
- next
artifacts_call_NNdetection; - initial artifact marker parsing and
LEARNING.md+BACKLOG.mdupdate parsing; Overall scoreextraction;- artifact path protection and subprocess tool restrictions;
- section-aware C3 validation, including stray-pipe rejection outside the matrix section;
- spawned-subprocess argv baseline capture and full
stdinprompt transport; - inactivity timeout handling;
- pause/resume/stop runtime control;
- elapsed time and animated monitor rendering;
- execution and thinking monitor in real time;
- smoke import of the main extension.
MIT