Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .omhu/COMPOST.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ A line named in an open issue's `**Compost:**` line is scheduled; `/implement` d
- 2026-11-27 — Precomputing a future row; only the pinned candidate list is eager — 1 — plan 1 on #115
- 2026-11-27 — A frozen/unfrozen overlay; the inspector note stands in for now — 1 — plan 1 on #115
- 2026-11-27 — Separating the Flip and Diffuse streams; they share a destination-step stream by decision — 1 — plan 1 on #115
- 2026-11-28 — Neighbours or the chain on hover; hover is an outline only. — 1 — plan 1 on #123
- 2026-11-28 — The radial arc, chain strip and random button; children 2 and 4. — 1 — plan 1 on #123
- 2026-11-28 — Deleting `NeighborGraph` or `NeighborList`; children 5 and 6. — 1 — plan 1 on #123
- 2026-11-28 — Focus trapping; the dialog is non-modal. — 1 — plan 1 on #123
- 2026-11-28 — Touch gestures; click, keyboard and wheel only. — 1 — plan 1 on #123
- 2026-11-28 — A WordNet freeze mask to the page; frozen tokens stay blue until the dialog's note. — 1 — plan 1 on #123
- Promoted: click/jump half to #113; mixed-strategies half stays for #60.
- Promoted: all-neighbours list and forced jumps to #114.
- Promoted: random flip and one-step diffusion to #115.
4 changes: 4 additions & 0 deletions .omhu/JOURNAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ Noticed: the walk's "Decided" bullets kept M2–M6 as five slots with click insi
## 2026-11-27 — implement — the target and the gate pull in opposite directions

Noticed: slice 1 first measured 505 changed lines, over the 500 gate, and was trimmed to 492 by shortening docs; slice 2 then landed at 417, over the 400 target but under the gate, mostly from moving the freeze helpers and growing the seeded differential.

## 2026-11-28 — implement — where did the estimate leak?

Noticed: slice 2 measured 310 changed lines against the plan's ~150 estimate, mostly because the outline rules, the outside-pointerdown exemption list and the dialog chrome each rewrote in place; slices 1 and 3 landed at 121 and 56 against ~140 and ~60.
3 changes: 2 additions & 1 deletion .omhu/MAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ The app name lives in `src/routes/+layout.svelte` (header and `<title>`) and
`DESIGN.md` §1/§8. First load opens on the lexical strategy over GPT-2 with the
encoded input as one row at $t = 0$; no trajectory is requested. Edit returns
to the text, and the embedding bundle is fetched only when an embedding walk is
chosen.
chosen. Clicking a prose token opens the named `TokenDialog` inspector (not on
hover); Escape, its × and a pointer-down outside close it, and it is non-modal.

## WordNet

Expand Down
6 changes: 3 additions & 3 deletions AGENT_CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cut text into tokens, and distance functions — language-model embeddings,
spelling, shared letters, WordNet relations — define networks of similarity
between them. A visitor walks a token through such a network: by scrubbing a
stochastic process on the timeline, by inspecting a token's local neighbourhood
on hover, or by following the full graph.
on click, or by following the full graph.

The D3PM chain is one mechanism for that walk, not the frame — it stays
documented in `DESIGN.md` and in the maths below as a way of moving tokens, not
Expand Down Expand Up @@ -38,7 +38,7 @@ to follow slavishly.
- **No graph framework.** The full-graph view uses a hand-written Canvas 2D
renderer (pan/zoom camera math in `engine/camera.ts`, progressive reveal,
occupancy in `components/FullGraph.svelte`) with a
grid-accelerated force layout in a worker; the hover tooltip keeps its
grid-accelerated force layout in a worker; the token dialog keeps its
plain-SVG graph. Cytoscape.js was considered and not needed.
- **RNG**: `seedrandom` (Alea algorithm) for reproducible seeded randomness.

