This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
swift build # Build all targets
swift test # Run all tests
swift test --filter HiveCoreTests # Run a single test target
swift test --filter HiveTests # Umbrella module smoke tests
swift run HiveTinyGraphExample # Run the example executableSwift 6.2 toolchain required. Core runtime targets macOS and Linux.
All source and tests live under Sources/Hive/:
Sources/Hive/
├── Sources/
│ ├── HiveCore/ # Schema, graph, runtime, store, checkpoint protocols
│ └── Hive/ # Umbrella - re-exports HiveCore
├── Tests/
│ ├── HiveCoreTests/ # Runtime, schema, store, graph, errors, data structures
│ └── HiveTests/ # Integration tests
└── Examples/TinyGraph/ # Executable example (fan-out, join, interrupt)
External dependency: swift-crypto for cross-platform SHA-256.
Hive executes deterministic superstep graphs using the Bulk Synchronous Parallel (BSP) model:
- Schema —
HiveSchemaprotocol declares typed channels with reducers, scopes, and codecs - Graph — Built via
HiveGraphBuilder - Runtime —
HiveRuntimeactor executes supersteps: frontier nodes run concurrently, writes commit atomically, routers schedule next frontier - Store —
HiveGlobalStore(shared state) +HiveTaskLocalStore(per-task overlay for fan-out) +HiveStoreView(read-only merged view for nodes) - Events — Rich
AsyncThrowingStreamof typed events for observation
| Directory | Responsibility |
|---|---|
Schema/ |
Channel specs, channel keys, reducers, codecs, schema registry, type erasure |
Store/ |
Global store, task-local store, store view, initial cache, fingerprinting |
Graph/ |
Graph builder, graph description (deterministic JSON), Mermaid export, ordering, versioning |
Runtime/ |
Superstep execution, frontier computation, event streaming, interrupts, retry, task management |
Checkpointing/ |
Checkpoint format and store protocol |
DataStructures/ |
Bitset |
Errors/ |
Runtime errors, error descriptions, checkpoint query errors |
Schema defines channels → Graph compiled from builder → Runtime executes supersteps:
1. Frontier nodes execute concurrently (lexicographic order for determinism)
2. Writes collected, reduced, committed atomically
3. Routers run on fresh post-commit state
4. Next frontier scheduled
5. Repeat until `Route.end` or interrupt
Hive's core invariant: same input → same output, same event trace. This is achieved through:
- Lexicographic ordering of node execution and write application by
HiveNodeID - Atomic superstep commits — all frontier writes apply together
- Deterministic reducers — associative merge strategies (
.lastWriteWins(),.append(),.setUnion()) - Golden tests — graph descriptions produce immutable JSON for regression testing
When writing tests, assert exact event ordering, not just presence.
Tests use Swift Testing (@Test, #expect, #require). Key conventions:
- Inline schemas — Each test file defines a minimal
HiveSchemaenum with only needed channels - Build graph imperatively — Use
HiveGraphBuilder<Schema>for test clarity - Collect events — Drain the runtime's
AsyncThrowingStreaminto an array - Assert deterministic ordering — Verify exact event sequence (superstep, task, write order)
- Checkpoint round-trips — Save/load cycle verification for resumable workflows
The HiveCoreTests target has a compiler flag: HIVE_V11_TRIGGERS.
| Scope | Behavior |
|---|---|
| Global | Shared across all tasks, visible to all nodes |
| Task-local | Per-task overlay from SpawnEach, isolated from siblings |
| Persistence | Behavior |
|---|---|
.checkpointed |
Saved in checkpoint snapshots |
.untracked |
Not included in checkpoints |
.ephemeral |
Reset at each superstep boundary |
- Node emits
Interrupt(payload)→ runtime saves checkpoint (store + frontier + join barriers + superstep index) - Resume via
runtime.resume(threadID:, interruptID:, payload:, options:) - Typed
Schema.ResumePayloadavailable in next node viainput.run.resume
HIVE_SPEC.md is the normative source of truth for runtime behavior. Implementation follows the spec — not the other way around. Use RFC 2119 keywords (MUST/SHOULD/MAY) when referencing spec requirements.
Use current project skills only after confirming they describe the cleaned core runtime surface.
- Swift 6.2 strict concurrency: all public types are
Sendable - Node IDs are strings — use lexicographically sortable names for deterministic ordering
- The
Hiveumbrella product is batteries-included; useHiveCorealone for minimal dependency - Do not edit plan documents in
tasks/or.claude/plans/