@ilya-lesikov/pi-pi 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/3p/pi-ask-user/index.ts +1835 -0
- package/3p/pi-ask-user/package.json +50 -0
- package/3p/pi-ask-user/single-select-layout.ts +203 -0
- package/3p/pi-lsp/extensions/lsp/client.ts +542 -0
- package/3p/pi-lsp/extensions/lsp/config.ts +135 -0
- package/3p/pi-lsp/extensions/lsp/effects/command.ts +42 -0
- package/3p/pi-lsp/extensions/lsp/effects/filesystem.ts +50 -0
- package/3p/pi-lsp/extensions/lsp/effects/runtime.ts +21 -0
- package/3p/pi-lsp/extensions/lsp/errors.ts +113 -0
- package/3p/pi-lsp/extensions/lsp/formatting.ts +315 -0
- package/3p/pi-lsp/extensions/lsp/index.ts +231 -0
- package/3p/pi-lsp/extensions/lsp/protocol.ts +209 -0
- package/3p/pi-lsp/extensions/lsp/retry.ts +39 -0
- package/3p/pi-lsp/extensions/lsp/tools/programs.ts +293 -0
- package/3p/pi-lsp/extensions/lsp/tools.ts +89 -0
- package/3p/pi-lsp/extensions/lsp/types.ts +243 -0
- package/3p/pi-lsp/package.json +54 -0
- package/3p/pi-plannotator/AGENTS.md +583 -0
- package/3p/pi-plannotator/apps/pi-extension/README.md +228 -0
- package/3p/pi-plannotator/apps/pi-extension/assistant-message.ts +128 -0
- package/3p/pi-plannotator/apps/pi-extension/config.test.ts +166 -0
- package/3p/pi-plannotator/apps/pi-extension/config.ts +318 -0
- package/3p/pi-plannotator/apps/pi-extension/current-pi-session.ts +147 -0
- package/3p/pi-plannotator/apps/pi-extension/index.ts +1279 -0
- package/3p/pi-plannotator/apps/pi-extension/package.json +56 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.test.ts +13 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.ts +616 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-events.ts +342 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator.json +12 -0
- package/3p/pi-plannotator/apps/pi-extension/server/agent-jobs.ts +515 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ai-runtime.ts +169 -0
- package/3p/pi-plannotator/apps/pi-extension/server/annotations.ts +85 -0
- package/3p/pi-plannotator/apps/pi-extension/server/external-annotations.ts +189 -0
- package/3p/pi-plannotator/apps/pi-extension/server/handlers.ts +210 -0
- package/3p/pi-plannotator/apps/pi-extension/server/helpers.ts +78 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ide.ts +46 -0
- package/3p/pi-plannotator/apps/pi-extension/server/integrations.ts +195 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.test.ts +158 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.ts +268 -0
- package/3p/pi-plannotator/apps/pi-extension/server/pr.ts +126 -0
- package/3p/pi-plannotator/apps/pi-extension/server/project.ts +64 -0
- package/3p/pi-plannotator/apps/pi-extension/server/reference.ts +362 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverAnnotate.ts +199 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverPlan.ts +505 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverReview.ts +1229 -0
- package/3p/pi-plannotator/apps/pi-extension/server/vcs.ts +121 -0
- package/3p/pi-plannotator/apps/pi-extension/server.test.ts +966 -0
- package/3p/pi-plannotator/apps/pi-extension/server.ts +44 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.test.ts +88 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.ts +39 -0
- package/3p/pi-plannotator/apps/pi-extension/tsconfig.json +16 -0
- package/3p/pi-plannotator/apps/pi-extension/vendor.sh +48 -0
- package/3p/pi-plannotator/package.json +53 -0
- package/3p/pi-plannotator/packages/ai/ai.test.ts +1407 -0
- package/3p/pi-plannotator/packages/ai/base-session.ts +94 -0
- package/3p/pi-plannotator/packages/ai/context.ts +250 -0
- package/3p/pi-plannotator/packages/ai/endpoints.ts +326 -0
- package/3p/pi-plannotator/packages/ai/index.ts +105 -0
- package/3p/pi-plannotator/packages/ai/package.json +21 -0
- package/3p/pi-plannotator/packages/ai/provider.ts +103 -0
- package/3p/pi-plannotator/packages/ai/providers/claude-agent-sdk.ts +447 -0
- package/3p/pi-plannotator/packages/ai/providers/codex-sdk.ts +430 -0
- package/3p/pi-plannotator/packages/ai/providers/command-path.ts +115 -0
- package/3p/pi-plannotator/packages/ai/providers/opencode-sdk.ts +546 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-events.ts +110 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk-node.ts +425 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk.ts +469 -0
- package/3p/pi-plannotator/packages/ai/session-manager.ts +195 -0
- package/3p/pi-plannotator/packages/ai/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/ai/types.ts +379 -0
- package/3p/pi-plannotator/packages/server/agent-jobs.ts +538 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.test.ts +135 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.ts +243 -0
- package/3p/pi-plannotator/packages/server/ai-runtime.ts +108 -0
- package/3p/pi-plannotator/packages/server/annotate.ts +401 -0
- package/3p/pi-plannotator/packages/server/browser.test.ts +87 -0
- package/3p/pi-plannotator/packages/server/browser.ts +245 -0
- package/3p/pi-plannotator/packages/server/claude-review.ts +352 -0
- package/3p/pi-plannotator/packages/server/code-nav.ts +73 -0
- package/3p/pi-plannotator/packages/server/codex-review-schema.json +41 -0
- package/3p/pi-plannotator/packages/server/codex-review.ts +330 -0
- package/3p/pi-plannotator/packages/server/config.ts +8 -0
- package/3p/pi-plannotator/packages/server/draft.ts +1 -0
- package/3p/pi-plannotator/packages/server/editor-annotations.ts +76 -0
- package/3p/pi-plannotator/packages/server/external-annotations.test.ts +18 -0
- package/3p/pi-plannotator/packages/server/external-annotations.ts +207 -0
- package/3p/pi-plannotator/packages/server/git.ts +141 -0
- package/3p/pi-plannotator/packages/server/goal-setup.test.ts +55 -0
- package/3p/pi-plannotator/packages/server/goal-setup.ts +248 -0
- package/3p/pi-plannotator/packages/server/ide.ts +43 -0
- package/3p/pi-plannotator/packages/server/image.test.ts +63 -0
- package/3p/pi-plannotator/packages/server/image.ts +66 -0
- package/3p/pi-plannotator/packages/server/index.ts +648 -0
- package/3p/pi-plannotator/packages/server/integrations.test.ts +172 -0
- package/3p/pi-plannotator/packages/server/integrations.ts +214 -0
- package/3p/pi-plannotator/packages/server/jj.test.ts +69 -0
- package/3p/pi-plannotator/packages/server/jj.ts +86 -0
- package/3p/pi-plannotator/packages/server/p4.ts +417 -0
- package/3p/pi-plannotator/packages/server/package.json +40 -0
- package/3p/pi-plannotator/packages/server/path-utils.ts +18 -0
- package/3p/pi-plannotator/packages/server/pr.ts +146 -0
- package/3p/pi-plannotator/packages/server/project.test.ts +115 -0
- package/3p/pi-plannotator/packages/server/project.ts +45 -0
- package/3p/pi-plannotator/packages/server/reference-handlers.ts +404 -0
- package/3p/pi-plannotator/packages/server/remote.test.ts +150 -0
- package/3p/pi-plannotator/packages/server/remote.ts +74 -0
- package/3p/pi-plannotator/packages/server/repo.ts +80 -0
- package/3p/pi-plannotator/packages/server/resolve-file.test.ts +310 -0
- package/3p/pi-plannotator/packages/server/review-workspace.test.ts +1032 -0
- package/3p/pi-plannotator/packages/server/review-workspace.ts +48 -0
- package/3p/pi-plannotator/packages/server/review.ts +1318 -0
- package/3p/pi-plannotator/packages/server/sessions.ts +111 -0
- package/3p/pi-plannotator/packages/server/share-url.ts +53 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.test.ts +43 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.ts +177 -0
- package/3p/pi-plannotator/packages/server/storage.test.ts +176 -0
- package/3p/pi-plannotator/packages/server/storage.ts +17 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.test.ts +146 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.ts +604 -0
- package/3p/pi-plannotator/packages/server/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/server/vcs.test.ts +48 -0
- package/3p/pi-plannotator/packages/server/vcs.ts +80 -0
- package/3p/pi-plannotator/packages/shared/agent-jobs.ts +132 -0
- package/3p/pi-plannotator/packages/shared/agents.ts +53 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.test.ts +386 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.ts +107 -0
- package/3p/pi-plannotator/packages/shared/at-reference.test.ts +99 -0
- package/3p/pi-plannotator/packages/shared/at-reference.ts +52 -0
- package/3p/pi-plannotator/packages/shared/checklist.ts +52 -0
- package/3p/pi-plannotator/packages/shared/code-file.test.ts +112 -0
- package/3p/pi-plannotator/packages/shared/code-file.ts +41 -0
- package/3p/pi-plannotator/packages/shared/code-nav.test.ts +515 -0
- package/3p/pi-plannotator/packages/shared/code-nav.ts +436 -0
- package/3p/pi-plannotator/packages/shared/compress.ts +51 -0
- package/3p/pi-plannotator/packages/shared/config.ts +262 -0
- package/3p/pi-plannotator/packages/shared/crypto.test.ts +172 -0
- package/3p/pi-plannotator/packages/shared/crypto.ts +97 -0
- package/3p/pi-plannotator/packages/shared/data-dir.ts +42 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.test.ts +30 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.ts +137 -0
- package/3p/pi-plannotator/packages/shared/draft.ts +64 -0
- package/3p/pi-plannotator/packages/shared/external-annotation.ts +397 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.test.ts +59 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.ts +66 -0
- package/3p/pi-plannotator/packages/shared/favicon.ts +5 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.test.ts +65 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.ts +29 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.test.ts +231 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.ts +336 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.test.ts +62 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.ts +32 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.test.ts +135 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.ts +115 -0
- package/3p/pi-plannotator/packages/shared/integrations-common.ts +243 -0
- package/3p/pi-plannotator/packages/shared/jj-core.test.ts +236 -0
- package/3p/pi-plannotator/packages/shared/jj-core.ts +433 -0
- package/3p/pi-plannotator/packages/shared/package.json +55 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.test.ts +88 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.ts +80 -0
- package/3p/pi-plannotator/packages/shared/pr-github.ts +661 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.test.ts +202 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.ts +620 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.test.ts +266 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.ts +123 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.test.ts +104 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.ts +194 -0
- package/3p/pi-plannotator/packages/shared/pr-types.ts +326 -0
- package/3p/pi-plannotator/packages/shared/project.ts +71 -0
- package/3p/pi-plannotator/packages/shared/prompts-integration.test.ts +421 -0
- package/3p/pi-plannotator/packages/shared/prompts.test.ts +504 -0
- package/3p/pi-plannotator/packages/shared/prompts.ts +247 -0
- package/3p/pi-plannotator/packages/shared/reference-common.ts +87 -0
- package/3p/pi-plannotator/packages/shared/repo.ts +71 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.test.ts +113 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.ts +509 -0
- package/3p/pi-plannotator/packages/shared/review-args.test.ts +64 -0
- package/3p/pi-plannotator/packages/shared/review-args.ts +85 -0
- package/3p/pi-plannotator/packages/shared/review-core.test.ts +286 -0
- package/3p/pi-plannotator/packages/shared/review-core.ts +895 -0
- package/3p/pi-plannotator/packages/shared/review-workspace-node.ts +230 -0
- package/3p/pi-plannotator/packages/shared/review-workspace.ts +436 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff-types.ts +76 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.test.ts +322 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.ts +520 -0
- package/3p/pi-plannotator/packages/shared/storage.ts +378 -0
- package/3p/pi-plannotator/packages/shared/tour.ts +61 -0
- package/3p/pi-plannotator/packages/shared/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/shared/types.ts +29 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.test.ts +177 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.ts +351 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.test.ts +332 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.ts +482 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.test.ts +162 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.ts +103 -0
- package/3p/pi-plannotator/packages/shared/worktree.ts +119 -0
- package/3p/pi-subagents/package.json +50 -0
- package/3p/pi-subagents/src/agent-manager.ts +413 -0
- package/3p/pi-subagents/src/agent-runner.ts +502 -0
- package/3p/pi-subagents/src/agent-types.ts +248 -0
- package/3p/pi-subagents/src/context.ts +58 -0
- package/3p/pi-subagents/src/cross-extension-rpc.ts +135 -0
- package/3p/pi-subagents/src/custom-agents.ts +137 -0
- package/3p/pi-subagents/src/default-agents.ts +144 -0
- package/3p/pi-subagents/src/env.ts +33 -0
- package/3p/pi-subagents/src/group-join.ts +141 -0
- package/3p/pi-subagents/src/index.ts +1811 -0
- package/3p/pi-subagents/src/invocation-config.ts +40 -0
- package/3p/pi-subagents/src/memory.ts +165 -0
- package/3p/pi-subagents/src/model-resolver.ts +81 -0
- package/3p/pi-subagents/src/output-file.ts +77 -0
- package/3p/pi-subagents/src/prompts.ts +85 -0
- package/3p/pi-subagents/src/skill-loader.ts +79 -0
- package/3p/pi-subagents/src/types.ts +111 -0
- package/3p/pi-subagents/src/ui/agent-widget.ts +496 -0
- package/3p/pi-subagents/src/ui/conversation-viewer.ts +250 -0
- package/3p/pi-subagents/src/worktree.ts +162 -0
- package/3p/pi-tasks/package.json +52 -0
- package/3p/pi-tasks/src/auto-clear.ts +91 -0
- package/3p/pi-tasks/src/index.ts +1150 -0
- package/3p/pi-tasks/src/process-tracker.ts +140 -0
- package/3p/pi-tasks/src/reminder-cadence.ts +90 -0
- package/3p/pi-tasks/src/task-store.ts +324 -0
- package/3p/pi-tasks/src/tasks-config.ts +27 -0
- package/3p/pi-tasks/src/types.ts +40 -0
- package/3p/pi-tasks/src/ui/settings-menu.ts +152 -0
- package/3p/pi-tasks/src/ui/task-widget.ts +296 -0
- package/AGENTS.md +28 -0
- package/LICENSE +201 -0
- package/extensions/orchestrator/agents/brainstorm-reviewer.ts +77 -0
- package/extensions/orchestrator/agents/code-reviewer.ts +89 -0
- package/extensions/orchestrator/agents/explore.ts +33 -0
- package/extensions/orchestrator/agents/librarian.ts +43 -0
- package/extensions/orchestrator/agents/plan-reviewer.ts +75 -0
- package/extensions/orchestrator/agents/planner.ts +61 -0
- package/extensions/orchestrator/agents/registry.ts +156 -0
- package/extensions/orchestrator/agents/task.ts +50 -0
- package/extensions/orchestrator/agents/tool-routing.ts +84 -0
- package/extensions/orchestrator/ast-search.ts +85 -0
- package/extensions/orchestrator/cbm.ts +330 -0
- package/extensions/orchestrator/command-handlers.test.ts +163 -0
- package/extensions/orchestrator/command-handlers.ts +116 -0
- package/extensions/orchestrator/commands.test.ts +81 -0
- package/extensions/orchestrator/commands.ts +75 -0
- package/extensions/orchestrator/config.test.ts +221 -0
- package/extensions/orchestrator/config.ts +230 -0
- package/extensions/orchestrator/context.test.ts +293 -0
- package/extensions/orchestrator/context.ts +206 -0
- package/extensions/orchestrator/event-handlers.test.ts +190 -0
- package/extensions/orchestrator/event-handlers.ts +1416 -0
- package/extensions/orchestrator/exa.ts +104 -0
- package/extensions/orchestrator/flant-infra.ts +486 -0
- package/extensions/orchestrator/index.ts +80 -0
- package/extensions/orchestrator/integration.test.ts +1214 -0
- package/extensions/orchestrator/orchestrator.test.ts +252 -0
- package/extensions/orchestrator/orchestrator.ts +538 -0
- package/extensions/orchestrator/phases/brainstorm.test.ts +15 -0
- package/extensions/orchestrator/phases/brainstorm.ts +273 -0
- package/extensions/orchestrator/phases/implementation.ts +40 -0
- package/extensions/orchestrator/phases/machine.test.ts +293 -0
- package/extensions/orchestrator/phases/machine.ts +209 -0
- package/extensions/orchestrator/phases/planning.ts +255 -0
- package/extensions/orchestrator/phases/review.ts +193 -0
- package/extensions/orchestrator/plannotator.ts +56 -0
- package/extensions/orchestrator/pp-menu.ts +866 -0
- package/extensions/orchestrator/state.test.ts +343 -0
- package/extensions/orchestrator/state.ts +237 -0
- package/extensions/orchestrator/validate-artifacts.test.ts +88 -0
- package/extensions/orchestrator/validate-artifacts.ts +272 -0
- package/extensions/orchestrator/vendor.d.ts +26 -0
- package/package.json +73 -0
- package/scripts/postinstall.sh +18 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { TOOL_ROUTING, ALL_CBM_TOOLS, EXA_TOOLS, WORKING_PRINCIPLES_READONLY, COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createBrainstormReviewerAgent(
|
|
5
|
+
variant: string,
|
|
6
|
+
config: PiPiConfig,
|
|
7
|
+
taskArtifacts: { userRequest: string; research: string; artifacts?: { name: string; content: string }[] },
|
|
8
|
+
outputPath: string,
|
|
9
|
+
) {
|
|
10
|
+
const variantConfig = config.brainstormReviewers[variant];
|
|
11
|
+
if (!variantConfig) {
|
|
12
|
+
throw new Error(`Unknown brainstorm-reviewer variant: ${variant}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
frontmatter: {
|
|
17
|
+
description: `Brainstorm reviewer (${variant} variant, pi-pi)`,
|
|
18
|
+
tools: `read, grep, find, bash, write, lsp, ast_search, ${ALL_CBM_TOOLS}, ${EXA_TOOLS}`,
|
|
19
|
+
model: variantConfig.model,
|
|
20
|
+
thinking: variantConfig.thinking,
|
|
21
|
+
max_turns: variantConfig.maxTurns ?? 120,
|
|
22
|
+
prompt_mode: "replace",
|
|
23
|
+
},
|
|
24
|
+
prompt: [
|
|
25
|
+
"You are a research reviewer. Your job is to verify the thoroughness and accuracy of brainstorm research artifacts.",
|
|
26
|
+
"",
|
|
27
|
+
"You are a GAP-FINDER, not a perfectionist.",
|
|
28
|
+
"Approve by default. Reject only for critical gaps — maximum 3.",
|
|
29
|
+
"",
|
|
30
|
+
WORKING_PRINCIPLES_READONLY,
|
|
31
|
+
"",
|
|
32
|
+
COMMUNICATION,
|
|
33
|
+
"",
|
|
34
|
+
TOOL_ROUTING,
|
|
35
|
+
"",
|
|
36
|
+
"# Your job:",
|
|
37
|
+
"1. Read USER_REQUEST.md and RESEARCH.md provided below",
|
|
38
|
+
"2. INDEPENDENTLY investigate the codebase to verify claims and find gaps",
|
|
39
|
+
"3. Check whether the research is thorough enough for a planner to work without re-exploring",
|
|
40
|
+
"",
|
|
41
|
+
"# Review criteria:",
|
|
42
|
+
"- Completeness: are all affected code paths identified? Any missed callers/callees?",
|
|
43
|
+
"- Accuracy: do the architecture claims match what you find in the code?",
|
|
44
|
+
"- Constraints: are there edge cases or hard requirements the researcher missed?",
|
|
45
|
+
"- Separation: does USER_REQUEST.md contain only user-stated info (no agent findings leaked in)?",
|
|
46
|
+
"- Structure: do both files follow the required format?",
|
|
47
|
+
"",
|
|
48
|
+
"# Format your review as:",
|
|
49
|
+
"- GAPS: (missing information that would block planning)",
|
|
50
|
+
"- INACCURACIES: (claims that don't match the code)",
|
|
51
|
+
"- SUGGESTIONS: (improvements, not required)",
|
|
52
|
+
"- VERDICT: APPROVE or NEEDS_WORK (with reason)",
|
|
53
|
+
"",
|
|
54
|
+
'You can spawn subagents: Agent(subagent_type="Explore", ...) for codebase, Agent(subagent_type="Librarian", ...) for external docs.',
|
|
55
|
+
"",
|
|
56
|
+
"# MANDATORY: Write your review to this exact file using the write tool:",
|
|
57
|
+
` ${outputPath}`,
|
|
58
|
+
"",
|
|
59
|
+
"Your task is NOT complete until this file exists. Do NOT finish without writing it.",
|
|
60
|
+
"You MUST NOT write to any other file. Only write .md files inside .pp/state/.",
|
|
61
|
+
"",
|
|
62
|
+
"=== USER REQUEST ===",
|
|
63
|
+
taskArtifacts.userRequest,
|
|
64
|
+
"",
|
|
65
|
+
"=== RESEARCH ===",
|
|
66
|
+
taskArtifacts.research,
|
|
67
|
+
...(taskArtifacts.artifacts && taskArtifacts.artifacts.length > 0
|
|
68
|
+
? [
|
|
69
|
+
"",
|
|
70
|
+
...taskArtifacts.artifacts.flatMap((a) => [`=== ${a.name} ===`, a.content, ""]),
|
|
71
|
+
]
|
|
72
|
+
: []),
|
|
73
|
+
"",
|
|
74
|
+
"The artifacts above are already in your context. Do NOT re-read them from disk.",
|
|
75
|
+
].join("\n"),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { TOOL_ROUTING, ALL_CBM_TOOLS, EXA_TOOLS, WORKING_PRINCIPLES_READONLY, COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createCodeReviewerAgent(
|
|
5
|
+
variant: string,
|
|
6
|
+
config: PiPiConfig,
|
|
7
|
+
taskArtifacts: { userRequest: string; research: string; synthesizedPlan: string },
|
|
8
|
+
outputPath: string,
|
|
9
|
+
) {
|
|
10
|
+
const variantConfig = config.codeReviewers[variant];
|
|
11
|
+
if (!variantConfig) {
|
|
12
|
+
throw new Error(`Unknown code-reviewer variant: ${variant}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
frontmatter: {
|
|
17
|
+
description: `Code reviewer (${variant} variant, pi-pi)`,
|
|
18
|
+
tools: `read, grep, find, ls, bash, write, lsp, ast_search, ${ALL_CBM_TOOLS}, ${EXA_TOOLS}`,
|
|
19
|
+
model: variantConfig.model,
|
|
20
|
+
thinking: variantConfig.thinking,
|
|
21
|
+
max_turns: variantConfig.maxTurns ?? 120,
|
|
22
|
+
prompt_mode: "replace",
|
|
23
|
+
},
|
|
24
|
+
prompt: [
|
|
25
|
+
// --- static prefix (cacheable) ---
|
|
26
|
+
"You are a code reviewer. Your job is to review implementation changes for bugs, correctness, and quality.",
|
|
27
|
+
"",
|
|
28
|
+
WORKING_PRINCIPLES_READONLY,
|
|
29
|
+
"",
|
|
30
|
+
COMMUNICATION,
|
|
31
|
+
"",
|
|
32
|
+
TOOL_ROUTING,
|
|
33
|
+
"",
|
|
34
|
+
"Steps:",
|
|
35
|
+
'1. Run `git diff` to see all changes (try HEAD~1, main, or appropriate base)',
|
|
36
|
+
"2. Run cbm_changes to understand symbol-level impact and blast radius",
|
|
37
|
+
"3. Read changed files for full context",
|
|
38
|
+
"4. Run lsp diagnostics on changed files",
|
|
39
|
+
"5. Use lsp findReferences to check callers of modified functions",
|
|
40
|
+
"6. Check the implementation against the plan",
|
|
41
|
+
"",
|
|
42
|
+
"Review criteria:",
|
|
43
|
+
"- Bugs: logic errors, off-by-ones, null handling, race conditions",
|
|
44
|
+
"- Correctness: does it match the plan and user request?",
|
|
45
|
+
"- Quality: error handling, edge cases, type safety",
|
|
46
|
+
"- Missing: untested paths, unhandled errors, incomplete implementations",
|
|
47
|
+
"",
|
|
48
|
+
"Evidence requirements:",
|
|
49
|
+
"- Every CRITICAL or MAJOR finding MUST cite file:line or backtick-quoted code",
|
|
50
|
+
"- Never assert a problem without reading the actual code first",
|
|
51
|
+
"- If you can't prove it with evidence, move it to Open Questions",
|
|
52
|
+
"",
|
|
53
|
+
"Perspectives to check:",
|
|
54
|
+
"- As a new hire: could someone unfamiliar follow these changes?",
|
|
55
|
+
"- As ops: what happens at scale, under load, when dependencies fail?",
|
|
56
|
+
"",
|
|
57
|
+
"For each CRITICAL/MAJOR finding, include:",
|
|
58
|
+
"- Confidence: HIGH / MEDIUM / LOW",
|
|
59
|
+
"- If LOW, move to Open Questions instead",
|
|
60
|
+
"",
|
|
61
|
+
"Format your review as:",
|
|
62
|
+
"- CRITICAL: (must fix — with file:line evidence)",
|
|
63
|
+
"- MAJOR: (should fix — with evidence)",
|
|
64
|
+
"- MINOR: (nice to have)",
|
|
65
|
+
"- OPEN QUESTIONS: (low-confidence concerns, speculative follow-ups)",
|
|
66
|
+
"- VERDICT: APPROVE or NEEDS_CHANGES",
|
|
67
|
+
"",
|
|
68
|
+
'You can spawn subagents: Agent(subagent_type="Explore", ...) for codebase, Agent(subagent_type="Librarian", ...) for external docs.',
|
|
69
|
+
"",
|
|
70
|
+
// --- dynamic suffix ---
|
|
71
|
+
"# MANDATORY: Write your review to this exact file using the write tool:",
|
|
72
|
+
` ${outputPath}`,
|
|
73
|
+
"",
|
|
74
|
+
"Your task is NOT complete until this file exists. Do NOT finish without writing it.",
|
|
75
|
+
"You MUST NOT write to any other file. Only write .md files inside .pp/state/.",
|
|
76
|
+
"",
|
|
77
|
+
"=== USER REQUEST ===",
|
|
78
|
+
taskArtifacts.userRequest,
|
|
79
|
+
"",
|
|
80
|
+
"=== RESEARCH ===",
|
|
81
|
+
taskArtifacts.research,
|
|
82
|
+
"",
|
|
83
|
+
"=== SYNTHESIZED PLAN ===",
|
|
84
|
+
taskArtifacts.synthesizedPlan,
|
|
85
|
+
"",
|
|
86
|
+
"The artifacts above are already in your context. Do NOT re-read them from disk.",
|
|
87
|
+
].join("\n"),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { TOOL_ROUTING, ALL_CBM_TOOLS, EXA_TOOLS, WORKING_PRINCIPLES_READONLY, COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createExploreAgent(config: PiPiConfig) {
|
|
5
|
+
return {
|
|
6
|
+
frontmatter: {
|
|
7
|
+
description: "Codebase explorer (pi-pi)",
|
|
8
|
+
tools: `read, bash, grep, find, ls, lsp, ast_search, ${ALL_CBM_TOOLS}, ${EXA_TOOLS}`,
|
|
9
|
+
model: config.agents.explore.model,
|
|
10
|
+
thinking: config.agents.explore.thinking,
|
|
11
|
+
max_turns: config.agents.explore.maxTurns ?? 170,
|
|
12
|
+
prompt_mode: "replace",
|
|
13
|
+
},
|
|
14
|
+
prompt: [
|
|
15
|
+
"You are a focused codebase search agent.",
|
|
16
|
+
"",
|
|
17
|
+
"Your job is to find specific information in the codebase and report back with file paths and findings.",
|
|
18
|
+
"You are read-only — do NOT modify any files.",
|
|
19
|
+
"",
|
|
20
|
+
WORKING_PRINCIPLES_READONLY,
|
|
21
|
+
"",
|
|
22
|
+
COMMUNICATION,
|
|
23
|
+
"",
|
|
24
|
+
TOOL_ROUTING,
|
|
25
|
+
"",
|
|
26
|
+
"# Instructions",
|
|
27
|
+
"- Search multiple angles in parallel for speed",
|
|
28
|
+
"- Start with cbm_search or cbm_search_code for discovery, then narrow with lsp for precision",
|
|
29
|
+
"- Return file paths with brief descriptions of what you found",
|
|
30
|
+
"- When done, provide a concise summary of findings",
|
|
31
|
+
].join("\n"),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createLibrarianAgent(config: PiPiConfig) {
|
|
5
|
+
return {
|
|
6
|
+
frontmatter: {
|
|
7
|
+
description: "External docs researcher (pi-pi)",
|
|
8
|
+
tools: "read, bash, grep, find, exa_search, exa_fetch",
|
|
9
|
+
model: config.agents.librarian.model,
|
|
10
|
+
thinking: config.agents.librarian.thinking,
|
|
11
|
+
max_turns: config.agents.librarian.maxTurns ?? 120,
|
|
12
|
+
prompt_mode: "replace",
|
|
13
|
+
},
|
|
14
|
+
prompt: [
|
|
15
|
+
"You are a research agent specializing in external documentation and libraries.",
|
|
16
|
+
"",
|
|
17
|
+
"Your job is to find documentation, best practices, and usage patterns for external libraries and APIs.",
|
|
18
|
+
"You are read-only — do NOT modify any project files.",
|
|
19
|
+
"",
|
|
20
|
+
COMMUNICATION,
|
|
21
|
+
"",
|
|
22
|
+
"# How to research",
|
|
23
|
+
"",
|
|
24
|
+
"Never guess at APIs — always look them up. Training data may be outdated or wrong.",
|
|
25
|
+
"",
|
|
26
|
+
"Web search and docs:",
|
|
27
|
+
"- exa_search: search the web for docs, guides, examples. Describe the ideal page, not keywords.",
|
|
28
|
+
"- exa_fetch: read a URL's full content as clean markdown. Use after exa_search for details.",
|
|
29
|
+
"",
|
|
30
|
+
"Local sources:",
|
|
31
|
+
"- Read installed package docs (node_modules/, vendor/, go module cache)",
|
|
32
|
+
"- grep: search installed dependencies for usage patterns",
|
|
33
|
+
"",
|
|
34
|
+
"Priority: exa_search → exa_fetch (for full page) → installed source → grep as fallback",
|
|
35
|
+
"",
|
|
36
|
+
"# Output",
|
|
37
|
+
"- Organize findings by topic",
|
|
38
|
+
"- Include exact URLs or file paths for every claim",
|
|
39
|
+
"- Quote relevant code snippets from docs",
|
|
40
|
+
"- Flag any version-specific caveats",
|
|
41
|
+
].join("\n"),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { TOOL_ROUTING, ALL_CBM_TOOLS, EXA_TOOLS, WORKING_PRINCIPLES_READONLY, COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createPlanReviewerAgent(
|
|
5
|
+
variant: string,
|
|
6
|
+
config: PiPiConfig,
|
|
7
|
+
taskArtifacts: { userRequest: string; research: string; synthesizedPlan: string },
|
|
8
|
+
outputPath: string,
|
|
9
|
+
) {
|
|
10
|
+
const variantConfig = config.planReviewers[variant];
|
|
11
|
+
if (!variantConfig) {
|
|
12
|
+
throw new Error(`Unknown plan-reviewer variant: ${variant}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
frontmatter: {
|
|
17
|
+
description: `Plan reviewer (${variant} variant, pi-pi)`,
|
|
18
|
+
tools: `read, grep, find, bash, write, lsp, ast_search, ${ALL_CBM_TOOLS}, ${EXA_TOOLS}`,
|
|
19
|
+
model: variantConfig.model,
|
|
20
|
+
thinking: variantConfig.thinking,
|
|
21
|
+
max_turns: variantConfig.maxTurns ?? 120,
|
|
22
|
+
prompt_mode: "replace",
|
|
23
|
+
},
|
|
24
|
+
prompt: [
|
|
25
|
+
// --- static prefix (cacheable) ---
|
|
26
|
+
"You are a plan reviewer. Your job is to validate the implementation plan for executability and completeness.",
|
|
27
|
+
"",
|
|
28
|
+
"You are a BLOCKER-FINDER, not a perfectionist.",
|
|
29
|
+
"Approve by default. Reject only for critical blockers — maximum 3.",
|
|
30
|
+
"",
|
|
31
|
+
WORKING_PRINCIPLES_READONLY,
|
|
32
|
+
"",
|
|
33
|
+
COMMUNICATION,
|
|
34
|
+
"",
|
|
35
|
+
TOOL_ROUTING,
|
|
36
|
+
"",
|
|
37
|
+
"Review criteria:",
|
|
38
|
+
"- Are all plan items actionable and verifiable?",
|
|
39
|
+
"- Are there missing steps that would block implementation?",
|
|
40
|
+
"- Are there contradictions or ambiguities?",
|
|
41
|
+
"- Does the plan account for edge cases mentioned in the research?",
|
|
42
|
+
"",
|
|
43
|
+
"Perspectives to consider:",
|
|
44
|
+
"- As the executor: can each step be completed with only what's written? Where would I get stuck?",
|
|
45
|
+
"- As the skeptic: what is the strongest argument this approach will fail?",
|
|
46
|
+
"- Feasibility: does the executor have everything needed (context, dependencies, access) without asking questions?",
|
|
47
|
+
"- Ambiguity: could two developers interpret any step differently? If yes, flag it.",
|
|
48
|
+
"",
|
|
49
|
+
"Format your review as:",
|
|
50
|
+
"- BLOCKERS: (critical issues that must be fixed)",
|
|
51
|
+
"- SUGGESTIONS: (improvements, not required)",
|
|
52
|
+
"- VERDICT: APPROVE or REJECT (with reason)",
|
|
53
|
+
"",
|
|
54
|
+
'You can spawn subagents: Agent(subagent_type="Explore", ...) for codebase, Agent(subagent_type="Librarian", ...) for external docs.',
|
|
55
|
+
"",
|
|
56
|
+
// --- dynamic suffix ---
|
|
57
|
+
"# MANDATORY: Write your review to this exact file using the write tool:",
|
|
58
|
+
` ${outputPath}`,
|
|
59
|
+
"",
|
|
60
|
+
"Your task is NOT complete until this file exists. Do NOT finish without writing it.",
|
|
61
|
+
"You MUST NOT write to any other file. Only write .md files inside .pp/state/.",
|
|
62
|
+
"",
|
|
63
|
+
"=== USER REQUEST ===",
|
|
64
|
+
taskArtifacts.userRequest,
|
|
65
|
+
"",
|
|
66
|
+
"=== RESEARCH ===",
|
|
67
|
+
taskArtifacts.research,
|
|
68
|
+
"",
|
|
69
|
+
"=== SYNTHESIZED PLAN ===",
|
|
70
|
+
taskArtifacts.synthesizedPlan,
|
|
71
|
+
"",
|
|
72
|
+
"The artifacts above are already in your context. Do NOT re-read them from disk.",
|
|
73
|
+
].join("\n"),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { TOOL_ROUTING, ALL_CBM_TOOLS, EXA_TOOLS, WORKING_PRINCIPLES_READONLY, COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createPlannerAgent(
|
|
5
|
+
variant: string,
|
|
6
|
+
config: PiPiConfig,
|
|
7
|
+
taskArtifacts: { userRequest: string; research: string },
|
|
8
|
+
outputPath: string,
|
|
9
|
+
) {
|
|
10
|
+
const variantConfig = config.planners[variant];
|
|
11
|
+
if (!variantConfig) {
|
|
12
|
+
throw new Error(`Unknown planner variant: ${variant}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
frontmatter: {
|
|
17
|
+
description: `Planner (${variant} variant, pi-pi)`,
|
|
18
|
+
tools: `read, grep, find, bash, write, lsp, ast_search, ${ALL_CBM_TOOLS}, ${EXA_TOOLS}`,
|
|
19
|
+
model: variantConfig.model,
|
|
20
|
+
thinking: variantConfig.thinking,
|
|
21
|
+
max_turns: variantConfig.maxTurns ?? 120,
|
|
22
|
+
prompt_mode: "replace",
|
|
23
|
+
},
|
|
24
|
+
prompt: [
|
|
25
|
+
// --- static prefix (cacheable) ---
|
|
26
|
+
"You are a planning agent. Your job is to create a detailed implementation plan.",
|
|
27
|
+
"",
|
|
28
|
+
WORKING_PRINCIPLES_READONLY,
|
|
29
|
+
"",
|
|
30
|
+
COMMUNICATION,
|
|
31
|
+
"",
|
|
32
|
+
TOOL_ROUTING,
|
|
33
|
+
"",
|
|
34
|
+
"Plan format rules:",
|
|
35
|
+
"- Start with # Plan",
|
|
36
|
+
"- ## Scope: 2-4 lines — what changes, what doesn't, critical constraints",
|
|
37
|
+
"- ## Checklist: each item is - [ ] <outcome> — Done when: <observable condition>",
|
|
38
|
+
" Each item = one independently verifiable outcome. No code snippets or file-by-file instructions.",
|
|
39
|
+
"- ## Blockers: unresolved issues blocking implementation (omit if none)",
|
|
40
|
+
"- No other top-level sections allowed",
|
|
41
|
+
"- Describe outcomes, not code-level mechanics",
|
|
42
|
+
"",
|
|
43
|
+
'You can spawn subagents: Agent(subagent_type="Explore", ...) for codebase, Agent(subagent_type="Librarian", ...) for external docs.',
|
|
44
|
+
"",
|
|
45
|
+
// --- dynamic suffix ---
|
|
46
|
+
"# MANDATORY: Write your plan to this exact file using the write tool:",
|
|
47
|
+
` ${outputPath}`,
|
|
48
|
+
"",
|
|
49
|
+
"Your task is NOT complete until this file exists. Do NOT finish without writing it.",
|
|
50
|
+
"You MUST NOT write to any other file. Only write .md files inside .pp/state/.",
|
|
51
|
+
"",
|
|
52
|
+
"=== USER REQUEST ===",
|
|
53
|
+
taskArtifacts.userRequest,
|
|
54
|
+
"",
|
|
55
|
+
"=== RESEARCH ===",
|
|
56
|
+
taskArtifacts.research,
|
|
57
|
+
"",
|
|
58
|
+
"The artifacts above are already in your context. Do NOT re-read them from disk.",
|
|
59
|
+
].join("\n"),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
interface AgentFrontmatter {
|
|
4
|
+
description: string;
|
|
5
|
+
tools: string;
|
|
6
|
+
model: string;
|
|
7
|
+
thinking: string;
|
|
8
|
+
max_turns?: number;
|
|
9
|
+
prompt_mode?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function registerAgentDefinitions(
|
|
13
|
+
pi: ExtensionAPI,
|
|
14
|
+
agents: Array<{ type: string; variant: string | null; frontmatter: AgentFrontmatter; prompt: string }>,
|
|
15
|
+
): void {
|
|
16
|
+
const agentMap = new Map<string, any>();
|
|
17
|
+
|
|
18
|
+
for (const agent of agents) {
|
|
19
|
+
const suffix = agent.variant ? `_${agent.variant}` : "";
|
|
20
|
+
const name = `${agent.type}${suffix}`;
|
|
21
|
+
const toolNames = agent.frontmatter.tools === "none" ? [] : agent.frontmatter.tools.split(",").map((t: string) => t.trim()).filter(Boolean);
|
|
22
|
+
|
|
23
|
+
agentMap.set(name, {
|
|
24
|
+
name,
|
|
25
|
+
description: agent.frontmatter.description,
|
|
26
|
+
builtinToolNames: toolNames,
|
|
27
|
+
extensions: true,
|
|
28
|
+
skills: false,
|
|
29
|
+
model: agent.frontmatter.model,
|
|
30
|
+
thinking: agent.frontmatter.thinking,
|
|
31
|
+
maxTurns: agent.frontmatter.max_turns,
|
|
32
|
+
systemPrompt: agent.prompt,
|
|
33
|
+
promptMode: agent.frontmatter.prompt_mode ?? "replace",
|
|
34
|
+
inheritContext: false,
|
|
35
|
+
runInBackground: true,
|
|
36
|
+
isolated: false,
|
|
37
|
+
enabled: true,
|
|
38
|
+
source: "project",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pi.events.emit("subagents:register-agents", { agents: agentMap });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function unregisterAgentDefinitions(pi: ExtensionAPI): void {
|
|
46
|
+
pi.events.emit("subagents:unregister-agents", { all: true });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function setExtensionOnlyMode(pi: ExtensionAPI): void {
|
|
50
|
+
pi.events.emit("subagents:set-extension-only", { enabled: true });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function spawnViaRpc(
|
|
54
|
+
pi: ExtensionAPI,
|
|
55
|
+
agentType: string,
|
|
56
|
+
prompt: string,
|
|
57
|
+
options: {
|
|
58
|
+
description: string;
|
|
59
|
+
maxTurns?: number;
|
|
60
|
+
spawnTimeout?: number;
|
|
61
|
+
validateCompletion?: () => string | undefined;
|
|
62
|
+
maxValidationRetries?: number;
|
|
63
|
+
},
|
|
64
|
+
): Promise<{ id: string }> {
|
|
65
|
+
const timeout = options.spawnTimeout ?? 30000;
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const requestId = crypto.randomUUID();
|
|
68
|
+
const replyEvent = `subagents:rpc:spawn:reply:${requestId}`;
|
|
69
|
+
|
|
70
|
+
const unsub = pi.events.on(replyEvent, (reply: any) => {
|
|
71
|
+
unsub();
|
|
72
|
+
if (reply.success) {
|
|
73
|
+
const mgr = (globalThis as any)[Symbol.for("pi-subagents:manager")];
|
|
74
|
+
mgr?.refreshWidget?.();
|
|
75
|
+
resolve({ id: reply.data?.id ?? requestId });
|
|
76
|
+
} else {
|
|
77
|
+
reject(new Error(reply.error || "spawn failed"));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
pi.events.emit("subagents:rpc:spawn", {
|
|
82
|
+
requestId,
|
|
83
|
+
type: agentType,
|
|
84
|
+
prompt,
|
|
85
|
+
options: {
|
|
86
|
+
description: options.description,
|
|
87
|
+
run_in_background: true,
|
|
88
|
+
maxTurns: options.maxTurns,
|
|
89
|
+
validateCompletion: options.validateCompletion,
|
|
90
|
+
maxValidationRetries: options.maxValidationRetries,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
unsub();
|
|
96
|
+
reject(new Error(`spawn timeout for ${agentType}`));
|
|
97
|
+
}, timeout);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function waitForCompletion(
|
|
102
|
+
pi: ExtensionAPI,
|
|
103
|
+
agentId: string,
|
|
104
|
+
): Promise<{ result: string; status: string }> {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
const cleanup = () => {
|
|
107
|
+
clearInterval(checkTimer);
|
|
108
|
+
unsubCompleted();
|
|
109
|
+
unsubFailed();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const unsubCompleted = pi.events.on("subagents:completed", (data: any) => {
|
|
113
|
+
if (data.id === agentId) {
|
|
114
|
+
cleanup();
|
|
115
|
+
resolve({ result: data.result ?? "", status: data.status ?? "completed" });
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const unsubFailed = pi.events.on("subagents:failed", (data: any) => {
|
|
120
|
+
if (data.id === agentId) {
|
|
121
|
+
cleanup();
|
|
122
|
+
reject(new Error(data.error || `agent ${agentId} failed`));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const checkTimer = setInterval(() => {
|
|
127
|
+
const mgr = (globalThis as any)[Symbol.for("pi-subagents:manager")];
|
|
128
|
+
const record = mgr?.getRecord?.(agentId);
|
|
129
|
+
if (!record) {
|
|
130
|
+
cleanup();
|
|
131
|
+
reject(new Error(`agent ${agentId} not found in manager`));
|
|
132
|
+
}
|
|
133
|
+
}, 30000);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function isSubagentsReady(pi: ExtensionAPI, pingTimeout?: number): Promise<boolean> {
|
|
138
|
+
const timeout = pingTimeout ?? 5000;
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
const requestId = crypto.randomUUID();
|
|
141
|
+
const replyEvent = `subagents:rpc:ping:reply:${requestId}`;
|
|
142
|
+
|
|
143
|
+
const timer = setTimeout(() => {
|
|
144
|
+
unsub();
|
|
145
|
+
resolve(false);
|
|
146
|
+
}, timeout);
|
|
147
|
+
|
|
148
|
+
const unsub = pi.events.on(replyEvent, (reply: any) => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
unsub();
|
|
151
|
+
resolve(reply.success === true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
pi.events.emit("subagents:rpc:ping", { requestId });
|
|
155
|
+
});
|
|
156
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { PiPiConfig } from "../config.js";
|
|
2
|
+
import { TOOL_ROUTING, ALL_CBM_TOOLS, EXA_TOOLS, WORKING_PRINCIPLES, FAILURE_RECOVERY, COMMUNICATION } from "./tool-routing.js";
|
|
3
|
+
|
|
4
|
+
export function createTaskAgent(
|
|
5
|
+
config: PiPiConfig,
|
|
6
|
+
subtaskDescription: string,
|
|
7
|
+
taskArtifacts: { userRequest: string; synthesizedPlan: string },
|
|
8
|
+
) {
|
|
9
|
+
return {
|
|
10
|
+
frontmatter: {
|
|
11
|
+
description: "Implementation subtask (pi-pi)",
|
|
12
|
+
tools: `read, write, edit, bash, grep, find, ls, lsp, ast_search, ${ALL_CBM_TOOLS}, ${EXA_TOOLS}`,
|
|
13
|
+
model: config.agents.task.model,
|
|
14
|
+
thinking: config.agents.task.thinking,
|
|
15
|
+
max_turns: config.agents.task.maxTurns ?? 170,
|
|
16
|
+
prompt_mode: "replace",
|
|
17
|
+
},
|
|
18
|
+
prompt: [
|
|
19
|
+
// --- static prefix (cacheable) ---
|
|
20
|
+
"You are a focused implementation agent working on a specific subtask.",
|
|
21
|
+
"",
|
|
22
|
+
WORKING_PRINCIPLES,
|
|
23
|
+
"",
|
|
24
|
+
COMMUNICATION,
|
|
25
|
+
"",
|
|
26
|
+
TOOL_ROUTING,
|
|
27
|
+
"",
|
|
28
|
+
FAILURE_RECOVERY,
|
|
29
|
+
"",
|
|
30
|
+
"# Constraints",
|
|
31
|
+
"- Do NOT spawn task subagents (no recursion)",
|
|
32
|
+
'- You CAN spawn subagents: Agent(subagent_type="Explore", ...) for codebase, Agent(subagent_type="Librarian", ...) for external docs',
|
|
33
|
+
"- Focus only on your subtask — do not modify unrelated code",
|
|
34
|
+
"- Before modifying a function, use lsp findReferences to understand all callers",
|
|
35
|
+
"- After editing files, run lsp diagnostics and fix errors before moving on",
|
|
36
|
+
"",
|
|
37
|
+
// --- dynamic suffix ---
|
|
38
|
+
"=== YOUR SUBTASK ===",
|
|
39
|
+
subtaskDescription,
|
|
40
|
+
"",
|
|
41
|
+
"=== USER REQUEST (for context) ===",
|
|
42
|
+
taskArtifacts.userRequest,
|
|
43
|
+
"",
|
|
44
|
+
"=== SYNTHESIZED PLAN (for broader context) ===",
|
|
45
|
+
taskArtifacts.synthesizedPlan,
|
|
46
|
+
"",
|
|
47
|
+
"The artifacts above are already in your context. Do NOT re-read them from disk.",
|
|
48
|
+
].join("\n"),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export const ALL_CBM_TOOLS = "cbm_search, cbm_search_code, cbm_trace, cbm_changes, cbm_query, cbm_architecture";
|
|
2
|
+
export const EXA_TOOLS = "exa_search, exa_fetch";
|
|
3
|
+
|
|
4
|
+
export const WORKING_PRINCIPLES = [
|
|
5
|
+
"# Working principles",
|
|
6
|
+
"",
|
|
7
|
+
"- Verify, don't assume. Check actual state with tools before making changes. Never guess paths, types, or APIs.",
|
|
8
|
+
"- Understand before modifying. Read the code, trace callers, check types BEFORE editing. Compiling ≠ correct.",
|
|
9
|
+
"- Smallest viable change. Do what was asked, nothing more. Don't broaden scope, don't refactor adjacent code.",
|
|
10
|
+
"- No temporary artifacts. No console.log, TODO, HACK, debugger, or commented-out code left behind.",
|
|
11
|
+
"- Evidence over claims. 'It should work' is not proof. Show fresh tool output (lsp diagnostics, test results, build output).",
|
|
12
|
+
"- Match existing patterns. Mirror the codebase's naming, error handling, imports, and structure exactly.",
|
|
13
|
+
].join("\n");
|
|
14
|
+
|
|
15
|
+
export const WORKING_PRINCIPLES_READONLY = [
|
|
16
|
+
"# Working principles",
|
|
17
|
+
"",
|
|
18
|
+
"- Verify, don't assume. Check actual state with tools. Never guess paths, types, or APIs.",
|
|
19
|
+
"- Evidence over claims. Show what you found with file paths and tool output, not guesses.",
|
|
20
|
+
].join("\n");
|
|
21
|
+
|
|
22
|
+
export const FAILURE_RECOVERY = [
|
|
23
|
+
"# Failure recovery",
|
|
24
|
+
"",
|
|
25
|
+
"If a fix attempt fails, analyze root cause before retrying — don't repeat the same approach.",
|
|
26
|
+
"After 3 failed attempts at the same issue:",
|
|
27
|
+
"1. STOP editing immediately",
|
|
28
|
+
"2. Revert to last working state if possible",
|
|
29
|
+
"3. Document what you tried and why it failed",
|
|
30
|
+
"4. Report the blocker — do not keep pushing",
|
|
31
|
+
].join("\n");
|
|
32
|
+
|
|
33
|
+
export const COMMUNICATION = [
|
|
34
|
+
"# Communication",
|
|
35
|
+
"",
|
|
36
|
+
"- CONCISE. Use minimum words needed. No preamble, no filler, no restatement.",
|
|
37
|
+
"- Never explain what you're about to do — just do it.",
|
|
38
|
+
"- Never summarize what you just did — the user can see the results.",
|
|
39
|
+
"- Think critically. Don't just agree — push back when something seems wrong.",
|
|
40
|
+
"- State concerns before implementing. If you see a better approach, say so.",
|
|
41
|
+
"- Dense over polished. One precise sentence beats three vague ones.",
|
|
42
|
+
].join("\n");
|
|
43
|
+
|
|
44
|
+
export const TOOL_ROUTING = [
|
|
45
|
+
"# Tool routing — what do you want to do?",
|
|
46
|
+
"",
|
|
47
|
+
"Find code by concept or behavior:",
|
|
48
|
+
"- cbm_search: natural-language search (query='deploy release chart')",
|
|
49
|
+
"- cbm_search with semantic_query: vector similarity (['deploy','install','upgrade'])",
|
|
50
|
+
"- cbm_search_code: graph-augmented grep — deduplicates into containing functions",
|
|
51
|
+
"Priority: cbm_search → lsp workspaceSymbol → grep",
|
|
52
|
+
"",
|
|
53
|
+
"Navigate to a definition, type, or interface:",
|
|
54
|
+
"- NEVER grep for definitions. ALWAYS use lsp goToDefinition.",
|
|
55
|
+
"- lsp hover: get type info and documentation",
|
|
56
|
+
"- lsp goToImplementation: find all types implementing an interface",
|
|
57
|
+
"- lsp documentSymbol: list all symbols in a file",
|
|
58
|
+
"",
|
|
59
|
+
"Find all usages of a symbol:",
|
|
60
|
+
"- NEVER grep for symbol names. ALWAYS use lsp findReferences.",
|
|
61
|
+
"",
|
|
62
|
+
"Trace call chains:",
|
|
63
|
+
"- lsp incomingCalls/outgoingCalls: accurate, needs file+line position",
|
|
64
|
+
"- cbm_trace: by function name, works across the whole graph",
|
|
65
|
+
"- cbm_query: Cypher queries for complex multi-hop patterns",
|
|
66
|
+
"",
|
|
67
|
+
"Find structural patterns:",
|
|
68
|
+
"- ast_search: AST-aware matching (e.g. 'if err != nil { $$$ }', 'go $FUNC($$$)')",
|
|
69
|
+
"",
|
|
70
|
+
"Search for literal text:",
|
|
71
|
+
"- grep: ONLY for literal strings, config keys, error messages. Not for definitions or references.",
|
|
72
|
+
"",
|
|
73
|
+
"Check for errors:",
|
|
74
|
+
"- lsp diagnostics: type errors and lint issues on a file",
|
|
75
|
+
"- lsp codeActions: auto-fix suggestions",
|
|
76
|
+
"",
|
|
77
|
+
"Assess impact of changes:",
|
|
78
|
+
"- cbm_changes: git diff → affected symbols + blast radius",
|
|
79
|
+
"- cbm_architecture: high-level codebase structure overview",
|
|
80
|
+
"",
|
|
81
|
+
"Web search:",
|
|
82
|
+
"- exa_search: search the web for docs, guides, examples. Describe the ideal page, not keywords.",
|
|
83
|
+
"- exa_fetch: read a URL's full content as clean markdown.",
|
|
84
|
+
].join("\n");
|