Expand Down Expand Up @@ -88,7 +88,7 @@ any schedule.
- Schedules: linear, cosine, constant. Mutual-information-based is future work.
- Time slider that scrubs smoothly through $[0, T]$.
- Prose, token-chip, and full token-graph display modes.
- Token inspector on hover showing the local transition distribution and a
- Token inspector on click showing the local transition distribution and a
neighbour graph.
- Diagnostics panel showing connectivity and stationary-distribution info
(future work).
Expand Down
7 changes: 4 additions & 3 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ where the two conflict. See §9 for the reconciliation.
Token Walks is an in-browser playground for exploring text as **spatially
embedded**: tokens placed in a space by their embeddings and their relations,
with networks of similarity drawn between them. The slider is one way to walk a
token through that network; the hover inspector and the full graph are others.
token through that network; the click-opened inspector and the full graph are
others.
Direct clicks and mixed strategies are the direction, not shipped interactions.
See `AGENT_CONTEXT.md` for the maths and non-goals, which still hold. This
document redefines the _experience_ around that walk.
Expand Down Expand Up @@ -223,8 +224,8 @@ A single **"Advanced"** (⚙) toggle reveals the technical layer:
is eligible for corruption. The schedule controls how aggressively the noise
ramps up."_ The cumulative curve is removed (or shown as a secondary dashed
line) to keep the focus on the per-step rate.
- **Per-token transition distribution** on hover/click (the "token inspector"
from `AGENT_CONTEXT.md`).
- **Per-token transition distribution** on click (the "token inspector" from
`AGENT_CONTEXT.md`).
- **Diagnostics** (connectivity / stationary distribution).
- Raw token IDs, $\beta_t$ value at current $t$, seed internals.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An in-browser playground for walking tokens through networks of similarity.
Tokenizers cut text into tokens, and a distance function — language-model
embeddings, spelling, shared letters, WordNet relations — places each one among
its neighbours. Click a token, then one of its neighbours, to walk it one step at
a time; scrub back through the rows you built, hover a token to inspect its local
a time; scrub back through the rows you built, click a token to inspect its local
neighbourhood, or open the full graph to see the whole network at once.
Built with SvelteKit and TypeScript, runs entirely in the browser with zero
server-side compute.
Expand Down
52 changes: 41 additions & 11 deletions e2e/hand-walk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ async function openTrail(page: Page): Promise<void> {
await expect(page.getByTestId('t-max')).toHaveText('0');
}

/** Click a prose token and wait for its pinned inspector. */
/** Click a prose token and wait for its inspector. */
async function pin(page: Page, index: number): Promise<void> {
await page.getByTestId('prose-token').nth(index).click();
await expect(page.getByRole('tooltip')).toBeVisible({ timeout: TIMEOUT });
await expect(page.getByRole('dialog')).toBeVisible({ timeout: TIMEOUT });
}

/** Jump to the first neighbour node in the pinned inspector. */
/** Jump to the first neighbour node in the inspector. */
async function pick(page: Page): Promise<void> {
const tooltip = page.getByRole('tooltip');
const node = tooltip.locator('g.node.neighbor[role="button"]').first();
const dialog = page.getByRole('dialog');
const node = dialog.locator('g.node.neighbor[role="button"]').first();
await expect(node).toBeVisible({ timeout: TIMEOUT });
await node.locator('circle').click();
await expect(tooltip).toBeVisible();
await expect(dialog).toBeVisible();
}

