Repository navigation
tools codegen
pnpm codegen (implemented in tools/codegen/src/cli.mjs) is a schema-driven generation tool. It imports the Zod schemas from @safrs/schemas at runtime — treating them as the single source of truth — and produces:
- an OpenAPI 3.1 document (
--openapi), -
mock data factories (
--mock), - a typed fetch wrapper over the Hono client (
--client).
Output is deterministic: same schema in, same bytes out. Generated files are declared in the consuming project's AGENTS.md/.gitignore as needed and are not forced into the golden-path build (tools/codegen/AGENTS.md).
| File | Purpose |
|---|---|
tools/codegen/src/cli.mjs |
CLI entrypoint and flag parsing |
tools/codegen/src/schemas.mjs |
Schema import, introspection (isZodSchema), type-name inference, mock walker |
tools/codegen/src/openapi.mjs |
buildOpenApiDocument via Zod 4 z.toJSONSchema (draft 2020-12) |
tools/codegen/src/mock.mjs |
Deterministic mock factories (renderMockModule, generateMock) using @faker-js/faker
|
tools/codegen/src/client.mjs |
Typed fetch-wrapper module (renderClientModule) |
tools/codegen/package.json |
@safrs/codegen; depends on zod + @faker-js/faker
|
buildOpenApiDocument(schemas, meta) iterates every exported Zod schema, converts it with z.toJSONSchema(...), and drops the non-OpenAPI $schema key. Each schema becomes a #/components/schemas/<name> component; refFor(name) produces $refs. paths start empty — the API package's own openapi.ts is the runtime counterpart that also defines the golden-path paths.
tools/codegen/src/schemas.mjs provides mockForSchema, a deterministic faker walker over the Zod _def shape (strings, numbers, booleans, dates, enums, literals, objects, arrays, optionals/nullables, unions, records — guarded at depth 6). renderMockModule emits a standalone mock.js that re-imports the live schemas and exports one factory per schema (mock<Name>(overrides)), so the generated file stays correct as schemas evolve.
renderClientModule emits client.ts that wraps createApiClient from @safrs/api/client with an AbortController timeout (default 10s), a single retry-on-network-error, and a normalized ApiResult<T> envelope — static request/response types still come from the Hono RPC client.
pnpm codegen --schema packages/schemas/src/index.ts --out codegen
pnpm codegen --openapi # openapi.json only
pnpm codegen --mock # mock.js only
pnpm codegen --client # client.ts only
pnpm codegen --title "My API" --version 1.0.0 --out build/codegen
pnpm codegen --helpDefault entry is packages/schemas/src/index.ts; without any artifact flag, all three artifacts are written. Exit code is non-zero if no Zod schemas are exported.
-
@safrs/schemasis the schema entry module — the tool imports it at runtime and never maintains a second copy. -
@safrs/api/clientis the import target of the generated typed client. -
packages/api/src/openapi.tsmirrors the samez.toJSONSchemaapproach for the served/api/openapi.json.
node --test tools/codegen/test/*.test.mjsTool, dependency, and generated-output changes are R2 and need review.
- Schemas — the source of truth for generation
- API — the typed client and runtime OpenAPI endpoint
- Tools overview
SAFRS — the Sentra Agent-First Repository Standard — defines how a software repository should be structured, governed, and enforced when autonomous Artificial Intelligence agents perform a substantial share of engineering work by Sentra Artificial Intelligence.
SAFRS v1.1 addresses that problem through five coupled mechanisms:
- a six-layer repository architecture from Trust Boundary to Human Authority;
- a role-based permission model in which capability never implies trust;
- a four-tier risk model with cumulative mandatory controls;
- a multi-agent execution protocol with explicit task states and one mutation owner per bounded scope;
- a knowledge governance model that distinguishes current architecture, historical decisions, execution plans, Git history, and running code.
Built in Indonesia as part of the Sentra Artificial Intelligence ecosystem.
Sentra Artificial Intelligence · Source Repository · Official Website
Dr Ferdi Iskandar — Creator & Maintainer
LinkedIn ·
ORCID ·
Hugging Face ·
Kaggle ·
Medium ·
Substack ·
X ·
Threads
MyPrompt · Sentra Artificial Intelligence · Indonesia
- SentraBot
- Kediri History
- Academic Smartboard
- Avery
- Portfolio Dr. Novia
- Golden Path (legacy demonstrator)
- Control Center
- Capsule template
- Risk model (R0–R3)
- Agent roles and permissions
- Capsule sovereignty
- Multi-agent protocol
- Document lifecycle
- Sensitive paths
- Verification integrity
Lore — how this repository grew
- Schemas (
@safrs/schemas) - Environment (
@safrs/env) - Database (
@safrs/database) - API (
@safrs/api) - UI (
@safrs/ui) - Telemetry (
@safrs/telemetry) - Token (
@sentra/token) - Config (
@safrs/config) - Auth (
packages/auth)
- SAFRS governance checkers
- SAFRS Automation Control Plane
- Gaffer Runtime
- Doctor
- Project wizard
- project-standalone
- Capabilities
- Codegen
- Deps-graph
- Status CLI
- Task CLI