Repository navigation
feat(web): presets, matrix paste and export, undo with saved workspace and share links, circuit from matrix - #15
Merged
Merged
Conversation
Parse hex grids, C and Rust array literals, Python, NumPy and Sage nested lists and LaTeX matrices into canonical cells, with errors that name the row and column. Format matrices as JSON, C, Rust, Sage or a plain grid; every export reads back to the same matrix.
naiveCircuit builds a straight-line program for y = M·x with each product computed once, and matrixDiff lists the coefficients where a circuit's matrix differs from its target.
Designs, matrices, S-boxes and circuits over GF(2^8) (0x11B) and BN254, each with a scope note. Unit tests recompute every MDS, invertibility, permutation and equivalence fact with lib/preview.ts, so a preset is listed as MDS only when the computation agrees.
Pure undo/redo with coalesced bursts, a debounce helper, a validated localStorage format for the workspace, compact share tokens (deflate-raw and base64url in the URL hash), hash routes with a share parameter and the undo key bindings.
Workspace edits go through one commit path with bounded undo history: typing in one cell coalesces, pastes, presets and imports are single steps. Ctrl/Cmd+Z and Shift+Ctrl/Cmd+Z work outside text areas. The inputs are saved to localStorage 300 ms after each change and restored on load. A story step that replaces edits keeps them for restoring, and links of the form #/workspace?d=... load a shared design.
Pasting a matrix in any supported notation into a cell fills the grid, a run of values fills from the focused cell, and a paste box previews the parsed matrix with a hex/decimal choice before applying it. Cells are normalized on blur. A Copy as menu exports JSON, C, Rust, Sage and a plain grid. The ad-hoc matrix load buttons give way to the presets.
A searchable presets picker groups designs, matrices, S-boxes and circuits with scope notes and browser-preview fact chips. The toolbar adds undo, redo, a share-link button and the save status. Below the circuit, the coefficient matrix it computes is shown beside the target with differing coefficients marked, a generator for a term-by-term circuit and a shortcut into the quick experiment search.
restoreWorkspace only needs getItem; the reader no longer asks for setItem too.
A value such as p-1 printed all 77 digits in the read-only matrices and in the diff summary, which pushed the workspace wider than a phone screen. Read-only cells and the summary now show values just below p as p-k and other long values as the first 6 and last 4 digits, with the full value in the tooltip and for screen readers. The grid may also scroll inside its own box and cells wrap rather than widen the page.
Opening a share link replaced the workspace as an ordinary edit, and the debounced save then overwrote the saved workspace, so a reload lost the user's own design with no way back. A share link now keeps unsaved edits in the same restorable slot a story step uses, saved with the workspace, and the banner offers Restore my edits or Keep the shared inputs. A link that matches the open inputs only says so.
Closing the Paste matrix box with Escape or Cancel dropped focus to the page; it now returns to the Paste matrix button, and Use this matrix moves focus to the first cell. The paste box's live region holds only a one-line summary or the error, with the preview matrix outside it, so a screen reader no longer re-reads every cell on each keystroke. Workspace announcements go through one live region that stays mounted and clears before each new message, instead of a region remounted with its text.
The generate button replaced a hand-written circuit without saying so and turned primary whenever the circuit differed. It now reads Replace circuit with term-by-term, stays secondary, and its announcement says Undo brings the previous circuit back. On the static build the search button reads Show the recorded search only when a recorded search matches the inputs, and No recorded search for these inputs otherwise; when the circuit does not compute the matrix, the panel says the search starts from the matrix and leaves the circuit out. Reasons for disabled buttons are shown as text tied to the buttons. The diff marker is drawn as a diamond that matches the summary, and the evidence icon no longer shrinks on phones.
Copy share link and Copy as explained a disabled state only in a title tooltip, which touch screens and keyboard focus never show. The reason is now visible text next to the control and its accessible description. The toolbar said Saved in this browser on a first visit before anything was saved; it now reads Changes are saved in this browser until the first write, or until a saved workspace has been restored.
The note under the preset list called the chips browser previews re-run by the unit tests, which means little to a cipher designer, and sat below the fold. A legend at the top now says the dashed chips are quick checks computed in the browser, not Lean proofs, and that Check gives evidence; each chip also carries that as a tooltip and a screen-reader prefix. Tests cover how presets are grouped and ordered with and without a query.
A link whose contents were not JSON ended in a double period, and a link holding only a circuit was reported as missing instructions. The decoder now says the link is damaged when its contents are not JSON, says the link does not contain a design when there is none, and wraps other import errors without doubling the period. Tests also guard the 128 KB limit on decompressed links against a small deflate bomb.
Pasting 01 02 03 into row 4, column 3 of a 4x4 matrix reported that one row was found where four were expected, as if a whole matrix had been pasted. A run of values that reads cleanly but does not fit from the focused cell now gets its own message; the matrix parser's error is kept for text that does not read as a run. Tests cover pasted runs (spreadsheet rows, quoted values, BN254 negatives, values that do not fit) and the shortened BN254 display.
This was referenced Nov 11, 2026
Resolve the overlap with the branches merged before it, as in the release/v0.2.0 integration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Workspace is now faster for a cipher designer working through many matrices:
lib/preview.ts.Everything computed in the browser stays labelled as an unchecked preview. Lean still decides on Check.
Changes
Presets (
src/lib/library.ts,src/components/PresetPicker.tsx)[[2,1,1],[1,2,1],[1,1,2]].circ(01,01,04,09)andcirc(01,02,03,04), non-MDS circulantscirc(02,01,01,01),circ(01,02,04,06)and binarycirc(00,01,01,01)(each labelled not MDS), identity; the Poseidon2 external and internal matrices and the weak internal one.v = (0,1,−1)satisfiesMv = vwithv₀ = 0; a unit test checks this fixed point. That weakness is outside what the workbench checks today.circ(02, 01) ranks first. Results are grouped by kind.Matrix notation (
src/lib/notation.ts,src/components/MatrixEditor.tsx)parseMatrixTextreads:0x02u8);F(2),F.fetch_int(2),e(0x02)andmatrix(F, 4, 4, [...]);pmatrix.normalizeCellruns on blur:1becomes01,0x1bbecomes1B, and in BN254-1becomes p − 1.formatMatrixwrites JSON, Cuint8_t, Rust[[u8; n]; n], Sage over GF(2)[x]/(x⁸+x⁴+x³+x+1) (or GF(p) for BN254), or a plain grid. Every format reads back to the same matrix (tested).Undo, persistence, story snapshots and share links (
src/lib/{history,debounce,persist,share,route,shortcuts,snapshot}.ts,src/state/*)commitpath with a bounded history of 100 steps.aria-keyshortcuts. Text areas and the preset search keep the browser's own undo.localStorage(cryptificate.workspace.v1) 300 ms after each change and flushed onpagehide. Storage access is wrapped in try/catch. Saved data is shape-checked on restore, and corrupt or foreign data is ignored. The toolbar shows the save status: Saved in this browser only after the first write or a restore, Changes are saved in this browser before that, and a warning when storage is blocked.origin: 'story'. If they replace user edits, the edits are kept: the Workspace shows Restore my edits, and the story shows a note linking there.#/workspace?d=<token>) encodes the canonical request and compresses it withdeflate-rawand base64url where available, with a plain JSON fallback. The AES design with the shared-sum circuit is about 450 characters.Circuit from matrix and computed-matrix diff (
src/lib/circuit.ts,src/components/ComputedMatrix.tsx)naiveCircuit(matrix, field)builds the circuit term by term:matrixDifflists the coefficients that differ.Review fixes
Each reviewer finding was reproduced first and fixed in its own commit:
aria-describedby.Screenshots
Each scenario was captured in light and dark themes, at 1440 px (desktop) and 390 px (phone), with Playwright against the replay-mode dev server:
Screenshots were taken locally (light and dark, 1440 px and 390 px) and are not attached:
01-workspace-dark-desktop.png01-workspace-dark-phone.png01-workspace-light-desktop.png01-workspace-light-phone.png02-presets-search-dark-desktop.png02-presets-search-dark-phone.png02-presets-search-light-desktop.png02-presets-search-light-phone.png03-computed-diff-dark-desktop.png03-computed-diff-dark-phone.png03-computed-diff-light-desktop.png03-computed-diff-light-phone.png04-generated-dark-desktop.png04-generated-dark-phone.png04-generated-light-desktop.png04-generated-light-phone.png05-paste-preview-dark-desktop.png05-paste-preview-dark-phone.png05-paste-preview-light-desktop.png05-paste-preview-light-phone.png06-paste-error-dark-desktop.png06-paste-error-dark-phone.png06-paste-error-light-desktop.png06-paste-error-light-phone.png07-copy-menu-dark-desktop.png07-copy-menu-dark-phone.png07-copy-menu-light-desktop.png07-copy-menu-light-phone.png08-toolbar-shared-dark-desktop.png08-toolbar-shared-dark-phone.png08-toolbar-shared-light-desktop.png08-toolbar-shared-light-phone.png09-share-opened-dark-desktop.png09-share-opened-dark-phone.png09-share-opened-light-desktop.png09-share-opened-light-phone.png10-story-replaced-dark-desktop.png10-story-replaced-dark-phone.png10-story-replaced-light-desktop.png10-story-replaced-light-phone.png11-presets-poseidon-dark-desktop.png11-presets-poseidon-dark-phone.png11-presets-poseidon-light-desktop.png11-presets-poseidon-light-phone.png12-workspace-bn254-dark-desktop.png12-workspace-bn254-dark-phone.png12-workspace-bn254-light-desktop.png12-workspace-bn254-light-phone.png13-story-kept-edits-dark-desktop.png13-story-kept-edits-dark-phone.png13-story-kept-edits-light-desktop.png13-story-kept-edits-light-phone.png14-paste-run-overflow-dark-desktop.png14-paste-run-overflow-dark-phone.png14-paste-run-overflow-light-desktop.png14-paste-run-overflow-light-phone.png15-share-kept-edits-dark-desktop.png15-share-kept-edits-dark-phone.png15-share-kept-edits-light-desktop.png15-share-kept-edits-light-phone.png16-bn254-p-minus-1-dark-desktop.png16-bn254-p-minus-1-dark-phone.png16-bn254-p-minus-1-light-desktop.png16-bn254-p-minus-1-light-phone.png17-presets-legend-dark-desktop.png17-presets-legend-dark-phone.png17-presets-legend-light-desktop.png17-presets-legend-light-phone.png18-disabled-reasons-design-dark-desktop.png18-disabled-reasons-design-dark-phone.png18-disabled-reasons-design-light-desktop.png18-disabled-reasons-design-light-phone.png18-disabled-reasons-toolbar-dark-desktop.png18-disabled-reasons-toolbar-dark-phone.png18-disabled-reasons-toolbar-light-desktop.png18-disabled-reasons-toolbar-light-phone.pngScenarios:
circ(02,01,01,01)with the AES circuit (4 of 16 coefficients differ); the search button reads No recorded search for these inputs with its reason.The script also checked:
0x1bbecomes1B, and Ctrl+Z inside a cell restores the previous value.scrollWidthequalsclientWidthat 390 px and 1440 px (the script fails otherwise)./api/capabilitiesproxy calls (no local service running, which is how the replay fallback is exercised).Tests run
npm run build: all workspaces build, includingtsc --noEmitandvite buildforapps/web.npm test: schema 14/14 and server 42 passed with 5 skipped (unchanged). Web: 21 files, 373 tests passed. New test files:lib/notation.test.ts: every notation, the hex and decimal readings, error messages and cell positions, BN254 reduction, and export round-trips.lib/library.test.ts: every preset applies cleanly to both fields; MDS, invertibility, permutation and equivalence facts are recomputed withlib/preview.tsandbranchWitness; checks thatv = (0,1,−1)is fixed by the weak internal matrix; search ranking.lib/circuit.test.ts(extended):naiveCircuiton 50 random 4×4 GF(2^8) and 50 random 3×3 BN254 matrices equals the matrix; operation counts; zero and single-term rows;matrixDiff.lib/history.test.ts,lib/debounce.test.ts(fake timers),lib/persist.test.ts(corrupt data and throwing storage),lib/share.test.ts(round-trip with the inputs digest preserved, compression, rejection of damaged, oversized and invalid links),lib/route.test.ts,lib/shortcuts.test.ts.state/actions.test.ts: per-cell coalescing, pastes as separate steps, story snapshot and restore, presets as one step, debounced saving and restore (and the save status), unavailable storage, share-link load and failure, edits kept when a link opens over them and restored after a fresh start, and a link that matches the open inputs.lib/share.test.tsalso covers a deflate bomb that would inflate past 128 KB (rejected as too large), a token just under the limit, a bare circuit and a JSON array (no design), and single-period error wording.lib/bn254.test.ts: p−k and 6…4 shortening anddisplayElement.components/MatrixEditor.test.tsx:pastedCells(spreadsheet rows, quoted values, BN254 negatives, values that are not elements),planCellPaste(fits, overflows, full-matrix text),MatrixViewrendering of p−1 with full values in the tooltip and screen-reader text, anddescribeCells.components/PresetPicker.test.ts:groupedPresetsorder with and without a query, field-first without a query, and every match listed once.components/WorkspaceToolbar.test.tsx: save-status wording and the visible share-link reason tied byaria-describedby.Scope and limits
apps/webplus the README files; the schema, server, engine and Lean are untouched.aes-like/gf256/v1and are not listed. The binarycirc(00,01,01,01)is labelled as a Midori-style 0/1 pattern, not Midori.CompressionStream(current Chromium, Firefox and Safari). Links made without it are plain base64url JSON and open everywhere.Generated by Claude Code