mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-04 20:18:06 +01:00
* 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 commit329dd587d8) * 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 commitedcf6eeee7) * 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>
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
/**
|
|
* Progress over the coverage corpus: how much of it carries a source.
|
|
*
|
|
* Views over `config/substrata-coverage.ts`, kept out of that file so the
|
|
* config holds data only.
|
|
*/
|
|
import { MATERIALS } from '@/config/substrata';
|
|
import { CHOKEPOINTS, COVERAGE } from '@/config/substrata-coverage';
|
|
|
|
export interface CoverageProgress {
|
|
/** Research leads in the universe. */
|
|
total: number;
|
|
/** Rows with a primary source attached — the only ones that count as covered. */
|
|
sourced: number;
|
|
/** Materials on the desk with no coverage entry at all. */
|
|
uncoveredMaterials: string[];
|
|
}
|
|
|
|
/**
|
|
* What Phase 1 completion actually means. Rows without a source are leads, so
|
|
* a universe of 90 unsourced entries is 0% covered, not 100% mapped.
|
|
*/
|
|
export function coverageProgress(): CoverageProgress {
|
|
const rows = COVERAGE.flatMap((entry) => entry.producers);
|
|
const covered = new Set(COVERAGE.map((entry) => entry.material));
|
|
return {
|
|
total: rows.length,
|
|
// A candidate row has a URL nobody has promoted: still a lead, not coverage.
|
|
sourced: rows.filter(
|
|
(producer) => producer.source !== null && producer.evidence !== 'candidate',
|
|
).length,
|
|
uncoveredMaterials: MATERIALS.map((material) => material.title).filter(
|
|
(title) => !covered.has(title),
|
|
),
|
|
};
|
|
}
|
|
|
|
/** @returns every material a company appears on — the overlaps are the point. */
|
|
export function materialsFor(companyName: string): string[] {
|
|
return COVERAGE.filter((entry) =>
|
|
entry.producers.some((producer) => producer.name === companyName),
|
|
).map((entry) => entry.material);
|
|
}
|
|
|
|
export interface ChokepointProgress {
|
|
total: number;
|
|
sourced: number;
|
|
byCurve: Record<string, number>;
|
|
}
|
|
|
|
/** Same honesty as the producer map: a row counts only once it has a source. */
|
|
export function chokepointProgress(): ChokepointProgress {
|
|
const byCurve: Record<string, number> = {};
|
|
for (const point of CHOKEPOINTS) {
|
|
byCurve[point.curve] = (byCurve[point.curve] ?? 0) + 1;
|
|
}
|
|
return {
|
|
total: CHOKEPOINTS.length,
|
|
sourced: CHOKEPOINTS.filter((point) => point.source !== null).length,
|
|
byCurve,
|
|
};
|
|
}
|