11 Commits
Author SHA1 Message Date
CatoandClaude 3c6860d110 refactor(dates): validate and count days with @bitbaum/whenkit (#381)
Seven local copies of the YYYY-MM-DD regex (registry schema, entry
vocabulary, graph validation, event rules, event drafts, two quality
checks) and three hand-rolled day calculations (price window dayBefore and
daysBetween, starter rotation day count) are replaced by whenkit's
isISODate, addDays and daysBetween, per the packages-first rule.

isISODate also rejects impossible calendar days (2026-02-30), which the
regex let through; every stored row still passes. The entry isoDate schema
carries JSON Schema format "date", and the printed shape notes YYYY-MM-DD,
so the data-entry shape still states the form after the pattern is gone.
package-plan.json binds the new files under the dates block.

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

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 08:49:49 +01:00
CatoandClaude Opus 5.5 3ed7dff5ed feat(universe): a written rule for which companies are in — and the first 461 identified companies (#250)
* docs(universe): the company-universe methodology — three tests, tiers, evidence

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

* feat(universe): admit companies by a written rule — theme, materiality, identity, each cited

A company is in when cited sources place it in a frontier-technology theme,
show it clears a size floor, and identify it in a registry. admit() applies
the rule from config/universe-themes.ts; whyCompany() answers for any name
(in, out with the failed test, considered, named, or queued as a GapTask);
company_membership lets the Ask answer it; /data/companies prints the rule
from the same config. Tier B companies are a derived entity source with an
'Identified, not profiled' page; a stub the universe identifies is promoted
in place. Adapters: issuer fund holdings (ARK, Global X, First Trust,
Defiance, State Street), SEC EDGAR tickers/public float/SIC, GLEIF and
Wikidata by ISIN, Wikidata industry classes; tested on recorded responses.

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

* data(universe): first wave — 461 tier B companies from 14 funds, EDGAR, GLEIF, Wikidata

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-25 12:54:53 +01:00
CatoandClaude f24778158f feat(policy): every map country is an instrument jurisdiction (#240)
The dossier queue blocked law_licensing for every producer country because
the instruments register knew ten jurisdictions. Jurisdictions now live in
config/substrata-jurisdictions.ts: the curated ten unchanged (ids, order,
lines), then every country in config/substrata-countries.ts by its ISO2,
branded so a bare string cannot pass for one, with one neutral generated
line that asserts nothing about its law.

- add.ts's instrument schema accepts any jurisdiction id (a refinement,
  not a 175-value enum).
- A derived jurisdiction stays out of the /policy table, tiles and map
  links until an adopted or in-force rule is recorded under it; its
  /policy/<iso2> page renders on request and says nothing is recorded,
  with a way to send a source and a link to the country.
- law_licensing tasks are no longer blocked for map countries; the task
  says what to record and lists the sources (gazette, ministry, OECD
  inventory entry with its document, law firm summaries only as
  secondary). Totals, pages and the ten curated rows are unchanged.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-24 11:49:38 +02:00
CatoandClaude Opus 5.5 2d0eb1d6aa feat(entities): stub companies from the relation graph, and a lab entity kind (#235)
* feat(entities): stub companies from the relation graph, and a lab entity kind

Stub companies: every minted company:<slug> node a stated or corroborated
relation touches (1,188 today; NAC Kazatomprom JSC, JV Inkai LLP, Uranium One
Inc.) becomes an entity built from the graph at load, with evidence "stub", a
page on the existing /markets/[slug] route that lists only the relations
naming it (grade, quote, source), and the note that no profile is held.
Rendered on demand, so the static page count is unchanged. The graph's
producers resolve against the directory only (resolveInDirectory), so the
stubs never change the graph they come from. Search and retrieval rank stubs
at 0.6 and leave word rarity to full-weight documents, so profiled rankings
do not move. Events and relations may name a stub; ownership and facility
operator fields stay directory-only. Reviewed aliases redirect to the
canonical page.

Labs: a closed-set `lab` kind (allowEmpty until the pilot fills it), the
labs candidate facet with schema and add.ts gate, a /labs/[slug] profile
(what it works on, where and how to join, stated funders from finances
relations), the lab dossier on lab:<id> with research fronts kept as their
own science kind, and the country people_labs box counting lab rows. Seeds
no lab data. Person is not added: the ADR pins it for office and board
holders, not lab staff.

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

* test(stubs): assert the summary's invariants, not its tail

Main now carries the pilot's Kazatomprom relations, so its stub summary
names a second source and the shipments. The test keeps what must hold:
the yearbook leads, the stakes and the shipments are named.

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 10:51:06 +02:00
CatoandClaude 70e2a863a9 fix(research): data-entry tooling gaps from the country:kz pilot (#232)
- submittedBy.model: the schema asks for "unrecorded" (adapters write
  "deterministic-adapter"); no text asks for a model id; old values still parse.
- Comtrade: the quote spans "reporterCode" through "netWgt", so reporter,
  partner and weight stand in one literal span (adapter records may run to
  800 chars; hand quotes stay at 400). volume.commodity names what HS 284410
  covers, and a new optional relation `note` says the weight is the
  compound's mass, not uranium content.
- run-task: leads are held back on --write and in rows.json unless
  --include-leads; the dry run prints why each row is a lead; rows already
  in the corpus or sidecar are skipped; the run ends with a plain-text list
  (rows written, rows skipped with reasons) to paste into a PR.
- prompts/data-entry.md: all of the above, plus what to do when a box
  cannot be filled honestly.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-24 10:24:53 +02:00
CatoandClaude Sonnet 5.5 5c7da90a25 fix(graph): a flow's commodity is part of its relation id (#224)
* fix(graph): a flow's commodity is part of its relation id

Uranium and refined copper from Kazakhstan to China in the same year are two
relations, but the id was from|type|to|asOf, so the second was skipped as a
duplicate. One rule now (lib/graph/id.ts) is shared by the graph validator and
the candidate path; ids without a stated commodity are unchanged.

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

* style: prettier on run-task

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-24 08:43:42 +02:00
CatoandClaude b2042d210e feat(sources): source adapters, PDF sources in add.ts, and the task runner (#223)
Adapters turn free public registries and filings into candidate relation
rows with their quotes cut from the fetched text. They never write curated
data, never guess an identity and never infer.

- add.ts reads PDFs (unpdf 1.8.1, pinned): page-by-page text, the quote
  check forgives line breaks and line-end hyphenation only, and prints the
  page it found the quote on. Same exit codes.
- lib/sources: an explicit host allow-list with agent strings, pacing, 429
  back-off and a .tmp cache; adapters for UN Comtrade (public preview, no
  key), SEC EDGAR, GLEIF, Wikidata (lead unless a second source agrees) and
  Kazatomprom's IR PDFs. One gate (finalise) drops any row whose quote is
  not in the fetched text; every row carries provenance.
- scripts/research/run-task.ts: a dossier task in, the adapters that serve
  its box in dry run, each row marked whether it fills the box; --write goes
  through add.ts.
- Candidate rows may carry source.locator and provenance.
- prompts/data-entry.md: the adapter workflow a data agent follows first.
- Tests on recorded real responses only (test/fixtures/sources).


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-24 08:37:08 +02:00
CatoandClaude 554a477e6d feat(graph): the typed, sourced, dated relation graph, with its first 1,815 edges (#221)
lib/graph: store + read API (relationsFrom/To, neighbours, pathsBetween,
relationEvidence, graphNode), a validator that throws on any relation without
a source, quote and date and enforces each grade's promise (corroborated needs
two sources, derived its chain and rule, a lead is never counted).

Edges from data already held:
- USGS Minerals Yearbook facility cells parsed conservatively into operates/owns
  (shares only where printed); scripts/research/build-usgs-relations.ts writes
  research/usgs-relations.json with a report of every string left unparsed.
- Ownership holders (stated with a share, lead without) and facility operators.

Candidate path: config/candidates/relations.json folded in through
config/substrata-relations.ts; add.ts accepts the `relations` facet with the
same gates and exit codes. Relation chunks in the retrieval index.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-24 07:55:03 +02:00
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