From 1dfd7f716e4e34eed9e2fa77b0d107bec8753093 Mon Sep 17 00:00:00 2001 From: Dylan Roy Date: Fri, 2 Oct 2026 09:25:40 -0500 Subject: [PATCH 1/5] Preserve Library filters in bookmarkable search links Implemented by OpenAI/Codex under Dylan Roy's delegated UI authority. Source pins, scientific records and prior navigation helper unchanged. --- docs/site/README.md | 16 +++++ docs/site/app.js | 8 ++- docs/site/catalog-query.mjs | 41 +++++++++++ docs/site/workspace.html | 2 +- tests/test_catalog_query.mjs | 119 +++++++++++++++++++++++++++++++ tests/test_reader_navigation.mjs | 1 + 6 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 docs/site/catalog-query.mjs create mode 100644 tests/test_catalog_query.mjs diff --git a/docs/site/README.md b/docs/site/README.md index 7618c5da0..a9e0d9a36 100644 --- a/docs/site/README.md +++ b/docs/site/README.md @@ -23,6 +23,22 @@ python3 -B -S -m unittest discover -s tests -p test_reader_links.py -v Check real desktop/mobile layouts, keyboard operation, light/dark appearance and source-unavailable behavior separately. The pure-model tests are not browser or scientific verification. +## Keep or share a Library search + +The Library's search, repository and path filters are saved in the current URL +without adding a browser-history entry for every keystroke. Refreshing or +returning with Back/Forward restores the filters. **Link to this search** gives a +bookmarkable link directly to the catalog; **Clear filters** restores its initial +50-row view. Filtering never changes source identities or recorded review scope. + +Search links use `q`, `repository` (`main` or `Math-`) and `path`. Empty values are +omitted; the first repeated value is used, and an unknown repository is treated +as all repositories. Unrelated parameters and section bookmarks are preserved in +the current address but omitted from the explicit search link. Filters are visible +in URLs and browser history. Links use the catalog’s pinned source records, not a +live proof index; the search URL does not freeze future catalog updates. If history updates are unavailable, filtering and the explicit +link still work; if source verification fails, controls stay unavailable. + ## Run locally From the repository root: diff --git a/docs/site/app.js b/docs/site/app.js index 55872500d..82fbc1a68 100644 --- a/docs/site/app.js +++ b/docs/site/app.js @@ -1,4 +1,5 @@ import {verifiedJSON, verifiedBytes, validateStatus, validateCoefficient, safeSourceURL, hex40, hex64} from './core.mjs'; +import {connectCatalogQuery} from './catalog-query.mjs'; import {prepareWorkspaceFragment} from './workspace-fragment.mjs'; const finishFragment=prepareWorkspaceFragment(); const el=id=>document.getElementById(id); @@ -85,9 +86,12 @@ async function inventory(config) { const render=()=>{const query=el('search').value.trim().toLowerCase(),repository=el('repository-filter').value,path=el('path-filter').value.trim().toLowerCase(); const matches=rows.filter(row=>(!repository||row.repository===repository)&&row.path.toLowerCase().includes(path)&&[row.repository,row.path,row.commit,row.sha256].some(s=>s.toLowerCase().includes(query)));el('catalog').replaceChildren(); matches.slice(0,limit).forEach(row=>{const tr=node('tr'),name=node('td'),commit=node('td'),hash=node('td');name.append(node('small',row.repository),link(row.path,safeSourceURL(row)));commit.append(node('code',row.commit));hash.append(node('code',row.sha256));tr.append(name,commit,hash);el('catalog').append(tr);}); - el('inventory-state').textContent=`${matches.length.toLocaleString()} matches · ${Math.min(limit,matches.length)} shown · all 2,138 source records loaded from the original hash-verified shards.`;el('more').hidden=matches.length<=limit;}; + el('inventory-state').textContent=`${matches.length.toLocaleString()} matches · ${Math.min(limit,matches.length)} shown · all 2,138 source records loaded from the original hash-verified shards.`;if(!matches.length)el('inventory-state').append(' Try a broader search or clear filters.');el('more').hidden=matches.length<=limit;}; + const syncQuery=connectCatalogQuery(typeof window==='undefined'?null:window,{search:el('search'),repository:el('repository-filter'),path:el('path-filter'),link:el('catalog-link'),note:el('catalog-query-note')},()=>{limit=50;render();}); + el('catalog-clear').disabled=false; + el('catalog-clear').addEventListener('click',()=>{for(const id of ['search','repository-filter','path-filter'])el(id).value='';limit=50;render();syncQuery();el('search').focus();}); for(const [id,event] of [['search','input'],['repository-filter','change'],['path-filter','input']]) { - el(id).disabled=false;el(id).addEventListener(event,()=>{limit=50;render();}); + el(id).disabled=false;el(id).addEventListener(event,()=>{limit=50;render();syncQuery();}); } el('more').addEventListener('click',()=>{limit+=50;render();});render(); } diff --git a/docs/site/catalog-query.mjs b/docs/site/catalog-query.mjs new file mode 100644 index 000000000..5f26b3950 --- /dev/null +++ b/docs/site/catalog-query.mjs @@ -0,0 +1,41 @@ +// URL state is a reader convenience, never a source or scientific-status input. +// URLSearchParams.get deliberately uses the first occurrence of each filter. +export function readCatalogQuery(search) { + const params=new URLSearchParams(search); + const repository=params.get('repository'); + return {query:(params.get('q')||'').trim(),repository:['main','Math-'].includes(repository)?repository:'',path:(params.get('path')||'').trim()}; +} +export function catalogQueryURL(href,filters,share=false) { + const url=new URL(href); + if(share){url.search='';url.hash='inventory';} + for(const [key,value] of [['q',filters.query],['repository',filters.repository],['path',filters.path]]) { + if(value.trim())url.searchParams.set(key,value.trim());else url.searchParams.delete(key); + } + return url; +} +export function connectCatalogQuery(win,controls,onRestore) { + const current=()=>{try{return new URL(win.location.href);}catch{return null;}}; + const values=()=>({query:controls.search.value,repository:controls.repository.value,path:controls.path.value}); + const note='Filters appear in the address, shared links, and browser history. Search links use the catalog’s pinned source records, not a live research index.'; + const link=()=>{ + const url=current();if(!url)return; + controls.link.href=catalogQueryURL(url,values(),true).href; + controls.link.setAttribute('aria-disabled','false'); + controls.note.textContent=note; + }; + const restore=()=>{ + const url=current();if(!url)return; + const filters=readCatalogQuery(url.search); + controls.search.value=filters.query;controls.repository.value=filters.repository;controls.path.value=filters.path; + link(); + }; + // Read at verified-catalog readiness so newer navigation wins over startup. + restore(); + if(current())win.addEventListener('popstate',()=>{restore();onRestore();}); + return ()=>{ + link();const url=current();if(!url)return; + const next=catalogQueryURL(url,values());if(next.href===url.href)return; + try {win.history.replaceState(win.history.state,'',next.href);} + catch {controls.note.textContent='The address could not be updated. Use Link to this search to preserve these filters. Shared links include the filters and use the catalog’s pinned source records.';} + }; +} diff --git a/docs/site/workspace.html b/docs/site/workspace.html index f5a3b3eae..b0c17c68e 100644 --- a/docs/site/workspace.html +++ b/docs/site/workspace.html @@ -26,7 +26,7 @@

