Documentation

Everything you need to know
about flow.

A complete reference for flow — the operator CLI, the agent CLI, graph model, lifecycle, configuration, and the AI session system.

Overview

flow is an AI-native planning and implementation toolchain built by Emergent Company. It bridges three systems — GitHub, a Memory knowledge graph, and OpenCode AI sessions — into a single structured software development lifecycle.

Instead of tickets in Jira, docs in Notion, and code in GitHub living as disconnected artefacts, flow stores every planning decision as a queryable, verifiable node in a knowledge graph. AI agents read the graph to understand what to build, write code against it, and the graph is updated when code ships.

flow is not a task manager. It is a structured contract between your planning intent and your codebase. Every component in the graph must be implemented — or it blocks promotion.

The core loop is: Plan a Scenario in the graph → Implement it with an AI agent in an isolated worktree → Verify every component against the real codebase → Promote to main.

Installation

Install the flow binary with the one-line installer:

Terminal
$ curl -fsSL https://getflow.dev/install | bash

Or build from source (requires Go 1.22+):

Terminal
$ git clone https://github.com/emergent-company/flow
$ cd flow && task install
# Installs to /usr/local/bin/flow

Verify installation:

Terminal
$ flow --version

flow v0.1.0

Configuration

Each project repo needs a .flow.yml at the root:

.flow.yml

plan_branch_name: plan/next-gen

plan_branch_id: 87b21b07-90cf-4738-b0c3-e2a0698bbcf0

main_branch_id: <uuid>

github_owner: emergent-company

github_repo: legalplant-api

Environment variables (loaded from .env.local or shell):

