@evandu/super-pi 0.1.190 → 0.1.191
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.
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"src/client/types.ts": "ef0586e206d0f229ed0e81e72397e1ddfd82c00ae7133d06d20892605e6f1ff4",
|
|
41
41
|
"src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5"
|
|
42
42
|
},
|
|
43
|
-
"recordedAt": "2026-11-
|
|
43
|
+
"recordedAt": "2026-11-11T21:28:42.047Z"
|
|
44
44
|
}
|
|
@@ -78,3 +78,37 @@ export declare function readStoreWindows(agentDir: string): ModelStore;
|
|
|
78
78
|
* taking the smallest is exactly how a million-token model ended up believing it had 128,000.
|
|
79
79
|
*/
|
|
80
80
|
export declare function arbitrateContextWindow(declared: Map<string, number>, store: ModelStore, provider: string, modelId: string, reported?: number): number | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
|
|
83
|
+
*
|
|
84
|
+
* WHY THIS IS A FUNCTION AND NOT A CLOSURE. The rule above is a pure function, and it has had a gate
|
|
85
|
+
* for a while - but the rule is only HALF of the runtime path. The other half is the code that reads
|
|
86
|
+
* the two files, asks the model runtime for the whole model object, and hands that object to Pi.
|
|
87
|
+
* That half lived inside `pi-session.ts` as an inline closure, where nothing could reach it: the pure
|
|
88
|
+
* function was tested, and the code that actually decides what window a session runs on was not.
|
|
89
|
+
*
|
|
90
|
+
* This is that code, extracted, so it can be driven with a temporary directory and a fake model
|
|
91
|
+
* runtime - no server, no socket, no browser, no model.
|
|
92
|
+
*
|
|
93
|
+
* WHAT IT DOES, IN ORDER:
|
|
94
|
+
*
|
|
95
|
+
* 1. Reads the person's `models.json` and the provider's catalogue `models-store.json`.
|
|
96
|
+
* 2. Asks the model runtime for the WHOLE model object for `(provider, modelId)`.
|
|
97
|
+
* 3. Arbitrates the window across the three sources.
|
|
98
|
+
* 4. Hands the WHOLE model back, carrying the arbitrated window.
|
|
99
|
+
*
|
|
100
|
+
* THE FILES ARE READ ONCE, WHEN THE RESOLVER IS CREATED - which is where the session used to read
|
|
101
|
+
* them. A live session therefore keeps the windows it started with, exactly as it did before, and a
|
|
102
|
+
* person editing `models.json` mid-turn does not silently change the window of a running session.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createModelResolver(options: {
|
|
105
|
+
agentDir: string;
|
|
106
|
+
modelRuntime: {
|
|
107
|
+
getModel?: (provider: string, modelId: string) => unknown;
|
|
108
|
+
};
|
|
109
|
+
}): (provider: string, modelId: string) => ({
|
|
110
|
+
provider: string;
|
|
111
|
+
id: string;
|
|
112
|
+
contextWindow?: number;
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
} | undefined);
|
|
@@ -195,3 +195,40 @@ export function arbitrateContextWindow(declared, store, provider, modelId, repor
|
|
|
195
195
|
return reported;
|
|
196
196
|
return exact ?? deliberate ?? storeEntry?.contextWindow ?? reported;
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* THE RESOLVER A LIVE SESSION HANDS ITS MODEL THROUGH.
|
|
200
|
+
*
|
|
201
|
+
* WHY THIS IS A FUNCTION AND NOT A CLOSURE. The rule above is a pure function, and it has had a gate
|
|
202
|
+
* for a while - but the rule is only HALF of the runtime path. The other half is the code that reads
|
|
203
|
+
* the two files, asks the model runtime for the whole model object, and hands that object to Pi.
|
|
204
|
+
* That half lived inside `pi-session.ts` as an inline closure, where nothing could reach it: the pure
|
|
205
|
+
* function was tested, and the code that actually decides what window a session runs on was not.
|
|
206
|
+
*
|
|
207
|
+
* This is that code, extracted, so it can be driven with a temporary directory and a fake model
|
|
208
|
+
* runtime - no server, no socket, no browser, no model.
|
|
209
|
+
*
|
|
210
|
+
* WHAT IT DOES, IN ORDER:
|
|
211
|
+
*
|
|
212
|
+
* 1. Reads the person's `models.json` and the provider's catalogue `models-store.json`.
|
|
213
|
+
* 2. Asks the model runtime for the WHOLE model object for `(provider, modelId)`.
|
|
214
|
+
* 3. Arbitrates the window across the three sources.
|
|
215
|
+
* 4. Hands the WHOLE model back, carrying the arbitrated window.
|
|
216
|
+
*
|
|
217
|
+
* THE FILES ARE READ ONCE, WHEN THE RESOLVER IS CREATED - which is where the session used to read
|
|
218
|
+
* them. A live session therefore keeps the windows it started with, exactly as it did before, and a
|
|
219
|
+
* person editing `models.json` mid-turn does not silently change the window of a running session.
|
|
220
|
+
*/
|
|
221
|
+
export function createModelResolver(options) {
|
|
222
|
+
const declared = readDeclaredWindows(options.agentDir);
|
|
223
|
+
const catalogue = readStoreWindows(options.agentDir);
|
|
224
|
+
return (provider, modelId) => {
|
|
225
|
+
const found = options.modelRuntime.getModel?.(provider, modelId);
|
|
226
|
+
if (!found || typeof found !== "object")
|
|
227
|
+
return undefined;
|
|
228
|
+
const model = found;
|
|
229
|
+
const window = arbitrateContextWindow(declared, catalogue, provider, modelId, model.contextWindow);
|
|
230
|
+
// The model is handed to Pi WHOLE - it is what the agent runs on - so this is where the
|
|
231
|
+
// corrected window has to be. A model Super Pi has no opinion about is handed over untouched.
|
|
232
|
+
return window === undefined ? model : { ...model, contextWindow: window };
|
|
233
|
+
};
|
|
234
|
+
}
|
|
@@ -27,7 +27,7 @@ import { existsSync, statSync } from "node:fs";
|
|
|
27
27
|
import { open, readdir } from "node:fs/promises";
|
|
28
28
|
import { StringDecoder } from "node:string_decoder";
|
|
29
29
|
import { dirname, join, resolve } from "node:path";
|
|
30
|
-
import {
|
|
30
|
+
import { createModelResolver } from "./model-context-window.js";
|
|
31
31
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
32
32
|
const traceSession = (conversationId, phase, startedAt, extra = "") => {
|
|
33
33
|
if (process.env.SUPER_PI_TRACE_LATENCY !== "1")
|
|
@@ -327,26 +327,10 @@ export async function createPiSession(creation) {
|
|
|
327
327
|
// It is attached to the session rather than kept beside it because the session is what outlives a
|
|
328
328
|
// turn: a model change applies to a LIVE session, and the live session is the thing that has to be
|
|
329
329
|
// able to answer "give me this model whole".
|
|
330
|
-
// THE WINDOW THE MODEL REALLY HAS. Pi's remote catalogue can overwrite the `contextWindow` the
|
|
331
|
-
// PERSON configured in `models.json` (Pi's own merge lets the catalogue win), and a provider
|
|
332
|
-
// that reports a million tokens makes Pi's auto-compaction wait for 983,616 tokens - while the
|
|
333
|
-
// model refuses at its real 128,000. The overflow recovery then asks the same too-long
|
|
334
|
-
// conversation of the same too-small model, and the session stops working entirely.
|
|
335
330
|
//
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
const catalogue = readStoreWindows(agentDir);
|
|
340
|
-
live.resolveModel = (provider, modelId) => {
|
|
341
|
-
const found = modelRuntime.getModel?.(provider, modelId);
|
|
342
|
-
if (!found || typeof found !== "object")
|
|
343
|
-
return undefined;
|
|
344
|
-
const model = found;
|
|
345
|
-
const window = arbitrateContextWindow(declared, catalogue, provider, modelId, model.contextWindow);
|
|
346
|
-
// The model is handed to Pi WHOLE - it is what the agent runs on - so this is where the
|
|
347
|
-
// corrected window has to be. A model Super Pi has no opinion about is handed over untouched.
|
|
348
|
-
return window === undefined ? model : { ...model, contextWindow: window };
|
|
349
|
-
};
|
|
331
|
+
// The window the model REALLY has is arbitrated inside the resolver - see
|
|
332
|
+
// `model-context-window.ts` for the whole reasoning and for the tests that hold it in place.
|
|
333
|
+
live.resolveModel = createModelResolver({ agentDir, modelRuntime });
|
|
350
334
|
return live;
|
|
351
335
|
})();
|
|
352
336
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.191",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"scripts/session-orchestrator-tools.test.mjs",
|
|
96
96
|
"scripts/project-service.test.mjs",
|
|
97
97
|
"scripts/project-ceremony-free.test.mjs",
|
|
98
|
+
"scripts/session-model-resolver.test.mjs",
|
|
98
99
|
"scripts/project-mechanism-guards.test.mjs",
|
|
99
100
|
"scripts/dead-end-decision.test.mjs",
|
|
100
101
|
"scripts/project-report-exception-title.test.mjs",
|