Skip to content
Open
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
9 changes: 9 additions & 0 deletions .changeset/record-context-two-mounts-prose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@objectstack/spec': patch
'@objectstack/service-record-context': patch
---

Clause-②: no
Metadata-protocol: none

Documentation text only. The `aiContexts` description on the stack, the `@objectstack/service-record-context` README and the `RecordContextServicePlugin` docblock now name both ways a host mounts the record-context service that serves `get_record_context`: the stack declares `requires: ['record-context']`, which the CLI expands to the plugin, or a host that composes its own kernel lists `RecordContextServicePlugin` in `plugins`. Before, the stack description read the token as the only serving condition, and the README and docblock taught only the `plugins` mount. No schema, key or runtime behaviour changes.
4 changes: 2 additions & 2 deletions content/docs/ai/skills-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ Use when the request is "when X happens, do Y" or you are editing `*.flow.ts`. N

Design ObjectStack AI skills, tools, knowledge sources, and the open-edition MCP server surface.

Use when the user is adding `*.skill.ts` / `*.tool.ts`, configuring an LLM provider, wiring the tools a skill grants, or indexing ObjectStack data as a knowledge source for RAG. Agents themselves are platform-internal (`ask` / `build`) — third parties extend them via skills, not by authoring `*.agent.ts`.
Use when the user is adding `*.skill.ts` / `*.tool.ts`, configuring an LLM provider, wiring the tools a skill grants, indexing ObjectStack data as a knowledge source for RAG, or writing a context pack (`aiContexts`). Agents themselves are platform-internal (`ask` / `build`) — third parties extend them via skills, not by authoring `*.agent.ts`.

Do not use for general LLM prompting questions unrelated to ObjectStack metadata.

**Tags:** `agent`, `tool`, `skill`, `knowledge`, `llm`, `embedding`, `mcp`
**Tags:** `agent`, `tool`, `skill`, `knowledge`, `context-pack`, `llm`, `embedding`, `mcp`

---

Expand Down
4 changes: 2 additions & 2 deletions content/docs/references/api/package-api-assembled.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Installed package row whose manifest is the assembled package body
| **agents** | `{ name: string; label: string; avatar?: string; role: string; … }[]` | optional | AI Agents — platform-internal (ADR-0063 §2): the kernel ships exactly two (ask/build); third parties extend via skills, not agents |
| **tools** | `{ name: string; label: string; description: string; parameters: Record<string, any>; … }[]` | optional | AI Tool metadata records — optional refinement layer, never required: the default path is skills referencing platform tools or materialised action_`<name>` tools (ADR-0109) |
| **skills** | `{ name: string; label: string; description?: string; surface?: Enum<'ask' \| 'build' \| 'both'>; … }[]` | optional | AI Skills (reusable capability bundles — the third-party AI extension primitive, ADR-0063) |
| **aiContexts** | `{ name: string; label: string; object: string; fields?: string[]; … }[]` | optional | AI context packs — the material of one record handed to a model, read as the caller by get_record_context (ADR-0160), which is served where `requires` includes `record-context` |
| **aiContexts** | `{ name: string; label: string; object: string; fields?: string[]; … }[]` | optional | AI context packs — the material of one record handed to a model, read as the caller by get_record_context (ADR-0160). A host serves that tool only when it mounts the record-context service: the CLI mounts it where `requires` includes `record-context`, and a host that composes its own kernel lists `RecordContextServicePlugin` in `plugins` |
| **hooks** | `{ name: string; label?: string; object: string \| string[]; events: Enum<'beforeFind' \| 'afterFind' \| 'beforeInsert' \| 'afterInsert' \| 'beforeUpdate' \| …>[]; … }[]` | optional | Object Lifecycle Hooks, as a JSON document carries them |
| **mappings** | `{ name: string; label?: string; sourceFormat?: Enum<'csv' \| 'json' \| 'xml' \| 'sql'>; targetObject: string; … }[]` | optional | Data Import/Export Mappings |
| **analyticsCubes** | `{ name: string; title?: string; description?: string; sql: string; … }[]` | optional | Analytics Semantic Layer Cubes |
Expand Down Expand Up @@ -388,7 +388,7 @@ This schema accepts one of the following structures:
| **agents** | `{ name: string; label: string; avatar?: string; role: string; … }[]` | optional | AI Agents — platform-internal (ADR-0063 §2): the kernel ships exactly two (ask/build); third parties extend via skills, not agents |
| **tools** | `{ name: string; label: string; description: string; parameters: Record<string, any>; … }[]` | optional | AI Tool metadata records — optional refinement layer, never required: the default path is skills referencing platform tools or materialised action_`<name>` tools (ADR-0109) |
| **skills** | `{ name: string; label: string; description?: string; surface?: Enum<'ask' \| 'build' \| 'both'>; … }[]` | optional | AI Skills (reusable capability bundles — the third-party AI extension primitive, ADR-0063) |
| **aiContexts** | `{ name: string; label: string; object: string; fields?: string[]; … }[]` | optional | AI context packs — the material of one record handed to a model, read as the caller by get_record_context (ADR-0160), which is served where `requires` includes `record-context` |
| **aiContexts** | `{ name: string; label: string; object: string; fields?: string[]; … }[]` | optional | AI context packs — the material of one record handed to a model, read as the caller by get_record_context (ADR-0160). A host serves that tool only when it mounts the record-context service: the CLI mounts it where `requires` includes `record-context`, and a host that composes its own kernel lists `RecordContextServicePlugin` in `plugins` |
| **hooks** | `{ name: string; label?: string; object: string \| string[]; events: Enum<'beforeFind' \| 'afterFind' \| 'beforeInsert' \| 'afterInsert' \| 'beforeUpdate' \| …>[]; … }[]` | optional | Object Lifecycle Hooks, as a JSON document carries them |
| **mappings** | `{ name: string; label?: string; sourceFormat?: Enum<'csv' \| 'json' \| 'xml' \| 'sql'>; targetObject: string; … }[]` | optional | Data Import/Export Mappings |
| **analyticsCubes** | `{ name: string; title?: string; description?: string; sql: string; … }[]` | optional | Analytics Semantic Layer Cubes |
Expand Down
18 changes: 13 additions & 5 deletions packages/services/service-record-context/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ field, a list or a row the caller cannot read is never carried, and the answer
says when something was withheld or cut.

