Rapid OS v3 Architecture
Roadmap Overview
Rapid OS v3 evolves Rapid OS from a static context template generator into a deterministic, provenance-backed engineering intelligence platform for AI coding harnesses.
Phase 0 Hardening Foundation (COMPLETE)
Phase 1 Project Intelligence (COMPLETE)
Phase 2 Context Compiler (COMPLETE)
Phase 3 Spec Registry v3 (COMPLETE)
Phase 4 Execution Policy Engine & Run Contract (COMPLETE)
Phase 5 Harness Capability Registry (COMPLETE)
Phase 6 Evidence Engine & Behavioral Evals (COMPLETE)
All Rapid OS v3 phases (Phases 0 through 6) are complete and hardened for the
v3.0.0stable release.Release Versioning vs. Artifact Schema Versioning: The product release version (
rapid_os.__version__ = "3.1.1") follows Semantic Versioning for the CLI and Python package, whereas persisted domain artifacts (.rapid-os/project.json,spec.json,revision.json,policy.json,run.json,contract.json,states/*.json,harnesses/*.json,capabilities.lock,records/E00N.json,reports/000N.json) independently maintainschema_version = 1(andBehavioralRuleset.version = 1) for deterministic serialization compatibility.
Phase 1: Project Intelligence Model
Architectural Principle
Rapid OS v3 strictly separates four epistemic layers that must never be conflated:
- Raw Observation (
Evidence): Verifiable local repository signals such aspackage.jsondependency entries,.envvariable key names, config files, or workflow files. - Detected Fact (
ProjectFact): A normalized, provenance-backed statement about the repository (category="framework",value="fastapi"). - Inference (
InitSuggestion/ScanSuggestions): Heuristic recommendations derived from facts (for example, suggestingstack = python-aiortopology = fullstack-separated). - User Decision (
.rapid-os/config.json&.rapid-os/standards/): Explicit choices confirmed or configured by the developer.
Pipeline
Repository
↓
Detectors (rapid_os.domain.scanner)
↓
ProjectFact (raw facts with Evidence + SourceType + detector ID)
↓
normalize_facts() (consolidation, deduplication, confidence promotion, deterministic sort)
↓
ProjectModel (canonical, immutable, serializable v3 intelligence model)
↓
Validation (RAPID600–RAPID604) & Optional Snapshot (.rapid-os/project.json)
Canonical Domain Entities (rapid_os.domain.project)
Confidence
Ordered enum (LOW = "low", MEDIUM = "medium", HIGH = "high") representing certainty for a fact or suggestion. Always serialized as lowercase strings.
SourceType
Enum classifying how an observation was obtained:
filemanifestconfigdirectoryenvironment-keydependencyworkflow
Evidence
Immutable record (path, reason, source_type, optional detector) proving why a fact was emitted:
pathis normalized to a relative POSIX path inside the project root (package.json,apps/api/pyproject.toml). Absolute host paths and..path traversal segments are rejected.reasonis human-readable and never contains secret values from.envfiles.
ProjectFact
Immutable fact (category, value, confidence, evidence, detector):
detectoris a stable domain identifier (language.python,framework.fastapi,database.postgres,testing.pytest,deploy.vercel) decoupled from internal private function names.- Performs no I/O, mutates no files, and contains no CLI presentation logic.
normalize_facts
Deterministic consolidation pass over emitted facts:
- Facts sharing
(category, value)are merged into a singleProjectFact. ProjectFact.detectoris resolved to the canonical detector identifiercanonical_detector_id(category, value)independent of input order.Evidence.detectorpreserves the concrete detector/producer provenance for each observation.Evidenceentries are deduplicated and sorted by(path, reason, source_type, detector or "").- The highest
Confidenceacross merged detections is preserved. - Distinct values within the same category (such as
nextjsandfastapiinframeworkfor a monorepo) are preserved as separate facts. - Output facts are sorted deterministically by
(category, value).
ProjectModel
Canonical container (schema_version = 1, root = ".", facts: tuple[ProjectFact, ...]) with:
- Query helpers:
values(category),has(category, value=None),facts_for(category),fact(category, value),by_category(), andcategories(). - Round-trip deterministic serialization:
to_dict(),to_json(),from_dict(), andfrom_json().
Compatibility Facade (ProjectScan)
ProjectScan in rapid_os.domain.scanner wraps ProjectModel without duplicating state:
scan_project(root)callsbuild_project_model(root)and returnsProjectScan(model=model).scan.detectionsandscan.factsboth returnmodel.facts.scan.to_model()returns the underlyingProjectModel.suggest_init_choices()accepts eitherProjectModelorProjectScan, keepingrapid initcompatible while operating directly onProjectFactdata.
Optional Snapshot Persistence (rapid_os.adapters.project_snapshot)
- By default, scanning (
scan_project(),build_project_model(),rapid scan,rapid scan --json, andrapid init) is read-only and does not write.rapid-os/project.json. - When explicitly requested via
rapid scan --write(orwrite_project_snapshot()), Rapid OS writes.rapid-os/project.jsonusingsafe_write_text(..., backup=True)and validates containment viaensure_path_within_root().
Snapshot Validation (RAPID6xx in rapid_os.domain.validation)
When .rapid-os/project.json is present, rapid validate and rapid doctor verify its integrity:
RAPID600(INFO): Valid project intelligence snapshot loaded.RAPID601(ERROR): Invalid JSON in.rapid-os/project.json.RAPID602(ERROR): Unreadable.rapid-os/project.json.RAPID603(ERROR): Unsupported or invalidschema_version.RAPID604(ERROR): Corrupt structure or invalidProjectFact/Evidenceentry.
CLI Surface (rapid scan)
rapid scan: Runs local detectors and prints a human-readable summary of detected facts grouped by category (value,confidence, anddetector) without writing any files or runningsuggest_init_choices().rapid scan --verbose: Includes per-factEvidenceentries (path,reason, andsource_type) in the human-readable output.rapid scan --json: Emits only the serializedProjectModelJSON tostdout(no banners or decorative text) for machine consumption.rapid scan --write: Persists the canonicalProjectModelsnapshot to.rapid-os/project.jsonwith atomic write and.bakbackup protection.rapid scan --json --write: Writes.rapid-os/project.jsonand emits the exact same JSON document tostdout.
Phase 2: Context Compiler
Architectural Principle
Whereas Project Intelligence answers "What exists in the project?", the Context Compiler answers "What does the agent actually need to know to execute this specific task?".
Instead of dumping all standards and raw scan facts indiscriminately, the Context Compiler resolves, ranks, budgets, and compiles task-relevant context with full provenance and explainability.
Pipeline
ProjectModel + Project Standards + Spec Registry / Task Intent (ContextRequest) + ContextPolicy
↓
ContextSourceLoader (rapid_os.adapters.context_sources)
↓
ContextResolver (selection, precedence, budget enforcement, conflict detection)
↓
ContextCompiler (deterministic Markdown rendering + ContextManifest generation)
↓
CompiledContext (schema_version = 1, content + manifest)
Canonical Domain Entities (rapid_os.domain.context)
ContextSourceKind & Precedence Order
Explicit precedence hierarchy where user-confirmed constraints and rules always take priority over lower-level defaults and detected project facts:
task_constraintssecuritybusinessarchitecturetopologytech_stackcoding_rulesspectasksacceptancedesignreferencecustomproject_intelligence
ContextPriority
Ordered integer enum (LOW = 10, MEDIUM = 50, HIGH = 80, CRITICAL = 100).
ContextMode
Task execution modes (feature, bugfix, refactor, hardening, research, general), each defining mode-preferred source kinds and task-relevant ProjectModel fact filtering.
ContextSource & ContextFragment
Immutable, validated units of context with stable public identifiers (task.constraints, standard.security, standard.business, standard.tech-stack, spec.<id>.requirements, spec.scope, project.intelligence), portable POSIX paths, tags, selection reasons, and end-to-end portable provenance preserved through ContextSource → ContextFragment → ManifestEntry → ContextManifest.
- File-backed standards/specs record their relative POSIX path (e.g.,
.rapid-os/standards/security.md). - Explicit task constraints (
ContextRequest.constraints) are promoted to a first-class canonical source (id="task.constraints",kind=ContextSourceKind.TASK_CONSTRAINTS,priority=ContextPriority.CRITICAL,required=True,provenance="ContextRequest.constraints"). - Project Intelligence distinguishes snapshot provenance (
snapshot:.rapid-os/project.json) from live scan provenance (scan:live), and fails explicitly withRAPID704if.rapid-os/project.jsonexists on disk but is corrupt or invalid (never silently falling back to a live scan).
ContextRequest & ContextPolicy
ContextRequest captures task intent (mode, harness, objective, affected_paths, tags, max_chars, constraints, spec_id, spec_revision). ContextPolicy (DEFAULT_CONTEXT_POLICY, max_chars = 24000) governs required kinds, mode preferences, priorities, and precedence order.
Budget Enforcement, Required Sources & Non-Truncation Guarantee
- Budget (
max_chars) is enforced against the final compiled Markdown output (len(compiled.content) <= max_chars). - Required fragments (including
task.constraintsand mode-required kinds such assecurityinhardeningmode) are included first. If required fragments alone exceedmax_chars,ContextBudgetExceededErroris raised (RAPID702) without silently truncating rules. - If a required source or mode-required kind is missing after resolution,
ContextCompiler.compile()raisesContextRequiredSourceMissingError(RAPID701) andrapid contextexits non-zero without emitting invalid compiled context tostdout(ContextResolver.resolve()retainsmissing_required_kindsonContextSelectionfor low-level inspection). - Optional fragments are evaluated in deterministic rank order (
-priority,-relevance_score,precedence_rank,source_id,fragment_id). Any optional fragment that would exceed the remaining budget is skipped in its entirety withreason="skipped: source exceeds remaining budget".
Conflict Detection (ContextConflict)
Detects structural contradictions across effectively selected fragments and ProjectModel facts (such as conflicting database declarations across task.constraints, standard.business, standard.tech-stack, and project.intelligence) and records the winning source according to ContextPolicy precedence. Sources skipped due to budget or relevance never participate in or win conflicts.
ContextManifest & CompiledContext
CompiledContext (schema_version = 1) bundles the deterministic compiled Markdown (content) with a machine-readable ContextManifest (selected, skipped, conflicts, compiled_chars, max_chars, content_digest), supporting full to_dict(), to_json(), from_dict(), and from_json() round-trip serialization (preserving provenance on every ManifestEntry).
Context Validation Diagnostics (RAPID7xx in rapid_os.domain.validation)
RAPID700(INFO): Context compiled successfully.RAPID701(ERROR): Required context source missing (ContextRequiredSourceMissingError).RAPID702(ERROR): Context budget exceeded by required sources (ContextBudgetExceededError).RAPID703(WARNING): Context conflict detected across selected sources.RAPID704(ERROR): Context source or.rapid-os/project.jsonsnapshot unreadable or invalid.RAPID705(ERROR): InvalidContextRequestor duplicate/invalid source identifiers.
CLI Surface (rapid context)
rapid context(orrapid context compile): Compiles and prints the task-relevant context in read-only mode (never writes files, never prompts, never makes network calls).rapid context --mode <mode>: Selects task mode (feature,bugfix,refactor,hardening,research,general).rapid context --harness <harness>: Selects target harness (validate_harness_id: built-inscursor,claude,codex,vscode,antigravity, or any syntactically valid customharness_idmatching^[a-z0-9][a-z0-9-]{0,62}$, while keeping the Context Compiler pure with respect to the Harness Registry).rapid context --objective "...": Provides task objective for relevance scoring and task header rendering.rapid context --spec <spec-id> [--spec-revision <n>]: Injects areadyspec (current or pinned revision) from.rapid-os/specs/<spec-id>/into the Context Compiler and suppresses root singletonSPECS.md/TASKS.md/ACCEPTANCE.mdfiles to prevent ambiguity.rapid context --max-chars <n>: Sets explicit character budget.rapid context --manifest: Prints human-readable manifest (SELECTED,SKIPPED, andCONFLICTS).rapid context --json: Emits pureCompiledContextJSON (schema_version = 1,manifest,content) tostdout.rapid inspect-contextandcompose_project_context()remain intact for v2 compatibility.
Phase 3: Spec Registry v3
Architectural Principle
Whereas legacy rapid scope overwrote three singleton root files (SPECS.md, TASKS.md, ACCEPTANCE.md) with no stable identity, concurrent spec support, revision history, or authoring lifecycle, the Spec Registry makes Spec-Driven Development (SDD) canonical, addressable, and immutable.
A Spec answers: "What must be built and how will we know it is properly defined?".
It strictly separates authoring state (draft, ready, archived) from execution state (which belongs to Phase 4+).
Pipeline & Filesystem Layout
Scope / Spec Input
↓
Canonical Spec Model (SpecRecord + SpecRevision in rapid_os.domain.specs)
↓
SpecRegistry (.rapid-os/specs/<spec-id>/)
├── spec.json (schema_version = 1, id, status, current_revision)
└── revisions/
├── 0001/
│ ├── revision.json (schema_version = 1, structured fields + digests)
│ ├── requirements.md
│ ├── tasks.md
│ └── acceptance.md
└── 0002/
└── ...
↓
Context Compiler (rapid context --spec <spec-id> [--spec-revision <n>])
- No Duplicate Index: Specs are discovered deterministically by scanning
.rapid-os/specs/*/spec.jsonin lexical order. - Immutable Revisions, Historical Continuity & Atomic Commit Point: Existing
revisions/<rev>/directories (format_revision_dir_name:0001..9999,10000, ...) are never modified in place, and every historical revision1..current_revisionmust remain present and valid. Creating or revising a spec validates the model, writesrequirements.md,tasks.md,acceptance.md, andrevision.json, verifies revision completeness and SHA-256 digests, and updatesspec.json(current_revision) last.
Canonical Domain Entities (rapid_os.domain.specs)
SPEC_SCHEMA_VERSION = 1 & SPEC_REVISION_SCHEMA_VERSION = 1
Independent schema versions governing spec.json and revision.json.
SpecStatus
Authoring lifecycle enum (DRAFT = "draft", READY = "ready", ARCHIVED = "archived"):
- Allowed transitions:
draft → ready,draft → archived,ready → draft,ready → archived. archivedis terminal in Phase 3.
SpecMode
Canonical authoring mode (FEATURE = "feature", BUGFIX = "bugfix", REFACTOR = "refactor", HARDENING = "hardening", RESEARCH = "research"), with compatibility mapping from legacy rapid scope modes (new feature → feature, legacy hardening → hardening).
SpecRecord
Immutable record (schema_version, id, status, current_revision) persisted in .rapid-os/specs/<spec-id>/spec.json. Contains no timestamps, no UUIDs, no host paths, and no execution state.
SpecRevision
Immutable structured revision (schema_version, spec_id, revision, title, mode, business_objective, problem_statement, scope, out_of_scope, actors_users, main_flow, edge_cases, business_rules, technical_constraints, affected_paths, data_impact, acceptance_criteria, testing_strategy, implementation_tasks, tags):
- Preserves exact user-authored ordering across all semantic tuple fields (
main_flow,implementation_tasks,acceptance_criteria, etc.); onlytagsare normalized, deduplicated, and sorted lowercase. - Strictly validates persisted
revision.jsonkeys againstCANONICAL_SPEC_REVISION_KEYS(RAPID803), rejecting unknown or execution-state fields (execution_status,run_id,agent). - Deterministically renders
requirements.md,tasks.md, andacceptance.md, and computesartifact_digests(requirements.md,tasks.md,acceptance.md) pluscontent_digest(<sha256-hex>). - Provides explicit compatibility converters
spec_revision_from_scope()andscope_spec_from_revision()so legacyScopeSpecacts strictly as an authoring DTO.
Context Compiler Integration
When ContextRequest.spec_id is provided (rapid context --spec <id>):
- The target spec must have
status == SpecStatus.READY(loading adraftorarchivedspec fails withRAPID805). ContextSourceLoaderemits three canonical sources with portable repository-relative POSIX path provenance (.rapid-os/specs/<id>/revisions/<rev>/<artifact>):spec.<id>.requirements(ContextSourceKind.SPEC,HIGHpriority,provenance=".rapid-os/specs/<id>/revisions/<rev>/requirements.md")spec.<id>.tasks(ContextSourceKind.TASKS,MEDIUMpriority,provenance=".rapid-os/specs/<id>/revisions/<rev>/tasks.md")spec.<id>.acceptance(ContextSourceKind.ACCEPTANCE,MEDIUMpriority,provenance=".rapid-os/specs/<id>/revisions/<rev>/acceptance.md")
- Root legacy singletons (
SPECS.md,TASKS.md,ACCEPTANCE.md) are automatically excluded when--specis active. - Without
--spec,rapid contextpreserves backward compatibility by reading root singletons if present and ignoring.rapid-os/specs/to avoid multi-spec ambiguity.
Spec Registry Validation (RAPID8xx in rapid_os.domain.validation)
validate_spec_registry(root) is integrated into rapid validate and rapid doctor:
RAPID800(INFO): Spec registry valid.RAPID801(ERROR): Invalid persistedspec.jsonrecord/schema (InvalidSpecRecordError: invalid JSON, unsupportedschema_version, unknown fields, or invalid persisted record/status value).RAPID802(ERROR): Missingrevisions/directory or missing required historical/current revision directory (1..current_revision,CurrentRevisionMissingError).RAPID803(ERROR): Invalid persistedrevision.jsonmanifest/schema (InvalidRevisionManifestError: invalid JSON, unsupportedschema_version, unknown fields, or invalid revision fields).RAPID804(ERROR): Missingrequirements.md,tasks.md, oracceptance.mdartifact, or SHA-256 digest drift (SpecArtifactDriftError).RAPID805(ERROR): Invalid lifecycle transition or spec lifecycle prevents requested operation (SpecLifecycleError, e.g.draft/archivedspec requested by operational context compilation).RAPID806(ERROR): Invalidspec_id, duplicate spec identity, or directory/record ID mismatch (DuplicateSpecIdentityError).RAPID807(ERROR): Referenced spec or revision not found (SpecNotFoundError).RAPID808(ERROR): Unsafe spec path, symlink escape, or unreadable spec entry (UnsafeSpecPathError).RAPID809(WARNING): Orphan or unreferenced revision entry insiderevisions/(revision > current_revisionor non-canonical entry).
CLI Surface (rapid spec)
rapid spec create: Creates a new spec (--title,--id,--mode,--objective,--problem,--scope,--out-of-scope,--actor,--main-flow/--flow,--edge-case,--business-rule/--rule,--technical-constraint/--constraint,--affected-path,--data-impact,--acceptance,--testing,--task,--tag,--status {draft,ready},--export-legacy,--json). Interactive wizard when flags are omitted.rapid spec list [--status {draft,ready,archived}] [--json]: Lists specs in deterministic ID order without writing files.rapid spec show <spec-id> [--revision <n>] [--json]: Displays a spec and its current or pinned revision in read-only mode.rapid spec revise <spec-id> [--json] [...]: Creates immutable revisioncurrent_revision + 1, inheriting unspecified fields fromcurrent_revisionand resetting status todraft.rapid spec status <spec-id> <status> [--json]: Transitions authoring status (draft,ready,archived).rapid spec export-legacy <spec-id> [--revision <n>]: Explicitly exports a spec revision to rootSPECS.md,TASKS.md, andACCEPTANCE.mdwith.bakbackup protection.rapid scope [--register] [--spec-id <id>] [--status {draft,ready}]: Preserves legacy root file generation while optionally registering the spec in.rapid-os/specs/.
Phase 4: Execution Policy Engine & Run Contract
Architectural Principle
Phase 4 answers: "Given an exact Spec revision and its compiled context, under what execution contract, risk classification, workspace requirement, and gates is work allowed to happen?"
Rapid OS v3 strictly separates:
- Spec: WHAT must be built (authoring lifecycle in
.rapid-os/specs/). - Context: WHAT the agent needs to know (
CompiledContext). - Policy: UNDER WHAT RULES work may happen (
ExecutionPolicy→PolicyDecision). - Run: ONE concrete execution attempt pinned to an immutable
ExecutionContractand append-onlyRunStatesnapshots in.rapid-os/runs/<run-id>/. - Evidence (Phase 6): PROOF of what actually happened (
RunEvidence&EvaluationReport).
Rapid OS does not act as an autonomous agent runtime: it never invokes external LLM CLIs, never runs shell commands, never creates git worktrees automatically, and never mutates application source code.
Pipeline & Filesystem Layout
ProjectModel + SpecRevision (status == ready) + CompiledContext + ExecutionPolicy
↓
ExecutionPolicyEvaluator (rapid_os.domain.policy)
↓
PolicyDecision (ExecutionClass, RiskLevel, RiskSignals, WorkspaceRequirement, GateRequirements, reasons)
↓
ExecutionContract (contract.json: immutable contract + SHA-256 digests)
↓
RunRegistry (.rapid-os/runs/<run-id>/)
├── run.json (schema_version = 1, id, spec_id, spec_revision, contract_digest, current_state_revision)
├── contract.json (schema_version = 1, immutable ExecutionContract)
├── context.md (immutable compiled context snapshot)
├── context-manifest.json (immutable ContextManifest snapshot)
└── states/
├── 0001.json (initial RunState: status=prepared, tasks=pending, gates=pending)
├── 0002.json (append-only state transition)
└── ...
- No Duplicate Index: Runs are discovered deterministically by scanning
.rapid-os/runs/*/run.jsonin lexical order. - Deterministic Run IDs: Default run IDs follow
<spec-id>-r<spec-revision>-run-<NNN>(001..999,1000, ...) with no timestamps, random UUIDs, or host paths. - Immutable Contract & Append-Only State History:
contract.json,context.md,context-manifest.json, and existingstates/<NNNN>.jsonfiles are never modified in place. Every transition writesstates/<next>.jsonfirst, verifies its schema and invariants, and updatesrun.json(current_state_revision) last.
Canonical Domain Entities (rapid_os.domain.policy & rapid_os.domain.execution)
ExecutionClass
Classification of execution scope (SPIKE = "spike", BOUNDED = "bounded", ARCHITECTURAL = "architectural"):
spike:SpecMode.RESEARCHwithout architectural signals.bounded:FEATURE,BUGFIX, orREFACTORwithout architectural signals.architectural:SpecMode.HARDENING, architectural tags/paths (migration,schema,infra,deployment,security,auth,ci,architecture), or non-emptydata_impact.
RiskLevel & RiskSignal
Ordered risk enum (LOW = 10, MEDIUM = 50, HIGH = 80, CRITICAL = 100) paired with structured RiskSignal records (id, level, reason, source).
- Neither project policy nor CLI overrides (
--classification,--risk) may downgrade the calculatedExecutionClassorRiskLevel; any downgrade attempt fails withRAPID1006.
WorkspaceRequirement
Declarative workspace rule (CURRENT_ALLOWED = "current_allowed", ISOLATED_REQUIRED = "isolated_required"):
LOW/MEDIUMdefault tocurrent_allowed.HIGH/CRITICALrequireisolated_required.
GateKind, GatePhase, & GateRequirement
Canonical execution gates evaluated across PRE_EXECUTION (gate.workspace-isolation, gate.baseline, gate.manual-approval) and POST_EXECUTION (gate.tests, gate.architecture (only when the project has an architecture rule), gate.review, gate.security-review, gate.migration-review, gate.final-verification):
- Ordered deterministically by
CANONICAL_GATE_ORDERwithout duplicates. - At
CRITICALrisk, no gate is waivable. BelowCRITICAL, only gates listed inpolicy.waivable_gate_ids(gate.review,gate.testsby default) may be waived, and waiving always requires a non-emptyreason.
ExecutionPolicy (.rapid-os/policy.json)
Optional project-level policy configuration (EXECUTION_POLICY_SCHEMA_VERSION = 1) defining minimum_classification, minimum_risk, architectural_tags, architectural_path_prefixes, high_risk_tags, critical_risk_tags, workspace_by_risk, waivable_gate_ids, and extra_required_gate_ids.
- If
.rapid-os/policy.jsondoes not exist,DEFAULT_EXECUTION_POLICYis used (source="default"). - If
.rapid-os/policy.jsonexists, it is validated strictly (source=".rapid-os/policy.json"); corrupt or invalid policy files fail explicitly withRAPID1005orRAPID1006without falling back to defaults. - Programmatically injected custom policies require an explicit truthful
policy_source("injected") and cannot claim"default"(RAPID1005).
TaskContract & ExecutionContract
ExecutionContract (EXECUTION_CONTRACT_SCHEMA_VERSION = 1) pins schema_version, run_id, spec_id, spec_revision, spec_content_digest, harness, context_digest, context_manifest_digest, project_model_digest, policy_source, policy_digest, decision, classification, risk, risk_signals, workspace, gates, tasks (T001, T002, ... derived deterministically from SpecRevision.implementation_tasks), and contract_digest.
contract_digestis computed over the semantic contract payload (excludingrun_idandcontract_digest), so identical inputs produce identicalcontract_digestvalues across runs.
RunStatus, TaskStatus, GateDisposition, & RunState
RunState (RUN_STATE_SCHEMA_VERSION = 1) records the state revision (1..current_state_revision):
- Initial snapshot (
states/0001.json) invariant:revision = 1,status = prepared, all taskspending(empty reason), all gatespending(empty reason), andchange_kind = "run.prepared"(RAPID1012). - Sequential history verification (
s1 → s2 → ... → current): every consecutive snapshot must advancerevisionby 1, mutate exactly one category (run status,1 task, or1 gate), matchchange_kind, and satisfy all phase boundary preconditions (RAPID1012). RunStatustransitions:prepared → active | cancelled,active → blocked | finished | failed | cancelled,blocked → active | failed | cancelled.finished,failed, andcancelledare terminal (RAPID1009).- Phase boundaries (
RAPID1014):PRE_EXECUTIONgates can only change whilestatus = prepared.- Precondition for
prepared → active: all requiredPRE_EXECUTIONgates must beacknowledgedorwaived. - Tasks can only change while
status = active. POST_EXECUTIONgates can only change whilestatus = activeand after all tasks are terminal (doneorskipped).- Precondition for
active → finished: all tasks must bedoneorskippedand all requiredPOST_EXECUTIONgates must beacknowledgedorwaived.
TaskStatustransitions:pending → in_progress | skipped,in_progress → done | blocked | skipped,blocked → in_progress | skipped.doneandskippedare terminal (RAPID1010).
Execution Policy & Run Registry Validation (RAPID1000–RAPID1019 in rapid_os.domain.validation)
validate_execution_policy(rapid_dir, root) and validate_run_registry(rapid_dir, root) are integrated into rapid validate and rapid doctor:
RAPID1000(INFO): Execution policy and run registry valid.RAPID1001(ERROR): Invalidrun.jsonrecord or schema (InvalidRunRecordError).RAPID1002(ERROR): Invalidcontract.jsonor contract digest mismatch (InvalidExecutionContractError).RAPID1003(ERROR): Invalid spec binding (InvalidSpecBindingError— missing spec/revision, spec notready, orspec_content_digestmismatch).RAPID1004(ERROR): Context snapshot or digest mismatch (ContextSnapshotMismatchError).RAPID1005(ERROR): Invalid execution policy schema (InvalidExecutionPolicyError).RAPID1006(ERROR): Policy violation or forbidden risk/classification downgrade (PolicyViolationError).RAPID1007(ERROR): Run identity error or referenced run not found (DuplicateRunIdentityError,RunNotFoundError).RAPID1008(ERROR): Unsafe run/policy path or symlink escape (UnsafeRunPathError).RAPID1009(ERROR): Invalid run status transition (InvalidRunTransitionError).RAPID1010(ERROR): Invalid task status transition (InvalidTaskTransitionError).RAPID1011(ERROR/WARNING): Run state history gap or missingstates/directory (ERROR,RunStateHistoryGapError); unreferenced future staterevision > current_state_revisionor non-canonical entry instates/(WARNING).RAPID1012(ERROR): InvalidRunStateschema, digest, contract alignment, initial state invariant, or semantic state transition history (InvalidRunStateError).RAPID1013(ERROR): Invalid gate disposition transition or invalid waiver (InvalidGateTransitionError).RAPID1014(ERROR): Run lifecycle or phase boundary precondition not satisfied (ExecutionPreconditionError).RAPID1015–RAPID1019: Reserved for future execution policy diagnostics.
CLI Surface (rapid policy & rapid run)
rapid policy show [--json]: Displays active execution policy (defaultor.rapid-os/policy.json) in read-only mode.rapid policy init [--json]: Writes default.rapid-os/policy.json(fails withRAPID1005if.rapid-os/policy.jsonalready exists).rapid run create --spec <spec-id> [--spec-revision <n>] [--id <run-id>] [--harness <harness>] [--classification <class>] [--risk <risk>] [--json]: Evaluates policy, compiles context, and creates an immutable run contract and initial state0001.json.rapid run list [--status <status>] [--json]: Lists runs in deterministic ID order without mutating files.rapid run show <run-id> [--state-revision <n>] [--json]: Displays run record, contract, risk signals, tasks, gates, and current or historical state in read-only mode.rapid run status <run-id> <status> [--reason "..."] [--json]: Appends a new state revision transitioning run status after verifying gate/task preconditions.rapid run task <run-id> <task-id> <status> [--reason "..."] [--json]: Appends a new state revision transitioning a task (T001, ...).rapid run gate <run-id> <gate-id> <disposition> [--reason "..."] [--json]: Appends a new state revision acknowledging or waiving a gate.
Phase 5: Harness Capability Registry
Architectural Principle
Phase 5 answers:
"Given an immutable
ExecutionContract, can the selected harness satisfy the capabilities required to execute that contract?"
Repository
↓
ProjectModel
↓
SpecRevision + CompiledContext
↓
ExecutionPolicy
↓
ExecutionContract
↓
HarnessProfile + CapabilityRequirementResolver
↓
CapabilityResolution
Fundamental Boundary & Product Truth
A capability declaration says what a harness is expected to support. It does not prove that the harness actually exercised that capability.
Phase 5 manages:
- Harness identity validation (
validate_harness_id,HARNESS_ID_RE = ^[a-z0-9][a-z0-9-]{0,62}$) - Canonical capability catalog (
CANONICAL_CAPABILITY_DEFINITIONS, 11 canonical capability IDs) - Declarative harness profiles (
HarnessProfile,HARNESS_PROFILE_SCHEMA_VERSION = 1) - Built-in vs. project-overridden profiles (
.rapid-os/harnesses/<id>.jsonwith full replacement semantics and no silent fallback on corrupt profiles) - Capability requirement derivation from
ExecutionContract(CapabilityRequirementResolver) - Compatibility resolution (
CapabilityResolver→CapabilityResolution) - Deterministic capability lock snapshots (
.rapid-os/capabilities.lock,CAPABILITY_LOCK_SCHEMA_VERSION = 1)
Phase 5 does not manage:
- Agent or LLM invocation
- Shell execution (
subprocess,os.system,Popen,shell=True) - Git command execution or worktree creation
- Subagent or MCP runtime invocation
- Evidence collection or behavioral evaluation (handled by Phase 6)
- Mutation of Phase 4 run artifacts (
run.json,contract.json,context.md,context-manifest.json,states/*.json)
Canonical Domain Entities (rapid_os.domain.harnesses & rapid_os.domain.capabilities)
Harness Identity (validate_harness_id)
- Validated by
HARNESS_ID_RE = re.compile(r"^[a-z0-9][a-z0-9-]{0,62}$"). - Rejects uppercase characters, whitespace, null bytes, path separators, traversal segments (
..), and Windows drive prefixes (RAPID1104,HarnessIdentityError). - Built-in harness IDs:
codex,claude,cursor,vscode,antigravity. ContextRequest,ContextManifest, andExecutionContract(EXECUTION_CONTRACT_SCHEMA_VERSION = 1unchanged) accept any syntactically validharness_id. The Context Compiler remains pure with respect to the Harness Registry.ExecutionContract.harnessis the single source of truth for capability resolution (profile.id == contract.harness); the harness is selected when creating a Run (rapid run create --harness <id>).
Capability Catalog (CapabilityCategory & CapabilityDefinition)
First-class canonical catalog with 8 categories (context, repository, workspace, execution, testing, git, integration, delegation) and 11 canonical capability IDs:
context.consume(context)repository.read(repository)repository.write(repository)workspace.current(workspace)workspace.isolated(workspace)shell.execute(execution)tests.execute(testing)git.inspect(git)git.modify(git)mcp.invoke(integration)subagents.delegate(delegation)
Unknown or out-of-catalog capability IDs are rejected with RAPID1101 (InvalidCapabilityIdError).
Capability Support (CapabilitySupportStatus & CapabilitySupport)
CapabilitySupportStatus:SUPPORTED = "supported",UNSUPPORTED = "unsupported",UNKNOWN = "unknown".- Critical invariant:
UNKNOWN != SUPPORTED. Anunknowncapability never satisfies a required capability. CapabilitySupport(capability_id, status, reason)requires a non-emptyreason, is deduplicated, and is sorted deterministically bycapability_id. Invalid or duplicate support declarations fail withRAPID1106(InvalidCapabilitySupportError).
HarnessProfile (HARNESS_PROFILE_SCHEMA_VERSION = 1)
- Immutable profile (
schema_version,id,capabilities,content_digest). - Strict persisted schema (
schema_version,id,capabilities, optionalcontent_digeston authoring input; unknown fields likeagent_status,model,last_seen, orexecution_resultare rejected withRAPID1102,InvalidHarnessProfileError). content_digestis the SHA-256 hex digest of the canonical JSON payload excludingcontent_digest. Ifcontent_digestis present in persisted JSON, it is strictly verified (RAPID1102); if omitted in hand-authored JSON, it is computed deterministically on load and always emitted on serialization.
Conservative Built-in Profiles & Project Override Semantics (rapid_os.adapters.harness_registry)
- Built-in profiles (
builtin:<id>) follow a conservative policy:context.consume:supportedrepository.read:supportedworkspace.current:supported- All other canonical capabilities (
repository.write,workspace.isolated,shell.execute,tests.execute,git.inspect,git.modify,mcp.invoke,subagents.delegate):unknown
- Project profiles live in
.rapid-os/harnesses/<id>.json(source = ".rapid-os/harnesses/<id>.json"). - Full Replacement Semantics: When
.rapid-os/harnesses/<id>.jsonexists, it completely replacesbuiltin:<id>(any canonical capability omitted from the JSON file defaults tounknownon that profile rather than merging from the built-in profile). - No Silent Fallback: If
.rapid-os/harnesses/<id>.jsonexists on disk but is corrupt, unreadable, has an ID/filename mismatch, or fails schema/digest validation,HarnessRegistryraises aHarnessCapabilityError(RAPID1102/RAPID1104/RAPID1105/RAPID1106) and never falls back tobuiltin:<id>.