diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index e9f36a5..cd2dd3a 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -6,14 +6,14 @@ }, "metadata": { "description": "Five AI specialists that bring user-centred design roles into government digital delivery teams – service design, content and interaction design, delivery, development and cyber security. For any government, anchored to a country-agnostic service standard baseline, the GOV.UK Design Principles and the GDS Way, with country profiles for local standards and design systems.", - "version": "0.1.1" + "version": "0.8.0" }, "plugins": [ { "name": "xstack", "source": "./", "description": "Five UCD specialists as AI team members for government digital teams. Turn a brief into testable prototypes, iterate from research, assess against your country's service standard.", - "version": "0.1.1", + "version": "0.8.0", "category": "service-design", "keywords": [ "government", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 70473e3..ac07e8f 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "xstack", - "version": "0.2.0", + "version": "0.8.0", "description": "Five AI specialists that bring user-centred design roles into government digital delivery teams – service design, content and interaction design, delivery, development and cyber security. For any government, anchored to a country-agnostic service standard baseline, the GOV.UK Design Principles and the GDS Way, with country profiles for local standards and design systems.", "author": { "name": "Public Digital", diff --git a/.github/workflows/constraints.yml b/.github/workflows/constraints.yml new file mode 100644 index 0000000..d0b7484 --- /dev/null +++ b/.github/workflows/constraints.yml @@ -0,0 +1,88 @@ +name: Constraints + +# The backstop for xstack's constraint hooks. The hooks only see the Write and +# Edit tools; this runs on every pull request, whoever or whatever made the change. + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: constraints-${{ github.ref }} + cancel-in-progress: true + +jobs: + runner: + name: Runner and hooks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Test the runner and the hooks + run: node --test scripts/xstack-check.test.mjs + - name: Vendored copies match the source + run: | + for dir in $(git ls-files '*/.xstack/constraints.json' | xargs -n1 dirname | xargs -n1 dirname); do + node scripts/xstack-check.mjs --vendor --root "$dir" + done + git diff --exit-code -- '*/.xstack/vendor/*' || { + echo "::error::A vendored xstack-check is out of date. Run: node scripts/xstack-check.mjs --vendor --root " + exit 1 + } + + example: + name: Example service (ci stage) + runs-on: ubuntu-latest + timeout-minutes: 30 + defaults: + run: + working-directory: examples/production-renew-medical-licence + env: + GITLEAKS_VERSION: 8.21.2 + GITLEAKS_SHA256: 5bc41815076e6ed6ef8fbecc9d9b75bcae31f39029ceb55da08086315316e3ba + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + cache-dependency-path: examples/production-renew-medical-licence/package-lock.json + - name: Install gitleaks + working-directory: ${{ runner.temp }} + run: | + curl -sSfL -o gitleaks.tar.gz "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" + echo "${GITLEAKS_SHA256} gitleaks.tar.gz" | sha256sum --check + tar -xzf gitleaks.tar.gz gitleaks + sudo install gitleaks /usr/local/bin/gitleaks + - name: Install dependencies + run: npm ci + - name: Install browsers + run: npx playwright install --with-deps + - name: Start a server for the header check + run: | + PORT=8081 ./scripts/serve.sh & + for i in $(seq 1 20); do curl -sf -o /dev/null http://localhost:8081/ && exit 0; sleep 1; done + echo "::error::The local server did not start"; exit 1 + - name: Run every constraint + env: + BASE_URL: http://localhost:8081 + run: node .xstack/vendor/xstack-check.mjs --stage ci + - name: Add the evidence to the run summary + if: always() + run: node .xstack/vendor/xstack-check.mjs --stage stop --format md --no-report >> "$GITHUB_STEP_SUMMARY" || true + - name: Keep the reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: constraint-reports + path: | + examples/production-renew-medical-licence/.xstack/check-report.json + examples/production-renew-medical-licence/reports/ + include-hidden-files: true + if-no-files-found: ignore diff --git a/.gitignore b/.gitignore index 4cea2de..dcdfa14 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,11 @@ coverage/ # Local scratch scratch/ notes-private/ + +# xstack constraint check output (regenerated on every run) +**/.xstack/check-report.json + +# Playwright output +test-results/ +playwright-report/ +reports/ diff --git a/AGENTS.md b/AGENTS.md index aef603d..b4ab9a9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -85,6 +85,8 @@ This file is the canonical roster. For the full definition of any agent, read th **Owns:** Right technology, Open platforms and standards, Works first time (with the service designer), Measuring performance (with the delivery manager). Supports Sustainable and reliable and Whole problem. +**Tools:** has a shell, to run the constraint checks and the tests it writes. + **Default deliverables:** clickable prototypes, production code, architecture decision records, runbooks, README and developer setup, technical-readiness reports. **Skills it calls into:** `xstack:brief-to-prototypes`, `xstack:build-for-production`, `xstack:government-design-systems` (via `/xstack:design-system`), `xstack:government-dpi` (via `/xstack:dpi`), `frontend-design:design-from-scratch`, `design:design-system`, plus any house-style skills listed in the profile's Related skills section. @@ -108,9 +110,11 @@ This file is the canonical roster. For the full definition of any agent, read th **Owns:** Trust, security and privacy. Supports Inclusion (security mustn't lock out disabled citizens), Right technology, Sustainable and reliable, Working in the open. +**Tools:** has a shell, to run the constraint checks and the scanners. + **Default deliverables:** threat models, data inventories, privacy notices, DPIAs, incident runbooks, security testing plans, phase-gate security readiness reports. -**Skills it calls into:** none specific (cyber work is mostly bespoke per service; the agent reaches for STRIDE / LINDDUN frames documented in its own file). +**Skills it calls into:** none specific (cyber work is mostly bespoke per service; the agent reaches for STRIDE / LINDDUN frames documented in its own file). Turns each threat-model control into a constraint that xstack checks – see `constraints/README.md`. **Triggers:** threat model, security review, pen test, privacy, data protection, incident, secure by design, PII, vulnerability, encryption, auth. diff --git a/CHANGELOG.md b/CHANGELOG.md index 12880c5..23355f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to xstack will be recorded here. Format inspired by [Keep a ## [Unreleased] +## [0.8.0] – 2026-11-19 + ### Changed - **xstack now works for any government** – the agents, skills and commands no longer assume Barbados. xstack brings user-centred design roles into government digital delivery teams as AI team members, especially for teams in regions that can't easily staff them @@ -18,6 +20,18 @@ All notable changes to xstack will be recorded here. Format inspired by [Keep a ### Added +- **Constraints** – rules a production service must meet, written so a machine checks them, and enforced by xstack instead of left to instructions. See `constraints/README.md` + - A service opts in with `.xstack/constraints.json`. It extends the baseline in `constraints/baseline.json` (secrets, inline script and inline styles, POST for uploads, page landmarks, alt text, dead links, inline styles, prototype chrome, dependency checks) and a profile layer where there is one. Barbados and Kestria each have one (`profiles//constraints.json`), and `profiles/_template/constraints.json` is the starting point for another country + - `scripts/xstack-check.mjs` runs them at three stages – `write`, `stop` and `ci` – and reports PASS, FAIL, WAIVED or NOT RUN. It has no dependencies, and `--vendor` copies it into a service for CI + - Plugin hooks in `hooks/`: a write that breaks a constraint is refused, a change to the constraints file or other protected path needs a person's approval, and an agent cannot finish while a "must" constraint fails + - CI: `.github/workflows/constraints.yml` tests the runner and hooks and runs the `ci` stage on the example. `constraints/ci/github-actions.yml` is the same job for a service to copy + - The developer and cyber-engineer agents now have a shell, so they run the checks and tests instead of describing them. `hooks/guard-bash.mjs` asks a person before a shell command changes a protected path + - The Kestria layer has ten rules: the fictional-country notice, GovKestria markup and tokens, the reserved phone numbers and domains, the language switcher, page weight, and no home-made sign-in or account fields. The GovKestria starter page no longer uses a `style` attribute + - Relaxing a constraint takes a waiver with a reason, an approver and an expiry date + - `/xstack:productionise` now writes the constraints file and builds PRODUCTION-READINESS.md from the check results, and no longer generates its own `audit.sh`. `/xstack:threat-model` turns each control into a drafted constraint + - The medical-licence production example is retrofitted. The shipped checks failed two things its generated audit had passed: a file upload sent by GET, and 50 links to pages that did not exist. Both are fixed – the upload uses POST and the ten missing pages are built + +- **`/xstack:help`** and the `help` skill – a starting point for anyone new to xstack. It shows the staircase, an interactive page of the five steps from first conversation to a live service, with every skill and command and what comes before and after each one. Then it asks where the team is and gives the one thing to run next, in the name that works in Claude Code or in the Claude app and Cowork. The page lives in `skills/help/assets/staircase.html` - **`/xstack:form-to-spec`** and the `form-to-spec` skill – a new entry point, **form → spec → build**. Most government services already exist as a paper or PDF form. The skill turns one – fillable PDF, flat PDF, scan, photo or Word document – into a `form-spec.md` that `/xstack:build` takes as its brief - Keeps every item with the form's own numbering, groups items into sections a citizen would recognise, and gives each a digital treatment: ask (with the component), lookup, lookup opportunity, conditional, add-another, government already holds this, drop or challenge, or back office - Uses only the lookups the country profile lists. Anything government plausibly holds but the profile doesn't cover becomes a lookup opportunity, never an assumed lookup diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0ff41a..0b8c3d9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,9 @@ xstack/ ├── commands/ one .md per slash command, frontmatter + body ├── skills/ one folder per skill, with SKILL.md ├── references/ one .md per reference, the canonical, country-agnostic xstack view +├── constraints/ the baseline constraints every production build must meet, and how they work +├── hooks/ plugin hooks that enforce constraints when an agent writes or stops +├── scripts/ xstack-check, the constraint runner └── profiles/ one folder per country profile, plus _template/ ``` @@ -68,6 +71,7 @@ Don't guess facts about a government. Only include what you can point to. - [ ] If you've added an agent: README roster updated, AGENTS.md updated, plugin manifest updated - [ ] If you've added a skill: SKILL.md frontmatter present, agents that should call it know about it - [ ] If you've added a command: README command table updated, frontmatter present +- [ ] If you've added, renamed or removed a skill or command: the staircase in `skills/help/assets/staircase.html` updated - [ ] CHANGELOG.md updated under the next version ## What we won't accept diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md index 1b3b38b..33a015b 100644 --- a/GETTING-STARTED.md +++ b/GETTING-STARTED.md @@ -10,6 +10,10 @@ Upload `xstack.zip` via **Customize → Plugins → upload a custom plugin file* > **If `/` invocations fail with "Unknown command" (even for valid skills):** there's a known Cowork bug where the slash-command resolver breaks — skills appear in the `/` menu but won't run, and even the built-in `/feedback` fails. When that happens, **trigger skills by natural language instead.** Don't type the slash name; just describe what you want and Claude picks the right skill from its description. For example, instead of `/discovery-kit`, write: *"Using xstack, scope a discovery for … — give me the problem statement, stakeholder map, research plan, and interview guide."* Fully quitting and reopening the app or starting a fresh conversation sometimes clears it. +## Not sure where to start? + +Run **`/help`** from the xstack skills, or ask *"How do I use xstack?"*. It shows the staircase – one interactive page with every step from first conversation to a live service. Tap any skill to see what comes before it and what it leads to. Then it asks where you are and tells you the one thing to run next. + ## Set up your country profile Do this once per project, before your first real piece of work. A country profile tells xstack about your government: its service standard, design system, shared platforms, terms and data formats. diff --git a/README.md b/README.md index 3c36244..cd78840 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ xstack/ │ ├── service-standard-assessment/ │ ├── plain-language-check/ │ ├── weeknote/ +│ ├── help/ start here – shows the staircase and tells you what to run next │ ├── discovery-kit/ │ ├── research-coach/ router + mentor across the research cycle │ ├── research-planning/ objectives first, then the discussion guide @@ -111,6 +112,9 @@ xstack/ │ ├── page-composition/ │ ├── token-cross-check/ │ └── show-the-thing/ +├── constraints/ rules a production build must meet, checked by machine +├── hooks/ plugin hooks that enforce the constraints +├── scripts/ xstack-check, the constraint runner ├── references/ the canonical, country-agnostic knowledge base │ ├── service-standard-baseline.md the 14 themes │ ├── govuk-design-principles.md @@ -136,6 +140,8 @@ Run `/xstack:profile` to set one up for your project. It writes `.xstack/profile ## New to xstack? +Run `/xstack:help`, or ask *"How do I use xstack?"*. It shows the staircase – one interactive page with every step from first conversation to a live service – then asks where you are and tells you what to run next. + Read **[MANUAL.md](./MANUAL.md)** – the single onboarding guide for new colleagues, partner departments, and vendor teams. About two hours to read and walk the worked example, after which you'll know which command to run, which agent to ask, and what good looks like at each phase. ## Day-to-day usage @@ -190,6 +196,7 @@ If you're not sure, ask the **delivery manager** first – they'll route you. | You want to… | Run | Hands off to | |---|---|---| +| Find out where to start | `/xstack:help` | help skill | | Set up your country profile | `/xstack:profile` | delivery-manager | | Use your government's design system | `/xstack:design-system` | developer | | Sign people in, pull what government knows and take payments | `/xstack:dpi` | developer | diff --git a/agents/cyber-engineer.md b/agents/cyber-engineer.md index 80dc5d9..c0e768f 100644 --- a/agents/cyber-engineer.md +++ b/agents/cyber-engineer.md @@ -1,7 +1,7 @@ --- name: cyber-engineer description: The Cybersecurity Engineer. Use when threat modelling a service, reviewing privacy, writing a privacy notice, planning a pen test, responding to an incident, hardening infrastructure, or assessing the service against the trust, security and privacy parts of the service standard. Triggers on "threat model", "security review", "pen test", "privacy", "data protection", "incident", "secure by design", "PII", "vulnerability", "harden", "encryption", "auth", "identity platform". -tools: Read, Write, Edit, Glob, Grep, WebSearch, WebFetch +tools: Read, Write, Edit, Glob, Grep, Bash, WebSearch, WebFetch model: sonnet --- @@ -139,6 +139,18 @@ When you say no, you say no with a reason and an alternative. --- +## Running the checks + +You have a shell. A control that nothing checks is a hope, so check it. + +- **Run the constraints.** In a folder with `.xstack/constraints.json`: `node .xstack/vendor/xstack-check.mjs --stage ci`. Read `constraints/README.md` for the format. +- **Run the scanners the service has:** the secret scan, the dependency audit, the header check. Review as the adversary – you did not write this code, and your job is to find what its author missed. +- **Report evidence, not opinion.** Quote the result and the constraint ids. If a tool is missing, say NOT RUN. A rating of Met needs a passing check behind it. +- **Never loosen a control to get a pass.** Do not use the shell to change `.xstack/constraints.json`, `.xstack/vendor/`, the security tests, or any path the service lists as protected. Draft new constraints for a person to approve. Only a person adds a waiver. +- **Stay inside the project, and stay passive.** Read and test what is in the repository and on localhost. No scanning or probing of any system the team has not put in scope in writing. + +--- + ## Iron laws 1. **Collect less.** Personal data the service doesn't have can't be lost. Trust, security and privacy. diff --git a/agents/developer.md b/agents/developer.md index 6d084cc..f8b2401 100644 --- a/agents/developer.md +++ b/agents/developer.md @@ -1,7 +1,7 @@ --- name: developer description: The Developer. Use when choosing a technology, building a prototype or production service, integrating with the national identity platform or other shared platforms, wiring up analytics, or making architecture decisions. Triggers on "build this", "what stack should we use", "integrate with", "deploy", "infrastructure", "analytics", "API", "identity platform", "payments", "design system", "design system component", "performance". -tools: Read, Write, Edit, Glob, Grep, WebSearch, WebFetch +tools: Read, Write, Edit, Glob, Grep, Bash, WebSearch, WebFetch model: sonnet --- @@ -148,6 +148,18 @@ You write British English. You favour n-dashes over m-dashes. --- +## Running the checks + +You have a shell. Use it to prove your work, not to describe what would happen. + +- **Run the constraints before you say something is done.** In a folder with `.xstack/constraints.json`: `node .xstack/vendor/xstack-check.mjs --stage stop`, and `--stage ci` when the tools are installed. Read `constraints/README.md` for the format. +- **Run the tests you write.** `npm ci`, then the suite. A test that has never run is not evidence. +- **Report what happened.** Quote the result – how many passed, which constraint ids failed. If a tool is missing, say NOT RUN. Never write "passes" for something you did not run. +- **Fix the code, not the check.** Do not use the shell to change `.xstack/constraints.json`, `.xstack/vendor/`, or any path the service lists as protected, and do not delete or skip a failing test. If a constraint is wrong or cannot be met, stop and tell the user which one and why. Only a person adds a waiver. +- **Stay inside the project.** No installing global tools, no pushing, no deploying, and nothing destructive, unless the user asked for it. + +--- + ## Iron laws 1. **Reuse before rebuild.** Before writing any code, check whether the digital team, another department, or a Digital Public Good already covers the need. Open platforms and standards, Principle 2. diff --git a/commands/productionise.md b/commands/productionise.md index a6f491c..69df0d6 100644 --- a/commands/productionise.md +++ b/commands/productionise.md @@ -20,10 +20,12 @@ Once you have the context, the skill produces (in a `production-[service-slug]/` 1. **Per-page HTML files** with proper URLs, real navigation, the design system's published stylesheet linked (from the profile, or as the team confirms), the assumptions panel and mock markers stripped 2. **The test suite** – Playwright E2E regression (3 specs), axe-core accessibility, security headers + CSP, k6 load tests (peak and soak) 3. **Configuration** – playwright.config.ts, package.json with npm scripts -4. **Scripts** – serve.sh, run-all.sh, audit.sh +4. **Scripts** – serve.sh, run-all.sh 5. **PRODUCTION-READINESS.md** – assessed against the **Works first time**, **Right technology**, **Trust, security and privacy** and **Measuring performance** themes (cited as the profile's own standards where there is a profile), each Met / Partly met / Not met, with evidence -Run what's runnable in the current environment: HTML validation, link integrity, design-system class usage. For the parts that need full tool installation (Playwright browsers, k6 binary, OWASP ZAP), the report explicitly says "requires CI environment with these tools installed" with the exact commands. +6. **Constraints** – `.xstack/constraints.json` (the baseline, the profile's layer where it has one, and this service's own), with xstack's check runner copied into `.xstack/vendor/`. See `constraints/README.md` + +Do not write your own audit script. Run the shipped runner – `node .xstack/vendor/xstack-check.mjs --stage stop` – and fix what it finds. The ratings in PRODUCTION-READINESS.md come from its output: a theme is Met only when every one of its constraints passes at the `ci` stage, and each rating cites the constraint ids it rests on. If a "must" constraint cannot be met, report it as failing and ask the user whether to fix it or record a waiver. Never add a waiver yourself. For the parts that need full tool installation (Playwright browsers, k6 binary, OWASP ZAP), the report explicitly says "requires CI environment with these tools installed" with the exact commands. After generation, share the production folder via a computer:// link. Highlight any standards still at Partly met or Not met, and name the next-step owner (cyber engineer for the threat-model gap, developer for the backend wiring, delivery manager for operational readiness). diff --git a/commands/profile.md b/commands/profile.md index 1409ddb..fbb686b 100644 --- a/commands/profile.md +++ b/commands/profile.md @@ -34,6 +34,7 @@ Start from `profiles/_template/profile.md`. Write `.xstack/profile.md` in the pr - Map **every** standard in their service standard to one or more themes in `references/service-standard-baseline.md`. List any baseline theme with no match under "Not in our standard". - If they gave you the full text of their standard, save it as `.xstack/service-standards.md` in the same format as `profiles/barbados/service-standards.md`, with "How an agent checks" questions for each standard. - Delete the template's comments and any section you have nothing for. +- If the team builds for production, offer a constraints layer: the rules that hold for every service in their government, written so a machine checks them. Start from `profiles/_template/constraints.json`, write `.xstack/profile-constraints.json`, and include only rules with a source the team can point to. See the Constraints section of `profiles/README.md`. ## 4. Confirm diff --git a/commands/threat-model.md b/commands/threat-model.md index 5d5fc55..4a57297 100644 --- a/commands/threat-model.md +++ b/commands/threat-model.md @@ -33,4 +33,12 @@ For diagrams, use Mermaid where the tooling supports it; otherwise produce a cle Cross-reference the assessment against the **Trust, security and privacy**, **Inclusion** (security mustn't lock disabled citizens out) and **Open platforms and standards** (reuse the national identity platform, don't bake your own) themes. Cite the profile's own standard by number and title where there is one. +**Turn every control into a constraint.** A control that nothing checks is a hope. If the service has `.xstack/constraints.json`, give each control in section 7 one of three endings: + +- **A constraint** – draft it in the format in `constraints/README.md`, with `source` set to the threat it answers (e.g. `threat model T-04`), and a check: a pattern, or a `command` that runs a test or a scanner. +- **A test still to write** – name the test and its owner, and draft the `command` constraint that will run it. +- **Not machine-checkable** – say so, and say who verifies it and when (pen test, DPIA, procedure). + +Each data-inventory item the service must not collect becomes a `forbid-pattern` constraint on the form field names. List the drafted constraints at the end of the threat model under "Constraints to add". The constraints file is protected: a person approves adding them. Never remove or loosen an existing constraint; if one is wrong, say why and ask for a waiver. + Save the threat model to the workspace folder as `threat-model-[service-slug]-YYYY-MM-DD.md` and share the file link with the user. Flag any findings the developer needs to act on immediately. diff --git a/constraints/README.md b/constraints/README.md new file mode 100644 index 0000000..3e83049 --- /dev/null +++ b/constraints/README.md @@ -0,0 +1,113 @@ +# Constraints + +A constraint is a rule a production service must meet, written so a machine can check it. xstack enforces constraints in three places, so they do not depend on an agent remembering an instruction. + +| Where | What happens | File | +|---|---|---| +| When the agent writes a file | A write that adds a secret, an inline script or prototype chrome is refused. A change to a protected path needs a person to say yes | `hooks/guard-write.mjs` | +| When the agent runs a shell command | A command that looks like it changes a protected path needs a person to say yes. Running the checks is never held up | `hooks/guard-bash.mjs` | +| When the agent says it is done | The checks run. If a "must" constraint fails, the agent is sent back with the findings | `hooks/stop-gate.mjs` | +| In CI | Every constraint runs, including the ones that need a server, browsers and scanners | `scripts/xstack-check.mjs --stage ci` | + +The checks ship with xstack. The agent that writes the code does not write the checker. + +Constraints raise the floor. They do not replace the threat model, the pen test or the DPIA. + +## Turning it on + +A folder is constrained when it has `.xstack/constraints.json`. `/xstack:productionise` creates one. Everywhere else the hooks do nothing. + +```json +{ + "version": 1, + "service": "renew-medical-licence", + "extends": ["xstack:baseline", "profile:barbados"], + "vars": { "web": "public" }, + "protected": ["tests/security/**"], + "constraints": [], + "waivers": [] +} +``` + +Then copy the runner into the service so CI can run it without the plugin: + +```bash +node "$CLAUDE_PLUGIN_ROOT/scripts/xstack-check.mjs" --vendor --root . +``` + +## Layers + +Constraints come from three layers. Later layers add constraints. They cannot redefine one from an earlier layer. + +1. **Baseline** – `constraints/baseline.json`. Ships with xstack and applies in every country. +2. **Profile** – `profiles//constraints.json`. The government's design system, house style, platforms and law. Barbados and Kestria have one. To write your own, start from `profiles/_template/constraints.json`. +3. **Service** – the `constraints` list in the service's own file. Each threat-model mitigation, each field in the data inventory and each test suite that must pass. + +## A constraint + +```json +{ + "id": "SVC-SEC-002", + "title": "The licence number is never written to a log", + "theme": "Trust, security and privacy", + "source": "threat model T-04 (information disclosure)", + "owner": "cyber-engineer", + "severity": "must", + "when": ["stop", "ci"], + "check": { "type": "forbid-pattern", "files": ["src/**/*.ts"], "patterns": ["log\\w*\\([^)]*licenceNumber"] }, + "fix": "Log the application reference instead." +} +``` + +- `theme` is a theme from `references/service-standard-baseline.md`. The readiness report groups evidence by theme. +- `source` says where the rule comes from: a standard, a law, a threat, a profile file. +- `severity` is `must` (blocks) or `should` (reported). +- `when` lists the stages the check runs at: `write`, `stop`, `ci`. The `ci` stage runs everything. +- `onlyIf` is optional: `{ "exists": "package.json" }` skips the constraint when the file is absent. + +## Check types + +| Type | Passes when | Options | +|---|---|---| +| `forbid-pattern` | No file matches any pattern. The only type that can run at `write` | `files`, `exclude`, `patterns`, `flags` | +| `require-pattern` | Every file matches every pattern | `files`, `exclude`, `patterns`, `flags` | +| `links-resolve` | Every internal `href`, `action` and `src` points at a file | `files`, `root`, `ignore` | +| `form-method` | Every form with a file or password input uses POST | `files` | +| `max-size` | No file is larger than `bytes` | `files`, `exclude`, `bytes` | +| `file-exists` | The file, or one of `anyOf`, exists | `path` or `anyOf` | +| `command` | The command exits 0. Use it to wrap a scanner or a test suite | `run`, `requires`, `timeoutSeconds` | + +If the tool a `command` check `requires` is not installed, the result is NOT RUN. At the `ci` stage a "must" constraint that did not run counts as a failure. + +## Waivers + +A team relaxes a constraint with a waiver, not by editing or deleting it. + +```json +{ "id": "WFT-001", "reason": "Help and privacy pages arrive in sprint 9", "approvedBy": "A. Person, service owner", "expires": "2027-01-31" } +``` + +A waiver needs all three of `reason`, `approvedBy` and `expires`. An expired or incomplete waiver does nothing. The constraints file is a protected path, so only a person can add one. Agents: if a constraint cannot be met, say which and why, and ask. + +## Reading the results + +```bash +node .xstack/vendor/xstack-check.mjs --stage stop # text +node .xstack/vendor/xstack-check.mjs --stage ci --format md # the evidence section for PRODUCTION-READINESS.md +``` + +Results are PASS, FAIL, WAIVED, NOT RUN or N/A. Each run writes `.xstack/check-report.json`. + +A theme is **Met** only if every one of its constraints is PASS at the `ci` stage. FAIL, WAIVED and NOT RUN are at best **Partly met**. A rating in a readiness report or a standards assessment cites the constraint ids it rests on. + +## CI + +The hooks only see the Write and Edit tools, so CI is the backstop. `constraints/ci/github-actions.yml` is a workflow for a service: copy it to `.github/workflows/constraints.yml`, make the job a required check, and require review for changes under `.xstack/`. + +xstack's own workflow, `.github/workflows/constraints.yml`, tests the runner and hooks (`node --test scripts/xstack-check.test.mjs`), checks that vendored copies match the source, and runs the `ci` stage on the medical-licence example. + +## Limits + +- The write guard covers the Write and Edit tools. The shell guard reads a command as text, so it is a tripwire, not a wall: a command can be written to slip past it. CI is the backstop – see the CI section above. +- Pattern checks find known shapes of mistake. They do not prove their absence. +- The baseline covers the front end and the repository. Back-end constraints – authorisation, input validation, logging – arrive with the back-end scaffold. diff --git a/constraints/baseline.json b/constraints/baseline.json new file mode 100644 index 0000000..7f81883 --- /dev/null +++ b/constraints/baseline.json @@ -0,0 +1,321 @@ +{ + "version": 1, + "layer": "xstack:baseline", + "description": "Constraints every xstack production build must meet, whatever the country. Themes are the ones in references/service-standard-baseline.md.", + "vars": { + "web": "public", + "backendRoutes": "/api/**" + }, + "constraints": [ + { + "id": "SEC-001", + "title": "No secrets in source", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "cyber-engineer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "**/*" + ], + "exclude": [ + "**/*.lock", + "**/package-lock.json" + ], + "patterns": [ + "AKIA[0-9A-Z]{16}", + "-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY", + "gh[pousr]_[A-Za-z0-9]{36,}", + "xox[baprs]-[A-Za-z0-9-]{10,}", + "sk_live_[A-Za-z0-9]{16,}", + "(?:api[_-]?key|secret|passwd|password|token)[\"']?\\s*[:=]\\s*[\"'][A-Za-z0-9+/_\\-]{20,}[\"']" + ], + "flags": "i" + }, + "fix": "Remove the value. Read it from the environment or the platform's secret store, and rotate it if it was ever real." + }, + { + "id": "SEC-002", + "title": "No inline event handlers", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "<[^>]+\\son[a-z]+\\s*=\\s*[\"']" + ], + "flags": "i" + }, + "fix": "Move the behaviour to a linked script and use addEventListener, so a strict Content-Security-Policy can stay on." + }, + { + "id": "SEC-003", + "title": "No inline scripts", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "]*\\ssrc=)[^>]*>", + "(?:href|action|src)\\s*=\\s*[\"']\\s*javascript:" + ], + "flags": "i" + }, + "fix": "Link the script with src. A strict Content-Security-Policy blocks inline script." + }, + { + "id": "SEC-008", + "title": "No inline style attributes", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "<[^>]+\\sstyle\\s*=\\s*[\"']" + ], + "flags": "i" + }, + "fix": "Use a class from the linked stylesheet. A strict Content-Security-Policy (style-src without 'unsafe-inline') makes browsers ignore style attributes, so the page will not look the way you wrote it." + }, + { + "id": "SEC-004", + "title": "Forms that send files or passwords use POST", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "stop", + "ci" + ], + "check": { + "type": "form-method", + "files": [ + "{{web}}/**/*.html" + ] + }, + "fix": "Set method=\"post\" on the form (and enctype=\"multipart/form-data\" for uploads). GET puts the data in the URL, in logs and in history." + }, + { + "id": "SEC-005", + "title": "No secrets leaked in git history or working tree (gitleaks)", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "cyber-engineer", + "severity": "must", + "when": [ + "ci" + ], + "check": { + "type": "command", + "requires": "gitleaks", + "run": "gitleaks dir . --no-banner --redact" + }, + "fix": "Remove and rotate whatever gitleaks reports." + }, + { + "id": "SEC-006", + "title": "No known high or critical vulnerabilities in dependencies", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "cyber-engineer", + "severity": "must", + "when": [ + "ci" + ], + "onlyIf": { + "exists": "package.json" + }, + "check": { + "type": "command", + "requires": "npm", + "run": "npm audit --audit-level=high" + }, + "fix": "Upgrade or replace the dependency. If there is no fix yet, a human records a waiver with an expiry date." + }, + { + "id": "SEC-007", + "title": "Dependencies are pinned by a lockfile", + "theme": "Sustainable and reliable", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "ci" + ], + "onlyIf": { + "exists": "package.json" + }, + "check": { + "type": "file-exists", + "anyOf": [ + "package-lock.json", + "pnpm-lock.yaml", + "yarn.lock" + ] + }, + "fix": "Run the package manager's install and commit the lockfile." + }, + { + "id": "A11Y-001", + "title": "Every page declares its language, has a title and a main landmark", + "theme": "Inclusion", + "source": "xstack baseline", + "owner": "content-designer", + "severity": "must", + "when": [ + "stop", + "ci" + ], + "check": { + "type": "require-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "", + "]*\\slang=[\"'][a-zA-Z-]+[\"']", + "[^<]+", + "]" + ], + "flags": "i" + }, + "fix": "Add the missing element. Screen readers need all four." + }, + { + "id": "A11Y-002", + "title": "Every image has an alt attribute", + "theme": "Inclusion", + "source": "xstack baseline", + "owner": "content-designer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "]*\\salt=)[^>]*>" + ], + "flags": "i" + }, + "fix": "Add alt text, or alt=\"\" if the image is decoration." + }, + { + "id": "WFT-001", + "title": "Every internal link and form action goes somewhere", + "theme": "Works first time", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "stop", + "ci" + ], + "check": { + "type": "links-resolve", + "files": [ + "{{web}}/**/*.html" + ], + "root": "{{web}}", + "ignore": [ + "{{backendRoutes}}" + ] + }, + "fix": "Build the page, or remove the link until it exists. A dead link in a government service is a dead end for a citizen." + }, + { + "id": "TECH-001", + "title": "Styles are linked, not inlined", + "theme": "Right technology", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "]" + ], + "flags": "i" + }, + "fix": "Move the rules to the linked stylesheet. Use the design system's own classes first." + }, + { + "id": "OPEN-001", + "title": "No prototype chrome in production", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "xstack-banner", + "xstack-assumptions", + "Show assumptions", + "verify-tag", + "fake-data", + "\\[VERIFY WITH " + ] + }, + "fix": "Strip the assumptions panel, banner and mock-data markers. Citizens must never see invented data presented as real." + } + ] +} diff --git a/constraints/ci/github-actions.yml b/constraints/ci/github-actions.yml new file mode 100644 index 0000000..43ebc81 --- /dev/null +++ b/constraints/ci/github-actions.yml @@ -0,0 +1,60 @@ +# Constraint checks for a service built with /xstack:productionise. +# Copy to .github/workflows/constraints.yml in the service's repository. +# +# It runs every constraint in .xstack/constraints.json at the ci stage. A "must" +# constraint that fails, or that cannot run because a tool is missing, fails the job. +# Make this job a required check, and require review for changes under .xstack/. + +name: Constraints + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + constraints: + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + GITLEAKS_VERSION: 8.21.2 + GITLEAKS_SHA256: 5bc41815076e6ed6ef8fbecc9d9b75bcae31f39029ceb55da08086315316e3ba + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - name: Install gitleaks + working-directory: ${{ runner.temp }} + run: | + curl -sSfL -o gitleaks.tar.gz "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" + echo "${GITLEAKS_SHA256} gitleaks.tar.gz" | sha256sum --check + tar -xzf gitleaks.tar.gz gitleaks + sudo install gitleaks /usr/local/bin/gitleaks + - name: Install dependencies + run: npm ci + - name: Install browsers + run: npx playwright install --with-deps + # If a constraint needs a running service (a header check, say), start it + # here on a port your browser tests do not use, and pass its URL below. + - name: Start a server for the header check + run: | + PORT=8081 ./scripts/serve.sh & + for i in $(seq 1 20); do curl -sf -o /dev/null http://localhost:8081/ && exit 0; sleep 1; done + exit 1 + - name: Run every constraint + env: + BASE_URL: http://localhost:8081 + run: node .xstack/vendor/xstack-check.mjs --stage ci + - name: Keep the report + if: always() + uses: actions/upload-artifact@v4 + with: + name: constraint-report + path: .xstack/check-report.json + include-hidden-files: true + if-no-files-found: ignore diff --git a/examples/production-renew-medical-licence/.xstack/constraints.json b/examples/production-renew-medical-licence/.xstack/constraints.json new file mode 100644 index 0000000..4ef1f90 --- /dev/null +++ b/examples/production-renew-medical-licence/.xstack/constraints.json @@ -0,0 +1,43 @@ +{ + "version": 1, + "service": "renew-medical-licence", + "extends": ["xstack:baseline", "profile:barbados"], + "vars": { "web": "public" }, + "protected": ["tests/security/**", "tests/accessibility/**", "playwright.config.ts"], + "constraints": [ + { + "id": "SVC-SEC-001", + "title": "The server sends the six security headers, with a CSP that forbids inline script", + "theme": "Trust, security and privacy", + "source": "Standard 11 (Trust, safety, confidentiality)", + "owner": "cyber-engineer", + "severity": "must", + "when": ["ci"], + "check": { "type": "command", "requires": "curl", "run": "./tests/security/headers.sh \"${BASE_URL:-http://localhost:8080}\"" }, + "fix": "Set the missing header on the server. scripts/serve.sh shows the values." + }, + { + "id": "SVC-A11Y-001", + "title": "Every page in every state passes axe at WCAG 2.1 AA", + "theme": "Inclusion", + "source": "Standard 3 (Inclusion)", + "owner": "content-designer", + "severity": "must", + "when": ["ci"], + "check": { "type": "command", "requires": "npx", "run": "npx --no-install playwright test tests/accessibility" }, + "fix": "Fix the violation axe reports. Do not add the rule to an exclusion list." + }, + { + "id": "SVC-WFT-001", + "title": "A doctor can renew end to end, including from abroad, through every error state and when correcting their details", + "theme": "Works first time", + "source": "Standard 5 (Works first time)", + "owner": "developer", + "severity": "must", + "when": ["ci"], + "check": { "type": "command", "requires": "npx", "run": "npx --no-install playwright test tests/e2e" }, + "fix": "Fix the journey, not the test." + } + ], + "waivers": [] +} diff --git a/examples/production-renew-medical-licence/.xstack/vendor/baseline.json b/examples/production-renew-medical-licence/.xstack/vendor/baseline.json new file mode 100644 index 0000000..7f81883 --- /dev/null +++ b/examples/production-renew-medical-licence/.xstack/vendor/baseline.json @@ -0,0 +1,321 @@ +{ + "version": 1, + "layer": "xstack:baseline", + "description": "Constraints every xstack production build must meet, whatever the country. Themes are the ones in references/service-standard-baseline.md.", + "vars": { + "web": "public", + "backendRoutes": "/api/**" + }, + "constraints": [ + { + "id": "SEC-001", + "title": "No secrets in source", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "cyber-engineer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "**/*" + ], + "exclude": [ + "**/*.lock", + "**/package-lock.json" + ], + "patterns": [ + "AKIA[0-9A-Z]{16}", + "-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY", + "gh[pousr]_[A-Za-z0-9]{36,}", + "xox[baprs]-[A-Za-z0-9-]{10,}", + "sk_live_[A-Za-z0-9]{16,}", + "(?:api[_-]?key|secret|passwd|password|token)[\"']?\\s*[:=]\\s*[\"'][A-Za-z0-9+/_\\-]{20,}[\"']" + ], + "flags": "i" + }, + "fix": "Remove the value. Read it from the environment or the platform's secret store, and rotate it if it was ever real." + }, + { + "id": "SEC-002", + "title": "No inline event handlers", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "<[^>]+\\son[a-z]+\\s*=\\s*[\"']" + ], + "flags": "i" + }, + "fix": "Move the behaviour to a linked script and use addEventListener, so a strict Content-Security-Policy can stay on." + }, + { + "id": "SEC-003", + "title": "No inline scripts", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "]*\\ssrc=)[^>]*>", + "(?:href|action|src)\\s*=\\s*[\"']\\s*javascript:" + ], + "flags": "i" + }, + "fix": "Link the script with src. A strict Content-Security-Policy blocks inline script." + }, + { + "id": "SEC-008", + "title": "No inline style attributes", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "<[^>]+\\sstyle\\s*=\\s*[\"']" + ], + "flags": "i" + }, + "fix": "Use a class from the linked stylesheet. A strict Content-Security-Policy (style-src without 'unsafe-inline') makes browsers ignore style attributes, so the page will not look the way you wrote it." + }, + { + "id": "SEC-004", + "title": "Forms that send files or passwords use POST", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "stop", + "ci" + ], + "check": { + "type": "form-method", + "files": [ + "{{web}}/**/*.html" + ] + }, + "fix": "Set method=\"post\" on the form (and enctype=\"multipart/form-data\" for uploads). GET puts the data in the URL, in logs and in history." + }, + { + "id": "SEC-005", + "title": "No secrets leaked in git history or working tree (gitleaks)", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "cyber-engineer", + "severity": "must", + "when": [ + "ci" + ], + "check": { + "type": "command", + "requires": "gitleaks", + "run": "gitleaks dir . --no-banner --redact" + }, + "fix": "Remove and rotate whatever gitleaks reports." + }, + { + "id": "SEC-006", + "title": "No known high or critical vulnerabilities in dependencies", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "cyber-engineer", + "severity": "must", + "when": [ + "ci" + ], + "onlyIf": { + "exists": "package.json" + }, + "check": { + "type": "command", + "requires": "npm", + "run": "npm audit --audit-level=high" + }, + "fix": "Upgrade or replace the dependency. If there is no fix yet, a human records a waiver with an expiry date." + }, + { + "id": "SEC-007", + "title": "Dependencies are pinned by a lockfile", + "theme": "Sustainable and reliable", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "ci" + ], + "onlyIf": { + "exists": "package.json" + }, + "check": { + "type": "file-exists", + "anyOf": [ + "package-lock.json", + "pnpm-lock.yaml", + "yarn.lock" + ] + }, + "fix": "Run the package manager's install and commit the lockfile." + }, + { + "id": "A11Y-001", + "title": "Every page declares its language, has a title and a main landmark", + "theme": "Inclusion", + "source": "xstack baseline", + "owner": "content-designer", + "severity": "must", + "when": [ + "stop", + "ci" + ], + "check": { + "type": "require-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "", + "]*\\slang=[\"'][a-zA-Z-]+[\"']", + "[^<]+", + "]" + ], + "flags": "i" + }, + "fix": "Add the missing element. Screen readers need all four." + }, + { + "id": "A11Y-002", + "title": "Every image has an alt attribute", + "theme": "Inclusion", + "source": "xstack baseline", + "owner": "content-designer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "]*\\salt=)[^>]*>" + ], + "flags": "i" + }, + "fix": "Add alt text, or alt=\"\" if the image is decoration." + }, + { + "id": "WFT-001", + "title": "Every internal link and form action goes somewhere", + "theme": "Works first time", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "stop", + "ci" + ], + "check": { + "type": "links-resolve", + "files": [ + "{{web}}/**/*.html" + ], + "root": "{{web}}", + "ignore": [ + "{{backendRoutes}}" + ] + }, + "fix": "Build the page, or remove the link until it exists. A dead link in a government service is a dead end for a citizen." + }, + { + "id": "TECH-001", + "title": "Styles are linked, not inlined", + "theme": "Right technology", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "]" + ], + "flags": "i" + }, + "fix": "Move the rules to the linked stylesheet. Use the design system's own classes first." + }, + { + "id": "OPEN-001", + "title": "No prototype chrome in production", + "theme": "Trust, security and privacy", + "source": "xstack baseline", + "owner": "developer", + "severity": "must", + "when": [ + "write", + "stop", + "ci" + ], + "check": { + "type": "forbid-pattern", + "files": [ + "{{web}}/**/*.html" + ], + "patterns": [ + "xstack-banner", + "xstack-assumptions", + "Show assumptions", + "verify-tag", + "fake-data", + "\\[VERIFY WITH " + ] + }, + "fix": "Strip the assumptions panel, banner and mock-data markers. Citizens must never see invented data presented as real." + } + ] +} diff --git a/examples/production-renew-medical-licence/.xstack/vendor/profile-barbados.json b/examples/production-renew-medical-licence/.xstack/vendor/profile-barbados.json new file mode 100644 index 0000000..33a9303 --- /dev/null +++ b/examples/production-renew-medical-licence/.xstack/vendor/profile-barbados.json @@ -0,0 +1,37 @@ +{ + "version": 1, + "layer": "profile:barbados", + "description": "Constraints from the Barbados profile: the GovBB design system and the GovTech Barbados house style.", + "constraints": [ + { + "id": "BB-DS-001", + "title": "Every page uses the GovBB design system and its skip link", + "theme": "Right technology", + "source": "profiles/barbados/design-guide.md", + "owner": "content-designer", + "severity": "must", + "when": ["stop", "ci"], + "check": { + "type": "require-pattern", + "files": ["{{web}}/**/*.html"], + "patterns": ["class=\"[^\"]*govbb-skip-link", "role=\"banner\"", "role=\"contentinfo\"", "rel=\"stylesheet\""] + }, + "fix": "Start the page from the GovBB page template: skip link, header and footer landmarks, linked stylesheet." + }, + { + "id": "BB-STYLE-001", + "title": "No em dashes in citizen-facing pages", + "theme": "Plain language", + "source": "profiles/barbados/house-style.md", + "owner": "content-designer", + "severity": "must", + "when": ["write", "stop", "ci"], + "check": { + "type": "forbid-pattern", + "files": ["{{web}}/**/*.html"], + "patterns": ["—"] + }, + "fix": "Use a spaced en dash, or split the sentence." + } + ] +} diff --git a/examples/production-renew-medical-licence/.xstack/vendor/xstack-check.mjs b/examples/production-renew-medical-licence/.xstack/vendor/xstack-check.mjs new file mode 100644 index 0000000..7c3abb3 --- /dev/null +++ b/examples/production-renew-medical-licence/.xstack/vendor/xstack-check.mjs @@ -0,0 +1,406 @@ +#!/usr/bin/env node +// xstack-check – run a service's constraints and report the evidence. +// +// The checks ship with xstack. The agent that writes the code does not write +// the checker. No dependencies: Node 20 or later. +// +// xstack-check [--root DIR] [--stage write|stop|ci] [--format text|json|md] +// [--no-report] +// xstack-check --vendor [--root DIR] copy the runner and its layers into +// DIR/.xstack/vendor so CI can run it +// +// Exit codes: 0 all "must" constraints hold, 1 at least one does not, +// 2 the constraints file is missing or invalid. +// +// See constraints/README.md for the file format. + +import fs from 'node:fs'; +import path from 'node:path'; +import { spawnSync } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +export const CONSTRAINTS_FILE = path.join('.xstack', 'constraints.json'); +export const REPORT_FILE = path.join('.xstack', 'check-report.json'); +const SKIP_DIRS = new Set(['node_modules', '.git', 'reports', 'test-results', 'playwright-report', 'dist', 'build', 'coverage']); +const BINARY = /\.(png|jpe?g|gif|webp|ico|pdf|woff2?|ttf|otf|eot|zip|gz|mp4|mov|docx|pptx|xlsx)$/i; +const STAGES = ['write', 'stop', 'ci']; +// A path the agent may not change without a person saying yes. +export const ALWAYS_PROTECTED = ['.xstack/constraints.json', '.xstack/vendor/**']; + +// ---------- small helpers ---------- + +export function globToRegExp(glob) { + let re = ''; + for (let i = 0; i < glob.length; i++) { + const c = glob[i]; + if (c === '*') { + if (glob[i + 1] === '*') { + i++; + if (glob[i + 1] === '/') { i++; re += '(?:.*/)?'; } else re += '.*'; + } else re += '[^/]*'; + } else if (c === '?') re += '[^/]'; + else re += c.replace(/[.+^${}()|[\]\\]/g, '\\$&'); + } + return new RegExp(`^${re}$`); +} + +export function matchesAny(rel, globs = []) { + return globs.some((g) => globToRegExp(g).test(rel)); +} + +export function walk(root) { + const out = []; + const visit = (dir) => { + let entries; + try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; } + for (const e of entries) { + if (e.isDirectory()) { + if (!SKIP_DIRS.has(e.name)) visit(path.join(dir, e.name)); + } else if (e.isFile()) { + out.push(path.relative(root, path.join(dir, e.name)).split(path.sep).join('/')); + } + } + }; + visit(root); + return out.sort(); +} + +function subst(value, vars) { + if (typeof value === 'string') return value.replace(/\{\{(\w+)\}\}/g, (m, k) => (k in vars ? vars[k] : m)); + if (Array.isArray(value)) return value.map((v) => subst(v, vars)); + if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, subst(v, vars)])); + return value; +} + +// Blank out HTML comments but keep the line numbers, so markup that is only +// described in a comment is neither credited nor blamed. +function withoutComments(text) { + return text.replace(//g, (m) => m.replace(/[^\n]/g, ' ')); +} + +function lineOf(text, index) { + return text.slice(0, index).split('\n').length; +} + +function readJson(file) { + return JSON.parse(fs.readFileSync(file, 'utf8')); +} + +// Every constrained folder at, above or (to a depth of four) below a directory. +export function findRoots(cwd) { + const out = new Set(); + const below = (dir, depth) => { + if (fs.existsSync(path.join(dir, CONSTRAINTS_FILE))) out.add(dir); + if (depth === 0) return; + let entries; + try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; } + for (const e of entries) if (e.isDirectory() && !SKIP_DIRS.has(e.name) && !e.name.startsWith('.')) below(path.join(dir, e.name), depth - 1); + }; + below(cwd, 4); + for (let d = path.dirname(cwd); d !== path.dirname(d); d = path.dirname(d)) if (fs.existsSync(path.join(d, CONSTRAINTS_FILE))) out.add(d); + return [...out]; +} + +// ---------- loading and merging layers ---------- + +function layerCandidates(name, root) { + const vendor = path.join(root, '.xstack', 'vendor'); + if (name === 'xstack:baseline') { + return [path.join(vendor, 'baseline.json'), path.join(HERE, 'baseline.json'), path.join(HERE, '..', 'constraints', 'baseline.json')]; + } + if (name.startsWith('profile:')) { + const p = name.slice('profile:'.length); + if (!/^[\w-]+$/.test(p)) throw new Error(`Bad profile name in extends: ${name}`); + return [path.join(vendor, `profile-${p}.json`), path.join(HERE, `profile-${p}.json`), path.join(HERE, '..', 'profiles', p, 'constraints.json')]; + } + return [path.resolve(root, name)]; +} + +export function resolveLayer(name, root) { + const found = layerCandidates(name, root).find((f) => fs.existsSync(f)); + if (!found) throw new Error(`Cannot find the constraints layer "${name}"`); + return found; +} + +export function loadConstraints(root) { + const file = path.join(root, CONSTRAINTS_FILE); + if (!fs.existsSync(file)) throw new Error(`No ${CONSTRAINTS_FILE} in ${root}`); + const project = readJson(file); + const layers = (project.extends || ['xstack:baseline']).map((name) => ({ name, ...readJson(resolveLayer(name, root)) })); + layers.push({ name: 'service', ...project }); + + const vars = Object.assign({}, ...layers.map((l) => l.vars || {})); + const byId = new Map(); + for (const layer of layers) { + for (const c of layer.constraints || []) { + // A later layer can add constraints. It cannot redefine an earlier one: + // loosening a rule is a waiver, with a name and an expiry on it. + if (byId.has(c.id)) throw new Error(`Constraint ${c.id} is defined twice (in "${byId.get(c.id).layer}" and "${layer.name}"). To relax a constraint, add a waiver.`); + validate(c, layer.name); + byId.set(c.id, { ...subst(c, vars), layer: layer.name }); + } + } + return { + service: project.service || path.basename(root), + vars, + constraints: [...byId.values()], + waivers: project.waivers || [], + protected: [...ALWAYS_PROTECTED, ...subst(project.protected || [], vars)], + }; +} + +function validate(c, layer) { + const bad = (msg) => { throw new Error(`Constraint ${c.id || '(no id)'} in "${layer}": ${msg}`); }; + for (const k of ['id', 'title', 'theme', 'source', 'owner', 'severity', 'when', 'check']) if (c[k] === undefined) bad(`missing "${k}"`); + if (!['must', 'should'].includes(c.severity)) bad('severity must be "must" or "should"'); + if (!Array.isArray(c.when) || !c.when.length || c.when.some((s) => !STAGES.includes(s))) bad(`"when" must list one or more of ${STAGES.join(', ')}`); + if (!CHECKS[c.check.type]) bad(`unknown check type "${c.check.type}"`); + if (c.when.includes('write') && c.check.type !== 'forbid-pattern') bad('only forbid-pattern checks can run at the "write" stage'); +} + +// ---------- the checks ---------- + +function selectFiles(ctx, check) { + return ctx.files.filter((f) => matchesAny(f, check.files) && !matchesAny(f, check.exclude) && !BINARY.test(f)); +} + +function read(ctx, rel) { + try { return fs.readFileSync(path.join(ctx.root, rel), 'utf8'); } catch { return ''; } +} + +export function findForbidden(text, check) { + const hits = []; + for (const p of check.patterns) { + const re = new RegExp(p, `g${check.flags || ''}`); + let m; + while ((m = re.exec(text)) && hits.length < 50) { + hits.push({ line: lineOf(text, m.index), pattern: p }); + if (m[0] === '') re.lastIndex++; + } + } + return hits; +} + +const CHECKS = { + 'forbid-pattern'(ctx, check) { + const files = selectFiles(ctx, check); + const findings = []; + for (const f of files) for (const h of findForbidden(read(ctx, f), check)) findings.push(`${f}:${h.line} matches /${h.pattern}/`); + return { ok: findings.length === 0, findings, checked: files.length }; + }, + + 'require-pattern'(ctx, check) { + const files = selectFiles(ctx, check); + const findings = []; + for (const f of files) { + const text = read(ctx, f); + for (const p of check.patterns) if (!new RegExp(p, check.flags || '').test(text)) findings.push(`${f} has nothing matching /${p}/`); + } + return { ok: findings.length === 0, findings, checked: files.length }; + }, + + 'links-resolve'(ctx, check) { + const files = selectFiles(ctx, check); + const webRoot = path.join(ctx.root, check.root || '.'); + const findings = []; + for (const f of files) { + const text = withoutComments(read(ctx, f)); + const re = /\s(?:href|action|src)\s*=\s*["']([^"']*)["']/gi; + let m; + const seen = new Set(); + while ((m = re.exec(text))) { + const target = m[1].trim(); + if (!target || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\{\{)/i.test(target)) continue; // external, fragment or template + const clean = target.split('#')[0].split('?')[0]; + if (!clean || seen.has(clean) || matchesAny(clean, check.ignore)) continue; + seen.add(clean); + const base = clean.startsWith('/') ? path.join(webRoot, clean) : path.resolve(path.join(ctx.root, path.dirname(f)), clean); + const candidates = [base, `${base}.html`, path.join(base, 'index.html')]; + if (!candidates.some((c) => fs.existsSync(c) && fs.statSync(c).isFile())) findings.push(`${f}:${lineOf(text, m.index)} links to ${target}, which does not exist`); + } + } + return { ok: findings.length === 0, findings, checked: files.length }; + }, + + 'form-method'(ctx, check) { + const files = selectFiles(ctx, check); + const findings = []; + for (const f of files) { + const text = withoutComments(read(ctx, f)); + const re = /]*)>([\s\S]*?)<\/form>/gi; + let m; + while ((m = re.exec(text))) { + const sensitive = /]*\stype\s*=\s*["']?(?:file|password)\b/i.test(m[2]); + const post = /\smethod\s*=\s*["']?post\b/i.test(m[1]); + if (sensitive && !post) findings.push(`${f}:${lineOf(text, m.index)} form with a file or password input does not use method="post"`); + } + } + return { ok: findings.length === 0, findings, checked: files.length }; + }, + + 'max-size'(ctx, check) { + const files = selectFiles(ctx, check); + const findings = []; + for (const f of files) { + const size = fs.statSync(path.join(ctx.root, f)).size; + if (size > check.bytes) findings.push(`${f} is ${size} bytes, over the limit of ${check.bytes}`); + } + return { ok: findings.length === 0, findings, checked: files.length }; + }, + + 'file-exists'(ctx, check) { + const want = check.anyOf || [check.path]; + const ok = want.some((p) => fs.existsSync(path.join(ctx.root, p))); + return { ok, findings: ok ? [] : [`none of ${want.join(', ')} exists`], checked: 1 }; + }, + + command(ctx, check) { + if (check.requires) { + if (!/^[\w.-]+$/.test(check.requires)) return { ok: false, findings: [`"requires" must be a plain tool name, not ${check.requires}`], checked: 1 }; + const probe = spawnSync(`command -v ${check.requires}`, { shell: true, encoding: 'utf8' }); + if (probe.status !== 0) return { notRun: `${check.requires} is not installed` }; + } + const res = spawnSync(check.run, { shell: true, cwd: ctx.root, encoding: 'utf8', timeout: (check.timeoutSeconds || 600) * 1000, env: process.env }); + if (res.error && res.error.code === 'ETIMEDOUT') return { ok: false, findings: [`timed out: ${check.run}`], checked: 1 }; + const tail = `${res.stdout || ''}${res.stderr || ''}`.trim().split('\n').slice(-15); + return { ok: res.status === 0, findings: res.status === 0 ? [] : [`\`${check.run}\` exited ${res.status}`, ...tail], checked: 1 }; + }, +}; + +// ---------- running ---------- + +export function waiverFor(id, waivers, today) { + const w = waivers.find((x) => x.id === id); + if (!w) return null; + const complete = w.reason && w.approvedBy && /^\d{4}-\d{2}-\d{2}$/.test(w.expires || ''); + if (!complete) return { ...w, state: 'invalid' }; + return { ...w, state: w.expires < today ? 'expired' : 'active' }; +} + +export function runChecks(root, stage = 'stop') { + const cfg = loadConstraints(root); + const ctx = { root, files: walk(root) }; + const today = new Date().toISOString().slice(0, 10); + const results = []; + + for (const c of cfg.constraints) { + const base = { id: c.id, title: c.title, theme: c.theme, source: c.source, owner: c.owner, severity: c.severity, layer: c.layer, fix: c.fix }; + // The ci stage runs everything. Earlier stages run only what is tagged for them. + if (stage !== 'ci' && !c.when.includes(stage)) { results.push({ ...base, status: 'not-run', detail: `runs at: ${c.when.join(', ')}` }); continue; } + if (c.onlyIf?.exists && !fs.existsSync(path.join(root, c.onlyIf.exists))) { results.push({ ...base, status: 'not-applicable', detail: `no ${c.onlyIf.exists}` }); continue; } + + const r = CHECKS[c.check.type](ctx, c.check); + if (r.notRun) { results.push({ ...base, status: 'not-run', detail: r.notRun, blocking: stage === 'ci' && c.severity === 'must' }); continue; } + if (r.ok) { results.push({ ...base, status: 'pass', checked: r.checked }); continue; } + + const w = waiverFor(c.id, cfg.waivers, today); + if (w?.state === 'active') results.push({ ...base, status: 'waived', findings: r.findings, waiver: w }); + else results.push({ ...base, status: 'fail', findings: r.findings, waiver: w || undefined, blocking: c.severity === 'must' }); + } + + const blocking = results.filter((r) => r.blocking); + const count = (s) => results.filter((r) => r.status === s).length; + return { + service: cfg.service, + stage, + generated: new Date().toISOString(), + passed: blocking.length === 0, + summary: { pass: count('pass'), fail: count('fail'), waived: count('waived'), notRun: count('not-run'), notApplicable: count('not-applicable'), blocking: blocking.length }, + results, + }; +} + +// ---------- output ---------- + +const MARK = { pass: 'PASS', fail: 'FAIL', waived: 'WAIVED', 'not-run': 'NOT RUN', 'not-applicable': 'N/A' }; + +export function formatText(report, { onlyProblems = false } = {}) { + const lines = [`xstack-check: ${report.service} (stage: ${report.stage})`, '']; + for (const r of report.results) { + if (onlyProblems && !r.blocking) continue; + lines.push(`${MARK[r.status].padEnd(8)} ${r.id.padEnd(13)} ${r.severity.padEnd(6)} ${r.title}${r.detail ? ` (${r.detail})` : ''}`); + if (r.status === 'fail' || r.status === 'waived') { + for (const f of (r.findings || []).slice(0, 8)) lines.push(` ${f}`); + if ((r.findings || []).length > 8) lines.push(` ...and ${r.findings.length - 8} more`); + if (r.status === 'fail' && r.fix) lines.push(` Fix: ${r.fix}`); + if (r.waiver?.state === 'active') lines.push(` Waived until ${r.waiver.expires} by ${r.waiver.approvedBy}: ${r.waiver.reason}`); + if (r.waiver?.state === 'expired') lines.push(` The waiver expired on ${r.waiver.expires}.`); + if (r.waiver?.state === 'invalid') lines.push(' The waiver is missing a reason, approvedBy or an expires date (YYYY-MM-DD).'); + } + } + const s = report.summary; + lines.push('', `${s.pass} pass, ${s.fail} fail, ${s.waived} waived, ${s.notRun} not run, ${s.notApplicable} not applicable.`); + lines.push(report.passed ? 'All "must" constraints that ran at this stage hold.' : `${s.blocking} "must" constraint(s) do not hold.`); + return lines.join('\n'); +} + +export function formatMarkdown(report) { + const themes = [...new Set(report.results.map((r) => r.theme))]; + const out = [`## Constraint evidence`, '', `Generated by \`xstack-check\` at stage \`${report.stage}\` on ${report.generated.slice(0, 10)}. Do not edit by hand – run the check again.`, '']; + for (const theme of themes) { + out.push(`### ${theme}`, '', '| Constraint | Result | Severity | Owner | Evidence |', '|---|---|---|---|---|'); + for (const r of report.results.filter((x) => x.theme === theme)) { + let ev = r.detail || ''; + if (r.status === 'pass') ev = `${r.checked} file(s) or command(s) checked`; + if (r.status === 'fail') ev = `${r.findings.length} finding(s), first: ${String(r.findings[0]).replace(/\|/g, '\\|')}`; + if (r.status === 'waived') ev = `${r.findings.length} finding(s). Waived until ${r.waiver.expires} by ${r.waiver.approvedBy}: ${r.waiver.reason}`; + out.push(`| \`${r.id}\` ${r.title} | ${MARK[r.status]} | ${r.severity} | ${r.owner} | ${ev} |`); + } + out.push(''); + } + const s = report.summary; + out.push(`**Total:** ${s.pass} pass, ${s.fail} fail, ${s.waived} waived, ${s.notRun} not run, ${s.notApplicable} not applicable.`, ''); + out.push('A theme can be rated **Met** only if every one of its constraints is PASS at the `ci` stage. FAIL, WAIVED and NOT RUN are at best **Partly met**.'); + return out.join('\n'); +} + +// ---------- vendoring ---------- + +function vendor(root) { + const project = readJson(path.join(root, CONSTRAINTS_FILE)); + const dest = path.join(root, '.xstack', 'vendor'); + fs.mkdirSync(dest, { recursive: true }); + const copied = []; + const copy = (from, name) => { fs.copyFileSync(from, path.join(dest, name)); copied.push(name); }; + const self = fileURLToPath(import.meta.url); + if (path.resolve(self) !== path.resolve(dest, 'xstack-check.mjs')) copy(self, 'xstack-check.mjs'); + for (const name of project.extends || ['xstack:baseline']) { + if (name === 'xstack:baseline') copy(resolveLayer(name, path.join(root, '.nonexistent')), 'baseline.json'); + else if (name.startsWith('profile:')) copy(resolveLayer(name, path.join(root, '.nonexistent')), `profile-${name.slice(8)}.json`); + } + return copied; +} + +// ---------- command line ---------- + +function main(argv) { + const args = { root: process.cwd(), stage: 'stop', format: 'text', report: true }; + for (let i = 0; i < argv.length; i++) { + const a = argv[i]; + if (a === '--root') args.root = path.resolve(argv[++i]); + else if (a === '--stage') args.stage = argv[++i]; + else if (a === '--format') args.format = argv[++i]; + else if (a === '--no-report') args.report = false; + else if (a === '--vendor') args.vendor = true; + else if (a === '--help' || a === '-h') { console.log('Usage: xstack-check [--root DIR] [--stage write|stop|ci] [--format text|json|md] [--no-report] | --vendor [--root DIR]'); return 0; } + else { console.error(`Unknown option: ${a}`); return 2; } + } + if (!STAGES.includes(args.stage)) { console.error(`--stage must be one of ${STAGES.join(', ')}`); return 2; } + + try { + if (args.vendor) { + console.log(`Copied into ${path.join(args.root, '.xstack', 'vendor')}: ${vendor(args.root).join(', ')}`); + return 0; + } + const report = runChecks(args.root, args.stage); + if (args.report) fs.writeFileSync(path.join(args.root, REPORT_FILE), `${JSON.stringify(report, null, 2)}\n`); + console.log(args.format === 'json' ? JSON.stringify(report, null, 2) : args.format === 'md' ? formatMarkdown(report) : formatText(report)); + return report.passed ? 0 : 1; + } catch (e) { + console.error(`xstack-check: ${e.message}`); + return 2; + } +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) process.exit(main(process.argv.slice(2))); diff --git a/examples/production-renew-medical-licence/PRODUCTION-READINESS.md b/examples/production-renew-medical-licence/PRODUCTION-READINESS.md index b72dec4..7be4d34 100644 --- a/examples/production-renew-medical-licence/PRODUCTION-READINESS.md +++ b/examples/production-renew-medical-licence/PRODUCTION-READINESS.md @@ -1,6 +1,6 @@ # Production-readiness report – Renew medical licence (front-end) -**Generated:** 2026-05-16 +**Generated:** 2026-05-16. Constraint evidence regenerated 2026-11-19 at the `ci` stage **Skill:** `xstack:build-for-production` via `/xstack:productionise` **Source iteration:** `examples/build-renew-medical-licence/prototype-1-phone-first/iteration-3/index.html` **Target phase gate:** Alpha → Beta @@ -9,19 +9,38 @@ ## Headline -The front-end is **substantially ready** for private beta. Static checks pass; security headers pass against a live local server; the test suite is in place. Full Playwright and k6 runs require a CI environment with browser binaries and the k6 binary installed – these are not in this generation environment but the test code is ready and runnable. +The front-end meets every one of its 18 constraints. 17 pass on a developer machine at the `ci` stage, and the eighteenth, the gitleaks secret scan, passes in CI. -**Recommended action:** wire the test suite into CI (GitHub Actions or GitLab CI), run the full Playwright matrix and k6 peak test in a staging environment, then proceed to the formal Standards self-assessment with the delivery manager. +That makes the front-end ready for private beta **on the checks that exist**. It does not make the service ready: the back end, the threat-model refresh, the pen test and the DPIA are still to do, and the load tests have never been run. + +What the constraints found, all now fixed: + +- `SEC-004` – the CPD upload sent its file by GET. It now posts, with an upload button so it works without JavaScript. +- `WFT-001` – 50 links went to pages that did not exist. The ten missing pages are built. The privacy page says the full notice is still to come. +- `SEC-008` – 100 inline `style` attributes that the Content-Security-Policy told browsers to ignore. They are now classes in the stylesheet. +- `SVC-A11Y-001` and `SVC-WFT-001` – the Playwright suites had never been run, and 11 of 28 tests failed. Secondary text now uses GovBB grey-70 (`#595959`) because `#777777` failed contrast, the summary list is valid markup, three test locators were wrong, and the test server could not serve five browser profiles at once. + +An earlier version of this report rated a static audit as a pass. That audit was written in the same run as the code it checked. The checks now ship with xstack (`xstack-check`), and the results below come from its output. + +Test results: 245 of 245 Playwright tests pass across five browser profiles (macOS, 2026-11-19), covering all 19 pages for accessibility. + +Still open: + +- **Load tests** – k6 has not been run. +- **Wording** – the privacy and accessibility pages need review by the Medical Council and a content designer. + +**Recommended action:** keep the Constraints workflow as a required check, then move to the back end and the formal Standards self-assessment. ## What's in this build ``` -public/ ← 9 HTML pages + shared CSS + minimal app.js -tests/e2e/ ← 3 Playwright specs covering happy path, abroad context, error states +public/ ← 19 HTML pages + shared CSS + minimal app.js +tests/e2e/ ← 4 Playwright specs covering happy path, abroad context, error states, supporting pages tests/accessibility/ ← axe-core suite across every page in every state tests/security/ ← Playwright header tests + a bash script for CI without a browser tests/load/ ← k6 peak (Oct–Dec profile) and 8-hour soak tests -scripts/ ← serve, run-all, static audit +scripts/ ← serve, run-all +.xstack/ ← constraints.json and the vendored xstack-check runner playwright.config.ts ← 5-project matrix (Chromium, Firefox, WebKit, mobile Chrome, mobile Safari) package.json ← npm scripts for everything ``` @@ -41,8 +60,8 @@ package.json ← npm scripts for everything **Outstanding:** - Server-side validation needs to mirror the client patterns when the back end is wired up -- The CPD upload still uses a single GET form action for the static demo; production needs proper multipart POST with progress reporting -- The address-override flow is currently a placeholder link – needs the actual screens in iteration 4 +- The CPD upload posts to the local test server, which discards the file. Production needs a real multipart handler with progress reporting +- The pages for correcting details post to the local test server, which stores nothing. They need real handlers **Next action:** developer agent wires up server-side handlers per ADR-008. @@ -55,7 +74,7 @@ package.json ← npm scripts for everything - Stylesheet linked from `assets/govbb.css`; not inlined; placeholder for the published `@govtech-bb/styles` CDN - Playwright + axe-core + k6 are mainstream open-source tools, well-supported, easy to find skills for in the Caribbean tech market - All `govbb-` design-system classes used; no Tailwind, no bespoke colours -- Static audit confirmed CSS not inlined in any of the 9 pages +- `TECH-001` confirms CSS is not inlined in any of the 19 pages **Outstanding:** - Publish the design system to a CDN MIST can endorse, then swap the local CSS link for the CDN @@ -104,18 +123,63 @@ package.json ← npm scripts for everything ## Test results from this run -### Static audit – PASS +### Constraint evidence + +Generated by `xstack-check` at stage `ci` on 2026-11-19. Do not edit by hand – run the check again. + +#### Trust, security and privacy + +| Constraint | Result | Severity | Owner | Evidence | +|---|---|---|---|---| +| `SEC-001` No secrets in source | PASS | must | cyber-engineer | 41 file(s) or command(s) checked | +| `SEC-002` No inline event handlers | PASS | must | developer | 19 file(s) or command(s) checked | +| `SEC-003` No inline scripts | PASS | must | developer | 19 file(s) or command(s) checked | +| `SEC-008` No inline style attributes | PASS | must | developer | 19 file(s) or command(s) checked | +| `SEC-004` Forms that send files or passwords use POST | PASS | must | developer | 19 file(s) or command(s) checked | +| `SEC-005` No secrets leaked in git history or working tree (gitleaks) | NOT RUN | must | cyber-engineer | gitleaks is not installed | +| `SEC-006` No known high or critical vulnerabilities in dependencies | PASS | must | cyber-engineer | 1 file(s) or command(s) checked | +| `OPEN-001` No prototype chrome in production | PASS | must | developer | 19 file(s) or command(s) checked | +| `SVC-SEC-001` The server sends the six security headers, with a CSP that forbids inline script | PASS | must | cyber-engineer | 1 file(s) or command(s) checked | + +#### Sustainable and reliable + +| Constraint | Result | Severity | Owner | Evidence | +|---|---|---|---|---| +| `SEC-007` Dependencies are pinned by a lockfile | PASS | must | developer | 1 file(s) or command(s) checked | + +#### Inclusion + +| Constraint | Result | Severity | Owner | Evidence | +|---|---|---|---|---| +| `A11Y-001` Every page declares its language, has a title and a main landmark | PASS | must | content-designer | 19 file(s) or command(s) checked | +| `A11Y-002` Every image has an alt attribute | PASS | must | content-designer | 19 file(s) or command(s) checked | +| `SVC-A11Y-001` Every page in every state passes axe at WCAG 2.1 AA | PASS | must | content-designer | 1 file(s) or command(s) checked | + +#### Works first time + +| Constraint | Result | Severity | Owner | Evidence | +|---|---|---|---|---| +| `WFT-001` Every internal link and form action goes somewhere | PASS | must | developer | 19 file(s) or command(s) checked | +| `SVC-WFT-001` A doctor can renew end to end, including from abroad, through every error state and when correcting their details | PASS | must | developer | 1 file(s) or command(s) checked | + +#### Right technology + +| Constraint | Result | Severity | Owner | Evidence | +|---|---|---|---|---| +| `TECH-001` Styles are linked, not inlined | PASS | must | developer | 19 file(s) or command(s) checked | +| `BB-DS-001` Every page uses the GovBB design system and its skip link | PASS | must | content-designer | 19 file(s) or command(s) checked | + +#### Plain language + +| Constraint | Result | Severity | Owner | Evidence | +|---|---|---|---|---| +| `BB-STYLE-001` No em dashes in citizen-facing pages | PASS | must | content-designer | 19 file(s) or command(s) checked | + +**Total:** 17 pass, 0 fail, 0 waived, 1 not run, 0 not applicable. + +A theme can be rated **Met** only if every one of its constraints is PASS at the `ci` stage. FAIL, WAIVED and NOT RUN are at best **Partly met**. -| Check | Result | -|---|---| -| 9 HTML pages produced | ✅ PASS | -| HTML boilerplate (DOCTYPE, lang, title, description, stylesheet, main, skip link, landmarks) on every page | ✅ PASS – all 9 pages | -| CSS linked not inlined | ✅ PASS – all 9 pages | -| No xstack chrome in production (no banner, no assumptions panel, no fake-data spans, no Show-assumptions button, no verify-tag) | ✅ PASS – 5 of 5 forbidden terms absent | -| govbb- design-system class prefix used consistently | ✅ PASS | -| No m-dashes (house-style rule) | ✅ PASS – 0 found across 9 pages | -| Stylesheet present | ✅ PASS – `assets/govbb.css` (13KB) | -| Internal links and form actions resolve | ⚠️ 50 references to ancillary pages (help, privacy, accessibility, contact, feedback, address-override, etc.) – flagged as INFO because these are beta build-out items, not regressions | +`SEC-005` (gitleaks) is NOT RUN here because gitleaks is not installed on the machine that generated this table. It passes in CI, where `.github/workflows/constraints.yml` runs all 18 constraints on every pull request. ### Security headers – PASS (against live local server) @@ -174,14 +238,15 @@ The Standards self-assessment (`/xstack:assess for the beta gate`) is the formal **Proceed with conditions:** -1. **Wire the test suite into CI** before private beta opens to citizens. Required. -2. **Run the full Playwright matrix against staging** (5 device profiles). Required for Standards 3 and 5. -3. **Run the k6 peak load test against staging** (twice expected Oct–Dec volume). Required for Standards 5 and 13. -4. **Refresh the threat model** to cover the production form actions and the address-override flow. Required for Standard 11. -5. **Pen test plan signed off** before public beta. Cyber engineer owns; external supplier executes. -6. **Council backstage interface** scoped as a parallel `/xstack:build` track. Not blocking for private beta if Sandra and one or two officers can review applications manually; blocking for public beta. +1. **Keep every "must" constraint passing at the `ci` stage.** Done for this front-end: the Constraints workflow runs them on every pull request. Required. +2. **Run the same checks against staging** once there is a back end. Required. +3. **Run the full Playwright matrix against staging** (5 device profiles). It passes against the local server. Required for Standards 3 and 5. +4. **Run the k6 peak load test against staging** (twice expected Oct–Dec volume). Required for Standards 5 and 13. +5. **Refresh the threat model** to cover the production form actions and the address-override flow. Required for Standard 11. +6. **Pen test plan signed off** before public beta. Cyber engineer owns; external supplier executes. +7. **Council backstage interface** scoped as a parallel `/xstack:build` track. Not blocking for private beta if Sandra and one or two officers can review applications manually; blocking for public beta. -If conditions 1–4 are met, the team is ready for private beta on the front end. Conditions 5–6 must be met before public beta. +If conditions 1–5 are met, the team is ready for private beta on the front end. Conditions 6–7 must be met before public beta. --- diff --git a/examples/production-renew-medical-licence/README.md b/examples/production-renew-medical-licence/README.md index bb16df3..f0a1a8f 100644 --- a/examples/production-renew-medical-licence/README.md +++ b/examples/production-renew-medical-licence/README.md @@ -41,7 +41,10 @@ production-renew-medical-licence/ ├── scripts/ │ ├── serve.sh ← local server with the security headers set │ ├── run-all.sh ← orchestrator -│ └── audit.sh ← static checks (no browser, no k6) +│ └── run-all.sh ← orchestrator +├── .xstack/ +│ ├── constraints.json ← the rules this service must meet (protected: a person approves changes) +│ └── vendor/ ← xstack-check and its baseline and Barbados layers, copied from xstack ├── playwright.config.ts └── package.json ``` @@ -58,9 +61,10 @@ brew install k6 # macOS sudo apt-get install k6 # Ubuntu / Debian # or use the Docker image: docker pull grafana/k6 -# Serve and audit +# Serve and check npm run serve # http://localhost:8080, with the security headers set -npm run audit # static checks, no browser, no network +npm run check # constraint checks, no browser, no network +npm run check:ci # every constraint, including the ones that need a server, browsers and scanners # Run the test categories npm run test:e2e @@ -77,14 +81,14 @@ npm run test:all | Alpha prototype | Production build | |---|---| -| `prototype-1-phone-first/iteration-3/index.html` – one file with all 9 pages | 9 separate HTML files, one per URL | +| `prototype-1-phone-first/iteration-3/index.html` – one file with all 9 pages | 19 separate HTML files, one per URL: the 9 journey pages plus help, contact, feedback, privacy, accessibility and five pages for correcting details | | Inline `') }, + 'OPEN-001': { 'public/a.html': PAGE('') }, + }; + for (const [id, files] of Object.entries(cases)) { + const report = runChecks(service(files), 'stop'); + assert.equal(status(report, id), 'fail', id); + assert.equal(report.passed, false, id); + } +}); + +test('markup inside an HTML comment is neither credited nor blamed', () => { + const body = '\n
'; + const report = runChecks(service({ 'public/a.html': PAGE(body) }), 'stop'); + assert.equal(status(report, 'SEC-004'), 'fail'); + assert.equal(status(report, 'WFT-001'), 'pass'); +}); + +test('backend routes are not treated as dead links', () => { + const report = runChecks(service({ 'public/a.html': PAGE('
') }), 'stop'); + assert.equal(status(report, 'WFT-001'), 'pass'); +}); + +test('every bundled profile layer loads, and the template is valid', () => { + const profiles = path.join(HERE, '..', 'profiles'); + for (const name of fs.readdirSync(profiles)) { + if (!fs.existsSync(path.join(profiles, name, 'constraints.json'))) continue; + const report = runChecks(service({}, { extends: ['xstack:baseline', `profile:${name}`] }), 'stop'); + assert.ok(report.results.length > 13, name); + } +}); + +test('the Kestria layer passes the design system starter page and catches each mistake', () => { + const ds = path.join(HERE, '..', 'profiles', 'kestria', 'design-system'); + const read = (f) => fs.readFileSync(path.join(ds, f), 'utf8'); + const good = read('example.html'); + const kestria = (files) => { + const root = service({ 'public/tokens.css': read('tokens.css'), 'public/kestria.css': read('kestria.css'), 'public/example.html': good, ...files }, { extends: ['xstack:baseline', 'profile:kestria'] }); + for (const f of ['index.html', 'next.html']) fs.rmSync(path.join(root, 'public', f)); + return runChecks(root, 'stop'); + }; + const clean = kestria({}); + assert.deepEqual(clean.results.filter((r) => r.status === 'fail').map((r) => r.id), []); + + const add = (html) => good.replace('', `${html}`); + const cases = { + 'KS-DS-001': good.replace(/Kestria is a fictional country, used for demonstration\./, 'A demo.'), + 'KS-DS-002': good.replace(/\s*/, ''), + 'KS-DS-006': add(''), + 'KS-DS-004': good.replace(/kg-header__lang/g, 'kg-header__other'), + 'KS-DS-005': add(`

${'x'.repeat(100001)}

`), + 'KS-DATA-001': add('

Call +44 20 7946 0000 or write to help@example.com

'), + 'KS-DPI-001': add(''), + 'KS-DPI-002': add(''), + 'KS-STYLE-001': add('

Done \u{1F389}

'), + }; + for (const [id, html] of Object.entries(cases)) assert.equal(status(kestria({ 'public/example.html': html }), id), 'fail', id); + assert.equal(status(kestria({ 'public/page.css': '.x { color: #ff0000; }' }), 'KS-DS-003'), 'fail'); + // Things that must not trip the rules: anchors that look like hex, the reserved codes, token use. + const fine = add('

Add Call +999 77 100 2000 or write to help@spa.kestria.test. It costs K 900.

'); + const ok = kestria({ 'public/example.html': fine, 'public/page.css': '.x { color: var(--ink); } #add:target { outline: 3px solid var(--focus); }' }); + assert.deepEqual(ok.results.filter((r) => r.status === 'fail').map((r) => r.id), []); +}); + +test('waivers: active waives, expired and incomplete do not', () => { + const files = { 'public/a.html': PAGE('Gone') }; + const w = (over) => ({ waivers: [{ id: 'WFT-001', reason: 'r', approvedBy: 'A. Person', expires: '2999-01-01', ...over }] }); + assert.equal(status(runChecks(service(files, w({})), 'stop'), 'WFT-001'), 'waived'); + assert.equal(runChecks(service(files, w({})), 'stop').passed, true); + assert.equal(status(runChecks(service(files, w({ expires: '2020-01-01' })), 'stop'), 'WFT-001'), 'fail'); + assert.equal(status(runChecks(service(files, w({ approvedBy: '' })), 'stop'), 'WFT-001'), 'fail'); +}); + +test('a service cannot redefine a baseline constraint', () => { + const dup = { id: 'SEC-001', title: 't', theme: 't', source: 's', owner: 'o', severity: 'should', when: ['ci'], check: { type: 'file-exists', path: 'x' } }; + assert.throws(() => runChecks(service({}, { constraints: [dup] }), 'stop'), /defined twice/); +}); + +test('at the ci stage a must constraint that cannot run blocks', () => { + const c = { id: 'SVC-001', title: 't', theme: 't', source: 's', owner: 'o', severity: 'must', when: ['ci'], check: { type: 'command', requires: 'no-such-tool-xyz', run: 'true' } }; + const root = service({}, { constraints: [c] }); + const ci = runChecks(root, 'ci').results.find((r) => r.id === 'SVC-001'); + assert.equal(ci.status, 'not-run'); + assert.equal(ci.blocking, true); + assert.ok(!runChecks(root, 'stop').results.find((r) => r.id === 'SVC-001').blocking); +}); + +test('write guard: denies a bad write, asks on a protected path, ignores the rest', () => { + const root = service({}, { protected: ['tests/security/**'] }); + const call = (file_path, content) => hook('guard-write.mjs', { cwd: root, tool_name: 'Write', tool_input: { file_path, content } }); + assert.equal(decision(call('public/a.html', '')), 'deny'); + assert.equal(decision(call('src/k.js', FAKE_KEY)), 'deny'); + assert.equal(decision(call('.xstack/constraints.json', '{}')), 'ask'); + assert.equal(decision(call('tests/security/headers.sh', 'exit 0')), 'ask'); + assert.equal(decision(call('public/a.html', '

Fine

')), 'none'); + const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'xstack-none-')); + assert.equal(decision(hook('guard-write.mjs', { cwd: outside, tool_name: 'Write', tool_input: { file_path: path.join(outside, 'k.js'), content: FAKE_KEY } })), 'none'); +}); + +test('shell guard: asks before a command changes a protected path, and only then', () => { + const root = service({}, { protected: ['tests/security/**'] }); + const run = (command) => decision(hook('guard-bash.mjs', { cwd: root, tool_name: 'Bash', tool_input: { command } })); + for (const c of [ + "sed -i '' 's/must/should/' .xstack/constraints.json", + 'rm .xstack/constraints.json', + 'echo "{}" > .xstack/constraints.json', + 'cp /tmp/x.mjs .xstack/vendor/xstack-check.mjs', + 'git checkout HEAD~3 -- tests/security/headers.sh', + 'cd public && echo "exit 0" >> ../tests/security/headers.sh', + ]) assert.equal(run(c), 'ask', c); + for (const c of [ + 'node .xstack/vendor/xstack-check.mjs --stage ci', + 'node .xstack/vendor/xstack-check.mjs --stage ci --format md > evidence.md', + 'cat .xstack/constraints.json', + './tests/security/headers.sh http://localhost:8080', + 'npx playwright test tests/security', + 'rm -rf node_modules && npm ci', + 'git status', + ]) assert.equal(run(c), 'none', c); + const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'xstack-none-')); + assert.equal(decision(hook('guard-bash.mjs', { cwd: outside, tool_name: 'Bash', tool_input: { command: 'rm .xstack/constraints.json' } })), 'none'); +}); + +test('stop gate: sends the agent back once, records the result, skips when unchanged', () => { + const bad = service({ 'public/a.html': PAGE('Gone') }); + const first = hook('stop-gate.mjs', { cwd: bad, stop_hook_active: false }); + assert.equal(first.status, 2); + assert.match(first.stderr, /WFT-001/); + assert.equal(hook('stop-gate.mjs', { cwd: bad, stop_hook_active: true }).status, 0); + assert.equal(JSON.parse(fs.readFileSync(path.join(bad, '.xstack', 'check-report.json'), 'utf8')).passed, false); + + const good = service(); + assert.equal(hook('stop-gate.mjs', { cwd: good }).status, 0); + const reportPath = path.join(good, '.xstack', 'check-report.json'); + const before = fs.readFileSync(reportPath, 'utf8'); + assert.equal(hook('stop-gate.mjs', { cwd: good }).status, 0); + assert.equal(fs.readFileSync(reportPath, 'utf8'), before); +}); diff --git a/skills/build-for-production/SKILL.md b/skills/build-for-production/SKILL.md index fa46835..538c950 100644 --- a/skills/build-for-production/SKILL.md +++ b/skills/build-for-production/SKILL.md @@ -9,8 +9,9 @@ This skill is the bridge between a validated alpha prototype and the front-end o 1. **Per-page HTML files** with proper URLs, real navigation (links and forms, not JS state), the design system's published stylesheet linked rather than inlined, the xstack assumptions panel and mock-data markers stripped. 2. **A comprehensive test suite** – E2E regression (Playwright), accessibility (axe-core), security (headers, CSP, basic OWASP checks), and load (k6). -3. **A runner** that orchestrates the suite locally and in CI. -4. **A production-readiness report** assessed against the **Works first time**, **Right technology**, **Trust, security and privacy** and **Measuring performance** themes (or the profile's own standards that map to them). +3. **A constraints file** – the rules the service must meet, checked by a runner that ships with xstack, not one written during the run. +4. **A runner** that orchestrates the suite locally and in CI. +5. **A production-readiness report** built from the check results and assessed against the **Works first time**, **Right technology**, **Trust, security and privacy** and **Measuring performance** themes (or the profile's own standards that map to them). It supports the transition from alpha to beta. It explicitly does **not** make the service production-ready end to end – the backend, the integrations, the threat model, the runbook, and the operational readiness are owned by the developer, the cyber engineer, and the delivery manager via other parts of xstack. This skill is the front-end's half of beta-readiness. @@ -67,8 +68,10 @@ production-[service-slug]/ │ └── soak.js ← k6 8-hour soak test ├── scripts/ │ ├── serve.sh ← local server for testing -│ ├── run-all.sh ← orchestrator -│ └── audit.sh ← static checks (HTML validity, link integrity, design-system class usage) +│ └── run-all.sh ← orchestrator (starts with xstack-check) +├── .xstack/ +│ ├── constraints.json ← the rules this service must meet; a person approves changes +│ └── vendor/ ← xstack-check.mjs and its layers, copied from xstack ├── playwright.config.ts └── package.json ``` @@ -94,6 +97,18 @@ The production HTML is **progressive enhancement**: every flow works without Jav --- +## Constraints – the rules are enforced, not remembered + +Read `constraints/README.md` before you start. In short: + +- **Write `.xstack/constraints.json` first**, before any page. It extends `xstack:baseline`, plus `profile:` if the profile has a `constraints.json`. Then copy the runner in: `node "$CLAUDE_PLUGIN_ROOT/scripts/xstack-check.mjs" --vendor --root production-[service-slug]`. +- **Add the service's own constraints**: one `command` constraint per test suite (accessibility, E2E, security headers), and one per threat-model control that can be checked. List `tests/security/**` and `tests/accessibility/**` as `protected`. +- **Never write an audit script.** The static checks are the shipped runner's job. A checker written in the same run as the code it checks will pass whatever that run produced. +- **Once the file exists, xstack's hooks enforce it.** A write that breaks a `write`-stage constraint is refused. You cannot finish while a "must" constraint fails at the `stop` stage. Fix the code, not the check. +- **If a constraint cannot be met, say so.** Report it as failing, name the constraint id, and ask the user whether to fix it or record a waiver. Only a person adds a waiver or changes the constraints file. + +--- + ## The test suite – what it covers ### Regression (Playwright) @@ -154,7 +169,7 @@ If thresholds fail, the beta gate is not met for **Works first time**. - **Write the backend.** Identity-platform integration, payment-platform calls, the back-office review queue, session management – these are the developer's responsibility, designed in ADRs and built in beta. - **Run the pen test.** That's the cyber engineer's job, with an external supplier, before public beta. -- **Configure CI/CD.** The team picks the platform (GitHub Actions, GitLab CI, etc.) and wires the runner script in. +- **Configure CI/CD.** The team picks the platform (GitHub Actions, GitLab CI, etc.) and wires the runner script in. For GitHub Actions, offer `constraints/ci/github-actions.yml` as the starting point – it runs every constraint at the `ci` stage. - **Deploy the service.** Hosting and deployment is part of beta operational readiness. - **Replace the threat model.** The security tests in this skill cover the front end. The threat model covers the whole system. @@ -172,9 +187,9 @@ When invoked, the skill: 6. **Strips alpha-only markup** – assumptions panel out, xstack banner out, fake-data markers replaced with semantic placeholders 7. **Generates the test suite** based on the journey it just split 8. **Writes the scripts and config** -9. **Runs the static checks** – HTML validity, link integrity (do internal links resolve?), design-system class usage (are we using the design system's class prefix consistently?) -10. **Attempts to run the dynamic tests** if the environment has the tooling; otherwise reports what would happen -11. **Writes PRODUCTION-READINESS.md** with the assessment +9. **Runs the constraint checks** – `node .xstack/vendor/xstack-check.mjs --stage stop` – and fixes what fails +10. **Attempts the `ci` stage** (`--stage ci`), which runs the dynamic tests if the environment has the tooling. What cannot run is reported as NOT RUN, never as a pass +11. **Writes PRODUCTION-READINESS.md** – paste the output of `--format md` as the evidence section, then rate each theme from it. Met needs every constraint for that theme to pass at the `ci` stage, and each rating cites its constraint ids The skill calls into the developer agent for technical decisions and the cyber engineer agent for the security tests. @@ -231,7 +246,8 @@ By the end of the skill's run, the team should have: - A `public/` folder they can serve with a one-line static server, and the journey works end-to-end without JavaScript - A `tests/` folder that runs locally with `npm test` -- A `PRODUCTION-READINESS.md` with each standard (or theme) marked Met / Partly met / Not met, with evidence +- A `.xstack/constraints.json` whose "must" constraints all hold at the `stop` stage, or a plain list of the ones that do not +- A `PRODUCTION-READINESS.md` with each standard (or theme) marked Met / Partly met / Not met, with the constraint ids as evidence - A clear next-step list: what the cyber engineer needs to do, what the developer needs to wire up to the backend, what the delivery manager needs to set up for operational readiness If the report has `Not met` for any of the four themes above, the team is not ready for the beta gate. **Trust, security and privacy** is the most common reason – the front-end can pass and the backend can still fail. That's a `/xstack:threat-model` and pen-test conversation, not a `/xstack:productionise` retry. diff --git a/skills/help/SKILL.md b/skills/help/SKILL.md new file mode 100644 index 0000000..4039f90 --- /dev/null +++ b/skills/help/SKILL.md @@ -0,0 +1,139 @@ +--- +name: help +description: Show someone new to xstack how to use it – open the staircase, the interactive map of every step from first conversation to a live service, then find out where they are and tell them the one thing to run next. Use when someone has just installed xstack, asks what it does, or doesn't know which skill or command to use. Triggers on "/xstack:help", "help with xstack", "how do I use xstack", "what can xstack do", "where do I start", "I'm new to xstack", "what should I run", "show me the staircase", "which skill do I use". +--- + +# Help + +This skill gets someone new to xstack to their first useful step. It does three things, in this order: + +1. Shows the staircase +2. Finds out where they are +3. Tells them the one thing to run next + +Keep it short. A new person wants to start, not to read a manual. Don't list every skill in chat – the staircase does that. + +--- + +## 1. Show the staircase + +The staircase is one interactive page: `assets/staircase.html`, in this skill's folder. It shows the five steps a team climbs – Setup, Discovery, Alpha, Beta, Live – with the main thing to run on each step and the skills that support it. Tapping any skill shows what comes before it and what it leads to. + +Show the page as it is. Don't rewrite it, restyle it or redraw it as a diagram. + +- **If you can publish or preview a page** (an artifact, a preview pane or a browser), show it there. +- **If you can only write files**, copy it to the project folder as `xstack-staircase.html` and give the person the link. In a terminal, offer to open it for them. +- **If you can't show a page at all**, use the short version below. + +Then say, in two or three sentences, how to read it: start at the bottom left and climb. The dark button on each step is the thing you run to move up. Everything around it helps you do that well. + +### The short version + +Use this only when you can't show the page. + +| Step | What you do | Run | +|---|---|---| +| 0 Setup | Tell xstack which government you work for. You do this once | `/xstack:profile` | +| 1 Discovery | Talk to people. Understand how things work today | `/xstack:discover` | +| 2 Alpha | Try several ideas, test them with people, improve them | `/xstack:build`, then `/xstack:iterate` | +| 3 Beta | Build the real thing and keep people's information safe | `/xstack:productionise`, `/xstack:threat-model` | +| 4 Live | Keep listening, and go round again | back to `/xstack:discover` | + +Every week, at every step: `/xstack:weeknote`, `/xstack:show`, `/xstack:plain-language`. Before every step up: `/xstack:assess`. + +--- + +## 2. Find out where they are + +First, look for yourself: + +- Is there a country profile – `.xstack/profile.md` in the project, or a line like `xstack profile: ` in the project's `CLAUDE.md`? +- Are there prototypes, a form spec, a discovery report or research notes in the project? + +Then ask one question, using the AskUserQuestion tool if you have it. Leave out any answer you have already ruled out. + +**Where are you with your service?** + +- We're just starting +- We have a paper or PDF form +- We have a brief or a discovery report +- We have a prototype and feedback from testing +- We're ready to build the real thing +- I'm just looking around + +If they have already told you what they want to do, don't ask. Go to step 3. + +--- + +## 3. Tell them the one thing to run next + +Give one next step, not a menu. Say what to type, what to give it, and what comes out. + +| Where they are | Next step | What comes out | +|---|---|---| +| No profile yet | `/xstack:profile` | A country profile, so xstack uses their government's standard, design system and shared platforms. They can skip this – xstack falls back to its baseline and says so | +| Just starting | `/xstack:discover` | A problem statement, stakeholder map, research plan and interview guide | +| Has a paper or PDF form | `/xstack:form-to-spec` | A form spec that keeps every item, ready to use as the brief for `/xstack:build` | +| Has a brief or discovery report | `/xstack:build` | Several clickable prototypes to test, with their assumptions listed | +| Has a prototype and feedback | `/xstack:iterate` | The next version, with a note of what changed and why | +| Ready to build the real thing | `/xstack:productionise` | A production-ready front end with tests | +| Just looking around | Nothing yet | Point them to the staircase and to `GETTING-STARTED.md` | + +If there is no profile and they want to start work, mention the profile once and let them choose. Don't block them. + +If they are stuck on research, send them to the `xstack:research-coach` skill. It works out where they are in the research cycle. If they don't know which specialist to ask, send them to the delivery manager, who routes. + +### Use the name that works where they are + +The staircase shows command names such as `/xstack:build`. These work in Claude Code. In the Claude app and Cowork, the `/` menu runs skills, so give the skill name instead, or tell them to ask in plain words. + +| Command (Claude Code) | Skill (Claude app and Cowork) | +|---|---| +| `/xstack:discover` | `/discovery-kit` | +| `/xstack:form-to-spec` | `/form-to-spec` | +| `/xstack:build` | `/brief-to-prototypes` | +| `/xstack:iterate` | `/prototype-iteration` | +| `/xstack:productionise` | `/build-for-production` | +| `/xstack:review` | `/service-design-review` | +| `/xstack:assess` | `/service-standard-assessment` | +| `/xstack:plain-language` | `/plain-language-check` | +| `/xstack:show` | `/show-the-thing` | +| `/xstack:weeknote` | `/weeknote` | +| `/xstack:design-system` | `/government-design-systems` | +| `/xstack:dpi` | `/government-dpi` | +| `/xstack:profile` | No skill – ask "Using xstack, set up our country profile" | +| `/xstack:threat-model` | No skill – ask the cyber engineer for a threat model | + +If a `/` name fails with "Unknown command", tell them to ask in plain words instead, starting with "Using xstack, …". Claude picks the right skill. + +--- + +## Where to read more + +Offer these only if the person asks for more: + +- `GETTING-STARTED.md` – the quick start, about five minutes +- `MANUAL.md` – the full onboarding guide, with a worked example +- `PLAYBOOK.md` – what a team does week by week, phase by phase +- `AGENTS.md` – the five specialists and when to ask each one + +--- + +## What good looks like + +- The person has seen the staircase, or the short version +- They know which step they are on +- They have one thing to type next, in a name that works where they are +- The whole reply fits on one screen + +--- + +## Keeping the staircase true + +The staircase is only useful if it matches what xstack has. When you add, rename or remove a skill or command, update `assets/staircase.html` in the same change: + +- `N` holds one entry per skill, command and file, with its plain-language description +- `E` holds the links – what comes before and after each one +- `STEPS` places each entry on a step + +The page is a single file with no build step. It follows the reader's light or dark setting. diff --git a/skills/help/assets/staircase.html b/skills/help/assets/staircase.html new file mode 100644 index 0000000..22bd934 --- /dev/null +++ b/skills/help/assets/staircase.html @@ -0,0 +1,273 @@ + + + + + +xstack Staircase + + + + + + +
+
+

From first conversation to a live service

+

This is the path a team takes with xstack. Each step is a stage of the work. The dark button on each step is the thing you do to move up. Everything around it helps you do that well. Tap any skill to see what comes before it and what it leads to.

+
+
+ uses your design system + uses your shared platforms + Every skill starts by reading your country profile + comes before + comes after +
+
+
+
+

Every week, at every stage

+
+

Write a weeknote. Show your work to real people. Check your words are plain. And before you move up a step, take an honest look at how you're doing against the standard.

+
+
+ + + + +