pi-advisor-flow 0.14.5-dev.3 → 0.14.5-dev.5

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/CHANGELOG.md CHANGED
@@ -8,12 +8,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
8
8
 
9
9
  ### Added
10
10
 
11
- - Support Pi virtual models as Advisor models. Activation defers credentials to Pi's request-time router, which resolves auth for the selected physical model.
11
+ - Support Pi virtual models as Advisor models. Activation defers credentials to Pi's request-time router, which resolves auth for the selected physical model. Runtimes without `modelRegistry.streamSimple` now get an explicit upgrade/physical-model error instead of a misleading missing-key error.
12
12
 
13
13
  ### Changed
14
14
 
15
15
  - Updated development dependencies: Pi packages (`pi-ai`, `pi-coding-agent`, and `pi-tui`) to 1.5.2, Oxlint and plugins to 1.93.0, Knip to 6.45.1, TypeBox to 1.4.6, and Ultracite to 8.2.0. Existing peer dependency ranges remain unchanged.
16
16
 
17
+ ### Fixed
18
+
19
+ - Advisor and fallback Advisor requests now forward the active Pi session id, so providers that require a session header (such as OpenCode Go's `x-opencode-session`) no longer fail with HTTP 400 `MissingSessionID`.
20
+
17
21
  ## 0.14.4 - 2026-11-03
18
22
 
19
23
  ### Added
package/README.md CHANGED
@@ -77,7 +77,7 @@ Reload Pi after installing.
77
77
  /advisor-stats # Show retained outcome adoption and validation stats
78
78
  ```
79
79
 
80
- The Executor is whichever model your Pi session is using; `/advisor` never switches it unless you pin one with `executor=` or `/advisor-models`. On first use, or whenever the saved Advisor is unavailable, `/advisor` opens the available-model picker; it never silently chooses an unconfigured Advisor. Pi virtual models can be selected as Advisors; Pi routes each request to a physical model and resolves that model's credentials. If the active Executor and Advisor use the same provider/model, calls and automatic gates are skipped with a notice; switching either model resumes consultations. Turn off **Disable same-model Advisor** in `/advisor-settings` (or set `"advisorDisableSameModel": false` globally) if you intentionally want a higher-effort review from that same model. You can also enable the flow and select both models at once:
80
+ The Executor is whichever model your Pi session is using; `/advisor` never switches it unless you pin one with `executor=` or `/advisor-models`. On first use, or whenever the saved Advisor is unavailable, `/advisor` opens the available-model picker; it never silently chooses an unconfigured Advisor. Pi virtual models can be selected as Advisors; Pi routes each request to a physical model and resolves that model's credentials. They require a Pi runtime with `modelRegistry.streamSimple`; on older runtimes, the request explains how to upgrade or select a physical Advisor model. If the active Executor and Advisor use the same provider/model, calls and automatic gates are skipped with a notice; switching either model resumes consultations. Turn off **Disable same-model Advisor** in `/advisor-settings` (or set `"advisorDisableSameModel": false` globally) if you intentionally want a higher-effort review from that same model. You can also enable the flow and select both models at once:
81
81
 
82
82
  ```text
83
83
  /advisor executor=openai-codex/gpt-5.6-luna advisor=openai-codex/gpt-5.6-sol
package/dist/index.js CHANGED
@@ -2055,6 +2055,9 @@ var resolveConfiguredModel = async (ctx, ref, label) => {
2055
2055
  streamSimple: streamSimple.bind(ctx.modelRegistry)
2056
2056
  };
2057
2057
  }
2058
+ if (model.api === "pi-virtual") {
2059
+ throw new Error(`Pi virtual model ${ref} requires modelRegistry.streamSimple, which is unavailable in this Pi runtime. Update Pi or select a physical ${label} model.`);
2060
+ }
2058
2061
  const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
