pi-plans 0.1.2 → 0.2.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 +43 -17
- package/index.ts +34 -59
- package/package.json +1 -1
- package/references/pi-planning-workflow.md +6 -3
- package/references/state-and-config.md +1 -1
- package/src/autocomplete.ts +163 -0
- package/src/compaction.ts +502 -0
- package/src/exec.ts +557 -333
- package/src/plan.ts +37 -0
- package/src/query-hook.ts +82 -0
- package/src/refine-ui-helpers.ts +89 -0
- package/src/refine-ui-state.ts +78 -0
- package/src/refine-ui.ts +322 -0
- package/src/state.ts +9 -27
- package/src/subagent.ts +196 -69
- package/tests/autocomplete.test.ts +142 -0
- package/tests/compaction.test.ts +74 -0
- package/tests/exec.test.ts +153 -248
- package/tests/execute-plan.test.ts +65 -0
- package/tests/plan.test.ts +11 -1
- package/tests/plans.test.ts +6 -5
- package/tests/query-hook.test.ts +82 -0
- package/tests/refine-ui.test.ts +127 -0
- package/tests/state.test.ts +12 -15
- package/tests/subagent.test.ts +114 -0
- package/tools/ask-choice.ts +22 -0
- package/tools/execute-plan.ts +7 -39
- package/tools/plans.ts +1 -18
- package/tools/refine.ts +125 -71
- package/src/execution-panel.ts +0 -633
- package/tests/execution-panel.test.ts +0 -234
package/tools/refine.ts
CHANGED
|
@@ -17,6 +17,7 @@ import * as path from "node:path";
|
|
|
17
17
|
import { loadConfig, normalizeWorkdir, readActive, recordSubagent, resolveStateRootOrNull, StateError, type RoleConfig } from "../src/state.ts";
|
|
18
18
|
import { buildCriticizerTask, buildReviewerTask, reviewerLanes } from "../src/refine-prompts.ts";
|
|
19
19
|
import { runPiSubagent, stripFrontmatter } from "../src/subagent.ts";
|
|
20
|
+
import { RefineOverlayController, refineOverlayContext } from "../src/refine-ui.ts";
|
|
20
21
|
|
|
21
22
|
const RefineParams = Type.Object({
|
|
22
23
|
role: StringEnum(["reviewer", "criticizer"] as const, { description: "Refinement role to run" }),
|
|
@@ -46,7 +47,29 @@ function roleGateError(role: string, roleConfig: RoleConfig | undefined, problem
|
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
function setupRefinementExecution(
|
|
51
|
+
ctx: ExtensionContext,
|
|
52
|
+
parentSignal: AbortSignal | undefined,
|
|
53
|
+
role: "reviewer" | "criticizer",
|
|
54
|
+
lanes: Array<{ id: string; label?: string }>,
|
|
55
|
+
) {
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const relayAbort = () => controller.abort();
|
|
58
|
+
if (parentSignal?.aborted) controller.abort();
|
|
59
|
+
else parentSignal?.addEventListener("abort", relayAbort, { once: true });
|
|
49
60
|
|
|
61
|
+
const overlay = ctx.mode === "tui" ? new RefineOverlayController(role, lanes, relayAbort) : undefined;
|
|
62
|
+
overlay?.open(refineOverlayContext(ctx));
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
signal: controller.signal,
|
|
66
|
+
overlay,
|
|
67
|
+
async close() {
|
|
68
|
+
await overlay?.close();
|
|
69
|
+
parentSignal?.removeEventListener("abort", relayAbort);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
50
73
|
|
|
51
74
|
export function registerRefineTool(pi: ExtensionAPI, baseDir: string): void {
|
|
52
75
|
const agentsDir = path.join(baseDir, "agents");
|
|
@@ -119,28 +142,35 @@ export function registerRefineTool(pi: ExtensionAPI, baseDir: string): void {
|
|
|
119
142
|
|
|
120
143
|
if (params.role === "criticizer") {
|
|
121
144
|
const name = `${roleConfig.name_prefix}-criticizer-${Date.now().toString(36)}`;
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
145
|
+
const execution = setupRefinementExecution(ctx, signal, "criticizer", [{ id: name, label: "criticizer" }]);
|
|
146
|
+
try {
|
|
147
|
+
const result = await runPiSubagent({
|
|
148
|
+
systemPrompt,
|
|
149
|
+
task: buildCriticizerTask({ planText, planPath, focus: params.focus, context: params.context }),
|
|
150
|
+
cwd: workdir,
|
|
151
|
+
model,
|
|
152
|
+
signal: execution.signal,
|
|
153
|
+
onProgress: (event) => execution.overlay?.update(name, event),
|
|
154
|
+
});
|
|
155
|
+
execution.overlay?.complete(name, result);
|
|
156
|
+
record(name, result.ok ? result.model ?? model : null);
|
|
157
|
+
if (!result.ok) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`criticizer subagent failed: ${result.errorMessage ?? "unknown error"}${result.stderr ? `\nstderr: ${result.stderr.slice(0, 2000)}` : ""}`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
type: "text",
|
|
166
|
+
text: `${result.output}\n\n---\nAsk each criticizer question with ask_choice (one call per question, in the configured language), record every answer, then revise the plan only after every question has an answer.`,
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
details: { mode: "delegated-subagent", role: params.role, planPath, model: result.model ?? model },
|
|
170
|
+
};
|
|
171
|
+
} finally {
|
|
172
|
+
await execution.close();
|
|
134
173
|
}
|
|
135
|
-
return {
|
|
136
|
-
content: [
|
|
137
|
-
{
|
|
138
|
-
type: "text",
|
|
139
|
-
text: `${result.output}\n\n---\nAsk each criticizer question with ask_choice (one call per question, in the configured language), record every answer, then revise the plan only after every question has an answer.`,
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
details: { mode: "delegated-subagent", role: params.role, planPath, model: result.model ?? model },
|
|
143
|
-
};
|
|
144
174
|
}
|
|
145
175
|
|
|
146
176
|
// Reviewer round: 1 by default, 3 for the big-plan concurrent round.
|
|
@@ -152,62 +182,86 @@ export function registerRefineTool(pi: ExtensionAPI, baseDir: string): void {
|
|
|
152
182
|
return { lane, name, task };
|
|
153
183
|
});
|
|
154
184
|
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return { job, result };
|
|
161
|
-
} catch (error) {
|
|
162
|
-
record(job.name, null);
|
|
163
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
164
|
-
return {
|
|
165
|
-
job,
|
|
166
|
-
result: { ok: false, output: "", model: model ?? undefined, errorMessage: message, stderr: "", turns: 0 },
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
185
|
+
const execution = setupRefinementExecution(
|
|
186
|
+
ctx,
|
|
187
|
+
signal,
|
|
188
|
+
"reviewer",
|
|
189
|
+
jobs.map((job) => ({ id: job.lane.id, label: job.lane.id })),
|
|
170
190
|
);
|
|
191
|
+
try {
|
|
192
|
+
const results = await Promise.all(
|
|
193
|
+
jobs.map(async (job) => {
|
|
194
|
+
try {
|
|
195
|
+
const result = await runPiSubagent({
|
|
196
|
+
systemPrompt,
|
|
197
|
+
task: job.task,
|
|
198
|
+
cwd: workdir,
|
|
199
|
+
model,
|
|
200
|
+
signal: execution.signal,
|
|
201
|
+
onProgress: (event) => execution.overlay?.update(job.lane.id, event),
|
|
202
|
+
});
|
|
203
|
+
execution.overlay?.complete(job.lane.id, result);
|
|
204
|
+
record(job.name, result.ok ? result.model ?? model : null);
|
|
205
|
+
return { job, result };
|
|
206
|
+
} catch (error) {
|
|
207
|
+
record(job.name, null);
|
|
208
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
209
|
+
const result = {
|
|
210
|
+
ok: false,
|
|
211
|
+
output: "",
|
|
212
|
+
model: model ?? undefined,
|
|
213
|
+
errorMessage: message,
|
|
214
|
+
stderr: "",
|
|
215
|
+
turns: 0,
|
|
216
|
+
};
|
|
217
|
+
execution.overlay?.complete(job.lane.id, result);
|
|
218
|
+
return { job, result };
|
|
219
|
+
}
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
171
222
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
223
|
+
const sections: string[] = [];
|
|
224
|
+
let failures = 0;
|
|
225
|
+
for (const { job, result } of results) {
|
|
226
|
+
const title = job.lane.lens ? `${job.name} — ${job.lane.lens}` : job.name;
|
|
227
|
+
if (!result.ok) {
|
|
228
|
+
failures += 1;
|
|
229
|
+
sections.push(`### ${title} — FAILED\n${result.errorMessage ?? "unknown error"}`);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
sections.push(`### ${title}\n${result.output}`);
|
|
233
|
+
}
|
|
234
|
+
if (failures === results.length) {
|
|
235
|
+
const first = results[0];
|
|
236
|
+
throw new Error(
|
|
237
|
+
`all reviewer subagents failed: ${first?.result.errorMessage ?? "unknown error"}${first?.result.stderr ? `\nstderr: ${first.result.stderr.slice(0, 2000)}` : ""}${model ? `\nIf the model selector "${model}" is unavailable, reset the confirmation (plans set-role --reset-confirmation) and re-ask the model-confirmation question.` : ""}`,
|
|
238
|
+
);
|
|
180
239
|
}
|
|
181
|
-
sections.push(`### ${title}\n${result.output}`);
|
|
182
|
-
}
|
|
183
|
-
if (failures === results.length) {
|
|
184
|
-
const first = results[0];
|
|
185
|
-
throw new Error(
|
|
186
|
-
`all reviewer subagents failed: ${first?.result.errorMessage ?? "unknown error"}${first?.result.stderr ? `\nstderr: ${first.result.stderr.slice(0, 2000)}` : ""}${model ? `\nIf the model selector "${model}" is unavailable, reset the confirmation (plans set-role --reset-confirmation) and re-ask the model-confirmation question.` : ""}`,
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
240
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
241
|
+
const combined = sections.join("\n\n---\n\n");
|
|
242
|
+
const truncation = truncateHead(combined, { maxLines: 2000, maxBytes: 50 * 1024 });
|
|
243
|
+
let text = truncation.content;
|
|
244
|
+
if (truncation.truncated) text += `\n\n[Output truncated; full outputs remain in this tool result's details.]`;
|
|
194
245
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
246
|
+
return {
|
|
247
|
+
content: [
|
|
248
|
+
{
|
|
249
|
+
type: "text",
|
|
250
|
+
text: `${text}\n\n---\nConsolidate: merge and dedupe findings into PLAN_vN_reviewer_comments.md${count === 3 ? " (one consolidated file; keep each finding's source reviewer, severity, evidence, and disposition)" : ""}, accept or reject each finding on repo/reference evidence, surface at most five high-priority findings to the user, then immediately ask the next refinement-mode question with ask_choice.`,
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
details: {
|
|
254
|
+
mode: "delegated-subagent",
|
|
255
|
+
role: "reviewer",
|
|
256
|
+
planPath,
|
|
257
|
+
reviewers: count,
|
|
258
|
+
model,
|
|
259
|
+
outputs: results.map(({ job, result }) => ({ name: job.name, lane: job.lane.id, lens: job.lane.lens, ok: result.ok, output: result.output, stderr: result.stderr, turns: result.turns })),
|
|
200
260
|
},
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
planPath,
|
|
206
|
-
reviewers: count,
|
|
207
|
-
model,
|
|
208
|
-
outputs: results.map(({ job, result }) => ({ name: job.name, lane: job.lane.id, lens: job.lane.lens, ok: result.ok, output: result.output, stderr: result.stderr, turns: result.turns })),
|
|
209
|
-
},
|
|
210
|
-
};
|
|
261
|
+
};
|
|
262
|
+
} finally {
|
|
263
|
+
await execution.close();
|
|
264
|
+
}
|
|
211
265
|
},
|
|
212
266
|
|
|
213
267
|
renderCall(args, theme) {
|