nexcoder 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.
- nexcoder-0.1.0/.github/workflows/ci.yml +43 -0
- nexcoder-0.1.0/.github/workflows/publish.yml +33 -0
- nexcoder-0.1.0/.gitignore +43 -0
- nexcoder-0.1.0/CHANGELOG.md +24 -0
- nexcoder-0.1.0/CLAUDE.md +268 -0
- nexcoder-0.1.0/LICENSE +21 -0
- nexcoder-0.1.0/PKG-INFO +170 -0
- nexcoder-0.1.0/README.md +136 -0
- nexcoder-0.1.0/pyproject.toml +99 -0
- nexcoder-0.1.0/src/nex/__init__.py +6 -0
- nexcoder-0.1.0/src/nex/agent.py +623 -0
- nexcoder-0.1.0/src/nex/api_client.py +194 -0
- nexcoder-0.1.0/src/nex/cli.py +506 -0
- nexcoder-0.1.0/src/nex/config.py +168 -0
- nexcoder-0.1.0/src/nex/context.py +252 -0
- nexcoder-0.1.0/src/nex/exceptions.py +39 -0
- nexcoder-0.1.0/src/nex/indexer/__init__.py +16 -0
- nexcoder-0.1.0/src/nex/indexer/index.py +332 -0
- nexcoder-0.1.0/src/nex/indexer/parser.py +352 -0
- nexcoder-0.1.0/src/nex/indexer/scanner.py +191 -0
- nexcoder-0.1.0/src/nex/memory/__init__.py +15 -0
- nexcoder-0.1.0/src/nex/memory/decisions.py +131 -0
- nexcoder-0.1.0/src/nex/memory/errors.py +257 -0
- nexcoder-0.1.0/src/nex/memory/project.py +158 -0
- nexcoder-0.1.0/src/nex/planner.py +122 -0
- nexcoder-0.1.0/src/nex/py.typed +0 -0
- nexcoder-0.1.0/src/nex/reviewer.py +111 -0
- nexcoder-0.1.0/src/nex/safety.py +235 -0
- nexcoder-0.1.0/src/nex/test_runner.py +201 -0
- nexcoder-0.1.0/src/nex/tools/__init__.py +114 -0
- nexcoder-0.1.0/src/nex/tools/file_ops.py +89 -0
- nexcoder-0.1.0/src/nex/tools/git_ops.py +183 -0
- nexcoder-0.1.0/src/nex/tools/search.py +156 -0
- nexcoder-0.1.0/src/nex/tools/shell.py +72 -0
- nexcoder-0.1.0/tests/conftest.py +77 -0
- nexcoder-0.1.0/tests/test_agent.py +133 -0
- nexcoder-0.1.0/tests/test_chat.py +130 -0
- nexcoder-0.1.0/tests/test_cli.py +111 -0
- nexcoder-0.1.0/tests/test_context.py +111 -0
- nexcoder-0.1.0/tests/test_errors.py +80 -0
- nexcoder-0.1.0/tests/test_indexer.py +197 -0
- nexcoder-0.1.0/tests/test_memory.py +52 -0
- nexcoder-0.1.0/tests/test_safety.py +147 -0
- nexcoder-0.1.0/tests/test_test_runner.py +101 -0
- nexcoder-0.1.0/tests/test_tools.py +72 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint with ruff
|
|
30
|
+
run: |
|
|
31
|
+
ruff check src/ tests/
|
|
32
|
+
ruff format --check src/ tests/
|
|
33
|
+
|
|
34
|
+
- name: Type check with mypy
|
|
35
|
+
run: mypy src/nex/
|
|
36
|
+
|
|
37
|
+
- name: Run tests
|
|
38
|
+
run: pytest -x --tb=short -q
|
|
39
|
+
|
|
40
|
+
- name: Build package
|
|
41
|
+
run: |
|
|
42
|
+
pip install build
|
|
43
|
+
python -m build
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-python@v5
|
|
13
|
+
with:
|
|
14
|
+
python-version: "3.12"
|
|
15
|
+
- run: pip install build
|
|
16
|
+
- run: python -m build
|
|
17
|
+
- uses: actions/upload-artifact@v4
|
|
18
|
+
with:
|
|
19
|
+
name: dist
|
|
20
|
+
path: dist/
|
|
21
|
+
|
|
22
|
+
publish:
|
|
23
|
+
needs: build
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
environment: pypi
|
|
26
|
+
permissions:
|
|
27
|
+
id-token: write
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/download-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: dist
|
|
32
|
+
path: dist/
|
|
33
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
*.egg
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.whl
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
env/
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.vscode/
|
|
18
|
+
.idea/
|
|
19
|
+
*.swp
|
|
20
|
+
*.swo
|
|
21
|
+
|
|
22
|
+
# Testing
|
|
23
|
+
.pytest_cache/
|
|
24
|
+
htmlcov/
|
|
25
|
+
.coverage
|
|
26
|
+
.coverage.*
|
|
27
|
+
|
|
28
|
+
# Type checking
|
|
29
|
+
.mypy_cache/
|
|
30
|
+
|
|
31
|
+
# Ruff
|
|
32
|
+
.ruff_cache/
|
|
33
|
+
|
|
34
|
+
# Environment
|
|
35
|
+
.env
|
|
36
|
+
.env.local
|
|
37
|
+
|
|
38
|
+
# Nex local DB (not committed — user-specific error history)
|
|
39
|
+
.nex/errors.db
|
|
40
|
+
|
|
41
|
+
# OS
|
|
42
|
+
.DS_Store
|
|
43
|
+
Thumbs.db
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] — 2026-02-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Core agent loop with 5 tools (read_file, write_file, run_command, search_files, list_directory)
|
|
13
|
+
- Safety layer with destructive operation detection and user approval prompts
|
|
14
|
+
- Project memory system (.nex/memory.md)
|
|
15
|
+
- Error pattern database (.nex/errors.db) with auto-logging and similarity search
|
|
16
|
+
- Codebase indexer with tree-sitter AST parsing and `nex index` command
|
|
17
|
+
- Context assembler with TF-IDF relevance ranking
|
|
18
|
+
- Git integration (branch per task, auto-commit, rollback)
|
|
19
|
+
- Interactive chat mode (`nex chat`)
|
|
20
|
+
- Test runner auto-detection (pytest, npm test, go test, cargo test, maven, gradle)
|
|
21
|
+
- CLI commands: nex, nex init, nex status, nex memory, nex rollback, nex auth, nex chat, nex index
|
|
22
|
+
- Dry-run mode (--dry-run flag)
|
|
23
|
+
- Task decomposition via Claude Haiku
|
|
24
|
+
- Independent code review step
|
nexcoder-0.1.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Nex AI — The Coding Agent That Remembers
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Nex AI is a CLI-based AI coding agent that wraps the Anthropic Claude API with persistent project memory, error pattern learning, and codebase indexing. It makes AI coding assistants more reliable by remembering your project context, avoiding past mistakes, and verifying its own work.
|
|
6
|
+
|
|
7
|
+
**What it is:** A Python CLI tool installed via `pip install nexcoder`. Users run `nex "add a login endpoint"` and the agent reads the codebase, recalls project conventions and past errors, generates code, runs tests, and commits — all with context it retains across sessions.
|
|
8
|
+
|
|
9
|
+
**What it is NOT:** An IDE. A Cursor/Windsurf competitor. A web app. A multi-model orchestrator (yet). Keep it simple.
|
|
10
|
+
|
|
11
|
+
## Tech Stack
|
|
12
|
+
|
|
13
|
+
- **Language:** Python 3.12+
|
|
14
|
+
- **CLI Framework:** Typer + Rich (beautiful terminal UI)
|
|
15
|
+
- **AI Provider:** Anthropic API (Claude Sonnet 4 for reasoning, Claude Haiku for planning/lightweight tasks)
|
|
16
|
+
- **Database:** SQLite via stdlib sqlite3 (error pattern DB)
|
|
17
|
+
- **AST Parsing:** py-tree-sitter (codebase indexing)
|
|
18
|
+
- **Git:** GitPython (branch, commit, diff operations)
|
|
19
|
+
- **HTTP Client:** httpx (async Anthropic API calls)
|
|
20
|
+
- **Testing:** pytest + pytest-asyncio
|
|
21
|
+
- **Linting:** ruff + mypy (strict mode)
|
|
22
|
+
- **Packaging:** PyPI distribution via pyproject.toml + hatchling
|
|
23
|
+
- **CI/CD:** GitHub Actions
|
|
24
|
+
|
|
25
|
+
## Project Structure
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
nex-ai/
|
|
29
|
+
├── src/nex/
|
|
30
|
+
│ ├── __init__.py # Version, package metadata
|
|
31
|
+
│ ├── cli.py # Typer CLI: entry point, all commands
|
|
32
|
+
│ ├── agent.py # Core agent loop (prompt → API → tools → observe → loop)
|
|
33
|
+
│ ├── planner.py # Task decomposition (single Haiku call, returns subtask list)
|
|
34
|
+
│ ├── reviewer.py # Independent code review (separate API call, no access to plan)
|
|
35
|
+
│ ├── context.py # Context assembly: selects relevant code for API context window
|
|
36
|
+
│ ├── api_client.py # Anthropic API wrapper (handles retries, token tracking, model routing)
|
|
37
|
+
│ ├── config.py # Settings: API keys, model prefs, .nex/config.toml parsing
|
|
38
|
+
│ ├── safety.py # Destructive op detection, user approval prompts, dry-run mode
|
|
39
|
+
│ ├── memory/
|
|
40
|
+
│ │ ├── __init__.py
|
|
41
|
+
│ │ ├── project.py # Read/write .nex/memory.md (project conventions, architecture)
|
|
42
|
+
│ │ ├── errors.py # Error pattern DB: log failures, query similar past errors
|
|
43
|
+
│ │ └── decisions.py # Decision log: append-only .nex/decisions.md
|
|
44
|
+
│ ├── indexer/
|
|
45
|
+
│ │ ├── __init__.py
|
|
46
|
+
│ │ ├── scanner.py # File discovery, .gitignore respect, language detection
|
|
47
|
+
│ │ ├── parser.py # tree-sitter AST: extract functions, classes, imports
|
|
48
|
+
│ │ └── index.py # Build/query .nex/index.json (function sigs, deps, structure)
|
|
49
|
+
│ └── tools/
|
|
50
|
+
│ ├── __init__.py
|
|
51
|
+
│ ├── file_ops.py # read_file, write_file, list_directory
|
|
52
|
+
│ ├── shell.py # run_command (with safety layer approval)
|
|
53
|
+
│ ├── search.py # grep/ripgrep wrapper for codebase search
|
|
54
|
+
│ └── git_ops.py # branch, commit, diff, status, rollback
|
|
55
|
+
├── tests/
|
|
56
|
+
│ ├── conftest.py # Shared fixtures, mock API client
|
|
57
|
+
│ ├── test_agent.py # Agent loop tests
|
|
58
|
+
│ ├── test_memory.py # Memory read/write tests
|
|
59
|
+
│ ├── test_errors.py # Error pattern DB tests
|
|
60
|
+
│ ├── test_indexer.py # Codebase indexing tests
|
|
61
|
+
│ ├── test_tools.py # Tool execution tests
|
|
62
|
+
│ ├── test_safety.py # Safety layer tests
|
|
63
|
+
│ └── test_cli.py # CLI integration tests
|
|
64
|
+
├── pyproject.toml # Package config, dependencies, scripts
|
|
65
|
+
├── README.md # User-facing docs
|
|
66
|
+
├── CLAUDE.md # This file
|
|
67
|
+
├── CHANGELOG.md # Keep updated with every release
|
|
68
|
+
├── LICENSE # MIT
|
|
69
|
+
└── .github/
|
|
70
|
+
└── workflows/
|
|
71
|
+
└── ci.yml # Test + lint on every push/PR
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Key Commands
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Development
|
|
78
|
+
pip install -e ".[dev]" # Install in editable mode with dev deps
|
|
79
|
+
pytest # Run all tests
|
|
80
|
+
pytest -x --tb=short # Run tests, stop on first failure
|
|
81
|
+
ruff check src/ tests/ # Lint
|
|
82
|
+
ruff format src/ tests/ # Format
|
|
83
|
+
mypy src/nex/ # Type check
|
|
84
|
+
|
|
85
|
+
# User-facing CLI
|
|
86
|
+
nex "your task here" # Run a task
|
|
87
|
+
nex init # Initialize .nex/ directory for a project
|
|
88
|
+
nex status # Show project memory, error count, index stats
|
|
89
|
+
nex memory edit # Interactive memory editor
|
|
90
|
+
nex rollback # Undo last agent change (git revert)
|
|
91
|
+
nex --dry-run "your task" # Show what would happen without executing
|
|
92
|
+
nex auth # Set up API key
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Architecture Decisions
|
|
96
|
+
|
|
97
|
+
### Agent Loop (Most Critical Component)
|
|
98
|
+
The agent follows the same agentic REPL pattern as Claude Code:
|
|
99
|
+
1. Assemble context: system prompt + project memory + relevant code from index + error patterns
|
|
100
|
+
2. Call Claude API with tool definitions
|
|
101
|
+
3. Parse response: if `tool_use` blocks, execute the tools
|
|
102
|
+
4. Feed tool results back to Claude
|
|
103
|
+
5. Repeat until Claude returns a text-only response (task complete) or max 25 iterations
|
|
104
|
+
6. Log any errors encountered + fixes applied to error pattern DB
|
|
105
|
+
7. If code was modified: run tests, show diff, ask to commit
|
|
106
|
+
|
|
107
|
+
### Memory System
|
|
108
|
+
- **Project memory** (`.nex/memory.md`): Human-readable markdown. Contains project overview, tech stack, coding conventions, architecture notes. Loaded into system prompt on every invocation. Users can edit directly.
|
|
109
|
+
- **Error patterns** (`.nex/errors.db`): SQLite. Schema: `(id, timestamp, task_summary, error_type, what_failed, what_fixed, file_path, language)`. Queried before code generation — top 3 similar errors injected into context.
|
|
110
|
+
- **Decision log** (`.nex/decisions.md`): Append-only. Records architectural choices made during sessions (e.g., "Chose Express over Fastify because existing codebase uses Express middleware").
|
|
111
|
+
|
|
112
|
+
### Tool System
|
|
113
|
+
Exactly 5 tools (kept minimal for safety + token efficiency):
|
|
114
|
+
- `read_file(path)` → returns file content
|
|
115
|
+
- `write_file(path, content)` → writes content, creates dirs if needed
|
|
116
|
+
- `run_command(command)` → executes shell command (safety layer checks first)
|
|
117
|
+
- `search_files(pattern, path?)` → ripgrep wrapper, returns matches with context
|
|
118
|
+
- `list_directory(path?, depth?)` → recursive directory listing
|
|
119
|
+
|
|
120
|
+
New tools require explicit justification and approval. Every tool schema adds ~200 tokens per API call.
|
|
121
|
+
|
|
122
|
+
### Safety Layer
|
|
123
|
+
- **Destructive command detection:** regex patterns for `rm -rf`, `DROP TABLE`, `DELETE FROM`, `git push --force`, `git clean`, etc. These ALWAYS require explicit user confirmation.
|
|
124
|
+
- **Dry-run mode:** `--dry-run` flag shows all planned actions without executing. Default for first-time users.
|
|
125
|
+
- **Git isolation:** Every task creates a branch (`nex/<task-slug>`). Changes are never made on main/master directly.
|
|
126
|
+
- **Max iterations:** Hard cap at 25 tool calls per task. Prevents runaway loops.
|
|
127
|
+
- **Cost cap:** Warn user if a single task exceeds $1 in API costs.
|
|
128
|
+
|
|
129
|
+
### Context Assembly
|
|
130
|
+
- Token budget: reserve 150K of 200K window. 50K for response.
|
|
131
|
+
- Priority order: system prompt (2K) → project memory (1-3K) → error patterns (1-2K) → relevant code from index (variable) → user's task
|
|
132
|
+
- Relevance ranking: TF-IDF match between task description and function signatures/docstrings from index. Include top N files until budget is reached.
|
|
133
|
+
- If index doesn't exist yet, fall back to including the file tree + README.
|
|
134
|
+
|
|
135
|
+
### Model Routing
|
|
136
|
+
- **Claude Sonnet 4:** All code generation, reasoning, review steps
|
|
137
|
+
- **Claude Haiku:** Planning/decomposition, context relevance scoring, simple file operations
|
|
138
|
+
- Selection happens in `api_client.py` based on task type, NOT user-configurable in Phase 1
|
|
139
|
+
|
|
140
|
+
## Conventions
|
|
141
|
+
|
|
142
|
+
### Code Style
|
|
143
|
+
- All code is typed. `mypy --strict` must pass.
|
|
144
|
+
- Use `async/await` for all API calls (httpx async client)
|
|
145
|
+
- Use dataclasses or Pydantic models for structured data (prefer dataclasses for simplicity)
|
|
146
|
+
- Named exports only. No wildcard imports.
|
|
147
|
+
- Docstrings on all public functions (Google style)
|
|
148
|
+
- No `print()` statements — use Rich console for all output
|
|
149
|
+
- Error handling: custom exception hierarchy (`NexError` base, `APIError`, `ToolError`, `SafetyError`, etc.)
|
|
150
|
+
- Configuration: `.nex/config.toml` for project settings, `~/.config/nex/config.toml` for global settings
|
|
151
|
+
- Secrets: NEVER log or store API keys in files. Use environment variables or keyring.
|
|
152
|
+
|
|
153
|
+
### Git Conventions
|
|
154
|
+
- Conventional commits: `feat:`, `fix:`, `refactor:`, `test:`, `docs:`, `chore:`
|
|
155
|
+
- Branch naming: `nex/<task-slug>` for agent-created branches
|
|
156
|
+
- Never commit `.nex/errors.db` to the user's repo (add to .gitignore template)
|
|
157
|
+
- Always commit `.nex/memory.md` and `.nex/decisions.md` (these are valuable project context)
|
|
158
|
+
|
|
159
|
+
### Testing
|
|
160
|
+
- Every module has a corresponding test file
|
|
161
|
+
- Mock the Anthropic API client in all tests (never make real API calls in tests)
|
|
162
|
+
- Use `tmp_path` fixture for file system tests
|
|
163
|
+
- Test the safety layer exhaustively — this is the highest-risk component
|
|
164
|
+
- Integration tests: use a real SQLite DB (in-memory) for error pattern tests
|
|
165
|
+
|
|
166
|
+
### Dependencies Policy
|
|
167
|
+
- Minimize dependencies. Every new dep needs justification.
|
|
168
|
+
- Core deps: anthropic, typer, rich, httpx, gitpython, tree-sitter
|
|
169
|
+
- Dev deps: pytest, pytest-asyncio, ruff, mypy, hatchling
|
|
170
|
+
- No LangChain, no LlamaIndex, no heavy frameworks. We own the orchestration logic.
|
|
171
|
+
|
|
172
|
+
## Error Pattern DB Schema
|
|
173
|
+
|
|
174
|
+
```sql
|
|
175
|
+
CREATE TABLE IF NOT EXISTS error_patterns (
|
|
176
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
177
|
+
timestamp TEXT NOT NULL DEFAULT (datetime('now')),
|
|
178
|
+
task_summary TEXT NOT NULL, -- what the user asked for
|
|
179
|
+
error_type TEXT NOT NULL, -- category: syntax, runtime, logic, import, test_failure
|
|
180
|
+
what_failed TEXT NOT NULL, -- what went wrong
|
|
181
|
+
what_fixed TEXT NOT NULL, -- how it was fixed
|
|
182
|
+
file_path TEXT, -- which file had the error
|
|
183
|
+
language TEXT, -- python, javascript, typescript, go, etc.
|
|
184
|
+
code_context TEXT -- relevant code snippet (truncated to 500 chars)
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
CREATE INDEX IF NOT EXISTS idx_error_language ON error_patterns(language);
|
|
188
|
+
CREATE INDEX IF NOT EXISTS idx_error_type ON error_patterns(error_type);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Query for similar errors: `SELECT * FROM error_patterns WHERE language = ? AND (task_summary LIKE ? OR file_path LIKE ?) ORDER BY timestamp DESC LIMIT 3`
|
|
192
|
+
|
|
193
|
+
## System Prompt Template
|
|
194
|
+
|
|
195
|
+
The system prompt is assembled dynamically. Here's the structure:
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
You are Nex, an AI coding agent that works on the user's codebase. You have access to tools for reading files, writing files, running commands, searching code, and listing directories.
|
|
199
|
+
|
|
200
|
+
## Project Context
|
|
201
|
+
{contents of .nex/memory.md}
|
|
202
|
+
|
|
203
|
+
## Past Errors to Avoid
|
|
204
|
+
{top 3 relevant error patterns from errors.db, if any}
|
|
205
|
+
|
|
206
|
+
## Relevant Code
|
|
207
|
+
{function signatures and code snippets selected by context assembler}
|
|
208
|
+
|
|
209
|
+
## Rules
|
|
210
|
+
- Always read existing code before modifying it. Match the project's style.
|
|
211
|
+
- Run tests after making changes. If tests fail, fix them before reporting success.
|
|
212
|
+
- Never execute destructive commands without user approval.
|
|
213
|
+
- When you make an architectural decision, explain why briefly.
|
|
214
|
+
- If you're unsure about something, ask the user rather than guessing.
|
|
215
|
+
- Keep changes minimal — don't refactor code that isn't related to the task.
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Environment Variables
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
ANTHROPIC_API_KEY=sk-ant-... # Required. User's Anthropic API key.
|
|
222
|
+
NEX_MODEL=claude-sonnet-4-20250514 # Optional. Override default model.
|
|
223
|
+
NEX_MAX_ITERATIONS=25 # Optional. Max tool calls per task.
|
|
224
|
+
NEX_DRY_RUN=false # Optional. Default dry-run mode.
|
|
225
|
+
NEX_LOG_LEVEL=INFO # Optional. DEBUG for development.
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Development Workflow
|
|
229
|
+
|
|
230
|
+
1. Create a feature branch: `git checkout -b feat/feature-name`
|
|
231
|
+
2. Write failing tests first (TDD encouraged)
|
|
232
|
+
3. Implement the feature
|
|
233
|
+
4. Run `ruff check src/ tests/ && mypy src/nex/ && pytest`
|
|
234
|
+
5. All must pass before committing
|
|
235
|
+
6. Write a clear commit message: `feat: add error pattern lookup before code generation`
|
|
236
|
+
7. Open a PR (when we have more than one contributor)
|
|
237
|
+
|
|
238
|
+
## What NOT to Build (Phase 1 Constraints)
|
|
239
|
+
|
|
240
|
+
These are explicitly out of scope. Do not build them regardless of how useful they seem:
|
|
241
|
+
- ❌ Web dashboard or web UI
|
|
242
|
+
- ❌ Multi-model support (GPT-4o, Ollama, etc.)
|
|
243
|
+
- ❌ Graph database (Neo4j, etc.) — use JSON index
|
|
244
|
+
- ❌ Vector database (Qdrant, Chroma, etc.) — use TF-IDF
|
|
245
|
+
- ❌ LangChain or LangGraph integration
|
|
246
|
+
- ❌ Docker sandboxing for code execution
|
|
247
|
+
- ❌ VS Code extension or IDE integration
|
|
248
|
+
- ❌ Team features or collaboration
|
|
249
|
+
- ❌ Billing, subscriptions, or payment processing
|
|
250
|
+
- ❌ MCP server support
|
|
251
|
+
- ❌ More than 5 tools
|
|
252
|
+
- ❌ Custom fine-tuned models
|
|
253
|
+
|
|
254
|
+
These may come in Phase 2/3 when validated by user demand and revenue.
|
|
255
|
+
|
|
256
|
+
## Current Phase: Phase 1 — Build MVP
|
|
257
|
+
|
|
258
|
+
We are in Phase 1 (Weeks 5–14 of the implementation plan). Focus areas in priority order:
|
|
259
|
+
1. Core agent loop with 5 tools ← START HERE
|
|
260
|
+
2. Safety layer (destructive op detection + approval)
|
|
261
|
+
3. Project memory system (.nex/memory.md)
|
|
262
|
+
4. Error pattern DB (.nex/errors.db) with auto-logging
|
|
263
|
+
5. Codebase indexer (tree-sitter + JSON index)
|
|
264
|
+
6. Context assembler (relevance ranking)
|
|
265
|
+
7. Git integration (branch per task, auto-commit)
|
|
266
|
+
8. Test runner detection (pytest/jest/go test)
|
|
267
|
+
9. CLI polish (nex init, nex status, nex memory edit)
|
|
268
|
+
10. PyPI publication
|
nexcoder-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nex AI 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.
|
nexcoder-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nexcoder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The coding agent that remembers — AI coding assistant with persistent memory and error learning.
|
|
5
|
+
Project-URL: Homepage, https://github.com/nex-ai/nex-ai
|
|
6
|
+
Project-URL: Repository, https://github.com/nex-ai/nex-ai
|
|
7
|
+
Author: Nex AI Contributors
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai,anthropic,claude,cli,coding-agent
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: anthropic>=0.40.0
|
|
19
|
+
Requires-Dist: gitpython>=3.1.0
|
|
20
|
+
Requires-Dist: httpx>=0.28.0
|
|
21
|
+
Requires-Dist: rich>=13.9.0
|
|
22
|
+
Requires-Dist: tree-sitter-javascript>=0.23.0
|
|
23
|
+
Requires-Dist: tree-sitter-python>=0.23.0
|
|
24
|
+
Requires-Dist: tree-sitter-typescript>=0.23.0
|
|
25
|
+
Requires-Dist: tree-sitter>=0.24.0
|
|
26
|
+
Requires-Dist: typer[all]>=0.15.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: mypy>=1.13.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.3.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# Nex AI — The Coding Agent That Remembers
|
|
36
|
+
|
|
37
|
+
A CLI-based AI coding agent that wraps the Anthropic Claude API with persistent project memory, error pattern learning, and codebase indexing.
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Persistent Memory** — Remembers your project context, conventions, and architecture across sessions
|
|
42
|
+
- **Error Learning** — Logs past mistakes and queries them before generating code to avoid repeating errors
|
|
43
|
+
- **Codebase Indexing** — Uses tree-sitter to parse your codebase and select relevant context for each task
|
|
44
|
+
- **Interactive Chat** — Multi-turn conversation mode with full tool access and persistent history
|
|
45
|
+
- **Smart Context Selection** — Two-phase token budgeting with file-level TF-IDF ranking and signature-only fallback
|
|
46
|
+
- **Safety Layer** — Detects destructive operations (rm -rf, DROP TABLE, force push) and requires confirmation
|
|
47
|
+
- **Git Integration** — Creates isolated branches per task, shows diffs, and offers to commit
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install nexcoder
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Initialize Nex in your project
|
|
59
|
+
nex init
|
|
60
|
+
|
|
61
|
+
# Set up your API key
|
|
62
|
+
nex auth
|
|
63
|
+
|
|
64
|
+
# Build the codebase index
|
|
65
|
+
nex index
|
|
66
|
+
|
|
67
|
+
# Run a one-shot task
|
|
68
|
+
nex "add a health check endpoint"
|
|
69
|
+
|
|
70
|
+
# Or start an interactive session
|
|
71
|
+
nex chat
|
|
72
|
+
|
|
73
|
+
# Check project status
|
|
74
|
+
nex status
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Commands
|
|
78
|
+
|
|
79
|
+
| Command | Description |
|
|
80
|
+
|---------|-------------|
|
|
81
|
+
| `nex "task"` | Run a coding task |
|
|
82
|
+
| `nex init` | Initialize .nex/ directory |
|
|
83
|
+
| `nex index` | Build codebase index (.nex/index.json) |
|
|
84
|
+
| `nex chat` | Start interactive chat session |
|
|
85
|
+
| `nex status` | Show project stats |
|
|
86
|
+
| `nex auth` | Configure API key |
|
|
87
|
+
| `nex memory show` | View project memory |
|
|
88
|
+
| `nex memory edit` | Edit project memory |
|
|
89
|
+
| `nex rollback` | Undo last agent change |
|
|
90
|
+
| `nex --dry-run "task"` | Preview without executing |
|
|
91
|
+
|
|
92
|
+
## How It Works
|
|
93
|
+
|
|
94
|
+
1. **Context Assembly** — Loads project memory, error patterns, and relevant code into the prompt. Files are ranked by TF-IDF relevance, with top files included in full and remaining files as signature summaries.
|
|
95
|
+
2. **Agent Loop** — Iterates: call Claude API → execute tools → feed results back, up to 25 iterations.
|
|
96
|
+
3. **Interactive Chat** — `nex chat` maintains a persistent conversation with the agent, accumulating context across turns. Useful for exploratory work, debugging, or multi-step tasks.
|
|
97
|
+
4. **Codebase Index** — `nex index` parses your source files with tree-sitter, extracting function/class signatures for fast relevance search.
|
|
98
|
+
5. **Git Commit** — Shows diff and offers to commit on an isolated branch.
|
|
99
|
+
|
|
100
|
+
## Tools
|
|
101
|
+
|
|
102
|
+
The agent has access to 5 tools:
|
|
103
|
+
|
|
104
|
+
| Tool | Description |
|
|
105
|
+
|------|-------------|
|
|
106
|
+
| `read_file` | Read file contents with line numbers |
|
|
107
|
+
| `write_file` | Write content, creating directories if needed |
|
|
108
|
+
| `run_command` | Execute shell commands (safety-checked) |
|
|
109
|
+
| `search_files` | Regex search across the codebase |
|
|
110
|
+
| `list_directory` | Recursive directory listing |
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Clone and install in editable mode
|
|
116
|
+
git clone https://github.com/nex-ai/nex-ai.git
|
|
117
|
+
cd nex-ai
|
|
118
|
+
pip install -e ".[dev]"
|
|
119
|
+
|
|
120
|
+
# Run tests
|
|
121
|
+
pytest
|
|
122
|
+
|
|
123
|
+
# Lint and format
|
|
124
|
+
ruff check src/ tests/
|
|
125
|
+
ruff format src/ tests/
|
|
126
|
+
|
|
127
|
+
# Type check
|
|
128
|
+
mypy src/nex/
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Architecture
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
src/nex/
|
|
135
|
+
├── cli.py # Typer CLI entry point
|
|
136
|
+
├── agent.py # Core agent loop + ChatSession
|
|
137
|
+
├── api_client.py # Anthropic API wrapper
|
|
138
|
+
├── planner.py # Task decomposition (Haiku)
|
|
139
|
+
├── reviewer.py # Independent code review
|
|
140
|
+
├── context.py # Context assembly + token budgeting
|
|
141
|
+
├── safety.py # Destructive operation detection
|
|
142
|
+
├── config.py # Configuration management
|
|
143
|
+
├── memory/ # Persistent memory system
|
|
144
|
+
│ ├── project.py # .nex/memory.md
|
|
145
|
+
│ ├── errors.py # .nex/errors.db (SQLite)
|
|
146
|
+
│ └── decisions.py # .nex/decisions.md
|
|
147
|
+
├── indexer/ # Codebase indexing
|
|
148
|
+
│ ├── scanner.py # File discovery
|
|
149
|
+
│ ├── parser.py # tree-sitter AST parsing
|
|
150
|
+
│ └── index.py # Index builder + TF-IDF search
|
|
151
|
+
└── tools/ # Agent tools (5 total)
|
|
152
|
+
├── file_ops.py # read_file, write_file
|
|
153
|
+
├── shell.py # run_command
|
|
154
|
+
├── search.py # search_files
|
|
155
|
+
└── git_ops.py # Git operations
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Environment Variables
|
|
159
|
+
|
|
160
|
+
| Variable | Description | Default |
|
|
161
|
+
|----------|-------------|---------|
|
|
162
|
+
| `ANTHROPIC_API_KEY` | Anthropic API key (required) | — |
|
|
163
|
+
| `NEX_MODEL` | Override default model | `claude-sonnet-4-20250514` |
|
|
164
|
+
| `NEX_MAX_ITERATIONS` | Max tool calls per task | `25` |
|
|
165
|
+
| `NEX_DRY_RUN` | Default dry-run mode | `false` |
|
|
166
|
+
| `NEX_LOG_LEVEL` | Logging verbosity | `INFO` |
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|