Skip to content
Draft
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
24 changes: 24 additions & 0 deletions .changeset/39102-app-skill-text-cap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/spec': minor
'@objectstack/cli': minor
'@objectstack/metadata-protocol': minor
'@object-ui/i18n': minor
---

feat!: an app's skills on the ask surface are capped at 8,000 characters, and os validate, the build and the metadata save door refuse an app over it; Studio's Skills page shows each app's total

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: registered app-skill-text-over-cap-refused -->

**BREAKING** accept-set narrowing at `os validate`, `os build` and the metadata save door (`@objectstack/cli`, `@objectstack/metadata-protocol`), for an app (package) whose skills with `surface` `ask` or `both` (or unset) add up to more than 8,000 characters: FROM the app building and its skill saves being stored TO `os validate` / `os build` failing it, and a skill save that raises its total refused `422 INVALID_METADATA`, each naming the total and the cap. The one-line fix: trim the app's ask skill text to 8,000 characters or fewer (shorten `description` / `instructions`, drop unneeded `tools`, or set `surface: 'build'` on a skill the ask agent does not need). No key is removed and no stored skill is rewritten.

The hosted `ask` agent puts every skill an app (package) binds on the `ask` surface into its system prompt and caps that text per app. The cap and its one measure are now declared in the spec, and every door counts with them:

- `@objectstack/spec/ai` exports `PACKAGE_SKILL_TEXT_CAP` (8,000), `composeSkillSection` (the section the runtime composes for one skill: `### {label} ({name})`, `description`, `instructions`, `Tools: …`), `packageSkillTextLength`, `packageSkillTextTotal`, `countsTowardPackageSkillText` (a skill with `surface` `ask`, `both` or unset counts; `build` never does), `formatPackageSkillTextCount` and `packageSkillTextCapMessage`.
- `os validate` and `os build` fail an app whose total is over the cap, naming the app, its total and the cap (`8,520 / 8,000`); `--json` carries one `errors[]` row per app (`packageId`, `total`, `cap`, `message`), and `os build` writes no artifact.
- The metadata save door (Studio, `PUT /api/v1/meta/skill/:name`, an MCP draft save) refuses a `skill` save after which the app it lands in is over the cap and higher than before, `422 INVALID_METADATA`, naming the app's total and the cap. A save that lowers an over-cap app is accepted, so an app can be trimmed one skill at a time.
- Studio → AI → Skills shows each app's total against the cap, in red when over.

**What an author changes.** An app that built and saved before and is over the cap now fails `os validate` / `os build`, and a save that adds skill text to it is refused. Shorten the skills' `description` or `instructions`, drop tools a skill does not need, or set `surface: 'build'` on a skill the `ask` agent does not need, until the total is within 8,000.
26 changes: 26 additions & 0 deletions content/docs/ai/agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,32 @@ does not exist is an authoring error in either distribution. So a skill written
against the open framework keeps its full meaning when the app runs on
ObjectOS; nothing is authored twice.

### An app's `ask` skills share an 8,000-character cap

On ObjectOS the `ask` agent puts every skill an app binds on the `ask`
surface into its system prompt, so the text one app (package) adds there is
capped at **8,000 characters** (`PACKAGE_SKILL_TEXT_CAP`,
`@objectstack/spec/ai`). One skill counts as the section the runtime composes
for it — its heading `### {label} ({name})`, its `description`, its
`instructions` and its `Tools: …` line — and the app's total sums every skill
whose `surface` is `'ask'` or `'both'`, or unset (the default is `'ask'`).
A `'build'` skill counts nothing.

The cap is held at every door, with one measure (`packageSkillTextTotal`):

- `os validate` and `os build` fail an app over it, naming the app, its total
and the cap (`8,520 / 8,000`).
- Saving a skill — in Studio, through the REST metadata API or as an MCP
draft — that would put its app over the cap is refused `422
INVALID_METADATA` with the same numbers. A save that brings an over-cap app
down is accepted, so an app can be trimmed one skill at a time.
- Studio → AI → Skills shows each app's total against the cap, in red when
over.

To get back under it, shorten the skills' `description` or `instructions`,
drop tools a skill does not need, or set `surface: 'build'` on a skill the
`ask` agent does not need.

## The shape of an agent

