fix(pi): keep thinking defaults specific to each model (#17835)

This commit is contained in:
Wout Stiens authored and GitHub committed 2026-10-10 17:47:45 -05:00
1 parent 7e8071f1f1
commit 160b18c866
3 files changed
+62 -16

No files matched your search

+2 -1
View File
@@ -36,7 +36,8 @@ update it through that manager instead. For example, a Nix profile installation
## What Carries Over
T3 Code discovers the models reported by Pi and exposes their supported thinking levels. The
thinking picker marks Pi's current configured level as the default without overriding it. Threads
thinking picker marks the discovered active model's configured level as its default without
overriding it. Other models keep their Pi defaults when no level is selected. Threads
use Pi's native session files for resume, rollback, and forks within the same Pi instance. Forks
preserve the native conversation through the selected turn in the destination workspace.
Switching providers uses portable conversation context. Extension
+49 -6
View File
@@ -47,7 +47,9 @@ const personalSkill = {
};
// Respond through the real stdio transport, with a distinct command catalog for each cwd.
const makePiSpawner = Effect.gen(function* () {
const makePiSpawner = Effect.fnUntraced(function* (
discovery: { readonly state?: unknown; readonly models?: ReadonlyArray<unknown> } = {},
) {
const pendingCommand = yield* Deferred.make<void>();
const launches: Array<ChildProcess.StandardCommand> = [];
const spawner = ChildProcessSpawner.make((command) =>
@@ -92,8 +94,10 @@ const makePiSpawner = Effect.gen(function* () {
],
}
: request.type === "get_available_models"
? { models: [{ provider: "test", id: "model" }] }
: {};
? { models: discovery.models ?? [{ provider: "test", id: "model" }] }
: request.type === "get_state"
? (discovery.state ?? {})
: {};
return Queue.offer(
stdout,
encoder.encode(
@@ -125,7 +129,7 @@ const create = (config: Partial<PiSettings> = {}, enabled = true) =>
it.layer(layerTest)("PiDriver workspace discovery", (it) => {
it.effect("keeps each workspace's skills and commands separate from the machine catalog", () =>
Effect.gen(function* () {
const { spawner, launches } = yield* makePiSpawner;
const { spawner, launches } = yield* makePiSpawner();
const instance = yield* create({ launchArgs: '--approve --skill "extra skill"' }).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
);
@@ -186,11 +190,50 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
}).pipe(Effect.scoped),
);
it.effect.each([true, false])(
"limits discovered thinking defaults to the known active model, known=%s",
(known) =>
Effect.gen(function* () {
const { spawner } = yield* makePiSpawner({
state: {
thinkingLevel: "high",
...(known ? { model: { provider: "test", id: "model" } } : {}),
},
models: [
{ provider: "test", id: "model", reasoning: true },
{ provider: "other", id: "model", reasoning: true },
{ provider: "test", id: "other", reasoning: true },
],
});
const instance = yield* create().pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
);
yield* instance.snapshot.refresh;
const snapshot = yield* instance.snapshot.getSnapshot;
assert.deepEqual(
snapshot.models.map((model) => [
model.slug,
(model.capabilities?.optionDescriptors ?? []).flatMap((descriptor) =>
descriptor.type === "select"
? descriptor.options.filter((option) => option.isDefault).map((option) => option.id)
: [],
),
]),
[
["default", []],
["test/model", known ? ["high"] : []],
["other/model", []],
["test/other", []],
],
);
}).pipe(Effect.scoped),
);
it.effect(
"fails command discovery instead of returning an empty successful workspace catalog",
() =>
Effect.gen(function* () {
const { spawner } = yield* makePiSpawner;
const { spawner } = yield* makePiSpawner();
const instance = yield* create().pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
);
@@ -208,7 +251,7 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
it.effect("times out workspace discovery that needs interactive input", () =>
Effect.gen(function* () {
const { spawner, pendingCommand } = yield* makePiSpawner;
const { spawner, pendingCommand } = yield* makePiSpawner();
const instance = yield* create().pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
);
+11 -9
View File
@@ -101,12 +101,12 @@ function piModelsFromSettings(
);
}
function parseDiscoveredModels(
data: unknown,
defaultThinkingLevel: unknown,
): ReadonlyArray<ServerProviderModel> {
function parseDiscoveredModels(data: unknown, state: unknown): ReadonlyArray<ServerProviderModel> {
const models = recordField(data, "models");
if (!Array.isArray(models)) return [];
const activeModel = recordField(state, "model");
const activeProvider = recordString(activeModel, "provider");
const activeModelId = recordString(activeModel, "id");
const seen = new Set<string>();
const parsed: Array<ServerProviderModel> = [];
for (const model of models) {
@@ -121,7 +121,12 @@ function parseDiscoveredModels(
name: recordString(model, "name") ?? slug,
subProvider: provider,
isCustom: false,
capabilities: thinkingCapabilitiesForPiModel(model, defaultThinkingLevel),
capabilities: thinkingCapabilitiesForPiModel(
model,
provider === activeProvider && id === activeModelId
? recordString(state, "thinkingLevel")
: undefined,
),
});
}
return parsed;
@@ -167,10 +172,7 @@ const discoverPiViaRpc = (
const commandsData = yield* connection
.request({ type: "get_commands" })
.pipe(Effect.orElseSucceed(() => undefined));
const discoveredModels = parseDiscoveredModels(
modelsData,
recordString(stateData, "thinkingLevel"),
);
const discoveredModels = parseDiscoveredModels(modelsData, stateData);
const { slashCommands, skills } = parsePiDiscoveredCommands(commandsData);
return {
models: discoveredModels,