VariablePurpose
MEMORY_SERVER_URLBase URL of the Memory API server
MEMORY_PROJECT_IDProject UUID for journal and search
MEMORY_API_KEYAuthentication token
OPENCODE_URLOpenCode ACP server URL (default: http://localhost:4096)
FLOW_DEBUG=1Enable debug logging (also: --debug flag)

Graph Object Model

All planning data lives in the Memory knowledge graph as typed nodes connected by typed relationships. This is the full object model:

Object model

Scenario

├── has ──────────► ScenarioStep (ordered by step_order)

├── acted_by ──────► Actor

└── belongs_to ────► Domain

ScenarioStep

├── occurs_in ─────► Context (which screen)

└── has_action ────► Action (what the user does)

Context (central fan-out node)

├── requires ──────► UIComponent

└── requires ──────► APIEndpoint

APIEndpoint

└── calls ─────────► ServiceMethod

ServiceMethod

└── uses ──────────► SQLQuery

SQLQuery

└── uses ──────────► SourceFile (migration)

All relationship types: has, belongs_to, acted_by, occurs_in, has_action, contains, navigates_to, requires, calls, uses, tested_by.

Three-Branch Model

flow keeps three distinct layers in sync:

BranchPurpose
Memory: mainVerified reality — matches shipped code
Memory: plan/next-genPlanning workspace — all components status: not_existing
Memory: execute/<key>Per-scenario execution tracking — status advances here
Git: masterProduction code
Git: scenario/<key>Implementation branch per scenario
Worktree: /tmp/lp-work/<key>Isolated checkout for parallel AI sessions

Memory branches are not git branches. They are logical branches inside the knowledge graph, used to namespace planning vs. reality without coupling to git state.

Scenario Lifecycle

Every scenario moves through a fixed set of statuses. Each transition is guarded:

StatusWhat it means
NEEDS KEYScenario exists but has no key set
NEEDS STEPSNo ScenarioStep objects linked via has
NEEDS CONTEXTSteps exist but no occurs_in → Context wired
NEEDS COMPONENTSContexts exist but no requires → APIEndpoint / UIComponent
READYFully planned — audit can run, branch can be opened
IN EXECUTIONexecute/<key> Memory branch + scenario/<key> git branch exist
PROMOTEDExecute branch merged to Memory main, git PR opened

--init-branch is gated: the Scenario must have user_value set AND a non-stale, non-failing constitution audit. Fix audit failures before branching.

Lifecycle commands
# 1. Plan
$ flow-operator session start --stage plan --key s-cases-archive
# 2. Audit
$ flow audit --key s-cases-archive
# 3. Open branches
$ flow verify --key s-cases-archive --init-branch
# 4. Implement
$ flow-operator session start --stage implement --key s-cases-archive
# 5. Verify
$ flow verify --key s-cases-archive
# 6. Promote
$ flow verify --key s-cases-archive --promote --execute

Component Types & Verification

flow verify checks each component against the real codebase. Here is how each type is verified:

TypeVerified when
SourceFileFile path exists on disk
SQLQuery.sql file exists AND func (q *Queries) Name( found in sqlcdb/
ServiceMethodFile exists and signature/name string found in file
APIEndpointFile exists and handler func name found in file
UIComponent.templ or _templ.go file exists
ScenarioStepUI keyword → templ file; API keyword → route; else git commit fallback

Key Naming Conventions

All graph object keys follow strict conventions enforced by flow audit:

TypeKey pattern
Scenarios-<domain>-<slug> e.g. s-cases-archive-restore
ScenarioStep<scenario-key>-step-<slug> e.g. s-cases-archive-restore-step-attorney-clicks
Contextctx-<domain>-<slug> e.g. ctx-cases-list
Actionact-<domain>-<verb>-<slug> e.g. act-cases-click-archive
APIEndpointep-<domain>-<verb> e.g. ep-cases-archive
ServiceMethodsm-<domain>-<verb> e.g. sm-cases-archive
SQLQuerysq-<verb>-<entity> e.g. sq-soft-delete-case
SourceFilesf-migration-<slug> e.g. sf-migration-archive-cases
UIComponentui-<domain>-<slug> e.g. ui-cases-list-page

flow-operator Reference

flow-operator is the human-facing orchestration tool. Operators use it to schedule AI sessions, review results, sync session data into the graph, and track findings across projects — without needing to know the internals of the agent toolchain.

flow-operator session start

Schedule an AI session for a scenario at a given stage. The operator triggers the session; the agent receives the appropriate skill and executes autonomously.

$ flow-operator session start --stage plan --key s-cases-archive
$ flow-operator session start --stage implement --key s-cases-archive
$ flow-operator session start --stage audit --key s-cases-archive

session ses_abc123 started

stage: implement → dispatched skill

flow-operator sessions / session status / session logs

Review the history of AI sessions synced to the operator graph, check live status, or read message logs.

$ flow-operator sessions # all synced sessions
$ flow-operator sessions --key s-cases-archive # filter by scenario key
$ flow-operator session status ses_abc123 # live status
$ flow-operator session logs ses_abc123 --text # full message log
$ flow-operator session abort ses_abc123 # abort a running session

flow-operator sync

Pull recent sessions from the OpenCode API and upsert them as AgentSession objects in the operator Memory graph. Also links open PRs to their scenarios.

$ flow-operator sync
$ flow-operator sync --include-subsessions
$ flow-operator sync --json

upserted AgentSession asa-cases-archive-implement

linked PR #142 → s-cases-archive

flow-operator analyze

Record an AgentSessionAnalysis for a session — either manually with notes and pipe-separated findings, or automatically via --auto which spins up a smooth-operator sub-session to read the transcript.

$ flow-operator analyze ses_abc123 --auto
$ flow-operator analyze ses_abc123 --type implementation \
$ --notes "Implemented archive flow" \
$ --findings "missing index|no error handling"
$ flow-operator feedback <asa-key> --items "item1|item2"
$ flow-operator analyses # list analyses

flow-operator projects

Register a project repo with the operator graph so its sessions are included in cross-project syncs and analyses.

$ flow-operator projects register # run from inside the project repo
$ flow-operator projects list # list all registered projects

flow CLI Reference

The flow CLI is the per-project, agent-facing tool. It runs from inside a project repo and is primarily invoked by AI agents during planning and implementation sessions. Operators interact with it indirectly — via flow-operator session commands that dispatch agents.

flow next

Find the next scenario to plan or implement.

$ flow next --plan # scenarios needing planning work
$ flow next --plan --domain cases # filter by domain
$ flow next --plan --top 5 # limit results
$ flow next --implement # scenarios in execution
$ flow next --json # JSON output

Output signals: NEEDS STEPS, NEEDS CONTEXT, NEEDS COMPONENTS, NEEDS KEY, READY.

flow verify

View, verify, and promote scenario implementations.

$ flow verify --list # all scenarios
$ flow verify --list --tier planning # filter by tier
$ flow verify --key <key> # full component tree + checks
$ flow verify --key <key> --init-branch # create branches
$ flow verify --key <key> --promote # dry-run
$ flow verify --key <key> --promote --execute # apply promotion
$ flow verify --key <key> --pr <number> # PR readiness check
$ flow verify --key <key> --write-back # write status to graph

flow audit

Run a constitution audit on a scenario.

$ flow audit --key <key>
$ flow audit --key <key> --force # re-run even if fresh
$ flow audit --key <key> --json

pass key naming: s-<domain>-<slug>

pass user_value property set

warn step count < 2

flow graph

CRUD operations on the knowledge graph.

$ flow graph list --type <Type> [--branch <id>] [--json]
$ flow graph get <key-or-uuid>
$ flow graph create --type <Type> --key <key> --properties '{}'
$ flow graph update --id <uuid> --properties '{}'
$ flow graph relate --type <rel> --from <id> --to <id>
$ flow graph rels <uuid> # outgoing rels
$ flow graph rels --reverse <uuid> # incoming rels
$ flow graph unrelate --from <id> --to <id> --type <rel>
$ flow graph tree <key-or-uuid> # dependency tree

flow session

Manage OpenCode AI sessions via the ACP API.

$ flow session start --stage plan --key <key>
$ flow session start --stage implement --key <key>
$ flow session start --stage audit --key <key>
$ flow session list [--key <filter>] [--active]
$ flow session status [<session-id>]
$ flow session send --session <id> "message text"
$ flow session abort <session-id>
$ flow session logs <session-id> [--text] [--limit N]

flow query

Semantic/hybrid search across the knowledge graph.

$ flow query "what API endpoints exist for cases?"
$ flow query "how is archive implemented?" --limit 10
$ flow query "..." --branch <uuid>
$ flow query "..." --json

flow journal

Append and list durable session notes in the graph.

$ flow journal note "## Session summary\n\n..."
$ echo "content" | flow journal note
$ flow journal list [--since 24h] [--limit 50]

flow worktree

Manage isolated git worktrees for scenario implementation.

$ flow worktree add <key> # create /tmp/lp-work/<key>
$ flow worktree path <key> # print worktree path
$ flow worktree remove <key> # delete worktree

flow spec

Show the Swagger/OpenAPI contract for a planned APIEndpoint.

$ flow spec --key ep-cases-create
$ flow spec --method POST --path /api/v1/cases

AI Sessions

flow launches and manages OpenCode AI sessions via the ACP API. Operators schedule sessions using flow-operator session start. Each session is scoped to a specific scenario and stage, and receives a purpose-built skill pack that instructs the agent on what to do.

Plan stage

Dispatches the flow-plan-scenario skill. The agent researches the codebase, consults the graph, and creates the full component blueprint: Scenario → Steps → Contexts → Actions → all required components with relationships wired.

$ flow-operator session start --stage plan --key s-cases-archive

Implement stage

Creates a git worktree at /tmp/lp-work/<key> and dispatches the flow-implement-scenario skill. The agent reads the component graph and writes code bottom-up: migration → SQL → service → API → UI. It calls flow verify continuously to check progress.

$ flow-operator session start --stage implement --key s-cases-archive

Audit stage

Runs flow audit --key <key> inside an OpenCode session, allowing the agent to fix any failing rules before branching.

$ flow-operator session start --stage audit --key s-cases-archive

Constitution & Patterns

The constitution is a set of Rule objects in the graph wired to a ConstitutionAudit object. Rules encode your team's conventions — naming patterns, required properties, and planning-phase constraints.

A scenario cannot have --init-branch run until flow audit passes or warns. Failing rules block branching entirely.

Patterns

Pattern objects document recurring implementation approaches — UI patterns, DB patterns, API patterns, service patterns. They are referenced by agents during planning to ensure consistency.

$ flow patterns # list all patterns
$ flow rules # list all constitution rules
$ flow check APIEndpoint # lint a type against rules