Skip to content

Commit de7c89c

Browse files
committed
feat(scenarios): gallery-refresh, the gallery refresh in one deterministic step
Version check against npm's latest stable @objectstack/cli, run on that release, export into the gallery checkout, commit on export/<version>; never pushes. Driver header names ruling D2; README runbook for the scheduled task. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5pZeHgu9hYkeNdBNEA
1 parent 7c523aa commit de7c89c

9 files changed

Lines changed: 911 additions & 10 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
feat(scenarios): `gallery-refresh`, the gallery refresh in one deterministic step
6+
7+
Clause-②: yes — a new `gallery-refresh` entry point on the published `@objectstack/scenarios` widens its surface; the PR body carries the reading
8+
Metadata-protocol: none
9+
10+
- **`pnpm --filter @objectstack/scenarios gallery-refresh --gallery DIR [--cards DIR] [--model M] [--debut] [--work DIR] [--chromium PATH]`** (`src/export/refresh-cli.ts`): reads npm's latest stable `@objectstack/cli` and the `framework.version` of every app the gallery checkout's `index.json` lists. When every listed app states that release it prints one `skip: …` line and exits 0, having run nothing; it also skips while a remote-tracking `export/<version>` branch awaits review. Otherwise it runs every card the gallery may show (origin `generic`, tier `starter` or `delivery`; `--debut`: the first of them, only into an empty gallery) with `run-scenarios --modes scratch --packages published --create-version <version>`, exports with screenshots into the checkout, commits `apps/` and `index.json` on a new local branch `export/<version>` and prints the branch, the commit and a ready PR body. It never pushes and never opens a PR. Every refusal (not a clean checkout, an index that does not validate, a prerelease `latest`, an existing local branch, no app exported, an app on another framework version, a change outside `apps/` and `index.json`) exits 1 with the reason.
11+
- **`@objectstack/scenarios/export`** also exports the step as a library: `galleryRefresh`, `runnerArgv`, `readGalleryVersions`, `npmLatestVersion`, `refreshPrBody`, `galleryBranch`, `RefreshRefusal`, `FRAMEWORK_PACKAGE`, `STABLE_VERSION` and their types.
12+
- The live driver's header names ruling D2: a local session or a scheduled cloud Claude Code task on the maintainer's subscription login may run the cards; an API-billed model still never may. The driver's refusal of an API key is unchanged.
13+
- The README gains "Refreshing the gallery — `gallery-refresh`" and the scheduled task's runbook: what it runs, what it needs, what it never does, and the task's prompt verbatim.

‎packages/qa/scenarios/README.md‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,78 @@ npx @objectstack/scenarios help # the comma
266266
dashboards and nav targets. `test/runner/prompt-trace.test.ts` reads the checks off the scorer itself and holds every
267267
card to it.
268268