03 / THE EXISTING CATALOG

Find the full argument.

Reading guide ↗

The existing 2,138-file inventory includes proofs, partial arguments, reviews, and historical reading copies. It counts files, not accepted theorems. New imports and proposals have separate public links.

-

Verifying the original inventory and its shards…

Repository / full textCommitSHA-256
+
Link to this search

Search links become available after catalog verification.

Verifying the original inventory and its shards…

Repository / full textCommitSHA-256

04 / JOIN THE WORK

Bring a result. Keep its evidence.

1. Claim a bounded task

Replay a pinned calculation, chart public data, document an import, or leave a source-bound review comment. Comment /claim; wait for assignment and keep one active claim.

Browse public tasks ↗

2. Submit a result PR

Fork main. Add an incoming/<id>/ package with your result, outputs, and source/file identities. Do not edit scientific status rows.

Contribution instructions ↗

3. Review before integration

A designated reviewer checks the sources, scope, and limitations. Intake checks validate packaging; accepted intake is not an accepted theorem.

Public review queue ↗
diff --git a/tests/test_catalog_query.mjs b/tests/test_catalog_query.mjs new file mode 100644 index 000000000..728510e6c --- /dev/null +++ b/tests/test_catalog_query.mjs @@ -0,0 +1,119 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs'; + +// Run the actual app against original hash-verified catalog bytes. These browser +// and fetch boundary doubles do not attest to layout or full accessibility. +const root=new URL('../',import.meta.url); +const html=fs.readFileSync(new URL('docs/site/workspace.html',root),'utf8'); +const config=JSON.parse(fs.readFileSync(new URL('docs/site/config.json',root))); +let run=0; +class Element extends EventTarget { + constructor(tag,attributes){super();this.tag=tag;this.children=[];this.value='';this._text='';this.disabled=attributes.includes(' disabled');this.hidden=attributes.includes(' hidden');} + set textContent(value){this._text=String(value);this.children=[];} + get textContent(){return this._text+this.children.map(child=>typeof child==='string'?child:child.textContent).join('');} + append(...children){this.children.push(...children);} + replaceChildren(...children){this._text='';this.children=children;} + setAttribute(name,value){this[name]=String(value);} + removeAttribute(name){delete this[name];} +} +async function page(t,{query='',hash='#inventory',historyFailure=false,inventoryFailure=false,delay=false}={}){ + const nodes=new Map(); + for(const match of html.matchAll(/<([a-z][a-z0-9-]*)\b([^>]*\bid="([^"]+)"[^>]*)>/gi))nodes.set(match[3],new Element(match[1],match[2])); + const window=new EventTarget(),writes=[],focus=[]; + window.location=new URL('https://example.test/site/workspace.html'+query+hash); + window.history={state:{reader:'keep'},replaceState(state,title,url){if(historyFailure)throw new Error('History refused');writes.push({state,url});window.location=new URL(url,window.location);}}; + window.requestAnimationFrame=fn=>{fn();return 1;}; + const document={getElementById:id=>nodes.get(id)||null,createElement:tag=>new Element(tag,''),createElementNS:(_,tag)=>new Element(tag,''),createTextNode:text=>({textContent:text})}; + for(const [id,node] of nodes){node.scrollIntoView=()=>{};node.focus=()=>focus.push(id);} + nodes.get('dimension').value='2'; + const mapping=new Map([ + ['status.json','docs/site/status.json'],[config.status.url,'tests/fixtures/status_f2e432e.md'], + [config.inventory.url,'docs/public-math/sources.json'],...config.inventory.pages.map(pin=>[pin.url,pin.path]) + ]); + let release;const pending=new Promise(r=>release=r); + const saved=new Map(['window','document','fetch'].map(name=>[name,Object.getOwnPropertyDescriptor(globalThis,name)])); + t.after(()=>{for(const [name,value] of saved)if(value)Object.defineProperty(globalThis,name,value);else delete globalThis[name];}); + globalThis.window=window;globalThis.document=document; + globalThis.fetch=async url=>{ + if(url==='config.json')return new Response(JSON.stringify(config)); + if(url===config.coefficient.url||url===config.imports.url)return new Response('',{status:503}); + if(url===config.inventory.url){if(delay)await pending;if(inventoryFailure)return new Response('',{status:503});} + assert.ok(mapping.has(url),`Unexpected fetch ${url}`);return new Response(fs.readFileSync(new URL(mapping.get(url),root))); + }; + const loading=import(`../docs/site/app.js?catalog-query-test=${++run}`); + if(!delay)await loading; + const change=(id,value,event='input')=>{nodes.get(id).value=value;nodes.get(id).dispatchEvent(new Event(event));}; + return {window,writes,focus,nodes,loading,release,change}; +} +const text=(p,id)=>p.nodes.get(id).textContent; +const count=p=>p.nodes.get('catalog').children.length; + +test('a bookmarked combined search restores the one exact proof and source link',async t=>{ + const p=await page(t,{query:'?q=PROOF.md&repository=Math-&path=coefficients%2Fside24_v1%2F'}); + assert.equal(p.nodes.get('search').value,'PROOF.md');assert.equal(count(p),1); + assert.match(p.nodes.get('catalog').children[0].textContent,/coefficients\/side24_v1\/PROOF.md/); + assert.match(p.nodes.get('catalog').children[0].children[0].children[1].href,/\/blob\/[0-9a-f]{40}\//); + assert.equal(p.writes.length,0); +}); +test('typing preserves unrelated parameters, fragment and history state; share link only includes filters',async t=>{ + const p=await page(t,{query:'?from=research',hash:'#coefficient'}); + p.change('search','SIDE24');assert.match(text(p,'inventory-state'),/^96 matches/); + assert.equal(p.window.location.search,'?from=research&q=SIDE24');assert.equal(p.window.location.hash,'#coefficient'); + assert.deepEqual(p.writes[0].state,{reader:'keep'}); + const link=new URL(p.nodes.get('catalog-link').href); + assert.equal(link.search,'?q=SIDE24');assert.equal(link.hash,'#inventory'); +}); +test('popstate restores filters and pagination without rewriting history or stealing focus',async t=>{ + const p=await page(t);p.nodes.get('more').dispatchEvent(new Event('click'));assert.equal(count(p),100); + const focusBefore=p.focus.length; + p.window.location=new URL('https://example.test/site/workspace.html?q=SIDE24&repository=Math-#board'); + p.window.dispatchEvent(new Event('popstate')); + assert.equal(p.nodes.get('search').value,'SIDE24');assert.equal(p.nodes.get('repository-filter').value,'Math-');assert.equal(count(p),1); + assert.equal(p.writes.length,0);assert.equal(p.focus.length,focusBefore);assert.equal(p.window.location.hash,'#board'); +}); +test('clear filters recovers from no matches and resets pagination with search focus',async t=>{ + const p=await page(t,{query:'?q=NO-MATCH&repository=main&path=missing&keep=1'}); + assert.equal(count(p),0);assert.match(text(p,'inventory-state'),/clear filters/i); + p.nodes.get('catalog-clear').dispatchEvent(new Event('click')); + assert.equal(count(p),50);assert.equal(p.nodes.get('search').value,'');assert.equal(p.nodes.get('repository-filter').value,'');assert.equal(p.nodes.get('path-filter').value,''); + assert.equal(p.window.location.search,'?keep=1');assert.equal(p.focus.at(-1),'search'); + p.nodes.get('more').dispatchEvent(new Event('click'));assert.equal(count(p),100); + p.nodes.get('catalog-clear').dispatchEvent(new Event('click'));assert.equal(count(p),50); +}); +test('unknown repository and duplicate parameters use documented first-value rules',async t=>{ + const p=await page(t,{query:'?q=SIDE24&q=absent&repository=unknown&repository=Math-&path='}); + assert.equal(p.nodes.get('search').value,'SIDE24');assert.equal(p.nodes.get('repository-filter').value,'');assert.equal(count(p),50); + assert.match(text(p,'inventory-state'),/^96 matches/);assert.equal(p.writes.length,0); +}); +test('encoded punctuation stays inert search text',async t=>{ + const p=await page(t,{query:'?q=%3Cscript%3E%26%23%2B%25E0%25A4%25A&path=a%2Fb'}); + assert.equal(p.nodes.get('search').value,'