- Get Started

Architecture-First Development

OpenFlows treats the plan as the primary deliverable. Before any implementation code is written, a FORGE agent produces a PLAN.md document and a SENTINEL agent reviews it into a CONTRACT.md. Only when the contract is AGREED does FORGE start writing code. This is the architecture-first philosophy in practice: engineering goes into the system, and software comes out.

The reason is pragmatic. Large language models are excellent at producing correct syntax and idiomatic boilerplate, but they are unreliable at deciding what to build and how the pieces should fit together. A vague prompt yields a plausible-looking program that is subtly wrong at the architectural level. A detailed plan - reviewed by a second model with a different provider - makes the hidden assumptions visible before they become bugs in the codebase.

Why OpenFlows Plans Before Executing

In a traditional workflow, the human engineer writes a plan inside their head, translates it into code, and submits a PR for review. The reviewer then tries to reverse-engineer the plan from the diff. OpenFlows inverts that order. The plan is externalised, reviewed, and agreed upon before the first commit. This has several consequences:

The plan is the contract, not the code

CONTRACT.md is the formal agreement that the plan is acceptable. It does not guarantee that the implementation is correct - SENTINEL checks that in each segment evaluation. It guarantees that the direction is correct, the scope is bounded, and the risks are acknowledged.

PLAN.md and CONTRACT.md

PLAN.md is written by FORGE inside the ticket workspace. It is designed to be readable by both humans and the reviewing agent. A good plan includes the goal, constraints, a segment breakdown, the files and dependencies that will be touched, and any risks or open questions that need human escalation. The plan is the input to the rest of the pipeline.

markdown
# PLAN.md

## Goal
Add idempotency retries to the PocketFlow executor so that a node that transiently fails can be retried
without corrupting the SharedStore.

## Constraints
- The retry count must be persisted in the store, not in memory, so that a restarted node resumes from
the correct count.
- No node may be retried more than max_retries (default 3).
- A retry must be visible in the event ring for TUI observers.

## Segments
1. Add a retry_count field to NodeState in the SharedStore contract.
2. Update Flow::run() to increment the counter and short-circuit when max_retries is exceeded.
3. Emit a node_retry event on each retry and a node_failed event on exhaustion.
4. Add unit tests for the three retry paths: success-on-retry, exhaustion, and idempotency.

## Files touched
- src/flow.rs
- src/store/state.rs
- src/events.rs
- tests/flow_retries.rs

## Risks / open questions
- Should we back off between retries? If so, what policy? Default to immediate retry for now.

SENTINEL reads the plan and writes CONTRACT.md. The contract is not a commentary; it is a decision. The status is one of AGREED, CHANGES_REQUESTED, or REJECTED. If changes are requested, the feedback must be specific enough that FORGE can rewrite the plan without asking for clarification. If the plan is rejected, SENTINEL escalates to NEXUS, which marks the ticket AwaitingHuman.

markdown
# CONTRACT.md

## Status: CHANGES_REQUESTED

## Reasoning
The plan is directionally correct but under-specifies the retry policy. "Default to immediate retry"
is a hidden operational risk for external API calls.

## Required changes
1. Choose a backoff policy. Suggested: exponential backoff with jitter, capped at 30 seconds, or a
   configurable policy string in registry.json.
2. Add a test case that proves the store counter is not incremented twice for the same failure.
3. Document the event schema for node_retry and node_failed in the ADR that LORE will write.

## Approval criteria
SENTINEL will re-evaluate after FORGE updates PLAN.md with the backoff policy and the idempotency test.

The Artifacts of the Pipeline

ArtifactAuthorConsumerPurpose
PLAN.mdFORGESENTINEL, NEXUS, humansA human-readable design: goals, constraints, segment breakdown, files touched, dependencies, and risk notes.
CONTRACT.mdSENTINELFORGEReview outcome: AGREED, CHANGES_REQUESTED, or REJECTED, with specific, actionable feedback.
segment-N-eval.mdSENTINELFORGEPer-segment evaluation after each commit. Catches drift before the next segment begins.
final-review.mdSENTINELFORGE / VESSELPre-PR approval. Must be APPROVED before VESSEL may merge.
STATUS.jsonFORGE / VESSELNEXUSStructured machine state: ticket id, status, blocker, PR link, and next action.

Why Specs Matter When Models Make Boilerplate Cheap

The cost of writing boilerplate has collapsed. A model can generate a REST handler, a database migration, a React component, or a Terraform module in seconds. That speed is valuable, but it is also dangerous: it makes it easy to build the wrong thing quickly. The bottleneck in modern software engineering is no longer typing speed; it is decision quality.

A specification is a compressed decision. It captures the intent, the constraints, the trade-offs, and the success criteria. When FORGE writes PLAN.md, it is doing the expensive work: translating a vague issue into a concrete design. The code that follows is, in a sense, a rendering of the spec. SENTINEL's job is to make sure the rendering is faithful, not to invent the design on the fly.

This division of labour mirrors the best human engineering teams. Architects produce a design; implementers build to it; reviewers verify conformance. OpenFlows simply encodes that division into a repeatable, observable machine process. The human team retains control over the design; the agents handle the execution and the mechanical review.

A good plan saves tokens, not just time

A rejected plan costs a few thousand tokens and a few seconds of review. A bad implementation that reaches final review costs tens of thousands of tokens, multiple workspace cycles, and possibly a flawed commit in the repository. Planning first is the cheapest correctness strategy available.

The Architecture-First Flow

PhaseWhat happens
1. DiscoveryNEXUS polls GitHub, normalises the issue into a Ticket, and writes it to SharedStore.
2. AssignmentNEXUS matches the ticket to an idle FORGE worker based on load, role, and any required skills.
3. PlanningFORGE writes PLAN.md; SENTINEL reviews it and emits CONTRACT.md.
4. ImplementationFORGE implements one segment per commit; SENTINEL evaluates each segment.
5. Final ReviewSENTINEL writes final-review.md. APPROVED unblocks the PR; CHANGES_REQUESTED loops back.
6. MergeFORGE opens the PR; VESSEL polls CI and merges.
7. DocumentationLORE writes ADRs and updates CHANGELOG.md.
8. TeardownThe Coder workspace is destroyed.

Design Principles

PrincipleWhy it matters
Plan is the contractBoth the human team and the LLM have a single source of truth: the agreed PLAN.md.
Review before executionSENTINEL sees the plan before any code is written. This is cheaper than reviewing code after the fact.
Segmented implementationEach segment is small enough to review in isolation and large enough to be meaningful.
Structured stateSTATUS.json and the SharedStore record what phase a ticket is in, so NEXUS can resume after a crash.
Human escalation is a featureCommandGate and AwaitingHuman are explicit, not failures. Ambiguity is escalated; routine work is automated.

When the Plan is Wrong

No plan survives contact with implementation. OpenFlows handles this by reviewing every segment. If FORGE discovers during segment 3 that segment 2's design is unworkable, it does not silently change direction. It updates PLAN.md, asks SENTINEL to re-approve the affected segments, and only then continues. The contract is a living document, but it is always explicit.

When the issue itself is ambiguous - the user story is incomplete, the acceptance criteria conflict, or the change touches a security boundary - OpenFlows does not guess. It writes a STATUS.json with status: AwaitingHuman and stops. The escalation is visible, auditable, and recoverable. Once a human clarifies the requirement, NEXUS resumes the pipeline at the planning phase.