10 Commits
Author SHA1 Message Date
CatoandClaude fa73bb626b fix(chat): the reader is told when the web search brought nothing back (#372)
Seen on production: every question showed "Searching the web for …" in
its steps and then an answer with no web page and no word about it. The
search outcome was known to the prompt only, so saying it was left to
the model, which did not.

The outcome of the answer's web searches (found, nothing, or could not
be reached) is now recorded by the search itself and carried on the
answer. When no page came back, a line under the answer says which of
the two it was. An outage is never told as "found nothing".

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

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 06:15:56 +01:00
CatoandClaude Opus 5.5 f4ee258bc8 refactor(ask): chatkit 0.19 — send handle, initial message, Retry keeps pictures; three answer fixes (#264)
* refactor(ask): chatkit 0.19 — send handle and initial message, thrown turn failures

Delete lib/chat/drive-composer.ts and useAutoAsk.ts, which typed into
chatkit's composer and pressed Send. /chat?q= is ChatApp's deepLinkParam
(sent at once, as before), the home box's ?send= handoff is its
initialMessage, and "Check this" goes through the ref's send with
newChat. The transport throws ChatTurnError instead of returning a failed
message, so the bubble keeps the server's words and Retry re-sends the
pictures.

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

* fix(ask): an attributed claim is Reported when the source only shows it was said

"Confirmed" over "Gartner estimates a $4.9T gap [W2]" told the reader
the gap was real when the page showed only that Gartner said so. The
writer is told the difference, and code downgrades an attributed
claim's Confirmed to Reported when its source line names the speaker or
reports a saying. Partly and Not found are unchanged.

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

* fix(ask): never cut a markdown link in two when dropping sentences

A link whose title held a full stop was split at it; when a guard dropped
the first half the reader saw "…IaaS… ](https://x.com/…))" in the
Reasoning. withoutMaterialFigures, withoutSentencesHolding and
uncitedForecasts split with a bare regex; default-deny masked links
itself. All four now split through lib/chat-agent/sentences.ts, which
masks links (URLs with one level of parentheses included) while
splitting.

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

* fix(ask): a web chip only on a sentence its page supports

The opening of a screenshot answer ended its generic analysis in [W1],
drawn as a finance.yahoo.com chip, and the page (a stock quote) said
nothing of the kind. Before default deny, a [W#] now stays only on a
sentence that carries a figure the cited passage prints or a name it
gives; otherwise the marker comes off and the sentence is judged as
uncited.

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

* fix(ask): the panel's chat list is a drawer at every width

ChatApp's rail follows the window (64rem), so in the ~30rem panel on a
desktop the list took half the panel and left the answer a 12rem column.
The panel passes railQuery="not all"; /chat keeps the rail.

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

* docs(changelog): the answer fixes and the panel's chat list

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-27 21:44:15 +01:00
CatoandClaude Opus 5.5 6e5bbf3483 feat(markets): a company page that reads like a markets product (#259)
* feat(markets): a company page that reads like a markets product

The owner, 2026-10-25: "I don't see any beautiful charts on stock
performance … think Bloomberg, think Yahoo Finance", and on NVIDIA's
holders, "'other' is 87%. We have a vague idea of what that means."

Every company page now carries one market frame, in one order, whatever
the company is (docs/design/company-page.md): a header quote (ticker,
exchange, currency, last close, 1-day change, date, "delayed end-of-day ·
Yahoo Finance"), then share price, key statistics, revenue and net income
by year, who owns it, how it does business, and peers. A section with no
data stays and says what source would fill it, with a Send-evidence link.

- Share price: a line chart with one row of six equal range cells
  (1M·3M·6M·YTD·1Y·5Y), the page's only client island. Every range is
  computed on the server, along with its return, span and largest fall,
  the 52-week range, a returns table and the 50/200-day averages
  (prices/compute.ts).
- Key statistics: eight equal cells. Market value is computed only where
  close × cover shares is the value; otherwise "Not computed" with the
  reason. Each annual figure shows its fiscal year, growth and filing.
- Financials: chartkit's new ColumnChart (0.2.0) for five fiscal years
  from XBRL, plus rows with growth and margin computed in code.
- Who owns it: holders from 13G/13D/proxy. The remainder is labelled
  "Others, each below 5%" in the legend (chartkit's new ShareBars
  otherLabel) and explained in its row. A company with no listing shows
  the owners the relation graph states.
- How it does business: customers, suppliers, competitors (always), and
  stakes, sites and partners from lib/graph, one row anatomy. An empty
  group names the filings that would fill it, and points to the quoted
  dependency rows where they exist.
- Peers: the same chain step (tier A) or the same theme (tier B), with
  last close, 1Y return and a sparkline.

Tier B companies get prices, financials and holders: lib/market-data/company.ts
joins a slug to a listing. It tries the seed first, then the universe
ticker on a venue the price source serves. New venues (US composite,
London, Hong Kong, Korea, Taiwan, Toronto, SIX) are added to Yahoo's
suffixes. Ambiguous venue codes are not guessed. Sections stream in their
own Suspense boundaries, with reads deduplicated per request, so a slow
price source never delays the header. Ask charts link "Open <Company>" to
the page, and the holders bar in answers carries the remainder label.

Verified: pnpm run verify; pnpm run build; test/company-page.test.ts;
scripts/ux/company-layout.mjs at 320/390/768/1440 on NVIDIA, Oklo,
SpaceX, NAC Kazatomprom and a stub, against live Yahoo and SEC.

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

* docs(design): the header's quote lives in price-view.ts

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-27 13:43:25 +01:00
CatoandClaude ac8056fd77 refactor(ask): chatkit ChatApp for the panel and /chat (#262)
The Ask panel and /chat were Substrata's own assembly of chatkit's pieces
(ChatScreen, Composer, ChatThread) with no chat list, no New chat and no
reload. They are now chatkit 0.18's ChatApp, the same app Heidi, Loki and
OrangeCat move onto: Chats drawer (a rail on a wide screen) with search,
rename and delete, New chat, temporary chat, titles, the queue, Stop and
the open chat reopened on reload. Chats are kept on the reader's device
(localConversationStore); no server conversations, no migration.

Substrata keeps only its own parts: the transport (askTransport: /api/chat
with pictures, the stream into turn.update, the evidence on the message,
the server's own words on a failed turn), chartkit renderers, AnswerFooter,
the key and "Send evidence" under the composer, one composer configuration
shared with the home box. Panel and /chat share the store and the open
chat, so Expand is only a bigger frame (lib/ask-thread.ts goes). A message
from elsewhere (Check this, ?q=, the home box's ?send= with its pictures)
opens a new chat and is sent through the composer, since ChatApp has no
send handle yet (lib/chat/drive-composer.ts says so).


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-27 12:35:27 +01:00
CatoandClaude 0dc40c2530 feat(ask): attach screenshots, read them, check their claims (#260)
The owner could not ask Substrata about a screenshot of a post: every
composer passed attach={false}, and /api/chat took no pictures.

- One composer (AskComposer) on the home box, the Ask panel and /chat:
  Camera / Photos / Files, paste and drop, pictures shrunk to 1024px in
  the browser (Heidi's limits), text files inlined, a message queued while
  a turn runs, the draft shared between surfaces.
- /api/chat validates pictures (strict data URLs, three at most, 1.5 MB,
  never stored or logged) and attached text, with a larger body cap.
- A turn that brings material is a claim check: one read call returns the
  visible text and checkable claims as JSON (claims whose numbers the
  material never printed are dropped), each claim is searched and, for a
  seed company, priced; the answer is bottom line first, one status per
  claim with a citation or "Not found", reasoning labelled, and no figure
  only the material gives repeated as fact. Every existing guard runs.
- No model that can see: one sentence (paste the text, or add a key);
  nothing is guessed.
- The home box hands its message and attachments to /chat (?send=).

Tests: claim-check (fixture, fake vision model, fake web), handoff, image
validation; two eval rows; ask-layout picks a picture into /chat's box.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-27 10:36:52 +01:00
CatoandClaude Opus 5.5 73dd498f49 feat(market-data): share prices, SEC fundamentals and filing-based holders, with Ask tools and charts (#249)
* feat(market-data): share prices, SEC fundamentals and filing-based holders, with Ask tools and charts

Prices: daily split-adjusted closes from Yahoo Finance's chart endpoint (query1,
then query2), stored in research_price_points by /api/cron/prices, read by
priceHistory(ticker, range) with a live fallback; returns, 52-week extremes,
drawdown and moving averages computed in code. Stooq (browser challenge),
Nasdaq (browser agent only) and Alpha Vantage (unadjusted free closes) were
tested and rejected; the reasons and the licence position are in
lib/market-data/prices/chain.ts.

Fundamentals: SEC XBRL company facts per CIK — revenue, margins, R&D, capex,
cash, assets, debt, shares — each point with form, accession and filing link;
a typed "unavailable" with the reason for companies the SEC holds nothing for.

Holders: the proxy's ownership table, structured Schedules 13G/13D filed since
(issuer checked, 0% amendments honoured) and recent Forms 4, with the rest as a
typed remainder that says what it is — never a bare "Other 87%". The company
page's ownership view and share bar carry the same remainder.

Ask: price_history, fundamentals and holders tools; a price question plans
price_history and the answer draws a line chart built in code (answer charts
routed like answer tables); four ask-evals rows.

Keyed by ticker in lib/market-data/identity.ts with a committed seed
(config/market-seed.ts) as the seam for the company universe.

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

* fix(market-data): fundamentals lists newest first so a length cut keeps the latest years

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-27 08:47:33 +01:00
CatoandClaude Opus 5.5 8e85c7e7b4 feat(ask): search and read the web up front for open-world questions (#244)
* feat(ask): search and read the web up front for open-world questions

The owner read the recent chats: the Ask behaved like a search over the
corpus, not like a language model that researches. Asked for Kazatomprom's
2026 guidance it opened with "The Substrata corpus does not track..." and
never gave the figure; asked how competitors' share prices moved this month
it said Substrata "does not record" equity moves, with web leads unused.

- route.ts: a pure router decides per question whether the web is needed
  (news, prices, guidance, what someone said, competitors, people,
  explanations, and by default anything but questions about Substrata
  itself or off-topic chat). runPlan searches it in parallel with the
  corpus lookups; "this month"/"today" become dated queries.
- Pages are read, not snippets: top four in parallel, PDFs as text via
  unpdf behind readPage's SSRF checks, the matching passages verbatim with
  the page's date.
- Prompt: answer first and directly from corpus rows, [W#] passages and
  marked general knowledge; figures only from a row or a dated passage;
  never open with what the corpus lacks.
- Guards: a figure cited [W#] must be in that passage (sent back once,
  then dropped); marked background survives default deny without figures
  or link claims; corpus-gap openings move to the end and "Unchecked web
  results" headings go. Corpus table guards unchanged.
- UI: [W#] renders as a chatkit source chip linked to the page with its
  site and date; "Web pages read · not checked by Substrata" under it;
  "Reading <domain>…" steps while it works.
- Evals and tests for the router, page reading (fake fetch), the PDF
  path, the web-figure guard, answer-first, and the six new questions.

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

* docs(ask): record the open-web Ask policy and why

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-24 18:49:23 +02:00
CatoandClaude e7959fb3d9 feat(ask): tables not walls, reviewed entity aliases, and the graph as chat tools (#222)
Asked live on 2026-10-24 which companies mine uranium in Kazakhstan and who
owns them, the Ask answered correctly from the USGS 2023 yearbook but pasted
the cell as one paragraph of sixteen ventures and one of sixteen places; the
graph split Kazatomprom in two; and no tool read the graph at all.

- Tables: producers_in builds an answer table in code from its rows
  (operator | owners as printed | commodity | location | capacity | year),
  one row per venture of a "Companies:" cell, every cell verbatim; a place
  list or capacity printed once for many rows is a shared note, never
  divided. registry.ts routes a result's `table` to the answer, not the
  model; the model is told not to paste. Drawn under the prose
  (AnswerTables): a table where wide, cards where narrow (container query),
  eight rows then "Show all", long places folded.
- Entity aliases: config/entity-aliases.ts holds reviewed pairs only
  (NAC Kazatomp JSC, UraniumOne Inc., Glencore), each with the rows that
  justify it; lib/graph/alias-match.ts proposes by named rules and
  `pnpm run research:alias-candidates` prints proposals with evidence.
  research/usgs-relations.json regenerated.
- related_to and how_connected over lib/graph: rows with share, grade,
  counted flag, source quote (the venture's part of a long cell, verbatim)
  and reading kind; leads listed apart and never counted. Planned first for
  who owns / shareholders / holds stakes / partners / how connected; the
  ladder counts related_to owners as covering the owners link.
- Six no-wall evals (Inkai, Kazatomprom, Cameco, Sumitomo, Collahuasi,
  Gazprom) with graded verbatim quotes; check:ask-layout draws the table at
  320/390/1440.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-24 08:29:39 +02:00
CatoandClaude Opus 5.5 b2dea2fcef feat(ask): fast, any AI via shared ai-kit BYOK, one-click claim verification (#89)
* feat(ask): fast, any-AI via shared ai-kit BYOK, and one-click claim verification

- BYOK on @bitbaum/ai-kit/byok (1.12.0): ten OpenAI-shaped vendors incl.
  Anthropic and Gemini, streamed with tools; drops @anthropic-ai/sdk and the
  local byok-shared copy. Signed-in keys sealed server-side (ai-kit/seal,
  SUBSTRATA_BYOK_SECRET, research_ai_keys); signed-out keys stay in the browser.
  Model picker reads the vendor's live catalogue. Panel in Ask and /account/settings#ai.
- Speed: status before any lookup, parallel tool calls, 3-round cap, page-only
  questions skip tools, free-chain link cooldown after 429s, parallel web reads,
  trimmed history.
- Verify: Check this on every Figure, event rows, bottleneck facts, company lede.
  Reads the cited source + searches the web in parallel before the model, answers
  Supported/Contradicted/Outdated/Unverifiable with quoted passages and links.
- /api/factcheck now runs the same agent loop.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ask): claim context for list values, computed figures check via their method, no web search for bare numbers

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 14:10:02 -07: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