localforge 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 (52) hide show
  1. localforge-0.1.0/.github/workflows/ci.yml +62 -0
  2. localforge-0.1.0/.localforge/commands.yml +49 -0
  3. localforge-0.1.0/.localforge/config.yml +75 -0
  4. localforge-0.1.0/.localforge/rules.md +44 -0
  5. localforge-0.1.0/CONTRIBUTING.md +123 -0
  6. localforge-0.1.0/LICENSE +21 -0
  7. localforge-0.1.0/PKG-INFO +478 -0
  8. localforge-0.1.0/README.md +444 -0
  9. localforge-0.1.0/TEST_REPORT.md +217 -0
  10. localforge-0.1.0/localforge/__init__.py +3 -0
  11. localforge-0.1.0/localforge/__main__.py +4 -0
  12. localforge-0.1.0/localforge/agent/__init__.py +27 -0
  13. localforge-0.1.0/localforge/agent/agents.py +256 -0
  14. localforge-0.1.0/localforge/agent/base.py +136 -0
  15. localforge-0.1.0/localforge/agent/display.py +119 -0
  16. localforge-0.1.0/localforge/agent/orchestrator.py +420 -0
  17. localforge-0.1.0/localforge/agent/state_manager.py +30 -0
  18. localforge-0.1.0/localforge/cli/__init__.py +5 -0
  19. localforge-0.1.0/localforge/cli/display.py +240 -0
  20. localforge-0.1.0/localforge/cli/main.py +837 -0
  21. localforge-0.1.0/localforge/context_manager/__init__.py +6 -0
  22. localforge-0.1.0/localforge/context_manager/assembler.py +285 -0
  23. localforge-0.1.0/localforge/context_manager/budget.py +186 -0
  24. localforge-0.1.0/localforge/core/__init__.py +86 -0
  25. localforge-0.1.0/localforge/core/config.py +139 -0
  26. localforge-0.1.0/localforge/core/models.py +204 -0
  27. localforge-0.1.0/localforge/core/ollama_client.py +214 -0
  28. localforge-0.1.0/localforge/core/prompt_templates.py +398 -0
  29. localforge-0.1.0/localforge/index/__init__.py +6 -0
  30. localforge-0.1.0/localforge/index/indexer.py +660 -0
  31. localforge-0.1.0/localforge/index/search.py +373 -0
  32. localforge-0.1.0/localforge/patching/__init__.py +6 -0
  33. localforge-0.1.0/localforge/patching/patcher.py +233 -0
  34. localforge-0.1.0/localforge/patching/validator.py +99 -0
  35. localforge-0.1.0/localforge/retrieval/__init__.py +5 -0
  36. localforge-0.1.0/localforge/retrieval/ranking.py +160 -0
  37. localforge-0.1.0/localforge/retrieval/retriever.py +346 -0
  38. localforge-0.1.0/localforge/verifier/__init__.py +5 -0
  39. localforge-0.1.0/localforge/verifier/runner.py +322 -0
  40. localforge-0.1.0/pyproject.toml +69 -0
  41. localforge-0.1.0/test_output.txt +0 -0
  42. localforge-0.1.0/tests/__init__.py +0 -0
  43. localforge-0.1.0/tests/conftest.py +295 -0
  44. localforge-0.1.0/tests/test_agents.py +250 -0
  45. localforge-0.1.0/tests/test_e2e.py +184 -0
  46. localforge-0.1.0/tests/test_indexer.py +227 -0
  47. localforge-0.1.0/tests/test_ollama_client.py +161 -0
  48. localforge-0.1.0/tests/test_orchestrator.py +320 -0
  49. localforge-0.1.0/tests/test_patcher.py +326 -0
  50. localforge-0.1.0/tests/test_patching_smoke.py +167 -0
  51. localforge-0.1.0/tests/test_retrieval.py +200 -0
  52. localforge-0.1.0/tests/test_verifier_smoke.py +66 -0
