fix: the knowledge-context slider is a discrete 6-stop scale — off, then powers of four from 64

The continuous 0-4096 dial was precision theater (a 128-token budget is
~2 propositions; nobody wants that granularity). Decided stops (owner,
2026-09-15): 0 / 64 / 256 / 1024 / 4096 / 16384 — the native range walks
positions 0-5 and maps through GRAPH_CONTEXT_TOKENS_STOPS in contracts.
Max rises to 16384 (route range follows); the server still accepts any
integer in range so a stale client cannot brick settings; non-stop
legacy values snap to the nearest stop for the thumb, readout stays
honest.
This commit is contained in:
amosblomqvist
2026-09-15 08:09:56 +03:00
parent f6b0c3fb86
commit 4022e3f0d0
4 changed files with 57 additions and 26 deletions
+37 -15
View File
@@ -3,8 +3,8 @@
import { BookOpenIcon } from "lucide-react"; import { BookOpenIcon } from "lucide-react";
import { import {
GRAPH_CONTEXT_TOKENS_DEFAULT, GRAPH_CONTEXT_TOKENS_DEFAULT,
GRAPH_CONTEXT_TOKENS_MAX, GRAPH_CONTEXT_TOKENS_STOPS,
GRAPH_CONTEXT_TOKENS_STEP, type ChatSettings,
} from "@/src/core"; } from "@/src/core";
/** /**
@@ -17,13 +17,15 @@ import {
* session contributed to the graph asks first what the graph will * session contributed to the graph asks first what the graph will
* contribute to the session. * contribute to the session.
* *
* One quiet compact row sized to sit in the stats band beside the model + * A DISCRETE 6-position slider (owner, 2026-09-15): off, then powers of four
* thinking pills: short slider, "tok" readout, the FULL number (owner, * from 64 — a continuous 0–4096 dial was precision theater (a 128-token
* 2026-09-15: no k-rounding — 1024 reads as 1024). 0 = off; absent settings * budget is ~2 propositions). The native range input walks positions 0–5
* show the DEFAULT (1024 — on). The value rides ChatSettings (the same * and maps through GRAPH_CONTEXT_TOKENS_STOPS; every stop is a real
* lifted settings the model picker uses), so it persists pre-chat via the * decision. Non-stop values from a stale client snap to the nearest stop
* same deferred PUT. Sessions never show this control — the injection is * for display. The readout shows the FULL number (no k-rounding). The
* one-shot at session start, so mid-session there is nothing to decide. * value rides ChatSettings (the same lifted settings the model picker
* uses), so it persists pre-chat via the same deferred PUT. Sessions
* never show this control — the injection is one-shot at session start.
*/ */
export function GraphContextControl({ export function GraphContextControl({
value, value,
@@ -34,6 +36,12 @@ export function GraphContextControl({
onChange: (tokens: number) => void; onChange: (tokens: number) => void;
testId?: string; testId?: string;
}) { }) {
// Snap for display only: a legacy non-stop value shows its nearest stop
// and the next drag lands on a real one.
const stop = nearestStop(value);
// indexOf on a readonly tuple rejects a plain number; the snap above
// always yields a member, so the cast is honest.
const index = (GRAPH_CONTEXT_TOKENS_STOPS as readonly number[]).indexOf(stop);
return ( return (
<div data-testid={testId} className="flex items-center gap-2 text-xs text-muted-foreground"> <div data-testid={testId} className="flex items-center gap-2 text-xs text-muted-foreground">
<BookOpenIcon className="size-3 shrink-0" /> <BookOpenIcon className="size-3 shrink-0" />
@@ -41,16 +49,19 @@ export function GraphContextControl({
<input <input
type="range" type="range"
min={0} min={0}
max={GRAPH_CONTEXT_TOKENS_MAX} max={GRAPH_CONTEXT_TOKENS_STOPS.length - 1}
step={GRAPH_CONTEXT_TOKENS_STEP} step={1}
value={value} value={index}
onChange={(e) => onChange(Number(e.target.value))} onChange={(e) => {
const next = (GRAPH_CONTEXT_TOKENS_STOPS as readonly number[])[Number(e.target.value)];
if (next !== undefined) onChange(next);
}}
aria-label="Prior-knowledge token budget" aria-label="Prior-knowledge token budget"
className="h-1 w-24 shrink-0 accent-primary" className="h-1 w-24 shrink-0 accent-primary"
data-testid="graph-context-slider" data-testid="graph-context-slider"
/> />
<span <span
className="w-14 shrink-0 tabular-nums" className="w-16 shrink-0 tabular-nums"
data-testid="graph-context-value" data-testid="graph-context-value"
> >
{value === 0 ? "off" : `${value} tok`} {value === 0 ? "off" : `${value} tok`}
@@ -59,9 +70,20 @@ export function GraphContextControl({
); );
} }
/** The nearest stop to any budget value (display snapping). */
export function nearestStop(value: number): number {
let best: number = GRAPH_CONTEXT_TOKENS_STOPS[0] ?? 0;
for (const s of GRAPH_CONTEXT_TOKENS_STOPS) {
if (Math.abs(s - value) < Math.abs(best - value)) best = s;
}
return best;
}
/** The control's effective value for a chat's settings — absent = the /** The control's effective value for a chat's settings — absent = the
* default (on), never 0: the decided default is a modest slice of prior * default (on), never 0: the decided default is a modest slice of prior
* knowledge for every fresh session. */ * knowledge for every fresh session. */
export function effectiveContextTokens(settings: { graphContextTokens?: number } | undefined): number { export function effectiveContextTokens(
settings: Pick<ChatSettings, "graphContextTokens"> | undefined,
): number {
return settings?.graphContextTokens ?? GRAPH_CONTEXT_TOKENS_DEFAULT; return settings?.graphContextTokens ?? GRAPH_CONTEXT_TOKENS_DEFAULT;
} }
+10 -5
View File
@@ -68,12 +68,17 @@ export interface ChatSettings {
graphContextTokens?: number; graphContextTokens?: number;
} }
/** The injection budget's decided knobs (2026-09-14): default 1024 (a /** The injection budget's decided knobs (2026-09-14; scale revised
* meaningful, modest slice of prior knowledge), hard max 4096, slider * 2026-09-15, owner): default 1024 (a meaningful, modest slice of prior
* step 128, 0 = off. */ * knowledge), hard max 16384, 0 = off. The UI is a DISCRETE slider over
* these stops — powers of four from 64 (the fine-grained low end was
* theater: a 128-token budget is ~2 propositions, nobody wants that
* dial); the server still accepts any integer in range (a stale client
* can't brick settings), the stops only govern what the slider sends. */
export const GRAPH_CONTEXT_TOKENS_DEFAULT = 1024; export const GRAPH_CONTEXT_TOKENS_DEFAULT = 1024;
export const GRAPH_CONTEXT_TOKENS_MAX = 4096; export const GRAPH_CONTEXT_TOKENS_MAX = 16384;
export const GRAPH_CONTEXT_TOKENS_STEP = 128; /** The slider's positions, left to right: off, then powers of four. */
export const GRAPH_CONTEXT_TOKENS_STOPS = [0, 64, 256, 1024, 4096, 16384] as const;
// ─── Background-extraction usage (the money channel, extraction side) ──────── // ─── Background-extraction usage (the money channel, extraction side) ────────
+6 -4
View File
@@ -13,7 +13,7 @@ import {
steerDelivered, steerDelivered,
GRAPH_CONTEXT_TOKENS_DEFAULT, GRAPH_CONTEXT_TOKENS_DEFAULT,
GRAPH_CONTEXT_TOKENS_MAX, GRAPH_CONTEXT_TOKENS_MAX,
GRAPH_CONTEXT_TOKENS_STEP, GRAPH_CONTEXT_TOKENS_STOPS,
graphContextText, graphContextText,
type GraphContextData, type GraphContextData,
} from "../src/core/contracts.ts"; } from "../src/core/contracts.ts";
@@ -279,10 +279,12 @@ describe("the runner's pure gates", () => {
assert.equal(effectiveContextBudget({ graphContextTokens: 2048 }), 2048); assert.equal(effectiveContextBudget({ graphContextTokens: 2048 }), 2048);
}); });
it("the decided knobs: default 1024, max 4096, step 128", () => { it("the decided knobs: default 1024, max 16384, discrete powers-of-four stops from 64", () => {
assert.equal(GRAPH_CONTEXT_TOKENS_DEFAULT, 1024); assert.equal(GRAPH_CONTEXT_TOKENS_DEFAULT, 1024);
assert.equal(GRAPH_CONTEXT_TOKENS_MAX, 4096); assert.equal(GRAPH_CONTEXT_TOKENS_MAX, 16384);
assert.equal(GRAPH_CONTEXT_TOKENS_STEP, 128); // The scale revision (owner, 2026-09-15): off then powers of four —
// every stop a real decision, no fine-grained dial theater.
assert.deepEqual([...GRAPH_CONTEXT_TOKENS_STOPS], [0, 64, 256, 1024, 4096, 16384]);
}); });
it("contextToolCallId is deterministic per chat (the one-shot dedup key)", () => { it("contextToolCallId is deterministic per chat (the one-shot dedup key)", () => {
+4 -2
View File
@@ -102,8 +102,10 @@ describe("DraftShell — the sessionless surface", () => {
html.indexOf('data-testid="stats-bar"') < html.indexOf('data-testid="graph-context-control"'), html.indexOf('data-testid="stats-bar"') < html.indexOf('data-testid="graph-context-control"'),
"the slider is the stats bar's left slot", "the slider is the stats bar's left slot",
); );
// The slider's default position: 1024 of 4096, step 128 (decided). // The DISCRETE slider (owner, 2026-09-15): 6 positions (off + powers of
assert.ok(html.includes('min="0"') && html.includes('max="4096"') && html.includes('step="128"')); // four from 64), not a continuous 0-4096 dial.
assert.ok(html.includes('min="0"') && html.includes('max="5"') && html.includes('step="1"'));
assert.ok(html.includes('value="3"'), "default 1024 = stop index 3");
// The readout: "tok" abbreviated, but the FULL number (owner, 2026-09-15: // The readout: "tok" abbreviated, but the FULL number (owner, 2026-09-15:
// no k-rounding — 1024 reads as 1024). // no k-rounding — 1024 reads as 1024).
assert.ok(html.includes("1024 tok"), "the readout shows the default budget, not 0 — default is ON"); assert.ok(html.includes("1024 tok"), "the readout shows the default budget, not 0 — default is ON");