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
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

# One job on every pull request, with no path filter, so the required `check` is emitted for every change, docs-only
# ones included. It runs the same two validators as the pre-commit hook.
# ones included. It runs the same check as the pre-commit hook.
on:
push:
branches: [main]
Expand All @@ -27,7 +27,5 @@ jobs:
- uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2
with:
deno-version: v2.x
- name: Validate the constitution
run: deno task test
- name: Validator tests
run: deno task test:validator
- name: Check markdown formatting
run: deno task check
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deno task test && deno task test:validator
deno task check
133 changes: 9 additions & 124 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,11 @@
# AGENTS.md — Constitution Repository
# constitution

Single source of truth for the supreme design law of [System F Software](https://systemfsoftware.com). Consumer repos vendor via `git subtree` + symlink. This repo has no production code, no test suite, and no build step — it is two documents plus governance tooling (corpus validation, commit validation): `CONSTITUTION.md`, the maker's law, resident in every agent's context, every law, always; and `ENFORCEMENT.md`, the instrument owner's doctrine, never loaded into the maker's context.
The organization's shared `CODING_STANDARDS.md` and `REVIEW.md`. Consumer
repositories vendor this repository at `repos/constitution/`. There is no code
here.

@CONSTITUTION.md

## Startup Workflow

Before making changes:

1. **Read this file** completely.
2. **Confirm the active task** with the user or the agent's task list.
3. **Review recent commits** with `git log --oneline -5`.
4. **Ensure current branch is not `main`** — feature branches only. If on main, create one.

## Working Rules

- **One task at a time.** Finish before starting the next.
- **Conventional commits required.** The commit-msg hook enforces `type(scope): description`. Run `git commit` through the hook — do not bypass with `--no-verify`.
- **Verification required.** Run the verification commands before claiming done.
- **Stay in scope.** Don't modify files unrelated to the task. Scope reduction requires explicit user approval.
- **Leave clean state.** The next session must run verification immediately.

## Amending the Constitution

### Corpus

- **`CONSTITUTION.md` (Resident):** the entire maker corpus — a one-line preamble and the laws in four sections (Model the domain, Shape the code, Prove it, Finish) — loaded in every session. There is no retrieved half and no on-demand trigger: law that is not in the window is not law. Residency delivers obligation, not enforcement; the machinery of judgment lives outside the maker's reach.
- **`ENFORCEMENT.md` (Non-resident):** the instrument owner's doctrine — gate design, instrument-change discipline, enrollment law. Read by whoever builds or changes a gate, never `@`-imported into a maker's context. Consumer repos route to it from the leaves that own enforcement surfaces (lint plugins, guard scripts, CI workflows, rules directories, advisor rosters): one line — "You are editing an enforcement instrument. Read the vendored `ENFORCEMENT.md` before this lands." A routing line added anywhere else is the defect: the maker must not meet instrument doctrine while doing graded work.
- **`docs/solutions/`:** past problems and their fixes, organized by category with YAML frontmatter (`module`, `tags`, `problem_type`); `CONCEPTS.md` at repo root holds shared domain vocabulary.

### Writing a Rule

Laws are fenced YAML sequences, one block per section of `CONSTITUTION.md`. Each item has exactly `id`, `law` (one sentence addressed to you), `why` (the harm), and `example` with exactly `wrong` and `right`. The whole file stays within 1,800 words (`wc -w`). `deno task test` fails on a missing or extra field and on the word budget.

Each law has exactly one entry in the `## Corpus` block of `ENFORCEMENT.md`: `law`, `handle`, `absorbs`, `checks` (each a `question` with its `criteria`), `mechanism` (type, command, refusal, review), `severity`, `waiver`, and at least two `incidents` — failures from public history, each a commit, path and line. The corpus also holds the `judging` rules and the `retired` ids. `deno task test` fails on a law without exactly one entry, a duplicate handle, fewer than two incidents, or a citation that resolves to no live, judging or absorbed id; whether each incident is a real failure is review.

### Minting an ID

ID format: `CONST-<family><n>`. Pick the next free number in the family (never renumber to close gaps).

| Letter | Family | Purpose |
|---|---|---|
| `G` | Governance | Judging rules in the `ENFORCEMENT.md` corpus: verdict severity, reading by purpose, supremacy |
| `E` | Enforcement | The maker's conduct under judgment (evidence, the instrument boundary); instrument design lives in `ENFORCEMENT.md` |
| `P` | Purity | Decision functions and side-effect isolation |
| `D` | Domain modelling | Domain types and constraints |
| `B` | Boundary | Core/shell boundaries, effects, adapters |
| `T` | Testing | Testing strategy, mutation, properties |
| `N` | Naming & structure | Module organization and naming |
| `W` | Work discipline | Task scope, bypass declarations, reviews |
| `S` | Subtraction | Code deletion and structural simplification |

### Changing a Rule

- Same obligation reworded or moved: **keep the id and its handle**.
- Obligations merged: the survivor keeps the lowest surviving id; the others go to its entry's `absorbs:`.
- Obligation removed: the id goes to `retired:` with its reason. Obligation narrowed, widened, or split: mint a new id.
- Handles are frozen once landed, and an absorbed or retired id is never reused: `deno task test --against <rev>` fails a changed handle and an absorbed or retired id that returns as live. Whether a change is a rewording or a changed obligation is review.
## Surface Classes

| Surface | Files | Rule |
|---|---|---|
| **Locked** | `AGENTS.md`, `.husky/_/`, verification scripts | Read and propose changes; do not edit to make verification pass. |
| **Editable** | `deno.json`, `deno.lock`, `commitlint.config.cjs`, `.gitignore`, `.husky/` (hooks only, not `_/`) | Edit freely within the active task. |
| **Human-controlled** | `CONSTITUTION.md`, `README.md`, merging to `main`, pushing, destructive ops | Propose changes; ask the user before acting. |

## Definition of Done

A task is done only when ALL of the following are true:

- [ ] Target changes are applied.
- [ ] Verification commands ran and passed.
- [ ] Commit uses conventional format (`type(scope): description`).
- [ ] Evidence recorded via the runtime memory system and task list.
- [ ] No dirty files left in the working tree.

## Verification Commands

```bash
deno task test # two files: law schema, word budget, corpus entries, handles, ids, families, dangling citations
deno run --allow-read --allow-env --allow-run npm:@commitlint/cli@21 --from HEAD~1
```

After a commit that deletes, splits, merges, or re-scopes a rule — not after every edit — also run the lineage check against the revision before it:

```bash
deno task test --against <rev>
```

### Anti-Bypass Rules

- Run the **full command**, not parts in isolation.
- Evidence must be from the **current run**, not a prior session.
- **Any failure blocks done.** Do not bypass with `--no-verify`.
- Do not suppress, skip, or disable checks to make verification pass.

### Hallucination Prevention

- **Read before edit:** before editing a file, read it in the current session. Do not edit from memory.
- **Verify before claim:** before saying "done," the verification command must have run and its output recorded.
- **Search before write:** before writing code that calls a library API, read the actual API surface. Do not generate from training memory.

## Multi-Agent Ownership

When multiple agents work in the same repo:

- Each agent owns a disjoint file/module set.
- An agent must claim a file before editing it.
- Agents may not recursively delegate to each other.
- The one-shot verification must pass before any agent claims done.

## End of Session

Before ending a session:

1. Record current state, blockers, and next steps via the runtime memory system and task list.
2. Commit with a conventional-format message once work is in a safe state.
3. Leave the repo clean — `git status` should show nothing unexpected.

## Escalation

- **Constitution conflict**: `CONSTITUTION.md` is already in context — reread it there, not from disk.
- **Unclear requirements**: Ask the user.
- **Verification failure**: Record via memory, flag for review, do not bypass.
- **Scope ambiguity**: Re-read this file and the Definition of Done.
- Read `CODING_STANDARDS.md`, `REVIEW.md` and `CONTRIBUTING.md` before you
change a rule.
- This repository is public. Nothing private goes in it (`SF-SEC-1`).
- Verify with `deno task check` before you push. Never pass `--no-verify`.
- Work on a branch; `main` changes only through a pull request.
161 changes: 161 additions & 0 deletions CODING_STANDARDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Coding Standards

Review criteria for every repository in systemfsoftware. Repositories vendor
this repo via `git subtree` at `repos/constitution/`. Local
`CODING_STANDARDS.md` files add repo-specific rules that take local precedence,
except that they cannot loosen anything `REVIEW.md` rates P0. Cite rules by ID,
such as `(SF-IMP-1)`.

Apply each rule by its purpose. Where wording and harm disagree, harm decides.

## Impossible states first

Make invalid states impossible to construct before writing or proposing a test.
A state the compiler refuses needs no test and cannot return unnoticed.

- **SF-IMP-1** In typed code, close types so illegal values cannot be
constructed: use a union of valid combinations, a branded type per role, or a
separate service tag per unshared resource. Model mutually exclusive states as
a tagged union where each variant holds only its own fields. Use a plain
nullable type only when a value is absent the same way in every state. Parse
external data into domain types only via a decoder returning a typed result,
never a cast or suppression comment. In untyped languages, validate external
data at the boundary with a schema that fails on invalid input.
- Why: an illegal value the compiler could have rejected reaches runtime,
where downstream code trusts it.
- Wrong: a lock helper accepted a lock spec and a nullable adapter, so a spec
requiring a lock with no adapter ran its body unlocked.
- Right: a single union of valid spec-and-adapter pairs made the unlocked
state impossible to construct.
- **SF-IMP-3** In typed code, give each failure a caller handles differently its
own tagged variant so callers can branch on it.
- **SF-IMP-4** The compiler is the evidence for such a fix. Commit one tstyche
assertion that the refused state is refused. Put it in the package's
`test-types/`, run by its `typecheck` script and never by its tests. Use
`expect<Bad>().type.not.toBeAssignableTo<Good>()` (or
`not.toBeAssignableFrom`); use `toRaiseError` only where no assignability pair
expresses the refusal (an overload, an inference failure, a missing service),
and always with the expected message. Import the real types: a published type
by the package's name, an internal one by a relative path into `src/`. Never
add or widen an export, subpath or imports map so an assertion can reach a
type. Write one per state the change closes, and delete it with the type.
Where the language has no such tool, paste the compiler error into the PR
body.
- Why: it costs no test run, fails when the state becomes constructable again,
and passes for that reason only.
- **SF-IMP-5** Never write or propose an integration, end-to-end, or microVM
test for an invariant a type can enforce; enforce it in types (`SF-IMP-1`).
Test at runtime only behaviour the compiler cannot prove (decoding external
data, peer responses, timing, or database and runtime behaviour). Run tests at
the lightest tier reaching that boundary and name the covered behaviour in any
test proposal.
- Why: slow tests tie up shared hosts while proving less than a compile error.

## Tests

- **SF-TST-1** Test the published surface with real inputs and outputs, using
only what consumers import or call, never package internals. A type assertion
under `SF-IMP-4` is not a test and may import internal types.
- Why: tests bypassing the published interface can pass when the shipped
artifact is broken.
- **SF-TST-2** Derive expected values from an oracle independent of the code
under test (requirement literal, independent fixture, law between two views,
or second implementation).
- Why: comparing code against its own output cannot fail when the code is
wrong.
- **SF-TST-4** Assert outcomes, not internal steps: verify what the system
produced, never which functions ran, which lines a file contains, or which
keys, entries, or values repo configuration lists.
- Why: tests coupled to steps or configuration break on refactoring and still
pass when outcomes are wrong.
- **SF-TST-5** Every test must fail when its named behaviour breaks. Delete any
test with a defective assertion (checking steps, configuration, or file
layout; copying expected values from code; unable to fail; or covering removed
behaviour); never rewrite, retitle, or replace it. Fix a test whose only fault
is how it reaches the code (an internal import or real clock). Deleting a
worthless test is welcome and does not count as lost coverage. When a valid
test fails, fix the code under test, not the test.
- Why: reshaping a bad test keeps its cost and false confidence; weakening a
good test hides defects.
- **SF-TST-6** Keep unit tests deterministic and isolated: no child processes,
real clocks, network calls, host ports, host file system, or shared state
across tests. Put I/O tests in adapter suites and run them where repo testing
rules specify.
- Why: tests that spawn processes or sleep stall the host and fail on timing
rather than code defects.
- **SF-TST-7** Treat a property-test timeout as a design failure. Fix its input
schema, or delete the test if it encodes one specific scenario. Never raise
its timeout, lower its run count, or narrow its generator.
- Why: tuning the budget hides a schema generating out-of-domain values.

## Shape the code

- **SF-SHP-1** Keep side effects at the edges: a pure core returns the next read
or write as data, and a thin shell executes it. The shell imports the core,
and one composition root wires all implementations. The core never imports the
shell, a database, or a framework.
- Why: decision logic coupled to side effects cannot be tested or replaced in
isolation.
- **SF-SHP-5** Fix the root cause of defects; restructure wrong underlying
designs. Never add unrequested aliases, fallbacks, or compatibility shims.
- Why: patching symptoms lets defects return, and each shim adds a second code
path to maintain.
- **SF-SHP-7** Every line of code is a liability. Delete dead code, unify
duplicate paths, or make invalid states unconstructable before adding code.
When removing something, delete every definition, call site, and export in the
same PR.
- Why: unused code or competing conventions lead future PRs to imitate the
wrong pattern.
- **SF-SHP-8** Before writing a client, script, test utility, or helper, search
org packages and repo skills for an existing one; use or fix it in place. Name
where you searched in any PR adding a helper. Never patch, fork, or override a
dependency; change the design that needed it or fix it upstream.
- Why: duplicate helpers drift out of sync, and patched dependencies silently
diverge on upgrade.
- **SF-SHP-9** Write scripts in the repo's typed language, or in Deno or
TypeScript if it has none. Use shell scripts only as thin wrappers setting
options and running one command.
- Why: shell scripts lack type checking and tests, and fail silently.

## Secrets and public repositories

- **SF-SEC-1** Never commit secrets, tokens, or credentials. Never put anything
from a private repo into a public repo across files, fixtures, commit
messages, PR text, or comments: private repo, package, or product names, local
paths, hosts, people, emails, private run IDs or links, issue-tracker IDs, or
internal agent or process names.
- Why: leaked secrets require rotation everywhere, and private names in public
git history cannot be erased.

## Graders and gates

Applies to graders (lint rules, CI jobs, hooks, thresholds, rubrics). Read
`GRADERS.md` when building or editing a grader.

- **SF-GATE-2** Add a grader only for a named mistake. Key it on the failure
itself (recomputed source, compiler verdict, or real outcome), never on names,
line positions, formatting, or author-supplied fields. Fix underlying failures
instead of adding graders beside them.
- Why: brittle graders pile up, block valid work, and still miss the
underlying mistake.
- **SF-GATE-5** Edit a grader only in a PR whose task is that grader, proving it
refuses a failing case and passes the clean tree (use a CI run when too heavy
to run locally). Never edit, loosen, or add to a grader so in-flight work
passes. Graders include thresholds, budgets, globs, baselines, lint configs,
workflows, rubrics, `CODING_STANDARDS.md`, `REVIEW.md`, and test or CI
timeouts, but not runtime timeouts waiting on a network, database, or peer.
When the owner orders a grader changed or turned off, that is a change whose
task is the grader: make it in its own PR, holding nothing else.
- Why: whoever edits the grader reports the score they chose.

## Maintaining this file

- Add a rule only when a fixed review finding, fix commit, or solution record
demonstrates the failure, no grader covers it, and it holds in every repo.
State rules as diff-visible conditions without volatile numbers. Delete or
merge existing rules before adding a new one.
- Rule IDs are permanent; gaps are never reused. Retired: SF-IMP-2 (merged into
SF-IMP-1), SF-TST-3 (merged into SF-TST-5), SF-SHP-2 (merged into SF-SHP-1).
Deleted: SF-SHP-3, SF-SHP-4, SF-SHP-6. Moved: SF-GATE-1, SF-GATE-3, SF-GATE-4,
SF-GATE-6 to `GRADERS.md`; SF-FIN-1 to `WORKING.md`.
- Put agent workflow rules, rather than code rules, in `WORKING.md`.
Loading