From d6968bb239a4dee701eb6edf9d97a594fecb35c1 Mon Sep 17 00:00:00 2001 From: "napkinstack-agent[bot]" <330339777+napkinstack-agent[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 04:51:08 +0100 Subject: [PATCH 1/4] =?UTF-8?q?D316=20=E2=80=94=20a=20module's=20formatter?= =?UTF-8?q?=20runs=20at=20the=20commit,=20from=20the=20verb=20it=20declare?= =?UTF-8?q?s=20(#593)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Downstream, a red `cargo fmt --check`, inside a module's check, was seen only at attest, after the push and the verifier's round. A module now declares its formatter's check as the optional verb `format`; the skeleton's pre-commit hook nstack-format runs it on the modules whose files are staged, and Module checks runs it after bootstrap, before check, so the one line is judged at the commit and in CI alike. Where nstack, an engine without the verb, or the module's own tool (exit 127) is missing, the hook says so and lets the commit go: CI judges. Chosen after an independent audit of moonrepo, lefthook, lint-staged, trunk, Bazel and Pants. Agent-Session: napkinstack-os-1e Co-Authored-By: Claude Opus 5.5 --- docs/governance/workstreams.md | 1 + platform/tests/test_forge.py | 1 + platform/tests/test_format_hook.py | 104 +++++++++++++++++++ skeleton/.github/workflows/module-checks.yml | 2 +- skeleton/.nstack/check-modules.sh | 4 +- skeleton/.nstack/format-before-commit.sh | 29 ++++++ skeleton/.nstack/handbook/09-platform.md | 11 +- skeleton/.pre-commit-config.yaml | 11 ++ src/napkinstack/cli.py | 2 + src/napkinstack/modules.py | 3 +- 10 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 platform/tests/test_format_hook.py create mode 100755 skeleton/.nstack/format-before-commit.sh diff --git a/docs/governance/workstreams.md b/docs/governance/workstreams.md index 60559839..b5f09432 100644 --- a/docs/governance/workstreams.md +++ b/docs/governance/workstreams.md @@ -330,6 +330,7 @@ state to its index: [`docs/adr/`](../adr/README.md), [`docs/pdr/`](../pdr/README | D311 | **An agent's skills lost their skip-worktree bit, and its commit stopped in the sandbox's mask** (#584). Downstream, 2026-11-29, nstack 0.35.3: the five agents' clones kept D261's sparse patterns, but their committed skills showed as deleted; pre-commit's stash wrote them back into the mask, and `git checkout -- .` failed with "Device or resource busy". The loss itself was not reproduced beyond one clone's commit of the sandbox's masks: git clears the bit wherever the file is present | **Done**: at each `nstack agent run`, a skill outside the patterns that is absent from the working tree gets its bit back, in the index alone; one the working tree holds stays and is said kept, as before. Not taken: `git sparse-checkout reapply`, which leaves them while the sandbox's placeholder stands; `--assume-unchanged`, a hint git may drop. Not caught: a bit lost during a session is set again only at the agent's next run | | D312 | **A cycle left proposed was approved as if accepted** (#587). Downstream, 2026-11-29: the next cycle, `proposed` with no `accepted_on` while one ran, was approved by the decider as its acceptance; neither fitness nor pr-check said the approval accepted nothing, and a second push and a second approval followed. The framing playbook said it; nothing said it where the approval is given | **Done**: pr-check warns (C11) on a pull request that leaves a cycle `proposed` with no `accepted_on`, in a framed project — on the check itself, beside the approval, not only in its log — with the gesture: `accepted_on` while a cycle runs, else `status: accepted` and its start. A warning, not a failure: a decider may approve a proposal still being framed. Not caught: a cycle proposed during framing, before the charter is accepted — the framing accepts both | | D313 | **The update's refusal off main did not say it makes its own branch, nor the way from a worktree** (#589). Downstream, 2026-11-29, 0.35.4: the coordinator made a branch and a worktree for the update first, as for any change; the refusal said `git switch main`, which a worktree beside main's cannot do | **Done**: `nstack update`, `nstack update --forge` and `nstack config` refuse with one Action: `git switch `, or in a worktree beside the one that holds it `git switch --detach ` (#261), and the command makes its own branch: make none before | +| D316 | **A module's formatter ran only in CI or at attest** (#593). Downstream, 2026-11-30, PR #1390: a red `cargo fmt --check`, inside the module's `check`, was seen after the push and the verifier's round; the shipped pre-commit config ran generic hooks only | **Done**: an optional verb `format` (the formatter's check, writing nothing, building nothing); the skeleton's pre-commit hook `nstack-format` runs it on the modules whose files are staged, and `Module checks` after `bootstrap`, before `check`. Where nstack, an engine without the verb or the module's tool (exit 127) is missing, the hook says so and lets the commit go: CI judges. Audited before (moonrepo, lefthook, lint-staged, trunk, Bazel, Pants). Not taken: `check` at push (a build, minutes), documentation alone (a copy per project). A project moves its formatter's check out of `check` into `format` | | v0.6.0 | **What is announced refuses, and the documents say what is true**: D51 to D54, and the documentary lot of the internal audit | **Done (2026-09-20)**: five workstreams merged (#83, #84, #85, #86, #87), **v0.6.0 published**, tag on `8ae544c`, verified on published artefacts — including an update of `tool-library` from v0.5.0, 9 files and no conflict, still compliant. Found doing it: D55. Next: the pilot, and M11 beside it | | Pilot | **`NapkinStack/flet`, the first real project**, run by a session that knew nothing of this repository, with the maintainer as decider and this repository's agent as observer — public on the Free plan, where the whole checklist is available, rather than private on Team where G5 is paid and G6 does not exist | **Set aside by the maintainer, 2026-10-15**, at its cycle boundary; the real product followed since is `summit`. **Ran from 2026-09-20**: discovery decided *go* after three rounds and two independent challenges, charter accepted; cycle 01 closed `stopped/reframed`, **cycle 02 closed** with two deliverables accepted and one deferred (its #27), **cycle 03 framed and approved** (#28, #30), which starts its first `critical` module; the framework taken to v0.6.1 by itself at the boundary (#29), v0.6.2 proposed (#31). It has produced D56 to D63, D68, D70 to D77, replicated D26 and D55, and measured D49 — the first figures on what an independent verifier finds (PDR-0003) | | M11 | **Ceremony follows consequence** (PDR-0011): the framework charges what a failure costs, per module and per project, and states each price before it is paid; with PDR-0004's routing, and PDR-0007, PDR-0008 and PDR-0010 — through to v0.7.0 | **Published as v0.7.0 (2026-10-12).** Planned 2026-09-23 (#98). Merged: **M11f** (#101), **M11a** (#102), **M11b** (#103), **M11d** (#104), **M11e** (#105), **M11c** (#106), **M11h** (#107), **M11g** (#108) closed by its probe — not clean, returned to M13; **M11m** (D68, D74, D75); **M11l** (PDR-0010, D59, D60); **M11n** (D79); **M11o** (PDR-0010 extended: every document has its moment); **M11p** (PDR-0002's three levels given a place: `docs/project/rules/`); **M11j** (PDR-0007: the unframed stage); **M11q** (no folder created empty; PDR-0012 proposed: a project's tree is the project's). **M11k** (PDR-0008's print mode: `nstack settings`; D77, D78). **M11s** (PDR-0012 accepted; the framework's files under `.nstack/`; an update carries what a project adapted); **M11u** (an update rewrites the old addresses a project wrote in its own files, D85). **M11t** (`nstack new-contract`: the contracts module is created by the first contract; PDR-0012 built in full); **M11v** (what the third project found: D81, D82, D83, D86, D87). **M11i**: v0.7.0 published 2026-10-12 (#125, D88). To do: **M11r** PDR-0008's apply mode and D57, after a probe on the real forge; the two earlier projects take v0.7.0 themselves, observed | diff --git a/platform/tests/test_forge.py b/platform/tests/test_forge.py index f4ac5e20..decec7b8 100644 --- a/platform/tests/test_forge.py +++ b/platform/tests/test_forge.py @@ -153,6 +153,7 @@ def test_a_github_project_s_update_writes_forge_github_and_changes_nothing_else( updated = yaml.safe_load((old / ".copier-answers.yml").read_text(encoding="utf-8")) assert updated["forge"] == "github" and updated["github_repo"] == "acme/demo" added_since = {".nstack/fitness-before-push.sh", ".gitattributes", # the skeleton's files new since v0.14.0 (D232, D252, D282) + ".nstack/format-before-commit.sh", # D316 (#593) ".nstack/playbooks/pause-and-resume.md", ".claude/skills/pause-and-resume/SKILL.md", ".agents/skills/pause-and-resume/SKILL.md"} assert before <= after and after - before == added_since, f"files added or removed: {sorted(after ^ before)}" diff --git a/platform/tests/test_format_hook.py b/platform/tests/test_format_hook.py new file mode 100644 index 00000000..66a5d790 --- /dev/null +++ b/platform/tests/test_format_hook.py @@ -0,0 +1,104 @@ +"""D316 (#593): downstream, a red `cargo fmt --check` was seen only at attest, after the push and the +verifier's round: no hook ran the formatter a module declares. A module now declares it as its +`format` verb, and the pre-commit hook nstack-format runs it on the modules whose files are staged. +Where nstack, or the module's own tool, is missing, it says so and lets the commit go: CI judges.""" + +from __future__ import annotations + +import os +import shutil +import subprocess +from pathlib import Path + +import pytest +import yaml + +from test_guardrails import VALID, degrade, write_module + +ROOT = Path(__file__).resolve().parents[2] +CONFIG = ROOT / "skeleton" / ".pre-commit-config.yaml" +UGLY = "! grep -q ugly src/page.txt" # a formatter's check: fails on what it would rewrite +ENV = {"GIT_AUTHOR_NAME": "P", "GIT_AUTHOR_EMAIL": "p@example.com", + "GIT_COMMITTER_NAME": "P", "GIT_COMMITTER_EMAIL": "p@example.com"} + + +def _hook() -> dict: + for repo in yaml.safe_load(CONFIG.read_text(encoding="utf-8"))["repos"]: + for hook in repo["hooks"]: + if hook["id"] == "nstack-format": + return hook + raise AssertionError("no nstack-format hook") + + +def _project(tmp_path: Path, formats: dict[str, str | None]) -> Path: + project = tmp_path / "project" + (project / ".nstack").mkdir(parents=True) + script = ROOT / "skeleton" / ".nstack" / "format-before-commit.sh" + (project / ".nstack" / script.name).write_bytes(script.read_bytes()) + for name, command in formats.items(): + commands = {"check": "true", "test": "true", **({"format": command} if command else {})} + write_module(project, name, degrade(module__name=name, commands=commands), {"src/page.txt": "neat\n"}) + subprocess.run(["git", "init", "-q", "-b", "main"], cwd=project, check=True) + subprocess.run(["git", "add", "-A"], cwd=project, check=True) + subprocess.run(["git", "commit", "-q", "-m", "base"], cwd=project, check=True, env={**os.environ, **ENV}) + return project + + +def _commit(project: Path, staged: dict[str, str], engine: bool = True) -> subprocess.CompletedProcess: + for path, content in staged.items(): + (project / path).write_text(content, encoding="utf-8") + subprocess.run(["git", "add", path], cwd=project, check=True) + nstack = Path(shutil.which("nstack") or "").parent + path = f"{nstack}:/usr/bin:/bin" if engine else "/usr/bin:/bin" + return subprocess.run(["sh", "-c", _hook()["entry"]], cwd=project, capture_output=True, text=True, + env={**os.environ, "PATH": path}, timeout=120) + + +def test_the_hook_runs_at_a_commit_and_judges_what_is_staged(): + hook = _hook() + assert hook["stages"] == ["pre-commit"] and hook["language"] == "system" and hook["pass_filenames"] is False + + +def test_a_staged_module_not_formatted_is_refused_by_name(tmp_path): + project = _project(tmp_path, {"billing": UGLY, "orders": UGLY}) + done = _commit(project, {"modules/billing/src/page.txt": "ugly\n"}) + assert done.returncode == 1, done.stdout + done.stderr + assert "not formatted: billing." in done.stdout and "Action:" in done.stdout + + +def test_a_formatted_module_passes(tmp_path): + project = _project(tmp_path, {"billing": UGLY}) + done = _commit(project, {"modules/billing/src/page.txt": "neater\n"}) + assert done.returncode == 0, done.stdout + done.stderr + assert "billing: ! grep -q ugly src/page.txt" in done.stderr, "the module's own command, from its folder" + + +def test_only_the_modules_whose_files_are_staged_are_judged(tmp_path): + project = _project(tmp_path, {"billing": UGLY, "orders": UGLY}) + (project / "modules/orders/src/page.txt").write_text("ugly\n", encoding="utf-8") # changed, not staged + done = _commit(project, {"modules/billing/src/page.txt": "neater\n"}) + assert done.returncode == 0, done.stdout + done.stderr + assert "orders" not in done.stdout + done.stderr + + +@pytest.mark.parametrize("formats, said", [ + ({"billing": "no-such-formatter --check"}, "billing: its formatter is not installed here: judged in CI"), + ({"billing": None}, "billing: format not declared, no formatter to run"), +]) +def test_a_formatter_missing_here_or_undeclared_lets_the_commit_go(tmp_path, formats, said): + project = _project(tmp_path, formats) + done = _commit(project, {"modules/billing/src/page.txt": "ugly\n"}) + assert done.returncode == 0, done.stdout + done.stderr + assert said in done.stdout + done.stderr + + +def test_without_nstack_the_commit_goes_and_ci_judges(tmp_path): + project = _project(tmp_path, {"billing": UGLY}) + done = _commit(project, {"modules/billing/src/page.txt": "ugly\n"}, engine=False) + assert done.returncode == 0 and "nstack is not installed: formatting is judged in CI" in done.stdout + + +def test_module_checks_runs_the_formatter_too(): + """The one line a module declares is judged in CI as at the commit: before check, after bootstrap.""" + script = (ROOT / "skeleton" / ".nstack" / "check-modules.sh").read_text(encoding="utf-8") + assert 'nstack bootstrap "$MODULE" && nstack format "$MODULE" && nstack check "$MODULE"' in script diff --git a/skeleton/.github/workflows/module-checks.yml b/skeleton/.github/workflows/module-checks.yml index a139bcd8..4d68ed70 100644 --- a/skeleton/.github/workflows/module-checks.yml +++ b/skeleton/.github/workflows/module-checks.yml @@ -43,7 +43,7 @@ jobs: - name: NapkinStack, the project version run: bash .nstack/install-engine.sh - # bootstrap, check, test, compat even after a failure, e2e, and clean on a self-hosted + # bootstrap, format, check, test, compat even after a failure, e2e, and clean on a self-hosted # runner — module by module (.nstack/handbook/05-workflow.md §7, 09-platform.md §2). - name: Every changed module env: diff --git a/skeleton/.nstack/check-modules.sh b/skeleton/.nstack/check-modules.sh index 302a23d8..c39af127 100755 --- a/skeleton/.nstack/check-modules.sh +++ b/skeleton/.nstack/check-modules.sh @@ -3,7 +3,7 @@ # project's ruleset requires: `Module checks` (.nstack/handbook/09-platform.md §2). # # nstack lists the modules with a file changed since BASE, and both sides of a contract version -# the change touches (.nstack/handbook/03-contracts.md §5). For each one: bootstrap, check, test; +# the change touches (.nstack/handbook/03-contracts.md §5). For each one: bootstrap, format, check, test; # then compat, even after a failure, so that a broken frozen version is named in the same round # (.nstack/handbook/03-contracts.md §4); then e2e, on a module still green; then clean, on a # self-hosted runner only, even after a failure — a hosted machine is thrown away after the job. @@ -40,7 +40,7 @@ while IFS=$'\t' read -r MODULE FOLDER <&3; do *) echo "Not a value the engine knows: judged as critical until M3 is satisfied." ;; esac GREEN=1 - { nstack bootstrap "$MODULE" && nstack check "$MODULE" && nstack test "$MODULE"; } || GREEN=0 + { nstack bootstrap "$MODULE" && nstack format "$MODULE" && nstack check "$MODULE" && nstack test "$MODULE"; } || GREEN=0 nstack compat "$MODULE" --base "$BASE" || GREEN=0 if [ "$GREEN" = 1 ]; then nstack e2e "$MODULE" || GREEN=0; fi if [ "${RUNNER_ENVIRONMENT:-}" = self-hosted ]; then nstack clean "$MODULE" || GREEN=0; fi diff --git a/skeleton/.nstack/format-before-commit.sh b/skeleton/.nstack/format-before-commit.sh new file mode 100755 index 00000000..f1653145 --- /dev/null +++ b/skeleton/.nstack/format-before-commit.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# At a commit, the formatter each module declares (commands.format), on the modules whose files are +# staged: the pre-commit hook nstack-format of .pre-commit-config.yaml (.nstack/handbook/09-platform.md +# §2). pre-commit has set aside what is not staged, so what is judged is what the commit holds. +# Module checks runs the same command in CI: this one only says it sooner. Where nstack, an engine +# that knows the verb, or the module's own tool (exit 127) is missing here, it says so and lets the +# commit go: CI judges. +# +# Plain sh: the workstation's engine may predate this file. +command -v nstack >/dev/null 2>&1 || { echo "nstack is not installed: formatting is judged in CI"; exit 0; } +nstack format --help >/dev/null 2>&1 || { echo "this nstack has no format verb: formatting is judged in CI"; exit 0; } + +STAGED=$(git diff --cached --name-only --no-renames) +[ -n "$STAGED" ] || exit 0 +TAB=$(printf '\t') +FAILED=$(nstack modules --root . | while IFS="$TAB" read -r MODULE FOLDER; do + printf '%s\n' "$STAGED" | awk -v folder="$FOLDER/" 'index($0, folder) == 1 { found = 1 } END { exit !found }' || continue + nstack format "$MODULE" &2 + case $? in + 0) ;; + 127) echo "-> $MODULE: its formatter is not installed here: judged in CI" >&2 ;; + *) printf '%s ' "$MODULE" ;; + esac +done) +if [ -n "$FAILED" ]; then + echo "FAIL [nstack] not formatted: ${FAILED% }." + echo " Action: run the module's formatter (its AGENTS.md says which), git add, then commit again." + exit 1 +fi diff --git a/skeleton/.nstack/handbook/09-platform.md b/skeleton/.nstack/handbook/09-platform.md index 11efad56..f3f92e01 100644 --- a/skeleton/.nstack/handbook/09-platform.md +++ b/skeleton/.nstack/handbook/09-platform.md @@ -53,6 +53,7 @@ section, with its own stack's commands. | Verb | Contract | Must work… | |---|---|---| | `bootstrap` | Make the module usable from a fresh clone | Without prior knowledge | +| `format` | Tell whether the module's files are formatted — the formatter's check, writing nothing, building nothing | In seconds, at every commit: the pre-commit hook runs it on the modules whose files are staged | | `check` | All the fast validations: format, lint, types | In under 2 minutes | | `test` | The module's test suite | With no dependency on another module | | `run` | Start the module locally | With doubles for the dependencies | @@ -63,14 +64,20 @@ section, with its own stack's commands. | `migrate` | Apply the data migrations | When the module owns data | | `release` | Produce the module's shippable artefacts into `$NSTACK_DIST` | Reproducibly, for the platform its arguments name | -The engine runs `bootstrap`, `check`, `test`, `run`, `e2e`, `clean`, `compat` and `release`: it reads the command from +The engine runs `bootstrap`, `format`, `check`, `test`, `run`, `e2e`, `clean`, `compat` and `release`: it reads the command from the manifest and launches it from the module's folder, locally as in CI. `check` and `test` are mandatory as soon as the module holds anything beyond its description — its -manifest, `AGENTS.md`, `README.md`, `docs/`; `bootstrap`, `e2e` and `clean` are optional. A new module +manifest, `AGENTS.md`, `README.md`, `docs/`; `bootstrap`, `format`, `e2e` and `clean` are optional. A new module holds only its description: its verbs report that there is nothing to run yet, and `nstack fitness` asks for `check` and `test` with its first other file. `contracts` and `migrate` are reserved names, to declare when a module needs them. +`format` is the formatter's check alone — `cargo fmt --check`, `ruff format --check`, `prettier --check .`, +`gofmt -l`: it moves out of `check`, and `Module checks` runs it before `check`, so the one line is +judged at the commit and in CI alike. At the commit, where nstack or the formatter is not installed — +an agent's sandbox, a newcomer's machine —, the hook says so and lets the commit go: CI judges. The +command that rewrites the files (`cargo fmt`) belongs in the module's `AGENTS.md`, never in `format`. + What a module's checks need from the CI machine — a kernel setting, a system package — is its `bootstrap`'s, which `Module checks` runs before `check` and `test`: the manifest is the project's, and `nstack update` keeps it. Never a step added to the framework's workflow, which diff --git a/skeleton/.pre-commit-config.yaml b/skeleton/.pre-commit-config.yaml index 17aec0ef..cc88f8de 100644 --- a/skeleton/.pre-commit-config.yaml +++ b/skeleton/.pre-commit-config.yaml @@ -118,6 +118,17 @@ repos: exit 1' -- stages: [commit-msg] + # At a commit, the formatter each module declares (commands.format), on the modules whose + # files are staged: a module's own command, in seconds, never a build. Where nstack, or the + # module's tool, is not installed here, it says so and lets the commit go: Module checks + # judges in CI. .nstack/format-before-commit.sh. + - id: nstack-format + name: NapkinStack modules' formatters (commands.format) + language: system + entry: sh .nstack/format-before-commit.sh + pass_filenames: false + stages: [pre-commit] + # Before a push, the fitness functions CI runs on every pull request — a fault seen here, # not after a round trip. The skills are left to CI: what they are generated from is # the engine's version, which a contributor's may not be. Where nstack is not diff --git a/src/napkinstack/cli.py b/src/napkinstack/cli.py index 3100116a..d63c4096 100644 --- a/src/napkinstack/cli.py +++ b/src/napkinstack/cli.py @@ -148,6 +148,8 @@ def build_parser() -> argparse.ArgumentParser: help="a user sees this module: from standard up, its pull requests carry a " "test sheet (.nstack/handbook/05-workflow.md §7)") for verb, help_text in (("bootstrap", "prepares one module, or all of them (commands.bootstrap)"), + ("format", "tells whether one module's files, or all modules', are formatted; " + "writes nothing (commands.format)"), ("check", "format, lint, types of one module, or all (commands.check)"), ("test", "tests of one module, or of all of them (commands.test)"), ("e2e", "end-to-end scenarios of one module, or of all (commands.e2e)"), diff --git a/src/napkinstack/modules.py b/src/napkinstack/modules.py index 17a2b69e..fcba95b8 100644 --- a/src/napkinstack/modules.py +++ b/src/napkinstack/modules.py @@ -38,7 +38,8 @@ def owner_valid(root: Path, owner: str) -> bool: return bool((OWNER if forge(root) == "github" else SUBGROUPS).fullmatch(owner)) -OPTIONAL = {"bootstrap": "nothing to prepare", "e2e": "no end-to-end scenario", "clean": "nothing to clean"} # undeclared: skipped +OPTIONAL = {"bootstrap": "nothing to prepare", "format": "no formatter to run", "e2e": "no end-to-end scenario", + "clean": "nothing to clean"} # undeclared: skipped # Undeclared, skipped when every module is released; asked of one module by name, it is owed. ALL_ONLY = {"release": "nothing to release"} # What a criticality requires is the matrix of .nstack/handbook/05-workflow.md §7, read once (assurance). From 711eea39d6b851b60850b0a68a586eb9a4c2ecc4 Mon Sep 17 00:00:00 2001 From: "napkinstack-agent[bot]" <330339777+napkinstack-agent[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 04:57:33 +0100 Subject: [PATCH 2/4] =?UTF-8?q?D316=20=E2=80=94=20the=20oracle,=20quoted?= =?UTF-8?q?=20paths,=20a=20formatter=20reading=20stdin,=20an=20older=20eng?= =?UTF-8?q?ine=20(#593)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The verifier found the oracle's Module checks sequence missing format; a staged path git quotes (café.txt) skipped; the header's claim on untracked files untrue; and three guards untested. The oracle expects format; paths are read unquoted; the header says what pre-commit sets aside; tests cover a folder another's begins with, a formatter reading stdin, a quoted path and an engine older than the verb. The manifest template, INSTALL's commands, 09-platform's check row, the CLI's help and platform/README name format. Agent-Session: napkinstack-os-1e Co-Authored-By: Claude Opus 5.5 --- platform/README.md | 2 +- platform/tests/run.sh | 2 +- platform/tests/test_format_hook.py | 36 ++++++++++++++++--- skeleton/.nstack/format-before-commit.sh | 5 +-- skeleton/.nstack/handbook/09-platform.md | 2 +- skeleton/.nstack/handbook/INSTALL.md.jinja | 1 + src/napkinstack/cli.py | 2 +- src/napkinstack/modules.py | 2 +- .../templates/module/MANIFEST.yaml | 3 +- 9 files changed, 43 insertions(+), 12 deletions(-) diff --git a/platform/README.md b/platform/README.md index 04b7c200..afb9a970 100644 --- a/platform/README.md +++ b/platform/README.md @@ -68,7 +68,7 @@ uv run nstack doctor --root # workstation and GitHub settings, re uv run nstack new-module --root uv run nstack new-contract --root uv run nstack settings --root # the calls that would close the gaps, printed -uv run nstack check [module] --root # also test, bootstrap, e2e, clean, release; run +uv run nstack check [module] --root # also format, test, bootstrap, e2e, clean, release; run ``` ## Skills diff --git a/platform/tests/run.sh b/platform/tests/run.sh index 5c13ad03..91b03175 100755 --- a/platform/tests/run.sh +++ b/platform/tests/run.sh @@ -1400,7 +1400,7 @@ checks() { # $1 = RUNNER_ENVIRONMENT; prints the script's output, its verbs log } if OUT=$(checks github-hosted); then echo "FAIL: a module whose tests failed passed the job."; echo "$OUT"; exit 1; fi CALLS=$(tr '\n' ',' < "$MC/calls") -[ "$CALLS" = "bootstrap a,check a,test a,compat a,bootstrap b,check b,test b,compat b,e2e b," ] \ +[ "$CALLS" = "bootstrap a,format a,check a,test a,compat a,bootstrap b,format b,check b,test b,compat b,e2e b," ] \ && grep_text "$OUT" -qF "Criticality: high" && grep_text "$OUT" -qF "Criticality: standard" \ && grep_text "$OUT" -qF "Module checks failed: a" \ || { echo "FAIL: every module, V1 after a failure, e2e only when green — not what ran."; echo "$CALLS"; echo "$OUT"; exit 1; } diff --git a/platform/tests/test_format_hook.py b/platform/tests/test_format_hook.py index 66a5d790..6b71658c 100644 --- a/platform/tests/test_format_hook.py +++ b/platform/tests/test_format_hook.py @@ -6,8 +6,8 @@ from __future__ import annotations import os -import shutil import subprocess +import sys from pathlib import Path import pytest @@ -48,7 +48,7 @@ def _commit(project: Path, staged: dict[str, str], engine: bool = True) -> subpr for path, content in staged.items(): (project / path).write_text(content, encoding="utf-8") subprocess.run(["git", "add", path], cwd=project, check=True) - nstack = Path(shutil.which("nstack") or "").parent + nstack = Path(sys.executable).parent # this checkout's engine, never one elsewhere on PATH path = f"{nstack}:/usr/bin:/bin" if engine else "/usr/bin:/bin" return subprocess.run(["sh", "-c", _hook()["entry"]], cwd=project, capture_output=True, text=True, env={**os.environ, "PATH": path}, timeout=120) @@ -74,11 +74,39 @@ def test_a_formatted_module_passes(tmp_path): def test_only_the_modules_whose_files_are_staged_are_judged(tmp_path): - project = _project(tmp_path, {"billing": UGLY, "orders": UGLY}) + project = _project(tmp_path, {"bill": UGLY, "billing": UGLY, "orders": UGLY}) (project / "modules/orders/src/page.txt").write_text("ugly\n", encoding="utf-8") # changed, not staged + (project / "modules/bill/src/page.txt").write_text("ugly\n", encoding="utf-8") # a folder billing's begins with done = _commit(project, {"modules/billing/src/page.txt": "neater\n"}) assert done.returncode == 0, done.stdout + done.stderr - assert "orders" not in done.stdout + done.stderr + assert "orders" not in done.stdout + done.stderr and "-> bill:" not in done.stderr + + +def test_every_staged_module_is_judged_whatever_its_formatter_reads(tmp_path): + """A formatter reading its standard input never takes the list of modules still to judge.""" + project = _project(tmp_path, {"billing": "cat >/dev/null; " + UGLY, "orders": UGLY}) + done = _commit(project, {"modules/billing/src/page.txt": "neater\n", "modules/orders/src/page.txt": "ugly\n"}) + assert done.returncode == 1 and "not formatted: orders." in done.stdout, done.stdout + done.stderr + + +def test_a_path_git_would_quote_is_judged(tmp_path): + project = _project(tmp_path, {"billing": "! grep -rq ugly src"}) + done = _commit(project, {"modules/billing/src/café.txt": "ugly\n"}) + assert done.returncode == 1 and "not formatted: billing." in done.stdout, done.stdout + done.stderr + + +def test_an_engine_older_than_the_verb_lets_the_commit_go(tmp_path): + """An engine that predates `format` refuses it as an unknown command: never a commit refused for that.""" + project = _project(tmp_path, {"billing": UGLY}) + old = tmp_path / "old" + old.mkdir() + (old / "nstack").write_text('#!/bin/sh\n[ "$1" = format ] && exit 2\nexit 0\n', encoding="utf-8") + (old / "nstack").chmod(0o755) + (project / "modules/billing/src/page.txt").write_text("ugly\n", encoding="utf-8") + subprocess.run(["git", "add", "-A"], cwd=project, check=True) + done = subprocess.run(["sh", "-c", _hook()["entry"]], cwd=project, capture_output=True, text=True, + env={**os.environ, "PATH": f"{old}:/usr/bin:/bin"}, timeout=60) + assert done.returncode == 0 and "this nstack has no format verb" in done.stdout, done.stdout + done.stderr @pytest.mark.parametrize("formats, said", [ diff --git a/skeleton/.nstack/format-before-commit.sh b/skeleton/.nstack/format-before-commit.sh index f1653145..257977c6 100755 --- a/skeleton/.nstack/format-before-commit.sh +++ b/skeleton/.nstack/format-before-commit.sh @@ -1,7 +1,8 @@ #!/bin/sh # At a commit, the formatter each module declares (commands.format), on the modules whose files are # staged: the pre-commit hook nstack-format of .pre-commit-config.yaml (.nstack/handbook/09-platform.md -# §2). pre-commit has set aside what is not staged, so what is judged is what the commit holds. +# §2). pre-commit sets aside the changes not staged; a file git does not track stays, and a formatter +# that reads its whole folder (`prettier --check .`) judges it too. # Module checks runs the same command in CI: this one only says it sooner. Where nstack, an engine # that knows the verb, or the module's own tool (exit 127) is missing here, it says so and lets the # commit go: CI judges. @@ -10,7 +11,7 @@ command -v nstack >/dev/null 2>&1 || { echo "nstack is not installed: formatting is judged in CI"; exit 0; } nstack format --help >/dev/null 2>&1 || { echo "this nstack has no format verb: formatting is judged in CI"; exit 0; } -STAGED=$(git diff --cached --name-only --no-renames) +STAGED=$(git -c core.quotePath=false diff --cached --name-only --no-renames) # `café.txt` as it is, never quoted [ -n "$STAGED" ] || exit 0 TAB=$(printf '\t') FAILED=$(nstack modules --root . | while IFS="$TAB" read -r MODULE FOLDER; do diff --git a/skeleton/.nstack/handbook/09-platform.md b/skeleton/.nstack/handbook/09-platform.md index f3f92e01..1df67748 100644 --- a/skeleton/.nstack/handbook/09-platform.md +++ b/skeleton/.nstack/handbook/09-platform.md @@ -54,7 +54,7 @@ section, with its own stack's commands. |---|---|---| | `bootstrap` | Make the module usable from a fresh clone | Without prior knowledge | | `format` | Tell whether the module's files are formatted — the formatter's check, writing nothing, building nothing | In seconds, at every commit: the pre-commit hook runs it on the modules whose files are staged | -| `check` | All the fast validations: format, lint, types | In under 2 minutes | +| `check` | All the fast validations: lint, types — and format, where `format` is not declared | In under 2 minutes | | `test` | The module's test suite | With no dependency on another module | | `run` | Start the module locally | With doubles for the dependencies | | `e2e` | The module's end-to-end scenarios; logs and screenshots written to `$NSTACK_EVIDENCE` (`.evidence/e2e/`), read after the run; exit 77 when it cannot run here. One at a time on a machine: a second waits for the first, whichever project or command started it, and says for whom, again every minute; a module whose run is sealed (`evidence.sealed: true`) neither waits nor holds | Against the running module, in CI | diff --git a/skeleton/.nstack/handbook/INSTALL.md.jinja b/skeleton/.nstack/handbook/INSTALL.md.jinja index 05bb54db..02c24c53 100644 --- a/skeleton/.nstack/handbook/INSTALL.md.jinja +++ b/skeleton/.nstack/handbook/INSTALL.md.jinja @@ -435,6 +435,7 @@ nstack doctor # the workstation and the forge's settings, read-only nstack settings # the calls that would bring the forge's settings to the checklist; --apply: yours makes them nstack new-module [--user-facing] # --user-facing: a user sees it, which decides a test sheet nstack new-contract # a contract, and the first time the module that holds them all +nstack format [module] # the formatter's check, commands.format, when declared — the pre-commit hook runs it nstack check [module] # the module's commands.check; default: every module nstack test [module] # commands.test, likewise nstack bootstrap [module] # commands.bootstrap, when declared diff --git a/src/napkinstack/cli.py b/src/napkinstack/cli.py index d63c4096..bdf483f0 100644 --- a/src/napkinstack/cli.py +++ b/src/napkinstack/cli.py @@ -150,7 +150,7 @@ def build_parser() -> argparse.ArgumentParser: for verb, help_text in (("bootstrap", "prepares one module, or all of them (commands.bootstrap)"), ("format", "tells whether one module's files, or all modules', are formatted; " "writes nothing (commands.format)"), - ("check", "format, lint, types of one module, or all (commands.check)"), + ("check", "lint, types — and format where commands.format is not declared — of one module, or all (commands.check)"), ("test", "tests of one module, or of all of them (commands.test)"), ("e2e", "end-to-end scenarios of one module, or of all (commands.e2e)"), ("clean", "removes what one module's commands left in its folder, or all " diff --git a/src/napkinstack/modules.py b/src/napkinstack/modules.py index fcba95b8..01c5eca0 100644 --- a/src/napkinstack/modules.py +++ b/src/napkinstack/modules.py @@ -1,6 +1,6 @@ """ A project's modules: creation (nstack new-module) and standard verbs (nstack bootstrap, -check, test, run, e2e, clean, release), with no imposed stack (PRODUCT.md P1, PDR-0001 R5). +format, check, test, run, e2e, clean, release), with no imposed stack (PRODUCT.md P1, PDR-0001 R5). Each verb runs the command declared in the `commands` section of the module's MANIFEST.yaml, from its folder, through the system shell. NapkinStack never assumes a diff --git a/src/napkinstack/templates/module/MANIFEST.yaml b/src/napkinstack/templates/module/MANIFEST.yaml index 739053c2..99ff95c7 100644 --- a/src/napkinstack/templates/module/MANIFEST.yaml +++ b/src/napkinstack/templates/module/MANIFEST.yaml @@ -73,7 +73,8 @@ dependencies: [] # No stack is imposed. check and test are required once the module holds more than its # description (fitness M7): declare them before its first file of code. commands: -# check: # under 2 min: format, lint, types +# format: # optional, seconds: the formatter's check alone, run at every commit +# check: # under 2 min: lint, types — and format, where `format` is not declared # test: # NEVER starts another module # bootstrap: # optional: make the module usable from a fresh clone # run: # optional: local start, with doubles for the dependencies From c3498d6479237fb04e229d56a0a0416bf95f7999 Mon Sep 17 00:00:00 2001 From: "napkinstack-agent[bot]" <330339777+napkinstack-agent[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 05:03:13 +0100 Subject: [PATCH 3/4] =?UTF-8?q?D316=20=E2=80=94=20the=20repository=20runs?= =?UTF-8?q?=20the=20hook=20it=20ships=20(P3)=20(#593)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The repository's .pre-commit-config.yaml is the skeleton's, as the oracle requires; .nstack/format-before-commit.sh beside fitness-before-push.sh. Agent-Session: napkinstack-os-1e Co-Authored-By: Claude Opus 5.5 --- .nstack/format-before-commit.sh | 30 ++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 11 +++++++++++ 2 files changed, 41 insertions(+) create mode 100755 .nstack/format-before-commit.sh diff --git a/.nstack/format-before-commit.sh b/.nstack/format-before-commit.sh new file mode 100755 index 00000000..257977c6 --- /dev/null +++ b/.nstack/format-before-commit.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# At a commit, the formatter each module declares (commands.format), on the modules whose files are +# staged: the pre-commit hook nstack-format of .pre-commit-config.yaml (.nstack/handbook/09-platform.md +# §2). pre-commit sets aside the changes not staged; a file git does not track stays, and a formatter +# that reads its whole folder (`prettier --check .`) judges it too. +# Module checks runs the same command in CI: this one only says it sooner. Where nstack, an engine +# that knows the verb, or the module's own tool (exit 127) is missing here, it says so and lets the +# commit go: CI judges. +# +# Plain sh: the workstation's engine may predate this file. +command -v nstack >/dev/null 2>&1 || { echo "nstack is not installed: formatting is judged in CI"; exit 0; } +nstack format --help >/dev/null 2>&1 || { echo "this nstack has no format verb: formatting is judged in CI"; exit 0; } + +STAGED=$(git -c core.quotePath=false diff --cached --name-only --no-renames) # `café.txt` as it is, never quoted +[ -n "$STAGED" ] || exit 0 +TAB=$(printf '\t') +FAILED=$(nstack modules --root . | while IFS="$TAB" read -r MODULE FOLDER; do + printf '%s\n' "$STAGED" | awk -v folder="$FOLDER/" 'index($0, folder) == 1 { found = 1 } END { exit !found }' || continue + nstack format "$MODULE" &2 + case $? in + 0) ;; + 127) echo "-> $MODULE: its formatter is not installed here: judged in CI" >&2 ;; + *) printf '%s ' "$MODULE" ;; + esac +done) +if [ -n "$FAILED" ]; then + echo "FAIL [nstack] not formatted: ${FAILED% }." + echo " Action: run the module's formatter (its AGENTS.md says which), git add, then commit again." + exit 1 +fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 17aec0ef..cc88f8de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -118,6 +118,17 @@ repos: exit 1' -- stages: [commit-msg] + # At a commit, the formatter each module declares (commands.format), on the modules whose + # files are staged: a module's own command, in seconds, never a build. Where nstack, or the + # module's tool, is not installed here, it says so and lets the commit go: Module checks + # judges in CI. .nstack/format-before-commit.sh. + - id: nstack-format + name: NapkinStack modules' formatters (commands.format) + language: system + entry: sh .nstack/format-before-commit.sh + pass_filenames: false + stages: [pre-commit] + # Before a push, the fitness functions CI runs on every pull request — a fault seen here, # not after a round trip. The skills are left to CI: what they are generated from is # the engine's version, which a contributor's may not be. Where nstack is not From 93ea9e4539e4b1ee58a68ed8241f4747c6727ec8 Mon Sep 17 00:00:00 2001 From: "napkinstack-agent[bot]" <330339777+napkinstack-agent[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 05:08:57 +0100 Subject: [PATCH 4/4] =?UTF-8?q?D316=20=E2=80=94=20the=20oracle's=20hook=20?= =?UTF-8?q?repositories=20hold=20the=20scripts=20the=20hooks=20run=20(#593?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Session: napkinstack-os-1e Co-Authored-By: Claude Opus 5.5 --- platform/tests/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/tests/run.sh b/platform/tests/run.sh index 91b03175..e89a9d9b 100755 --- a/platform/tests/run.sh +++ b/platform/tests/run.sh @@ -412,6 +412,7 @@ repo_with_hooks() { git "${GIT_ID[@]}" init -q "$d" [ -f .pre-commit-config.yaml ] && cp .pre-commit-config.yaml "$d/" [ -f .yamllint.yaml ] && cp .yamllint.yaml "$d/" + mkdir -p "$d/.nstack" && cp .nstack/*.sh "$d/.nstack/" # what the hooks run, as a project holds it git -C "$d" add -A git "${GIT_ID[@]}" -C "$d" commit -q --no-verify --allow-empty -m init (cd "$d" && pre-commit install >/dev/null)