@howaboua/pi-subagent-review 0.2.2 → 0.2.4

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 CHANGED
@@ -23,7 +23,7 @@ It runs an isolated review subagent against your current repo, optionally prepar
23
23
 
24
24
  `/review loop` starts a review loop. It sets a review-specific marker at the current conversation point, strips the `loop` word from the review guidance, and then runs the normal review.
25
25
 
26
- The first `/review` in a session branch also adds a visible advisory preface without starting an agent turn. The preface reminds the main agent that review findings are advisory and should be triaged against the current task, prior conversation, architectural decisions, and accepted tradeoffs before coding.
26
+ The first `/review` in a session branch also adds a visible advisory preface without starting an agent turn. The preface tells the main agent not to treat review findings as a TODO list, and to summarize and triage them against session context and the current implementation before changing code.
27
27
 
28
28
  After that, plain `/review` detects the active review marker, summarizes the work since that marker back into a compact review-fix increment, advances the review marker, and then runs the next isolated review pass from the compacted point. If the stored marker is gone, `/review` simply behaves like a normal review.
29
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-subagent-review",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Pi extension that adds /review via an isolated review subagent.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -38,8 +38,8 @@
38
38
  ]
39
39
  },
40
40
  "peerDependencies": {
41
- "@earendil-works/pi-ai": "^0.78.0",
42
- "@earendil-works/pi-coding-agent": "^0.78.0"
41
+ "@earendil-works/pi-ai": "*",
42
+ "@earendil-works/pi-coding-agent": "*"
43
43
  },
44
44
  "scripts": {
45
45
  "check": "bun run lint && bun run typecheck",
@@ -49,8 +49,8 @@
49
49
  "format": "biome check --write ."
50
50
  },
