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 {
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 (
<div data-testid={testId} className="flex items-center gap-2 text-xs text-muted-foreground">
<BookOpenIcon className="size-3 shrink-0" />
@@ -41,16 +49,19 @@ export function GraphContextControl({
<input
type="range"
min={0}
max={GRAPH_CONTEXT_TOKENS_MAX}
step={GRAPH_CONTEXT_TOKENS_STEP}
value={value}
onChange={(e) => 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"
/>
<span
className="w-14 shrink-0 tabular-nums"
className="w-16 shrink-0 tabular-nums"
data-testid="graph-context-value"
>
{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<ChatSettings, "graphContextTokens"> | undefined,
): number {
return settings?.graphContextTokens ?? GRAPH_CONTEXT_TOKENS_DEFAULT;
}
+10 -5
View File
@@ -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) ────────
+6 -4
View File
@@ -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)", () => {
+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"'),
"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");