GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(pi): link Pi enabledModels with T3 model preferences · pechhe/t3code@7a00e75

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/provider
    • ProviderHostLive.ts
  • fork
    • differences.md
  • packages
    • provider-core/src/server
      • ProviderHost.ts
    • provider-pi/src/server
      • driver.test.ts
      • driver.ts
      • enabledModels.test.ts
      • enabledModels.ts
    • provider-testing/src
      • TestProviderHost.ts
    • shared/src
      • serverSettings.test.ts
      • serverSettings.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/provider/ProviderHostLive.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/ProviderHostLive.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const layer = Layer.effect(
3838
},
3939
settings: {
4040
get: serverSettings.getSettings,
41+
update: serverSettings.updateSettings,
4142
withSnapshot: serverSettings.withSettingsSnapshot,
4243
changes: serverSettings.streamChanges,
4344
subscribe: serverSettings.subscribeChanges,
Collapse file

‎fork/differences.md‎

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 numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ Seeded from `git diff 9c161462c9 d1d4354daf` (≈813 files, 265 non-merge commit
100100

101101
- **Kind:** durable extension
102102
- **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.
106106
- **Upstream:** none; upstream has the text generation model and no Pi Blackhole integration.
107107
- **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.
108108

Collapse file

‎packages/provider-core/src/server/ProviderHost.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/ProviderHost.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
ChatAttachment,
44
ServerSettings,
55
ServerSettingsError,
6+
ServerSettingsPatch,
67
} from "@t3tools/contracts";
78
import * as Context from "effect/Context";
89
import type * as Effect from "effect/Effect";
@@ -35,6 +36,9 @@ export class ProviderHost extends Context.Service<
3536
readonly paths: ProviderHostPaths;
3637
readonly settings: {
3738
readonly get: Effect.Effect<ServerSettings, ServerSettingsError>;
39+
readonly update?: (
40+
patch: ServerSettingsPatch,
41+
) => Effect.Effect<ServerSettings, ServerSettingsError>;
3842
/** Runs `use` on a settings snapshot that no settings write can change until it finishes. */
3943
readonly withSnapshot: <A, E, R>(
4044
use: (settings: ServerSettings) => Effect.Effect<A, E, R>,
Collapse file

‎packages/provider-pi/src/server/driver.test.ts‎

Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/driver.test.ts
+78Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
33
import { assert, it } from "@effect/vitest";
44
import { DEFAULT_SERVER_SETTINGS, ProviderInstanceId } from "@t3tools/contracts";
5+
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
56
import * as Deferred from "effect/Deferred";
7+
import * as FileSystem from "effect/FileSystem";
68
import * as Effect from "effect/Effect";
79
import * as Layer from "effect/Layer";
810
import * as Queue from "effect/Queue";
@@ -242,6 +244,82 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
242244
}),
243245
);
244246

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+
245323
it.effect(
246324
"fails command discovery instead of returning an empty successful workspace catalog",
247325
() =>
Collapse file

‎packages/provider-pi/src/server/driver.ts‎

Copy file name to clipboardExpand all lines: packages/provider-pi/src/server/driver.ts
+81-1Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
import {
33
ProviderDriverKind,
44
type ServerProvider,
5+
type ServerProviderModel,
56
type ServerProviderUsageSlot,
7+
type ServerSettings,
68
} from "@t3tools/contracts";
79
import { PiSettings } from "../settings.ts";
810
import * as DateTime from "effect/DateTime";
911
import * as Effect from "effect/Effect";
12+
import * as Equal from "effect/Equal";
1013
import * as FileSystem from "effect/FileSystem";
1114
import * as Path from "effect/Path";
1215
import * as Ref from "effect/Ref";
1316
import * as Digest from "effect/crypto/Digest";
1417
import * as Schema from "effect/Schema";
18+
import * as Stream from "effect/Stream";
1519
import * as HttpClient from "effect/http/HttpClient";
1620
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1721

@@ -23,6 +27,7 @@ import {
2327
probePiUsageSlots,
2428
retainPriorUsageSlots,
2529
} from "./usageSlots.ts";
30+
import { reconcilePiScopedModels } from "./enabledModels.ts";
2631
import { makePiTextGeneration } from "./textGeneration.ts";
2732
import { PiAdapterV2Driver, type PiAdapterV2DriverEnv } from "./adapter.ts";
2833
import { ProviderDriverError } from "@t3tools/provider-core/server/errors";
@@ -87,6 +92,16 @@ const withInstanceIdentity =
8792
continuation: { groupKey: input.continuationGroupKey },
8893
});
8994

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+
90105
export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = {
91106
driverKind: DRIVER_KIND,
92107
metadata: {
@@ -156,6 +171,28 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = {
156171
);
157172
const textGeneration = yield* makePiTextGeneration(effectiveConfig, processEnv);
158173

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+
159196
const checkProvider = fileSystem
160197
.makeDirectory(probeCwd, { recursive: true })
161198
.pipe(
@@ -203,7 +240,10 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = {
203240
haveSettingsChanged: haveProviderSnapshotSettingsChanged,
204241
initialSnapshot: (settings) =>
205242
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+
),
207247
enrichSnapshot: ({ settings, snapshot: currentSnapshot, publishSnapshot }) =>
208248
resolveMaintenance().pipe(
209249
Effect.flatMap((maintenanceCapabilities) =>
@@ -229,6 +269,45 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = {
229269
),
230270
);
231271

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+
232311
// Re-reads every account's allowance alone; a probe that cannot read credentials changes nothing.
233312
const refreshUsage = Effect.gen(function* () {
234313
if (!effectiveConfig.enabled) return;
@@ -271,6 +350,7 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = {
271350
Effect.map(([machineSnapshot, commands]) => ({
272351
...machineSnapshot,
273352
...commands,
353+
274354
slashCommandsPending: false,
275355
})),
276356
),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.