```ts
import { RecordContextServicePlugin } from '@objectstack/service-record-context';

export default defineStack({
requires: ['record-context'],
aiContexts: [{
name: 'policy_document',
label: 'Policy document',
Expand All @@ -21,12 +20,21 @@ export default defineStack({
related: [{ object: 'policy_revision', fields: ['version', 'published_at'] }],
body: { field: 'content' },
}],
plugins: [new RecordContextServicePlugin()],
});
```

A host that mounts the plugin serves `get_record_context` on its MCP doors
(`data:read`, read-only). A host without it serves no such tool.
Two doors mount the service, and either is enough:

- `requires: ['record-context']` on the stack. The CLI expands the token to
`RecordContextServicePlugin` (`CAPABILITY_PROVIDERS` in `@objectstack/core`),
so an app that ships only metadata gets the tool with no host code.
- `plugins: [new RecordContextServicePlugin()]`, for a host that composes its
own kernel. A host that lists the plugin keeps its own instance when the
token is declared too.

A host that mounts the service serves `get_record_context` on its MCP doors
(`data:read`, read-only). A host that does neither serves no such tool,
whatever packs it holds.

The answer is `{ data, notes, framing }`: `data` is the record material,
`notes` are the executor's statements about it, and `framing` says that `data`
Expand Down
18 changes: 16 additions & 2 deletions packages/services/service-record-context/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,25 @@ export interface RecordContextService {
* A host that mounts it serves `get_record_context` on its MCP doors (both
* resolve the service by structure, as they resolve the dataset and knowledge
* executors); a host without it registers no `get_record_context`, and
* nothing else changes (ADR-0160 D5). Composition is explicit: mount it in
* `plugins[]`.
* nothing else changes (ADR-0160 D5). Composition is explicit, by either of
* two doors: a stack declares `requires: ['record-context']`, which the CLI
* expands to this plugin (`CAPABILITY_PROVIDERS` in `@objectstack/core`), or a
* host that composes its own kernel mounts it in `plugins[]` and keeps that
* instance when the token is declared too.
*
* @example
* ```ts
* // An app that ships only metadata: the token mounts the plugin.
* export default defineStack({
* // …
* requires: ['record-context'],
* aiContexts: [policyDocumentPack],
* });
* ```
*
* @example
* ```ts
* // A host that composes its own kernel.
* import { RecordContextServicePlugin } from '@objectstack/service-record-context';
*
* export default defineStack({
Expand Down
8 changes: 6 additions & 2 deletions packages/spec/src/stack.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,13 @@ const STACK_DEFINITION_COLLECTIONS_SHAPE = {
/**
* [ADR-0160 D1] Context packs: which of one record's fields, related lists
* and body text are handed to a model, read as the caller by
* `get_record_context` (`@objectstack/service-record-context`).
* `get_record_context` (`@objectstack/service-record-context`). The tool
* exists on a host that mounts that service, by either door: the CLI mounts
* it where `requires` includes `record-context`, and a host that composes
* its own kernel lists `RecordContextServicePlugin` in `plugins`. A host
* that does neither serves no such tool, whatever packs it holds.
*/
aiContexts: z.array(AiContextSchema).optional().describe('AI context packs — the material of one record handed to a model, read as the caller by get_record_context (ADR-0160), which is served where `requires` includes `record-context`'),
aiContexts: z.array(AiContextSchema).optional().describe('AI context packs — the material of one record handed to a model, read as the caller by get_record_context (ADR-0160). A host serves that tool only when it mounts the record-context service: the CLI mounts it where `requires` includes `record-context`, and a host that composes its own kernel lists `RecordContextServicePlugin` in `plugins`'),

/**
* ObjectQL: Data Extensions
Expand Down
10 changes: 10 additions & 0 deletions scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,16 @@ export const CEILINGS = new Map([
['skills/objectstack-platform/references/operations.md', 3394],
['skills/objectstack-platform/references/plugin-development.md', 3137],
['skills/objectstack-upgrade/references/examples-upgrade.md', 1197],
// NEW FILE, pinned AT the measurement: the context pack (`ai_context`, ADR-0160)
// is a metadata kind no published skill taught beyond its key name. Card #37177
// (the `Skills-docs: follow-up` of the PR that admitted the kind) asks for the
// teaching "in references where the ceiling binds", and both SKILL.md rows were
// at 14 and 0 tokens of headroom, so the keys, bounds, body outline, pack names
// and `os validate` rules live here and each SKILL.md carries a pointer paid by
// deleting restatement in the same file (neither SKILL.md row moves). The row is
// the seat's claim amendment 7179788843 on that card: one new row for this file.
// 5813 bytes -> ceil(5813 / 4) = 1454; zero headroom.
['skills/objectstack-ai/references/context-packs.md', 1454],

// ── 2026-10-26 the objectui bundle joins the catalog — decision C, #25832 ──
// The maintainer ruled (decision C, 2026-10-25, recorded as item 17d of the
Expand Down
30 changes: 16 additions & 14 deletions skills/objectstack-ai/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ name: objectstack-ai
description: >
Design ObjectStack AI skills, tools, knowledge sources, and the open-edition
MCP server surface. Use when the user is adding `*.skill.ts` / `*.tool.ts`,
configuring an LLM provider, wiring the tools a skill grants, or indexing
ObjectStack data as a knowledge source for RAG. Agents themselves are
configuring an LLM provider, wiring the tools a skill grants, indexing
ObjectStack data as a knowledge source for RAG, or writing a context pack
(`aiContexts`). Agents themselves are
platform-internal (`ask` / `build`) — third parties extend them via skills,
not by authoring `*.agent.ts`. Do not use for general LLM prompting questions
unrelated to ObjectStack metadata.
Expand All @@ -14,7 +15,7 @@ metadata:
author: objectstack-ai
version: "18.6.0"
domain: ai
tags: agent, tool, skill, knowledge, llm, embedding, mcp
tags: agent, tool, skill, knowledge, context-pack, llm, embedding, mcp
---

# AI Agent Design — ObjectStack AI Protocol
Expand All @@ -28,14 +29,6 @@ metadata:
> expose the app to your own AI over **MCP** (below), and author metadata in
> **source mode** with an AI coding agent (Claude Code, Cursor).

```
Agent → Skill → Tool
│ │ │
│ │ └─ Atomic operation (query, action, flow, API call)
│ └─ Capability bundle with instructions & trigger conditions
└─ Autonomous actor with role, instructions, and guardrails
```

---

## Skill Configuration
Expand Down Expand Up @@ -137,7 +130,7 @@ still run under the caller's own permissions.

## Actions as AI Tools — the default path ☁️

You usually **don't author tool definitions by hand** for action invocation. An
An
`Action` attached to an object via `defineObject({ actions: [...] })` becomes a
tool named `action_<actionName>` **only when it opts in** — `ai.exposed: true`
(default `false`) plus an `ai.description` of ≥ 40 chars, refused by the parse
Expand Down Expand Up @@ -234,6 +227,7 @@ permissions and row-level security:
|:--|:--|
| `list_objects`, `describe_object` | schema introspection (system objects filtered out by default) |
| `query_records`, `get_record` | reads — filter, field selection, sorting, pagination |
| `get_record_context` | one record through its context pack (**Context packs** below) |
| `aggregate_records` | GROUP BY totals; registered only when the data bridge implements `aggregate` |
| `validate_expression` | build-accurate CEL check before a formula is authored into metadata |
| `create_record`, `update_record`, `delete_record` | writes; `delete_record` is refused with `ACTION_CONFIRMATION_REQUIRED` (428) unless it sends `confirm: true`. A request in which the human names the record to delete, with exactly one record matching, is their approval: send `confirm: true` on that call without asking again. When the name matches more than one record, or the request does not identify one, list the candidates, ask which one, and send `confirm: true` only after the answer |
Expand All @@ -250,6 +244,15 @@ these tools, a client advertising form-mode `elicitation` is asked instead:

---

## Context packs — one record's material

A context pack (`aiContexts`, `*.ai-context.ts`) lists the fields, related
lists and body of one record that `get_record_context` hands a model, read as
the caller; `requires: ['record-context']` serves the tool. Keys, bounds, pack
names, `os validate` rules: [references/context-packs.md](./references/context-packs.md).

---

## Knowledge Sources (RAG)

The RAG primitive is the **KnowledgeSource** (`KnowledgeSourceSchema` in
Expand Down Expand Up @@ -289,7 +292,7 @@ import { KnowledgeSourceSchema, type KnowledgeSource } from '@objectstack/spec/a
export const supportKb: KnowledgeSource = KnowledgeSourceSchema.parse({
id: 'support_kb',
label: 'Support Knowledge Base',
adapter: 'ragflow', // or 'memory' for dev/test
adapter: 'ragflow',
source: {
kind: 'object',
object: 'kb_article',
Expand Down Expand Up @@ -467,7 +470,6 @@ author-time gate before reporting done:

```bash
os validate # Zod schema + CEL predicate validation + bindings (no artifact)
# or: os build # the same gates, plus emits dist/
```

This domain has no CEL site — a model-registry `promptTemplate.system` / `.user` is
Expand Down
10 changes: 10 additions & 0 deletions skills/objectstack-ai/evals/skills-tools-knowledge.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
"must_contain": ["ask_ai", "record_header", "locations"],
"must_not_contain": ["target:"]
}
},
{
"id": 11,
"prompt": "Give the AI a customer's open opportunities and notes when a user asks about that customer. Customers are `account` records with a long-text `notes` field; an `opportunity` has an `account` lookup and a `stage` whose closed values are `closed_won` and `closed_lost`. Write the metadata.",
"expected_output": "Emits a context pack (an `aiContexts` entry or a `*.ai-context.ts` file) with `name`, `label`, `object: 'account'`, a `related` entry on `opportunity` (`field: 'account'`, a few `fields`) whose `where` keeps the open rows on the child's own `stage` field with an admitted operator (`{ stage: { $nin: ['closed_won', 'closed_lost'] } }`), optionally `orderBy: [{ field, order }]` and a `limit` of at most 20, and `body: { field: 'notes' }`. Declares `requires: ['record-context']` (or mounts `RecordContextServicePlugin`) so `get_record_context` is served, and says the pack reads as the caller and grants nothing. No `description` or top-level `filter` key on the pack, no `direction` in `orderBy`, and no `aiReadable` on the object.",
"files": [],
"assertions": {
"must_contain": ["opportunity", "related", "where", "stage", "body", "notes", "record-context"],
"must_not_contain": ["filter:", "direction:", "aiReadable"]
}
}
]
}
Loading
Loading