Imported from code-yeongyu/senpi (
packages/ai/scripts/AGENTS.md). Install upstream withnpx skills add code-yeongyu/senpi --skill scripts. Copyright stays with the author.
packages/ai/scripts
Generated: 2026-08-24. Commit baf15a54d.
Networked generators that produce the committed model catalogs (src/providers/data/*.json, src/models.generated.ts, src/image-models.generated.ts) plus their validators. Scored 7 but kept: this is the only place the generation contract (flags, staging/rename, manifest hashing) is written down, and the parent file states only the outcome.
FILE MAP
generate-models.ts 3.4k LOC orchestrator; all four model scripts are flag variants of it
generate-models-opengateway.ts fetchOpenGatewayModels + OpenGatewayReasoningRecorder (enrichment source)
models-dev-reasoning-options.ts getEffortThinkingLevelMap — models.dev effort -> thinkingLevelMap
model-data.ts Shared manifest/schema layer: MODEL_DATA_SCHEMA_VERSION=3,
createModelDataManifest, validateGeneratedModelData, assertExactModelIds
check-model-data.ts Thin CLI over validateGeneratedModelData
generate-image-models.ts Image catalog (OpenRouter `/models?output_modalities=image`)
generate-test-image.ts Writes test/data/red-circle.png; requires the `canvas` native dep
transform-cursor-agent-proto.mjs Rewrites protoc-gen-es enums to const objects for erasableSyntaxOnly
FLAG CONTRACT (generate-models.ts)
| Invocation | Flags | Effect |
|---|---|---|
bun run generate-models |
--strict |
Full: data/ JSON + models.generated.ts |
bun run hydrate-model-data |
--strict --data-only |
data/ JSON only; rejects any JSON-catalog flag |
bun run generate-model-catalog |
--strict --json-only --json-output <dir> |
Publishable catalog to .artifacts/model-catalog; --json-only requires --json-output |
bun run check:model-data |
— | Validates manifest hashes; fails with "run bun run hydrate:model-data from the repository root" |
--strict turns per-provider fetch failures into a thrown error instead of a skip. Without it a network hiccup silently ships a shrunken catalog — always keep it on for committed regeneration.
CONVENTIONS
data/writes are staged, not in-place: a.model-generation-*temp dir undersrc/providers/, then rename-swap with the previous dir kept for rollback. Never writedata/file-by-file.- Every provider fetch skips records with
status === "deprecated"(five separate call sites) — deprecated upstream models must not enter the catalog. model-data.tsis the single schema authority: the manifest carries a sha256 per file plus astructureHash, so a hand-edit of any JSON failscheck:model-data.- Scripts run under
tsx(see package scripts), use explicit.tsimport suffixes, and import repo types from../src/types.ts— they are type-checked against runtime contracts, not standalone. - These are the only files in the package that legitimately use bare
fs/pathimports rather thannode:-prefixed ones; leave the style alone unless converting the whole file.
ANTI-PATTERNS
- Hand-editing
src/providers/data/*.json,src/models.generated.ts, orsrc/image-models.generated.tsinstead of rerunning the generator — the manifest will catch it, but only atcheck:model-datatime. - Running generation without
--strictand committing the diff. - Adding a provider fetcher that does not honor the deprecated-status skip or the staging/rename path.
- Editing
src/api/cursor-agent/gen/agent_pb.tsby hand: regenerate viabuf generateonproto/cursor/agent.proto, thenbun scripts/transform-cursor-agent-proto.mjs <in> <out>(the exactbufinvocation is in that file's header comment).
VALIDATION
- After any regeneration:
bun run check:model-data, then inspect thedata/diff for unintended model removals. - Root-level entry points are
bun run generate:models,bun run hydrate:model-data,bun run check:model-data; thepackages/aiscripts are what they delegate to.