Facet
EnglishInstallieren
Mit KI-Agenten arbeiten

Schema-Entscheidungen für den Agenten festhalten

Verknüpfe Anforderung und Entscheidung hinter einer Tabelle mit ihrer Migration, damit dein Coding-Agent sie kennt, bevor er das Schema ändert.

  • 5 Min. Lesezeit
  • 7 Schritte
  • Claude CodeCodexMCP-ServerMCP ist der übliche Weg, über den KI-Assistenten externe Werkzeuge aufrufen. FACET startet mit facet mcp einen MCP-Server aus deinem Projekt, über den ein Assistent Records und den verankerten Code nachschlagen kann.Im Glossar
  • Dein Coding-Agent

Das Problem: Dein Agent räumt die Rechnungstabelle auf und ersetzt fünf kopierte Adressspalten durch eine billing_address_id. Die Kopie war aber gewollt: Eine ausgestellte Rechnung darf sich nicht ändern. Jetzt zeigt jede alte Rechnung die neue Adresse des Kunden.

Wie FACET hilft: Ein FACET-RecordEin FACET-Record ist eine kurze, prüfbare Beschreibung eines Features, abgelegt als YAML-Datei neben dem Code. Er hält fest, warum es das Feature gibt, welches Verhalten es als Szenarien zusagt und welche Tests das prüfen.Im Glossar hält die Anforderung fest und verweist auf die Entscheidung. Ein AnkerEin Anker ist ein Kommentar im Quellcode, beginnend mit @facet:, der den Record nennt, zu dem der Code gehört. Aus diesen Kommentaren weiß FACET, wo jedes Feature umgesetzt ist.Im Glossar verbindet ihn mit der Migration. Das Agent-Plugin zeigt dem Agenten die Anforderung, sobald er die Datei öffnet, und hält ihn zur Prüfung an, wenn er den Code trotzdem ändert.

Beispiel: der Shop aus den FACET-Beispielen, so wie ihn Eine Antwort statt drei hinterlässt:

sh
  • git clone --depth 1 --branch guide/write-down-what-a-feature-does https://github.com/facet-framework/examples.git
  • cp -r examples/shop shop && cd shop
  • git init && git add -A && git commit -m "Example shop"
  • npm install

Der Branch guide/schema-decisions-your-agent-keeps enthält das Ergebnis.

Schritt 1Die Anforderung aufschreiben und die Entscheidung verknüpfen

Speichere als docs/facets/features/billing/invoicing/issue-invoice.yaml:

yaml
schema_version: "0.1"id: billing/invoicing/issue-invoicelifecycle: activeintent:  summary: An order is billed with an invoice that keeps the billing address it was issued to, because an issued invoice may not change.  decision_records:    - docs/adr/0004-invoice-address-snapshot.mdcontract:  scenarios:    - id: address-stays-as-issued      statement: |        Given an invoice issued to Old Street 1        When the customer changes the billing address to New Street 2        Then the invoice still shows Old Street 1    - id: new-invoice-uses-current-address      statement: |        Given a customer who changed the billing address to New Street 2        When the next invoice is issued        Then that invoice shows New Street 2verification:  unit_tests:    - id: tests/invoice.test.ts      proves: [address-stays-as-issued, new-invoice-uses-current-address]lineage:  owner:    team: billing  created_at: "2026-11-23"  related_data_entities:    - data/billing/invoice
  • intent.summary: das Versprechen, die erste Zeile, die der Agent sieht.
  • contract.scenarios: die Anforderung als prüfbares Verhalten.
  • intent.decision_records: der Verweis auf das ADR, das die Kopie begründet.

Schritt 2Die Tabelle als Datenobjekt beschreiben

Optional. Speichere als docs/facets/data-entities/billing/invoice.yaml:

yaml
schema_version: "0.1"id: data/billing/invoicecanonical_schema:  fields:    - { name: customer_id, type: uuid, references: data/customers/customer }    - { name: billing_street, type: string, constraints: [copied-at-issue, immutable] }    - { name: billing_city, type: string, constraints: [copied-at-issue, immutable] }retention:  policy: Retain for 10 years after issue, unchanged  duration: P10Yownership: { team: billing }read_by:  - billing/invoicing/issue-invoicemutated_by:  - billing/invoicing/issue-invoice

Der Feature-Record verweist über lineage.related_data_entities hierher.

Schritt 3Den Record in Migration und Code verankern

Oben in db/migrations/0007_invoices.sql:

sql
-- @facet: billing/invoicing/issue-invoice-- @facet-role: primaryCREATE TABLE invoices (  id                  UUID PRIMARY KEY,  customer_id         UUID NOT NULL REFERENCES customers(id),  billing_name        TEXT NOT NULL,  billing_street      TEXT NOT NULL,  billing_postal_code TEXT NOT NULL,  billing_city        TEXT NOT NULL,  billing_country     CHAR(2) NOT NULL  -- …);

Dieselben zwei Zeilen kommen über issueInvoice in src/billing/invoice.ts. Dann:

sh
  • npx facet lint
text
3 record(s), 3 anchor(s) checked — 0 error(s), 1 warning(s) (unclaimed-tests 1)

Schritt 4Die Records mit dem Schema committen

sh
  • git add docs db/migrations src/billing/invoice.ts
  • git commit -m "Record why invoices copy the billing address"

DriftDrift heißt: Der Code ändert sich, der Record, der ihn beschreibt, aber nicht, sodass beide nicht mehr zusammenpassen. facet drift listet die Features, deren verankerter Code sich seit einem gewählten Stand geändert hat.Im Glossar vergleicht mit dem letzten Commit. Committe deshalb, bevor du dem Agenten die Tabelle überlässt.

Schritt 5Sehen, was der Agent beim Öffnen der Migration bekommt

Bitte den Agenten, die Tabelle zu normalisieren. Liest er die Migration, ergänzt das Plugin:

text
FACET claims for db/migrations/0007_invoices.sql, before editing:billing/invoicing/issue-invoice  promises: An order is billed with an invoice that keeps the billing address it was issued to, because an issued invoice may not change.  contract: address-stays-as-issued, new-invoice-uses-current-address

Den ganzen Record samt ADR-Pfad liest er mit einem read_facet-Aufruf.

Schritt 6Ändert der Agent es trotzdem, muss er den Record prüfen

Ändert der Agent issueInvoice trotzdem, hält das Plugin ihn vor dem Abschluss an:

text
FACET: source implementing these features changed, but their records did not:- billing/invoicing/issue-invoice — changed: src/billing/invoice.ts

Er muss die Änderung zurücknehmen oder den Record anpassen und begründen. Dasselbe zeigt dir npx facet drift.

Schritt 7Jede Migration verankern, die die Tabelle ändert

Drift sieht nur verankerte Dateien. Eine neue Migration ohne Anker ergibt No drift found. Verankere deshalb jede:

sql
-- @facet: billing/invoicing/issue-invoice-- @facet-role: relatedALTER TABLE invoices ADD COLUMN billing_address_id UUID REFERENCES customer_addresses(id);

Quellen