test('hand-walk: start, pin, jump, branch and undo', async ({ page }) => {
Expand All @@ -55,9 +55,9 @@ test('hand-walk: start, pin, jump, branch and undo', async ({ page }) => {

// AC3: click pins the inspector at position 1; the chain shows the token.
await pin(page, 1);
const tooltip = page.getByRole('tooltip');
await expect(tooltip.locator('svg')).toContainText('quick', { timeout: TIMEOUT });
await expect(tooltip.getByRole('button', { name: 'Close inspector' })).toBeVisible();
const dialog = page.getByRole('dialog');
await expect(dialog.locator('svg')).toContainText('quick', { timeout: TIMEOUT });
await expect(dialog.getByRole('button', { name: 'Close inspector' })).toBeVisible();

// AC4: a neighbour pick appends one row and follows it.
await pick(page);
Expand All @@ -81,11 +81,11 @@ test('hand-walk: start, pin, jump, branch and undo', async ({ page }) => {
await expect(page.getByTestId('t-max')).toHaveText('1');
expect((await readProse(page))!.text).toBe(row1.text);

// Scrubbing closes the pinned inspector so the branch point and focus
// Scrubbing closes the inspector so the branch point and focus
// agree; the next pin belongs to the visible row.
await pin(page, 1);
await page.getByTestId('time-slider').fill('0');
await expect(page.getByRole('tooltip')).toHaveCount(0);
await expect(page.getByRole('dialog')).toHaveCount(0);
await expect(page.locator('.readout')).toContainText('t = 0 / 1');

// Branch from row 0: the future is replaced, not appended at 3.
Expand Down Expand Up @@ -154,3 +154,33 @@ test('hand-walk: flip repeats by seed and diffuse steps the whole row', async ({

expect(errors).toEqual([]);
});

test('hand-walk: each close leaves t-max alone and a keyboard open takes focus', async ({
page,
}) => {
await openTrail(page);
await pin(page, 1);
await pick(page);
await expect(page.getByTestId('t-max')).toHaveText('1');

// Escape, × and an outside click close without touching the timeline.
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog')).toHaveCount(0);
await expect(page.getByTestId('t-max')).toHaveText('1');

await pin(page, 1);
await page.getByRole('button', { name: 'Close inspector' }).click();
await expect(page.getByRole('dialog')).toHaveCount(0);
await expect(page.getByTestId('t-max')).toHaveText('1');

await pin(page, 1);
await page.getByRole('heading', { name: 'Token Walks' }).click();
await expect(page.getByRole('dialog')).toHaveCount(0);
await expect(page.getByTestId('t-max')).toHaveText('1');

// A pointer open leaves focus on the token; a keyboard open moves it in.
await page.getByTestId('prose-token').nth(1).focus();
await page.keyboard.press('Enter');
await expect(page.getByRole('dialog')).toBeFocused();
await expect(page.getByTestId('t-max')).toHaveText('1');
});
26 changes: 13 additions & 13 deletions e2e/neighbor-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ async function openTrail(page: Page): Promise<void> {
});
}

/** Click a prose token and wait for its pinned inspector. */
/** Click a prose token and wait for its inspector. */
async function pin(page: Page, index: number): Promise<void> {
await page.getByTestId('prose-token').nth(index).click();
await expect(page.getByRole('tooltip')).toBeVisible({ timeout: TIMEOUT });
await expect(page.getByRole('dialog')).toBeVisible({ timeout: TIMEOUT });
}

/** Jump to the first neighbour node in the pinned inspector. */
/** Jump to the first neighbour node in the inspector. */
async function pick(page: Page): Promise<void> {
const tooltip = page.getByRole('tooltip');
const node = tooltip.locator('g.node.neighbor[role="button"]').first();
const dialog = page.getByRole('dialog');
const node = dialog.locator('g.node.neighbor[role="button"]').first();
await expect(node).toBeVisible({ timeout: TIMEOUT });
await node.locator('circle').click();
await expect(tooltip).toBeVisible();
await expect(dialog).toBeVisible();
}

test('neighbor list: pages past eight and resets after a jump', async ({ page }) => {
Expand All @@ -46,19 +46,19 @@ test('neighbor list: pages past eight and resets after a jump', async ({ page })
await openTrail(page);
await page.getByTestId('prose-token').nth(1).click();

const tooltip = page.getByRole('tooltip');
const rows = tooltip.locator('.neighbor-list .row');
const dialog = page.getByRole('dialog');
const rows = dialog.locator('.neighbor-list .row');
await expect(rows.first()).toBeVisible({ timeout: TIMEOUT });
await expect(tooltip.locator('.neighbor-list .caption')).toContainText('Neighbours (');
await expect(dialog.locator('.neighbor-list .caption')).toContainText('Neighbours (');

// The graph keeps its top-eight overview while the list reaches further.
const graphNodes = await tooltip.locator('g.node.neighbor').count();
const graphNodes = await dialog.locator('g.node.neighbor').count();
expect(graphNodes).toBeLessThanOrEqual(8);
const firstPage = await rows.count();
expect(firstPage).toBeGreaterThan(8);

// "Load more" appends the next page; no gaps or duplicates by construction.
await tooltip.getByRole('button', { name: 'Load more' }).click();
await dialog.getByRole('button', { name: 'Load more' }).click();
await expect.poll(() => rows.count()).toBeGreaterThan(firstPage);

// A row beyond the graph's eight is a legal jump: one row appended.
Expand Down Expand Up @@ -104,8 +104,8 @@ test('neighbor list: jumps to a row the kernel never offered', async ({ page })
const row0 = (await readProse(page))!;

await pin(page, 2);
const tooltip = page.getByRole('tooltip');
const rows = tooltip.locator('.neighbor-list .row');
const dialog = page.getByRole('dialog');
const rows = dialog.locator('.neighbor-list .row');
await expect(rows.first()).toBeVisible({ timeout: TIMEOUT });
const dists = await rows.locator('.dist').allTextContents();
const far = dists.findIndex((d) => Number(d) >= 2);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "token-walks",
"version": "1.20.0",
"version": "1.21.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
11 changes: 5 additions & 6 deletions src/lib/components/AboutPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@
</p>

<p>
Click a token to pin its inspector, then click a neighbour node to jump: exactly one row is
Click a token to open its inspector, then click a neighbour node to jump: exactly one row is
appended, the chosen token replaces that position, and every other token is copied. A random
<strong>Flip this token</strong> forces one position to take the active kernel's next-token
jump, and <strong>Diffuse one step</strong> samples every unfrozen position in order; both
append a row. Scrub the timeline to revisit a row, or undo to pop the last jump. Acting while
scrubbed back discards the rows after it. The <strong>strategy</strong> picks which network
you walk — embedding neighbours, similar spellings, shared letters, WordNet relations — and
the
<strong>schedule</strong> sets the weights the inspector reads. Hover over a token to preview its
immediate neighbourhood, open the pinned inspector for every stored neighbour, or switch to the
graph view to see the whole network at once. Mixing strategies is where this is heading, not what
it does yet. The highlights show you which tokens moved most recently. Nothing is computed ahead:
your clicks decide the walk.
<strong>schedule</strong> sets the weights the inspector reads. Click a token to open its immediate
neighbourhood and every stored neighbour, or switch to the graph view to see the whole network at
once. Mixing strategies is where this is heading, not what it does yet. The highlights show you
which tokens moved most recently. Nothing is computed ahead: your clicks decide the walk.
</p>

<h3>What this is (and isn't)</h3>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/AdvancedPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<section class="panel-section">
<h4 class="section-heading">Token inspector</h4>
<p class="hint">
Hover a token in the noisy view to see its local neighborhood. These settings control how many
Click a token in the noisy view to open its inspector. These settings control how many
neighbors are shown per hop.
</p>
<div class="inspector-controls">
Expand Down
43 changes: 29 additions & 14 deletions src/lib/components/InlineTokens.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
text: string;
/** Per-token character spans (from `allTokenCharSpans`). */
spans?: readonly TokenCharSpan[];
/** Called on token hover with the token id, its index, and bounding rect. */
onhover?: (tokenId: number, index: number, rect: DOMRect) => void;
/** Called when the pointer leaves a token span. */
onunhover?: () => void;
/** Called on click/Enter/Space to pin the inspector. */
onpin?: (tokenId: number, index: number, rect: DOMRect) => void;
/** Whether a click on this position can open the inspector. */
inspectable?: (index: number) => boolean;
/** Position whose inspector is currently open. */
pinnedIndex?: number | null;
/** Called on click/Enter/Space to open the inspector. */
onpin?: (tokenId: number, index: number, rect: DOMRect, viaKeyboard?: boolean) => void;
}

let { text, spans = [], onhover, onunhover, onpin }: Props = $props();
let { text, spans = [], inspectable, pinnedIndex = null, onpin }: Props = $props();

/**
* Split `text` into per-token segments. Each span contributes its slice
Expand Down Expand Up @@ -50,26 +50,28 @@
{#if seg.span}
<span
class="taper"
class:inspectable={inspectable?.(seg.span.index)}
class:pinned={pinnedIndex === seg.span.index}
style="--r: {seg.span.recency}"
data-testid="prose-token"
data-inspect-target
data-start={seg.span.start}
data-end={seg.span.end}
data-token-id={seg.span.tokenId}
role="button"
tabindex={0}
aria-label="token {seg.text}"
onmouseenter={(e) =>
onhover?.(seg.span!.tokenId, seg.span!.index, e.currentTarget.getBoundingClientRect())}
onmouseleave={() => onunhover?.()}
onfocus={(e) =>
onhover?.(seg.span!.tokenId, seg.span!.index, e.currentTarget.getBoundingClientRect())}
onblur={() => onunhover?.()}
onclick={(e) =>
onpin?.(seg.span!.tokenId, seg.span!.index, e.currentTarget.getBoundingClientRect())}
onkeydown={(e) => {
if (e.key !== 'Enter' && e.key !== ' ') return;
e.preventDefault();
onpin?.(seg.span!.tokenId, seg.span!.index, e.currentTarget.getBoundingClientRect());
onpin?.(
seg.span!.tokenId,
seg.span!.index,
e.currentTarget.getBoundingClientRect(),
true,
);
}}>{seg.text}</span
>
{:else}
Expand All @@ -89,6 +91,19 @@
margin: 0;
}

.taper:hover,
.taper:focus-visible {
outline: 2px solid #3b82f6;
outline-offset: 1px;
}
.taper:not(.inspectable):hover,
.taper:not(.inspectable):focus-visible {
outline-color: #e8a0a0;
}
.taper.pinned {
outline: 2px solid #1d4ed8;
outline-offset: 1px;
}
.taper {
/*
* Fading highlight: recency $r \in [0, 1]$ drives the background
Expand Down
Loading
Loading