Gate Authoring Example
Author a GatePack, freeze a pinned GateBinding, evaluate and validate a GateReport offline, and discover bundle packs
Author a pack, freeze a binding, inspect a report
Use this offline example alongside the gate-pack authoring guide. It exercises the three `gates.aiwg.io/v1alpha1` artifacts with the existing CLI:
| Artifact | Authoring responsibility |
|---|---|
| `GatePack` | Declare metrics, gates, directed thresholds and failure outcomes. |
| `GateBinding` | Preregister full pack pins (authored and composed digests), provider pins, parameters, slice inventory, references, times and ceiling. |
| `GateReport` | Let the evaluator produce evidence, pins, floors, ceilings, decision, time and digest. Retain it with the inputs. |
The example uses synthetic counts from the core `test.proportion/v1` provider, one blocking-slice `count-max` gate and the shipped integrity floor. Clean observations pass the count gate; the diagnostic binding and synthetic upstream both cap the result at HOLD. One observed false-ready event on `blocking` would force ROLLBACK. Missing observations hold. This is an authoring exercise; the seals below are caller assertions over synthetic inputs, not live evidence. For verified held-out studies use the boundary documented at `$AIWG_ROOT/docs/decision/heldout-gate-boundary.md`.
Run the example
Prerequisites: Node.js 24+, Bash, and an AIWG installation with its built CLI. Set the environment variable `AIWG_ROOT` to that installation's absolute root (the directory containing `bin/`, `dist/`, `schemas/` and `agentic/`). The commands below create a unique temporary workspace, including an empty project config and isolated HOME; they leave its path printed for inspection. The example does not opt out of floors or activate bundle providers.
set -eu
: "${AIWG_ROOT:?Set AIWG_ROOT to the absolute AIWG installation root}"
EXAMPLE_DIR=$(node --input-type=module -e 'import {mkdtempSync} from "node:fs"; import {tmpdir} from "node:os"; import {join} from "node:path"; console.log(mkdtempSync(join(tmpdir(), "aiwg-gate-authoring-")))')
export EXAMPLE_DIR
cd "$EXAMPLE_DIR"
export HOME="$EXAMPLE_DIR/home"
export XDG_CONFIG_HOME="$HOME/.config"
node --input-type=module <<'NODE'
import { mkdirSync, writeFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
import { resolve } from 'node:path';
const load = file => import(pathToFileURL(resolve(process.env.AIWG_ROOT, 'dist/src', file)));
const { artifactDigest } = await load('decision/validate.js');
const { showGatePack } = await load('gates/driver.js');
const { sealGateHoldout, sealUpstream } = await load('gates/evaluate.js');
const { proportionProvider: provider } = await load('gates/providers/index.js');
const write = (file, value) => writeFileSync(file, JSON.stringify(value, null, 2) + '\
');
mkdirSync(process.env.HOME, { recursive: true });
mkdirSync('.aiwg');
write('.aiwg/aiwg.config', {});
const pack = {
apiVersion: 'gates.aiwg.io/v1alpha1', kind: 'GatePack',
metadata: { id: 'project:authoring-counter', version: '1.0.0', description: 'Synthetic blocking count example.' },
spec: {
metrics: { 'false-ready': { provider: provider.id, kind: 'proportion' } },
gates: [{
id: 'blocking-events', kind: 'count-max',
metric: { provider: provider.id, name: 'false-ready' },
threshold: { op: 'lte', value: 0 },
scope: { mode: 'listed', slices: ['blocking'] },
direction: 'lower-is-stricter', onFail: 'ROLLBACK',
}],
combine: { rule: 'max-severity' },
},
};
write('counter.gatepack.json', pack);
const pin = ({ id, version, digest, resolvedDigest }) => ({ id, version, digest, resolvedDigest });
const binding = {
apiVersion: pack.apiVersion, kind: 'GateBinding',
metadata: { id: 'authoring-counter/demo', version: '1.0.0', description: 'Synthetic diagnostic binding.' },
spec: {
packs: [
pin(showGatePack(pack.metadata.id, { packDirs: ['counter.gatepack.json'] })),
pin(showGatePack('aiwg:decision-engine/integrity-ceiling')),
],
parameters: {}, slices: ['blocking'], references: [],
metricProviders: [{ id: provider.id, version: provider.version, sourceDigest: provider.sourceDigest }],
ceiling: 'HOLD',
registeredAt: '2026-09-01T00:00:00.000Z', frozenAt: '2026-09-02T00:00:00.000Z',
},
};
write('binding.json', binding);
// Retain this pin before observations exist. Production callers use an independently trusted record.
const trustedDigest = artifactDigest(binding);
writeFileSync('trusted-binding-digest.txt', trustedDigest + '\
');
write('holdout.json', sealGateHoldout({ frozenDigest: trustedDigest, firstAccessedAt: null }));
// No held-out split is declared; a real split requires verified first-access evidence.
write('metrics.json', { providers: { [provider.id]: provider.compute([
{ slice: 'blocking', metric: 'false-ready', event: false },
]) } });
write('upstream.json', sealUpstream({
sample_n: 1, uncertainty: { profile: 'synthetic' }, paired_baseline: { baseline: 'synthetic' },
integrity_mode: 'fresh', fresh_workspace_required: true, fresh_workspace_verified: true,
integrity_state: 'verified', trusted_score_source: 'fresh-workspace',
compromise_labels: [], weak_signal_reason: null,
release_gate: { decision: 'HOLD', reasons: ['synthetic-authoring-example'] },
}));
NODE
aiwg gates validate pack counter.gatepack.json
aiwg gates validate binding binding.json --pack-dir counter.gatepack.json
TRUSTED_BINDING_DIGEST=$(node --input-type=module -e 'import {readFileSync} from "node:fs"; console.log(readFileSync("trusted-binding-digest.txt", "utf8").trim())')
aiwg gates evaluate --binding binding.json --metrics metrics.json \
--holdout holdout.json --upstream upstream.json \
--now 2026-09-03T00:00:00.000Z --trusted-binding-digest "$TRUSTED_BINDING_DIGEST" \
--pack-dir counter.gatepack.json > report.json
aiwg gates validate report report.json
aiwg gates list --namespace project --pack-dir counter.gatepack.json
aiwg gates show project:authoring-counter --pack-dir counter.gatepack.json
printf 'Example workspace: %s\
' "$EXAMPLE_DIR"
All three validations return `valid: true`. `report.json` has `decision: HOLD`, `attestation: offline-cli`, applied floors, a passing `blocking-events` entry, and both upstream and binding ceilings at HOLD. CLI evaluation exits zero when it produces a report, including HOLD or ROLLBACK; inspect `decision` separately. `validate report` checks schema, component ceilings and self-digest. Full evidence verification uses `validateGateReport(report, originalTrustedContext)` to replay evaluation; a self-digest alone does not authenticate the inputs.
Freeze pins before observing results. A new threshold, parameter value or pack version requires a new binding and trusted digest; after holdout access it requires a new study version. Hashes use the existing canonical `artifactDigest` helper, not a raw file hash. Keep authored `digest` and composed `resolvedDigest` distinct when using `extends`. Project floors still take precedence.
Find and contribute packs
The discovery index finds packaged packs; `gates list/show` inspect the evaluation registry. The temporary project file above enters that registry through `--pack-dir`; it is not automatically a packaged discovery entry.
aiwg discover "integrity ceiling" --type gate-pack --limit 5 --format json > discovered-packs.json
aiwg show gate-pack aiwg:decision-engine/integrity-ceiling
aiwg gates list --namespace aiwg
aiwg gates show aiwg:decision-engine/integrity-ceiling
`discovered-packs.json` includes `aiwg:decision-engine/integrity-ceiling` as a `gate-pack` result. Discovery and registration do not activate evaluation.
Extend the existing bundle manifest. In a framework use `frameworkConfig`, in an addon `addonConfig`, and in an extension `extensionConfig`. Merge the following fields into that config block (this is a fragment, not a complete manifest):
{
"entry": { "gatePacks": "gate-packs/" },
"gatePacks": ["counter"]
}
Put `counter.gatepack.yaml`, `.yml` or `.json` directly in `gate-packs/`. Names in `gatePacks` omit the suffix. Keep paths inside the bundle; symlinks, traversal, unknown fields and files over 256 KiB are rejected. Shipped packs use `aiwg:<bundle>/<name>`; standalone `--pack-dir` files and directories must use `project:` IDs. Trusted project-bundle registration can use `framework:`, `addon:` or `extension:` origins. Merely declaring a namespace does not grant it.
Use the existing CI/CD bundle as the packaging model: `agentic/code/frameworks/cicd-complete/manifest.json`, its `gate-packs/` directory, and the mirrored `agentic/code/plugins/cicd-complete/` files. See the CI/CD overview. For rules, declare `enforcedBy: ["<full-pack-id>#<gate-id>"]` as described in rule linkage and coverage. That declaration records coverage; it does not execute or activate a gate.
Prefer the core metric providers. Addon/extension executable providers require the existing review, pinning and project allowlist workflow at `$AIWG_ROOT/docs/decision/gate-providers.md` and remain experimental and default-off. Authoring a pack grants no live-run, promotion or default-activation authority. The operator decision record remains at `$AIWG_ROOT/docs/architecture/adr-first-class-gates.md`.