51
51
  "devDependencies": {
52
- "@earendil-works/pi-ai": "^0.78.0",
53
- "@earendil-works/pi-coding-agent": "^0.78.0",
52
+ "@earendil-works/pi-ai": "0.80.1",
53
+ "@earendil-works/pi-coding-agent": "0.80.1",
54
54
  "@types/node": "^24.10.0",
55
55
  "typescript": "^5.9.3",
56
56
  "@biomejs/biome": "^2.4.16"
@@ -1,10 +1,177 @@
1
- import { completeSimple } from "@earendil-works/pi-ai";
1
+ import type {
2
+ Api,
3
+ AssistantMessage,
4
+ AssistantMessageEventStream,
5
+ Context,
6
+ Model,
7
+ SimpleStreamOptions,
8
+ } from "@earendil-works/pi-ai";
9
+ import { streamSimple as streamAnthropicMessages } from "@earendil-works/pi-ai/api/anthropic-messages";
10
+ import { streamSimple as streamAzureOpenAIResponses } from "@earendil-works/pi-ai/api/azure-openai-responses";
11
+ import { streamSimple as streamBedrockConverseStream } from "@earendil-works/pi-ai/api/bedrock-converse-stream";
12
+ import { streamSimple as streamGoogleGenerativeAI } from "@earendil-works/pi-ai/api/google-generative-ai";
13
+ import { streamSimple as streamGoogleVertex } from "@earendil-works/pi-ai/api/google-vertex";
14
+ import { streamSimple as streamMistralConversations } from "@earendil-works/pi-ai/api/mistral-conversations";
15
+ import { streamSimple as streamOpenAICodexResponses } from "@earendil-works/pi-ai/api/openai-codex-responses";
16
+ import { streamSimple as streamOpenAICompletions } from "@earendil-works/pi-ai/api/openai-completions";
17
+ import { streamSimple as streamOpenAIResponses } from "@earendil-works/pi-ai/api/openai-responses";
2
18
  import type {
3
19
  ExtensionCommandContext,
4
20
  SessionEntry,
5
21
  } from "@earendil-works/pi-coding-agent";
6
22
  import type { ResolvedReviewConfig } from "./types.js";
7
23
 
24
+ type RegisteredProviderConfig = {
25
+ api?: Api;
26
+ authHeader?: boolean;
27
+ streamSimple?: (
28
+ model: Model<Api>,
29
+ context: Context,
30
+ options?: SimpleStreamOptions,
31
+ ) => AssistantMessageEventStream;
32
+ };
33
+
34
+ type ModelRegistryInternals = {
35
+ providerRequestConfigs?: Map<
36
+ string,
37
+ Pick<RegisteredProviderConfig, "authHeader">
38
+ >;
39
+ registeredProviders?: Map<string, RegisteredProviderConfig>;
40
+ };
41
+
42
+ function getModelRegistryInternals(
43
+ modelRegistry: ExtensionCommandContext["modelRegistry"],
44
+ ): ModelRegistryInternals {
45
+ return modelRegistry as unknown as ModelRegistryInternals;
46
+ }
47
+
48
+ function getRegisteredStreamSimple(
49
+ modelRegistry: ExtensionCommandContext["modelRegistry"],
50
+ model: Model<Api>,
51
+ ): RegisteredProviderConfig["streamSimple"] {
52
+ const providerConfig = getModelRegistryInternals(
53
+ modelRegistry,
54
+ ).registeredProviders?.get(model.provider);
55
+ if (providerConfig?.api !== model.api) return undefined;
56
+ return providerConfig.streamSimple;
57
+ }
58
+
59
+ function isMissingApiKeyError(error: string, provider: string): boolean {
60
+ return error === `No API key found for "${provider}"`;
61
+ }
62
+
63
+ async function getSummaryOptions(
64
+ ctx: ExtensionCommandContext,
65
+ model: Model<Api>,
66
+ config: ResolvedReviewConfig,
67
+ ): Promise<SimpleStreamOptions> {
68
+ const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
69
+ const fallbackApiKey =
70
+ auth.ok && auth.apiKey
71
+ ? undefined
72
+ : await ctx.modelRegistry.getApiKeyForProvider(model.provider);
73
+ if (!auth.ok && !isMissingApiKeyError(auth.error, model.provider)) {
74
+ throw new Error(`Summary model unavailable: ${auth.error}`);
75
+ }
76
+ if (!auth.ok && !fallbackApiKey) {
77
+ throw new Error(`Summary model unavailable: ${auth.error}`);
78
+ }
79
+
80
+ let headers = auth.ok ? auth.headers : undefined;
81
+ if (
82
+ fallbackApiKey &&
83
+ getModelRegistryInternals(ctx.modelRegistry).providerRequestConfigs?.get(
84
+ model.provider,
85
+ )?.authHeader
86
+ ) {
87
+ headers = { ...headers, Authorization: `Bearer ${fallbackApiKey}` };
88
+ }
89
+
90
+ const options: SimpleStreamOptions = {};
91
+ const apiKey = auth.ok && auth.apiKey ? auth.apiKey : fallbackApiKey;
92
+ const env = auth.ok
93
+ ? auth.env
94
+ : ctx.modelRegistry.authStorage.getProviderEnv(model.provider);
95
+ if (apiKey) options.apiKey = apiKey;
96
+ if (headers) options.headers = headers;
97
+ if (env) options.env = env;
98
+ if (model.reasoning && config.summary.thinking !== "off") {
99
+ options.reasoning = config.summary.thinking;
100
+ }
101
+ if (ctx.signal) options.signal = ctx.signal;
102
+ return options;
103
+ }
104
+
105
+ async function completeSummaryWithModelApi(
106
+ model: Model<Api>,
107
+ context: Context,
108
+ options: SimpleStreamOptions,
109
+ registeredStreamSimple: RegisteredProviderConfig["streamSimple"],
110
+ ): Promise<AssistantMessage> {
111
+ if (registeredStreamSimple) {
112
+ return registeredStreamSimple(model, context, options).result();
113
+ }
114
+
115
+ switch (model.api) {
116
+ case "anthropic-messages":
117
+ return streamAnthropicMessages(
118
+ model as Model<"anthropic-messages">,
119
+ context,
120
+ options,
121
+ ).result();
122
+ case "azure-openai-responses":
123
+ return streamAzureOpenAIResponses(
124
+ model as Model<"azure-openai-responses">,
125
+ context,
126
+ options,
127
+ ).result();
128
+ case "bedrock-converse-stream":
129
+ return streamBedrockConverseStream(
130
+ model as Model<"bedrock-converse-stream">,
131
+ context,
132
+ options,
133
+ ).result();
134
+ case "google-generative-ai":
135
+ return streamGoogleGenerativeAI(
136
+ model as Model<"google-generative-ai">,
137
+ context,
138
+ options,
139
+ ).result();
140
+ case "google-vertex":
141
+ return streamGoogleVertex(
142
+ model as Model<"google-vertex">,
143
+ context,
144
+ options,
145
+ ).result();
146
+ case "mistral-conversations":
147
+ return streamMistralConversations(
148
+ model as Model<"mistral-conversations">,
149
+ context,
150
+ options,
151
+ ).result();
152
+ case "openai-codex-responses":
153
+ return streamOpenAICodexResponses(
154
+ model as Model<"openai-codex-responses">,
155
+ context,
156
+ options,
157
+ ).result();
158
+ case "openai-completions":
159
+ return streamOpenAICompletions(
160
+ model as Model<"openai-completions">,
161
+ context,
162
+ options,
163
+ ).result();
164
+ case "openai-responses":
165
+ return streamOpenAIResponses(
166
+ model as Model<"openai-responses">,
167
+ context,
168
+ options,
169
+ ).result();
170
+ default:
171
+ throw new Error(`Summary model API is unsupported: ${model.api}`);
172
+ }
173
+ }
174
+
8
175
  function textFromContent(content: unknown): string {
9
176
  if (typeof content === "string") return content;
10
177
  if (!Array.isArray(content)) return "";
@@ -113,19 +280,9 @@ export async function buildReviewConversationSummary(
113
280
  const model = ctx.modelRegistry.find(parsed.provider, parsed.modelId);
114
281
  if (!model)
115
282
  throw new Error(`Summary model not found: ${config.summary.model}`);
116
- const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
117
- if (!auth.ok) throw new Error(`Summary model unavailable: ${auth.error}`);
118
-
119
- const options = {
120
- ...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
121
- ...(auth.headers ? { headers: auth.headers } : {}),
122
- ...(model.reasoning && config.summary.thinking !== "off"
123
- ? { reasoning: config.summary.thinking }
124
- : {}),
125
- ...(ctx.signal ? { signal: ctx.signal } : {}),
126
- };
127
-
128
- const response = await completeSimple(
283
+ const options = await getSummaryOptions(ctx, model, config);
284
+
285
+ const response = await completeSummaryWithModelApi(
129
286
  model,
130
287
  {
131
288
  messages: [
@@ -137,6 +294,7 @@ export async function buildReviewConversationSummary(
137
294
  ],
138
295
  },
139
296
  options,
297
+ getRegisteredStreamSimple(ctx.modelRegistry, model),
140
298
  );
141
299
 
142
300
  const summary = response.content
package/src/messages.ts CHANGED
@@ -9,13 +9,21 @@ export const REVIEW_LOOP_PREFACE_MESSAGE_TYPE = "subagent-review-preface";
9
9
  export const REVIEW_FINDINGS_MESSAGE_TYPE = "subagent-review-findings";
10
10
 
11
11
  export const REVIEW_LOOP_PREFACE_MESSAGE = [
12
- "Review advisory note.",
12
+ "A review subagent is about to inspect the repository in isolation. Its findings are advisory only and may be wrong, overbroad, or missing session context.",
13
13
  "",
14
- "A review subagent is about to inspect the repository in isolation. Treat its findings as advisory review input, not direct implementation instructions.",
14
+ "Do not treat review findings as a TODO list. Do not implement review findings automatically.",
15
15
  "",
16
- "When findings come back, triage before coding. Check each item against the current task, prior conversation, accepted architectural decisions, and any intentional tradeoffs from this session.",
16
+ "When findings return, compare each one against the user’s actual request, prior conversation, accepted decisions, intentional tradeoffs from this session, and the current implementation.",
17
17
  "",
18
- "Act directly only on clearly worthwhile issues: correctness bugs, security risks, data loss, broken builds, or serious regressions. For context-dependent, stylistic, architectural, low-impact, or preference-based findings, discuss the tradeoff first and say whether you would address, defer, or skip it.",
18
+ "Default response: summarize and triage, not code.",
19
+ "",
20
+ "For each finding, mark one of:",
21
+ "",
22
+ "- address: concrete, in-scope, necessary for the current implementation",
23
+ "- defer: plausible but outside the current work",
24
+ "- skip: stylistic, speculative, preference-based, overengineered, or not useful",
25
+ "",
26
+ "Only after triage, explain what you recommend doing next. If a finding is not obviously required for the current implementation, do not change code for it.",
19
27
  ].join("\n");
20
28
 
21
29
  function getReviewPrefaceMessageId(
@@ -82,9 +90,11 @@ export function buildReviewUserMessage(
82
90
  "",
83
91
  "These findings are advisory output from an isolated review subagent.",
84
92
  "",
85
- "Triage before coding. Weigh each item against the current task, prior conversation, accepted architectural decisions, and intentional tradeoffs from this session.",
93
+ "Do not treat review findings as a TODO list. Default response: summarize and triage, not code.",
94
+ "",
95
+ "Compare each finding against the user’s actual request, prior conversation, accepted decisions, intentional tradeoffs from this session, and the current implementation.",
86
96
  "",
87
- "If you address, skip, or defer findings, briefly say why.",
97
+ "Mark each finding as address, defer, or skip. Only change code for findings that are obviously required for the current implementation.",
88
98
  ].join("\n");
89
99
  }
90
100