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
26 changes: 26 additions & 0 deletions .changeset/38929-step19-notice-relevance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@objectstack/spec': patch
'@objectstack/cli': patch
---

fix(spec,cli): `os migrate meta --from 18` proves the protocol-19 notices a stack has no surface for absent, and says why when it cannot

Clause-②: yes (widening)
Metadata-protocol: none

Widened: `MigrationChainResult` (`@objectstack/spec/migrations`) gains the optional member `unanswered` — `{ todos, unread }`, the entries whose relevance question the chain could not answer and what it could not read (`plugins`, `devPlugins`, `tiers`, a key whose value is not a list or a map, an unreadable manifest or package body). It moves nothing off any list; it only says why. `os migrate meta --json` emits it, under the same name, when a question stayed open; otherwise the payload is unchanged.

Most protocol-19 semantic entries whose surface is metadata authored under top-level stack keys now carry a `relevantWhen` question naming each key it can be written under, nested sites included (an action an object carries inline counts under `objects`). On a stack that declares none of them, the chain proves the entry absent, and `os migrate meta` counts it rather than listing it (`--all` lists it). The rule: a surface that a stored copy of the same metadata also meets still takes a question, since the proof covers the stack the command loads and never what a deployment stores. An entry stays listed to every stack when its surface is host code, a deployment's own state and doors (installed packages, rows written at run time), or something every stack carries, or when its own check runs over the rows a deployment stores — the protocol-19 permission-set field vote and the move of forms out of views among them. No prose is matched.

The question now also reads the stack's own `manifest`, as it reads a package body: a seed dataset declared under `manifest.data` keeps the seed notices listed.

`os migrate meta` prints the count of notices proven absent even when it is zero, whenever the run crossed an entry that asks, and says why a question stayed open. A stack that lists a plugin (`plugins:`, `devPlugins:`) or a `tiers` preset proves nothing absent, because a plugin can register metadata at boot that the stack does not show. The 18.x blank template lists three connector plugins, so an app scaffolded from it keeps every notice listed, and the report now says so:

```
0 more manual change(s) not listed: no surface they ask about was proven absent from this stack.
N of the manual change(s) listed above ask whether this stack declares their surface, and this run could not prove it absent: it cannot read `plugins`.
```

The proof covers the definitions the stack declares. Two sources of metadata are outside it, and the line that scopes the count names both: what a deployment stores (Studio, the metadata API), and what the app's `onEnable` hook registers through the engine it is handed at start. `onEnable` is not treated as a carrier: it is described for action handlers and drivers, and registering metadata there is off-label.

An app that lists no plugins, such as one scaffolded from the current blank template, sees the protocol-19 notices about agents, knowledge sources and the other surfaces it does not author, among those that carry a question, leave the default list.
179 changes: 179 additions & 0 deletions packages/cli/src/commands/migrate/meta.relevance-count.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* `os migrate meta` — group ④ counts the notices proven absent, zero
* included, and says why a question it could not answer left its notice on
* the list (`utils/migrate-meta-relevance.ts`).
*
* The input is the scaffold's own blank template, loaded the way the command
* loads it (`loadConfig(…, { authoredSource: true })`, then the map → array
* pass only) and replayed through the command's own chain
* (`applyMetaMigrationsToPackages`). That template lists no `plugins:`, so
* the chain proves `agents` and `knowledgeSources` absent from it and their
* two protocol-19 notices leave ③. The same stack with a plugin listed — the
* shape the 18.6.0 template had, three connector plugins — proves nothing
* absent, and ④ prints the zero count and the reason instead.
*/

import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { stripVTControlCharacters } from 'node:util';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { ObjectStackDefinitionSchema, normalizeStackInput } from '@objectstack/spec';
import { MIGRATION_MAJORS, type MigrationChainResult } from '@objectstack/spec/migrations';
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
import { loadConfig } from '../../utils/config.js';
import { applyMetaMigrationsToPackages, printMigrationReport, type MigrationReport } from './meta.js';
import { NONE_PROVEN_ABSENT_LINE } from '../../utils/migrate-meta-relevance.js';
// The packages the command reaches through dynamic imports, loaded at module top so the
// first load is paid during collection, never inside a clocked case (`check:test-source-alias`).
import '@objectstack/cloud-connection';
import '@objectstack/driver-sql';
import '@objectstack/driver-turso';
import '@objectstack/metadata';
import '@objectstack/metadata-protocol';
import '@objectstack/platform-objects/plugin';
import '@objectstack/plugin-hono-server';
import '@objectstack/plugin-security';
import '@objectstack/rest';
import '@objectstack/service-automation';
import '@objectstack/service-datasource';
import '@objectstack/service-settings';
import '@objectstack/service-storage';

