Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/rust/metaobjects-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ name = "cargo-meta"
path = "src/main.rs"

[dependencies]
metaobjects = { path = "../metaobjects" }
metaobjects-codegen = { path = "../metaobjects-codegen" }
metaobjects = { path = "../metaobjects", version = "0.1.0" }
metaobjects-codegen = { path = "../metaobjects-codegen", version = "0.1.0" }

[dev-dependencies]
serde_json.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion server/rust/metaobjects-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false
build = "build.rs"

[dependencies]
metaobjects = { path = "../metaobjects" }
metaobjects = { path = "../metaobjects", version = "0.1.0" }
serde_json.workspace = true
indexmap.workspace = true
serde.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions server/rust/metaobjects/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Embeds the repo-root `library/` tree (YAML files and `library.json` manifests)
//! into the crate, as the other ports do, so a shipped library resolves with no
//! file on disk. When the directory is absent (the crate built outside the
//! repository) the embed is empty.
//! Embeds the shipped libraries (YAML files and `library.json` manifests) into the
//! crate, as the other ports do, so a shipped library resolves with no file on disk.
//! They come from `data/library/`, a byte-identical copy of the repo-root `library/`
//! that `tests/vendored_data_parity.rs` holds to its source.

use std::fmt::Write as _;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -36,7 +36,7 @@ fn collect(
fn main() {
let manifest_dir =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
let lib_dir = manifest_dir.join("../../../library");
let lib_dir = manifest_dir.join("data/library");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed={}", lib_dir.display());
let (mut yaml, mut manifests) = (Vec::new(), Vec::new());
Expand Down
131 changes: 131 additions & 0 deletions server/rust/metaobjects/data/ERROR-CODES.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions server/rust/metaobjects/data/library/ai/db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# library/ai/db.yaml — the DB PERSISTENCE layer for metaobjects::ai.
#
# Opted into as `"ai/db"`, which IMPLIES `"ai"`: `LlmCall` is declared in model.yaml and
# this file only re-opens it, so without the core layer the overlay has no target.
#
# `LlmCall` is the concrete, table-backed instance of the abstract envelope. An adopter
# who wants their OWN table (a different name, extra columns, a different id strategy)
# extends `LlmCallBase` in their own metadata and never opts into this layer at all.
metadata:
package: metaobjects::ai
children:
- object.entity:
name: LlmCall
overlay: true
children:
- source.rdb: { table: llm_call, role: primary }
20 changes: 20 additions & 0 deletions server/rust/metaobjects/data/library/ai/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$comment": "Library manifest (FR-043 §4). Embedded beside the YAML in every port. Every fact here is RESOLVED by a test, never trusted: `packages` against the library loaded standalone, `layers[].refs` against the embedded set, `generators[].name` against the generator registry, `generators[].anchor` against the library's own nodes, and `name` against the last package segment.",
"name": "ai",
"kind": "feature",
"stability": "stable",
"since": "0.20.0",
"description": "The LLM-call trace envelope: what was asked, what came back, what it cost, how long it took.",
"useWhen": "the application calls a language model and someone will ask what it cost or why a call failed",
"packages": ["metaobjects::ai"],
"layers": {
"": { "refs": ["ai/model", "ai/requirements"], "description": "the core model and its requirements — sourceless, so it adds no tables" },
"db": { "refs": ["ai/db"], "description": "the concrete llm_call table" }
},
"generators": [
{ "name": "trace-helper", "anchor": "metaobjects::ai::LlmCallBase" }
],
"runtime": {
"typescript": ["@metaobjectsdev/runtime-ts"]
}
}
44 changes: 44 additions & 0 deletions server/rust/metaobjects/data/library/ai/model.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# library/ai/model.yaml — the CORE layer: the LLM-call trace envelope.
#
# Adopters opt in via `libraries: ["ai"]`, then `extends: "metaobjects::ai::LlmCallBase"`.
#
# This layer declares NO `source.rdb`, so opting into `"ai"` alone adds zero tables and
# zero generated code — the design is present and resolvable, and nothing else happens
# until the adopter adds `"ai/db"`. See library/iam/model.yaml for the full rationale.
#
# This file was split out of the former `library/ai/llm-call.yaml`, which shipped the
# abstract base and a concrete `LlmCall` carrying `source.rdb` together. That was
# recorded as an accepted wart on the grounds that splitting would change what existing
# `ai` adopters get; a sweep of the estate found there are none, so it was closed rather
# than documented (FR-043 Amendment 1).
metadata:
package: metaobjects::ai
children:
- object.entity:
name: LlmCallBase
abstract: true
children:
- field.uuid: { name: traceId }
- field.uuid: { name: spanId }
- field.uuid: { name: parentSpanId }
- field.string: { name: sessionId }
- field.string: { name: callType }
- field.string: { name: system }
- field.string: { name: requestModel }
- field.string: { name: responseModel }
- field.int: { name: inputTokens }
- field.int: { name: outputTokens }
- field.currency: { name: costMinor, currency: USD }
- field.int: { name: latencyMs }
- field.string: { name: finishReason }
- field.string: { name: status }
- field.string: { name: errorDetail }
- field.timestamp: { name: startedAt }
- field.string: { name: llmRequest, dbColumnType: jsonb } # generic jsonb (no objectRef)
- field.string: { name: llmResponse, dbColumnType: jsonb }
- object.entity:
name: LlmCall
extends: metaobjects::ai::LlmCallBase
description: The concrete trace row. Its `source.rdb` lives in db.yaml, so opting into the core layer alone declares the shape without proposing a table.
children:
- identity.primary: { name: id, fields: ["spanId"] }
112 changes: 112 additions & 0 deletions server/rust/metaobjects/data/library/ai/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# library/ai/requirements.yaml — what the LLM-call trace envelope PROMISES.
#
# A RETROFIT, not new design: llm-call.yaml landed 2026-06-03 and `requirement.functional`
# first appears 2026-08-11, so the library could not have carried requirements when it was
# written. That is why this file is worth reading as a worked example — it shows what
# declaring the design of something that already exists actually turns up.
#
# The entry that earns its keep is `typedIo`, honestly `partial` + `accepted`: the library
# declares the ENVELOPE and the adopter declares the typed VO columns. Recording that seam
# in the ledger is where an agent meets it, before adding a fourth trace column.
#
# HIERARCHY IS NESTING, and the L4/L5 split is grain. An L4 names the OBJECT it is about;
# the fields that carry it hang off it as an L5 child. Writing the fields at L4 is
# ERR_REQUIREMENT_L4_NOT_OBJECT, and writing the concerns as SIBLINGS of the L2 leaves the
# L2 claiming nothing — both of which this file did until the standalone verify gate
# existed (`cli/test/shipped-library-verify.test.ts`).
metadata:
package: metaobjects::ai
children:
- requirement.functional:
name: llmTracing
level: 2
status: live
statement: Every call to a language model leaves a row that says what was asked, what came back, what it cost and how long it took.
counterexample: A spend figure nobody can attribute to a call.
description: The segment this library covers. Its three children below are the concerns it decomposes into.
children:
- requirement.functional:
name: envelope
level: 4
status: live
statement: A trace row identifies its call and its place in a trace — trace, span, parent span, session, call type, system.
counterexample: A log line that cannot be joined to the request that produced it.
implementedBy: [LlmCallBase]
children:
- requirement.functional:
name: traceAddressing
level: 5
status: live
statement: The four addressing columns are declared on the base — trace, span, parent span and session.
counterexample: A row whose place in a trace is inferred from insertion order.
description: >-
The member grain exists here so the claim RESOLVES against the fields
themselves: renaming or dropping one of them dangles this reference and
fails the build, which naming the object alone would not.
implementedBy: [LlmCallBase.traceId, LlmCallBase.spanId, LlmCallBase.parentSpanId, LlmCallBase.sessionId]

- requirement.functional:
name: accounting
level: 4
status: live
statement: A trace row carries the tokens in, the tokens out, and the cost in integer minor units.
counterexample: A cost stored as a float.
description: >-
`field.currency` — integer minor units on the wire, always. Float arithmetic for
money is forbidden by the cross-port wire contract, and a spend total is exactly
the sum that exposes it.
implementedBy: [LlmCallBase]
children:
- requirement.functional:
name: tokenAndCostColumns
level: 5
status: live
statement: Tokens in, tokens out and cost are three declared columns, the cost a field.currency.
counterexample: A cost column declared as a double.
implementedBy: [LlmCallBase.inputTokens, LlmCallBase.outputTokens, LlmCallBase.costMinor]

- requirement.functional:
name: typedIo
level: 4
status: partial
disposition: accepted
statement: The request and response bodies are stored as structured jsonb, not as opaque text.
counterexample: A prompt stored as a string nobody can query a field out of.
notes: >-
The library declares the two columns as generic jsonb with no `@objectRef`,
because it cannot know the adopter's request/response shape. Typing them is the
ADOPTER's move: declare an `object.value` and overlay the field with
`@objectRef` + `@storage: jsonb`. This is the seam ADR-0024 drew, recorded here
rather than in prose so it is in the ledger an agent reads before adding a
fourth trace column of its own.
implementedBy: [LlmCallBase]
children:
- requirement.functional:
name: jsonbBodies
level: 5
status: live
statement: The request and response bodies are declared as jsonb columns on the base.
counterexample: A prompt stored in a text column.
description: >-
`live` where its parent is `partial`, and the split is the point: the
COLUMNS are shipped and this claim is fully realised; what is outstanding
is the TYPING of them, which is the parent's gap and the adopter's move.
implementedBy: [LlmCallBase.llmRequest, LlmCallBase.llmResponse]

- requirement.architectural:
name: traceRowsCarryTiming
status: live
statement: Every trace row records when the call started and how long it took.
counterexample: A latency figure derived from log timestamps after the fact.
description: >-
Architectural, so it propagates down `extends` to every adopter entity deriving
from LlmCallBase — which is the point: an adopter's own trace table is claimed
by this requirement for free, and dropping the columns breaks the build.
implementedBy: [LlmCallBase]

- requirement.architectural:
name: traceRowsCarryOutcome
status: live
statement: Every trace row records how the call ended — a status, a finish reason, and the error detail when there was one.
counterexample: A failed call indistinguishable from one that never happened.
implementedBy: [LlmCallBase]
81 changes: 81 additions & 0 deletions server/rust/metaobjects/data/library/iam/db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# library/iam/db.yaml — the DB PERSISTENCE layer for metaobjects::iam.
#
# Opted into as `"iam/db"`, which IMPLIES `"iam"`: this file is nothing but
# `overlay: true` redeclarations, and an overlay whose target was never declared is
# ERR_OVERLAY_NO_TARGET.
#
# It carries exactly two kinds of child — `source.rdb` and `index.lookup` — and nothing
# else. The field set, the identities and the relationships all live in model.yaml,
# because they are the DESIGN; what lives here is where the rows go and which lookups are
# worth an index. Add a field here and the core layer stops being the whole model, which
# is the thing the split exists to guarantee.
#
# Physical names are `iam_`-prefixed. Two reasons, both real: `user` and `group` are
# reserved words in Postgres, and an adopter very likely has tables of their own by those
# names. A library that collides on a table name is a library nobody can adopt.
metadata:
package: metaobjects::iam
children:
- object.entity:
name: User
overlay: true
children:
- source.rdb: { table: iam_user, role: primary }

- object.entity:
name: GroupType
overlay: true
children:
- source.rdb: { table: iam_group_type, role: primary }

- object.entity:
name: Group
overlay: true
children:
- source.rdb: { table: iam_group, role: primary }
# Nesting is walked parent-ward constantly; the FK alone gives no index.
- index.lookup: { name: ixParent, fields: [parentId] }

- object.entity:
name: Role
overlay: true
children:
- source.rdb: { table: iam_role, role: primary }

- object.entity:
name: Permission
overlay: true
children:
- source.rdb: { table: iam_permission, role: primary }

- object.entity:
name: GroupMember
overlay: true
children:
- source.rdb: { table: iam_group_member, role: primary }
# The composite PK covers (userId, groupId), so "who is in this group?" —
# the other direction — has no index without this one. Same reasoning for
# every ixSecond below.
- index.lookup: { name: ixGroup, fields: [groupId] }

- object.entity:
name: RolePermission
overlay: true
children:
- source.rdb: { table: iam_role_permission, role: primary }
- index.lookup: { name: ixPermission, fields: [permissionId] }

- object.entity:
name: UserRole
overlay: true
children:
- source.rdb: { table: iam_user_role, role: primary }
- index.lookup: { name: ixRole, fields: [roleId] }

- object.entity:
name: GroupMemberRole
overlay: true
children:
- source.rdb: { table: iam_group_member_role, role: primary }
# "who holds this role in this group?" — the scoped-grant read.
- index.lookup: { name: ixGroupRole, fields: [groupId, roleId] }
16 changes: 16 additions & 0 deletions server/rust/metaobjects/data/library/iam/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$comment": "Library manifest (FR-043 §4). Embedded beside the YAML in every port. Every fact here is RESOLVED by a test, never trusted: `packages` against the library loaded standalone, `layers[].refs` against the embedded set, `generators[].name` against the generator registry, `generators[].anchor` against the library's own nodes, and `name` against the last package segment.",
"name": "iam",
"kind": "feature",
"stability": "preview",
"since": "1.1.0",
"description": "Users, nestable typed groups, roles as permission bundles, grants global or scoped to a group.",
"useWhen": "the application has people who log in and things some of them may not do",
"packages": ["metaobjects::iam"],
"layers": {
"": { "refs": ["iam/model", "iam/requirements"], "description": "the core model and its requirements — sourceless, so it adds no tables" },
"db": { "refs": ["iam/db"], "description": "nine tables, iam_-prefixed, plus the lookup indexes the composite keys do not cover" }
},
"generators": [],
"runtime": {}
}
Loading
Loading