Let the console search, browse, forget and mount

The store had a write path, a mount path and a search path, and the console
still showed a dashboard of counters. Nothing in the UI could ask what someone
knows, page through atoms, look at a wordless picture, forget one memory, or
mount a cartridge — so the mechanisms built in P0 were invisible.

Backend:
- senses.py: one function decides what this machine can perceive. /api/status
  and doctor each computed it before, which is two truths. Picture atoms are now
  counted by image_ref rather than by modality, so a screenshot crop from a PDF
  counts and a picture whose bytes were deleted stops claiming it can be encoded.
- browse.py: GET /api/atoms pages newest-first through v_atoms_current with
  modality/holder/source filters; GET /api/atoms/{id}/image serves the stored
  bytes so a picture with no OCR text can be looked at.
- Deleted 8 HTTP routes nobody calls (4 benchmark, research modules, dense index,
  visual-contradiction-proof, memory-map). Their functions stay: the CLI and the
  proof checks use them. The surface is 30 routes, pinned as a set by a test so a
  new unused route fails the suite.

Frontend: App.tsx (517 lines) became a 131-line shell plus seven panels that own
their own fetches, and lib/format.ts. types.ts now carries the memory dimensions
the backend has been sending since schema v2.

Two invented fields were rendering lies: AdapterPanel showed gpu_available and
probe_status, which AdapterLoadReport does not have — every machine looked GPU-less
including this one. The panel now shows only what the server says.

Proof: scripts/ui_smoke.sh starts the API on a fresh temp home, serves the built
UI from the same origin, and drives five interactions in a real browser — search
as somebody in a scenario, page and view a wordless picture, forget, mount, read
adapter states with reasons. It prints the mount refusal verbatim rather than
pretending the mount succeeded.

Gates: 263 pytest passed; ruff and mypy clean on the 8 touched backend files
(repo-wide mypy unchanged at 24 errors / 6 files); pyright 0 errors there;
go build/vet/test/gofmt clean; npm build + eslint clean; ui_smoke and
mcp_write_smoke both PASS.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-08 05:13:38 -04:00
1 parent a5008e1476
commit 9f91ff7ed7
27 files changed
+2146 -616

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
"""Page through the store the way a person browses a shelf: newest first, filtered by who and what."""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from .config import Settings
from .db import Database, row_to_atom
from .retrieval import decode_cursor, encode_cursor
from .schemas import AtomPage, Modality
from .storage import ObjectStore
@dataclass(frozen=True)
class Picture:
"""The bytes behind an atom and how to label them when serving."""
path: Path
mime: str
def browse(
settings: Settings,
*,
limit: int,
cursor: str | None = None,
modality: Modality | None = None,
source_id: str | None = None,
holder: str | None = None,
) -> AtomPage:
"""One page plus the total, so a list can say what it left out instead of looking endless."""
offset = decode_cursor(cursor)
wanted = (modality.value if modality else None, source_id, holder)
filters = tuple(value for bound in wanted for value in (bound, bound))
database = Database(settings)
with database.connect() as connection:
total = int(
connection.execute(
"SELECT COUNT(*) FROM v_atoms_current WHERE (? IS NULL OR modality = ?) AND (? IS NULL OR source_id = ?) AND (? IS NULL OR holder_id = ?)",
filters,
).fetchone()[0]
)
rows = connection.execute(
"SELECT * FROM v_atoms_current WHERE (? IS NULL OR modality = ?) AND (? IS NULL OR source_id = ?) AND (? IS NULL OR holder_id = ?) ORDER BY ingested_at DESC, atom_id DESC LIMIT ? OFFSET ?",
(*filters, limit + 1, offset),
).fetchall()
atoms = [row_to_atom(row) for row in rows[:limit]]
more = len(rows) > limit or offset + limit < total
return AtomPage(
atoms=atoms,
total=total,
next_cursor=encode_cursor(offset + limit) if atoms and more else None,
)
def picture(settings: Settings, atom_id: str) -> Picture | None:
"""The stored bytes behind one atom, through the same visibility view search uses.
None covers three cases the caller cannot tell apart and does not need to: the atom is unknown,
it was forgotten, or its bytes are gone. All three mean "there is no picture to show".
"""
database = Database(settings)
with database.connect() as connection:
row = connection.execute(
"SELECT image_ref, mime FROM v_atoms_current JOIN sources USING (source_id) WHERE atom_id = ?",
(atom_id,),
).fetchone()
if row is None or not row["image_ref"]:
return None
path = ObjectStore(settings).resolve(str(row["image_ref"]))
if not path.exists():
return None
mime = str(row["mime"]) if row["mime"] else "image/png"
return Picture(path=path, mime=mime)