const HERE = dirname(fileURLToPath(import.meta.url));
const BLANK_CONFIG = resolve(HERE, '../../../../create-objectstack/src/templates/blank/objectstack.config.ts');

/** Where the chain ends by default — derived, so the file survives the next major. */
const TERMINUS = Math.max(PROTOCOL_MAJOR, ...MIGRATION_MAJORS);

const AGENT_ENTRY = '19:agent-model-provider-retired';
const KNOWLEDGE_ENTRY = '19:knowledge-source-publish-refuses-missing-references-and-gated-objects';

/** ④'s count line when some notices were proven absent — the line `meta.report-order.test.ts` pins. */
const ABSENT_COUNT_RE = /^ {2}(\d+) more manual change\(s\) not listed: their surfaces are absent from this stack /;
const UNANSWERED_RE = /^ {4}(\d+) of the manual change\(s\) listed above ask whether this stack declares their surface, and this run could not prove it absent: it cannot read (.+)\.$/;
const PLUGIN_REASON_RE = /^ {4}A plugin, or a platform plugin a `tiers` preset loads, can register metadata at boot /;

class ConnectorLikePlugin {
name = 'com.example.connector';
}

let printed: string[] = [];

beforeEach(() => {
printed = [];
vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
printed.push(args.map(String).join(' '));
});
});

afterEach(() => {
vi.restoreAllMocks();
});

/** The blank template's stack as the command reads it: authored source, map → array only. */
async function blankStack(): Promise<Record<string, unknown>> {
const { config } = await loadConfig(BLANK_CONFIG, { authoredSource: true });
return normalizeStackInput(config as Record<string, unknown>, { convert: false });
}

/** Replay `--from 18` the way the command does and print the human report; `amend` edits the result. */
function report(
stack: Record<string, unknown>,
amend: (r: MigrationChainResult) => MigrationChainResult = (r) => r,
): { result: MigrationChainResult; lines: string[] } {
const result = amend(applyMetaMigrationsToPackages(stack, 18, TERMINUS));
const parsed = ObjectStackDefinitionSchema.safeParse(result.stack);
const migrationReport: MigrationReport = {
result,
normalized: stack,
schemaValid: parsed.success,
refusals: parsed.success ? [] : parsed.error.issues,
dataMigrations: [],
step: false,
all: false,
elapsed: '1ms',
};
vi.mocked(console.log).mockClear();
printed = [];
printMigrationReport(migrationReport);
return { result, lines: stripVTControlCharacters(printed.join('\n')).split('\n') };
}

const ids = (todos: MigrationChainResult['todos']) => todos.map((t) => `${t.toMajor}:${t.id}`);

describe('the blank template proves agents and knowledge sources absent (ACCEPTANCE)', () => {
it('lists no `plugins:`, so both notices leave ③ and ④ counts them', async () => {
const stack = await blankStack();
expect(stack.plugins).toBeUndefined();
const { result, lines } = report(stack);
expect(ids(result.absentTodos)).toEqual(expect.arrayContaining([AGENT_ENTRY, KNOWLEDGE_ENTRY]));
expect(result.unanswered).toBeUndefined();

const count = lines.find((l) => ABSENT_COUNT_RE.test(l));
expect(count, 'the count line').toBeDefined();
expect(Number(ABSENT_COUNT_RE.exec(count!)![1])).toBe(result.absentTodos.length);
expect(lines.filter((l) => UNANSWERED_RE.test(l))).toEqual([]);
// The scope line names both sources the proof does not read.
const scope = lines.filter((l) => l.startsWith(' Absent is proven over the stack this run loaded; '));
expect(scope).toHaveLength(1);
expect(scope[0]).toContain('metadata a deployment stores');
expect(scope[0]).toContain('`onEnable`');
for (const t of result.absentTodos.filter((u) => [AGENT_ENTRY, KNOWLEDGE_ENTRY].includes(`${u.toMajor}:${u.id}`))) {
expect(lines, `${t.id} is counted, not listed`).not.toContain(` ⚠ [protocol ${t.toMajor}] ${t.surface} → ${t.replacement}`);
}
});

it('a template that declares an agent keeps its notice listed (control)', async () => {
const stack = { ...(await blankStack()), agents: [{ name: 'helper', label: 'Helper' }] };
const { result } = report(stack);
expect(ids(result.absentTodos)).not.toContain(AGENT_ENTRY);
expect(ids(result.absentTodos)).toContain(KNOWLEDGE_ENTRY);
});
});