@@ -0,0 +1,62 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ lint:
14
+ name: Lint (ruff)
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.11"
22
+
23
+ - name: Install dependencies
24
+ run: pip install -e ".[dev]"
25
+
26
+ - name: Run ruff
27
+ run: ruff check .
28
+
29
+ typecheck:
30
+ name: Type Check (mypy)
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+
35
+ - uses: actions/setup-python@v5
36
+ with:
37
+ python-version: "3.11"
38
+
39
+ - name: Install dependencies
40
+ run: pip install -e ".[dev]"
41
+
42
+ - name: Run mypy
43
+ run: mypy localforge/
44
+
45
+ test:
46
+ name: Tests (Python ${{ matrix.python-version }})
47
+ runs-on: ubuntu-latest
48
+ strategy:
49
+ matrix:
50
+ python-version: ["3.11", "3.12"]
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+
54
+ - uses: actions/setup-python@v5
55
+ with:
56
+ python-version: ${{ matrix.python-version }}
57
+
58
+ - name: Install dependencies
59
+ run: pip install -e ".[dev]"
60
+
61
+ - name: Run pytest
62
+ run: pytest -v --tb=short
@@ -0,0 +1,49 @@
1
+ # =============================================================================
2
+ # LocalForge Custom Verification Commands
3
+ # =============================================================================
4
+ # Define additional commands that LocalForge will run during the verification
5
+ # phase. These are run AFTER the auto-detected commands (syntax check, ruff,
6
+ # mypy, pytest).
7
+ #
8
+ # Each command needs:
9
+ # name — A short identifier shown in output.
10
+ # cmd — The shell command to execute. Use {changed_files} as a placeholder
11
+ # for the list of files modified by the current patch.
12
+ # timeout — Maximum seconds before the command is killed (default: 60).
13
+ #
14
+ # LocalForge auto-detects and runs these by default if the tooling is present:
15
+ # - python -m py_compile (syntax check)
16
+ # - ruff check .
17
+ # - mypy --ignore-missing-imports
18
+ # - pytest --tb=short -q
19
+ # - npm test (if package.json present)
20
+ # - go test ./... (if go.mod present)
21
+ #
22
+ # Add your own below:
23
+ # =============================================================================
24
+
25
+ commands:
26
+ # Example: Run a custom linter
27
+ # - name: custom_lint
28
+ # cmd: "flake8 --max-line-length 100 ."
29
+ # timeout: 60
30
+
31
+ # Example: Run a specific test suite
32
+ # - name: integration_tests
33
+ # cmd: "pytest tests/integration/ -v --tb=short"
34
+ # timeout: 300
35
+
36
+ # Example: Check for security issues
37
+ # - name: security_scan
38
+ # cmd: "bandit -r src/ -ll"
39
+ # timeout: 120
40
+
41
+ # Example: Validate OpenAPI spec
42
+ # - name: openapi_validate
43
+ # cmd: "openapi-spec-validator api/openapi.yml"
44
+ # timeout: 30
45
+
46
+ # Example: Run only changed-file checks
47
+ # - name: changed_lint
48
+ # cmd: "ruff check {changed_files}"
49
+ # timeout: 60
@@ -0,0 +1,75 @@
1
+ # =============================================================================
2
+ # LocalForge Configuration
3
+ # =============================================================================
4
+ # This file controls how LocalForge behaves in this repository.
5
+ # All fields are optional — defaults are shown below.
6
+ #
7
+ # Values can also be set via environment variables with the LOCALFORGE_ prefix:
8
+ # LOCALFORGE_MODEL_NAME=codellama:13b
9
+ # LOCALFORGE_MAX_CONTEXT_TOKENS=8192
10
+ #
11
+ # Priority: env vars > this file > built-in defaults
12
+ # =============================================================================
13
+
14
+ # ---------------------------------------------------------------------------
15
+ # Model Settings
16
+ # ---------------------------------------------------------------------------
17
+
18
+ # Ollama model tag to use for all LLM calls.
19
+ # Run `ollama list` to see available models on your machine.
20
+ model_name: "qwen2.5-coder:7b"
21
+
22
+ # Base URL of the Ollama HTTP API.
23
+ # Change this if Ollama is running on a different host or port.
24
+ ollama_base_url: "http://localhost:11434"
25
+
26
+ # Model size profile. Controls context window, retrieval limits, and chunk size.
27
+ # Options: small, medium, large
28
+ #
29
+ # small — 4K context, 5 chunks, fast iteration (7B models)
30
+ # medium — 8K context, 10 chunks, balanced (13-16B models)
31
+ # large — 32K context, 20 chunks, best quality (32B+ models)
32
+ model_profile: "small"
33
+
34
+ # ---------------------------------------------------------------------------
35
+ # Context & Token Budget
36
+ # ---------------------------------------------------------------------------
37
+
38
+ # Maximum number of tokens to include in the LLM context window.
39
+ # Set this to match your model's actual context size for best results.
40
+ # The context assembler will truncate and prioritize to fit within this budget.
41
+ max_context_tokens: 4096
42
+
43
+ # ---------------------------------------------------------------------------
44
+ # Agent Behavior
45
+ # ---------------------------------------------------------------------------
46
+
47
+ # Maximum number of agent loop iterations before forced stop.
48
+ # This prevents runaway loops. Each plan step + retry counts as an iteration.
49
+ max_iterations: 50
50
+
51
+ # Automatically approve all proposed patches without user confirmation.
52
+ # Use with caution — recommended only for trusted, well-tested tasks.
53
+ auto_approve: false
54
+
55
+ # When true, show planned patches as diffs but do not write any files.
56
+ # Useful for previewing what the agent would do.
57
+ dry_run: false
58
+
59
+ # ---------------------------------------------------------------------------
60
+ # Paths
61
+ # ---------------------------------------------------------------------------
62
+
63
+ # Path to the repository root. Usually "." (current directory).
64
+ repo_path: "."
65
+
66
+ # Path to the SQLite index database (relative to repo root).
67
+ # The index stores file chunks, symbols, and metadata for fast retrieval.
68
+ index_db_path: ".localforge/index.db"
69
+
70
+ # ---------------------------------------------------------------------------
71
+ # Logging
72
+ # ---------------------------------------------------------------------------
73
+
74
+ # Logging verbosity. Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
75
+ log_level: "INFO"
@@ -0,0 +1,44 @@
1
+ # LocalForge Rules
2
+ #
3
+ # This file tells the agent about project-specific conventions and constraints.
4
+ # Everything here is included in the agent's context for every task, so keep it
5
+ # concise and actionable.
6
+
7
+ ## Coding Style
8
+
9
+ - Follow PEP 8 and use `ruff` for linting.
10
+ - Maximum line length: 100 characters.
11
+ - Use type hints on all public function signatures.
12
+ - Prefer `pathlib.Path` over `os.path`.
13
+ - Use f-strings for string formatting (no `.format()` or `%`).
14
+
15
+ ## Forbidden Patterns
16
+
17
+ - Do not use `print()` for logging — use the `logging` module.
18
+ - Do not use `import *` anywhere.
19
+ - Do not use mutable default arguments (e.g., `def f(x=[])`).
20
+ - Do not catch bare `except:` — always specify the exception type.
21
+ - Do not use `os.system()` or `subprocess.call()` with `shell=True` for
22
+ untrusted input.
23
+
24
+ ## Test Requirements
25
+
26
+ - Every new public function must have at least one corresponding test.
27
+ - Tests live in `tests/` and follow the naming convention `test_<module>.py`.
28
+ - Use `pytest` as the test runner.
29
+ - Use `pytest-asyncio` for async tests (mode: `auto`).
30
+ - Mock external dependencies (Ollama, filesystem) in unit tests.
31
+ - Tests must pass before any PR is merged.
32
+
33
+ ## File Naming
34
+
35
+ - Python modules: `snake_case.py`
36
+ - Test files: `test_<module_name>.py`
37
+ - Configuration files: lowercase with hyphens or underscores.
38
+ - No spaces or special characters in filenames.
39
+
40
+ ## Documentation
41
+
42
+ - Add docstrings to all public classes and functions.
43
+ - Use Google-style or NumPy-style docstrings consistently.
44
+ - Update the README when adding new CLI commands or config fields.
@@ -0,0 +1,123 @@
1
+ # Contributing to LocalForge
2
+
3
+ Thanks for your interest in contributing! LocalForge is an open-source project
4
+ and we welcome contributions of all kinds.
5
+
6
+ ## Getting Started
7
+
8
+ 1. **Fork & clone** the repository:
9
+
10
+ ```bash
11
+ git clone https://github.com/localforge/localforge.git
12
+ cd localforge
13
+ ```
14
+
15
+ 2. **Install in development mode** with dev dependencies:
16
+
17
+ ```bash
18
+ pip install -e ".[dev]"
19
+ ```
20
+
21
+ 3. **Verify** the setup:
22
+
23
+ ```bash
24
+ pytest
25
+ ruff check .
26
+ ```
27
+
28
+ ## Development Workflow
29
+
30
+ 1. Create a feature branch from `main`:
31
+
32
+ ```bash
33
+ git checkout -b feature/my-feature
34
+ ```
35
+
36
+ 2. Make your changes. Follow the existing code style (PEP 8, 100 char lines,
37
+ type hints on public APIs).
38
+
39
+ 3. Write or update tests for any changed functionality.
40
+
41
+ 4. Run the full check suite:
42
+
43
+ ```bash
44
+ # Lint
45
+ ruff check .
46
+
47
+ # Type check
48
+ mypy localforge/
49
+
50
+ # Tests
51
+ pytest -v
52
+ ```
53
+
54
+ 5. Commit with a clear, descriptive message:
55
+
56
+ ```bash
57
+ git commit -m "feat: add support for custom retrieval strategies"
58
+ ```
59
+
60
+ 6. Push and open a Pull Request against `main`.
61
+
62
+ ## Code Style
63
+
64
+ - **Formatter:** Black (line length 100).
65
+ - **Linter:** Ruff with the rule set defined in `pyproject.toml`.
66
+ - **Type checker:** mypy in strict mode.
67
+ - Python 3.11+ features are fine (use `from __future__ import annotations`).
68
+ - Use `pathlib.Path` over `os.path`.
69
+ - Use structured logging, not `print()`.
70
+
71
+ ## Project Structure
72
+
73
+ ```
74
+ localforge/
75
+ agent/ # Multi-agent system (orchestrator, specialist agents)
76
+ cli/ # Typer CLI commands and display helpers
77
+ context_manager/ # Token budget management and context assembly
78
+ core/ # Config, models, Ollama client, prompt templates
79
+ index/ # Repository indexing (SQLite) and search
80
+ patching/ # File patching with backup and validation
81
+ retrieval/ # Context retrieval and ranking
82
+ verifier/ # Verification runner (lint, test, type-check)
83
+ tests/ # All tests (pytest)
84
+ ```
85
+
86
+ ## Writing Tests
87
+
88
+ - Place tests in `tests/test_<module>.py`.
89
+ - Use `pytest` fixtures from `tests/conftest.py`.
90
+ - Mock external dependencies (Ollama API, filesystem writes) in unit tests.
91
+ - Use `pytest-asyncio` for async tests — the project uses `asyncio_mode = "auto"`.
92
+ - Aim for tests that run fast and don't require a running Ollama instance.
93
+
94
+ ## Commit Messages
95
+
96
+ Follow [Conventional Commits](https://www.conventionalcommits.org/):
97
+
98
+ - `feat:` — new feature
99
+ - `fix:` — bug fix
100
+ - `docs:` — documentation only
101
+ - `test:` — adding or updating tests
102
+ - `refactor:` — code change that neither fixes a bug nor adds a feature
103
+ - `chore:` — build process, CI, dependency updates
104
+
105
+ ## Pull Request Guidelines
106
+
107
+ - Keep PRs focused — one feature or fix per PR.
108
+ - Include a clear description of **what** changed and **why**.
109
+ - All CI checks (pytest, ruff, mypy) must pass.
110
+ - Add tests for new functionality.
111
+ - Update documentation if you add or change CLI commands or config fields.
112
+
113
+ ## Reporting Issues
114
+
115
+ - Use GitHub Issues.
116
+ - Include: Python version, OS, Ollama version, model used, and steps to
117
+ reproduce.
118
+ - Paste the full error traceback if applicable.
119
+
120
+ ## License
121
+
122
+ By contributing, you agree that your contributions will be licensed under the
123
+ MIT License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 localforge contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.