Skip to content

Commit 1c53783

Browse files
feat(cli,create-objectstack): os build says when the dev database holds Studio customizations it leaves behind; the starter docs name os package export (#30336)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgKdSU8f1JN5b9XUG5XoGicJ)_ domain:server#4 · os-bill · session_01Utp6CZMkHvuDeVYgTD73qF Refs #30119 (server half). The Studio notice "where a customization is saved" is the ui half and stays open on the card. Clause-②: yes (widening) — the exported CompileCommand gains a protected reportsLocalCustomizations flag (default false); nothing removed or narrowed Metadata-protocol: none ## 维护者速读 - 改了什么:`os build` 结束时,若本地开发库里有 Studio 定制(`包名.custom` 的条目),打印一次提示:几条、在哪个包、库文件在哪,用 `os package export` 带走;脚手架的 AGENTS.md 和 README 写明 Studio 改动存在数据库里、不进 `src/`,并说明代理该改 `src/`。 - 为什么改:开发者在 `os dev` 里用 Studio 调好视图,再 `os build` + Dockerfile 部署,改动丢了且无任何提示(卡上实测,本 PR 在当前 main 复测成立)。 - 风险与回滚:只读本地 SQLite、只多打印几行,不改构建产物、不改 `--json` 输出、不新增服务端接口;回滚即 revert 本 PR。 - 先看:`packages/cli/src/utils/local-customizations.ts`(读库与提示文字),`packages/cli/src/commands/compile.ts`(只在 build 上打开的那段),`packages/create-objectstack/src/templates/AGENTS.md`。 - 两分钟验证:在 examples/app-todo 跑 `os dev`,给 `todo_task.default` 存一个 `.custom` 覆盖,再跑 `os build`,结尾应看到「This build does not carry 1 Studio customization…`os package export`」。 - 需要你做的:无,席位落地。 ## What changes **`os build` says what the artifact leaves behind.** After the artifact is written, the text face reads the SQLite file `os dev` opens for the project and counts the `sys_metadata` rows whose `package_id` ends in `.custom` (ADR-0146 D2: a Studio change to a shipped item is an item of `BASE.custom`). When there are any, it prints one warning and two dim lines: the count per pair, the database file, and the remedy (make the change in `src/`, or `os package export` while `os dev` runs). - **Which database:** the one shared resolution `resolveProjectDatabaseUrl` (`@objectstack/runtime`), over this process's environment layered on the project's development `.env*` files the way `os dev` loads them (dotenv-flow, process wins), without loading them into the build's process. - **Cheap and local:** opened read-only (`better-sqlite3`, the CLI's optional dependency, as `sqlite-occupancy.ts` already does), one aggregate `SELECT`. No server door, no network round trip. A database that is not a local SQLite file (Postgres, MongoDB, libSQL, `:memory:`) is not probed and prints nothing. - **Never a verdict it did not reach:** a file that cannot be read, or a missing `better-sqlite3`, prints "Could not check FILE … (reason)" plus the remedy, never silence-as-empty. A database with no `sys_metadata` table yet, or no `.custom` row, prints nothing. The probe never fails the build. - **Only on `os build`:** `Compile` gains a protected `reportsLocalCustomizations = false`, and `Build` sets it `true`. `os dev` compiles through `os compile` on every boot and rebuild, so the notice never prints there. `os build --json` is unchanged: no new key. **The starter's docs.** The generated `AGENTS.md` gains "Change the app in `src/` — a Studio change stays in its database", and the blank README's "Deploy" section gains "A Studio change is not in the image". Both say: - Studio saves into that environment's database, as an item of `PACKAGE_ID.custom`, never into `src/`, so `build` and the `Dockerfile` leave it behind. - App changes are made in `src/`, never through Studio or the metadata API of a running server. A change a person tried in Studio is made again in `src/` when it belongs to the app. No write-back is built, as the card asked. - A customization that should stay one moves as a package: `os login` and then `os package export` against the dev server, commit `objectstack-export/`, then `os package install … --runtime URL` on the deployment, in the numbered order. ## Tests - `packages/cli/src/utils/local-customizations.test.ts` (unit tier): the `.env` layering (process wins, nothing loaded), which URLs name a local file, `not_applicable` for a remote, unbooted or refused database, the notice text for found / unknown / none, and that `Build` turns the notice on while `Compile` keeps it off. - `packages/cli/src/utils/local-customizations.sqlite.test.ts` (integration tier, because it imports `better-sqlite3` to write its fixture): counts per `.custom` package and nothing else (a non-pair package, a package-less row, `com.custom.tools` and `com.example.customs` are not counted), `none` for no pair rows or no table, the file is byte-identical after the read, `unknown` for a file that is not a database, and `OS_DATABASE_URL` is followed. - `packages/create-objectstack/src/studio-customization-disclosure.test.ts`: both docs carry the section and say `.custom`, database, `src/`, `Dockerfile`, `os package export`, `os package install`; AGENTS.md tells the agent to make app changes in `src/`. <details><summary>Local runs on 0baf7e9</summary> Head `0baf7e9a4` (after merging `origin/main` once, rebuilding the workspace, `pnpm --filter @objectstack/spec check:generated` exit 0). - `pnpm --filter @objectstack/cli typecheck` exit 0; `pnpm --filter create-objectstack typecheck` exit 0. - `pnpm --filter @objectstack/cli exec vitest run --project unit`: 385/385 files, 5435/5435 tests. - `pnpm --filter @objectstack/cli exec vitest run src/utils/local-customizations.sqlite.test.ts` (integration tier): 5/5. The rest of the CLI integration tier is declared to CI. - `pnpm --filter create-objectstack test`: 24/24 files, 369/369 tests. - `node scripts/pm/dispatch-gates.mjs --commands`: 62 families, each run with its exit code captured before any pipe, all exit 0; `--ran`: 62 derived, 62 run, 0 NOT-MEASURED, 0 UNRUN. - `pnpm lint` exit 0. - `fd70306c1` changes the changeset's `Clause-②` line only (the seat's ruling: the exported `CompileCommand` gains a protected member). Re-run on it: `check-adr-0087-registration`, `check-changeset-no-major`, `check-empty-changeset`, `check:changeset-gate-self-tests`, all exit 0. - The first unit run caught `test/validate-build-gate-parity.test.ts` red: the closed roster of names `compile.ts` calls did not classify the two new calls. They are now a `NOT_A_GATE` row with its reason (an advisory about the dev database, judges no metadata, refuses nothing). </details> ## Acceptance notes - **Re-measured on current `main` (959c26b), app-todo, real `os dev`:** `POST /packages/com.example.todo/ensure-customization` then `PUT /meta/view/todo_task.default?package=com.example.todo.custom` with `overrides: { package: 'com.example.todo', basedOn: '2.0.0' }` is served (label changed). The row is in `sys_metadata` with `package_id = com.example.todo.custom`, `state = active`. `src/`: 0 hits for the change; `os build` artifact: 0; `os package export`: 1, in `01-com.example.todo.custom/objectstack.json`. The card's premise holds. - **The notice, measured on this branch:** `os build` on that project printed `⚠ This build does not carry 1 Studio customization stored in your dev database: com.example.todo.custom (1).` and the two lines under it, both with `os dev` running (WAL, read-only open alongside the live server) and after it stopped. `os dev`'s own boot compile printed nothing new. - **Scope of the read:** only a local SQLite dev database is probed. A developer whose dev database is Postgres gets the docs, not the build notice: reading it would be a network round trip, which the dispatch ruled out. - **What counts:** stored `.custom` items, all states. An ensured pair with no item has no row and nothing to lose, so it is not counted. A package authored wholly in Studio (not a pair) is not counted either; `os package export` carries it, and the docs' "every package the database holds that `src/` does not register" covers it. - **ui residue (out of scope, ui lane paused):** the card's first Expected bullet, Studio saying where a customization is saved and how it moves. No `ui/**` edit here. ## Verification 1. `cd examples/app-todo && os dev`, sign in, `POST /api/v1/packages/com.example.todo/ensure-customization`, then save any view override into `com.example.todo.custom`. 2. `os build` in the same directory: the last block names `com.example.todo.custom (1)`, the database file, and `os package export`. 3. `os compile` (or `os build --json`): no such block. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbrroXG7sXSzmQs4uj)_ <!-- signed: domain:server#4 · os-bill · session_01Utp6CZMkHvuDeVYgTD73qF --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ff3f83b commit 1c53783

10 files changed

Lines changed: 549 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/cli': patch
3+
'create-objectstack': patch
4+
---
5+
6+
feat(cli,create-objectstack): `os build` says when the local dev database holds Studio customizations the artifact leaves behind; the starter's `AGENTS.md` and README say a Studio change lives in the database and name `os package export`
7+
8+
Clause-②: yes (widening) — the exported CompileCommand gains a protected reportsLocalCustomizations flag (default false); nothing removed or narrowed
9+
Metadata-protocol: none
10+
11+
- **`@objectstack/cli`: `os build`** ends, on its text face, with one notice when the SQLite database `os dev` opens for the project (the same resolution, over the project's development `.env*` files) holds items of a `<base>.custom` package: how many, in which pair, the database file, and that `os package export` takes them out while `os dev` runs. A change saved in Studio is such an item (ADR-0146 D2), never part of `src/`, so neither the artifact nor the starter's `Dockerfile` carries it. The read is local and read-only; a database that is not a local SQLite file is not probed and prints nothing, and a file that cannot be read is said to be unchecked, never empty. `os compile`, which `os dev` runs on every boot and rebuild, and `os build --json` print nothing new.
12+
- **`create-objectstack`: the generated `AGENTS.md` and the blank starter's README** say that Studio saves into the environment's database as an item of `<package id>.custom`, that `build` and the `Dockerfile` leave it behind, that app changes are made in `src/`, and how a customization moves as a package (`os login`, `os package export`, then `os package install` on the deployment, in the numbered order).

‎packages/cli/src/commands/build.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import Compile from './compile.js';
44

55
export default class Build extends Compile {
66
static override description = 'Compile ObjectStack configuration to JSON artifact (alias for compile)';
7+
8+
/** `os build` is what a deployment runs, so it says what the artifact leaves behind. */
9+
protected override reportsLocalCustomizations = true;
710
}

‎packages/cli/src/commands/compile.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import { findExtensionFieldSuffixRefusals } from '../utils/extension-field-suffi
8787
// [#29051] An undeclared top-level flow cycle — the walk `os validate` step
8888
// 3a-vii runs, over the automation engine's own judge.
8989
import { findFlowCycleRefusals } from '../utils/flow-undeclared-cycle.js';
90+
import { localCustomizationNotice, readLocalCustomizations } from '../utils/local-customizations.js';
9091

9192
export default class Compile extends Command {
9293
static override description = 'Compile ObjectStack configuration to JSON artifact';
@@ -121,6 +122,13 @@ export default class Compile extends Command {
121122
}),
122123
};
123124

125+
/**
126+
* Whether the text face ends with the local-customization notice
127+
* (`utils/local-customizations.ts`). `os build` turns it on; `os compile`,
128+
* which `os dev` runs on every boot and rebuild, keeps it off.
129+
*/
130+
protected reportsLocalCustomizations = false;
131+
124132
async run(): Promise<void> {
125133
const { args, flags } = await this.parse(Compile);
126134
const timer = createTimer();
@@ -1447,6 +1455,22 @@ export default class Compile extends Command {
14471455
}
14481456
console.log('');
14491457

1458+
// A Studio customization in the local dev database is left behind by
1459+
// this artifact (ADR-0146 D2: it lives in `<base>.custom`, in the
1460+
// database). Said once, on `os build` only — the command a deployment
1461+
// runs; `os dev` compiles through `os compile` on every boot and rebuild,
1462+
// where it would be noise.
1463+
if (this.reportsLocalCustomizations) {
1464+
const notice = localCustomizationNotice(
1465+
await readLocalCustomizations({ projectRoot: process.cwd(), artifactPath }),
1466+
);
1467+
if (notice.length > 0) {
1468+
printWarning(notice[0]);
1469+
for (const line of notice.slice(1)) console.log(chalk.dim(` ${line}`));
1470+
console.log('');
1471+
}
1472+
}
1473+
14501474
} catch (error: any) {
14511475
if (isExitSignal(error)) throw error;
14521476
if (flags.json) {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// The integration half of `os build`'s local-customization notice: the read
4+
// against a real SQLite file, the shape `os dev` leaves in
5+
// `.objectstack/data/objectstack.db` (a `sys_metadata` row per stored item,
6+
// keyed by `package_id`). The pure half is `local-customizations.test.ts`.
7+
8+
import { describe, it, expect, afterEach } from 'vitest';
9+
import fs from 'node:fs';
10+
import os from 'node:os';
11+
import path from 'node:path';
12+
import Database from 'better-sqlite3';
13+
// Loaded here, at module top, so no clocked test pays the runtime graph's first
14+
// load inside its window: `readLocalCustomizations` imports it lazily.
15+
import '@objectstack/runtime';
16+
import { readCustomizationsFromSqlite, readLocalCustomizations } from './local-customizations.js';
17+
18+
const dirs: string[] = [];
19+
function tempProject(): string {
20+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-local-customizations-db-'));
21+
dirs.push(dir);
22+
return dir;
23+
}
24+
afterEach(() => {
25+
for (const d of dirs.splice(0)) fs.rmSync(d, { recursive: true, force: true });
26+
});
27+
28+
function devDatabase(root: string, rows: Array<[type: string, name: string, packageId: string | null]>): string {
29+
const file = path.join(root, '.objectstack', 'data', 'objectstack.db');
30+
fs.mkdirSync(path.dirname(file), { recursive: true });
31+
const db = new Database(file);
32+
db.exec('CREATE TABLE sys_metadata (id TEXT PRIMARY KEY, type TEXT, name TEXT, package_id TEXT, state TEXT)');
33+
const insert = db.prepare('INSERT INTO sys_metadata (id, type, name, package_id, state) VALUES (?, ?, ?, ?, ?)');
34+
rows.forEach(([type, name, packageId], i) => insert.run(`m${i}`, type, name, packageId, 'active'));
35+
db.close();
36+
return file;
37+
}
38+
39+
describe('reading the stored `.custom` items of the dev database', () => {
40+
it('counts the items of each `.custom` package, and nothing else', async () => {
41+
const root = tempProject();
42+
const file = devDatabase(root, [
43+
['view', 'asset_list', 'com.example.asset-repair.custom'],
44+
['dashboard', 'ops', 'com.example.asset-repair.custom'],
45+
['view', 'lead_list', 'com.vendor.crm.custom'],
46+
['view', 'authored', 'com.example.studio-app'],
47+
['view', 'packageless', null],
48+
// A package whose id merely contains the suffix is not a pair.
49+
['view', 'decoy', 'com.custom.tools'],
50+
// The suffix ends the id; `.customs` is another package.
51+
['view', 'decoy2', 'com.example.customs'],
52+
]);
53+
54+
const reading = await readLocalCustomizations({ projectRoot: root, env: {} });
55+
expect(reading).toEqual({
56+
status: 'found',
57+
filename: file,
58+
packages: [
59+
{ id: 'com.example.asset-repair.custom', items: 2 },
60+
{ id: 'com.vendor.crm.custom', items: 1 },
61+
],
62+
});
63+
});
64+
65+
it('answers none for a database with no `.custom` item, or not yet booted into tables', async () => {
66+
const root = tempProject();
67+
const file = devDatabase(root, [['view', 'authored', 'com.example.studio-app']]);
68+
expect(await readCustomizationsFromSqlite(file)).toEqual({ status: 'none', filename: file });
69+
70+
const empty = path.join(tempProject(), 'empty.db');
71+
new Database(empty).close();
72+
expect(await readCustomizationsFromSqlite(empty)).toEqual({ status: 'none', filename: empty });
73+
});
74+
75+
it('opens the file read-only: it is byte-identical after the read', async () => {
76+
const root = tempProject();
77+
const file = devDatabase(root, [['view', 'asset_list', 'com.example.app.custom']]);
78+
const before = fs.readFileSync(file);
79+
await readCustomizationsFromSqlite(file);
80+
expect(fs.readFileSync(file).equals(before)).toBe(true);
81+
});
82+
83+
it('answers unknown, with the reason, for a file that is not a database', async () => {
84+
const file = path.join(tempProject(), 'objectstack.db');
85+
fs.writeFileSync(file, 'not a sqlite database, just text that is long enough to have a header'.repeat(10));
86+
const reading = await readCustomizationsFromSqlite(file);
87+
expect(reading.status).toBe('unknown');
88+
expect(reading).toMatchObject({ filename: file });
89+
});
90+
91+
it('follows OS_DATABASE_URL to the file `os dev` would open', async () => {
92+
const root = tempProject();
93+
const elsewhere = devDatabase(tempProject(), [['view', 'v', 'com.example.app.custom']]);
94+
const reading = await readLocalCustomizations({ projectRoot: root, env: { OS_DATABASE_URL: `file:${elsewhere}` } });
95+
expect(reading).toMatchObject({ status: 'found', filename: elsewhere });
96+
});
97+
});
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// The pure half of `os build`'s local-customization notice: which database it
4+
// reads, which file a URL names, what it says for each reading, and that only
5+
// `os build` says it. Reading a real SQLite file is the integration half
6+
// (`local-customizations.sqlite.test.ts`).
7+
8+
import { describe, it, expect, afterEach } from 'vitest';
9+
import fs from 'node:fs';
10+
import os from 'node:os';
11+
import path from 'node:path';
12+
import { sqliteFilenameFromUrl } from '@objectstack/runtime';
13+
import {
14+
devDatabaseEnv,
15+
localSqliteFile,
16+
localCustomizationNotice,
17+
readCustomizationsFromSqlite,
18+
readLocalCustomizations,
19+
} from './local-customizations.js';
20+
import Build from '../commands/build.js';
21+
import Compile from '../commands/compile.js';
22+
23+
const dirs: string[] = [];
24+
function tempProject(): string {
25+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-local-customizations-'));
26+
dirs.push(dir);
27+
return dir;
28+
}
29+
afterEach(() => {
30+
for (const d of dirs.splice(0)) fs.rmSync(d, { recursive: true, force: true });
31+
});
32+
33+
describe('the database the notice reads is the one `os dev` opens', () => {
34+
it('layers the development .env files under the process environment, without loading them', () => {
35+
const root = tempProject();
36+
fs.writeFileSync(path.join(root, '.env'), 'OS_DATABASE_URL=file:./from-env-file.db\nOS_ONLY_IN_FILE=1\n');
37+
fs.writeFileSync(path.join(root, '.env.development'), 'OS_DATABASE_URL=file:./from-development.db\n');
38+
39+
const fromFiles = devDatabaseEnv(root, {});
40+
expect(fromFiles.OS_DATABASE_URL).toBe('file:./from-development.db');
41+
expect(fromFiles.OS_ONLY_IN_FILE).toBe('1');
42+
43+
// dotenv-flow never overrides a variable the process already has.
44+
expect(devDatabaseEnv(root, { OS_DATABASE_URL: 'file:/from-shell.db' }).OS_DATABASE_URL).toBe('file:/from-shell.db');
45+
expect(process.env.OS_ONLY_IN_FILE).toBeUndefined();
46+
});
47+
48+
it('names a file only for a local SQLite URL', () => {
49+
expect(localSqliteFile('file:/tmp/x/objectstack.db', sqliteFilenameFromUrl)).toBe('/tmp/x/objectstack.db');
50+
expect(localSqliteFile('wasm-sqlite:///tmp/x/objectstack.db', sqliteFilenameFromUrl)).toBe('/tmp/x/objectstack.db');
51+
expect(localSqliteFile('file::memory:', sqliteFilenameFromUrl)).toBeNull();
52+
expect(localSqliteFile(':memory:', sqliteFilenameFromUrl)).toBeNull();
53+
expect(localSqliteFile('postgres://u:p@db:5432/app', sqliteFilenameFromUrl)).toBeNull();
54+
expect(localSqliteFile('libsql://app.turso.io', sqliteFilenameFromUrl)).toBeNull();
55+
});
56+
57+
it('reads nothing when the resolved database is remote or not created yet', async () => {
58+
const root = tempProject();
59+
expect(await readLocalCustomizations({ projectRoot: root, env: { OS_DATABASE_URL: 'postgres://u:p@db:5432/app' } }))
60+
.toEqual({ status: 'not_applicable' });
61+
// The unified default `<root>/.objectstack/data/objectstack.db`, never booted.
62+
expect(await readLocalCustomizations({ projectRoot: root, env: {} })).toEqual({ status: 'not_applicable' });
63+
expect(await readCustomizationsFromSqlite(path.join(root, 'absent.db'))).toEqual({ status: 'not_applicable' });
64+
});
65+
66+
it('reads nothing, and never throws, for a selection the dev boot refuses', async () => {
67+
const root = tempProject();
68+
expect(await readLocalCustomizations({ projectRoot: root, env: { OS_DATABASE_DRIVER: 'memory' } }))
69+
.toEqual({ status: 'not_applicable' });
70+
});
71+
});
72+
73+
describe('what the notice says', () => {
74+
it('names each pair, the count, the file and `os package export`', () => {
75+
const lines = localCustomizationNotice({
76+
status: 'found',
77+
filename: '/p/.objectstack/data/objectstack.db',
78+
packages: [
79+
{ id: 'com.example.app.custom', items: 2 },
80+
{ id: 'com.vendor.crm.custom', items: 1 },
81+
],
82+
});
83+
const text = lines.join('\n');
84+
expect(text).toContain('3 Studio customizations');
85+
expect(text).toContain('com.example.app.custom (2)');
86+
expect(text).toContain('com.vendor.crm.custom (1)');
87+
expect(text).toContain('/p/.objectstack/data/objectstack.db');
88+
expect(text).toContain('os package export');
89+
});
90+
91+
it('says it could not check, never that there is nothing, when the read failed', () => {
92+
const text = localCustomizationNotice({ status: 'unknown', filename: '/p/x.db', detail: 'file is not a database' }).join('\n');
93+
expect(text).toContain('Could not check /p/x.db');
94+
expect(text).toContain('file is not a database');
95+
expect(text).toContain('os package export');
96+
});
97+
98+
it('says nothing when there is nothing to leave behind', () => {
99+
expect(localCustomizationNotice({ status: 'none', filename: '/p/x.db' })).toEqual([]);
100+
expect(localCustomizationNotice({ status: 'not_applicable' })).toEqual([]);
101+
});
102+
});
103+
104+
describe('only `os build` says it', () => {
105+
it('turns the notice on for build and leaves it off for compile, which `os dev` runs', () => {
106+
const flag = (C: typeof Compile) => (Reflect.construct(C, [[], {}]) as unknown as { reportsLocalCustomizations: boolean })
107+
.reportsLocalCustomizations;
108+
expect(flag(Build)).toBe(true);
109+
expect(flag(Compile)).toBe(false);
110+
});
111+
});

0 commit comments

Comments
 (0)