describe('④ prints the zero count, and why a question stayed open (PRINTER)', () => {
it('the template with a plugin listed proves nothing absent: zero, the count of open questions, and why', async () => {
const stack = { ...(await blankStack()), plugins: [new ConnectorLikePlugin(), new ConnectorLikePlugin()] };
const { result, lines } = report(stack);
expect(result.absentTodos).toEqual([]);
expect(ids(result.unanswered!.todos)).toEqual(expect.arrayContaining([AGENT_ENTRY, KNOWLEDGE_ENTRY]));

expect(lines.filter((l) => l === NONE_PROVEN_ABSENT_LINE)).toHaveLength(1);
const open = lines.filter((l) => UNANSWERED_RE.test(l));
expect(open).toHaveLength(1);
const [, n, unread] = UNANSWERED_RE.exec(open[0]!)!;
expect(Number(n)).toBe(result.unanswered!.todos.length);
expect(unread).toBe('`plugins`');
expect(lines.filter((l) => PLUGIN_REASON_RE.test(l))).toHaveLength(1);
// Both notices are still listed in ③.
for (const t of result.todos.filter((u) => [AGENT_ENTRY, KNOWLEDGE_ENTRY].includes(`${u.toMajor}:${u.id}`))) {
expect(lines).toContain(` ⚠ [protocol ${t.toMajor}] ${t.surface} → ${t.replacement}`);
}
// The order: ③'s header, then the zero count, then the reason.
const semantic = lines.findIndex((l) => /^ {2}\d+ manual change\(s\) require your judgment:$/.test(l));
const zero = lines.indexOf(NONE_PROVEN_ABSENT_LINE);
expect(semantic).toBeGreaterThan(-1);
expect(zero).toBeGreaterThan(semantic);
expect(lines.findIndex((l) => UNANSWERED_RE.test(l))).toBe(zero + 1);
});

it('an unreadable key is named, with no plugin sentence', async () => {
const stack = { ...(await blankStack()), agents: 'helper' };
const { lines } = report(stack);
const open = lines.filter((l) => UNANSWERED_RE.test(l));
expect(open).toHaveLength(1);
expect(UNANSWERED_RE.exec(open[0]!)![2]).toBe('`agents`');
expect(lines.filter((l) => PLUGIN_REASON_RE.test(l))).toEqual([]);
});

it('prints no zero count when no crossed entry asks a question', async () => {
const { lines } = report(await blankStack(), (r) => ({
...r,
todos: r.todos.map(({ relevantWhen: _question, ...rest }) => rest),
absentTodos: [],
}));
expect(lines.filter((l) => l === NONE_PROVEN_ABSENT_LINE)).toEqual([]);
});
});
5 changes: 4 additions & 1 deletion packages/cli/src/commands/migrate/meta.report-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
} from '@objectstack/spec/migrations';
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
import { printMigrationReport, type MigrationReport } from './meta.js';
import { NONE_PROVEN_ABSENT_LINE } from '../../utils/migrate-meta-relevance.js';
// The packages the command reaches through dynamic imports, loaded at module top so the
// first load is paid during collection, never inside a clocked case (`check:test-source-alias`).
import '@objectstack/cloud-connection';
Expand Down Expand Up @@ -613,9 +614,11 @@ describe('the notices proven absent leave ③ for one counting line, and --all l
for (const t of result.absentTodos) expect(t.relevantWhen, `${t.id} carries relevantWhen`).toBeDefined();
});

