# Chapter 5 — Scripts, References and Assets

> Move arithmetic into scripts and provide references, assets and reproducible display strings.

*Felix Reyes · The Skills Pack · First edition, 2026 · [CC BY 4.0](../LICENSE) · [Router](../SKILL.md)*

<a id="ch-scripts"></a>

Chapter [4](04-the-skill-file.md#ch-skillfile) wrote the skill file, and its draft ended on a step that runs a script nobody had written. This chapter finishes step 4, Write the skill, with the three folders that sit beside `SKILL.md`: `scripts/` contains the programs that make every figure, `references/` the rules the model reads when it applies judgment, and `assets/` the files a script reads or fills, such as a brand file. Two rules join them: the model never computes, and every path starts from the installed pack.

The specification recommends these folder names. The deck leaf has the first two, and its script reads the one asset in the four packs.

The chapter reads the budget-vs-actual script, `bva.py`, in four excerpts, then takes up what every script shares: flags, one output file and three exit codes. It ends with the budget-vs-actual draft of Chapter [4](04-the-skill-file.md#ch-skillfile) turned into a skill a host can run.

## Why the model never computes

<a id="sec-scripts-why"></a>

A figure a model writes into a note can be checked only by doing the work again. A figure a script writes can be checked twice, and neither check trusts the model. Run the script again on the same file and the output must be identical. Recompute the figure from the source file with a different program and it must agree. The first check finds a script that is not deterministic, and the second finds one that is wrong.

Chapter [3](03-sorting-the-work.md#ch-sorting) drew the boundary: a step that makes a number is compute, including the rounding and the choice of unit. The router of the Variance and Bridge pack states the rule first:

File: `packs/variance-bridge/SKILL.md` (lines 31–31).

```markdown
1. Numbers come from scripts. Never calculate, round or restate a figure yourself.
```

The word that matters is “restate”. A model that rewrites the script’s `($443K)` as “down 443 thousand” has made a new figure from an old one. This book’s checks match exact display strings: the script printed no string “443”, so the provenance check fails the note, and the reviewer judges whether the restatement is right.

**Figure — text equivalent.**

`bridge.py` reads `--input <csv>` and optional `--py-col` / `--cy-col`. It writes `--output bridge.json` with `input` (file, SHA-256, rows), exact `totals`, `counts`, `identity` (ok, lhs, cy) and `display` strings. Exit 0 means success; exit 2 means bad input; exit 3 means it does not reconcile. The illustrated stdout reads: `FY2024 $11,243K -> FY2025 $11,238K`, `change ($5K), (0.04%); reconciles to the cent.`, then `Wrote bridge.json`.

<a id="fig-script-io"></a>

A pack script, drawn as the revenue bridge’s `bridge.py`: two kinds of flag in, one JSON file and one line of standard output out, and three exit codes.

Which script languages a host runs is up to the host. The book’s scripts are Python on the standard library alone, except the deck builder, whose pack’s `compatibility` field lists its one extra package. Chapter [12](12-the-host-interface.md#ch-hosts) answers host by host whether scripts run at all, and Figure [5.1](05-scripts-references-and-assets.md#fig-script-io) shows the shape every script has.

## A script writes what the contract fixes

<a id="sec-scripts-why-model"></a>

The output contract of Chapter [6](06-output-contracts.md#ch-contracts) fixes the sections, the table and most of the headline, and leaves the model one free section and the sentences. A program can copy the rest.

The rule, for a new production skill, is that a script renders the fixed sections wherever it reliably can and the model writes what needs judgment. The model can miscopy any string it copies: in the edition’s repeat runs at version 1.0.0 the third model wrote a figure no script printed in 20 of its 60 runs, the first primary model in 1 and the second in none (Chapter [12](12-the-host-interface.md#ch-hosts) has the record).

The budget-vs-actual leaf applies the rule. Run with `--note`, `bva.py` reads the `output/bva.json` it wrote and writes `output/bva-note.md`: Headline, Results, Month and Data notes filled from the display strings, and Drivers left as one marked line. Step 5 of the leaf has the model replace that line and leave every other section as written (Chapter [4](04-the-skill-file.md#ch-skillfile)). Here is the script’s output for the case, to the marked line:

File: `packs/variance-bridge/tests/golden/budget-vs-actual-note.md` (lines 1–14).

```markdown
## Headline

YTD 2025 revenue was $11,238K against a $11,600K budget, unfavourable by ($362K), or (3.1%); operating income $388K against $583K, unfavourable by ($195K), or (33.5%).

## Results

| Measure | Actual | Budget | Variance |
| --- | --- | --- | --- |
| Revenue | $11,238K | $11,600K | ($362K) |
| COGS | $8,324K | $8,491K | $167K |
| Gross profit | $2,914K | $3,109K | ($194K) |
| Gross margin | 25.9% | 26.8% | (0.9) pts |
| Operating expenses | $2,527K | $2,526K | ($1K) |
| Operating income | $388K | $583K | ($195K) |
```

File: `packs/variance-bridge/tests/golden/budget-vs-actual-note.md` (lines 16–22).

```markdown
## Month

December 2025 revenue was $827K against a budget of $824K, a favourable $3K. Operating income was $8K against $13K, an unfavourable ($5K).

## Drivers

<!-- Drivers: replace this line with the bullets the contract asks for; edit no other line -->
```

Because the script wrote the fixed sections, a check can compare the note with them. The leaf’s check `rendered_sections_match` runs the renderer again on the run’s `bva.json`, compares every section but Drivers with the note, and requires that the marked line is gone and Drivers is not empty. The contract and the other checks are unchanged. In a 2.0.0 run on the first primary model its detail line read “Headline, Results, Month and Data notes are bva.py --note’s output for output/bva.json, line for line; Drivers holds 4 lines of the model’s in place of the placeholder”.

Rendering takes the fixed figures, the table rows and the data notes away from the model. The model still writes Drivers, which can go wrong in four ways: which lines the bullets select, which figure goes with which line, which way a variance runs, and what is left out. The provenance check fails a figure no script printed. The binding check catches some wrong pairings: a figure beside a known record name it does not belong to (Chapter [6](06-output-contracts.md#ch-contracts)). No check sees an omission or a misread direction, and Section [9.1](09-testing.md#sec-testing-reading) says what the reviewer looks for in Drivers.

Rendering has not been shown to raise the pass rate on the smaller model. On the third model, budget-vs-actual passed 2 of 3 at 1.0.1, which wrote the full note, and 1 of 3 at 1.1.0, which renders it. The 1.0.1 failure was in the headline, a fixed section. Both 1.1.0 failures were in Drivers. In each run the model summed three months itself, `$360K` in one and `($360K)` in the other, and dropped or added signs. Every 1.1.0 run’s fixed sections matched the renderer. At 2.0.0 it passed 2 of 3, and the re-check agreed. The failed run’s fixed sections matched too, and its fault was in Drivers: two favourable percentages put in parentheses. Three runs a version, on one host and one model family, show no trend either way.

One leaf of the sixteen has a renderer in this edition, and no other is converted for the sake of uniformity. The revenue bridge, and with it the tutorial of Chapter [1](01-a-tutorial-introduction.md#ch-tutorial), stays full-note because it is the simplest working skill. The KPI scorecard stays full-note for two reasons. Its contract already gives every fixed line as a template of display strings, and its runs have shown no fixed line copied wrong: the repeat-suite failures at 1.0.0 and 2.0.0 were figures in the model’s own sentences (Section [11.2](11-four-complete-packs.md#sec-complete-management-reporting)), and at 1.1.0 it passed 3 of 3 on each model. A leaf is converted when its runs show the model copying fixed sections wrong, as budget-vs-actual’s 1.0.0 runs did. The conversion follows that leaf’s pattern, and it is a version change that needs new runs. Section [9.11](09-testing.md#sec-testing-baseline) compares a plain prompt, the pack and the renderer experiment, `tools/render_note.py`, on the same requests.

## The script in four excerpts

<a id="sec-scripts-bridge"></a>

The budget-vs-actual script, `bva.py` under `packs/variance-bridge/skills/budget-vs-actual/scripts/`, is 431 lines long, imports only from the standard library, and keeps every figure in a `Decimal` rounded with `ROUND_HALF_UP`. The first of four excerpts is the input policy: the pattern at line 40 and `to_money`, lines 49 to 55.

File: `packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py` (lines 40–40).

```python
NUMBER = re.compile(r"-?(\d{1,3}(,\d{3}){0,4}|\d{1,15})(\.\d+)?", re.ASCII)  # no 1e3, NaN or Infinity
```

File: `packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py` (lines 49–55).

```python
def to_money(raw: str | None, where: str) -> Decimal:
    """Digits, an optional minus sign, thousands commas and decimals, at most 15 digits before the point;
    a blank is bad input, never zero."""
    text = (raw or "").strip()
    if not NUMBER.fullmatch(text):
        raise InputError(f"{where} is blank" if not text else f"{where}: '{raw}' is not a number")
    return Decimal(text.replace(",", "")).quantize(CENT, rounding=ROUND_HALF_UP)
```

`NUMBER` is the whole of what a cell may contain: an optional minus, digits with or without thousands separators, and an optional fraction. `NaN`, `Infinity` and an exponent such as `1e3` are values Python’s `Decimal` accepts and finance does not, and the pattern refuses them before any arithmetic: “line 2 budget: ’Infinity’ is not a number”. The script does not read a blank as zero: a blank in a required column is bad input, exit 2 with the line and column named. `to_money` turns the cell into an exact decimal rounded half up to the cent, because binary floating point cannot represent most cent amounts, and a sum that must reconcile to the cent cannot be allowed to drift (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.6.7 and 3.6.12).

The second excerpt is the sign, lines 136 to 142:

File: `packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py` (lines 136–142).

```python
def variance(category: str, actual: Decimal, budget: Decimal) -> Decimal:
    """Favourable-positive: more revenue or profit, or less cost, than budget."""
    return budget - actual if category in ("COGS", "Opex") else actual - budget


def direction(v: Decimal) -> str:
    return "favourable" if v > 0 else "unfavourable" if v < 0 else "on budget"
```

A cost line’s variance is budget less actual and a revenue line’s is actual less budget, so a positive variance is favourable on every line and one function covers row 4a of the sort sheet, sign by category, for every line type (Table [3.2](03-sorting-the-work.md#tab-sorting-sheet-bva)). `direction` turns the sign into a word. `bva.py` has the display functions of the pack standard (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.7.2), and its `in_k`, `fmt_k` and `fmt_pct` are exact copies of `bridge.py`’s, which the repository test `test_fmt_functions_are_verbatim_copies` enforces: a display rule is written once and copied, so two scripts cannot print one amount two ways. `fmt_k` prints every amount in thousands with separators, each rounded half up on its own, and an amount that is not zero but would print as `$0K` keeps the fewest decimals that show it: 437.89 prints `$0.4K`. A negative goes in parentheses and zero never does. `fmt_pct` prints one decimal, or two below one percent, and `fmt_pts` ends a difference of two percentages in `pts`.

The third excerpt is `peaks`, lines 178 to 189:

File: `packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py` (lines 178–189).

```python
def peaks(rows: list[dict], category: dict[str, str], periods: list[str]) -> list[dict]:
    """Per line, the largest year-to-date variance (in absolute value) reached in any month, and that month."""
    out = []
    for line in category:
        run, best = Decimal("0"), {"period": periods[0], "variance": Decimal("0")}
        for p in periods:
            run += sum((variance(category[line], r["actual"], r["budget"]) for r in rows
                        if r["period"] == p and r["line_item"] == line), Decimal("0"))
            if abs(run) > abs(best["variance"]):
                best = {"period": p, "variance": run}
        out.append({"line_item": line, **best})
    return out
```

It keeps each line’s largest year-to-date variance and its month, and stops there: the model says whether the line came back (Table [3.2](03-sorting-the-work.md#tab-sorting-sheet-bva), row 9b).

The fourth excerpt is the identity: the lines of `build` that set `ok`, 231 to 234, and the `identity` block of the output, 266 to 270:

File: `packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py` (lines 231–234).

```python
    monthly_sum = sum((m["variance"] for m in monthly), Decimal("0"))
    ok = monthly_sum == ytd["subtotals"]["revenue"]["variance"] and all(
        s["identity"]["oi_from_lines"] == s["identity"]["oi"]
        and s["identity"]["variance_sum"] == s["identity"]["oi_variance"] for s in (month, ytd))
```

File: `packs/variance-bridge/skills/budget-vs-actual/scripts/bva.py` (lines 266–270).

```python
        "identity": {"ok": ok,
                     "month": {k: money(v) for k, v in month["identity"].items()},
                     "ytd": {k: money(v) for k, v in ytd["identity"].items()},
                     "monthly_revenue_sum": money(monthly_sum),
                     "ytd_revenue_variance": money(ytd["subtotals"]["revenue"]["variance"])},
```

Operating income from the lines must equal operating income from the subtotals and the line variances must sum to the operating-income variance, each for the month and for the year to date, and the monthly revenue variances must sum to the year-to-date revenue variance. When any fails the script exits 3 and still writes the file, with both sides of each identity. This is the script’s check on itself. A script with a bug can pass its own identity, and a result built from a different file still adds up, so Chapter [9](09-testing.md#ch-testing) adds an independent identity that checks the input’s hash and recomputes the same figures from the CSV without the script.

A percentage whose budget is zero is `n/a` rather than `0%`, in the exact block and the display block alike, and the contract tells the model to copy the string (Chapter [6](06-output-contracts.md#ch-contracts)). Exact amounts are strings with two places and exact ratios have four, so no program that reads the file can round them on the way in. `main`, which the excerpts leave out, turns a refused input, a failed identity and a file that reconciles into the three exit codes of Section [5.5](05-scripts-references-and-assets.md#sec-scripts-exit).

**Exercise 5-1.** `bridge.py`’s `build` reads the input with `read_bytes()` and decodes it afterwards. Why not open the file as text? Name the check in `packs/variance-bridge/tests/checks.py` that depends on the answer.

**Exercise 5-2.** Find, to the cent, the smallest amount that `fmt_k` prints as `$1K` and the largest it prints as `$0.5K`, and say what it prints for one cent and for zero. Import `bridge.py` with `python3 -B`, so that no `__pycache__/` is left in the pack, and verify all four.

**Exercise 5-3.** Make three copies of `data/interstationary/customers_fy24_fy25.csv`: one with a blank `fy2025_revenue` on its first data row, one with `NaN` in `fy2024_revenue` on that row, and one in which every customer’s `fy2024_revenue` is `0.00`. Run `bridge.py` on each and report the exit code and the message. The third copy does not run: say why, make the smallest change that lets it, and report `display.change_pct` and the identity.

## Inputs, flags and the one output file

<a id="sec-scripts-io"></a>

A script takes `--input` and `--output`, and as few other flags as the data forces. `bridge.py` adds `--py-col` and `--cy-col` for a file whose revenue columns follow neither naming rule. `bva.py` adds `--period`, because a P&L file contains many months and the note is about one of them, and, in this leaf, `--note` (Section [5.2](05-scripts-references-and-assets.md#sec-scripts-why-model)). A script with several inputs takes one named flag per input in place of `--input`, such as the forecast-accuracy script’s `--forecasts` and `--actuals`. A threshold is a flag with a default, and the skill file states the default (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.6.3).

The script writes one JSON file, and its top-level keys come in a fixed order: `schema`, `input`, `labels`, the exact figures, `identity`, `display`. Here are the first three in the budget-vs-actual golden file, lines 1 to 14:

File: `packs/variance-bridge/tests/golden/budget-vs-actual.json` (lines 1–14).

```json
{
  "schema": "budget-vs-actual/2",
  "input": {
    "file": "pnl_fy2025.csv",
    "sha256": "eaa52ac89e9734eea433cf97a03ed584899f51566e3fb68cfb12b0f2ee88ec7b",
    "rows": 120,
    "period": "2025-12",
    "months_ytd": 12
  },
  "labels": {
    "period": "2025-12",
    "period_name": "December 2025",
    "ytd": "YTD 2025"
  },
```

`input` records the file name without its folder, the full hash, the row count and the choices the script made: here the month it took when no `--period` was passed, and the months in the year to date.

The display block is the last key. It contains every figure the deliverable may use, each one a string formatted by the display rules (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.7.2), and it opens with the display input block Chapter [1](01-a-tutorial-introduction.md#ch-tutorial) printed: the file name, the row count and the first 12 characters of the hash, the three strings the data notes copy (Chapter [6](06-output-contracts.md#ch-contracts)).

A script with several inputs writes `inputs`, a list shaped like `input` in flag order, and `display.inputs`, keyed by the flag that took each file, so that the data notes can name every file.

On exit 0 a script prints one line to standard output: the headline figures from the display block and the path it wrote.

## Exit codes and stopping

<a id="sec-scripts-exit"></a>

A script’s exit code tells the skill file what happened. There are three.

- `0`: the output file is complete and every identity holds.

- `2`: bad input: a missing file or column, a blank in a required column, a value that is not a finite number, a duplicate key or a period the file does not contain. One line on standard error starts `error:` and names the place, and nothing is written to `--output`. A missing or unknown flag also exits 2, reported by the argument parser in its own form.

- `3`: an identity failed after the input was read and computed. The JSON is written for diagnosis, and the line on standard error says the figures must not be reported.

Code 1 is left for crashes, and no script sets it deliberately (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.6.5). Table [5.1](05-scripts-references-and-assets.md#tab-scripts-exit-codes) collects the messages of two scripts, each run on a file edited to provoke it. Each message says what is wrong and where. With `--note`, `bva.py` exits 3 on a result whose identity failed, prints the same line, and writes no note.

<a id="tab-scripts-exit-codes"></a>

Exit codes and messages of two scripts, and what the skill file says to do: the revenue-bridge leaf for `bridge.py`, the stage of Section [5.9](05-scripts-references-and-assets.md#sec-scripts-stage) for `bva.py`.

| Exit | Script | Message | The skill file says |
| --- | --- | --- | --- |
| 2 | `bridge.py` | `error: line 2 fy2025_revenue is blank` | show the error and stop |
| 2 | `bridge.py` | `error: line 3: timing_amount exceeds current-year revenue for IS-002` | show the error and stop |
| 2 | `bva.py` | `error: line 2 budget: ’Infinity’ is not a number` | show it; ask for a corrected file |
| 2 | `bva.py` | `error: missing column ’budget’` | show it; ask for a file that has the column |
| 2 | `bva.py` | `error: period 2025-13 is not in the file, which runs from 2025-01 to 2025-12` | show it; ask for a month the file contains |
| 3 | `bridge.py` | `error: bridge does not reconcile; do not report these figures` | show the error and stop; report no figure |
| 3 | `bva.py` | `error: the variances do not reconcile; do not report these figures` | show the error and stop; report no figure |

Exit 3 is rarer. In `bridge.py` every branch both classifies and adds, so no input that passed the row tests can break the identity and an exit 3 means the script is wrong. The forecast-accuracy script’s identity ties two inputs, so it also exits 3 when they disagree. The message, “do not report these figures”, is a control: with the skill file’s stop gate, it keeps a figure that does not reconcile out of any note.

The skill file’s gates read these codes, and each tells the model to show the message rather than count on the host to pass standard error along.

**Exercise 5-4.** Run `bridge.py` on the customer file with `--py-col fy2024_revenue` and no `--cy-col`, then again with no `--input`. Report each exit code and what reaches standard error. Which message does the script write itself, and which comes from the argument parser?

**Exercise 5-5.** In a copy of `bridge.py`, delete the line in the decline branch that adds to `totals`. Run the copy on `data/interstationary/customers_fy24_fy25.csv`. Report the exit code, the message, and what `identity` says in the file it wrote. Was the file written, and should it have been?

## References: rules read on demand

<a id="sec-scripts-references"></a>

A reference is a file under a leaf’s `references/` folder that contains what the model reads to apply judgment: definitions, a method, the meaning of a metric. The specification says agents load such files on demand, so a reference uses no context until the model needs it. The pack standard keeps every reference one level from the skill file that names it (Appendix [A](appendix-a-reference-manual.md#app-reference), 2.8). A reference explains the rules, the script applies every rule that makes a figure, and the two change together.

A reference longer than 100 lines opens with a contents list, because a file reached through the router and then its leaf may be read only in part, from its first lines. The validator warns about a longer reference without one (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.9.4). None of the six references in the packs reaches 100 lines: the longest, the deck leaf’s slide map, has 67.

Chapter [1](01-a-tutorial-introduction.md#ch-tutorial) printed the revenue bridge’s reference to the end of its movement table, each row of which is one branch of `build` in words. Here are the two paragraphs that follow the table, lines 22 to 30:

File: `packs/variance-bridge/skills/revenue-bridge/references/definitions.md` (lines 22–30).

```markdown
A customer with no revenue in either year has no movement. The script
refuses negative revenue, a timing amount on a customer with no prior-year
revenue, and a timing amount larger than current-year revenue, so CY after
timing is never negative.

Counts. `counts.customers` is every row. `counts.lost` counts Loss, and
`counts.new`, `counts.upsell`, `counts.decline` and `counts.flat` count
their rows. `counts.timing` counts customers with a timing amount; each of
them is also counted in its movement.
```

The first paragraph lists three of `build`’s refusals, and the second says why the counts exceed `customers`: a customer with a timing amount is counted under `timing` and again under its movement. The model reads this file to learn what “Loss” means before it writes a sentence about Fenwick Legal, the first customer in the Loss list, and computes nothing from it.

The price-volume-mix reference, `references/method.md`, does the same for a method: its Rounding section says why every row, family, segment and total reconciles to the cent. The other four are a metric’s meaning, a slide map, review questions and a policy. The budget-vs-actual leaf has none, because what the model needs to read its figures fits in the five bullets of its skill file’s “Reading the display block”.

**Exercise 5-6.** Copy the Variance and Bridge pack to a scratch folder and delete any `__pycache__/` folders from the copy. Change the Rounding section of the price-volume-mix `method.md` so that it contradicts `pvm.py`: say each row’s three effects are rounded on their own. Run the validator on the copy and search the pack’s tests for anything that reads the reference. Does any check notice the change? What does the answer say about who keeps a reference true?

## Assets: files a script reads or fills

<a id="sec-scripts-assets"></a>

An asset is a file under an `assets/` folder that a script reads or a deliverable embeds: a brand file, a template, a logo. The script finds it from its own location, in either shape of a pack (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.6.2).

The four packs ship one asset: the brand file of the company-branding house skill, in the Management Reporting pack. The skill points to it at the top of its instructions:

File: `packs/management-reporting/_shared/company-branding/SKILL.md` (lines 8–11).

```markdown
The exact values (hex colours, font lists, number formats, the file-name
pattern) are in `<pack root>/_shared/company-branding/assets/brand.json`.
Scripts that build decks, workbooks or charts read that file. Never retype a
colour, font or format from memory.
```

The deck leaf’s `build_deck.py` is the script that reads it, and finds it with this function:

File: `packs/management-reporting/skills/deck-assembly/scripts/build_deck.py` (lines 89–95).

```python
def find_brand(override: Path | None) -> Path:
    if override:
        return override
    for parent in Path(__file__).resolve().parents:
        if (parent / "_shared").is_dir():
            return parent / "_shared" / "company-branding" / "assets" / "brand.json"
    raise InputError("no _shared/ folder above this script; pass --brand")
```

It walks up from its own folder to the first parent that contains `_shared/`: the pack root in the bundle shape, the deck skill’s own folder in the split shape. When no parent has one, the error names the flag that fixes it. An asset counts in the pack’s file count and bytes (Chapter [7](07-packs.md#ch-packs)). The brand file, 2755 bytes of values, is printed in Appendix [B](appendix-b-the-house-skills.md#app-shared).

## Paths start at the pack root

<a id="sec-scripts-paths"></a>

A script cannot know which folder a host will run it from. The pack standard puts the user’s output in that folder, the working directory (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.4.6), and a script that opened `assets/brand.json` relative to the working directory would find nothing. A script finds its own files from `Path(__file__)`, the path of the script itself. `find_brand` is one example. The pack’s checks are another. The first statement of the generic core in `tests/checks.py` is

File: `packs/variance-bridge/tests/checks.py` (lines 36–36).

```python
HERE = Path(__file__).resolve().parent
```

and the golden check opens its golden file from `HERE`. The other fifteen scripts in the four packs open no file but the ones their flags name.

The skill file follows the same rule: it names every file from the pack root, writes a command’s script path after the `<pack root>/` placeholder, and treats user-side paths such as `output/` as the exception (Chapter [4](04-the-skill-file.md#ch-skillfile)). The validator checks those paths, within the limits Section [7.5](07-packs.md#sec-packs-paths) states. Move the stage’s script up one folder in a scratch copy and validate:

File: `examples/ch05/outputs/validate-moved-script.txt` (lines 1–6).

```text
$ cp -r examples/ch05/budget-vs-actual-2 /tmp/budget-vs-actual-2
$ mv /tmp/budget-vs-actual-2/scripts/bva.py /tmp/budget-vs-actual-2/
$ python3 tools/validate_pack.py --auto /tmp/budget-vs-actual-2
/tmp/budget-vs-actual-2: FAIL (split, 3/20 files, 44502 bytes below the root)
  error: SKILL.md: spec 3.4.1: path `scripts/bva.py` does not exist relative to the pack root
  error: SKILL.md: spec 3.4.4: `<pack root>/scripts/bva.py` does not exist relative to the pack root
```

There are two errors, one for each place the skill file names the script: the backticked path in step 4 and the command’s placeholder path.

**Exercise 5-7.** Make the scratch copy above and confirm the two errors. Then edit the copy’s skill file so that both places name the script where it now is, `bva.py` and `<pack root>/bva.py`, validate again, and run the script. The validator passes. Which of the two new paths did it check? Try a misspelt name in both places to find out.

## The stage, run

<a id="sec-scripts-stage"></a>

The stage `examples/ch05/budget-vs-actual-2/` is the draft of Chapter [4](04-the-skill-file.md#ch-skillfile) with its script, a skill installed alone whose `scripts/bva.py` is identical to the script the pack ships. Its skill file is the draft’s with a new name, a clause in step 7 for `display.rounding`, and new steps 3 to 5, lines 18 to 36:

File: `examples/ch05/budget-vs-actual-2/SKILL.md` (lines 18–27).

```markdown
3. Take the period from the request, written YYYY-MM, and pass it as
   `--period`. If the request names none, leave the flag out.
4. Run the script, `scripts/bva.py`. Paths in this file are relative to
   the folder that holds it, written `<pack root>` in the command:

       python3 <pack root>/scripts/bva.py \
           --input <the CSV> --output output/bva.json [--period YYYY-MM]

   `--input` is the CSV, `--output` the file the script writes, and
   `--period` the month, by default the last period in the file.
```

File: `examples/ch05/budget-vs-actual-2/SKILL.md` (lines 28–36).

```markdown
5. Read the exit code, then go on, ask or stop:
   - 0: the figures reconcile. Go on.
   - 2: the input is wrong; the message names the column, line or
     period. If the user can fix it (another file, a month the file
     holds), show the message and ask. Otherwise show it and stop.
   - 3: the variances do not reconcile. Show the error and stop. Never
     report the figures in `output/bva.json`.

   Never compute a figure yourself.
```

Step 4 writes the command with `<pack root>`, which for a skill installed alone is its own folder, so the validator now resolves the path and the stage validates.

Run it from the repository’s root on the P&L file, with `--output` the stage’s own `output/bva.json`:

File: `examples/ch05/budget-vs-actual-2/output/run.txt` (lines 2–3).

```text
YTD 2025 revenue $11,238K vs budget $11,600K, variance ($362K); operating income $388K vs $583K, variance ($195K); reconciles. Wrote examples/ch05/budget-vs-actual-2/output/bva.json
exit 0
```

The file it wrote, 905 lines, is identical to the pack’s golden file. Under `display.ytd.subtotals`, operating income is unfavourable by `($195K)`, or `(33.5%)`, and revenue by `($362K)`, or `(3.1%)`. The gross margin’s `(0.9) pts` is `fmt_pts` at work (Appendix [A](appendix-a-reference-manual.md#app-reference), 3.7.2). The model’s part is still loose: step 7 does not say which figures “a sentence on the month” should contain or which lines drove the variance, so two runs can write notes of different shapes and no check tests either shape. Chapter [6](06-output-contracts.md#ch-contracts) fixes the shape with an output contract.

**Exercise 5-8.** Run the stage’s script for June 2025 (`--period 2025-06`) and compare `input` and `display.labels` with the December run. Which strings the note quotes change, and why does the hash in the data notes stay the same?