An agent is typed metadata validated by `AgentSchema` — exported, together with the
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import { findViewContainerNameRefusals } from '../utils/view-container-names.js'
// [ADR-0150 D2, child N] The package door's namespace name refusal — the same
// call `os validate` makes at its step 2c-bis.
import { findNamespaceNameRefusals } from '../utils/namespace-co-owner-names.js';
// cloud ADR-0118 D5: the app skill text cap — the walk; the measure is the spec's.
import { findAppSkillTextCapRefusals } from '../utils/app-skill-text-cap.js';
// [ADR-0150 D6, child K] A namespace never equals an object name, both directions,
// and no object is short-named `custom` — the spec's predicate over one artifact.
import { findNamespaceObjectNameRefusals } from '../utils/namespace-object-names.js';
Expand Down Expand Up @@ -588,6 +590,25 @@ export default class Compile extends Command {
this.exit(1);
}

// 2c-bis'. [cloud ADR-0118 D5] An app whose skills on the `ask` surface
// add up to more than the cap the hosted `ask` runtime holds them
// to. The cap, the measure and the sentence are the spec's, the ones
// the metadata save door refuses the same app with.
const skillTextCapRefusals = findAppSkillTextCapRefusals(result.data as Record<string, unknown>);
if (skillTextCapRefusals.length > 0) {
if (flags.json) {
await emitJson({ success: false, errors: skillTextCapRefusals, warnings: warningsSoFar(), conversions: conversionNotices }, 0, { compact: true });
this.exit(1);
}
console.log('');
printError(`App skill text over the cap (${skillTextCapRefusals.length} app${skillTextCapRefusals.length > 1 ? 's' : ''})`);
printBulletList(
skillTextCapRefusals.map((r) => r.message),
{ noun: 'skill text cap refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
);
this.exit(1);
}

// 3a-quater. [ADR-0150 D6, child K] A namespace of this artifact equal
// to one of its object names, or an object short-named `custom`, is
// REFUSED, naming both spellings — the SAME call `os validate` makes
Expand Down
27 changes: 27 additions & 0 deletions packages/cli/src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ import { findViewContainerNameRefusals } from '../utils/view-container-names.js'
// bucket 2/3 types has one package holder: the package door's predicate and
// sentence, walked over the artifact's packages in boot order.
import { findNamespaceNameRefusals } from '../utils/namespace-co-owner-names.js';
// cloud ADR-0118 D5: the app skill text cap — the walk; the measure is the spec's.
import { findAppSkillTextCapRefusals } from '../utils/app-skill-text-cap.js';
// [ADR-0150 D6, child K] A namespace never equals an object name, both directions,
// and no object is short-named `custom` — the spec's predicate over one artifact.
import { findNamespaceObjectNameRefusals } from '../utils/namespace-object-names.js';
Expand Down Expand Up @@ -597,6 +599,31 @@ export default class Validate extends Command {
this.exit(1);
}

// 2c-bis'. [cloud ADR-0118 D5] An app whose skills on the `ask` surface
// add up to more than the cap the hosted `ask` runtime holds them
// to. The cap, the measure and the sentence are the spec's, the ones
// the metadata save door refuses the same app with.
const skillTextCapRefusals = findAppSkillTextCapRefusals(result.data as Record<string, unknown>);
if (skillTextCapRefusals.length > 0) {
if (flags.json) {
await emitJson({
valid: false,
errors: skillTextCapRefusals,
warnings: warningsSoFar(),
conversions: conversionNotices,
duration: timer.elapsed(),
});
this.exit(1);
}
console.log('');
printError(`App skill text over the cap (${skillTextCapRefusals.length} app${skillTextCapRefusals.length > 1 ? 's' : ''})`);
printBulletList(
skillTextCapRefusals.map((r) => r.message),
{ noun: 'skill text cap refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
);
this.exit(1);
}

// 2c-ter. [ADR-0150 D6, child K] A namespace of this artifact equal to
// one of its object names (either direction), or an object
// short-named `custom` (`NS_custom`, the ADR-0146 pair's namespace),
Expand Down
49 changes: 49 additions & 0 deletions packages/cli/src/utils/app-skill-text-cap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { describe, expect, it } from 'vitest';
import { PACKAGE_SKILL_TEXT_CAP, packageSkillTextCapMessage, packageSkillTextLength } from '@objectstack/spec/ai';
import { findAppSkillTextCapRefusals } from './app-skill-text-cap.js';

/** A skill whose composed section is `size` characters long. */
function skillOf(name: string, size: number, surface?: 'ask' | 'build' | 'both') {
const base = { name, label: 'S', tools: [] as string[], ...(surface ? { surface } : {}) };
const head = packageSkillTextLength({ ...base, surface: 'ask' });
return { ...base, instructions: 'x'.repeat(size - head - 1) };
}

describe('findAppSkillTextCapRefusals (cloud ADR-0118 D5)', () => {
it('the fixture measures what it says', () => {
expect(packageSkillTextLength(skillOf('a', 5000))).toBe(5000);
});

it('refuses a one-app stack over the cap, naming the app, its total and the cap', () => {
const rows = findAppSkillTextCapRefusals({
manifest: { id: 'com.acme.crm' },
skills: [skillOf('a', 5000), skillOf('b', 3520, 'both')],
});
expect(rows).toEqual([{
packageId: 'com.acme.crm',
total: 8520,
cap: PACKAGE_SKILL_TEXT_CAP,
message: packageSkillTextCapMessage('com.acme.crm', 8520),
}]);
});

it('accepts exactly the cap, and never counts a build skill', () => {
expect(findAppSkillTextCapRefusals({ manifest: { id: 'p' }, skills: [skillOf('a', 8000)] })).toEqual([]);
expect(findAppSkillTextCapRefusals({
manifest: { id: 'p' },
skills: [skillOf('a', 5000), skillOf('b', 5000, 'build')],
})).toEqual([]);
});

it('judges each package of an artifact as its own app', () => {
const rows = findAppSkillTextCapRefusals({
packages: [
{ manifest: { id: 'com.acme.one', skills: [skillOf('a', 5000)] } },
{ manifest: { id: 'com.acme.two', skills: [skillOf('b', 5000), skillOf('c', 5000)] } },
],
});
expect(rows.map((r) => [r.packageId, r.total])).toEqual([['com.acme.two', 10000]]);
});
});
76 changes: 76 additions & 0 deletions packages/cli/src/utils/app-skill-text-cap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* `os validate`'s and `os build`'s half of the app skill text cap (cloud
* ADR-0118 D5): an app (package) whose skills on the `ask` surface add up to
* more than `PACKAGE_SKILL_TEXT_CAP` characters fails the command, and the
* message names the app, its total and the cap.
*
* ## One measure, not a second rule
*
* The cap, the measure of one skill and the sentence are `@objectstack/spec`'s
* (`PACKAGE_SKILL_TEXT_CAP`, `packageSkillTextTotal`,
* `packageSkillTextCapMessage`) — the same exports the metadata save door and
* Studio's Skills page read, and the measure the hosted `ask` runtime counts.
* What this module owns is the WALK: which skills belong to which app.
*
* ## The walk
*
* An artifact's `packages[]` bodies are one app each, under the id the
* registry installs them by (`artifactPackages`). The stack's own top-level
* `skills` are the stack's app, under its `manifest.id`. A stack with no
* `packages[]` is that one app.
*/

import {
PACKAGE_SKILL_TEXT_CAP,
packageSkillTextCapMessage,
packageSkillTextTotal,
type PackageSkillTextSource,
} from '@objectstack/spec/ai';
import { artifactPackages } from './artifact-packages.js';

/** One app over the cap, located. */
export interface AppSkillTextCapRefusalRow {
/** The app's package id, as the registry installs it. */
packageId: string;
/** The app's total, in characters (`packageSkillTextTotal`). */
total: number;
/** The cap (`PACKAGE_SKILL_TEXT_CAP`). */
cap: number;
/** The refusal, in the shared sentence. */
message: string;
}

const skillsOf = (body: Record<string, unknown>): PackageSkillTextSource[] =>
Array.isArray(body.skills) ? (body.skills as PackageSkillTextSource[]) : [];

const stackAppId = (parsed: Record<string, unknown>): string => {
const manifest = parsed.manifest as { id?: unknown; name?: unknown } | undefined;
if (typeof manifest?.id === 'string' && manifest.id !== '') return manifest.id;
if (typeof manifest?.name === 'string' && manifest.name !== '') return manifest.name;
return 'this stack';
};

/**
* Every app of this stack whose `ask` skill text exceeds the cap. `[]` for a
* stack every app of which is within it.
*/
export function findAppSkillTextCapRefusals(parsed: Record<string, unknown>): AppSkillTextCapRefusalRow[] {
const apps: Array<{ packageId: string; skills: PackageSkillTextSource[] }> = [
{ packageId: stackAppId(parsed), skills: skillsOf(parsed) },
...artifactPackages(parsed).map(({ id, body }) => ({ packageId: id, skills: skillsOf(body) })),
];
const rows: AppSkillTextCapRefusalRow[] = [];
for (const { packageId, skills } of apps) {
const total = packageSkillTextTotal(skills);
if (total <= PACKAGE_SKILL_TEXT_CAP) continue;
rows.push({
packageId,
total,
cap: PACKAGE_SKILL_TEXT_CAP,
message: packageSkillTextCapMessage(packageId, total),
});
}
return rows;
}
113 changes: 113 additions & 0 deletions packages/cli/test/validate-app-skill-text-cap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* [cloud ADR-0118 D5] `os validate` and `os build` refuse an app whose skills
* on the `ask` surface add up to more than `PACKAGE_SKILL_TEXT_CAP`, and the
* row names the app's total and the cap; `os build` writes nothing. A stack
* at the cap validates.
*/

import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { execFile } from 'node:child_process';
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { PACKAGE_SKILL_TEXT_CAP, packageSkillTextLength } from '@objectstack/spec/ai';
import { childEnv } from './helpers/serve-process.js';
import { defineStackSource, linkSpec } from './helpers/define-stack-fixture.js';

const HERE = resolve(fileURLToPath(import.meta.url), '..');
const CLI = resolve(HERE, '../bin/run-dev.js');
/** A cold spawn of the CLI source entry runs well past vitest's 5 s default. */
const SPAWN_TIMEOUT_MS = 120_000;
const ARTIFACT = join('dist', 'objectstack.json');
const APP = 'com.example.skill-cap';

interface Run { code: number; stdout: string; stderr: string }

function runCli(args: string[], cwd: string): Promise<Run> {
return new Promise((done) => {
execFile(process.execPath, [CLI, ...args], { cwd, maxBuffer: 16 * 1024 * 1024, env: childEnv({ NO_COLOR: '1' }) },
(err, stdout, stderr) => done({
code: err ? (typeof (err as { code?: unknown }).code === 'number' ? (err as unknown as { code: number }).code : 1) : 0,
stdout: String(stdout),
stderr: String(stderr),
}));
});
}

function payloadOf(run: Run, label: string): Record<string, any> {
try {
return JSON.parse(run.stdout) as Record<string, any>;
} catch {
throw new Error(`${label}: stdout was not one JSON document (exit ${run.code})\n${run.stdout}\n${run.stderr}`);
}
}

/** A skill whose composed section is `size` characters long. */
function skillOf(name: string, size: number) {
const base = { name, label: 'Skill', tools: [] as string[] };
return { ...base, instructions: 'x'.repeat(size - packageSkillTextLength(base) - 1) };
}

const stackOf = (sizes: number[]) => ({
manifest: { id: APP, name: 'skill_cap', version: '1.0.0', type: 'app' },
skills: sizes.map((size, i) => skillOf(`cap_skill_${i}`, size)),
});

const dirs: Record<string, string> = {};
let root = '';

beforeAll(() => {
root = mkdtempSync(join(tmpdir(), 'os-validate-skill-text-cap-'));
const make = (label: string, s: Record<string, unknown>) => {
const dir = join(root, label);
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, 'objectstack.config.ts'), defineStackSource(s));
linkSpec(dir);
dirs[label] = dir;
};
make('over-validate', stackOf([5000, 3520]));
make('over-build', stackOf([5000, 3520]));
make('at-cap', stackOf([5000, 3000]));
});

