Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
ci(release): a since: 'TBD' BEHAVIOR_CHANGES row never ships
garrytanfd4b560ae43c
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 2e9e4e76aa..614fe5988d 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -88,9 +88,13 @@ jobs:persist-credentials: falsesparse-checkout: |scripts+ src/core/behavior-change-notice.ts- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2with:bun-version: 1.4.3+ # A since: 'TBD' BEHAVIOR_CHANGES row never ships (scripts/check-behavior-since.ts).+ - name: Refuse a since 'TBD' BEHAVIOR_CHANGES row+ run: bun scripts/check-behavior-since.ts --stamped- id: gatename: Wait for Test and E2E Tests on the release commitenv:diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex e8f1c76c71..964205f79e 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -205,7 +205,10 @@ and the commit it would make, and changes nothing.required row of the CLAUDE.md "Version locations" table: VERSION,`package.json`, the three plugin manifests, the BOOTSTRAP runbook stamp,the CHANGELOG entry (re-stamped on top of master's entries with today's- date), and branch-added TODOS lines naming the old version.+ date), branch-added TODOS lines naming the old version, and every+ `since: 'TBD'` row in `src/core/behavior-change-notice.ts` (development+ branches write their BEHAVIOR_CHANGES rows as TBD; the stamp gives them the+ new version).5. Renumbers the branch's own schema migrations (files `origin/master` doesnot have) consecutively from master's latest + 1, in their original order.It changes only the filename, the `export const v<NNN>` name and the@@ -223,7 +226,8 @@ and the commit it would make, and changes nothing.line (an edited line is not listed again), or pass `--accept-references`with `--continue` when a line means the published migration.8. Runs the drift checks (version stamps and CHANGELOG agree, bootstrap- stamp, plugin tree, template repo, migration registry and order), commits+ stamp, plugin tree, template repo, migration registry and order, no+ `since: 'TBD'` row left: `bun scripts/check-behavior-since.ts --stamped`), commitsonce as `v<new> chore(release): restamp onto master v<master>`, and printsthe old-to-new migration mapping with the collision-recovery steps, thegolden-regeneration reason for the PR body, the PR title anddiff --git a/package.json b/package.jsonindex 0ee6c897a2..e2b2ee747f 100644--- a/package.json+++ b/package.json@@ -174,6 +174,7 @@"check:shared-tree-git": "bash scripts/check-shared-tree-git.sh","check:bash32": "bash scripts/check-bash32.sh","check:schema-migration-order": "bun scripts/check-schema-migration-order.ts",+ "check:behavior-since": "bun scripts/check-behavior-since.ts","check:compile-autoload": "bash scripts/check-compile-autoload.sh","check:structural-manifest": "bash scripts/check-structural-manifest.sh","regen:all": "bun scripts/regen-all.ts",diff --git a/scripts/check-behavior-since.ts b/scripts/check-behavior-since.tsnew file mode 100644index 0000000000..aa2d62afa8--- /dev/null+++ b/scripts/check-behavior-since.ts@@ -0,0 +1,102 @@+#!/usr/bin/env bun+/**+ * check:behavior-since — a BEHAVIOR_CHANGES row with `since: 'TBD'` never ships.+ *+ * bun run check:behavior-since verify / CI: refuse TBD rows on a stamped tree or master+ * bun scripts/check-behavior-since.ts --stamped+ * restamp / release: refuse any TBD row+ *+ * Unstamped development branches write their rows as since: 'TBD' and the+ * merge-slot stamp gives them the release. compareReleases ranks 'TBD' below+ * every release, so a TBD row that ships is never disclosed by the upgrade+ * notice. Any TBD row is refused when:+ * - --stamped is passed (release:restamp after it rewrites the rows, the+ * Release workflow before it publishes);+ * - the run is on master (GITHUB_REF=refs/heads/master, or HEAD is the base+ * ref's commit), or the base ref itself carries a TBD row;+ * - CHANGELOG.md has a release header for VERSION and VERSION differs from+ * the base ref's VERSION (a stamped PR head, stamped by tool or by hand).+ * Otherwise VERSION equals the base's (an unstamped branch) and TBD rows pass.+ *+ * Base ref: $GBRAIN_RELEASE_BASE_REF, default origin/master. When it is+ * unavailable the check fails under CI=true and skips locally.+ * Exit: 0 ok or skipped, 1 refused, 2 usage. Docs: docs/RELEASING.md#release-restamp+ */+import { spawnSync } from 'node:child_process';+import { existsSync, readFileSync } from 'node:fs';+import { join } from 'node:path';++export const NOTICE_FILE = 'src/core/behavior-change-notice.ts';+const TBD = /since:\s*'TBD'/;+const SEE = 'See: docs/RELEASING.md#release-restamp';++/** 1-based line numbers of the since: 'TBD' rows in the notice source. */+export function tbdLines(text: string): number[] {+ return text.split('\n').flatMap((line, i) => (TBD.test(line) ? [i + 1] : []));+}++export function main(argv: string[], opts: { cwd?: string; env?: Record<string, string | undefined>; log?: (line: string) => void } = {}): number {+ const root = opts.cwd ?? process.cwd();+ const env = opts.env ?? process.env;+ const log = opts.log ?? ((line: string) => console.log(line));+ const unknown = argv.filter((a) => a !== '--stamped');+ if (unknown.length) {+ log(`usage: bun scripts/check-behavior-since.ts [--stamped] (unknown: ${unknown.join(' ')})`);+ return 2;+ }+ const git = (...args: string[]) => {+ const r = spawnSync('git', args, { cwd: root, encoding: 'utf8' });+ return { ok: r.status === 0, out: (r.stdout ?? '').trim() };+ };+ const read = (file: string) => (existsSync(join(root, file)) ? readFileSync(join(root, file), 'utf8') : '');++ if (argv.includes('--stamped') && !existsSync(join(root, NOTICE_FILE))) {+ log(`FAIL: ${NOTICE_FILE} is missing, so its rows cannot be checked before stamping or release.`);+ log('Fix: check the file out (a sparse checkout must include it), then rerun.');+ log(SEE);+ return 1;+ }+ const lines = tbdLines(read(NOTICE_FILE));+ if (lines.length === 0) {+ log(`check-behavior-since: ok (no since: 'TBD' row in ${NOTICE_FILE})`);+ return 0;+ }+ const version = read('VERSION').trim();+ const refuse = (context: string) => {+ log(`FAIL: ${lines.length} BEHAVIOR_CHANGES row(s) in ${NOTICE_FILE} still say since: 'TBD' (line ${lines.join(', ')}) on ${context}.`);+ log("Why: compareReleases ranks 'TBD' below every release, so a shipped TBD row is never shown by the upgrade notice; the merge-slot stamp must give each row its release.");+ log(`Fix: run bun run release:restamp (it rewrites every since: 'TBD' to the new VERSION), or replace each since: 'TBD' with since: '${version}' by hand, then rerun bun run check:behavior-since.`);+ log(SEE);+ return 1;+ };++ if (argv.includes('--stamped')) return refuse(`a tree being stamped or released (VERSION ${version})`);+ if (env.GITHUB_REF === 'refs/heads/master') return refuse(`master (VERSION ${version})`);++ const ref = env.GBRAIN_RELEASE_BASE_REF || 'origin/master';+ const baseCommit = git('rev-parse', '--verify', '-q', `${ref}^{commit}`);+ if (!baseCommit.ok) {+ const msg = `check-behavior-since: base ref ${ref} is not available (git fetch origin master)`;+ if (env.CI === 'true') {+ log(`FAIL: ${msg}`);+ log('Why: without the base ref the check cannot tell an unstamped branch from a stamped one.');+ log('Fix: fetch it in the workflow (git fetch --no-tags --depth=1 origin +refs/heads/master:refs/remotes/origin/master)');+ log(SEE);+ return 1;+ }+ log(`skip: ${msg}`);+ log(`GBRAIN_CHECK_SKIPPED: base ref ${ref} unavailable`);+ return 0;+ }+ if (git('rev-parse', 'HEAD').out === baseCommit.out) return refuse(`the base ref ${ref} itself (VERSION ${version})`);+ const base = git('show', `${ref}:${NOTICE_FILE}`);+ if (base.ok && tbdLines(base.out).length > 0) return refuse(`a tree whose base ${ref} already ships a TBD row`);+ const baseVersion = git('show', `${ref}:VERSION`).out.trim();+ const header = read('CHANGELOG.md').split('\n').some((line) => line.startsWith(`## [${version}]`));+ if (header && version !== baseVersion) return refuse(`a stamped tree (VERSION ${version} has a CHANGELOG release header; ${ref} is at ${baseVersion})`);++ log(`check-behavior-since: ok (${lines.length} since: 'TBD' row(s) on an unstamped branch: VERSION ${version} equals ${ref}'s; the merge-slot stamp replaces them)`);+ return 0;+}++if (import.meta.main) process.exit(main(process.argv.slice(2)));diff --git a/scripts/guards-manifest.tsv b/scripts/guards-manifest.tsvindex 9b839592d0..e4d304135e 100644--- a/scripts/guards-manifest.tsv+++ b/scripts/guards-manifest.tsv@@ -81,6 +81,7 @@ check-retired-phrases.sh scanner yes W7 (refactor wave 1): retired contributor-wcheck-shared-tree-git.sh scanner yes #6530: unsafe shared-checkout git (pull --rebase, autostash, stash, repo-wide add/commit, reset --hard, bare or force push) fails in fenced code and inline code under skills/, recipes/, templates/, docs/, plugin trees and the three agent docs; allow markers with a reason; multi-agent rules block identical in AGENTS/BOOTSTRAP/INSTALL; GBRAIN_GUARD_ROOT seam; bad-<variant> fixturescheck-bash32.sh scanner todo #5810: every tracked *.sh parses under bash 3.2 (real parser: GBRAIN_BASH32, stock macOS /bin/bash, or the digest-pinned bash:3.2 image); not in verify CHECKS or this self-test, which must not need Docker; its bad/good fixtures run in test/scripts/check-bash32.test.ts, mandatory in the test.yml verify-job step (GBRAIN_TEST_BASH32_REQUIRE=1)check-schema-migration-order.ts repostate exempt EO10: a migration origin/master lacks must be numbered above its latest version; reads the base ref from git (unit: test/scripts/build-schema-migrations.test.ts)+check-behavior-since.ts repostate exempt A since: 'TBD' BEHAVIOR_CHANGES row never ships: refused on a stamped tree, on master and with --stamped (restamp, Release); reads the base ref from git (unit: test/scripts/check-behavior-since.test.ts)check-structural-manifest.sh buildfresh exempt regenerate+diff of structural-suites.tsv (classify-tests.ts); the diff IS the self-testcheck-opencode-pin.sh repostate exempt pin-stamp drift check (OPENCODE-CLI-PIN.md stamps vs heavy-tests opencode-door env); own bun guard tests in test/check-bootstrap-guards.test.tscheck-pin-doc-privacy.sh repostate exempt PIN-doc placeholder discipline (no operator paths/key material/emails in docs/mcp/*-CLI-PIN.md); own bun guard tests in test/check-bootstrap-guards.test.tsdiff --git a/scripts/lib/restamp.ts b/scripts/lib/restamp.tsindex 486d2449be..47cc37cca2 100644--- a/scripts/lib/restamp.ts+++ b/scripts/lib/restamp.ts@@ -165,6 +165,14 @@ export const STAMPS: Stamp[] = [/** Files restamp keeps in step beyond STAMPS (named so the coverage test can match the CLAUDE.md table). */export const OTHER_STAMPED_FILES = ['CHANGELOG.md', 'TODOS.md', 'templates/bootstrap/template-repo/'];+/** The BEHAVIOR_CHANGES registry whose since: 'TBD' rows restamp gives the new version. */+export const BEHAVIOR_NOTICE_FILE = 'src/core/behavior-change-notice.ts';++/** Rewrite every `since: 'TBD'` row to `since: '<version>'`. */+export function stampTbdSince(text: string, version: string): string {+ return text.replace(/since:(\s*)'TBD'/g, (_match, space: string) => `since:${space}'${version}'`);+}+/** Rewrite `vOLD` to `vNEW` in branch-added TODOS.md lines (1-based line numbers). */export function restampTodoLines(text: string, addedLines: Set<number>, oldVersion: string, newVersion: string): string {if (oldVersion === newVersion) return text;diff --git a/scripts/release-restamp.ts b/scripts/release-restamp.tsindex ef70efa248..629a413564 100644--- a/scripts/release-restamp.ts+++ b/scripts/release-restamp.ts@@ -35,9 +35,9 @@import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { join, resolve } from 'node:path';import {- COLLISION_DOCS, MIGRATION_FILE_RE, MIGRATIONS_DIR, RESTAMP_DOCS, RestampError, STAMPS,+ BEHAVIOR_NOTICE_FILE, COLLISION_DOCS, MIGRATION_FILE_RE, MIGRATIONS_DIR, RESTAMP_DOCS, RestampError, STAMPS,branchEntrySections, fail, findLeftoverRefs, isGenerated, migrationPayloadKey, nextPatchVersion, parseAddedLines,- isVersionToken, planRenumber, rebuildChangelog, renumberMigrationText, resolveVersionOnlyHunks, restampTodoLines, versionOfHeader,+ isVersionToken, planRenumber, rebuildChangelog, renumberMigrationText, resolveVersionOnlyHunks, restampTodoLines, stampTbdSince, versionOfHeader,type BranchMigration, type ChangelogSection, type LeftoverRef, type Renumber,} from './lib/restamp.ts';import { offlineEnv } from './regen-all.ts';@@ -72,6 +72,7 @@ export const DEFAULT_CHECKS: Step[] = [{ name: 'bootstrap template drift', argv: ['bash', 'scripts/check-bootstrap-templates.sh'] },{ name: 'schema migration registry fresh', argv: ['bash', 'scripts/check-schema-migrations-fresh.sh'] },{ name: 'schema migration order', argv: ['bun', 'scripts/check-schema-migration-order.ts'] },+ { name: "no since: 'TBD' BEHAVIOR_CHANGES row", argv: ['bun', 'scripts/check-behavior-since.ts', '--stamped'] },];interface State {@@ -344,6 +345,11 @@ function restampTree(ctx: Ctx, state: State, opts: { acceptRefs: boolean; date:const text = ctx.read(stamp.file);if (stamp.read(text) !== version) ctx.write(stamp.file, stamp.write(text, version));}+ if (existsSync(join(ctx.root, BEHAVIOR_NOTICE_FILE))) {+ const notice = ctx.read(BEHAVIOR_NOTICE_FILE);+ const stamped = stampTbdSince(notice, version);+ if (stamped !== notice) ctx.write(BEHAVIOR_NOTICE_FILE, stamped);+ }const olds = new Set([state.branchVersion, state.entry ? versionOfHeader(state.entry.header) ?? '' : ''].filter((v) => v && v !== version && isVersionToken(v)));if (state.entry) {const old = versionOfHeader(state.entry.header) ?? state.branchVersion;diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex 47828342c4..0d7b52648b 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -212,6 +212,9 @@ CHECKS=(# --hard or a bare/force push for a shared brain checkout (~0.5s)."check:shared-tree-git""check:schema-migration-order"+ # A since: 'TBD' BEHAVIOR_CHANGES row never ships: refused on a stamped tree+ # (VERSION has a CHANGELOG header and differs from origin/master's) and on master.+ "check:behavior-since""check:structural-manifest"# Every generated artifact's freshness in one place (GBRA-47 B8); its Fix# line is `bun run regen:all`, the same code path that regenerates them.diff --git a/test/scripts/check-behavior-since.test.ts b/test/scripts/check-behavior-since.test.tsnew file mode 100644index 0000000000..df52e7aba4--- /dev/null+++ b/test/scripts/check-behavior-since.test.ts@@ -0,0 +1,156 @@+/**+ * check:behavior-since (scripts/check-behavior-since.ts): a BEHAVIOR_CHANGES+ * row with since: 'TBD' passes on an unstamped development branch and is+ * refused on a stamped tree (VERSION has a CHANGELOG release header and differs+ * from the base ref's), on master, and under --stamped (release:restamp's drift+ * check and the Release workflow). release:restamp rewrites the rows first.+ * Fixtures are throwaway git repos; origin/master is a local ref.+ */+import { afterAll, describe, expect, test } from 'bun:test';+import { execFileSync } from 'node:child_process';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { dirname, join } from 'node:path';+import { main, NOTICE_FILE, tbdLines } from '../../scripts/check-behavior-since.ts';+import { DEFAULT_CHECKS } from '../../scripts/release-restamp.ts';+import { BEHAVIOR_NOTICE_FILE, stampTbdSince } from '../../scripts/lib/restamp.ts';++const roots: string[] = [];+afterAll(() => { for (const root of roots) rmSync(root, { recursive: true, force: true }); });++function git(cwd: string, ...args: string[]): string {+ return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();+}++function put(root: string, files: Record<string, string>): void {+ for (const [path, text] of Object.entries(files)) {+ mkdirSync(dirname(join(root, path)), { recursive: true });+ writeFileSync(join(root, path), text);+ }+}++function notice(...sinces: string[]): string {+ return ['export const BEHAVIOR_CHANGES = [', ...sinces.map((since, i) => ' { since: \'' + since + '\', text: \'Row ' + i + '.\' },'), '];', ''].join('\n');+}++function changelog(...versions: string[]): string {+ return '# Changelog\n\n' + versions.map((v) => '## [' + v + '] - 2026-10-20\n\nEntry.\n').join('\n');+}++function commit(root: string, message: string): void {+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', message);+}++/** A repo whose origin/master is at 0.60.322.0 with only released rows, checked out on a feature branch. */+function repo(): string {+ const root = mkdtempSync(join(tmpdir(), 'gbrain-behavior-since-'));+ roots.push(root);+ git(root, 'init', '-q', '-b', 'master');+ git(root, 'config', 'user.email', '[email protected]');+ git(root, 'config', 'user.name', 't');+ put(root, { VERSION: '0.60.322.0\n', 'CHANGELOG.md': changelog('0.60.322.0'), [NOTICE_FILE]: notice('0.60.321.0', '0.60.322.0') });+ commit(root, 'master');+ git(root, 'update-ref', 'refs/remotes/origin/master', 'HEAD');+ git(root, 'checkout', '-q', '-b', 'feature');+ return root;+}++function run(root: string, argv: string[] = [], env: Record<string, string> = {}): { code: number; out: string } {+ const lines: string[] = [];+ const code = main(argv, { cwd: root, env, log: (line) => lines.push(line) });+ return { code, out: lines.join('\n') };+}++describe('check:behavior-since', () => {+ test('an unstamped branch (VERSION equals origin/master) may carry TBD rows', () => {+ const root = repo();+ put(root, { [NOTICE_FILE]: notice('0.60.321.0', '0.60.322.0', 'TBD') });+ commit(root, 'feature');+ const r = run(root);+ expect(r.code).toBe(0);+ expect(r.out).toContain('unstamped branch');+ });++ test('a stamped tree with one TBD row is refused with a fix line', () => {+ const root = repo();+ put(root, { VERSION: '0.60.323.0\n', 'CHANGELOG.md': changelog('0.60.323.0', '0.60.322.0'), [NOTICE_FILE]: notice('0.60.321.0', '0.60.322.0', '0.60.323.0', 'TBD') });+ commit(root, 'stamp by hand, one row missed');+ const r = run(root);+ expect(r.code).toBe(1);+ expect(r.out).toContain('FAIL: 1 BEHAVIOR_CHANGES row(s)');+ expect(r.out).toContain('line 5');+ expect(r.out).toContain('a stamped tree');+ expect(r.out).toContain("Fix: run bun run release:restamp");+ expect(r.out).toContain("since: '0.60.323.0'");+ });++ test('a stamped tree whose rows carry the release passes', () => {+ const root = repo();+ put(root, { VERSION: '0.60.323.0\n', 'CHANGELOG.md': changelog('0.60.323.0', '0.60.322.0'), [NOTICE_FILE]: notice('0.60.322.0', '0.60.323.0', '0.60.323.0') });+ commit(root, 'stamp');+ expect(run(root).code).toBe(0);+ });++ test('--stamped refuses any TBD row, even on an unstamped branch, and passes without one', () => {+ const root = repo();+ expect(run(root, ['--stamped']).code).toBe(0);+ put(root, { [NOTICE_FILE]: notice('0.60.322.0', 'TBD') });+ commit(root, 'feature');+ const r = run(root, ['--stamped']);+ expect(r.code).toBe(1);+ expect(r.out).toContain('a tree being stamped or released');+ });++ test('--stamped refuses when the registry is missing (a sparse checkout without it)', () => {+ const root = repo();+ rmSync(join(root, NOTICE_FILE));+ expect(run(root, ['--stamped']).code).toBe(1);+ });++ test('master refuses a TBD row: by GITHUB_REF, by HEAD at the base, and when the base itself ships one', () => {+ const root = repo();+ put(root, { [NOTICE_FILE]: notice('0.60.322.0', 'TBD') });+ commit(root, 'feature');+ expect(run(root, [], { GITHUB_REF: 'refs/heads/master' }).code).toBe(1);+ git(root, 'update-ref', 'refs/remotes/origin/master', 'HEAD');+ const atBase = run(root);+ expect(atBase.code).toBe(1);+ expect(atBase.out).toContain('the base ref origin/master itself');+ put(root, { 'README.md': 'later\n' });+ commit(root, 'a branch off a master that ships TBD');+ const r = run(root);+ expect(r.code).toBe(1);+ expect(r.out).toContain('already ships a TBD row');+ });++ test('without the base ref: refused under CI, skipped locally', () => {+ const root = repo();+ put(root, { [NOTICE_FILE]: notice('0.60.322.0', 'TBD') });+ commit(root, 'feature');+ git(root, 'update-ref', '-d', 'refs/remotes/origin/master');+ expect(run(root, [], { CI: 'true' }).code).toBe(1);+ const local = run(root);+ expect(local.code).toBe(0);+ expect(local.out).toContain('GBRAIN_CHECK_SKIPPED');+ });++ test('unknown arguments are a usage error', () => {+ expect(run(repo(), ['--nope']).code).toBe(2);+ });+});++describe('release:restamp and the TBD rows', () => {+ test('stampTbdSince gives every TBD row the new version and leaves released rows alone', () => {+ const text = notice('0.60.322.0', 'TBD', 'TBD');+ const stamped = stampTbdSince(text, '0.60.323.0');+ expect(tbdLines(stamped)).toEqual([]);+ expect(stamped).toBe(notice('0.60.322.0', '0.60.323.0', '0.60.323.0'));+ expect(stampTbdSince(stamped, '0.60.324.0')).toBe(stamped);+ expect(BEHAVIOR_NOTICE_FILE).toBe(NOTICE_FILE);+ });++ test("restamp's drift checks run the guard with --stamped", () => {+ expect(DEFAULT_CHECKS.map((c) => c.argv.join(' '))).toContain('bun scripts/check-behavior-since.ts --stamped');+ });+});