diff --git a/components/graph-context-control.tsx b/components/graph-context-control.tsx index e3ba6a6..27a99cd 100644 --- a/components/graph-context-control.tsx +++ b/components/graph-context-control.tsx @@ -3,8 +3,8 @@ import { BookOpenIcon } from "lucide-react"; import { GRAPH_CONTEXT_TOKENS_DEFAULT, - GRAPH_CONTEXT_TOKENS_MAX, - GRAPH_CONTEXT_TOKENS_STEP, + GRAPH_CONTEXT_TOKENS_STOPS, + type ChatSettings, } from "@/src/core"; /** @@ -17,13 +17,15 @@ import { * session contributed to the graph asks first what the graph will * contribute to the session. * - * One quiet compact row sized to sit in the stats band beside the model + - * thinking pills: short slider, "tok" readout, the FULL number (owner, - * 2026-09-15: no k-rounding — 1024 reads as 1024). 0 = off; absent settings - * show the DEFAULT (1024 — on). The 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, so mid-session there is nothing to decide. + * A DISCRETE 6-position slider (owner, 2026-09-15): off, then powers of four + * from 64 — a continuous 0–4096 dial was precision theater (a 128-token + * budget is ~2 propositions). The native range input walks positions 0–5 + * and maps through GRAPH_CONTEXT_TOKENS_STOPS; every stop is a real + * decision. Non-stop values from a stale client snap to the nearest stop + * for display. The readout shows the FULL number (no k-rounding). The + * 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({ value, @@ -34,6 +36,12 @@ export function GraphContextControl({ onChange: (tokens: number) => void; 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 (
@@ -41,16 +49,19 @@ export function GraphContextControl({ onChange(Number(e.target.value))} + max={GRAPH_CONTEXT_TOKENS_STOPS.length - 1} + step={1} + value={index} + 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" className="h-1 w-24 shrink-0 accent-primary" data-testid="graph-context-slider" /> {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 * default (on), never 0: the decided default is a modest slice of prior * knowledge for every fresh session. */ -export function effectiveContextTokens(settings: { graphContextTokens?: number } | undefined): number { +export function effectiveContextTokens( + settings: Pick | undefined, +): number { return settings?.graphContextTokens ?? GRAPH_CONTEXT_TOKENS_DEFAULT; } \ No newline at end of file diff --git a/src/core/contracts/chat.ts b/src/core/contracts/chat.ts index b53895d..3e77c11 100644 --- a/src/core/contracts/chat.ts +++ b/src/core/contracts/chat.ts @@ -68,12 +68,17 @@ export interface ChatSettings { graphContextTokens?: number; } -/** The injection budget's decided knobs (2026-09-14): default 1024 (a - * meaningful, modest slice of prior knowledge), hard max 4096, slider - * step 128, 0 = off. */ +/** The injection budget's decided knobs (2026-09-14; scale revised + * 2026-09-15, owner): default 1024 (a meaningful, modest slice of prior + * 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_MAX = 4096; -export const GRAPH_CONTEXT_TOKENS_STEP = 128; +export const GRAPH_CONTEXT_TOKENS_MAX = 16384; +/** 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) ──────── diff --git a/tests/graph-context-core.test.ts b/tests/graph-context-core.test.ts index cdfb5a3..611e0d4 100644 --- a/tests/graph-context-core.test.ts +++ b/tests/graph-context-core.test.ts @@ -13,7 +13,7 @@ import { steerDelivered, GRAPH_CONTEXT_TOKENS_DEFAULT, GRAPH_CONTEXT_TOKENS_MAX, - GRAPH_CONTEXT_TOKENS_STEP, + GRAPH_CONTEXT_TOKENS_STOPS, graphContextText, type GraphContextData, } from "../src/core/contracts.ts"; @@ -279,10 +279,12 @@ describe("the runner's pure gates", () => { 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_MAX, 4096); - assert.equal(GRAPH_CONTEXT_TOKENS_STEP, 128); + assert.equal(GRAPH_CONTEXT_TOKENS_MAX, 16384); + // 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)", () => { diff --git a/tests/render-new-session.test.tsx b/tests/render-new-session.test.tsx index 4172da6..9186f7e 100644 --- a/tests/render-new-session.test.tsx +++ b/tests/render-new-session.test.tsx @@ -102,8 +102,10 @@ describe("DraftShell — the sessionless surface", () => { html.indexOf('data-testid="stats-bar"') < html.indexOf('data-testid="graph-context-control"'), "the slider is the stats bar's left slot", ); - // The slider's default position: 1024 of 4096, step 128 (decided). - assert.ok(html.includes('min="0"') && html.includes('max="4096"') && html.includes('step="128"')); + // The DISCRETE slider (owner, 2026-09-15): 6 positions (off + powers of + // 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: // no k-rounding — 1024 reads as 1024). assert.ok(html.includes("1024 tok"), "the readout shows the default budget, not 0 — default is ON");