gunk-dev/the-valley

architecture.md

sourcee0011a5346e3main's published tip history
13.3 KiB · Rendered
1# Architecture
2
3The bets, each traced to a requirement ([requirements.md](./requirements.md)) and taken no deeper
4than rationale. Detailed design lives in the rest of `design/`, and only for roadmap phases that are
5current or next — later phases get their detail re-fleshed when they start, informed by what
6validation 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
37GitHub Actions, GitLab CI, Jenkins — all push-based pipelines. An event happens, a workflow runs, it
38exits, the trail is a log file.
39
40A 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
50Per-repo events (refs, attestations, integration requests) are durable in git itself; the bus is a
51projection that can be rebuilt. Only ephemeral cross-system events (deploys, metrics, agent runs)
52have the bus as their source of truth — so the log is never load-bearing for the crown-jewel data.
53
54Prior art: Atomist (defunct, but had this model). Kubernetes controllers. Datomic / event sourcing
55generally. `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
61The contributor's own hermetic environment runs the canonical checks and produces a signed
62attestation of what ran, against what inputs, with what result. Subscribers act on the attestation
63immediately. Re-verifiers cross-check it asynchronously. Trust is _measured_ per attester from
64re-verification confirm rates, and divergence revokes it.
65
66This 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
73For most environments — personal projects, small teams, trusted contributor sets — false positives
74that are _detected and revocable_ are a much better trade than a slow, brittle gate. The primary win
75is 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
82The simplest option is a `pre-receive` hook that checks attestations on every push to a protected
83branch. It works — but it makes integration a different _shape_ from the rest of the system, a
84synchronous 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
86integration 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
97Merge-queue semantics fall out for free: requests targeting the same ref serialize in the
98integrator. 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
100refreshing it is the branch owner's problem, not the integrator's.
101
102### The one structural git invariant
103
104The bare repo enforces exactly one thing: **only the integrator's key may write protected refs**.
105Everything else — topic branches, attestation refs, integration requests — is wide open to anyone
106with push access. That's a one-line `pre-receive` hook; all complex policy lives in the integrator.
107
108## Bet: review is observability + feedback
109
110_Serves: observability & feedback; dissolves the "how do humans review agent code" question._
111
112"Review" is one slice of a larger problem: how the system gives feedback to anyone or anything that
113needs it. The PR-as-page model conflates:
114
115| Concern | What it does | Failure mode today |
116| ------------ | ------------------------------------------- | -------------------------------------------------------- |
117| Coordination | A place humans converge to discuss a change | Discussion thread is locked to the PR; orphaned at merge |
118| Gating | Correctness checks must pass before merge | Slow, brittle, false negatives |
119| Record | Persistent trace of why a change happened | Lives inside one vendor's database |
120| Notification | Someone needs to look at this | Firehose; no useful prioritization |
121
122Unbundled: **gating** is handled by attestations; the **record** is the event log itself;
123**coordination** happens in threads — named, persistent _views_ over events scoped to a change,
124derived rather than stored; **notification** becomes a priority/routing subsystem, which is the hard
125new bottleneck the design creates. The PR object disappears — what people call "a PR" becomes a
126query with a name. Pre-merge human review becomes the exception: humans engage when the priority
127layer flags something for them, and feedback accrues continuously before and after a change lands,
128on the same machinery.
129
130## Bet: project knowledge is a typed-node graph
131
132_Serves: project knowledge & discussion, agents as first-class authors._
133
134Everything in a project that isn't executable code or user-facing docs — outcomes, bugs, principles,
135decisions, ideas, threads — is a **typed node**: a markdown file whose YAML frontmatter carries the
136structured layer (type, id, status, typed edges) and whose body carries prose. The graph lives at
137the repo root, clones with the code, and is equally navigable by a human with `grep` and an agent
138parsing frontmatter. Nodes are signed by the same keys as commits; discussion threads are themselves
139nodes; and active principles can become load-bearing on integration policy. Not a wiki, not
140Obsidian, not Jira — a project substrate that exposes a knowledge-tool-shaped surface.
141
142## Bet: the knowledge graph read generatively — an outcome DAG
143
144_Serves: project knowledge & discussion (the work itself is knowledge), agents as first-class
145authors. Anchored at rungs S3/S4 of the [scenario ladder](./user-scenarios.md)._
146
147The typed-node graph already stores dependency structure: `blocked_by`/`blocks` edges form a
148dependency DAG. The bet is to make **outcome** — a thing someone wants to exist that does not yet —
149the central node type and read that DAG _generatively_: open outcomes are not a record of intent but
150a worklist the system is under pressure to complete. Root outcomes — the things a human actually
151asked for — carry a priority that propagates down to the sub-outcomes that must complete for them.
152The system dispatches the **unblocked frontier** — the open outcomes whose blockers are all closed —
153on the critical path toward the highest-priority root. Dispatch is klaus-shaped: one more subscriber
154on the log, spawning agent runs against frontier nodes.
155
156This splits the old "priority layer" question in two: **work-scheduling** — what the system produces
157next — is what this bet answers; **attention-routing** — what a human must see, and how urgently —
158stays open ([openquestions.md](./openquestions.md)). Scheduler mechanics and node formats are
159deliberately absent here; that detail returns when its rung is the top priority. The fuller sketch:
160[.the-valley/ideas/ida-eac723e-outcome-dag.md](../.the-valley/ideas/ida-eac723e-outcome-dag.md).
161
162## Federation: the group is the unit
163
164_Serves: small trusted teams (rung S5 and the S7 limit of the [ladder](./user-scenarios.md))._
165
166A **group** — a team, a company, a personal namespace — is the unit of federation. Each group runs
167exactly one instance of the substrate: its hosting and its coordination (the bare repos, the bus,
168the integrator). An instance is instantiable on a single machine — the v1 case — and distributable
169later without changing shape. This frame splits the cross-repo open questions in two:
170**intra-group** (one bus, one integrator — the tractable near-term case) and **inter-group**
171(genuine federation — harder, later). See [openquestions.md](./openquestions.md); anything deeper is
172deferred until its rung is in reach. The fuller sketch:
173[.the-valley/ideas/ida-8482624-federation-groups.md](../.the-valley/ideas/ida-8482624-federation-groups.md).
174
175## Components
176
177One line each; these are the current picks, not commitments:
178
179- **Hosting** — bare git over SSH; each repo is just a directory; `cgit` or similar for browsing if
180 needed.
181- **Bus** — NATS JetStream; single binary, persistent streams, runs on the same Tailscale box;
182 replicate later if needed.
183- **Transparency log** — Tessera-backed tlog via
184 [tesseract](https://github.com/transparency-dev/tesseract); every attestation lands with an
185 inclusion proof, giving non-repudiation and external auditability without depending on any one
186 host.
187- **Pure reactions** — Nix derivations; inputs are events, outputs are content-addressed artifacts,
188 replayable from the log.
189- **Effectful reactions** — [armstrong](https://github.com/gunk-dev/armstrong) as a Go controller;
190 the controller-shaped successor to the current Actions-based armstrong.
191- **Agent dispatch** — klaus, with its existing run-budget mechanism.
192- **Schemas** — CUE, already used by armstrong; shared across event producers and consumers.