| 1 | # Architecture |
| 2 | |
| 3 | The bets, each traced to a requirement ([requirements.md](./requirements.md)) and taken no deeper |
| 4 | than rationale. Detailed design lives in the rest of `design/`, and only for roadmap phases that are |
| 5 | current or next — later phases get their detail re-fleshed when they start, informed by what |
| 6 | validation has taught us. |
| 7 | |
| 8 | ## Shape of the system |
| 9 | |
| 10 | ``` |
| 11 | bare git (Tailscale) ──┐ ┌──► nix build (pure reactions) |
| 12 | build outputs ───┤ │ |
| 13 | agent runs (klaus) ───┼──► event bus ──► subscribers ──► armstrong (effectful reactions) |
| 14 | deploy state ───┤ (NATS JS) │ |
| 15 | external signals ──┘ └──► integrator (per-repo integration) |
| 16 | |
| 17 | attestations published to a Tessera-backed transparency log on every push |
| 18 | ``` |
| 19 | |
| 20 | ## The concerns, unbundled |
| 21 | |
| 22 | | Concern | Current state | Direction | |
| 23 | | ------------------------ | --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | |
| 24 | | Hosting | Works fine, lock-in is the cost | Bare git over SSH on a Tailscale-reachable box | |
| 25 | | Identity / access | Works fine | Tailscale ACLs + SSH keys | |
| 26 | | Verification | Slow, YAML-shaped | `nix flake check` triggered by events | |
| 27 | | Artifacts | Opaque, ephemeral | Nix derivations, content-addressed, pushed to a cache | |
| 28 | | Automation | Actions: push-based, brittle | Reactive controllers subscribing to an event log | |
| 29 | | Integration / merge | Branch protection in vendor UI | Pull-based integrator controllers reacting to integration-requested events | |
| 30 | | Observability & feedback | PR-shaped, conflates four concerns | Continuous feedback as events; threads as derived views; priority/routing as a first-class subsystem | |
| 31 | | Project knowledge | Scattered: issues, wikis, docs, scratch files, agent histories, heads | Unified typed-node graph in markdown, equally navigable by humans and agents; discussion threads are themselves nodes | |
| 32 | |
| 33 | ## Bet: git as event source — a log, not a workflow engine |
| 34 | |
| 35 | _Serves: automation, observability._ |
| 36 | |
| 37 | GitHub Actions, GitLab CI, Jenkins — all push-based pipelines. An event happens, a workflow runs, it |
| 38 | exits, the trail is a log file. |
| 39 | |
| 40 | A reactive log inverts this: |
| 41 | |
| 42 | - **Causality is preserved.** The chain of "commit → build → deploy → notification" is one queryable |
| 43 | history, not seven disconnected job UIs. |
| 44 | - **Reactions are independent.** Adding a new subscriber doesn't touch any other subscriber or any |
| 45 | workflow file. |
| 46 | - **Replay is free.** Want to know what would have happened if a reaction had been different? Replay |
| 47 | the log against a new subscriber. |
| 48 | - **No central workflow file.** Each subscriber owns its own logic and lifecycle. |
| 49 | |
| 50 | Per-repo events (refs, attestations, integration requests) are durable in git itself; the bus is a |
| 51 | projection that can be rebuilt. Only ephemeral cross-system events (deploys, metrics, agent runs) |
| 52 | have the bus as their source of truth — so the log is never load-bearing for the crown-jewel data. |
| 53 | |
| 54 | Prior art: Atomist (defunct, but had this model). Kubernetes controllers. Datomic / event sourcing |
| 55 | generally. `git` itself — commits are events, refs are views. |
| 56 | |
| 57 | ## Bet: attestation with revocation, not CI as gate |
| 58 | |
| 59 | _Serves: verification (feedback in seconds), agents as first-class authors._ |
| 60 | |
| 61 | The contributor's own hermetic environment runs the canonical checks and produces a signed |
| 62 | attestation of what ran, against what inputs, with what result. Subscribers act on the attestation |
| 63 | immediately. Re-verifiers cross-check it asynchronously. Trust is _measured_ per attester from |
| 64 | re-verification confirm rates, and divergence revokes it. |
| 65 | |
| 66 | This trades two failure modes: |
| 67 | |
| 68 | | Model | Failure mode | |
| 69 | | ----------- | ------------------------------------------------------------------------------ | |
| 70 | | CI-as-gate | False negatives — slow feedback, flakes, infra outages block correct changes | |
| 71 | | Attestation | False positives — a bad attestation can land before the re-verifier catches it | |
| 72 | |
| 73 | For most environments — personal projects, small teams, trusted contributor sets — false positives |
| 74 | that are _detected and revocable_ are a much better trade than a slow, brittle gate. The primary win |
| 75 | is latency; the security properties are a side effect of doing it well. See |
| 76 | [verification.md](./verification.md) for what makes an attestation hard to forge. |
| 77 | |
| 78 | ## Bet: a pull-based integrator, not a pre-receive gate |
| 79 | |
| 80 | _Serves: integration (observable, policy-driven), architectural minimalism._ |
| 81 | |
| 82 | The simplest option is a `pre-receive` hook that checks attestations on every push to a protected |
| 83 | branch. It works — but it makes integration a different _shape_ from the rest of the system, a |
| 84 | synchronous special case whose failure mode is a terse line of stderr. The design instead adopts a |
| 85 | **pull-based integrator**: a controller subscribing to integration-request events, performing |
| 86 | integration as a reaction, emitting outcome events back into the log. |
| 87 | |
| 88 | | | Pre-receive gate | Pull-based integrator | |
| 89 | | ------------------------------- | -------------------------------------- | -------------------------------- | |
| 90 | | Where policy lives | Hook script on git server | Controller subscribing to events | |
| 91 | | Failure mode | Push error to stderr | Outcome event in log, threadable | |
| 92 | | Multiple policies | Hard (one hook per repo) | Trivial (multiple subscribers) | |
| 93 | | Async validation | No — must answer before push completes | Yes — controller takes its time | |
| 94 | | Re-running on transient failure | Re-push | Re-fire the event | |
| 95 | | Architectural consistency | Special case | Same pattern as everything else | |
| 96 | |
| 97 | Merge-queue semantics fall out for free: requests targeting the same ref serialize in the |
| 98 | integrator. And the failure model is deliberately unified — there is no rejection, only |
| 99 | **staleness**: a request that can't progress against current policy is marked stale, once, and |
| 100 | refreshing it is the branch owner's problem, not the integrator's. What makes staleness computable |
| 101 | per check, so that refreshing one is not refreshing all of them, is |
| 102 | [integration.md](./integration.md). |
| 103 | |
| 104 | ### The one structural git invariant |
| 105 | |
| 106 | The bare repo enforces exactly one invariant, with two parts: **only the integrator's key may write |
| 107 | protected refs, and attestation refs are create-only**. Everything else — topic branches, new |
| 108 | attestation refs, integration requests — is wide open to anyone with push access. That's one short |
| 109 | `pre-receive` hook; all complex policy lives in the integrator. |
| 110 | |
| 111 | ## Bet: review is observability + feedback |
| 112 | |
| 113 | _Serves: observability & feedback; dissolves the "how do humans review agent code" question._ |
| 114 | |
| 115 | "Review" is one slice of a larger problem: how the system gives feedback to anyone or anything that |
| 116 | needs it. The PR-as-page model conflates: |
| 117 | |
| 118 | | Concern | What it does | Failure mode today | |
| 119 | | ------------ | ------------------------------------------- | -------------------------------------------------------- | |
| 120 | | Coordination | A place humans converge to discuss a change | Discussion thread is locked to the PR; orphaned at merge | |
| 121 | | Gating | Correctness checks must pass before merge | Slow, brittle, false negatives | |
| 122 | | Record | Persistent trace of why a change happened | Lives inside one vendor's database | |
| 123 | | Notification | Someone needs to look at this | Firehose; no useful prioritization | |
| 124 | |
| 125 | Unbundled: **gating** is handled by attestations; the **record** is the event log itself; |
| 126 | **coordination** happens in threads — named, persistent _views_ over events scoped to a change, |
| 127 | derived rather than stored; **notification** becomes a priority/routing subsystem, which is the hard |
| 128 | new bottleneck the design creates. The PR object disappears — what people call "a PR" becomes a |
| 129 | query with a name. Pre-merge human review becomes the exception: humans engage when the priority |
| 130 | layer flags something for them, and feedback accrues continuously before and after a change lands, |
| 131 | on the same machinery. |
| 132 | |
| 133 | ## Bet: project knowledge is a typed-node graph |
| 134 | |
| 135 | _Serves: project knowledge & discussion, agents as first-class authors._ |
| 136 | |
| 137 | Everything in a project that isn't executable code or user-facing docs — outcomes, bugs, principles, |
| 138 | decisions, ideas, threads — is a **typed node**: a markdown file whose YAML frontmatter carries the |
| 139 | structured layer (type, id, status, typed edges) and whose body carries prose. The graph lives at |
| 140 | the repo root, clones with the code, and is equally navigable by a human with `grep` and an agent |
| 141 | parsing frontmatter. Nodes are signed by the same keys as commits; discussion threads are themselves |
| 142 | nodes; and active principles can become load-bearing on integration policy. Not a wiki, not |
| 143 | Obsidian, not Jira — a project substrate that exposes a knowledge-tool-shaped surface. |
| 144 | |
| 145 | ## Bet: the knowledge graph read generatively — an outcome DAG |
| 146 | |
| 147 | _Serves: project knowledge & discussion (the work itself is knowledge), agents as first-class |
| 148 | authors. Anchored at rungs S3/S4 of the [scenario ladder](./user-scenarios.md)._ |
| 149 | |
| 150 | The typed-node graph already stores dependency structure: `blocked_by`/`blocks` edges form a |
| 151 | dependency DAG. The bet is to make **outcome** — a thing someone wants to exist that does not yet — |
| 152 | the central node type and read that DAG _generatively_: open outcomes are not a record of intent but |
| 153 | a worklist the system is under pressure to complete. Root outcomes — the things a human actually |
| 154 | asked for — carry a priority that propagates down to the sub-outcomes that must complete for them. |
| 155 | The system dispatches the **unblocked frontier** — the open outcomes whose blockers are all closed — |
| 156 | on the critical path toward the highest-priority root. Dispatch is klaus-shaped: one more subscriber |
| 157 | on the log, spawning agent runs against frontier nodes. |
| 158 | |
| 159 | This splits the old "priority layer" question in two: **work-scheduling** — what the system produces |
| 160 | next — is what this bet answers; **attention-routing** — what a human must see, and how urgently — |
| 161 | stays open ([openquestions.md](./openquestions.md)). Scheduler mechanics and node formats are |
| 162 | deliberately absent here; that detail returns when its rung is the top priority. The fuller sketch: |
| 163 | [.the-valley/ideas/ida-eac723e-outcome-dag.md](../.the-valley/ideas/ida-eac723e-outcome-dag.md). |
| 164 | |
| 165 | ## Federation: the group is the unit |
| 166 | |
| 167 | _Serves: small trusted teams (rung S5 and the S7 limit of the [ladder](./user-scenarios.md))._ |
| 168 | |
| 169 | A **group** — a team, a company, a personal namespace — is the unit of federation. Each group runs |
| 170 | exactly one instance of the substrate: its hosting and its coordination (the bare repos, the bus, |
| 171 | the integrator). An instance is instantiable on a single machine — the v1 case — and distributable |
| 172 | later without changing shape. This frame splits the cross-repo open questions in two: |
| 173 | **intra-group** (one bus, one integrator — the tractable near-term case) and **inter-group** |
| 174 | (genuine federation — harder, later). See [openquestions.md](./openquestions.md); anything deeper is |
| 175 | deferred until its rung is in reach. The fuller sketch: |
| 176 | [.the-valley/ideas/ida-8482624-federation-groups.md](../.the-valley/ideas/ida-8482624-federation-groups.md). |
| 177 | |
| 178 | ## Components |
| 179 | |
| 180 | One line each; these are the current picks, not commitments: |
| 181 | |
| 182 | - **Hosting** — bare git over SSH; each repo is just a directory; `cgit` or similar for browsing if |
| 183 | needed. |
| 184 | - **Bus** — NATS JetStream; single binary, persistent streams, runs on the same Tailscale box; |
| 185 | replicate later if needed. |
| 186 | - **Transparency log** — Tessera-backed tlog via |
| 187 | [tesseract](https://github.com/transparency-dev/tesseract); every attestation lands with an |
| 188 | inclusion proof, giving non-repudiation and external auditability without depending on any one |
| 189 | host. |
| 190 | - **Pure reactions** — Nix derivations; inputs are events, outputs are content-addressed artifacts, |
| 191 | replayable from the log. |
| 192 | - **Effectful reactions** — [armstrong](https://github.com/gunk-dev/armstrong) as a Go controller; |
| 193 | the controller-shaped successor to the current Actions-based armstrong. |
| 194 | - **Agent dispatch** — klaus, with its existing run-budget mechanism. |
| 195 | - **Schemas** — CUE, already used by armstrong; shared across event producers and consumers. |