Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes
garrytan3a08ecd122e8
diff --git a/.github/workflows/scale-tier.yml b/.github/workflows/scale-tier.ymlindex 31578586c6..2c5c2ad874 100644--- a/.github/workflows/scale-tier.yml+++ b/.github/workflows/scale-tier.yml@@ -65,6 +65,7 @@ jobs:steps:- id: dynamic-ciuses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8 # v1 (v0.1.7)+ continue-on-error: truewith:token: ${{ secrets.TRUNK_API_TOKEN }}job-keys: scalediff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex bbbe6cad8b..066a2676fd 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -92,6 +92,7 @@ jobs:steps:- id: dynamic-ciuses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8 # v1 (v0.1.7)+ continue-on-error: truewith:token: ${{ secrets.TRUNK_API_TOKEN }}job-keys: security-regressions,native-locks,persistence-validation,stress-changed-tests@@ -1399,6 +1400,7 @@ jobs:sparse-checkout-cone-mode: false- name: Aggregate the cheap tierenv:+ CHANGES: ${{ needs.changes.result }}GITLEAKS: ${{ needs.gitleaks.result }}SECURITY: ${{ needs.security-regressions.result }}AUDIT: ${{ needs.dependency-audit.result }}diff --git a/docs/ci-event-parity.md b/docs/ci-event-parity.mdindex b058839169..c0621980c7 100644--- a/docs/ci-event-parity.md+++ b/docs/ci-event-parity.md@@ -342,10 +342,10 @@ Measured by hand on 2026-10-26 against master at `b06ac32b` (0.60.465.0) on a 2-## Trunk Dynamic CI-Trunk Dynamic CI (private beta; [docs](https://docs.trunk.io/ci/dynamic-ci)) decides per pull-request push which jobs still need to run, from this repository's own CI history. A `dynamic-ci` job in `test.yml` and in `scale-tier.yml` runs `trunk-io/dynamic-ci` (pinned to v1) with the `TRUNK_API_TOKEN` repository secret and writes one output per gated job.+Trunk Dynamic CI (private beta; [docs](https://docs.trunk.io/ci/dynamic-ci)) decides per pull-request push which jobs still need to run, from this repository's own CI history. A `dynamic-ci` job in `test.yml` and in `scale-tier.yml` runs `trunk-io/dynamic-ci` (pinned to v1) with the `TRUNK_API_TOKEN` repository secret and writes one output per gated job. The step has `continue-on-error: true`, so a Trunk or runner failure leaves the outputs empty and the check green instead of red on the head.- **Gated jobs.** `test.yml`: `security-regressions` (including the Windows and macOS cells), `native-locks`, `persistence-validation` and `stress-changed-tests`. `scale-tier.yml`: `scale`. They were chosen from the seven days before 2026-11-04 as the pull-request jobs that take minutes and nearly always pass. `changes`, `gitleaks`, `dependency-audit`, `verify`, `typecheck`, `semgrep`, the scale `plan` and the aggregates are not gated.- **Form.** A gated job lists `dynamic-ci` in `needs` and its `if` starts `!cancelled() && needs.dynamic-ci.outputs.<job key> != 'false' &&`, followed by `needs.<other>.result == 'success'` for every other job it needs and then its original condition. `!cancelled()` keeps a skipped or failed filter from skipping the job, `!= 'false'` makes an empty output (no token, a Trunk outage, no verdict yet) run it, and the `result == 'success'` checks keep what the implicit `success()` did before.- **Events.** The filter's `if` is `github.event_name == 'pull_request'`. On a push, merge-queue entry, schedule or dispatch (the full-ci run) it is skipped, every output is empty, and every gated job runs exactly as before, so `full-suite`, `e2e-full-suite` and the ci-reuse evidence are unchanged. `e2e.yml` has no pull-request trigger and no filter.-- **Modes.** A repository starts in Learning mode: Trunk records a verdict for every gated job and skips nothing. Enforcement is the Mode dropdown in the repository's row on the Dynamic CI settings page in the Trunk web app (app.trunk.io), not this file; Learning mode can also enforce only for listed engineers or labels (the Allow list column). Under enforcement `cheap-tier` accepts a gated lane that skipped only when its verdict was exactly `'false'` (`scripts/ci-cheap-tier.sh`). `stress-changed-tests` repeats changed tests only on pull requests (no full run repeats them), so a skip there removes that check for the push.-- **Guard.** `scripts/check-dynamic-ci.ts` (in `bun run verify`) fails when a filter job can run on another event, sits in a workflow without a pull-request trigger, is not SHA-pinned, or exports outputs that differ from its `job-keys`; when a gated job's `if` lacks the form above; and when a merge or release aggregate is gated.+- **Modes.** A repository starts in Learning mode: Trunk records a verdict for every gated job and skips nothing. Enforcement is the Mode dropdown in the repository's row on the Dynamic CI settings page in the Trunk web app (app.trunk.io), not this file; Learning mode can also enforce only for listed engineers or labels (the Allow list column). Under enforcement `cheap-tier` accepts a gated lane that skipped only when its verdict was exactly `'false'` and `changes` succeeded (`scripts/ci-cheap-tier.sh`). Before enforcing, weigh three gaps. `stress-changed-tests` repeats changed tests only on pull requests (no full run repeats them), so a skip there removes that check for the push. A `'false'` verdict also skips `scale` on a pull request that carries the `scale-tier` label, since Trunk does not read labels. And Trunk learns false skips from its own merge queue; gbrain's backstop is the full-ci dispatch, which skips the filter, so a gated lane that a pull request skipped and full-ci then failed never reaches Trunk as a false skip. Pin a job to run on the Configuration tab when a gap matters.+- **Guard.** `scripts/check-dynamic-ci.ts` (in `bun run verify`) fails when a filter job can run on another event, sits in a workflow without a pull-request trigger, is not SHA-pinned, lacks `continue-on-error: true`, or exports outputs that differ from its `job-keys`; when a gated job's `if` lacks the form above or has a top-level `||` after it; and when a merge or release aggregate is gated.diff --git a/scripts/check-dynamic-ci.ts b/scripts/check-dynamic-ci.tsindex 388da23e38..66067502fc 100644--- a/scripts/check-dynamic-ci.ts+++ b/scripts/check-dynamic-ci.ts@@ -13,12 +13,13 @@* `if: github.event_name == 'pull_request'`, in a workflow that has a* pull_request trigger, with the action pinned to a commit SHA, the token* from secrets.TRUNK_API_TOKEN, and `job-keys` naming exactly the jobs- * its `outputs` re-export as `steps.<id>.outputs.<key>`;+ * its `outputs` re-export as `steps.<id>.outputs.<key>`, and+ * `continue-on-error: true` on that step so a failed step reads as "run";* - a gated job (one whose key is a filter output and that needs the filter)* has an `if` that starts `!cancelled() && needs.<filter>.outputs.<key>* != 'false' &&`, requires `needs.<other>.result == 'success'` for each- * other job it needs (what the implicit success() checked before), and- * uses no other status function;+ * other job it needs (what the implicit success() checked before), uses+ * no other status function, and has no top-level || after the prefix;* - every other job that needs a filter only reads its outputs: its `if`* starts with always(), and it is not a filter output;* - every filter output is a job that needs that filter, and no merge or@@ -32,7 +33,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';import { join } from 'node:path';import { load } from 'js-yaml';-type Step = { id?: string; uses?: string; with?: Record<string, unknown> };+type Step = { id?: string; uses?: string; with?: Record<string, unknown>; 'continue-on-error'?: unknown };type Job = { if?: unknown; needs?: string | string[]; outputs?: Record<string, unknown>; steps?: Step[] };type Workflow = { on?: unknown; jobs?: Record<string, Job> };@@ -45,6 +46,20 @@ const needsOf = (job: Job) => (job.needs === undefined ? [] : Array.isArray(job.const hasPullRequest = (on: unknown) =>on === 'pull_request' || (Array.isArray(on) && on.includes('pull_request')) || (typeof on === 'object' && on !== null && 'pull_request' in on);+function topLevelOr(expression: string): boolean {+ let depth = 0;+ let quoted = false;+ for (let i = 0; i < expression.length; i++) {+ const c = expression[i];+ if (c === "'") quoted = !quoted;+ else if (quoted) continue;+ else if (c === '(') depth++;+ else if (c === ')') depth--;+ else if (depth === 0 && c === '|' && expression[i + 1] === '|') return true;+ }+ return false;+}+export function checkWorkflow(file: string, doc: Workflow): string[] {const problems: string[] = [];const jobs = doc.jobs ?? {};@@ -57,6 +72,7 @@ export function checkWorkflow(file: string, doc: Workflow): string[] {if (!hasPullRequest(doc.on)) problems.push(`${at}: the workflow has no pull_request trigger, so it carries merge or release evidence and must not filter jobs`);if (!/^trunk-io\/dynamic-ci@[0-9a-f]{40}$/.test(step.uses!)) problems.push(`${at}: pin ${step.uses} to a full commit SHA`);if (String(step.with?.token ?? '').trim() !== '${{ secrets.TRUNK_API_TOKEN }}') problems.push(`${at}: the token must be \${{ secrets.TRUNK_API_TOKEN }}`);+ if (step['continue-on-error'] !== true) problems.push(`${at}: the dynamic-ci step needs continue-on-error: true, so a Trunk or runner failure leaves the outputs empty (run) instead of a red check on the head`);if (!step.id) { problems.push(`${at}: the dynamic-ci step needs an id`); continue; }const outputs = Object.keys(job.outputs ?? {}).sort();const keys = String(step.with?.['job-keys'] ?? '').split(',').map(k => k.trim()).filter(Boolean).sort();@@ -90,6 +106,7 @@ export function checkWorkflow(file: string, doc: Workflow): string[] {}const rest = condition.slice(prefix.length);if (/\b(?:always|success|failure|cancelled)\(\)/.test(rest)) problems.push(`${at}: no other status function may follow the gate prefix`);+ if (topLevelOr(rest)) problems.push(`${at}: wrap the condition after the gate prefix in parentheses; a top-level || would run the job past a 'false' verdict or a failed need`);for (const other of needs.filter(n => n !== filter)) {if (!rest.includes(`needs.${other}.result == 'success'`)) problems.push(`${at}: add needs.${other}.result == 'success' after the gate prefix; !cancelled() drops the implicit success() that kept the job from running when ${other} failed`);}diff --git a/scripts/ci-cheap-tier.sh b/scripts/ci-cheap-tier.shindex 433530eba0..960b44d6df 100755--- a/scripts/ci-cheap-tier.sh+++ b/scripts/ci-cheap-tier.sh@@ -1,6 +1,6 @@#!/usr/bin/env bash# test.yml cheap-tier aggregator (docs/ci-event-parity.md#full-ci-on-pull-requests).-# Inputs: job results in GITLEAKS SECURITY AUDIT VERIFY TYPECHECK STRESS NATIVE+# Inputs: job results in CHANGES GITLEAKS SECURITY AUDIT VERIFY TYPECHECK STRESS NATIVE# PERSISTENCE, and the selectors NATIVE_SCOPE and CONVERGENCE.# Every cheap lane must succeed. The native and persistence lanes may be# skipped only when their selector left them out (native scope smoke,@@ -16,7 +16,7 @@ trunk_skipped() {[ "$1" = skipped ] && [ "$2" = false ] || return 1echo " skipped by Trunk Dynamic CI (verdict false)"}-for row in "gitleaks|${GITLEAKS:-}|" "security-regressions|${SECURITY:-}|${DCI_SECURITY:-}" "dependency-audit|${AUDIT:-}|" \+for row in "changes|${CHANGES:-}|" "gitleaks|${GITLEAKS:-}|" "security-regressions|${SECURITY:-}|${DCI_SECURITY:-}" "dependency-audit|${AUDIT:-}|" \"verify|${VERIFY:-}|" "typecheck|${TYPECHECK:-}|" "stress-changed-tests|${STRESS:-}|${DCI_STRESS:-}"; doIFS='|' read -r name result verdict <<< "$row"echo "$name=$result"diff --git a/scripts/guards-manifest.tsv b/scripts/guards-manifest.tsvindex b8f6756e90..7374156ab0 100644--- a/scripts/guards-manifest.tsv+++ b/scripts/guards-manifest.tsv@@ -105,4 +105,4 @@ check-write-gate-regex.ts scanner yes #5575 ENG-16: write-gate detector patternscheck-chunk-visibility.ts scanner yes Wave B segmented storage (spec 4.2, TS AST): every FROM/JOIN content_chunks statement in src uses chunkVisibleFilter (or its generation siblings) or carries -- chunk-visibility-ok: <reason>; per-file uncovered counts in scripts/chunk-visibility-baseline.tsv only shrink; --prune lowers rowscheck-file-url-pathname.sh scanner yes #6845: a file URL .pathname in test/ keeps %20 escapes; GBRAIN_GUARD_ROOT seam; skips test/fixtures/guards/check-derived-census.ts scanner yes GBRA-161: per-file soft-delete sites (softDeletePage(s), retireDerivedPages(InTransaction), UPDATE pages ... deleted_at =) need a reviewed row with a class in docs/architecture/derived-census.tsv; growth, stale (ceiling above count) and unknown classes fail; --prune lowers ceilings-check-dynamic-ci.ts scanner yes Trunk Dynamic CI (docs/ci-event-parity.md#trunk-dynamic-ci): a trunk-io/dynamic-ci filter job runs only on pull_request in a workflow with that trigger, SHA-pinned, token from secrets.TRUNK_API_TOKEN, job-keys equal to its outputs; a gated job starts its if with !cancelled() && needs.<filter>.outputs.<key> != 'false' and checks each other need succeeded; merge and release aggregates are never gated; GBRAIN_GUARD_ROOT seam; bad-* fixtures cover a filter on every event and a dropped other-needs check+check-dynamic-ci.ts scanner yes Trunk Dynamic CI (docs/ci-event-parity.md#trunk-dynamic-ci): a trunk-io/dynamic-ci filter job runs only on pull_request in a workflow with that trigger, SHA-pinned, token from secrets.TRUNK_API_TOKEN, job-keys equal to its outputs; a gated job starts its if with !cancelled() && needs.<filter>.outputs.<key> != 'false' and checks each other need succeeded; merge and release aggregates are never gated; GBRAIN_GUARD_ROOT seam; bad-* fixtures cover a filter on every event, a dropped other-needs check and a top-level || past the gate; the step must carry continue-on-error: truediff --git a/test/fixtures/guards/check-dynamic-ci.ts/bad-every-event/.github/workflows/ci.yml b/test/fixtures/guards/check-dynamic-ci.ts/bad-every-event/.github/workflows/ci.ymlindex eb9fdb2b84..686c119bd8 100644--- a/test/fixtures/guards/check-dynamic-ci.ts/bad-every-event/.github/workflows/ci.yml+++ b/test/fixtures/guards/check-dynamic-ci.ts/bad-every-event/.github/workflows/ci.yml@@ -11,6 +11,7 @@ jobs:steps:- id: dynamic-ciuses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8+ continue-on-error: truewith:token: ${{ secrets.TRUNK_API_TOKEN }}job-keys: unitdiff --git a/test/fixtures/guards/check-dynamic-ci.ts/bad-other-needs/.github/workflows/ci.yml b/test/fixtures/guards/check-dynamic-ci.ts/bad-other-needs/.github/workflows/ci.ymlindex 72e5d89f42..6cbc8a8598 100644--- a/test/fixtures/guards/check-dynamic-ci.ts/bad-other-needs/.github/workflows/ci.yml+++ b/test/fixtures/guards/check-dynamic-ci.ts/bad-other-needs/.github/workflows/ci.yml@@ -12,6 +12,7 @@ jobs:steps:- id: dynamic-ciuses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8+ continue-on-error: truewith:token: ${{ secrets.TRUNK_API_TOKEN }}job-keys: unitdiff --git a/test/fixtures/guards/check-dynamic-ci.ts/bad-top-level-or/.github/workflows/ci.yml b/test/fixtures/guards/check-dynamic-ci.ts/bad-top-level-or/.github/workflows/ci.ymlnew file mode 100644index 0000000000..12b00df0af--- /dev/null+++ b/test/fixtures/guards/check-dynamic-ci.ts/bad-top-level-or/.github/workflows/ci.yml@@ -0,0 +1,28 @@+name: CI+on:+ pull_request: {}+ push:+ branches: [master]+jobs:+ dynamic-ci:+ if: github.event_name == 'pull_request'+ runs-on: ubuntu-latest+ outputs:+ unit: ${{ steps.dynamic-ci.outputs.unit }}+ steps:+ - id: dynamic-ci+ uses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8+ continue-on-error: true+ with:+ token: ${{ secrets.TRUNK_API_TOKEN }}+ job-keys: unit+ plan:+ runs-on: ubuntu-latest+ steps:+ - run: echo plan+ unit:+ needs: [plan, dynamic-ci]+ if: ${{ !cancelled() && needs.dynamic-ci.outputs.unit != 'false' && needs.plan.result == 'success' || github.event_name == 'push' }}+ runs-on: ubuntu-latest+ steps:+ - run: echo unitdiff --git a/test/fixtures/guards/check-dynamic-ci.ts/bad/.github/workflows/ci.yml b/test/fixtures/guards/check-dynamic-ci.ts/bad/.github/workflows/ci.ymlindex 0ac9edca91..554b35894a 100644--- a/test/fixtures/guards/check-dynamic-ci.ts/bad/.github/workflows/ci.yml+++ b/test/fixtures/guards/check-dynamic-ci.ts/bad/.github/workflows/ci.yml@@ -12,6 +12,7 @@ jobs:steps:- id: dynamic-ciuses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8+ continue-on-error: truewith:token: ${{ secrets.TRUNK_API_TOKEN }}job-keys: unitdiff --git a/test/fixtures/guards/check-dynamic-ci.ts/good/.github/workflows/ci.yml b/test/fixtures/guards/check-dynamic-ci.ts/good/.github/workflows/ci.ymlindex 8980d3724f..807a225fa7 100644--- a/test/fixtures/guards/check-dynamic-ci.ts/good/.github/workflows/ci.yml+++ b/test/fixtures/guards/check-dynamic-ci.ts/good/.github/workflows/ci.yml@@ -12,6 +12,7 @@ jobs:steps:- id: dynamic-ciuses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8+ continue-on-error: truewith:token: ${{ secrets.TRUNK_API_TOKEN }}job-keys: unitdiff --git a/test/scripts/check-dynamic-ci.test.ts b/test/scripts/check-dynamic-ci.test.tsindex c8b07ecc68..50cf7b43a4 100644--- a/test/scripts/check-dynamic-ci.test.ts+++ b/test/scripts/check-dynamic-ci.test.ts@@ -39,6 +39,10 @@ describe('check-dynamic-ci.ts', () => {['a gated job adds always()', doc => { doc.jobs['security-regressions']!.if = doc.jobs['security-regressions']!.if.replace("!= 'false' && ", "!= 'false' && always() && "); }, /no other status function/],['a gated job forgets to need the filter', doc => { doc.jobs['security-regressions']!.needs = []; }, /security-regressions: a gated job must list dynamic-ci in needs/],['an aggregate is gated', doc => { doc.jobs['dynamic-ci']!.outputs['full-suite'] = '${{ steps.dynamic-ci.outputs.full-suite }}'; filterStep(doc).with['job-keys'] += ',full-suite'; }, /full-suite: merge and release aggregates are never gated/],+ ['the dynamic-ci step can fail the job', doc => { delete filterStep(doc)['continue-on-error']; }, /needs continue-on-error: true/],+ ['the dynamic-ci step has no id', doc => { delete filterStep(doc).id; }, /the dynamic-ci step needs an id/],+ ['an output names no job', doc => { doc.jobs['dynamic-ci']!.outputs.ghost = '${{ steps.dynamic-ci.outputs.ghost }}'; filterStep(doc).with['job-keys'] += ',ghost'; }, /output ghost names no job/],+ ['a gated job ORs past the gate', doc => { doc.jobs['native-locks']!.if = doc.jobs['native-locks']!.if.replace(/ \}\}$/, " || github.event_name == 'push' }}"); }, /native-locks: wrap the condition after the gate prefix in parentheses/],['a non-aggregate job reads the verdicts', doc => { doc.jobs.verify!.needs = ['dynamic-ci']; }, /verify: needs dynamic-ci but is not one of its outputs/],])('fails when %s', (_, mutate, message) => {const problems = broken(mutate);diff --git a/test/scripts/full-ci-workflow.test.ts b/test/scripts/full-ci-workflow.test.tsindex 290c23066a..96496aab1c 100644--- a/test/scripts/full-ci-workflow.test.ts+++ b/test/scripts/full-ci-workflow.test.ts@@ -220,7 +220,7 @@ describe('full CI on pull requests', () => {});describe('cheap-tier aggregator', () => {- const green = { GITLEAKS: 'success', SECURITY: 'success', AUDIT: 'success', VERIFY: 'success', TYPECHECK: 'success', STRESS: 'success',+ const green = { CHANGES: 'success', GITLEAKS: 'success', SECURITY: 'success', AUDIT: 'success', VERIFY: 'success', TYPECHECK: 'success', STRESS: 'success',NATIVE: 'skipped', NATIVE_SCOPE: 'smoke', PERSISTENCE: 'skipped', CONVERGENCE: 'skip' };const aggregate = (env: Record<string, string>) => {const dir = mkdtempSync(join(tmpdir(), 'gbrain-cheap-tier-'));@@ -241,7 +241,7 @@ describe('full CI on pull requests', () => {expect(aggregate({ ...green, NATIVE: 'success', NATIVE_SCOPE: 'primary', PERSISTENCE: 'success', CONVERGENCE: 'run' }).status).toBe(0);});- test.each(['GITLEAKS', 'SECURITY', 'AUDIT', 'VERIFY', 'TYPECHECK', 'STRESS'])('%s not succeeding fails the tier', lane => {+ test.each(['CHANGES', 'GITLEAKS', 'SECURITY', 'AUDIT', 'VERIFY', 'TYPECHECK', 'STRESS'])('%s not succeeding fails the tier', lane => {for (const result of ['failure', 'cancelled', 'skipped', '']) {expect(aggregate({ ...green, [lane]: result }).status, `${lane}=${result}`).toBe(1);}@@ -262,6 +262,11 @@ describe('full CI on pull requests', () => {for (const other of ['', 'true']) expect(aggregate({ ...green, ...selected, [lane]: 'skipped', [verdict]: other }).status, other).toBe(1);expect(aggregate({ ...green, ...selected, [lane]: 'failure', [verdict]: 'false' }).status).toBe(1);});++ test('a failed changes job fails the tier even when Trunk said false for every gated lane', () => {+ expect(aggregate({ ...green, CHANGES: 'failure', NATIVE: 'skipped', NATIVE_SCOPE: '', PERSISTENCE: 'skipped', CONVERGENCE: '',+ DCI_NATIVE: 'false', DCI_PERSISTENCE: 'false', SECURITY: 'skipped', DCI_SECURITY: 'false', STRESS: 'skipped', DCI_STRESS: 'false' }).status).toBe(1);+ });});});