QonQrete Documentation
Version: v1.0.0-stable (See VERSION file for the canonical version).
This document provides a comprehensive overview of the QonQrete Secure AI Construction Loop System.
Table of Contents
Architecture
This section contains Mermaid diagrams illustrating the complete architecture of the QonQrete system v1.0.0.
High-Level System Overview
flowchart TB
subgraph HOST["๐ฅ๏ธ Host System"]
User([๐ค User])
Shell[./qonqrete.sh]
EnvFile[.env<br/>API Keys]
Version[VERSION<br/>v1.0.0]
end
subgraph CONTAINER["๐ณ Container Runtime"]
subgraph QRANE["๐๏ธ Qrane Orchestrator"]
Loader[loader.py<br/>Config Parser]
TUI[tui.py<br/>Display Filter]
PathMgr[paths.py<br/>Path Manager]
MainLoop[qrane.py<br/>Main Loop]
end
subgraph AGENTS["๐ค Agent Pipeline"]
direction TB
subgraph LOCAL["โก Local Agents (Zero Cost)"]
Qompressor[๐ฆด Qompressor<br/>Skeletonizer]
Qontextor[๐ Qontextor<br/>AST + Jedi + PyCG]
CalQulator[๐งฎ CalQulator<br/>Cost Estimator]
LoQal[โ
LoQal Verifier<br/>Syntax + Imports]
end
subgraph AI["๐ง AI Agents"]
InstruQtor[๐ InstruQtor<br/>Briq Planner]
ConstruQtor[๐จ ConstruQtor<br/>Code Generator]
InspeQtor[๐ InspeQtor<br/>Batched Reviewer]
end
subgraph CACHE["๐พ Cache Layer"]
Qontrabender[๐ Qontrabender<br/>Hybrid Cache]
end
end
subgraph LIBAI["๐ AI Provider Abstraction"]
LibAI[lib_ai.py]
OpenAI[(OpenAI<br/>gpt-4.1-*)]
Gemini[(Gemini<br/>2.5-flash/pro)]
Anthropic[(Anthropic<br/>claude-*)]
DeepSeek[(DeepSeek<br/>V3.2)]
Qwen[(Qwen<br/>qwen3-coder)]
end
end
subgraph WORQSPACE["๐ Worqspace Volume"]
Config[config.yaml]
PipeConfig[pipeline_config.yaml]
TasQ[tasq.md]
subgraph QAGE["๐ฆ qage_timestamp/"]
BriqD[briq.d/]
BloqD[bloq.d/]
QontextD[qontext.d/]
Qodeyard[qodeyard/]
ExeqD[exeq.d/]
ReqapD[reqap.d/]
StruqtureD[struqture/<br/>Logs]
end
end
User --> Shell
Shell --> EnvFile
Shell --> Version
Shell --> CONTAINER
MainLoop --> Loader
MainLoop --> TUI
MainLoop --> PathMgr
Loader --> Config
Loader --> PipeConfig
MainLoop --> Qompressor
MainLoop --> Qontextor
MainLoop --> CalQulator
MainLoop --> InstruQtor
MainLoop --> ConstruQtor
MainLoop --> InspeQtor
MainLoop --> Qontrabender
ConstruQtor --> LoQal
InstruQtor --> LibAI
ConstruQtor --> LibAI
InspeQtor --> LibAI
LibAI --> OpenAI
LibAI --> Gemini
LibAI --> Anthropic
LibAI --> DeepSeek
LibAI --> Qwen
TasQ --> InstruQtor
InstruQtor --> BriqD
Qodeyard --> Qompressor
Qompressor --> BloqD
Qodeyard --> Qontextor
Qontextor --> QontextD
BriqD --> CalQulator
BloqD --> CalQulator
BriqD --> ConstruQtor
BloqD --> ConstruQtor
ConstruQtor --> Qodeyard
ConstruQtor --> ExeqD
Qodeyard --> InspeQtor
ExeqD --> InspeQtor
InspeQtor --> ReqapD
Qontrabender --> BloqD
classDef host fill:#2d2d2d,stroke:#888,color:#fff
classDef container fill:#1a3a1a,stroke:#4a4,color:#fff
classDef local fill:#1a1a3a,stroke:#44a,color:#fff
classDef ai fill:#3a1a1a,stroke:#a44,color:#fff
classDef cache fill:#3a3a1a,stroke:#aa4,color:#fff
classDef volume fill:#2a1a2a,stroke:#a4a,color:#fff
classDef provider fill:#1a2a2a,stroke:#4aa,color:#fff
class User,Shell,EnvFile,Version host
class Qompressor,Qontextor,CalQulator,LoQal local
class InstruQtor,ConstruQtor,InspeQtor ai
class Qontrabender cache
class Config,PipeConfig,TasQ,BriqD,BloqD,QontextD,Qodeyard,ExeqD,ReqapD,StruqtureD volume
class OpenAI,Gemini,Anthropic,DeepSeek,Qwen provider
Detailed Pipeline Flow
flowchart LR
subgraph CYCLE["๐ CyQle N"]
direction TB
Start([Start CyQle]) --> Qompressor
subgraph PREP["1๏ธโฃ Preparation Phase"]
Qompressor[๐ฆด Qompressor<br/>Generate Skeletons]
Qontextor[๐ Qontextor<br/>Build Symbol Map]
Qompressor --> Qontextor
end
subgraph PLAN["2๏ธโฃ Planning Phase"]
InstruQtor[๐ InstruQtor<br/>Decompose TasQ โ BriQs]
CalQulator[๐งฎ CalQulator<br/>Estimate Costs]
Qontextor --> InstruQtor
InstruQtor --> CalQulator
end
subgraph BUILD["3๏ธโฃ Build Phase (Interleaved)"]
direction TB
ConstruQtor[๐จ ConstruQtor<br/>Generate Code]
LoQal[โ
LoQal<br/>Verify Syntax]
Retry{Retry?}
CalQulator --> ConstruQtor
ConstruQtor --> LoQal
LoQal -->|FAIL| Retry
Retry -->|Yes| ConstruQtor
Retry -->|No| NextBriq
LoQal -->|PASS| NextBriq[Next BriQ]
NextBriq -->|More BriQs| ConstruQtor
end
subgraph REVIEW["4๏ธโฃ Review Phase (Batched)"]
InspeQtor[๐ InspeQtor<br/>Batch Review All BriQs]
MetaReview[๐ Meta-Review<br/>Consolidate Results]
NextBriq -->|All Done| InspeQtor
InspeQtor --> MetaReview
end
subgraph CACHE["5๏ธโฃ Cache Phase"]
Qontrabender[๐ Qontrabender<br/>Save to Qache]
MetaReview --> Qontrabender
end
subgraph CHECKPOINT["6๏ธโฃ CheQpoint"]
CheQpoint{User Decision}
Qontrabender --> CheQpoint
CheQpoint -->|Continue| NextCycle([CyQle N+1])
CheQpoint -->|TweaQ| TweaQ[Modify TasQ]
CheQpoint -->|Quit| Done([Exit])
TweaQ --> NextCycle
end
end
style PREP fill:#1a1a3a,stroke:#44a
style PLAN fill:#2a1a2a,stroke:#a4a
style BUILD fill:#3a1a1a,stroke:#a44
style REVIEW fill:#1a3a1a,stroke:#4a4
style CACHE fill:#3a3a1a,stroke:#aa4
style CHECKPOINT fill:#2a2a2a,stroke:#888
ConstruQtor Build Loop (Interleaved Mode)
flowchart TB
subgraph CONSTRUQTOR["๐จ ConstruQtor v0.8.8 - Per-BriQ Processing"]
Start([Start]) --> LoadBriqs[Load BriQ Files]
LoadBriqs --> ForEach{For Each BriQ}
ForEach --> Attempt[Attempt 1/3]
subgraph ATTEMPT["Build Attempt"]
Attempt --> Context[Gather Context<br/>bloq.d + qontext.d]
Context --> Prompt[Build AI Prompt]
Prompt --> AICall[๐ง AI Generate Code]
AICall --> Parse[Parse Response<br/>Extract Files]
Parse --> Write[Write to qodeyard/]
end
subgraph VERIFY["LoQal Verification"]
Write --> Syntax[Python compile]
Syntax -->|Error| SyntaxFail[โ Syntax Error]
Syntax -->|OK| Imports[Check Imports]
Imports -->|Warning| ImportWarn[โ ๏ธ Import Warning]
Imports -->|OK| Pass[โ
Passed]
end
SyntaxFail --> RetryCheck{Attempts < 3?}
RetryCheck -->|Yes| Attempt
RetryCheck -->|No| MarkFail[Mark FAILURE]
ImportWarn --> WriteExeq
Pass --> WriteExeq[Write exeQ Summary]
MarkFail --> WriteExeq
WriteExeq --> ForEach
ForEach -->|Done| Complete([All BriQs Complete])
end
style ATTEMPT fill:#3a1a1a,stroke:#a44
style VERIFY fill:#1a3a1a,stroke:#4a4
InspeQtor Batched Review Flow
flowchart TB
subgraph INSPEQTOR["๐ InspeQtor v0.8.8 - Two-Stage Batched Review"]
Start([Start]) --> Gather[Gather All ExeQs<br/>from exeq.d/cyqleN/]
subgraph STAGE1["Stage 1: Batched Per-BriQ Reviews"]
Gather --> CalcBatches[Calculate Batches<br/>max 12 briqs, 60K tokens]
CalcBatches --> ForBatch{For Each Batch}
ForBatch --> BuildPrompt[Build Batch Prompt<br/>All BriQs + Code]
BuildPrompt --> AIReview[๐ง AI Batch Review]
AIReview --> ParseResults[Parse Results<br/>Extract Per-BriQ Status]
ParseResults --> WriteReqaps[Write Individual<br/>reqap.md Files]
WriteReqaps --> ForBatch
end
subgraph STAGE2["Stage 2: Meta-Review"]
ForBatch -->|All Batches Done| GatherReqaps[Gather All ReQaps]
GatherReqaps --> MetaPrompt[Build Meta Prompt]
MetaPrompt --> MetaAI[๐ง AI Consolidate]
MetaAI --> FinalReqap[Write Final ReQap<br/>Cycle Summary]
end
subgraph LOQAL["LoQal Verification"]
FinalReqap --> LoQalCheck[Run Full Verification<br/>All qodeyard/ Files]
LoQalCheck --> Report[Append to ReQap]
end
Report --> Done([Complete])
end
style STAGE1 fill:#1a3a1a,stroke:#4a4
style STAGE2 fill:#3a3a1a,stroke:#aa4
style LOQAL fill:#1a1a3a,stroke:#44a
Directory Structure
flowchart TB
subgraph DIRS["๐ QonQrete Directory Structure"]
direction TB
subgraph ROOT["qonqrete/"]
qonqrete_sh[qonqrete.sh<br/>Entry Point]
VERSION[VERSION<br/>0.8.8]
env[.env<br/>API Keys]
Dockerfile[Dockerfile]
end
subgraph QRANE["qrane/"]
qrane_py[qrane.py<br/>Orchestrator]
loader[loader.py<br/>Config]
paths[paths.py<br/>Paths]
tui[tui.py<br/>Display]
lib_funq[lib_funqtions.py<br/>Pricing]
end
subgraph WORQER["worqer/"]
lib_ai[lib_ai.py<br/>AI Abstraction]
instruqtor[instruqtor.py]
construqtor[construqtor.py]
inspeqtor[inspeqtor.py]
qompressor[qompressor.py]
qontextor[qontextor.py]
qontrabender[qontrabender.py]
calqulator[calqulator.py]
loqal_verifier[loqal_verifier.py]
end
subgraph WORQSPACE["worqspace/"]
config[config.yaml]
pipeline[pipeline_config.yaml]
tasq[tasq.md]
sqrapyard[sqrapyard/<br/>Persistent Storage]
subgraph QAGE["qage_YYYYMMDD_HHMMSS/"]
briq_d[briq.d/<br/>Planned Steps]
bloq_d[bloq.d/<br/>Skeletons]
qontext_d[qontext.d/<br/>Symbol Maps]
qodeyard_g[qodeyard/<br/>Generated Code]
exeq_d[exeq.d/<br/>Build Summaries]
reqap_d[reqap.d/<br/>Reviews]
struqture[struqture/<br/>Logs]
end
end
subgraph DOC["doc/"]
docs[DOCUMENTATION.md<br/>RELEASE-NOTES.md<br/>QUICKSTART.md<br/>etc.]
end
end
qonqrete_sh --> qrane_py
qrane_py --> loader
qrane_py --> paths
qrane_py --> tui
loader --> config
loader --> pipeline
qrane_py --> instruqtor
qrane_py --> construqtor
qrane_py --> inspeqtor
instruqtor --> lib_ai
construqtor --> lib_ai
construqtor --> loqal_verifier
inspeqtor --> lib_ai
instruqtor --> briq_d
qompressor --> bloq_d
qontextor --> qontext_d
construqtor --> qodeyard_g
construqtor --> exeq_d
inspeqtor --> reqap_d
style ROOT fill:#2d2d2d,stroke:#888
style QRANE fill:#1a3a1a,stroke:#4a4
style WORQER fill:#3a1a1a,stroke:#a44
style WORQSPACE fill:#2a1a2a,stroke:#a4a
style QAGE fill:#3a3a1a,stroke:#aa4
style DOC fill:#1a1a3a,stroke:#44a
Cost Flow Visualization
flowchart LR
subgraph COSTS["๐ฐ Token Cost Flow (v0.8.8)"]
subgraph FREE["๐ Zero Cost"]
Qompressor[Qompressor<br/>Local Python]
Qontextor[Qontextor<br/>AST + Jedi]
CalQulator[CalQulator<br/>Local Math]
LoQal[LoQal Verifier<br/>compile + imports]
Qontrabender[Qontrabender<br/>Local Cache]
end
subgraph CHEAP["๐ต Low Cost"]
InstruQtor[InstruQtor<br/>gpt-4.1-nano<br/>$0.10/1M in]
InspeQtorBatch[InspeQtor Batched<br/>gpt-4.1-mini<br/>$0.40/1M in]
end
subgraph MAIN["๐ฐ Main Cost"]
ConstruQtor[ConstruQtor<br/>gemini-2.5-flash<br/>$0.30/1M in]
end
subgraph TOTAL["๐ 7 CyQle Estimate"]
Est[InstruQtor: ~$0.01<br/>ConstruQtor: ~$1.50<br/>InspeQtor: ~$0.30<br/>โโโโโโโโโโโ<br/>TOTAL: ~$2.00]
end
end
FREE --> CHEAP
CHEAP --> MAIN
MAIN --> TOTAL
style FREE fill:#1a3a1a,stroke:#4a4
style CHEAP fill:#3a3a1a,stroke:#aa4
style MAIN fill:#3a1a1a,stroke:#a44
style TOTAL fill:#1a1a3a,stroke:#44a
Execution Flows
This section traces the end-to-end execution flows of the QonQrete system, from user command to the completion of a cycle.
1. Initialization Flow (./qonqrete.sh init)
- User Input: User executes
./qonqrete.sh init. An optional--msbor--dockerflag can be provided. qonqrete.sh: The script parses theinitcommand.- Runtime Detection: It checks for the
--msbor--dockerflags. If none are provided, it checkspipeline_config.yamlfor amicrosandbox: truesetting. If not found, it defaults to Docker. - Container Build:
- If the runtime is
docker, it executesdocker build -t qonqrete-qage -f Dockerfile .. - If the runtime is
msb, it executesmsb build . -t qonqrete-qage(ormbx).
- If the runtime is
- Result: A container image named
qonqrete-qageis created in the local registry of the selected runtime, ready for execution.
2. Main Execution Flow (./qonqrete.sh run)
- User Input: User executes
./qonqrete.sh run. Optional flags like--auto,--user, and--tuican be included. qonqrete.sh:- Parses the
runcommand and any additional flags. - Reads the
VERSIONfile and exports it asQONQ_VERSION. - Creates a unique timestamped run directory (
qage_<timestamp>) insideworqspace/. - Sqrapyard Initialization: It checks the persistent
worqspace/sqrapyarddirectory. If it contains files, they are copied into the newqage_<timestamp>/qodeyard. Ifsqrapyard/tasq.mdexists, itโs copied to become the initial tasq for the first cycle. - Copies configuration files into the new run directory.
- Constructs the
docker runormsb runcommand, mounting theqage_<timestamp>directory and passing the necessary environment variables.
- Parses the
qrane.py(Inside the Container):- The orchestrator starts.
- API Key Validation: It reads
config.yamlto identify all unique AI providers being used for the current run. It then checks that the corresponding environment variables (e.g.,OPENAI_API_KEY,DEEPSEEK_API_KEY) are set. If a required key for a configured provider is missing, it exits with a clear error message. - It determines the UI mode (TUI/headless) and enters the main
cyQleloop.
- The
cyQleLoop:- The
Qranedynamically loads the agent pipeline frompipeline_config.yaml. - It executes each agent in sequence.
- The
- The
CheQpoint:qrane.pyreads the finalreQap.mdof the cycle. . It pauses and prompts the user for input ([Q]ontinue,[T]weaQ,[X]Quit), unless in autonomous mode. The default behavior (autonomous vs. user-gated) is controlled by thecheqpointoption inconfig.yaml, and can be overridden by the--autoor--userflags.
- Loop Continuation:
- If approved, the
reQap.mdis promoted to become the task for the next cycle. - The cycle counter increments, and the loop repeats.
- If approved, the
- Exit: If the user quits, the loop breaks, the container exits, and the script finishes.
3. Cleanup Flow (./qonqrete.sh clean)
- User Input: User executes
./qonqrete.sh clean. qonqrete.sh:- Searches for
qage_*directories inworqspace/. - Prompts the user for confirmation.
- If confirmed, it executes
rm -rf worqspace/qage_*.
- Searches for
- Result: The
worqspaceis cleared of all previous run data.
Agent & Orchestrator Logic
This section details the operational logic for the QonQrete system.
Orchestrator Logic (qrane/qrane.py)
The Qrane is the heart of the system.
- Dynamic Pipeline Loading: On startup, the
Qranereads theworqspace/pipeline_config.yamlfile. It iterates through theagentslist defined in this file to build the execution pipeline for the cycle. - Generic Execution: For each agent in the pipeline, the orchestrator constructs the appropriate command-line arguments based on the
script,input, andoutputfields in the config. - Centralized Paths: It utilizes the
PathManagerclass to resolve all file and directory paths.
Default Agent Logic
The following describes the logic of the three default agents that constitute the standard QonQrete pipeline.
Core Abstraction: worqer/lib_ai.py
All agents utilize this central library to interact with AI models. It uses a hybrid approach:
- Official Python Libraries: Used for OpenAI, Google Gemini, and Anthropic. These libraries read their respective API keys (
OPENAI_API_KEY,GOOGLE_API_KEY,ANTHROPIC_API_KEY) directly from the environment. - Custom Provider: A custom, OpenAI-compatible provider located in
sqeleton/deepseek_provider.pyis used for DeepSeek. This method is more reliable and uses theDEEPSEEK_API_KEYfrom the environment. - CLI Wrapper: A wrapper around the
@qwen-code/qwen-codeCLI tool is used for Qwen models.
This provides a consistent and modular interface for all AI interactions.
1. instruQtor (The Planner)
- Purpose: To decompose a high-level task (
tasQ.md) into a series of small, actionable steps (briQ.mdfiles). - Logic: It reads the task, constructs a detailed prompt for the AI, invokes the AI via
lib_ai.py, and then parses the markdown response into individualbriQ.mdfiles. - Sensitivity: The level of detail in the breakdown can be controlled with the
QONQ_SENSITIVITYenvironment variable, which corresponds to 10 predefined levels (0-9). - Context-Aware: It reads the contents of the
qodeyardto provide the AI with the current state of the codebase.
2. construQtor (The Executor)
- Purpose: To execute the steps from the
briQ.mdfiles and generate code. - Logic: It iterates through the
briQfiles sequentially. For each, it builds a prompt that includes the stepโs instructions and the current state of theqodeyarddirectory. It then calls the AI to execute the step and writes the generated code to theqodeyard.
3. inspeQtor (The Reviewer)
- Purpose: To review the
construQtorโs work and provide feedback for the next cycle. - Logic: It gathers all generated code from the
qodeyard, constructs a prompt instructing the AI to act as a senior code reviewer, and saves the AIโs assessment and suggestions to areQap.mdfile.
Specialized Agents
The following agents can be added to the pipeline in pipeline_config.yaml to provide additional functionality.
1. qompressor (The Skeletonizer)
- Purpose: To create a low-token, high-context representation of the codebase.
- Logic: It mirrors the
qodeyarddirectory into a newbloq.ddirectory. During the mirroring process, it strips the implementation bodies from source code files, keeping only the architectural elements like class/function signatures, imports, and docstrings. This โskeletonโ provides the AI with the overall structure of the code at a fraction of the token cost. - Cost: Zero token cost. Itโs a local pre-processing step.
2. qontextor (The Symbol Mapper)
- Purpose: To generate a detailed, machine-readable map of the codebaseโs symbols and their relationships.
- Dual-Mode Logic:
- Local Mode (
provider: local): This is the default mode.qontextorperforms a deterministic analysis of Python files using a sophisticated stack of local tools. It extracts classes, functions, signatures, and purposes with high accuracy and speed, incurring zero token cost.- Python AST: Extracts the fundamental structure of the code.
- Docstrings & Verb Heuristics: Determines the purpose of functions and classes.
- Jedi: Provides type inference and cross-file understanding.
- PyCG: Generates a call graph for dependency analysis.
- Fast vs. Complex Mode: Can be configured in
worqspace/config.yamlto run in a'fast'(AST, Jedi, Heuristics) or'complex'(adds deep semantic analysis withsentence-transformers) mode.
- AI Mode (
provider: [ai_provider]): In this legacy mode, it uses the โskeletonizedโ output from theqompressorto analyze each file. It then uses an AI call to generate a YAML file for each source file, detailing its symbols (classes, functions, etc.), their signatures, their purpose, and their dependencies.
- Local Mode (
- Cost: Incurs AI token costs only when an AI provider is specified. Itโs best used for initial scans or when major architectural changes occur.
3. calqulator (The Cost Estimator)
- Purpose: To provide a token and cost estimate for the upcoming
construqtorcycle. - Logic: It analyzes the
briQ.mdfiles for the current cycle. Its calculation includes:- A base cost for the โskeletonizedโ project context from
bloq.d. - The cost of the instructions in each
briQ.mdfile. - A โdeep readโ cost for any specific files that are explicitly referenced within a
briQ.
- A base cost for the โskeletonizedโ project context from
- Output: It annotates each
briQ.mdfile with its estimated token count and cost, and prints a detailed report to the console. - Cost: Zero token cost. It performs local calculations.
Configuration
The behavior of the QonQrete system can be configured in the worqspace/ directory.
config.yaml:cheqpoint: A boolean that sets the default execution mode.true(the default) enables user-gatedcheqpoints.falsemakes the system autonomous by default. This can be overridden by the--userand--autocommand-line flags.auto_cycle_limit: The maximum number ofcyQles to run in autonomous mode.0means infinite.agents: The AI models to be used by each agent. You can also set the provider tolocalfor agents that do not use AI.
pipeline_config.yaml:microsandbox: Set totrueto make Microsandbox (msb) the default container runtime.agents: Defines the sequence of agents in the pipeline.
Getting Started
To get started with QonQrete, please see the QUICKSTART.md guide.
Terminology
For a complete list of the terminology used in the QonQrete system, please see the TERMINOLOGY.md file.