269+
## Refreshing the gallery — `gallery-refresh`
270+
271+
```bash
272+
G="$(realpath ../gallery)" # pnpm runs the script in the package directory: pass absolute paths
273+
pnpm --filter @objectstack/scenarios gallery-refresh --gallery "$G" # every exportable card
274+
pnpm --filter @objectstack/scenarios gallery-refresh --gallery "$G" --debut # one card: the gallery's first app
275+
pnpm --filter @objectstack/scenarios gallery-refresh --gallery "$G" --model sonnet # the model every turn asks for
276+
```
277+
278+
One step from "is there a new stable release?" to a local commit in a checkout of objectstack-ai/gallery
279+
(`src/export/refresh.ts`, CLI `src/export/refresh-cli.ts`). It reads npm's `latest` `@objectstack/cli` and the
280+
`framework.version` of every app the gallery's `index.json` lists. When the index lists an app and every app states
281+
that version, it prints one `skip: …` line and exits 0, having run nothing. It also skips when a remote-tracking
282+
`export/<version>` branch exists: that refresh was pushed and awaits review. Otherwise it:
283+
284+
1. runs every card the gallery may show (origin `generic`, tier `starter` or `delivery`; `--debut`: the first of them
285+
by id) with `run-scenarios --modes scratch --packages published --create-version <version>`, so the apps are built
286+
on exactly that release, the turns recorded;
287+
2. exports with screenshots into the checkout (`export-gallery`'s rules: only a run that passed every half);
288+
3. creates the branch `export/<version>`, commits `apps/` and `index.json` under the checkout's own git identity, and
289+
prints the branch, the commit and a ready PR body.
290+
291+
It refuses, exit 1 with the reason, when: `--gallery` is not the top of a git checkout or has uncommitted changes;
292+
the index does not validate; npm's `latest` is not a plain `MAJOR.MINOR.PATCH`; a local `export/<version>` branch
293+
already exists; `--debut` meets an index that lists an app; no card may be exported; no app exported; an exported app
294+
states another framework version; or anything outside `apps/` and `index.json` changed. The last three leave the
295+
working tree as the export left it, uncommitted. `--work DIR` keeps the records, projects and recording (default: a
296+
temp directory, named on a refusal). ⛔ It never pushes, never opens a PR and never talks to GitHub.
297+
298+
### The scheduled task's runbook
299+
300+
Ruling D2 (2026-11-06): a daily scheduled Claude Code task in this project's cloud environment runs the refresh on the
301+
maintainer's subscription login, and the maintainer merges its PR on the gallery.
302+
303+
- **What it runs**: `gallery-refresh` from a fresh checkout of this repository, into a fresh clone of
304+
objectstack-ai/gallery; then `git push` of the one branch it created, and one PR.
305+
- **What it needs**: both repositories in the environment's resources, with push access to the gallery; npm reachable;
306+
the container's `claude` logged in with the subscription (`claude auth status` reports `oauth_token`) and neither
307+
`ANTHROPIC_API_KEY` nor `ANTHROPIC_AUTH_TOKEN` set (the live driver refuses both); a permission mode that lets the
308+
session launch the headless `claude -p` the runner spawns (Auto mode's classifier refuses it, see
309+
[the cloud session settings](#running-the-cards-in-a-claude-code-cloud-session)); Chromium for the screenshots
310+
(preinstalled in the cloud container). A full refresh runs one `starter` build after another, longer than the
311+
2-hour cap on a background command, so the task starts it detached and waits in the foreground.
312+
- **What it never does**: push `main` or any branch but `export/<version>`, force-push, merge, edit a gallery file by
313+
hand, pass `--packages workspace`, or run on an API key. A refusal is reported, never retried around.
314+
315+
The task's prompt, verbatim:
316+
317+
```text
318+
Refresh the ObjectStack scenario gallery. Run each step in order and stop at the first that fails.
319+
320+
1. Check the login: `unset ANTHROPIC_API_KEY ANTHROPIC_AUTH_TOKEN; claude auth status` must report oauth_token.
321+
Anything else is a failure (step 6).
322+
2. In the objectstack checkout: `git fetch origin main && git checkout --detach origin/main`, `pnpm install`,
323+
`pnpm --filter '@objectstack/scenarios^...' build`.
324+
3. Clone the gallery beside it: `git clone https://github.com/objectstack-ai/gallery ../gallery`.
325+
If ../gallery/index.json is missing or lists no app, add `--debut` to the command in step 4.
326+
4. Start the refresh detached and wait for it in the foreground:
327+
`nohup sh -c 'pnpm --filter @objectstack/scenarios gallery-refresh --gallery "$(realpath ../gallery)" --work /tmp/gallery-refresh; echo "gallery-refresh exit $?"' > /tmp/gallery-refresh.log 2>&1 & echo $! > /tmp/gallery-refresh.pid`
328+
then repeat `timeout 590 tail --pid="$(cat /tmp/gallery-refresh.pid)" -f /dev/null` until the process is gone.
329+
The log's last line is `gallery-refresh exit N`; any N but 0 is a failure (step 6).
330+
5. If a line of the log starts with `skip:`, stop: report that line and do nothing else.
331+
Otherwise the log names a `branch: export/VERSION`: push exactly that branch
332+
(`git -C ../gallery push origin export/VERSION`) and open one pull request on objectstack-ai/gallery from it into
333+
main, titled `Gallery refresh for ObjectStack VERSION`, with the text after "open the PR with this body:" as its
334+
body. Never push main, never force-push, never merge, never edit a gallery file by hand.
335+
6. On any failure (a refusal, a non-zero exit, a failed push or PR): search the open issues of
336+
objectstack-ai/objectstack for one titled `Gallery refresh failed`. If one exists, add a comment with today's
337+
date, the step that failed and the last 40 lines of /tmp/gallery-refresh.log; otherwise open one issue with that
338+
title and the same text. Never open a second one.
339+
```
340+
269341
## Other agent tools — Codex and the external driver contract
270342

271343
The same card can measure another agent tool. Every record (`env.driver`) and every gallery app page (`- Driver:`)

‎packages/qa/scenarios/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
"test": "vitest run",
6767
"typecheck": "tsc --noEmit",
6868
"run-scenarios": "tsx src/runner/cli.ts",
69-
"export-gallery": "tsx src/export/cli.ts"
69+
"export-gallery": "tsx src/export/cli.ts",
70+
"gallery-refresh": "tsx src/export/refresh-cli.ts"
7071
},
7172
"dependencies": {
7273
"@objectstack/core": "workspace:*",

‎packages/qa/scenarios/src/export/cli.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export function renderSummary(s: ExportSummary): string[] {
8585
return lines;
8686
}
8787

88+
/** The real screenshot step: boot the project, sign in as the dev admin, drive Chromium (`--chromium PATH`, or Playwright's own). */
89+
export function liveScreenshots(chromium?: string): CaptureScreenshots {
90+
const browser = playwrightBrowser(chromium ? { executablePath: chromium } : {});
91+
return (input) => captureScreenshots(input, { boot: (dir) => bootDev(dir), harness: (url) => new HttpApp({ baseUrl: url, adminEmail: ADMIN.email, adminPassword: ADMIN.password }), browser, admin: ADMIN });
92+
}
93+
8894
/** Test seam: replace the screenshot step (the CLI's is the real browser). */
8995
export interface ExportCliDeps {
9096
screenshots?: CaptureScreenshots;
@@ -102,11 +108,7 @@ export async function main(argv: readonly string[], deps: ExportCliDeps = {}): P
102108
});
103109
for (const r of refusals) console.error(formatRefusal(r));
104110
const recordings = args.recordings.map((f) => JSON.parse(readFileSync(resolve(f), 'utf8')) as Recording);
105-
const browser = playwrightBrowser(args.chromium ? { executablePath: args.chromium } : {});
106-
const screenshots: CaptureScreenshots | false = !args.screenshots
107-
? false
108-
: (deps.screenshots ??
109-
((input) => captureScreenshots(input, { boot: (dir) => bootDev(dir), harness: (url) => new HttpApp({ baseUrl: url, adminEmail: ADMIN.email, adminPassword: ADMIN.password }), browser, admin: ADMIN })));
111+
const screenshots: CaptureScreenshots | false = !args.screenshots ? false : (deps.screenshots ?? liveScreenshots(args.chromium));
110112
const summary = await exportGallery({
111113
runsDir,
112114
outDir: resolve(args.out!),

‎packages/qa/scenarios/src/export/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
* `@objectstack/scenarios/export` — the gallery exporter: verified scenario
55
* apps written to a local directory in the layout of objectstack-ai/gallery.
66
* Private, like the rest of this package. CLI:
7-
* `pnpm --filter @objectstack/scenarios export-gallery --runs DIR --out DIR`.
7+
* `pnpm --filter @objectstack/scenarios export-gallery --runs DIR --out DIR`;
8+
* the whole refresh (version check, run, export, commit) is
9+
* `pnpm --filter @objectstack/scenarios gallery-refresh --gallery DIR`.
810
*/
911

1012
export * from './exporter.js';
1113
export * from './generic.js';
1214
export * from './manifest.js';
1315
export * from './pass.js';
1416
export * from './record.js';
17+
export * from './refresh.js';
1518
export * from './screenshots.js';
1619
export * from './source.js';
1720
export * from './transcript.js';
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `pnpm --filter @objectstack/scenarios gallery-refresh --gallery DIR [flags]`
5+
* — the gallery refresh in one step (`refresh.ts`): npm's latest stable
6+
* `@objectstack/cli` against the gallery's `index.json`; when they differ, run
7+
* the cards on that release, export into the gallery checkout and commit on
8+
* `export/<version>`. Ruling D2: a daily scheduled Claude Code task on the
9+
* maintainer's subscription login runs it (the package README holds the
10+
* task's runbook).
11+
*
12+
* --gallery DIR the gallery checkout, the top of its git working tree (required)
13+
* --cards DIR the card directory (default: the repo's docs/qa/scenarios);
14+
* any other directory is loaded as the private overlay,
15+
* where a `generic` card is refused (`libraryOf`)
16+
* --model M the model every live turn asks for (`run-scenarios --model`;
17+
* default: the login's own)
18+
* --debut run and export one card only, the first exportable card
19+
* by id: the gallery's first app (refused once the index lists one)
20+
* --work DIR where the run's records, projects and recording go
21+
* (default: a new temp directory)
22+
* --chromium PATH the Chromium executable for the screenshots
23+
*
24+
* Output: `skip: …` (one line, exit 0) when the gallery is already on the
25+
* release; otherwise the branch, the commit and the PR body, exit 0. A refusal
26+
* prints why and exits 1. ⛔ It never pushes and never opens the PR.
27+
*/
28+
29+
import { existsSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs';
30+
import { tmpdir } from 'node:os';
31+
import { dirname, join, resolve } from 'node:path';
32+
import { fileURLToPath } from 'node:url';
33+
34+
import { formatRefusal, libraryOf, loadScenarios, readCapabilityAreas } from '../loader.js';
35+
import { findUp, main as runScenarios } from '../runner/cli.js';
36+
import { liveScreenshots, renderSummary } from './cli.js';
37+
import { galleryRefresh, RefreshRefusal, runnerArgv, type RefreshDeps, type RefreshOutcome } from './refresh.js';
38+
39+
export interface RefreshCliArgs {
40+
gallery: string;
41+
cards?: string;
42+
model?: string;
43+
debut: boolean;
44+
work?: string;
45+
chromium?: string;
46+
}
47+
48+
export function parseRefreshArgs(argv: readonly string[]): RefreshCliArgs {
49+
const a: Partial<RefreshCliArgs> & { debut: boolean } = { debut: false };
50+
for (let i = 0; i < argv.length; i++) {
51+
const flag = argv[i]!;
52+
const val = () => {
53+
const v = argv[++i];
54+
if (v === undefined) throw new Error(`${flag} needs a value`);
55+
return v;
56+
};
57+
if (flag === '--gallery') a.gallery = val();
58+
else if (flag === '--cards') a.cards = val();
59+
else if (flag === '--model') {
60+
const raw = val();
61+
if (raw.trim() === '' || raw.startsWith('-')) throw new Error(`--model takes a model alias or name (sonnet, opus, claude-sonnet-4-5), not \`${raw}\``);
62+
a.model = raw;
63+
} else if (flag === '--debut') a.debut = true;
64+
else if (flag === '--work') a.work = val();
65+
else if (flag === '--chromium') a.chromium = val();
66+
else throw new Error(`unknown flag \`${flag}\``);
67+
}
68+
if (!a.gallery) throw new Error('--gallery DIR is required: the gallery checkout the refresh exports into and commits in');
69+
return a as RefreshCliArgs;
70+
}
71+
72+
/** What the CLI prints for an outcome, one entry per line. */
73+
export function renderOutcome(o: RefreshOutcome): string[] {
74+
if (o.kind === 'skip') return [o.line];
75+
return [
76+
...renderSummary(o.summary),
77+
`branch: ${o.branch}`,
78+
`commit: ${o.commit}`,
79+
'Not pushed. Push the branch and open the PR with this body:',
80+
'',
81+
o.body,
82+
];
83+
}
84+
85+
/** Test seam: replace the steps that reach outside (npm, the model, the browser). */
86+
export type RefreshCliDeps = Partial<RefreshDeps>;
87+
88+
export async function main(argv: readonly string[], deps: RefreshCliDeps = {}, io = { out: (l: string) => console.log(l), err: (l: string) => console.error(l) }): Promise<number> {
89+
const args = parseRefreshArgs(argv);
90+
const here = dirname(fileURLToPath(import.meta.url));
91+
const repo = findUp(here, (d) => existsSync(join(d, 'pnpm-workspace.yaml')));
92+
const cardsDir = resolve(args.cards ?? join(repo, 'docs/qa/scenarios'));
93+
const { cards, refusals } = loadScenarios(cardsDir, {
94+
areas: readCapabilityAreas(join(repo, 'docs/qa/platform-checklist/areas')),
95+
library: libraryOf(cardsDir, repo),
96+
});
97+
for (const r of refusals) io.err(formatRefusal(r));
98+
const work = resolve(args.work ?? mkdtempSync(join(tmpdir(), 'gallery-refresh-')));
99+
mkdirSync(work, { recursive: true });
100+
const run: RefreshDeps['run'] =
101+
deps.run ??
102+
(async (plan) => {
103+
const code = await runScenarios(runnerArgv(plan));
104+
if (code !== 0) throw new RefreshRefusal(`run-scenarios exited ${code}: nothing is exported`);
105+
});
106+
try {
107+
const outcome = await galleryRefresh(
108+
{ galleryDir: resolve(args.gallery), cards, ...(args.cards ? { cardsDir } : {}), debut: args.debut, ...(args.model ? { model: args.model } : {}), workDir: work },
109+
{ ...deps, run, screenshots: deps.screenshots ?? liveScreenshots(args.chromium) },
110+
);
111+
// A skip ran nothing: the temp directory it was given is removed again.
112+
if (outcome.kind === 'skip' && args.work === undefined) rmSync(work, { recursive: true, force: true });
113+
for (const line of renderOutcome(outcome)) io.out(line);
114+
return 0;
115+
} catch (e) {
116+
if (!(e instanceof RefreshRefusal)) throw e;
117+
io.err(`gallery-refresh: refused — ${e.message}`);
118+
io.err(`work directory: ${work}`);
119+
return 1;
120+
}
121+
}
122+
123+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
124+
main(process.argv.slice(2)).then(
125+
(code) => process.exit(code),
126+
(e) => {
127+
console.error(e instanceof Error ? e.message : e);
128+
process.exit(1);
129+
},
130+
);
131+
}

0 commit comments

Comments
 (0)