it('prints no ④ at all when the chain proved nothing absent', () => {
it('prints only the zero count as ④ when the chain proved nothing absent', () => {
const { lines } = run(FINDINGS_STACK, MIGRATION_SUPPORT_FLOOR, TERMINUS, (r) => ({ ...r, absentTodos: [] }));
expect(lines.filter((l) => ABSENT_COUNT_RE.test(l) || ABSENT_SCOPE_RE.test(l) || ABSENT_HEADER_RE.test(l))).toEqual([]);
// The count is printed at zero too (`meta.relevance-count.test.ts` pins its conditions).
expect(lines.filter((l) => l === NONE_PROVEN_ABSENT_LINE)).toHaveLength(1);
});

it('a run whose only notices are proven absent still counts them and still writes --out', () => {
Expand Down
16 changes: 14 additions & 2 deletions packages/cli/src/commands/migrate/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PROTOCOL_MAJOR, PROTOCOL_VERSION } from '@objectstack/spec/kernel';
import { FILE_REFERENCE_TYPES, REFERENCE_VALUE_TYPES, STRUCTURED_JSON_TYPES } from '@objectstack/spec/data';
import { FILE_REFERENCES_MIGRATION_ID, VALUE_SHAPES_MIGRATION_ID } from '@objectstack/spec/system';
import { loadConfig } from '../../utils/config.js';
import { printNoneProvenAbsent, printUnansweredRelevance } from '../../utils/migrate-meta-relevance.js';
import { authoringRuleUnionStack } from '../../utils/stack-collections.js';
import {
printHeader,
Expand Down Expand Up @@ -1183,7 +1184,12 @@ function absentKeysText(t: MigrationTodo): string {
*/
function printAbsentNotices(result: MigrationChainResult, all: boolean): void {
const count = result.absentTodos.length;
if (count === 0) return;
// Zero is a count too: printed whenever a crossed entry asks, with
// why a question stayed open (`utils/migrate-meta-relevance.ts`).
if (count === 0) {
printNoneProvenAbsent(result);
return;
}
if (!all) {
console.log(
chalk.dim(
Expand All @@ -1194,9 +1200,10 @@ function printAbsentNotices(result: MigrationChainResult, all: boolean): void {
console.log(
chalk.dim(
' Absent is proven over the stack this run loaded; metadata a deployment stores '
+ '(Studio, the metadata API) is not read here.',
+ '(Studio, the metadata API), and what an `onEnable` hook registers at start, is not read here.',
),
);
printUnansweredRelevance(result);
console.log('');
return;
}
Expand All @@ -1205,6 +1212,7 @@ function printAbsentNotices(result: MigrationChainResult, all: boolean): void {
printNotice(t);
console.log(chalk.dim(` absent: nothing is declared under ${absentKeysText(t)}`));
}
printUnansweredRelevance(result);
console.log('');
}

Expand Down Expand Up @@ -1595,6 +1603,10 @@ export default class MigrateMeta extends Command {
// subset the chain proved irrelevant to this stack (ADR-0087 D3),
// so a machine consumer reads the default list as the difference.
absentTodos: result.absentTodos,
// Only when a relevance question stayed open: those entries (all
// still in `todos`) and what the chain could not read, as the
// human report's why line prints them.
...(result.unanswered ? { unanswered: result.unanswered } : {}),
// Only when the run crosses into protocol 19 and the form move
// left a site: without one the payload is what it always was.
...(formSites.length > 0 ? { formMoveSites: formSites } : {}),
Expand Down
74 changes: 74 additions & 0 deletions packages/cli/src/utils/migrate-meta-relevance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* `os migrate meta` — the two lines group ④ adds beside its count of the
* notices proven absent (ADR-0087 D3; the count itself is printed by
* `printAbsentNotices` in `commands/migrate/meta.ts`).
*
* - The count is printed even when it is zero, whenever the run crossed an
* entry that carries a relevance question: an author reading a full list
* can tell "nothing was proven absent" from "nothing was asked".
* - The entries whose question the chain could not answer
* (`MigrationChainResult.unanswered`) are counted, with what it could not
* read: a stack that lists a plugin proves nothing absent, and says so
* instead of handing every notice over without a reason.
*
* Both lines only explain. Neither moves a notice off ③'s list, and neither
* reads prose: the count comes from `absentTodos`, the explanation from
* `unanswered`, both the chain's.
*/

import chalk from 'chalk';
import type { MigrationChainResult } from '@objectstack/spec/migrations';

/**
* The `unread` paths that are carriers of metadata the stack does not show —
* `MigrationChainResult.unanswered` documents them — and whose presence the
* second explanatory line is about.
*/
const PLUGIN_CARRIERS: ReadonlySet<string> = new Set(['plugins', 'devPlugins', 'tiers']);

/** The line counting the notices proven absent when there are none, printed only if a question was asked. */
export const NONE_PROVEN_ABSENT_LINE =
' 0 more manual change(s) not listed: no surface they ask about was proven absent from this stack.';

/**
* Says why the questions the chain could not answer left their notices on
* the list above: how many, and what the evaluation could not read. Prints
* nothing when every question was answered.
*/
export function printUnansweredRelevance(result: MigrationChainResult): void {
const open = result.unanswered;
if (!open || open.todos.length === 0) return;
// The chain names at least one path for every open question; should it name
// none, the line says so rather than printing an empty list.
const unread = open.unread.length > 0
? open.unread.map((path) => `\`${path}\``).join(', ')
: 'a value it was not told about';
console.log(
chalk.dim(
` ${open.todos.length} of the manual change(s) listed above ask whether this stack declares their `
+ `surface, and this run could not prove it absent: it cannot read ${unread}.`,
),
);
if (open.unread.some((path) => PLUGIN_CARRIERS.has(path))) {
console.log(
chalk.dim(
' A plugin, or a platform plugin a `tiers` preset loads, can register metadata at boot that the '
+ 'stack does not show, so no surface is proven absent while one is listed.',
),
);
}
}

/**
* Group ④ when the chain proved nothing absent: the zero count, when the run
* crossed an entry that carries a relevance question, then why the questions
* it could not answer stayed open. Prints nothing when no entry crossed asks.
*/
export function printNoneProvenAbsent(result: MigrationChainResult): void {
if (!result.todos.some((t) => t.relevantWhen)) return;
console.log(chalk.dim(NONE_PROVEN_ABSENT_LINE));
printUnansweredRelevance(result);
console.log('');
}
Loading
Loading