afterAll(() => {
if (root) rmSync(root, { recursive: true, force: true });
});

describe('app skill text cap — os validate and os build', () => {
it('os validate --json exits 1 with one row naming the app, its total and the cap', async () => {
const run = await runCli(['validate', '--json'], dirs['over-validate']);
const payload = payloadOf(run, 'validate --json');
expect(run.code).toBe(1);
expect(payload.valid).toBe(false);
expect(payload.errors.map((r: any) => [r.packageId, r.total, r.cap]))
.toEqual([[APP, 8520, PACKAGE_SKILL_TEXT_CAP]]);
expect(payload.errors[0].message).toContain('(8,520 / 8,000)');
}, SPAWN_TIMEOUT_MS);

it('os validate (text) names the total and the cap', async () => {
const run = await runCli(['validate'], dirs['over-validate']);
expect(run.code).toBe(1);
expect(`${run.stdout}${run.stderr}`).toContain('binds 8,520 characters of skill text on the ask surface; the cap is 8,000');
}, SPAWN_TIMEOUT_MS);

it('os build --json exits 1 with the same row and writes no artifact', async () => {
const dir = dirs['over-build'];
const run = await runCli(['build', '--json'], dir);
const payload = payloadOf(run, 'build --json');
expect(run.code).toBe(1);
expect(payload.success).toBe(false);
expect(payload.errors.map((r: any) => [r.packageId, r.total])).toEqual([[APP, 8520]]);
expect(existsSync(join(dir, ARTIFACT)), 'os build wrote an artifact over the cap').toBe(false);
}, SPAWN_TIMEOUT_MS);

it('CONTROL — an app exactly at the cap validates', async () => {
const run = await runCli(['validate', '--json'], dirs['at-cap']);
const payload = payloadOf(run, 'at-cap --json');
expect(payload.valid, JSON.stringify(payload.errors)).toBe(true);
expect(run.code).toBe(0);
}, SPAWN_TIMEOUT_MS);
});
Loading
Loading