opalacoder 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. opalacoder-0.1.0/.github/workflows/publish.yml +38 -0
  2. opalacoder-0.1.0/.gitignore +8 -0
  3. opalacoder-0.1.0/AGENT.md +31 -0
  4. opalacoder-0.1.0/ALGS.md +47 -0
  5. opalacoder-0.1.0/ARCH_SUMMARY.md +76 -0
  6. opalacoder-0.1.0/CLAUDE.md +1 -0
  7. opalacoder-0.1.0/GEMINI.md +31 -0
  8. opalacoder-0.1.0/PKG-INFO +230 -0
  9. opalacoder-0.1.0/README.md +210 -0
  10. opalacoder-0.1.0/agents.yaml +78 -0
  11. opalacoder-0.1.0/analysis_results.md +41 -0
  12. opalacoder-0.1.0/main.py +5 -0
  13. opalacoder-0.1.0/opalacoder/__init__.py +2 -0
  14. opalacoder-0.1.0/opalacoder/agents.py +233 -0
  15. opalacoder-0.1.0/opalacoder/api_keys.py +75 -0
  16. opalacoder-0.1.0/opalacoder/cli.py +339 -0
  17. opalacoder-0.1.0/opalacoder/cli_commands.py +277 -0
  18. opalacoder-0.1.0/opalacoder/config.py +215 -0
  19. opalacoder-0.1.0/opalacoder/embeddings.py +85 -0
  20. opalacoder-0.1.0/opalacoder/i18n.py +249 -0
  21. opalacoder-0.1.0/opalacoder/orchestrator.py +381 -0
  22. opalacoder-0.1.0/opalacoder/planner.py +206 -0
  23. opalacoder-0.1.0/opalacoder/project.py +196 -0
  24. opalacoder-0.1.0/opalacoder/session.py +4 -0
  25. opalacoder-0.1.0/opalacoder/skills.py +184 -0
  26. opalacoder-0.1.0/opalacoder/structured.py +113 -0
  27. opalacoder-0.1.0/opalacoder/terminal.py +186 -0
  28. opalacoder-0.1.0/opalacoder/tools.py +351 -0
  29. opalacoder-0.1.0/opalacoder/vcs.py +254 -0
  30. opalacoder-0.1.0/pyproject.toml +41 -0
  31. opalacoder-0.1.0/rename_project.py +57 -0
  32. opalacoder-0.1.0/requirements.txt +6 -0
  33. opalacoder-0.1.0/scratch_tail.py +14 -0
  34. opalacoder-0.1.0/skills/generaldeveloper.md +52 -0
  35. opalacoder-0.1.0/skills/html_css_js.md +51 -0
  36. opalacoder-0.1.0/skills/opalacoder.md +37 -0
  37. opalacoder-0.1.0/skills/python_subprocess.md +11 -0
  38. opalacoder-0.1.0/skills/react_vite.md +6 -0
  39. opalacoder-0.1.0/test_complexity.py +13 -0
  40. opalacoder-0.1.0/tests/test_agent_config.py +101 -0
  41. opalacoder-0.1.0/tests/test_complexity_evaluator.py +23 -0
  42. opalacoder-0.1.0/tests/test_context_guard.py +177 -0
  43. opalacoder-0.1.0/tests/test_double_inference.py +21 -0
  44. opalacoder-0.1.0/tests/test_executor_context_extraction.py +119 -0
  45. opalacoder-0.1.0/tests/test_i18n_coverage.py +134 -0
  46. opalacoder-0.1.0/tests/test_intent_classifier.py +170 -0
  47. opalacoder-0.1.0/tests/test_new_features.py +262 -0
  48. opalacoder-0.1.0/tests/test_orchestrator_prompt.py +112 -0
  49. opalacoder-0.1.0/tests/test_pipeline_integration.py +225 -0
  50. opalacoder-0.1.0/tests/test_planner_flow.py +146 -0
  51. opalacoder-0.1.0/tests/test_project_dir_isolation.py +248 -0
  52. opalacoder-0.1.0/tests/test_project_store.py +191 -0
  53. opalacoder-0.1.0/tests/test_refinement_loop.py +256 -0
  54. opalacoder-0.1.0/tests/test_skills_loading.py +226 -0
