Skip to content

Latest commit

 

History

History
100 lines (78 loc) · 5.75 KB

AGENTS.md

File metadata and controls

100 lines (78 loc) · 5.75 KB

Working with MetaObjects in this project

Stack: typescript server, react client.

Generated by MetaObjects (refresh: meta init --refresh-docs). Put project notes in your root AGENTS.md or CLAUDE.md, not here: this file is regenerated.

The metadata (metaobjects/ unless .metaobjects/config.json says otherwise) is the source of truth. Code, schema and migrations are generated from it and are regenerated output.

Start here: the whole loop, in order

TypeScript: generate with npx meta gen

  1. Config. In metaobjects.config.ts set dialect ("postgres" | "sqlite" | "mysql"; D1 is "sqlite") and list the generators. Nothing is generated until it is listed. The usual data layer:

    import { entityFile, namesFile, barrel } from "@metaobjectsdev/codegen-ts/generators";
    // generators: [entityFile(), namesFile(), barrel()]

    Per entity: <Entity>.ts (Drizzle table, row types, Zod schemas, enum types) and <Entity>.names.ts (physical names), plus an index.ts barrel. Install what they import: npm i drizzle-orm zod and your database driver. Every other generator (CRUD queriesFile() / routesFile(), docs, requirementTests()) is one line too; npx meta gen --list is the catalog. npx meta eject <name> copies one into codegen/generators/ to change it; npx meta generator new <name> writes a new one.

  2. Generate. npx meta gen. See a file's exports with grep -n "^export" <file>. When agentDocsFile() / apiDocsFile() are wired, read the agent/*.md or api/AGENT-API.md page for the tier you touch.

Web client: generated by the Node npx meta gen

The client tiers are generators in metaobjects.config.ts, whatever the backend: formFile() from @metaobjectsdev/codegen-ts-react, tanstackQuery() and tanstackGrid() from @metaobjectsdev/codegen-ts-tanstack, with the runtime packages @metaobjectsdev/react and @metaobjectsdev/tanstack. Wrap the app in <EntityFetcherProvider fetcher={...} baseUrl="/api">: baseUrl is where the server mounts its routes, and leaving it out drops that prefix from every hook without an error. The metaobjects-runtime-ui skill has the detail.

Requirements, when the metadata declares requirement.* nodes

A commit that changes behaviour updates them in the same commit: @status: live once a claim is built (never before), a new node for new behaviour.

Before you call it done

  • npx meta verify --codegen (the generated code and docs pages; the requirement gate runs on every meta verify).

Commit the metadata, the generated code and .metaobjects/.gen-state/.hashes/.

Calling the generated REST API

When the project serves the generated routes (any port):

  • Filter as ?filter[<field>][<op>]=<value>: ?filter[status][eq]=active, never ?status=active (TypeScript refuses that with 400; the other ports ignore it). Operators: eq, ne, isNull (true/false), in (comma list, at most 100), like (case-sensitive, % and _), gt, gte, lt, lte. Filters AND; only @filterable fields filter.
  • ?sort=<field>:asc|desc, ?limit=N&offset=N; withCount=1 returns {"rows", "total"}. Always send limit: without it the project's api.pagination.defaultLimit applies, or with none set C# returns every row, the other ports 50; above maxLimit is 400.
  • PUT is the same partial update as PATCH. Send only declared fields: an undeclared key is 400 unknown_fields (unless api.unknownFields is drop).
  • Errors are {"error": "<code>"}: 400 for validation (issues lists each problem) and for a bad filter or sort (invalid_filter_field, _op, _value, invalid_sort, each naming field), 404 not_found, 409 for a unique or foreign-key conflict.

Rules

  • What the metadata describes is generated, never hand-written (tables, types, validators, foreign keys, schema, migrations). Hand-write only what it cannot describe, on top.
  • Never hand-edit generated output: change the metadata and regenerate. Output wrong for you, or broken? Fix the generator: eject it and it is yours, no permission needed, nothing to wait on.
  • Never spell a table or column name as a string; use the generated table or names constants.
  • Wire a generator only for output you will import.
  • An LLM prompt in a project that declares template.prompt is a declared template (metaobjects-prompts); a grouped total or report view is an object.report (metaobjects-authoring). Open the skill before writing either by hand.
  • Never invent metadata vocabulary. Search it: npx meta types <term>, and npx meta types <type>.<subType> --detail for one construct's valid attributes. Vocabulary of your own says what a thing is and relates to, never a product, a version or a step.
  • Metadata nodes are fused-key maps, {"field.string": {"name": "email"}}. Attribute names are unique within a node, and package paths use ::.

Going deeper

The loop above needs no skill. For less common work load a metaobjects-* skill by name, or open .claude/skills/<skill>/SKILL.md if your assistant does not load skills: metaobjects-authoring (unusual shapes, your own vocabulary, reports, adopting existing code), metaobjects-codegen (owning or writing a generator), metaobjects-runtime-ui (REST routes, the web client), metaobjects-prompts (LLM prompts), metaobjects-verify (migration edge cases, drift, upgrades), metaobjects-audit (an adoption review). Each names the one reference page to open.

meta init --refresh-docs regenerates this file and the skills, so keep project guidance in the root AGENTS.md or CLAUDE.md (or copy a skill to a new name). A refresh never overwrites a file you edited; it writes <path>.new beside it, which you merge into <path> and delete. Never --force a refresh over local edits.