@ilya-lesikov/pi-pi 0.5.0 → 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.
- package/3p/pi-ask-user/index.ts +65 -49
- package/3p/pi-subagents/src/agent-manager.ts +8 -0
- package/3p/pi-subagents/src/agent-runner.ts +112 -19
- package/3p/pi-subagents/src/index.ts +3 -0
- package/extensions/orchestrator/agents/brainstorm-reviewer.ts +32 -19
- package/extensions/orchestrator/agents/code-reviewer.ts +31 -17
- package/extensions/orchestrator/agents/constraints.ts +55 -0
- package/extensions/orchestrator/agents/explore.ts +13 -13
- package/extensions/orchestrator/agents/librarian.ts +12 -9
- package/extensions/orchestrator/agents/plan-reviewer.ts +31 -19
- package/extensions/orchestrator/agents/planner.ts +28 -23
- package/extensions/orchestrator/agents/registry.ts +2 -1
- package/extensions/orchestrator/agents/repo-context.ts +11 -0
- package/extensions/orchestrator/agents/task.ts +14 -11
- package/extensions/orchestrator/agents/tool-routing.ts +17 -32
- package/extensions/orchestrator/ast-search.ts +2 -1
- package/extensions/orchestrator/cbm.test.ts +35 -0
- package/extensions/orchestrator/cbm.ts +43 -13
- package/extensions/orchestrator/command-handlers.test.ts +390 -19
- package/extensions/orchestrator/command-handlers.ts +68 -28
- package/extensions/orchestrator/commands.test.ts +255 -2
- package/extensions/orchestrator/commands.ts +108 -10
- package/extensions/orchestrator/config.test.ts +289 -68
- package/extensions/orchestrator/config.ts +630 -121
- package/extensions/orchestrator/context.test.ts +177 -10
- package/extensions/orchestrator/context.ts +115 -14
- package/extensions/orchestrator/custom-footer.ts +2 -1
- package/extensions/orchestrator/doctor.test.ts +559 -0
- package/extensions/orchestrator/doctor.ts +664 -0
- package/extensions/orchestrator/event-handlers.test.ts +84 -22
- package/extensions/orchestrator/event-handlers.ts +1177 -341
- package/extensions/orchestrator/exa.test.ts +46 -0
- package/extensions/orchestrator/exa.ts +16 -10
- package/extensions/orchestrator/flant-infra.test.ts +224 -0
- package/extensions/orchestrator/flant-infra.ts +110 -41
- package/extensions/orchestrator/index.ts +13 -2
- package/extensions/orchestrator/integration.test.ts +2866 -118
- package/extensions/orchestrator/log.test.ts +219 -0
- package/extensions/orchestrator/log.ts +153 -0
- package/extensions/orchestrator/model-registry.test.ts +238 -0
- package/extensions/orchestrator/model-registry.ts +282 -0
- package/extensions/orchestrator/model-version.test.ts +27 -0
- package/extensions/orchestrator/model-version.ts +19 -0
- package/extensions/orchestrator/orchestrator.test.ts +206 -56
- package/extensions/orchestrator/orchestrator.ts +287 -140
- package/extensions/orchestrator/phases/brainstorm.test.ts +10 -7
- package/extensions/orchestrator/phases/brainstorm.ts +41 -36
- package/extensions/orchestrator/phases/implementation.ts +7 -11
- package/extensions/orchestrator/phases/machine.test.ts +27 -8
- package/extensions/orchestrator/phases/machine.ts +13 -0
- package/extensions/orchestrator/phases/planning.ts +57 -31
- package/extensions/orchestrator/phases/review-task.ts +3 -7
- package/extensions/orchestrator/phases/review.ts +38 -39
- package/extensions/orchestrator/phases/spawn-blocking.test.ts +69 -0
- package/extensions/orchestrator/phases/verdict.test.ts +139 -0
- package/extensions/orchestrator/phases/verdict.ts +82 -0
- package/extensions/orchestrator/plannotator.test.ts +85 -0
- package/extensions/orchestrator/plannotator.ts +24 -6
- package/extensions/orchestrator/pp-menu.test.ts +134 -0
- package/extensions/orchestrator/pp-menu.ts +2557 -347
- package/extensions/orchestrator/repo-utils.test.ts +151 -0
- package/extensions/orchestrator/repo-utils.ts +67 -0
- package/extensions/orchestrator/spawn-cleanup.test.ts +57 -0
- package/extensions/orchestrator/spawn-cleanup.ts +35 -0
- package/extensions/orchestrator/state.test.ts +76 -6
- package/extensions/orchestrator/state.ts +89 -26
- package/extensions/orchestrator/subagent-session-marker.test.ts +36 -0
- package/extensions/orchestrator/test-helpers.ts +217 -0
- package/extensions/orchestrator/tracer.test.ts +132 -0
- package/extensions/orchestrator/tracer.ts +127 -0
- package/extensions/orchestrator/transition-controller.test.ts +207 -0
- package/extensions/orchestrator/transition-controller.ts +259 -0
- package/extensions/orchestrator/usage-tracker.test.ts +435 -0
- package/extensions/orchestrator/usage-tracker.ts +23 -2
- package/extensions/orchestrator/validate-artifacts.test.ts +83 -1
- package/package.json +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
2
2
|
import { registerEventHandlers } from "./event-handlers.js";
|
|
3
3
|
import { Orchestrator, type ActiveTask } from "./orchestrator.js";
|
|
4
|
+
import { getDefaultConfig } from "./config.js";
|
|
4
5
|
|
|
5
6
|
type Handler = (event: any, ctx: any) => any;
|
|
6
7
|
|
|
@@ -25,30 +26,25 @@ function makePi() {
|
|
|
25
26
|
setSessionName: vi.fn(),
|
|
26
27
|
_handlers: handlers,
|
|
27
28
|
_eventHandlers: eventHandlers,
|
|
29
|
+
// Drive a synthetic lifecycle/session event by invoking the pi.on-registered
|
|
30
|
+
// handler (NOT pi.events.emit, which is only for extension/subagent events).
|
|
31
|
+
emitAgentEnd: (event: any = { type: "agent_end" }, ctx: any = {}) => handlers.get("agent_end")?.(event, ctx),
|
|
32
|
+
emitSessionCompact: (event: any = { type: "session_compact", fromExtension: true }, ctx: any = {}) =>
|
|
33
|
+
handlers.get("session_compact")?.(event, ctx),
|
|
28
34
|
};
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
function makeConfig() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
brainstormReviewers: {},
|
|
43
|
-
agents: {
|
|
44
|
-
explore: { model: "x/e", thinking: "low" },
|
|
45
|
-
librarian: { model: "x/l", thinking: "medium" },
|
|
46
|
-
task: { model: "x/t", thinking: "medium" },
|
|
47
|
-
},
|
|
48
|
-
commands: { afterEdit: [], afterImplement: [] },
|
|
49
|
-
timeouts: { afterEdit: 1, afterImplement: 1, agentSpawn: 1, agentReadyPing: 1, lockStale: 1, lockUpdate: 1 },
|
|
50
|
-
autoCommit: false,
|
|
51
|
-
};
|
|
38
|
+
const config = getDefaultConfig();
|
|
39
|
+
config.general.autoCommit = false;
|
|
40
|
+
config.commands.afterEdit = {};
|
|
41
|
+
config.commands.afterImplement = {};
|
|
42
|
+
config.performance.commands.afterEdit = 1;
|
|
43
|
+
config.performance.commands.afterImplement = 1;
|
|
44
|
+
config.performance.internals.subagentStale = 1;
|
|
45
|
+
config.performance.internals.taskLockStale = 1;
|
|
46
|
+
config.performance.internals.taskLockRefresh = 1;
|
|
47
|
+
return config;
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
function makeActiveTask(): ActiveTask {
|
|
@@ -153,7 +149,7 @@ describe("tool_result implementation tracking", () => {
|
|
|
153
149
|
{ toolName: "write", input: { path: "src/index.ts" }, isError: false, content: [] },
|
|
154
150
|
{},
|
|
155
151
|
);
|
|
156
|
-
expect(orchestrator.active.modifiedFiles.has("src/index.ts")).toBe(true);
|
|
152
|
+
expect(orchestrator.active.modifiedFiles.has("/project/src/index.ts")).toBe(true);
|
|
157
153
|
});
|
|
158
154
|
|
|
159
155
|
it("skips .pp/ paths in modified-file tracking", async () => {
|
|
@@ -186,6 +182,72 @@ describe("tool_result implementation tracking", () => {
|
|
|
186
182
|
{ toolName: "edit", input: { file_path: "src/bar.ts" }, isError: false, content: [] },
|
|
187
183
|
{},
|
|
188
184
|
);
|
|
189
|
-
expect(orchestrator.active.modifiedFiles.has("src/bar.ts")).toBe(true);
|
|
185
|
+
expect(orchestrator.active.modifiedFiles.has("/project/src/bar.ts")).toBe(true);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("ask_user ESC aborts the turn", () => {
|
|
190
|
+
it("aborts the turn when the user cancels (reason 'user')", async () => {
|
|
191
|
+
const handler = getHandler("tool_result");
|
|
192
|
+
const ctx = { abort: vi.fn() };
|
|
193
|
+
await handler(
|
|
194
|
+
{
|
|
195
|
+
toolName: "ask_user",
|
|
196
|
+
input: {},
|
|
197
|
+
isError: false,
|
|
198
|
+
content: [{ type: "text", text: "User cancelled the question" }],
|
|
199
|
+
details: { cancelled: true, response: null, cancelReason: "user" },
|
|
200
|
+
},
|
|
201
|
+
ctx,
|
|
202
|
+
);
|
|
203
|
+
expect(ctx.abort).toHaveBeenCalledTimes(1);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("does NOT abort on a timeout cancellation", async () => {
|
|
207
|
+
const handler = getHandler("tool_result");
|
|
208
|
+
const ctx = { abort: vi.fn() };
|
|
209
|
+
await handler(
|
|
210
|
+
{
|
|
211
|
+
toolName: "ask_user",
|
|
212
|
+
input: {},
|
|
213
|
+
isError: false,
|
|
214
|
+
content: [{ type: "text", text: "User cancelled the question" }],
|
|
215
|
+
details: { cancelled: true, response: null, cancelReason: "timeout" },
|
|
216
|
+
},
|
|
217
|
+
ctx,
|
|
218
|
+
);
|
|
219
|
+
expect(ctx.abort).not.toHaveBeenCalled();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("does NOT abort on a programmatic signal cancellation", async () => {
|
|
223
|
+
const handler = getHandler("tool_result");
|
|
224
|
+
const ctx = { abort: vi.fn() };
|
|
225
|
+
await handler(
|
|
226
|
+
{
|
|
227
|
+
toolName: "ask_user",
|
|
228
|
+
input: {},
|
|
229
|
+
isError: false,
|
|
230
|
+
content: [{ type: "text", text: "User cancelled the question" }],
|
|
231
|
+
details: { cancelled: true, response: null, cancelReason: "signal" },
|
|
232
|
+
},
|
|
233
|
+
ctx,
|
|
234
|
+
);
|
|
235
|
+
expect(ctx.abort).not.toHaveBeenCalled();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("does NOT abort when the user actually answered", async () => {
|
|
239
|
+
const handler = getHandler("tool_result");
|
|
240
|
+
const ctx = { abort: vi.fn() };
|
|
241
|
+
await handler(
|
|
242
|
+
{
|
|
243
|
+
toolName: "ask_user",
|
|
244
|
+
input: {},
|
|
245
|
+
isError: false,
|
|
246
|
+
content: [{ type: "text", text: "User answered: Alpha" }],
|
|
247
|
+
details: { cancelled: false, response: { kind: "selection", selections: ["Alpha"] } },
|
|
248
|
+
},
|
|
249
|
+
ctx,
|
|
250
|
+
);
|
|
251
|
+
expect(ctx.abort).not.toHaveBeenCalled();
|
|
190
252
|
});
|
|
191
253
|
});
|