@@ -0,0 +1,38 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*.*.*'
7
+ release:
8
+ types:
9
+ - published
10
+
11
+ jobs:
12
+ build-and-publish:
13
+ runs-on: ubuntu-latest
14
+
15
+ # These permissions are required for Trusted Publishing
16
+ permissions:
17
+ id-token: write
18
+ contents: read
19
+
20
+ steps:
21
+ - name: Checkout repository
22
+ uses: actions/checkout@v4
23
+
24
+ - name: Set up Python
25
+ uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.11"
28
+
29
+ - name: Install build dependencies
30
+ run: pip install --upgrade pip build
31
+
32
+ - name: Build sdist and wheel
33
+ run: python -m build
34
+
35
+ - name: Publish to PyPI
36
+ uses: pypa/gh-action-pypi-publish@release/v1
37
+ # To use Trusted Publishing, you need to configure your PyPI project
38
+ # to trust this GitHub repository and workflow.
@@ -0,0 +1,8 @@
1
+ *.env
2
+ .env
3
+ *.env*
4
+ .venv
5
+ *.venv
6
+ node_modules
7
+ plan.md
8
+
@@ -0,0 +1,31 @@
1
+ # Project Guide
2
+
3
+ ## Language
4
+
5
+ All code, comments, and documentation must be written in **English**.
6
+
7
+ ## Architecture
8
+
9
+ This project uses the **AgenticBlocks.IO** framework.
10
+ Before starting any task, read the library source and documentation at:
11
+ https://github.com/gilzamir/agenticblocks
12
+
13
+ Key things to understand from that repo:
14
+ - How blocks are structured and composed
15
+ - How agents communicate and dispatch events
16
+ - Naming conventions used throughout the framework
17
+
18
+ ## Project Context
19
+
20
+ Read `ARCH_SUMMARY.md` before making changes. It contains the current project status,
21
+ known issues, and decisions already made. Do not re-litigate what is documented there.
22
+
23
+ ## Build & Test Commands
24
+ Run tests on tests dir after you implement a new feature.
25
+
26
+
27
+ > Fill in your actual commands below — this is the highest-value section.
28
+
29
+ ```bash
30
+ python -m pytest
31
+ ```
@@ -0,0 +1,47 @@
1
+ # OpalaCoder Algorithms
2
+
3
+ This document describes the core algorithmic logic and decision flows adopted in OpalaCoder's architecture.
4
+
5
+ ## 1. Double Inference Complexity Algorithm and Dynamic Budgeting
6
+
7
+ OpalaCoder implements an innovative model known as **Two-Stage Predictive Budgeting** to ensure maximum financial and resolutive efficiency for LLM agents. The goal of this algorithm is to avoid wasting tokens from expensive models on initial planning if the task is trivial, but without compromising the execution if the detailed plan reveals architectural complexities.
8
+
9
+ The execution is controlled by the `complexity_inference_mode` configuration located in `agents.yaml`, operating in either `simple` or `double` modes.
10
+
11
+ ### Logic Flow (`double` mode)
12
+
13
+ The algorithm follows these procedural steps:
14
+
15
+ 1. **First Stage: Pre-Plan Heuristic Inference (Strategy 1)**
16
+ - The user submits a prompt with their original request.
17
+ - The `make_complexity_evaluator` receives this raw request and returns one of two complexity labels: `"default"` or `"alternative"`.
18
+ - Based on this label, OpalaCoder chooses the base model that will generate the "Landscape" (Phase 1) and conduct the interactive Refinement (Phase 2).
19
+ - *Purpose:* Ensure that the initial cognitive capacity of the planner is equivalent to the presumed complexity by the user, saving excessive processing on short and simple requests.
20
+
21
+ 2. **Plan Refinement Loop**
22
+ - The plan goes through interactive cycles of human approval. The final outcome of this step is the `approved_plan` text.
23
+
24
+ 3. **Second Stage: Post-Plan JSON Evaluation (Strategy 3)**
25
+ - Instead of jumping straight to execution (as competing agents would do), OpalaCoder intercepts the pipeline before the orchestrator initializes.
26
+ - The `make_post_plan_evaluator` reads the final `approved_plan` line by line.
27
+ - The expected output from this agent is a strict JSON format:
28
+ ```json
29
+ {
30
+ "model": "default | alternative",
31
+ "estimated_steps": <integer>
32
+ }
33
+ ```
34
+ - *Execution Promotion Analysis (`model`)*: The algorithm compares the orchestrator's current model with the JSON prediction. If the JSON concludes that the architecture outlined in the plan is more complex than it seemed in the prompt (requiring `"alternative"`) and the orchestrator was set to `"default"`, the algorithm **upgrades (promotes)** the orchestrator to the alternative model *in-flight*, guaranteeing deep reasoning power for the most critical stage.
35
+ - *Budget Calculation (`max_heartbeats == "auto"`)*: If the orchestration config dictates static heartbeats, nothing changes. However, if it is set to `"auto"`, the ceiling calculation takes effect:
36
+ ```python
37
+ max_hb_config = min(estimated_steps * 3 + 5, 200)
38
+ ```
39
+ The estimated number of steps (e.g., read_file, write_file, run_command) semantically extracted by the LLM is multiplied by a safety margin (3) plus a fixed delta (5), always capped by the maximum logical limit (200), preventing infinite hallucination loops.
40
+
41
+ 4. **Execution**
42
+ - The `AutonomousOrchestratorStrategy` inherits the readjusted `model` and the organically calculated `max_heartbeats`, and triggers the MemGPT instances.
43
+
44
+ ### Fallback Mode (`simple` mode)
45
+ If the configuration is set to `simple` or if the JSON Extraction of the *Post-Plan Evaluator* fails due to formatting hallucination:
46
+ - In-flight model promotion is ignored.
47
+ - If heartbeats are set to `"auto"`, a static contingency ceiling of `max_hb_config = 50` is applied.
@@ -0,0 +1,76 @@
1
+ # OpalaCoder — Architecture Summary
2
+
3
+ ## Focus
4
+
5
+ OpalaCoder is designed to work with **small language models** (e.g. Mistral-Nemo, Llama 3 8B via Ollama) as its primary target. Large models (Gemini, GPT-4, Claude) are supported as a fallback for complex tasks, but the core design prioritizes correctness and usability under constrained context windows and limited reasoning capacity.
6
+
7
+ ## Core Idea: Project-Centric Context Management
8
+
9
+ The central abstraction is the **project**, not the session. Every interaction happens within a named project that has a fixed filesystem path. This design decision exists for one reason: **context management**.
10
+
11
+ Small models degrade quickly when context is large, mixed, or unbounded. By anchoring all activity to a project, OpalaCoder can:
12
+
13
+ - Inject a stable, minimal project header (`[PROJECT: name | PATH: /path]`) into every prompt instead of growing conversation state
14
+ - Load only the skills relevant to that project type (selected at creation, not dynamically per-request)
15
+ - Scope all file reads, writes, and commands to the project directory, eliminating ambiguity about where things should go
16
+ - Persist history, plan state, and skill configuration per project in SQLite, keeping each LLM call focused
17
+
18
+ ## Architecture
19
+
20
+ ```
21
+ CLI (cli.py)
22
+ ├── startup_menu() — load or create project
23
+ ├── _create_project() — name + path + description → LLM selects skills
24
+ └── repl_loop() — main REPL; loads project-scoped skills once
25
+ ├── Intent classifier — routes input to: plan | chat | question | greetings
26
+ ├── run_pipeline() — triggers orchestration for planning tasks
27
+ │ ├── AutonomousOrchestratorStrategy (capable models)
28
+ │ │ ├── generate_panorama() phase 1: high-level plan
29
+ │ │ ├── refine_plan() phase 2: user refinement loop
30
+ │ │ └── MemGPT agent loop autonomous execution with tools
31
+ │ └── DeterministicOrchestratorStrategy (small models)
32
+ │ ├── generate_panorama() phase 1
33
+ │ ├── refine_plan() phase 2
34
+ │ ├── decompose_plan() phase 3: subplan decomposition
35
+ │ ├── execute_subplans() phase 4: WorkflowGraph execution
36
+ │ └── aggregate_results() phase 5: final summary
37
+ └── chat_agent — MemGPT agent for Q&A and conversation
38
+
39
+ Project (project.py)
40
+ ├── ProjectData — name, path, skills, description, history, plan state
41
+ └── ProjectStore — SQLite CRUD for projects and message history
42
+
43
+ Skills (skills.py)
44
+ ├── load_project_skills() — loads only skills listed in the project
45
+ ├── select_skills_for_project() — LLM picks skills from description at creation
46
+ ├── find_skill_file() — resolves <name>.md across skill search dirs
47
+ └── get_relevant_skills_llm() — semantic router (uses project skills only)
48
+
49
+ Tools (tools.py) — file read/write, run_command, search_code, ask_human
50
+ └── PROJECT_PATH global — all tools resolve paths relative to the project dir
51
+
52
+ Skill search order:
53
+ 1. {project_path}/skills/ (project-local, highest priority)
54
+ 2. {repo_root}/skills/ (OpalaCoder built-in skills)
55
+ 3. ~/.opalacoder/skills/ (user global skills)
56
+ ```
57
+
58
+ ## Key Decisions
59
+
60
+ | Decision | Reason |
61
+ |---|---|
62
+ | Project replaces session as primary abstraction | Stable context anchor; avoids unbounded session drift |
63
+ | Skills fixed at project creation | Prevents irrelevant skill injection; reduces prompt size for small models |
64
+ | `/addskill` command | Lets users extend skills without restarting or recreating the project |
65
+ | `opalacoder` skill always loaded | Core behavioral instructions must always be present |
66
+ | Two orchestrator strategies | Small models cannot reliably drive autonomous tool loops; deterministic DAG is more reliable for them |
67
+ | All tools use `PROJECT_PATH` as `cwd` | Eliminates path ambiguity; agent does not need to reason about absolute paths |
68
+ | SQLite persistence | Lightweight, zero-dependency, suitable for local-first tooling |
69
+
70
+ ## Skill Scopes
71
+
72
+ Skills carry a `scope` frontmatter field that controls where they are injected:
73
+
74
+ - `all` — injected into both the intent classifier and the orchestrator
75
+ - `orchestrator` — injected only into the planner/executor (behavioral instructions)
76
+ - `classifier` — injected only into the intent classifier
@@ -0,0 +1 @@
1
+ LOAD the file AGENT.md.
@@ -0,0 +1,31 @@
1
+ # Project Guide
2
+
3
+ ## Language
4
+
5
+ All code, comments, and documentation must be written in **English**.
6
+
7
+ ## Architecture
8
+
9
+ This project uses the **AgenticBlocks.IO** framework.
10
+ Before starting any task, read the library source and documentation at:
11
+ https://github.com/gilzamir/agenticblocks
12
+
13
+ Key things to understand from that repo:
14
+ - How blocks are structured and composed
15
+ - How agents communicate and dispatch events
16
+ - Naming conventions used throughout the framework
17
+
18
+ ## Project Context
19
+
20
+ Read `ARCH_SUMMARY.md` before making changes. It contains the current project status,
21
+ known issues, and decisions already made. Do not re-litigate what is documented there.
22
+
23
+ ## Build & Test Commands
24
+ Run tests on tests dir after you implement a new feature.
25
+
26
+
27
+ > Fill in your actual commands below — this is the highest-value section.
28
+
29
+ ```bash
30
+ python -m pytest
31
+ ```
@@ -0,0 +1,230 @@
1
+ Metadata-Version: 2.4
2
+ Name: opalacoder
3
+ Version: 0.1.0
4
+ Summary: Autonomous coding agent with interactive planning and modular execution
5
+ Project-URL: Homepage, https://github.com/gilzamir/OpalaCoder
6
+ Project-URL: Bug Tracker, https://github.com/gilzamir/OpalaCoder/issues
7
+ Author-email: Gil Zamir <gilzamir@example.com>
8
+ License: MIT
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: agenticblocks-io
14
+ Requires-Dist: instructor>=1.15.1
15
+ Requires-Dist: numpy>=1.21.0
16
+ Requires-Dist: python-dotenv>=1.0.0
17
+ Requires-Dist: pyyaml>=6.0
18
+ Requires-Dist: rich>=13.0.0
19
+ Description-Content-Type: text/markdown
20
+
21
+ # OpalaCoder
22
+
23
+ **OpalaCoder** is an autonomous coding agent with interactive planning, modular execution, and persistent project memory. It is designed to work well with small and less autonomous models while maintaining the feel of a fully autonomous agent. It is built using the **AgenticBlocks.IO** framework.
24
+
25
+ ---
26
+
27
+ ## Features
28
+
29
+ ### Project-Centric Context Management
30
+ OpalaCoder centers around **projects** rather than transient chat sessions. Every interaction happens within a named project with a fixed filesystem path. This anchors the LLM context, loads only project-relevant skills, scopes all file and terminal operations, and persists history effectively for both small local models and large hosted APIs.
31
+
32
+ ### Advanced Semantic Router (Chain of Thought)
33
+ Uses an LLM for semantic routing with internal reasoning (Chain of Thought). It translates user demands to English internally, correctly deduces the intent, and seamlessly routes execution even for multilingual commands, injecting only the necessary context from specific **Skills** (`skills/*.md`).
34
+
35
+ ### Dynamic Model Selection (Double Inference Architecture)
36
+ OpalaCoder dynamically evaluates task complexity. For trivial tasks, it uses a fast default model (e.g., `ollama/mistral-nemo`). If the task requires architectural refactoring or advanced complex logic, it automatically falls back to a more powerful alternative model configured via API keys.
37
+
38
+ ### Interactive Planning
39
+ The agent receives a natural language demand, generates a high-level landscape plan, and enters a refinement loop with the user until the plan is approved. The approved plan is then automatically decomposed into executable sub-steps (subplans).
40
+
41
+ ### Execution with Retry & Strategy Routing
42
+ OpalaCoder delegates orchestration to specialized strategies. Small models use a deterministic execution pipeline (DAG), while capable models can use a fully autonomous agent loop. If a sub-step fails, the agent retries (up to a configurable limit) by injecting the previous error into the context for self-correction.
43
+
44
+ ### Execution Modes
45
+
46
+ | Mode | Behavior |
47
+ |--------|---------------|
48
+ | `plan` | Generates a plan and asks for user approval before executing (default) |
49
+ | `auto` | Executes everything without interruptions — ideal for automated pipelines |
50
+ | `edit` | Requests user confirmation only for sensitive operations (file creation/deletion, network calls, etc.) |
51
+
52
+ ### Persistent Projects and CLI Commands
53
+ Each execution belongs to a named project with continuous memory. During the chat with OpalaCoder, you can interact with the state manager using native commands:
54
+ - `/help` or `/h`: Shows available commands.
55
+ - `/clear`: Clears the memory and history of the current project.
56
+ - `/rename <new_name>`: Renames the active project.
57
+ - `/list`: Lists all projects saved in SQLite.
58
+ - `/load <name>` and `/delete <name>`: Loads or deletes old projects. (Deleting also asks to delete the project directory).
59
+ - `/skills`: Lists available skills and highlights the active ones for the project.
60
+ - `/addskill <name>` and `/rmskill <name>`: Adds or removes specific skills for the current project.
61
+ - `/undo`: Reverts the last change made by the agent via internal shadow VCS.
62
+ - `/commit <msg>`: Forces a commit to the local shadow git control.
63
+ - `/exit` or `/quit`: Exits the application.
64
+
65
+ ### Shadow Git (VCS)
66
+ Every project comes with an isolated "Shadow Git" (`.opalacoder/.git`) that automatically checkpoints the codebase before and after execution. This allows for safe iteration without muddying the user's main git repository, and enables the `/undo` command.
67
+
68
+ ### Elegant Terminal
69
+ Formatted output with [Rich](https://github.com/Texel-io/rich): banners, progress spinners, plan panels, per-subplan status tables, and highlighted error reports.
70
+
71
+ ### Modular Architecture
72
+ The code is divided into independent, easy-to-debug modules:
73
+
74
+ ```text
75
+ opalacoder/
76
+ ├── config.py Global settings (model, retries, mode, db, VCS)
77
+ ├── terminal.py Rich output (banners, spinners, panels, tables)
78
+ ├── project.py SQLite project management and state
79
+ ├── vcs.py Internal shadow Git strategies (auto, hybrid, agent-driven)
80
+ ├── agents.py LLM agent factories
81
+ ├── planner.py Pipeline: panorama → refinement → decomposition
82
+ ├── orchestrator.py Strategy-based execution (deterministic vs autonomous)
83
+ └── cli.py Argparse + project bootstrap + REPL
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Requirements
89
+
90
+ - Python 3.11+
91
+ - [agenticblocks](https://github.com/gilzamir/agenticblocks) installed in the virtual environment
92
+ - [Rich](https://github.com/Texel-io/rich): `pip install rich`
93
+ - An accessible LLM server (e.g., [Ollama](https://ollama.com) with `mistral-nemo`, or any model supported by [litellm](https://docs.litellm.ai))
94
+
95
+ ---
96
+
97
+ ## Installation
98
+
99
+ ```bash
100
+ # Clone the repository
101
+ git clone <repository-url>
102
+ cd OpalaCoder
103
+
104
+ # Create and activate the virtual environment
105
+ python -m venv .env
106
+ source .env/bin/activate # Linux/macOS
107
+ # .env\Scripts\activate # Windows
108
+
109
+ # Install the dependencies
110
+ pip install -r requirements.txt
111
+ ```
112
+
113
+ ### Environment Variables (Optional)
114
+
115
+ Create a `.env` file in the project root to override defaults:
116
+
117
+ ```env
118
+ # Default LLM model (any litellm supported string)
119
+ OPALA_MODEL=ollama/mistral-nemo
120
+ ```
121
+
122
+ ---
123
+
124
+ ## How to Run
125
+
126
+ ```bash
127
+ # Activate the virtual environment
128
+ source .env/bin/activate
129
+
130
+ # Default execution (plan mode)
131
+ python main.py
132
+
133
+ # Choose execution mode
134
+ python main.py --mode auto
135
+ python main.py --mode plan
136
+ python main.py --mode edit
137
+
138
+ # Use another model
139
+ python main.py --model ollama/llama3
140
+
141
+ # Custom database path
142
+ python main.py --db /path/to/projects.db
143
+
144
+ # Show version
145
+ python main.py --version
146
+
147
+ # Help
148
+ python main.py --help
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Project Flow
154
+
155
+ ```text
156
+ 1. Banner + Mode Selection
157
+
158
+ 2. Project Configuration
159
+ ├── New Project → Name, Path, Description -> LLM selects skills
160
+ └── Existing → Load context and skills
161
+
162
+ 3. User enters demand
163
+
164
+ 4. Agent generates landscape (high-level plan)
165
+
166
+ 5. Refinement loop (plan/edit modes)
167
+ ├── User approves → proceeds
168
+ └── User suggests changes → agent refines and loops back to step 5
169
+
170
+ 6. Decomposition into subplans (SP-1, SP-2, …)
171
+
172
+ 7. Sequential execution by dependency
173
+ └── For each subplan:
174
+ ├── Pre-run VCS checkpoint
175
+ ├── Executes generated code (AgenticBlocks WorkflowGraph)
176
+ ├── Success → Next subplan
177
+ └── Failure → Retry up to max_retries, then report error
178
+ ├── Post-run VCS checkpoint
179
+
180
+ 8. Aggregation: Final synthesized result of the operation
181
+
182
+ 9. Result displayed + project saved
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Advanced Configuration
188
+
189
+ ### Build & Test Commands
190
+ Run tests in the `tests` directory after implementing a new feature:
191
+
192
+ ```bash
193
+ python -m pytest
194
+ ```
195
+
196
+ ### Change the Default Model
197
+
198
+ Edit `opalacoder/config.py`:
199
+
200
+ ```python
201
+ DEFAULT_MODEL = "ollama/mistral-nemo" # change here
202
+ ```
203
+
204
+ Or use the environment variable `OPALA_MODEL`.
205
+
206
+ ### Sensitive Operations
207
+
208
+ In `opalacoder/config.py`:
209
+
210
+ ```python
211
+ SENSITIVE_OPS = {
212
+ "write_file", "delete_file", "run_shell",
213
+ "send_network_request", "create_user", "delete_user",
214
+ # add keywords here for operations that require confirmation in edit mode
215
+ }
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Security
221
+
222
+ - The `edit` mode requires explicit confirmation for operations affecting the filesystem, network, or user accounts.
223
+ - Generated code is executed locally. For greater isolation, the `CodePlanExecutorBlock` from the AgenticBlocks library supports execution in a Docker container — edit `make_executor_block` in `opalacoder/agents.py` changing `execution_mode="local"` to `execution_mode="docker"`.
224
+ - Never run the agent in `auto` mode with access to production systems without reviewing the generated subplans.
225
+
226
+ ---
227
+
228
+ ## License
229
+
230
+ MIT
@@ -0,0 +1,210 @@
1
+ # OpalaCoder
2
+
3
+ **OpalaCoder** is an autonomous coding agent with interactive planning, modular execution, and persistent project memory. It is designed to work well with small and less autonomous models while maintaining the feel of a fully autonomous agent. It is built using the **AgenticBlocks.IO** framework.
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ ### Project-Centric Context Management
10
+ OpalaCoder centers around **projects** rather than transient chat sessions. Every interaction happens within a named project with a fixed filesystem path. This anchors the LLM context, loads only project-relevant skills, scopes all file and terminal operations, and persists history effectively for both small local models and large hosted APIs.
11
+
12
+ ### Advanced Semantic Router (Chain of Thought)
13
+ Uses an LLM for semantic routing with internal reasoning (Chain of Thought). It translates user demands to English internally, correctly deduces the intent, and seamlessly routes execution even for multilingual commands, injecting only the necessary context from specific **Skills** (`skills/*.md`).
14
+
15
+ ### Dynamic Model Selection (Double Inference Architecture)
16
+ OpalaCoder dynamically evaluates task complexity. For trivial tasks, it uses a fast default model (e.g., `ollama/mistral-nemo`). If the task requires architectural refactoring or advanced complex logic, it automatically falls back to a more powerful alternative model configured via API keys.
17
+
18
+ ### Interactive Planning
19
+ The agent receives a natural language demand, generates a high-level landscape plan, and enters a refinement loop with the user until the plan is approved. The approved plan is then automatically decomposed into executable sub-steps (subplans).
20
+
21
+ ### Execution with Retry & Strategy Routing
22
+ OpalaCoder delegates orchestration to specialized strategies. Small models use a deterministic execution pipeline (DAG), while capable models can use a fully autonomous agent loop. If a sub-step fails, the agent retries (up to a configurable limit) by injecting the previous error into the context for self-correction.
23
+
24
+ ### Execution Modes
25
+
26
+ | Mode | Behavior |
27
+ |--------|---------------|
28
+ | `plan` | Generates a plan and asks for user approval before executing (default) |
29
+ | `auto` | Executes everything without interruptions — ideal for automated pipelines |
30
+ | `edit` | Requests user confirmation only for sensitive operations (file creation/deletion, network calls, etc.) |
31
+
32
+ ### Persistent Projects and CLI Commands
33
+ Each execution belongs to a named project with continuous memory. During the chat with OpalaCoder, you can interact with the state manager using native commands:
34
+ - `/help` or `/h`: Shows available commands.
35
+ - `/clear`: Clears the memory and history of the current project.
36
+ - `/rename <new_name>`: Renames the active project.
37
+ - `/list`: Lists all projects saved in SQLite.
38
+ - `/load <name>` and `/delete <name>`: Loads or deletes old projects. (Deleting also asks to delete the project directory).
39
+ - `/skills`: Lists available skills and highlights the active ones for the project.
40
+ - `/addskill <name>` and `/rmskill <name>`: Adds or removes specific skills for the current project.
41
+ - `/undo`: Reverts the last change made by the agent via internal shadow VCS.
42
+ - `/commit <msg>`: Forces a commit to the local shadow git control.
43
+ - `/exit` or `/quit`: Exits the application.
44
+
45
+ ### Shadow Git (VCS)
46
+ Every project comes with an isolated "Shadow Git" (`.opalacoder/.git`) that automatically checkpoints the codebase before and after execution. This allows for safe iteration without muddying the user's main git repository, and enables the `/undo` command.
47
+
48
+ ### Elegant Terminal
49
+ Formatted output with [Rich](https://github.com/Texel-io/rich): banners, progress spinners, plan panels, per-subplan status tables, and highlighted error reports.
50
+
51
+ ### Modular Architecture
52
+ The code is divided into independent, easy-to-debug modules:
53
+
54
+ ```text
55
+ opalacoder/
56
+ ├── config.py Global settings (model, retries, mode, db, VCS)
57
+ ├── terminal.py Rich output (banners, spinners, panels, tables)
58
+ ├── project.py SQLite project management and state
59
+ ├── vcs.py Internal shadow Git strategies (auto, hybrid, agent-driven)
60
+ ├── agents.py LLM agent factories
61
+ ├── planner.py Pipeline: panorama → refinement → decomposition
62
+ ├── orchestrator.py Strategy-based execution (deterministic vs autonomous)
63
+ └── cli.py Argparse + project bootstrap + REPL
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Requirements
69
+
70
+ - Python 3.11+
71
+ - [agenticblocks](https://github.com/gilzamir/agenticblocks) installed in the virtual environment
72
+ - [Rich](https://github.com/Texel-io/rich): `pip install rich`
73
+ - An accessible LLM server (e.g., [Ollama](https://ollama.com) with `mistral-nemo`, or any model supported by [litellm](https://docs.litellm.ai))
74
+
75
+ ---
76
+
77
+ ## Installation
78
+
79
+ ```bash
80
+ # Clone the repository
81
+ git clone <repository-url>
82
+ cd OpalaCoder
83
+
84
+ # Create and activate the virtual environment
85
+ python -m venv .env
86
+ source .env/bin/activate # Linux/macOS
87
+ # .env\Scripts\activate # Windows
88
+
89
+ # Install the dependencies
90
+ pip install -r requirements.txt
91
+ ```
92
+
93
+ ### Environment Variables (Optional)
94
+
95
+ Create a `.env` file in the project root to override defaults:
96
+
97
+ ```env
98
+ # Default LLM model (any litellm supported string)
99
+ OPALA_MODEL=ollama/mistral-nemo
100
+ ```
101
+
102
+ ---
103
+
104
+ ## How to Run
105
+
106
+ ```bash
107
+ # Activate the virtual environment
108
+ source .env/bin/activate
109
+
110
+ # Default execution (plan mode)
111
+ python main.py
112
+
113
+ # Choose execution mode
114
+ python main.py --mode auto
115
+ python main.py --mode plan
116
+ python main.py --mode edit
117
+
118
+ # Use another model
119
+ python main.py --model ollama/llama3
120
+
121
+ # Custom database path
122
+ python main.py --db /path/to/projects.db
123
+
124
+ # Show version
125
+ python main.py --version
126
+
127
+ # Help
128
+ python main.py --help
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Project Flow
134
+
135
+ ```text
136
+ 1. Banner + Mode Selection
137
+
138
+ 2. Project Configuration
139
+ ├── New Project → Name, Path, Description -> LLM selects skills
140
+ └── Existing → Load context and skills
141
+
142
+ 3. User enters demand
143
+
144
+ 4. Agent generates landscape (high-level plan)
145
+
146
+ 5. Refinement loop (plan/edit modes)
147
+ ├── User approves → proceeds
148
+ └── User suggests changes → agent refines and loops back to step 5
149
+
150
+ 6. Decomposition into subplans (SP-1, SP-2, …)
151
+
152
+ 7. Sequential execution by dependency
153
+ └── For each subplan:
154
+ ├── Pre-run VCS checkpoint
155
+ ├── Executes generated code (AgenticBlocks WorkflowGraph)
156
+ ├── Success → Next subplan
157
+ └── Failure → Retry up to max_retries, then report error
158
+ ├── Post-run VCS checkpoint
159
+
160
+ 8. Aggregation: Final synthesized result of the operation
161
+
162
+ 9. Result displayed + project saved
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Advanced Configuration
168
+
169
+ ### Build & Test Commands
170
+ Run tests in the `tests` directory after implementing a new feature:
171
+
172
+ ```bash
173
+ python -m pytest
174
+ ```
175
+
176
+ ### Change the Default Model
177
+
178
+ Edit `opalacoder/config.py`:
179
+
180
+ ```python
181
+ DEFAULT_MODEL = "ollama/mistral-nemo" # change here
182
+ ```
183
+
184
+ Or use the environment variable `OPALA_MODEL`.
185
+
186
+ ### Sensitive Operations
187
+
188
+ In `opalacoder/config.py`:
189
+
190
+ ```python
191
+ SENSITIVE_OPS = {
192
+ "write_file", "delete_file", "run_shell",
193
+ "send_network_request", "create_user", "delete_user",
194
+ # add keywords here for operations that require confirmation in edit mode
195
+ }
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Security
201
+
202
+ - The `edit` mode requires explicit confirmation for operations affecting the filesystem, network, or user accounts.
203
+ - Generated code is executed locally. For greater isolation, the `CodePlanExecutorBlock` from the AgenticBlocks library supports execution in a Docker container — edit `make_executor_block` in `opalacoder/agents.py` changing `execution_mode="local"` to `execution_mode="docker"`.
204
+ - Never run the agent in `auto` mode with access to production systems without reviewing the generated subplans.
205
+
206
+ ---
207
+
208
+ ## License
209
+
210
+ MIT