2059
2062
  if (!auth.ok) {
2060
2063
  throw new Error(auth.error);
@@ -2169,6 +2172,7 @@ var createTextEventStream = (resolved, options, streamModel) => {
2169
2172
  if (!streamModel && resolved.streamSimple) {
2170
2173
  return resolved.streamSimple(resolved.model, context, {
2171
2174
  reasoning: toSimpleReasoning(options.reasoning),
2175
+ sessionId: options.sessionId,
2172
2176
  signal: options.signal
2173
2177
  });
2174
2178
  }
@@ -2177,6 +2181,7 @@ var createTextEventStream = (resolved, options, streamModel) => {
2177
2181
  env: resolved.env,
2178
2182
  headers: resolved.headers,
2179
2183
  reasoning: options.reasoning,
2184
+ sessionId: options.sessionId,
2180
2185
  signal: options.signal
2181
2186
  };
2182
2187
  if (options.reasoning !== undefined) {
@@ -2214,6 +2219,36 @@ var collectTextStream = async (resolved, options, streamModel) => {
2214
2219
  };
2215
2220
  };
2216
2221
 
2222
+ // src/session-context.ts
2223
+ var projectBranch = (source) => {
2224
+ const resetBoundaryIndex = source.findLastIndex((entry) => Object.is(entry.type, "reset_boundary"));
2225
+ const branch = source.slice(resetBoundaryIndex + 1);
2226
+ const compactionIndex = branch.findLastIndex((entry) => entry.type === "compaction");
2227
+ if (compactionIndex === -1) {
2228
+ return branch;
2229
+ }
2230
+ const compaction = branch[compactionIndex];
2231
+ if (compaction.type !== "compaction") {
2232
+ return branch;
2233
+ }
2234
+ const firstKeptIndex = branch.findIndex((entry, index) => index < compactionIndex && entry.id === compaction.firstKeptEntryId);
2235
+ const projected = [compaction];
2236
+ if (firstKeptIndex !== -1) {
2237
+ for (let index = firstKeptIndex;index < compactionIndex; index += 1) {
2238
+ const entry = branch[index];
2239
+ if (entry.type !== "compaction" && !(entry.type === "message" && entry.message.role === "system")) {
2240
+ projected.push(entry);
2241
+ }
2242
+ }
2243
+ }
2244
+ return [...projected, ...branch.slice(compactionIndex + 1)];
2245
+ };
2246
+ var currentSessionId = (ctx) => ctx.sessionManager?.getSessionId?.();
2247
+ var sessionContextEntries = (ctx) => {
2248
+ const sessionManager = ctx.sessionManager;
2249
+ return sessionManager.buildContextEntries ? sessionManager.buildContextEntries() : projectBranch(sessionManager.getBranch());
2250
+ };
2251
+
2217
2252
  // src/tools/consult-context.ts
2218
2253
  import { randomUUID } from "node:crypto";
2219
2254
 
@@ -2596,35 +2631,6 @@ var detectImageFormat = (bytes) => {
2596
2631
  }
2597
2632
  };
2598
2633
 
2599
- // src/session-context.ts
2600
- var projectBranch = (source) => {
2601
- const resetBoundaryIndex = source.findLastIndex((entry) => Object.is(entry.type, "reset_boundary"));
2602
- const branch = source.slice(resetBoundaryIndex + 1);
2603
- const compactionIndex = branch.findLastIndex((entry) => entry.type === "compaction");
2604
- if (compactionIndex === -1) {
2605
- return branch;
2606
- }
2607
- const compaction = branch[compactionIndex];
2608
- if (compaction.type !== "compaction") {
2609
- return branch;
2610
- }
2611
- const firstKeptIndex = branch.findIndex((entry, index) => index < compactionIndex && entry.id === compaction.firstKeptEntryId);
2612
- const projected = [compaction];
2613
- if (firstKeptIndex !== -1) {
2614
- for (let index = firstKeptIndex;index < compactionIndex; index += 1) {
2615
- const entry = branch[index];
2616
- if (entry.type !== "compaction" && !(entry.type === "message" && entry.message.role === "system")) {
2617
- projected.push(entry);
2618
- }
2619
- }
2620
- }
2621
- return [...projected, ...branch.slice(compactionIndex + 1)];
2622
- };
2623
- var sessionContextEntries = (ctx) => {
2624
- const sessionManager = ctx.sessionManager;
2625
- return sessionManager.buildContextEntries ? sessionManager.buildContextEntries() : projectBranch(sessionManager.getBranch());
2626
- };
2627
-
2628
2634
  // src/images.ts
2629
2635
  var ADVISOR_IMAGE_MAX_BYTES = 4 * 1024 * 1024;
2630
2636
  var ADVISOR_IMAGES_TOTAL_MAX_BYTES = 8 * 1024 * 1024;
@@ -3787,7 +3793,7 @@ var setupAbortWatch = (parentSignal, timeoutMs) => {
3787
3793
  wasTimedOut: () => timedOut
3788
3794
  };
3789
3795
  };
