Files
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

53 lines
1.8 KiB
TypeScript

/**
* What every kind's box file shares: where a facet's rows are written, and
* the parts of a worked example that do not change from box to box.
*/
import type { Facet } from '@/lib/entry/candidate';
import type { WriteTo } from '../definitions';
const ADD = 'pnpm exec tsx scripts/research/add.ts';
/** The candidate path for a facet (`relations` is one: config/candidates/relations.json). */
export function writeTo(facet: Facet): WriteTo {
return {
facet,
file: `config/candidates/${facet}.json`,
command: `${ADD} ${facet} rows.json --dry-run`,
};
}
/** A box no candidate file feeds: a person edits config, or a script regenerates a research file. */
export function byPerson(file: string, command: string): WriteTo {
return { facet: null, file, command };
}
/** Who wrote an example row. A real row names the agent, model and run. */
export const RUN = { agent: 'data-agent', model: 'the-model-id', runId: 'run-0001' } as const;
export const SOURCE = {
/**
* Every worked example carries this in place of a quote. The examples show
* the SHAPE of a good row; a quote is only ever copied from the page read.
*/
shapeOnly: 'Shape only: copy the exact sentence or table cell from the page you read.',
eventExample: {
evidence: 'candidate',
asOf: '2025-12-03',
source: {
url: 'https://www.coherent.com/news',
quote: 'Shape only: copy the exact sentence or table cell from the page you read.',
readOn: '2026-10-24',
},
submittedBy: RUN,
id: '2025-12-03-example-capacity-announcement',
date: '2025-12-03',
headline: 'Producer announces new capacity for a tracked material',
kind: 'capacity',
effect: 'loosens',
bottlenecks: ['Gallium, refined'],
participants: [],
jurisdictions: ['US'],
primary: true,
},
} as const;