Files
CatoandClaude Fable 5.2 b6f04bb60b feat(themes): each organisation's themes are its own data (#214)
* feat(themes): each organisation's themes are its own data

ThemeId was a code enum of one organisation's seven fields of work, and every
foundation, badge, filter, score, Gesuch and triage prompt on the platform was
described in it. An assessment stored in another organisation's theme ids
failed to parse and disappeared from its pages.

Themes are now org_content['themes'] per organisation (shape and lookups in
src/lib/schemas/theme.ts), authored in org-context/<org>/themes.json. Each
theme carries its label, the story section and HOW slot a Gesuch draws on,
whether it is a region, and the keywords the register is classified with; the
order is the order the organisation leads with. The story is bound to its
organisation's vocabulary, so a composer cannot describe a foundation in
another organisation's themes. HOW competency slots are the organisation's own.

The triage prompts are built from the organisation's own brief
(org_content['triage-brief']) and themes. pipeline-graduate phase 1 reads the
organisation's assessments instead of a column migration 0015 dropped.

Migration 0020 writes the first tenant's vocabulary and brief, ported
unchanged from the code: the classifier gives identical themes on all 16,781
foundations of the 29 Nov register, and a test holds the story mapping and the
migration to the files. One put script (org-content:put) stores themes, triage
brief and raise profile from org-context.

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

* feat(themes): the workspace reads the organisation's own themes

The tools moved to the workspace while this was under review; its layout
now loads the theme vocabulary of the organisation in the URL.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtMwPqoAJ2pHxdSn3t

* docs(claude): the quick reference describes the workspace

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtMwPqoAJ2pHxdSn3t

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-30 23:40:20 +01:00

98 lines
4.0 KiB
TypeScript

#!/usr/bin/env tsx
/**
* Org Screen — keyword screen of the public register for one organisation.
*
* Reads a register snapshot (`pnpm run zefix:download`) and the organisation's
* own theme vocabulary (`org-context/<org>/themes.json`), and writes the candidates to
* `research/org-screen/<org>-<date>.json`.
*
* Reads no database and writes none; calls no model; contacts nobody. The
* result is a reading list for a person, not an assessment: storing a second
* organisation's assessments needs themes to be per-organisation data first
* (docs/FUNDERS.md, "What is still foundation-shaped").
*
* Usage:
* pnpm run screen:org -- --org biaslens
* pnpm run screen:org -- --org biaslens --register research/zefix-register-2026-11-29.json
*/
import * as fs from 'fs';
import * as path from 'path';
import { requireOrgId } from './lib/require-org';
import { screenRegister, type RegisterEntry } from './lib/org-screen';
import { themeVocabulary, themeVocabularySchema } from '../src/lib/schemas/theme';
function latestRegister(): string | null {
const dir = path.resolve('research');
if (!fs.existsSync(dir)) return null;
const files = fs
.readdirSync(dir)
.filter((f) => /^zefix-register-\d{4}-\d{2}-\d{2}\.json$/.test(f))
.sort();
const last = files.at(-1);
return last ? path.join(dir, last) : null;
}
function main() {
const orgId = requireOrgId();
const args = process.argv.slice(2);
const registerFlag = args.indexOf('--register');
const registerPath = registerFlag !== -1 ? args[registerFlag + 1] : latestRegister();
if (!registerPath || !fs.existsSync(registerPath)) {
console.error('No register snapshot found. Run `pnpm run zefix:download` first.');
process.exit(1);
}
const rulesPath = path.resolve('org-context', orgId, 'themes.json');
if (!fs.existsSync(rulesPath)) {
console.error(`No theme vocabulary for '${orgId}': ${rulesPath} does not exist.`);
process.exit(1);
}
const stored = themeVocabularySchema.parse(JSON.parse(fs.readFileSync(rulesPath, 'utf-8')));
const themes = themeVocabulary(stored.themes);
if (!stored.themes.some((t) => t.keywords.length > 0 || t.compounds.length > 0)) {
console.error(`${rulesPath} has no keywords; nothing can be matched.`);
process.exit(1);
}
const register = JSON.parse(fs.readFileSync(registerPath, 'utf-8')) as {
meta: { date: string; source: string };
foundations: RegisterEntry[];
};
if (!register.foundations.some((f) => f.purpose)) {
console.error(
`${registerPath} carries no purpose text. It was downloaded before the\n` +
'download recorded purposes; run `pnpm run zefix:download` again.',
);
process.exit(1);
}
const report = screenRegister(register.foundations, orgId, themes);
console.log(`\nKeyword screen for '${orgId}'`);
console.log(` Register: ${registerPath} (${register.meta.source}, ${register.meta.date})`);
console.log(` Rules: ${rulesPath}`);
console.log(` Foundations in the register: ${report.total}`);
console.log(` With a registered purpose: ${report.withPurpose}`);
console.log(` No keyword of this organisation: ${report.noThemeMatch}`);
console.log(` Keyword match, but not a funder: ${report.notAFunder}`);
console.log(` Candidates: ${report.candidates.length}`);
console.log(` core theme matched: ${report.byTier.core}`);
console.log(` adjacent theme only: ${report.byTier.adjacent}`);
for (const theme of stored.themes) {
console.log(` ${theme.id.padEnd(22)} ${report.byTheme[theme.id] ?? 0}`);
}
const outDir = path.resolve('research/org-screen');
fs.mkdirSync(outDir, { recursive: true });
const outPath = path.join(outDir, `${orgId}-${register.meta.date}.json`);
fs.writeFileSync(
outPath,
JSON.stringify({ register: register.meta, rulesBasis: stored.basis, ...report }, null, 2),
);
console.log(`\n Written: ${outPath}`);
console.log(' These are candidates to read about, not assessed fits.\n');
}
main();