4 Commits
Author SHA1 Message Date
CatoandClaude Opus 5.5 78943594ab fix: restore the data-entry contract (#211) and the search index (#212), removed by #213 (#216)
* feat(entry): the data-entry contract — candidate rows a cheaper model may add, validated at the gate (#211)

PR 5 of docs/architecture/2026-10-23-knowledge-system.md §3.

- lib/entry/candidate.ts: candidate types derived from each config row
  (CandidateOf<Row>), and the folds that merge a sidecar row into its config
  list flagged `evidence: 'candidate'`. No runtime config import, so config
  modules include it without a cycle.
- lib/entry/schemas.ts (+ vocab.ts, shape.ts): one Zod schema per facet, each
  `satisfies z.ZodType<…Candidate>`, refs resolved through resolveIn / the
  config's closed lists; events reuse lib/event-rules eventProblems.
- config/candidates/<facet>.json: eight empty sidecars, merged into COVERAGE,
  EVENTS, ENDOWMENTS, FACILITIES, INSTRUMENTS, SCIENCE, OWNERSHIP and the
  corpus series the way substrata-events-accepted.json is merged into EVENTS.
- A candidate producer reads "Candidate source", never "Sourced"
  (verificationFor takes the row's evidence), and coverage progress does not
  count it.
- scripts/research/add.ts <facet> <json|-> [--dry-run] [--branch] [--schema]:
  exit 2 schema, 3 unreachable, 4 quote absent (verbatimIn), 5 duplicate;
  appends sorted, idempotent; --branch commits on data/<facet>-<key>.
- test/candidates.test.ts: every sidecar row passes its schema, is
  `candidate`, has url + asOf <= today; the gate exits 4 / appends sorted /
  exits 5 against a local HTTP server.
- prompts/data-entry.md: the §3.4 prompt, how to run it, the printed shapes.
- NODE_TYPE_LABEL moves to config/substrata.ts and the ownership labels to
  config/substrata-ownership-labels.ts (both re-exported) to keep the two
  config files under their size ceilings.

Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

Co-authored-by: Claude <noreply@anthropic.com>
(cherry picked from commit 329dd587d8)

* feat(index): the corpus as retrievable chunks, and the ask-evals that name the failures (#212)

* feat(index): the corpus as retrievable chunks, and the ask-evals that name the failures

PR 2 and PR 3 of docs/architecture/2026-10-23-knowledge-system.md §7.

- test/ask-evals.json: 20 questions (bottleneck, company, country, material,
  policy, science, capital, events, jobs, three off-topic), including
  niger-uranium with mustNotLead oil/natural gas and its quality gap.
  test/ask-evals.test.ts checks them against planLookups and the in-process
  retriever, no model, no DB; rows waiting on PR 1 / PR 6 are skipped with
  a printed count.
- lib/index/: Chunk type, ids, hashes, splitter; one producer per facet
  (entity, event, series, policy, science, restriction, quantity, ranking,
  quality); buildChunks(); retrieve() with the ADR's hybrid score minus
  vectors, reusing scoreDocuments. Evidence labels map to the closed set in
  one function, typed against config/substrata-evidence.
- search_corpus runs on retrieve(), so chat sees events, series, policy,
  restrictions, quantities, rankings and findings as rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

* perf(index): warm the chunk index at server start, off the request path

buildChunks() costs ~5 s cold; without this the first reader to Ask after a
deploy paid for it inside search_corpus. instrumentation.ts register() (nodejs
runtime only) loads lib/index/warm and schedules the build on a later
event-loop turn without awaiting it; a failure only logs, and the index then
builds lazily as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

---------

Co-authored-by: Claude <noreply@anthropic.com>
(cherry picked from commit edcf6eeee7)

* chore: restore #211 and #212, removed by #213's squash-merge

The Ask panel branch (#213) was cut before the data-entry contract (#211)
and the search index (#212) merged; its squash-merge wrote main back to
its own copy of those files and deleted both features (60 files: lib/entry,
lib/index, config/candidates, prompts/data-entry.md, scripts/research/add.ts,
instrumentation.ts, test/ask-evals*). The two commits above re-apply them
onto current main by cherry-pick; both applied without conflicts, and
format, type-check, lint and 660 tests pass (4 pending evals skipped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-23 13:47:27 +02:00
CatoandClaude 366d3edb30 feat(ask): the Ask panel scrolls, expands to /chat, and answers draw charts (#213)
The owner's phone (2026-10-23, /atlas, Ask Substrata over a bottleneck): the
answer could not be scrolled, there was no way to expand it, "Quick replies"
was a heading over nothing, "3 records read" a stray line, and the composer
carried "Model: Auto" and a paperclip.

- The panel is chatkit's ChatScreen in a sheet (AskPanel): on a phone a
  bottom sheet to 92% of the visual viewport with a grip; from 768px a
  right-hand panel. One title row: Ask Substrata · Expand · Close.
- Expand hands the whole thread to /chat (lib/ask-thread.ts); the URL
  carries only an id and the conversation id continues.
- Suggested replies are chatkit's reply row (nothing drawn when empty);
  records read are the thought row above the answer ("Read 3 records").
- Composer: microphone and send; the key chip only with a BYOK key.
- Charts in answers (chatkit 0.15): chart blocks drawn by chartkit
  (LineChart, BarChart, ShareBars, Timeline, StatTiles) on every chat
  surface; chartable tools return page links and plain numbers.
- --ck-page mapped to the surface token: unmapped, the dark theme drew
  light text on chatkit's near-white page.
- check:ask-layout (scripts/ux/ask-layout.mjs): 320/390/1440, light and
  dark — the thread scrolls, no sideways overflow, 44px targets, no cut
  words, Expand lands on /chat with the same turns.


Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-23 13:00:25 +02:00
CatoandClaude 329dd587d8 feat(entry): the data-entry contract — candidate rows a cheaper model may add, validated at the gate (#211)
PR 5 of docs/architecture/2026-10-23-knowledge-system.md §3.

- lib/entry/candidate.ts: candidate types derived from each config row
  (CandidateOf<Row>), and the folds that merge a sidecar row into its config
  list flagged `evidence: 'candidate'`. No runtime config import, so config
  modules include it without a cycle.
- lib/entry/schemas.ts (+ vocab.ts, shape.ts): one Zod schema per facet, each
  `satisfies z.ZodType<…Candidate>`, refs resolved through resolveIn / the
  config's closed lists; events reuse lib/event-rules eventProblems.
- config/candidates/<facet>.json: eight empty sidecars, merged into COVERAGE,
  EVENTS, ENDOWMENTS, FACILITIES, INSTRUMENTS, SCIENCE, OWNERSHIP and the
  corpus series the way substrata-events-accepted.json is merged into EVENTS.
- A candidate producer reads "Candidate source", never "Sourced"
  (verificationFor takes the row's evidence), and coverage progress does not
  count it.
- scripts/research/add.ts <facet> <json|-> [--dry-run] [--branch] [--schema]:
  exit 2 schema, 3 unreachable, 4 quote absent (verbatimIn), 5 duplicate;
  appends sorted, idempotent; --branch commits on data/<facet>-<key>.
- test/candidates.test.ts: every sidecar row passes its schema, is
  `candidate`, has url + asOf <= today; the gate exits 4 / appends sorted /
  exits 5 against a local HTTP server.
- prompts/data-entry.md: the §3.4 prompt, how to run it, the printed shapes.
- NODE_TYPE_LABEL moves to config/substrata.ts and the ownership labels to
  config/substrata-ownership-labels.ts (both re-exported) to keep the two
  config files under their size ceilings.


Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-23 12:32:49 +02:00
CatoandClaude Opus 5.5 cfaf05a10c refactor: split the god files by job, and globals.css by feature (#83)
Every code file the size ratchet grandfathered is now under its 300-line
ceiling, split by what it does rather than by line count:

- lib/search.ts -> entry + lib/search/{text,corpus,build,expand,score,snippets}
- lib/chat-tools.ts -> lib/chat-tools/ (one module per tool family + registry)
- lib/chat-agent.ts -> lib/chat-agent/{loop,parse,turn,prompt,stream-gate}
- lib/chat.ts -> lib/chat/{types,retrieve,models,answer}
- ResearchChat.tsx -> components/portal/chat/ (thread, turn, composer,
  BYOK panel, contribute form, hooks)
- SearchBox.tsx -> components/portal/search/ (popover, page form, shared)
- profile modules, lib/bottlenecks.ts, lib/participants.ts -> build/board
  and module-family files beside them
- app/page.tsx, app/markets/[slug]/page.tsx, app/policy/page.tsx -> section
  components in private _home/_sections folders

globals.css (2379 -> 664 lines) keeps tokens, base and site chrome; the
feature blocks moved to app/styles/*.css, imported from the root layout in
the order they had inside globals.css so the cascade is unchanged.
Screenshots of /, /search?q=asml, /markets/asml, the EUV bottleneck, /chat,
/notes, /atlas, /policy and /talent at 390/820/1440px are pixel-identical
to main.

The config/ corpus files stay grandfathered as data; the logic that was in
them moved to lib/ (coverage-progress.ts, participants.ts, geo.ts).

Also: the desk's "Open on" select said "Last all time"; and
INFRASTRUCTURE.md now records the hourly :17 sweep timer, the everyHours
setting that decides whether a run is due, and that 005-desk.sql is applied.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:22:12 -07:00