3790
- var streamScoutResponse = async (dependencies, resolved, executorModel, executorEffort, manifest, parentSignal, timeoutMs, publish) => {
3796
+ var streamScoutResponse = async (dependencies, resolved, executorModel, executorEffort, sessionId, manifest, parentSignal, timeoutMs, publish) => {
3791
3797
  const { abortPromise, controller, teardown, wasTimedOut } = setupAbortWatch(parentSignal, timeoutMs);
3792
3798
  try {
3793
3799
  const collection = dependencies.collect(resolved, {
@@ -3798,6 +3804,7 @@ var streamScoutResponse = async (dependencies, resolved, executorModel, executor
3798
3804
  }
3799
3805
  },
3800
3806
  reasoning: executorEffort,
3807
+ sessionId,
3801
3808
  signal: controller.signal,
3802
3809
  systemPrompt: SCOUT_SYSTEM
3803
3810
  });
@@ -3855,7 +3862,7 @@ var runAdvisorScout = async (ctx, manifest, parentSignal, onEvent, timeoutMs = a
3855
3862
  return cancelled();
3856
3863
  }
3857
3864
  publish({ model: executorModel, type: "call" });
3858
- const streamed = await streamScoutResponse(dependencies, resolved, executorModel, executorEffort, manifest, parentSignal, timeoutMs, publish);
3865
+ const streamed = await streamScoutResponse(dependencies, resolved, executorModel, executorEffort, currentSessionId(ctx), manifest, parentSignal, timeoutMs, publish);
3859
3866
  if (!streamed.ok) {
3860
3867
  if (parentSignal?.aborted) {
3861
3868
  return cancelled();
@@ -4337,6 +4344,7 @@ var runAdvisorAttempt = async (options, prepared, resolved, modelRef) => {
4337
4344
  messages: structuredClone(prepared.messages),
4338
4345
  onChunk: options.onChunk,
4339
4346
  reasoning: advisorEffortRef,
4347
+ sessionId: currentSessionId(options.ctx),
4340
4348
  signal: options.signal,
4341
4349
  systemPrompt: prepared.systemPrompt
4342
4350
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-advisor-flow",
3
- "version": "0.14.5-dev.3",
3
+ "version": "0.14.5-dev.5",
4
4
  "description": "Advanced Executor/Advisor flow for Pi, fully configurable and extendable.",
5
5
  "keywords": [
6
6
  "advisor",
@@ -52,6 +52,12 @@ export const resolveConfiguredModel = async (
52
52
  };
53
53
  }
54
54
 
55
+ if (model.api === "pi-virtual") {
56
+ throw new Error(
57
+ `Pi virtual model ${ref} requires modelRegistry.streamSimple, which is unavailable in this Pi runtime. Update Pi or select a physical ${label} model.`
58
+ );
59
+ }
60
+
55
61
  const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
56
62
 
57
63
  if (!auth.ok) {
@@ -75,6 +81,7 @@ export interface CollectTextStreamOptions {
75
81
  messages: Message[];
76
82
  onChunk?: (thinking: string, text: string) => void;
77
83
  reasoning?: string;
84
+ sessionId?: string;
78
85
  signal?: AbortSignal;
79
86
  systemPrompt: string;
80
87
  }
@@ -250,6 +257,7 @@ const createTextEventStream = (
250
257
  if (!streamModel && resolved.streamSimple) {
251
258
  return resolved.streamSimple(resolved.model, context, {
252
259
  reasoning: toSimpleReasoning(options.reasoning),
260
+ sessionId: options.sessionId,
253
261
  signal: options.signal,
254
262
  });
255
263
  }
@@ -259,6 +267,7 @@ const createTextEventStream = (
259
267
  env: resolved.env,
260
268
  headers: resolved.headers,
261
269
  reasoning: options.reasoning,
270
+ sessionId: options.sessionId,
262
271
  signal: options.signal,
263
272
  };
264
273
 
package/src/scout.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  SCOUT_SYNTHESIS_MAX_BYTES,
20
20
  } from "./scout-types.ts";
21
21
  import type { ScoutManifest } from "./scout-types.ts";
22
+ import { currentSessionId } from "./session-context.ts";
22
23
  import { snapshotAdvisorUsage } from "./usage.ts";
23
24
  import type { AdvisorUsageSnapshot } from "./usage.ts";
24
25
 
@@ -281,6 +282,7 @@ const streamScoutResponse = async (
281
282
  resolved: ResolvedConfiguredModel,
282
283
  executorModel: string,
283
284
  executorEffort: string | undefined,
285
+ sessionId: string | undefined,
284
286
  manifest: ScoutManifest,
285
287
  parentSignal: AbortSignal | undefined,
286
288
  timeoutMs: number,
@@ -300,6 +302,7 @@ const streamScoutResponse = async (
300
302
  }
301
303
  },
302
304
  reasoning: executorEffort,
305
+ sessionId,
303
306
  signal: controller.signal,
304
307
  systemPrompt: SCOUT_SYSTEM,
305
308
  });
@@ -395,6 +398,7 @@ export const runAdvisorScout = async (
395
398
  resolved,
396
399
  executorModel,
397
400
  executorEffort,
401
+ currentSessionId(ctx),
398
402
  manifest,
399
403
  parentSignal,
400
404
  timeoutMs,
@@ -51,6 +51,10 @@ const projectBranch = (source: SessionEntry[]): SessionEntry[] => {
51
51
  return [...projected, ...branch.slice(compactionIndex + 1)];
52
52
  };
53
53
 
54
+ export const currentSessionId = (ctx: {
55
+ sessionManager?: { getSessionId?: () => string };
56
+ }): string | undefined => ctx.sessionManager?.getSessionId?.();
57
+
54
58
  export const sessionContextEntries = (
55
59
  ctx: ExtensionContext
56
60
  ): SessionEntry[] => {
@@ -17,6 +17,7 @@ import type { GitContextLevel } from "../git.ts";
17
17
  import { collectTextStream, resolveConfiguredModel } from "../model-stream.ts";
18
18
  import { redactSecrets } from "../redaction.ts";
19
19
  import type { ScoutLifecycleEvent } from "../scout.ts";
20
+ import { currentSessionId } from "../session-context.ts";
20
21
  import type { ConsultationTrigger, GateTrigger } from "../session-state.ts";
21
22
  import { assembleConsultationContext } from "./consult-context.ts";
22
23
  import type { ConsultationContext } from "./consult-context.ts";
@@ -282,6 +283,7 @@ const runAdvisorAttempt = async (
282
283
  messages: structuredClone(prepared.messages),
283
284
  onChunk: options.onChunk,
284
285
  reasoning: advisorEffortRef,
286
+ sessionId: currentSessionId(options.ctx),
285
287
  signal: options.signal,
286
288
  systemPrompt: prepared.systemPrompt,
287
289
  });