@juicesharp/rpiv-advisor 1.0.16 → 1.0.18

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.
Files changed (2) hide show
  1. package/advisor.ts +15 -21
  2. package/package.json +1 -1
package/advisor.ts CHANGED
@@ -61,11 +61,7 @@ const CHECKMARK = " ✓";
61
61
  // Messages (static)
62
62
  const MSG_ADVISOR_DISABLED = "Advisor disabled";
63
63
  const MSG_REQUIRES_INTERACTIVE = "/advisor requires interactive mode";
64
-
65
- // User-tail nudge — appended when stripping leaves an assistant tail (some
66
- // providers, e.g. recent Anthropic models, reject payloads not ending with
67
- // a user message: "This model does not support assistant message prefill.").
68
- const ADVISOR_NUDGE_TEXT = "Please advise on the executor's situation above.";
64
+ const MSG_ADVISOR_NUDGE = "Please advise on the executor's situation above.";
69
65
 
70
66
  // Errors (static)
71
67
  const ERR_NO_MODEL = "No advisor model is configured. The user can enable one with the /advisor command.";
@@ -211,23 +207,21 @@ export function stripInflightAdvisorCall(messages: Message[]): Message[] {
211
207
  return [...messages.slice(0, -1), { ...last, content: filtered }];
212
208
  }
213
209
 
214
- // Some providers (recent Anthropic Claude models) reject payloads that end on
215
- // an assistant turn — they treat a trailing assistant message as a prefill and
216
- // require user-tail. After stripInflightAdvisorCall, the tail can be assistant
217
- // (e.g. the executor wrote thinking text before calling advisor). Append a
218
- // minimal user-role nudge so the request is well-formed for those providers.
219
- export function ensureUserTail(messages: Message[]): Message[] {
210
+ // Some providers (recent Anthropic Claude models) reject payloads ending on an
211
+ // assistant turn ("This model does not support assistant message prefill. The
212
+ // conversation must end with a user message."). After stripInflightAdvisorCall
213
+ // the tail can be assistant (e.g. the executor wrote thinking text before
214
+ // calling advisor). Append a minimal user-role nudge to guarantee user-tail.
215
+ export function ensureUserTailForAdvisor(messages: Message[]): Message[] {
220
216
  if (messages.length === 0) return messages;
221
217
  const last = messages[messages.length - 1];
222
- if (last.role === "user" || last.role === "toolResult") return messages;
223
- return [
224
- ...messages,
225
- {
226
- role: "user",
227
- content: [{ type: "text", text: ADVISOR_NUDGE_TEXT }],
228
- timestamp: Date.now(),
229
- },
230
- ];
218
+ if (last.role !== "assistant") return messages;
219
+ const nudge: Message = {
220
+ role: "user",
221
+ content: [{ type: "text", text: MSG_ADVISOR_NUDGE }],
222
+ timestamp: Date.now(),
223
+ };
224
+ return [...messages, nudge];
231
225
  }
232
226
 
233
227
  // Returns `undefined` when the registry is empty (no extensions loaded) so
@@ -361,7 +355,7 @@ async function executeAdvisor(
361
355
  const agentMessages = branch
362
356
  .filter((e): e is SessionEntry & { type: "message" } => e.type === "message")
363
357
  .map((e) => e.message);
364
- const branchMessages = ensureUserTail(stripInflightAdvisorCall(convertToLlm(agentMessages)));
358
+ const branchMessages = ensureUserTailForAdvisor(stripInflightAdvisorCall(convertToLlm(agentMessages)));
365
359
  const inventoryMessage = getInventoryMessage(pi.getAllTools());
366
360
  const messages: Message[] = inventoryMessage ? [inventoryMessage, ...branchMessages] : branchMessages;
367
361
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-advisor",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Pi extension: lets the model ask a stronger reviewer model for a second opinion before it acts",
5
5
  "keywords": [
6
6
  "pi-package",