Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Under the Hood

crates/agentstacks follows a ports-and-adapters (hexagonal) layout. All logic sits inside, behind ports, and is tested with fakes. Only the adapters touch the disk, git, the airsl binary or Lua.

                 ┌──────────────── inside (no OS, no airsl) ───────────────┐
                 │                                                         │
 fs/      ──impl──►  port/   ◄──uses──  app/   ──uses──►  types/           │
 process/ ──impl──►  traits             use cases          domain:         │
 host/    ──impl──►  + fakes            plan, apply,       data + pure     │
                 │                      doctor, update     rules           │
                 └─────────────────────────────────────────────────────────┘
 outside: adapters                       ▲
                                         └── agentstacks-cli wires the real adapters in
 process/ ──uses──► fs/cache   (the one edge from one adapter to another)
 types/   ──uses──► port::{FileTree, EntryKind}   (the read-only tree the format loaders take)

Modules

ModuleHoldsState
types/the domain: the pack, extension, project and lock formats, and pure rules (operations, source resolution, plan steps, JSON text edit, the hook protocol, the ext test check rules)built
port/traits only, each with a fake for tests: FileTree, Workspace, Scratch, Git, Binary, Adapterbuilt
app/use cases, generic over ports: plan, apply, doctor, update, init, and ext (ext add, ext test)built
fs/adapter: FileTree and Workspace on the real disk, and Scratch (a directory outside the project, a temporary project that is removed on drop)built
process/adapter: Git on the git CLI, Binary on airsl --version and airsl test <dir>built
host/adapter: Adapter on the airsl sandbox, where extension Lua runsbuilt

The command-line crate agentstacks-cli is the composition root: it builds the real adapters and passes them to app/.

Dependency rule

types             → port::{FileTree, EntryKind} only
port              → types
app               → port, types
fs, process, host → port, types;  process → fs::cache only

Inside (types, port, app) never imports an adapter and never calls std::fs, std::process or std::net. crates/agentstacks/tests/isolation.rs enforces this.

  • types/ may name only FileTree and EntryKind from crate::port, the read-only tree port the pack, extension and project loaders take. tests/isolation.rs allows exactly those two names inside src/types, plus crate::port::FakeFileTree in #[cfg(test)] code.
  • process/ may use fs::cache, the cache-directory helper, and nothing else from fs/. It is the only edge from one adapter to another.

Dependency policy

deny.toml exempts airsl's subtree from the duplicate-version ban with skip-tree, because airsl 0.1.5 pins sha2 0.10 and toml 0.8 while agentstacks uses sha2 0.11 and toml 1. The exemption can go once airsl moves to those versions. Zlib is in the allowed licences, for foldhash, which serde_json's preserve_order feature pulls in.

Where logic lives

LayerHoldsExample
types/rules: pure decisions, data in, answer out"the file's hash differs from the lock, so the step is refused"
app/flows: the order of steps; it calls a port, hands the result to a rule, then calls the next portread the lock, resolve sources, run the extension, decide each file's step
port/abstraction: traits and fakes, no logicWorkspace::resolve(path)
adapterstranslation: no decisionsbytes on disk, git output, Lua values ↔ Operation

One rule, traced through the layers:

"a file changed since the last apply is refused"

types   decide_locked(lock_hash, state, new) → no action, so the step is StepError::Changed:
          "<path>: changed since the last apply"
          pure: three values in, one answer out
app     plan asks port::Workspace::resolve(path) for the disk state
          flow: no rule of its own
fs      StdWorkspace::resolve returns the real disk state
          translation

Testing

WhatHowNeeds disk, git or airsl
every rule (types/)unit tests on plain valuesno
every flow (app/): plan, apply order, conflicts, stale lock, doctorunit tests with FakeWorkspace, FakeGit, FakeBinary, FakeAdapter, FakeScratchno
each adapterone contract test: does the real adapter behave like its fake?yes, only these

Logic is never tested only through an end-to-end run. If a rule can only be reached end to end, it is in the wrong layer.

Rust rules applied

RuleApplied as
one job per module, no God objecteach module above has one job; app/ holds flows, never rules
one type per conceptOperation is defined once, in types/; host/ returns it, never a copy
static dispatchports are generic parameters (W: Workspace); the one dyn is airsl's ModuleSet::insert(Box<dyn HostModule>), which airsl's API requires
mod.rs is export-onlyevery mod.rs holds only its docs and mod / pub use lines
namingone-word folder and file names, no _