GeezerVison is showing github.com — feat(pi): link Pi enabledModels with T3 model preferences · pechhe/t3code@7a00e75
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/provider/ProviderHostLive.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,7 @@ export const layer = Layer.effect( | 38 | 38 | }, | 39 | 39 | settings: { | 40 | 40 | get: serverSettings.getSettings, | | 41 | + update: serverSettings.updateSettings, | 41 | 42 | withSnapshot: serverSettings.withSettingsSnapshot, | 42 | 43 | changes: serverSettings.streamChanges, | 43 | 44 | subscribe: serverSettings.subscribeChanges, | |
Collapse file Copy file name to clipboardExpand all lines: fork/differences.md +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -100,9 +100,9 @@ Seeded from `git diff 9c161462c9 d1d4354daf` (≈813 files, 265 non-merge commit | 100 | 100 |
| 101 | 101 | - **Kind:** durable extension | 102 | 102 | - **Why:** Background work should run on one cheap model the user picks once. Pi Blackhole's memory worker (observation, reflection, compaction) reads its model only from its own config, so it drifted from the model T3 uses for titles and other generated text. | 103 | | -- **Requirements:** Settings → Threads names `textGenerationModelSelection` the **Utility model** (key, search id and project scoping unchanged); source control, voice cleanup and review guides still follow it unless set. Its picker is the composer's: pooled models (a pooled pick keeps the account the selection is on, else takes the first in the user's order) and every Pi model, including those a Pi extension or package registers; Pi text generation starts with `--no-extensions` and, when the chosen model is missing from that launch, relaunches once with extensions loaded and tools and MCP still off. `RuntimePolicyV2` passes the environment's Utility model with its instance's driver as `utilityModel`. Before a Pi session's first turn the Pi adapter writes the memory worker's model into `<agentDir>/pi-blackhole/pi-blackhole-config.json`: the Utility model when its driver is Pi (with its thinking option), else the Pi instance's `memoryModel` setting (a picker over that instance's models, Settings → Providers → Pi → Memory worker), and restarts the process it just opened when anything changed, alongside the compaction point. Other keys of the config's `model` (such as `thinking`) are kept. `.t3-model-override.json` beside the config records what T3 replaced and wrote; with neither choice the original returns, unless someone changed the model since (compared by provider, id and thinking, not by serialisation), and the record is removed only after the restore is written. A new model builds on the user's original `model` keys, never on T3's earlier write. Slugs resolve through Pi's reported models, since provider names may contain `/`; nothing changed means no restart. No config file means Pi Blackhole is not installed there, and nothing is written. The config is per agent directory: Pi instances sharing one share the Memory worker, and the environment-level Utility model is used, never a project override. The session's single model inventory (`discoverModels`) is fetched early only when a choice exists and Pi Blackhole is installed. | 104 | | -- **Integration points:** `makePiTextGeneration`'s relaunch in packages/provider-pi/src/server/textGeneration.ts and `buildPiRpcLaunch`'s `disableMcp` (mcpInjection.ts), which adds `--no-mcp` only beside `--no-tools` and alone keeps MCP servers off in that extensions-on relaunch; `modelPickerPooling` (apps/web/src/components/chat/useComposerPooling.ts) feeding the Settings picker; `ProviderAdapterV2RuntimePolicy.utilityModel` (provider-core), `RuntimePolicyV2`, `PiSettings.memoryModel`, `syncPiBlackholeModel` (packages/provider-pi/src/server/blackhole.ts) using the settings lock in `compaction.ts`, the Pi adapter's session-open preparation; `ProviderSettingsFormAnnotation.modelOptions` with an optional `instanceKey` (absent: this account's models only) and `ProviderSettingsModelPicker`; Pi Blackhole's config path and `model` shape (`provider`, `id`, `thinking`). | 105 | | -- **Proof:** packages/provider-pi/src/server/blackhole.test.ts, adapter.test.ts ("memory worker"), textGeneration.test.ts ("relaunches with extensions"), apps/server/src/orchestration-v2/RuntimePolicy.test.ts ("Utility model's driver"); the pooled picker by capture only. | | 103 | +- **Requirements:** Settings → Threads names `textGenerationModelSelection` the **Utility model** (key, search id and project scoping unchanged); source control, voice cleanup and review guides still follow it unless set. Its picker is the composer's: pooled models (a pooled pick keeps the account the selection is on, else takes the first in the user's order) and every Pi model, including those a Pi extension or package registers; Pi text generation starts with `--no-extensions` and, when the chosen model is missing from that launch, relaunches once with extensions loaded and tools and MCP still off. `RuntimePolicyV2` passes the environment's Utility model with its instance's driver as `utilityModel`. Before a Pi session's first turn the Pi adapter writes the memory worker's model into `<agentDir>/pi-blackhole/pi-blackhole-config.json`: the Utility model when its driver is Pi (with its thinking option), else the Pi instance's `memoryModel` setting (a picker over that instance's models, Settings → Providers → Pi → Memory worker), and restarts the process it just opened when anything changed, alongside the compaction point. Other keys of the config's `model` (such as `thinking`) are kept. `.t3-model-override.json` beside the config records what T3 replaced and wrote; with neither choice the original returns, unless someone changed the model since (compared by provider, id and thinking, not by serialisation), and the record is removed only after the restore is written. A new model builds on the user's original `model` keys, never on T3's earlier write. Slugs resolve through Pi's reported models, since provider names may contain `/`; nothing changed means no restart. No config file means Pi Blackhole is not installed there, and nothing is written. The config is per agent directory: Pi instances sharing one share the Memory worker, and the environment-level Utility model is used, never a project override. The session's single model inventory (`discoverModels`) is fetched early only when a choice exists and Pi Blackhole is installed. When `<agentDir>/settings.json` defines `enabledModels` (`/scoped-models`), T3 links it with the Pi instance's `providerModelPreferences`: models outside `enabledModels` (including newly added provider catalog models) are placed in `hiddenModels`, `modelOrder` starts with the enabled list, starring a hidden model unhides it, and editing visibility, order or favorites in T3 writes `enabledModels` back under the Pi settings lock (preserving `:thinkingLevel` suffixes and unmatched patterns). | | 104 | +- **Integration points:** `makePiTextGeneration`'s relaunch in packages/provider-pi/src/server/textGeneration.ts and `buildPiRpcLaunch`'s `disableMcp` (mcpInjection.ts), which adds `--no-mcp` only beside `--no-tools` and alone keeps MCP servers off in that extensions-on relaunch; `modelPickerPooling` (apps/web/src/components/chat/useComposerPooling.ts) feeding the Settings picker; `ProviderAdapterV2RuntimePolicy.utilityModel` (provider-core), `RuntimePolicyV2`, `PiSettings.memoryModel`, `syncPiBlackholeModel` (packages/provider-pi/src/server/blackhole.ts) using the settings lock in `compaction.ts`, `reconcilePiScopedModels` (packages/provider-pi/src/server/enabledModels.ts) and `ProviderHost.settings.update`, the Pi adapter's session-open preparation; `ProviderSettingsFormAnnotation.modelOptions` with an optional `instanceKey` (absent: this account's models only) and `ProviderSettingsModelPicker`; Pi Blackhole's config path and `model` shape (`provider`, `id`, `thinking`). | | 105 | +- **Proof:** packages/provider-pi/src/server/enabledModels.test.ts, driver.test.ts ("links Pi enabledModels"), packages/shared/src/serverSettings.test.ts ("unhides a hidden model when it is starred"), packages/provider-pi/src/server/blackhole.test.ts, adapter.test.ts ("memory worker"), textGeneration.test.ts ("relaunches with extensions"), apps/server/src/orchestration-v2/RuntimePolicy.test.ts ("Utility model's driver"); the pooled picker by capture only. | 106 | 106 | - **Upstream:** none; upstream has the text generation model and no Pi Blackhole integration. | 107 | 107 | - **Retire when:** Pi Blackhole takes its model from the session (an env override or RPC), or upstream ships a utility model that reaches Pi extensions. | 108 | 108 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-core/src/server/ProviderHost.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import type { | 3 | 3 | ChatAttachment, | 4 | 4 | ServerSettings, | 5 | 5 | ServerSettingsError, | | 6 | + ServerSettingsPatch, | 6 | 7 | } from "@t3tools/contracts"; | 7 | 8 | import * as Context from "effect/Context"; | 8 | 9 | import type * as Effect from "effect/Effect"; | @@ -35,6 +36,9 @@ export class ProviderHost extends Context.Service< | 35 | 36 | readonly paths: ProviderHostPaths; | 36 | 37 | readonly settings: { | 37 | 38 | readonly get: Effect.Effect<ServerSettings, ServerSettingsError>; | | 39 | + readonly update?: ( | | 40 | + patch: ServerSettingsPatch, | | 41 | + ) => Effect.Effect<ServerSettings, ServerSettingsError>; | 38 | 42 | /** Runs `use` on a settings snapshot that no settings write can change until it finishes. */ | 39 | 43 | readonly withSnapshot: <A, E, R>( | 40 | 44 | use: (settings: ServerSettings) => Effect.Effect<A, E, R>, | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/driver.test.ts +78Lines changed: 78 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,9 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; | 2 | 2 | import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; | 3 | 3 | import { assert, it } from "@effect/vitest"; | 4 | 4 | import { DEFAULT_SERVER_SETTINGS, ProviderInstanceId } from "@t3tools/contracts"; | | 5 | +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; | 5 | 6 | import * as Deferred from "effect/Deferred"; | | 7 | +import * as FileSystem from "effect/FileSystem"; | 6 | 8 | import * as Effect from "effect/Effect"; | 7 | 9 | import * as Layer from "effect/Layer"; | 8 | 10 | import * as Queue from "effect/Queue"; | @@ -242,6 +244,82 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => { | 242 | 244 | }), | 243 | 245 | ); | 244 | 246 |
| | 247 | + it.effect( | | 248 | + "links Pi enabledModels in settings.json with T3 providerModelPreferences in both directions", | | 249 | + () => | | 250 | + Effect.gen(function* () { | | 251 | + const fs = yield* FileSystem.FileSystem; | | 252 | + const agentDir = yield* fs.makeTempDirectoryScoped({ prefix: "pi-driver-scoped-" }); | | 253 | + const settingsPath = `${agentDir}/settings.json`; | | 254 | + yield* fs.writeFileString( | | 255 | + settingsPath, | | 256 | + JSON.stringify({ | | 257 | + enabledModels: ["test/model:high"], | | 258 | + }), | | 259 | + ); | | 260 | + const { spawner } = yield* makePiSpawner({ | | 261 | + models: [ | | 262 | + { provider: "test", id: "model" }, | | 263 | + { provider: "openrouter", id: "google/gemini-4-neon" }, | | 264 | + { provider: "openrouter", id: "google/gemini-4-neon:batch" }, | | 265 | + ], | | 266 | + }); | | 267 | + const host = yield* ProviderHost.ProviderHost; | | 268 | + const instanceId = ProviderInstanceId.make("pi-workspace-test"); | | 269 | + const settingsWritten = yield* Deferred.make<void>(); | | 270 | + const realWriteFileString = fs.writeFileString; | | 271 | + const watchedFs = FileSystem.FileSystem.of({ | | 272 | + ...fs, | | 273 | + writeFileString: (path, data, options) => | | 274 | + realWriteFileString(path, data, options).pipe( | | 275 | + Effect.tap(() => | | 276 | + path === settingsPath | | 277 | + ? Deferred.succeed(settingsWritten, undefined).pipe(Effect.asVoid) | | 278 | + : Effect.void, | | 279 | + ), | | 280 | + ), | | 281 | + }); | | 282 | + const instance = yield* PiDriver.create({ | | 283 | + instanceId, | | 284 | + displayName: "My Pi", | | 285 | + accentColor: "#abcdef", | | 286 | + environment: [{ name: "PI_CODING_AGENT_DIR", value: agentDir, sensitive: false }], | | 287 | + enabled: true, | | 288 | + config: { ...PiDriver.defaultConfig(), binaryPath: "custom-pi" }, | | 289 | + }).pipe( | | 290 | + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), | | 291 | + Effect.provideService(FileSystem.FileSystem, watchedFs), | | 292 | + ); | | 293 | + | | 294 | + yield* instance.snapshot.refresh; | | 295 | + const afterProbe = yield* host.settings.get; | | 296 | + assert.deepEqual(afterProbe.providerModelPreferences?.[instanceId], { | | 297 | + hiddenModels: [ | | 298 | + "openrouter/google/gemini-4-neon", | | 299 | + "openrouter/google/gemini-4-neon:batch", | | 300 | + ], | | 301 | + modelOrder: ["test/model"], | | 302 | + }); | | 303 | + | | 304 | + // Toggling a model on in T3 writes back to Pi's settings.json. | | 305 | + yield* host.settings.update!({ | | 306 | + setModelsHidden: [ | | 307 | + { | | 308 | + provider: instanceId, | | 309 | + model: "openrouter/google/gemini-4-neon", | | 310 | + hidden: false, | | 311 | + }, | | 312 | + ], | | 313 | + }); | | 314 | + yield* Deferred.await(settingsWritten); | | 315 | + const written = JSON.parse(yield* fs.readFileString(settingsPath)); | | 316 | + assert.deepEqual(written.enabledModels, [ | | 317 | + "test/model:high", | | 318 | + "openrouter/google/gemini-4-neon", | | 319 | + ]); | | 320 | + }), | | 321 | + ); | | 322 | + | 245 | 323 | it.effect( | 246 | 324 | "fails command discovery instead of returning an empty successful workspace catalog", | 247 | 325 | () => | |
Collapse file Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/driver.ts +81-1Lines changed: 81 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | import { | 3 | 3 | ProviderDriverKind, | 4 | 4 | type ServerProvider, | | 5 | + type ServerProviderModel, | 5 | 6 | type ServerProviderUsageSlot, | | 7 | + type ServerSettings, | 6 | 8 | } from "@t3tools/contracts"; | 7 | 9 | import { PiSettings } from "../settings.ts"; | 8 | 10 | import * as DateTime from "effect/DateTime"; | 9 | 11 | import * as Effect from "effect/Effect"; | | 12 | +import * as Equal from "effect/Equal"; | 10 | 13 | import * as FileSystem from "effect/FileSystem"; | 11 | 14 | import * as Path from "effect/Path"; | 12 | 15 | import * as Ref from "effect/Ref"; | 13 | 16 | import * as Digest from "effect/crypto/Digest"; | 14 | 17 | import * as Schema from "effect/Schema"; | | 18 | +import * as Stream from "effect/Stream"; | 15 | 19 | import * as HttpClient from "effect/http/HttpClient"; | 16 | 20 | import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; | 17 | 21 |
| @@ -23,6 +27,7 @@ import { | 23 | 27 | probePiUsageSlots, | 24 | 28 | retainPriorUsageSlots, | 25 | 29 | } from "./usageSlots.ts"; | | 30 | +import { reconcilePiScopedModels } from "./enabledModels.ts"; | 26 | 31 | import { makePiTextGeneration } from "./textGeneration.ts"; | 27 | 32 | import { PiAdapterV2Driver, type PiAdapterV2DriverEnv } from "./adapter.ts"; | 28 | 33 | import { ProviderDriverError } from "@t3tools/provider-core/server/errors"; | @@ -87,6 +92,16 @@ const withInstanceIdentity = | 87 | 92 | continuation: { groupKey: input.continuationGroupKey }, | 88 | 93 | }); | 89 | 94 |
| | 95 | +const piInstanceModelPreferenceView = ( | | 96 | + settings: ServerSettings, | | 97 | + instanceId: ProviderInstance["instanceId"], | | 98 | +) => ({ | | 99 | + preferences: settings.providerModelPreferences?.[instanceId], | | 100 | + favorites: (settings.favorites ?? []) | | 101 | + .filter((favorite) => favorite.provider === instanceId) | | 102 | + .map((favorite) => favorite.model), | | 103 | +}); | | 104 | + | 90 | 105 | export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = { | 91 | 106 | driverKind: DRIVER_KIND, | 92 | 107 | metadata: { | @@ -156,6 +171,28 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = { | 156 | 171 | ); | 157 | 172 | const textGeneration = yield* makePiTextGeneration(effectiveConfig, processEnv); | 158 | 173 |
| | 174 | + const lastDiscoveredModelsRef = yield* Ref.make<ReadonlyArray<ServerProviderModel>>([]); | | 175 | + const syncScopedModelsFromPi = Effect.fn("PiDriver.syncScopedModelsFromPi")(function* ( | | 176 | + snapshot: ServerProvider, | | 177 | + ) { | | 178 | + if (!effectiveConfig.enabled || snapshot.auth.status !== "authenticated") { | | 179 | + return snapshot; | | 180 | + } | | 181 | + yield* Ref.set(lastDiscoveredModelsRef, snapshot.models); | | 182 | + yield* reconcilePiScopedModels({ | | 183 | + instanceId, | | 184 | + environment: processEnv, | | 185 | + discoveredModels: snapshot.models, | | 186 | + getSettings: host.settings.get, | | 187 | + updateSettings: host.settings.update, | | 188 | + direction: "from-pi", | | 189 | + }).pipe( | | 190 | + Effect.provideService(FileSystem.FileSystem, fileSystem), | | 191 | + Effect.ignoreCause({ log: true }), | | 192 | + ); | | 193 | + return snapshot; | | 194 | + }); | | 195 | + | 159 | 196 | const checkProvider = fileSystem | 160 | 197 | .makeDirectory(probeCwd, { recursive: true }) | 161 | 198 | .pipe( | @@ -203,7 +240,10 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = { | 203 | 240 | haveSettingsChanged: haveProviderSnapshotSettingsChanged, | 204 | 241 | initialSnapshot: (settings) => | 205 | 242 | buildInitialPiProviderSnapshot(settings.provider).pipe(Effect.map(stampIdentity)), | 206 | | - checkProvider: checkProvider.pipe(Effect.flatMap(attachUsageSlots)), | | 243 | + checkProvider: checkProvider.pipe( | | 244 | + Effect.flatMap(syncScopedModelsFromPi), | | 245 | + Effect.flatMap(attachUsageSlots), | | 246 | + ), | 207 | 247 | enrichSnapshot: ({ settings, snapshot: currentSnapshot, publishSnapshot }) => | 208 | 248 | resolveMaintenance().pipe( | 209 | 249 | Effect.flatMap((maintenanceCapabilities) => | @@ -229,6 +269,45 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = { | 229 | 269 | ), | 230 | 270 | ); | 231 | 271 |
| | 272 | + const initialPreferenceView = yield* host.settings.get.pipe( | | 273 | + Effect.map((current) => piInstanceModelPreferenceView(current, instanceId)), | | 274 | + Effect.orElseSucceed(() => undefined), | | 275 | + ); | | 276 | + const settingsChanges = yield* host.settings.subscribe; | | 277 | + yield* ( | | 278 | + initialPreferenceView === undefined | | 279 | + ? settingsChanges.pipe( | | 280 | + Stream.map((current) => piInstanceModelPreferenceView(current, instanceId)), | | 281 | + Stream.changesWith(Equal.equals), | | 282 | + ) | | 283 | + : Stream.concat( | | 284 | + Stream.make(initialPreferenceView), | | 285 | + settingsChanges.pipe( | | 286 | + Stream.map((current) => piInstanceModelPreferenceView(current, instanceId)), | | 287 | + ), | | 288 | + ).pipe(Stream.changesWith(Equal.equals), Stream.drop(1)) | | 289 | + ).pipe( | | 290 | + Stream.runForEach(() => | | 291 | + Ref.get(lastDiscoveredModelsRef).pipe( | | 292 | + Effect.flatMap((discoveredModels) => | | 293 | + discoveredModels.length === 0 | | 294 | + ? Effect.void | | 295 | + : reconcilePiScopedModels({ | | 296 | + instanceId, | | 297 | + environment: processEnv, | | 298 | + discoveredModels, | | 299 | + getSettings: host.settings.get, | | 300 | + direction: "to-pi", | | 301 | + }).pipe( | | 302 | + Effect.provideService(FileSystem.FileSystem, fileSystem), | | 303 | + Effect.ignoreCause({ log: true }), | | 304 | + ), | | 305 | + ), | | 306 | + ), | | 307 | + ), | | 308 | + Effect.forkScoped, | | 309 | + ); | | 310 | + | 232 | 311 | // Re-reads every account's allowance alone; a probe that cannot read credentials changes nothing. | 233 | 312 | const refreshUsage = Effect.gen(function* () { | 234 | 313 | if (!effectiveConfig.enabled) return; | @@ -271,6 +350,7 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = { | 271 | 350 | Effect.map(([machineSnapshot, commands]) => ({ | 272 | 351 | ...machineSnapshot, | 273 | 352 | ...commands, | | 353 | + | 274 | 354 | slashCommandsPending: false, | 275 | 355 | })), | 276 | 356 | ), | |
|