Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .nstack/format-before-commit.sh
Original file line number Diff line number Diff line change
@@ -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" </dev/null >&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
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/governance/workstreams.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ state to its index: [`docs/adr/`](../adr/README.md), [`docs/pdr/`](../pdr/README
| 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 <default>`, or in a worktree beside the one that holds it `git switch --detach <default>` (#261), and the command makes its own branch: make none before |
| D314 | **A pull request titled with a deliverable's part, "D126 3c —", was not read as delivering it** (#588). Downstream, 2026-11-29, 0.35.4: `nstack deliver D126 --held '1=#1372'` refused it; the team titles a deliverable's parts "D121 4a —", "D123 (a) —", "D126 3c —", one pull request in two. D300 read a letter glued to the id only | **Done**: after the id and its letter, a part is read too — a number with an optional letter, "-1", or, opening the title, "(a)" — before the dash or the colon, and in the closing parentheses; `deliver`, `plan` and the start branches' landing read these part forms alike. Words there stay a mention, and a part takes no scope after it: "D12 is next —", "D7 (wip) —", "D12 3 files:" name nothing. Not read: "(a)" inside the closing parentheses, which hold no nested ones |
| 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 |
Expand Down
2 changes: 1 addition & 1 deletion platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uv run nstack doctor --root <project> # workstation and GitHub settings, re
uv run nstack new-module <name> <owner> <criticality> --root <project>
uv run nstack new-contract <name> --root <project>
uv run nstack settings --root <project> # the calls that would close the gaps, printed
uv run nstack check [module] --root <project> # also test, bootstrap, e2e, clean, release; run <module>
uv run nstack check [module] --root <project> # also format, test, bootstrap, e2e, clean, release; run <module>
```

## Skills
Expand Down
3 changes: 2 additions & 1 deletion platform/tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1400,7 +1401,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; }
Expand Down
1 change: 1 addition & 0 deletions platform/tests/test_forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
Expand Down
132 changes: 132 additions & 0 deletions platform/tests/test_format_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""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 subprocess
import sys
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(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)


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, {"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 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", [
({"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
2 changes: 1 addition & 1 deletion skeleton/.github/workflows/module-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions skeleton/.nstack/check-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading