视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
, or `&` in values. Use literal replacement (`fixed = TRUE` in R, a replacement *function* in Python `re.sub`).\n- **Placeholder grammar too loose**: `\\{(\\w+)\\}` matches legitimate braces in code spans and shell text. Require the dotted-path grammar so only metric keys match — and unknown *matching* keys still fail loudly.\n- **Figures that claim derivation but hardcode**: a script that loads a file and then annotates with a typed literal passes casual review. The guard (Step 6) is what makes the claim checkable — insist on it for every displayed value.\n- **Templating non-measurements**: version numbers, event dates, and prose counts do not belong in stats.json. Templating them adds churn without honesty gains; Step 1's bucket 3 stays untouched.\n\n## Related Skills\n\n- `generative-recipe-dsl` - data-driven artifact generation; this skill keeps the numbers those generated artifacts display honest\n- `build-parameterized-report` - parameter-driven report rendering; combine with this skill so report parameters select *which* metrics render while the extractor guarantees their freshness\n","licenseDocuments":[]}}
stale-proof-rendered-numbers【文档与办公】Make every measured number displayed in a generated artifact resolve from source files at build time, so stale numbers fail the build instead of rendering silently. Displayed figures become {metric.key} placeholders; a single extractor reads the real measurement artifacts (results JSON, run logs, ledgers) and emits a stats.json of value/source/as-of …
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Convert hardcoded numbers in generated artifacts into templates that resolve from measurement sources at render time, where a missing key is a build error. Hardcoded numbers rot the moment the underlying measurement moves — and they rot silently, which is worse than a visible error. This skill makes staleness loud: numbers are never typed into the artifact, one extractor is the only writer of the stats file, and the renderer refuses to build anything it cannot trace to a source.
--json output)bench.api.p95_ms)List every number the artifact displays. For each, answer: which file on disk backs this number right now?
# Surface numeric literals in the artifact's source or template data
grep -nE '[0-9]+(\.[0-9]+)?\s*(%|ms|pts?|n=|/)' docs/README.template.md
Classify each hit into one of three buckets:
--json flag away from it)Expected: A table of displayed number → source file (or FROZEN + provenance) covering every measured figure in the artifact. Nothing is left as "I remember it was 30%".
On failure: If a number has no locatable source, it is either frozen (pin it in Step 3 with a provenance string naming where the result was recorded) or unsubstantiated (remove it from the artifact — a number nobody can trace should not render).
{metric.key} PlaceholdersTurn the artifact's data or template into templates. Every measured literal becomes a placeholder:
## Status (as of {meta.generated_at})
- Test suite: {tests.passed}/{tests.total} passing, {coverage.line_pct}% line coverage
- API p95 latency: {bench.api.p95_ms} ms (n={bench.api.n}, measured {bench.api.as_of})
- v1.0 baseline: {frozen.v1_baseline_p95_ms} ms (closed load test, 2026-05-02)
Key grammar: lowercase dotted paths, at least one dot ([a-z0-9_]+(\.[a-z0-9_]+)+). Requiring the dot keeps the substitution regex from matching legitimate braces elsewhere in the document (code spans, shell snippets).
Expected: grep -nE '[0-9]' on the template shows no measured literals left — only placeholders, prose, and non-measurement numbers from Step 1's bucket 3.
On failure: If a line mixes a measured number with prose punctuation that resists templating, split the placeholder finer ({ladder.lucario.wr_pct}% (n={ladder.lucario.n})) rather than templating a whole preformatted string — one placeholder per number keeps sources auditable.
Write ONE extractor (e.g. tools/doc_stats.py) that reads the real artifacts and emits stats.json. It is the only writer of that file; numbers are never typed into the artifact or the stats file by hand.
FROZEN_METRICS = {
# Point-in-time results of CLOSED measurements: pinned HERE, one audited
# place, each with source + as_of. When an artifact-backed source appears,
# migrate the key OUT of this block into a reader function below.
"frozen.v1_baseline_p95_ms": {
"value": "212",
"source": "release-1.0 load test, docs/perf-report-v1.md (closed 2026-05-02)",
"as_of": "2026-05-02",
},
}
def bench_metrics(today: str) -> dict:
run_path = newest(Path("bench/results").glob("api_*.json"))
run = json.loads(run_path.read_text())
source = f"{run_path} ({run['n']} requests)"
return {
"bench.api.p95_ms": {"value": str(run["p95_ms"]), "source": source, "as_of": today},
"bench.api.n": {"value": str(run["n"]), "source": source, "as_of": today},
"bench.api.as_of": {"value": today, "source": source, "as_of": today},
}
Every metric entry has exactly the shape {value, source, as_of}:
{
"generated_at": "2026-07-10",
"metrics": {
"bench.api.p95_ms": {
"value": "187",
"source": "bench/results/api_2026-07-08.json (500 requests)",
"as_of": "2026-07-10"
}
}
}
Rules that make this stale-proof rather than merely centralized:
stats.json. A hand edit to stats.json is a defect, not a shortcut.FROZEN_METRICS with a provenance string naming where the result was recorded and an as_of date. This is the ONE audited place for point-in-time numbers. Migrate keys out as live sources appear.FAIL: message — do not emit a partial stats file silently.See references/EXAMPLES.md for the complete extractor.
Expected: Running the extractor prints each key with its value and as-of date and writes stats.json; re-running it after a new measurement run changes the affected values with zero manual edits.
On failure: If a source is not machine-readable, first check for a --json flag or an existing structured sibling (ledger TSV, JSONL results). Only regex-parse human-oriented output as a last resort, and make the parse fail loudly when the pattern stops matching.
The renderer resolves placeholders from stats.json at build time. A missing key is a build error — stale can never render silently:
stats = json.loads(Path("docs/stats.json").read_text())
metrics = dict(stats["metrics"])
metrics["meta.generated_at"] = {"value": stats["generated_at"]}
def resolve(text: str) -> str:
def substitute(match: re.Match) -> str:
metric_key = match.group(1)
if metric_key not in metrics:
sys.exit(f"FAIL: stats.json is missing metric '{metric_key}' "
f"— rerun: python3 tools/doc_stats.py")
return metrics[metric_key]["value"]
return re.sub(r"\{([a-z0-9_]+(?:\.[a-z0-9_]+)+)\}", substitute, text)
The same guard in R (generalized from a card-rendering pipeline; full version in references/EXAMPLES.md):
metric <- stats$metrics[[metric_key]]
if (is.null(metric)) {
stop("stats.json is missing metric '", metric_key,
"' — rerun: python3 tools/doc_stats.py", call. = FALSE)
}
text <- sub(placeholder, as.character(metric$value), text, fixed = TRUE)
Two properties are non-negotiable: the lookup stops the build on a missing key (no .get(key, "N/A"), no warning-and-continue), and substitution of the matched placeholder is literal (fixed = TRUE / replacement from a function), never a second regex pass over the value.
Expected: A full build renders the artifact with every placeholder resolved; the output contains no {...} placeholder-grammar matches.
On failure: If a legitimate brace expression in the document trips the substitution, tighten the key grammar (the required dot usually suffices) rather than loosening the failure — silent skips reintroduce the rot this pipeline exists to prevent.
Every rendered artifact displays when its numbers were extracted, sourced from stats.json — never typed:
Status as of {meta.generated_at} from the stats file's generated_at(measured {bench.api.as_of})This is the reader-facing half of the honesty contract: the build guarantees numbers match sources at extraction time, and the as-of date tells the reader what that time was.
Expected: The rendered artifact visibly carries an as-of date that changes when (and only when) the extractor reruns.
On failure: If the artifact has no natural place for a date, add a caption, footer, or badge suffix. An artifact showing measured numbers without an as-of date fails review under this skill.
stopifnot VariantPlaceholders cover text substitution. Generated figures need the same honesty a different way: each figure script re-reads its source files at render time and guards every value it displays, so a plot literally cannot render a number it did not just read.
bench <- jsonlite::fromJSON("bench/results/api_2026-07-08.json")
stopifnot(
is.numeric(bench$p95_ms), bench$p95_ms > 0,
bench$n >= 100 # the caption claims n >= 100 — enforce it
)
p95_label <- sprintf("p95 = %.0f ms (n = %d)", bench$p95_ms, bench$n)
# every annotation below derives from `bench`; no numeric literals in labels
Two guard styles compose:
stopifnot() asserts the invariants the figure's message depends on (row counts sum to the traced total, rates are in range, the cited n is met)stopifnot(grepl("n=100", readme_text, fixed = TRUE)) — so the caption never states a number the source stopped backingThis makes "claimed file-derivation" enforceable: an adversarial review of scripts that claimed to read files but hardcoded literals is what motivated this variant. In Python, assert/sys.exit guards on freshly loaded data serve the same role.
Expected: Every figure script reads its sources at render time; deleting or changing a source file makes the figure build fail or visibly change — never silently render the old number.
On failure: If a script has literals in labels or annotations, replace each with a value computed from the loaded data plus a guard. If the value exists nowhere machine-readable, route it through the extractor's FROZEN block and read stats.json instead.
Document and wire the pipeline as measure → extract → render:
python3 tools/doc_stats.py # extract: artifacts -> docs/stats.json
python3 tools/render_docs.py # render: template + stats.json -> README.md
Then run the two proofs (these are the skill's acceptance tests):
# Proof 1 — bogus key fails the build
printf '\n- bogus: {does.not_exist}\n' >> docs/README.template.md
python3 tools/render_docs.py; echo "exit=$?" # expect FAIL message, exit != 0
git checkout -- docs/README.template.md
# Proof 2 — live source auto-refresh, zero manual edits
# (land a new measurement run, e.g. bench/results/api_<today>.json)
python3 tools/doc_stats.py && python3 tools/render_docs.py
git diff --stat docs/ README.md # only generated files changed
Proof 2 is the payoff: in the originating pipeline a rendered card auto-updated n=70 → n=200 from a still-running measurement's artifact with no hand edits.
Expected: Proof 1 exits non-zero naming the missing key and the rerun command. Proof 2 shows the new values and as-of date in the rendered artifact with git diff touching only extractor output and rendered files.
On failure: If Proof 1 renders the bogus placeholder or exits 0, the renderer has a silent-default path — remove it (Step 4). If Proof 2 requires any hand edit, a number is still typed somewhere; trace it and move it behind the extractor.
{metric.key} placeholder; none are typed literalsstats.json; every entry has value, source, and as_ofstats.jsonstopifnot or equivalent)measure → extract → render flow is documented next to the pipeline (README or script headers)metrics.get(key, "N/A"), warn-and-continue, or rendering the raw placeholder on a miss turns a build error back into silent rot. The missing-key path must stop the build.\, $, or & in values. Use literal replacement (fixed = TRUE in R, a replacement function in Python re.sub).\{(\w+)\} matches legitimate braces in code spans and shell text. Require the dotted-path grammar so only metric keys match — and unknown matching keys still fail loudly.generative-recipe-dsl - data-driven artifact generation; this skill keeps the numbers those generated artifacts display honestbuild-parameterized-report - parameter-driven report rendering; combine with this skill so report parameters select which metrics render while the extractor guarantees their freshness