codefission 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.
- codefission-0.1.0/.gitignore +20 -0
- codefission-0.1.0/CONTRIBUTING.md +66 -0
- codefission-0.1.0/LICENSE +21 -0
- codefission-0.1.0/Makefile +27 -0
- codefission-0.1.0/PKG-INFO +110 -0
- codefission-0.1.0/README.md +92 -0
- codefission-0.1.0/codefission/__init__.py +0 -0
- codefission-0.1.0/codefission/__main__.py +5 -0
- codefission-0.1.0/codefission/cli.py +20 -0
- codefission-0.1.0/codefission/config.py +29 -0
- codefission-0.1.0/codefission/db.py +116 -0
- codefission-0.1.0/codefission/events.py +103 -0
- codefission-0.1.0/codefission/handlers.py +830 -0
- codefission-0.1.0/codefission/main.py +359 -0
- codefission-0.1.0/codefission/models.py +36 -0
- codefission-0.1.0/codefission/providers/__init__.py +79 -0
- codefission-0.1.0/codefission/providers/anthropic_provider.py +189 -0
- codefission-0.1.0/codefission/providers/base.py +76 -0
- codefission-0.1.0/codefission/providers/openai_provider.py +172 -0
- codefission-0.1.0/codefission/sandbox_exec.py +33 -0
- codefission-0.1.0/codefission/services/__init__.py +0 -0
- codefission-0.1.0/codefission/services/_process_darwin.py +112 -0
- codefission-0.1.0/codefission/services/_process_linux.py +82 -0
- codefission-0.1.0/codefission/services/_sandbox_linux.py +128 -0
- codefission-0.1.0/codefission/services/chat_service.py +320 -0
- codefission-0.1.0/codefission/services/orchestrator.py +556 -0
- codefission-0.1.0/codefission/services/process_service.py +220 -0
- codefission-0.1.0/codefission/services/sandbox.py +157 -0
- codefission-0.1.0/codefission/services/summary_service.py +87 -0
- codefission-0.1.0/codefission/services/tree_service.py +342 -0
- codefission-0.1.0/codefission/services/workspace_service.py +469 -0
- codefission-0.1.0/codefission/static/assets/index-BZV40eAE.css +1 -0
- codefission-0.1.0/codefission/static/assets/index-BhJ1fRI1.js +366 -0
- codefission-0.1.0/codefission/static/index.html +2050 -0
- codefission-0.1.0/codefission/tests/conftest.py +24 -0
- codefission-0.1.0/codefission/tests/test_cancel.py +96 -0
- codefission-0.1.0/codefission/tests/test_chat_service.py +157 -0
- codefission-0.1.0/codefission/tests/test_db.py +68 -0
- codefission-0.1.0/codefission/tests/test_events.py +83 -0
- codefission-0.1.0/codefission/tests/test_generator_cleanup.py +282 -0
- codefission-0.1.0/codefission/tests/test_models.py +64 -0
- codefission-0.1.0/codefission/tests/test_orchestrator.py +597 -0
- codefission-0.1.0/codefission/tests/test_process_service.py +343 -0
- codefission-0.1.0/codefission/tests/test_sandbox.py +336 -0
- codefission-0.1.0/codefission/tests/test_tree_service.py +288 -0
- codefission-0.1.0/codefission/tests/test_workspace_service.py +717 -0
- codefission-0.1.0/docs/dev/architecture-review.md +68 -0
- codefission-0.1.0/docs/dev/bugs.md +221 -0
- codefission-0.1.0/docs/dev/learn/dev-pipeline.md +224 -0
- codefission-0.1.0/docs/dev/mount-namespace-workspace.md +87 -0
- codefission-0.1.0/docs/dev/thoughts.md +43 -0
- codefission-0.1.0/docs/ephemeral-worktrees.md +296 -0
- codefission-0.1.0/frontend/.gitignore +24 -0
- codefission-0.1.0/frontend/eslint.config.js +23 -0
- codefission-0.1.0/frontend/index.html +2049 -0
- codefission-0.1.0/frontend/package-lock.json +3958 -0
- codefission-0.1.0/frontend/package.json +38 -0
- codefission-0.1.0/frontend/src/App.tsx +230 -0
- codefission-0.1.0/frontend/src/components/Canvas.tsx +634 -0
- codefission-0.1.0/frontend/src/components/ChatPanel.tsx +240 -0
- codefission-0.1.0/frontend/src/components/FilesPanel.tsx +790 -0
- codefission-0.1.0/frontend/src/components/NodeModal.tsx +126 -0
- codefission-0.1.0/frontend/src/components/QuoteBrowser.tsx +241 -0
- codefission-0.1.0/frontend/src/components/SettingsPanel.tsx +249 -0
- codefission-0.1.0/frontend/src/components/ToolCallLine.tsx +67 -0
- codefission-0.1.0/frontend/src/components/TreeList.tsx +109 -0
- codefission-0.1.0/frontend/src/components/TreeNode.tsx +766 -0
- codefission-0.1.0/frontend/src/dag.test.ts +165 -0
- codefission-0.1.0/frontend/src/fileAttach.ts +403 -0
- codefission-0.1.0/frontend/src/layout.test.ts +279 -0
- codefission-0.1.0/frontend/src/layout.ts +208 -0
- codefission-0.1.0/frontend/src/main.tsx +9 -0
- codefission-0.1.0/frontend/src/renderMarkdown.ts +75 -0
- codefission-0.1.0/frontend/src/store.ts +480 -0
- codefission-0.1.0/frontend/src/ws.ts +290 -0
- codefission-0.1.0/frontend/tsconfig.app.json +28 -0
- codefission-0.1.0/frontend/tsconfig.json +7 -0
- codefission-0.1.0/frontend/tsconfig.node.json +26 -0
- codefission-0.1.0/frontend/vite.config.ts +17 -0
- codefission-0.1.0/pyproject.toml +47 -0
- codefission-0.1.0/run.sh +26 -0
- codefission-0.1.0/uv.lock +1531 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
venv/
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.pyc
|
|
5
|
+
node_modules/
|
|
6
|
+
frontend/dist/
|
|
7
|
+
.DS_Store
|
|
8
|
+
.env
|
|
9
|
+
data/workspaces/
|
|
10
|
+
data/*.db
|
|
11
|
+
data/*.db-wal
|
|
12
|
+
data/*.db-shm
|
|
13
|
+
backend/data/
|
|
14
|
+
test_repo/
|
|
15
|
+
ref_repos/
|
|
16
|
+
.claude/
|
|
17
|
+
.cursor/
|
|
18
|
+
codefission-ai/
|
|
19
|
+
codefission/static/
|
|
20
|
+
dist/
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Contributing to CodeFission
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing! Here's how to get started.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Clone and set up the backend
|
|
9
|
+
git clone https://github.com/your-username/codefission.git
|
|
10
|
+
cd codefission
|
|
11
|
+
python3 -m venv venv
|
|
12
|
+
source venv/bin/activate
|
|
13
|
+
pip install -r requirements.txt
|
|
14
|
+
|
|
15
|
+
# Set up the frontend (with hot reload)
|
|
16
|
+
cd frontend
|
|
17
|
+
npm install
|
|
18
|
+
npm run dev # Starts Vite dev server on :5173
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Run the backend separately during development:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
source venv/bin/activate
|
|
25
|
+
cd backend
|
|
26
|
+
uvicorn main:app --reload --port 8080
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Project Structure
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
├── backend/ # FastAPI application
|
|
33
|
+
│ ├── main.py # App entry point and routes
|
|
34
|
+
│ ├── db.py # Database connection and migrations
|
|
35
|
+
│ ├── models.py # Pydantic models
|
|
36
|
+
│ ├── tree_service.py
|
|
37
|
+
│ ├── chat_service.py
|
|
38
|
+
│ └── workspace_service.py
|
|
39
|
+
├── frontend/ # React + TypeScript (Vite)
|
|
40
|
+
│ └── src/
|
|
41
|
+
│ ├── App.tsx
|
|
42
|
+
│ ├── store.ts # State management
|
|
43
|
+
│ └── components/
|
|
44
|
+
├── data/ # SQLite DB + git workspaces (gitignored)
|
|
45
|
+
└── run.sh # Production start script
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Coding Standards
|
|
49
|
+
|
|
50
|
+
- **Python:** Follow PEP 8. Use type hints where practical.
|
|
51
|
+
- **TypeScript:** Use strict mode. Prefer functional components with hooks.
|
|
52
|
+
- **Commits:** Write concise, descriptive commit messages.
|
|
53
|
+
|
|
54
|
+
## Pull Request Workflow
|
|
55
|
+
|
|
56
|
+
1. Fork the repo and create a feature branch from `main`.
|
|
57
|
+
2. Make your changes and test them locally.
|
|
58
|
+
3. Ensure the frontend builds cleanly: `cd frontend && npm run build`
|
|
59
|
+
4. Open a pull request with a clear description of what you changed and why.
|
|
60
|
+
|
|
61
|
+
## Reporting Issues
|
|
62
|
+
|
|
63
|
+
Open an issue on GitHub with:
|
|
64
|
+
- Steps to reproduce
|
|
65
|
+
- Expected vs. actual behavior
|
|
66
|
+
- Browser/OS/Python version if relevant
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tianyu Hua
|
|
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.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.PHONY: dev build-frontend build publish clean test
|
|
2
|
+
|
|
3
|
+
# Development: builds frontend + starts server with hot reload
|
|
4
|
+
dev:
|
|
5
|
+
./run.sh
|
|
6
|
+
|
|
7
|
+
# Build frontend static assets
|
|
8
|
+
build-frontend:
|
|
9
|
+
cd frontend && npm install && npm run build
|
|
10
|
+
|
|
11
|
+
# Bundle frontend into Python package, then build wheel + sdist
|
|
12
|
+
build: build-frontend
|
|
13
|
+
rm -rf codefission/static
|
|
14
|
+
cp -r frontend/dist codefission/static
|
|
15
|
+
uv run hatch build
|
|
16
|
+
|
|
17
|
+
# Publish to PyPI (builds first if needed)
|
|
18
|
+
publish: build
|
|
19
|
+
uv run hatch publish
|
|
20
|
+
|
|
21
|
+
# Run tests
|
|
22
|
+
test:
|
|
23
|
+
uv run pytest
|
|
24
|
+
|
|
25
|
+
# Clean build artifacts
|
|
26
|
+
clean:
|
|
27
|
+
rm -rf frontend/dist dist codefission/static
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codefission
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tree-structured AI coding assistant with git worktree isolation
|
|
5
|
+
Project-URL: Homepage, https://github.com/codefission-ai/CodeFission
|
|
6
|
+
Project-URL: Repository, https://github.com/codefission-ai/CodeFission
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Requires-Dist: aiosqlite
|
|
11
|
+
Requires-Dist: anthropic
|
|
12
|
+
Requires-Dist: claude-agent-sdk
|
|
13
|
+
Requires-Dist: fastapi
|
|
14
|
+
Requires-Dist: openai
|
|
15
|
+
Requires-Dist: pydantic
|
|
16
|
+
Requires-Dist: uvicorn[standard]
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# CodeFission
|
|
20
|
+
|
|
21
|
+
Tree-structured AI coding assistant. Each conversation node is an isolated git worktree — branch conversations to explore alternative approaches, and each branch gets its own filesystem sandbox.
|
|
22
|
+
|
|
23
|
+
## Prerequisites
|
|
24
|
+
|
|
25
|
+
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) — AI backend (spawned as subprocess). Install: `npm install -g @anthropic-ai/claude-code`
|
|
26
|
+
- [uv](https://docs.astral.sh/uv/installation/) — Python package manager. Install: `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
|
27
|
+
- [Node.js](https://nodejs.org/en/download) 18+ — frontend build. Install via system package manager or [nvm](https://github.com/nvm-sh/nvm)
|
|
28
|
+
- [git](https://git-scm.com/downloads) — worktree isolation. Usually pre-installed.
|
|
29
|
+
|
|
30
|
+
Authenticate Claude Code before first use:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
claude login
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
### Option A: Let Claude do it
|
|
39
|
+
|
|
40
|
+
If you already have Claude Code installed:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
claude -p "git clone <repo-url> codefission && cd codefission && ./run.sh"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Option B: Manual
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
git clone <repo-url> codefission
|
|
50
|
+
cd codefission
|
|
51
|
+
./run.sh
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
On first run, `run.sh` will:
|
|
55
|
+
1. Install Python dependencies via `uv` (creates `.venv/` automatically)
|
|
56
|
+
2. Install npm packages and build the frontend
|
|
57
|
+
3. Start the server on `http://localhost:8080`
|
|
58
|
+
|
|
59
|
+
Subsequent runs skip steps 1-2 (unless dependencies or source changed).
|
|
60
|
+
|
|
61
|
+
To use a different port: `./run.sh 3000`
|
|
62
|
+
|
|
63
|
+
## How it works
|
|
64
|
+
|
|
65
|
+
Create a tree in the sidebar, type a message, and CodeFission spawns a Claude Code session in an isolated git worktree. Branch any node to explore alternatives — each branch forks the conversation context and the filesystem state.
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
[root]
|
|
69
|
+
/ \
|
|
70
|
+
[add auth] [add auth] <- same prompt, different approaches
|
|
71
|
+
| |
|
|
72
|
+
[fix tests] [add logging] <- independent follow-ups
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Every node tracks its git branch, commit, and Claude session. Child nodes fork from the parent's prompt cache so context carries over without re-sending history.
|
|
76
|
+
|
|
77
|
+
## Authentication
|
|
78
|
+
|
|
79
|
+
Configurable in the Settings panel (gear icon in sidebar):
|
|
80
|
+
|
|
81
|
+
- **CLI (OAuth)** — default. Uses your `claude login` session. No API key needed.
|
|
82
|
+
- **API Key** — provide an Anthropic API key in settings. Useful for headless/remote setups.
|
|
83
|
+
|
|
84
|
+
Both modes require the Claude Code CLI binary to be installed.
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
Open Settings (gear icon) to configure:
|
|
89
|
+
|
|
90
|
+
- **Global defaults** — provider, model, max turns, auth mode. Applies to all trees.
|
|
91
|
+
- **Per-tree overrides** — provider, model, max turns. Leave as "Default" to inherit global settings.
|
|
92
|
+
|
|
93
|
+
Settings persist in the backend database across sessions and devices.
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
Run tests:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
uv run --group dev pytest
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Frontend dev server (hot reload):
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
cd frontend
|
|
107
|
+
npm run dev
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Data is stored in `~/.codefission/` (SQLite database, git worktrees). Override with `CODEFISSION_DATA_DIR` env var.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# CodeFission
|
|
2
|
+
|
|
3
|
+
Tree-structured AI coding assistant. Each conversation node is an isolated git worktree — branch conversations to explore alternative approaches, and each branch gets its own filesystem sandbox.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) — AI backend (spawned as subprocess). Install: `npm install -g @anthropic-ai/claude-code`
|
|
8
|
+
- [uv](https://docs.astral.sh/uv/installation/) — Python package manager. Install: `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
|
9
|
+
- [Node.js](https://nodejs.org/en/download) 18+ — frontend build. Install via system package manager or [nvm](https://github.com/nvm-sh/nvm)
|
|
10
|
+
- [git](https://git-scm.com/downloads) — worktree isolation. Usually pre-installed.
|
|
11
|
+
|
|
12
|
+
Authenticate Claude Code before first use:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
claude login
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
### Option A: Let Claude do it
|
|
21
|
+
|
|
22
|
+
If you already have Claude Code installed:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
claude -p "git clone <repo-url> codefission && cd codefission && ./run.sh"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Option B: Manual
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
git clone <repo-url> codefission
|
|
32
|
+
cd codefission
|
|
33
|
+
./run.sh
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
On first run, `run.sh` will:
|
|
37
|
+
1. Install Python dependencies via `uv` (creates `.venv/` automatically)
|
|
38
|
+
2. Install npm packages and build the frontend
|
|
39
|
+
3. Start the server on `http://localhost:8080`
|
|
40
|
+
|
|
41
|
+
Subsequent runs skip steps 1-2 (unless dependencies or source changed).
|
|
42
|
+
|
|
43
|
+
To use a different port: `./run.sh 3000`
|
|
44
|
+
|
|
45
|
+
## How it works
|
|
46
|
+
|
|
47
|
+
Create a tree in the sidebar, type a message, and CodeFission spawns a Claude Code session in an isolated git worktree. Branch any node to explore alternatives — each branch forks the conversation context and the filesystem state.
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
[root]
|
|
51
|
+
/ \
|
|
52
|
+
[add auth] [add auth] <- same prompt, different approaches
|
|
53
|
+
| |
|
|
54
|
+
[fix tests] [add logging] <- independent follow-ups
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Every node tracks its git branch, commit, and Claude session. Child nodes fork from the parent's prompt cache so context carries over without re-sending history.
|
|
58
|
+
|
|
59
|
+
## Authentication
|
|
60
|
+
|
|
61
|
+
Configurable in the Settings panel (gear icon in sidebar):
|
|
62
|
+
|
|
63
|
+
- **CLI (OAuth)** — default. Uses your `claude login` session. No API key needed.
|
|
64
|
+
- **API Key** — provide an Anthropic API key in settings. Useful for headless/remote setups.
|
|
65
|
+
|
|
66
|
+
Both modes require the Claude Code CLI binary to be installed.
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
Open Settings (gear icon) to configure:
|
|
71
|
+
|
|
72
|
+
- **Global defaults** — provider, model, max turns, auth mode. Applies to all trees.
|
|
73
|
+
- **Per-tree overrides** — provider, model, max turns. Leave as "Default" to inherit global settings.
|
|
74
|
+
|
|
75
|
+
Settings persist in the backend database across sessions and devices.
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
Run tests:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
uv run --group dev pytest
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Frontend dev server (hot reload):
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
cd frontend
|
|
89
|
+
npm run dev
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Data is stored in `~/.codefission/` (SQLite database, git worktrees). Override with `CODEFISSION_DATA_DIR` env var.
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""CLI entry point for CodeFission."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import uvicorn
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
|
|
10
|
+
uvicorn.run(
|
|
11
|
+
"codefission.main:app",
|
|
12
|
+
host="0.0.0.0",
|
|
13
|
+
port=port,
|
|
14
|
+
ws_ping_interval=30,
|
|
15
|
+
ws_ping_timeout=10,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
# Fixed location for the bootstrap config (read before DB exists)
|
|
6
|
+
CONFIG_FILE = Path.home() / ".codefission.json"
|
|
7
|
+
|
|
8
|
+
def _load_config() -> dict:
|
|
9
|
+
if CONFIG_FILE.exists():
|
|
10
|
+
try:
|
|
11
|
+
return json.loads(CONFIG_FILE.read_text())
|
|
12
|
+
except Exception:
|
|
13
|
+
pass
|
|
14
|
+
return {}
|
|
15
|
+
|
|
16
|
+
def save_config(updates: dict):
|
|
17
|
+
"""Merge updates into the config file."""
|
|
18
|
+
cfg = _load_config()
|
|
19
|
+
cfg.update(updates)
|
|
20
|
+
CONFIG_FILE.write_text(json.dumps(cfg, indent=2) + "\n")
|
|
21
|
+
|
|
22
|
+
_cfg = _load_config()
|
|
23
|
+
|
|
24
|
+
# Data directory: config file > env var > default
|
|
25
|
+
DATA_DIR = Path(
|
|
26
|
+
_cfg.get("data_dir")
|
|
27
|
+
or os.environ.get("CODEFISSION_DATA_DIR")
|
|
28
|
+
or str(Path.home() / ".codefission")
|
|
29
|
+
)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import aiosqlite
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from contextlib import asynccontextmanager
|
|
4
|
+
|
|
5
|
+
from models import DEFAULT_PROVIDER, DEFAULT_MODEL
|
|
6
|
+
from config import DATA_DIR
|
|
7
|
+
|
|
8
|
+
DB_PATH = DATA_DIR / "codefission.db"
|
|
9
|
+
|
|
10
|
+
_conn: aiosqlite.Connection | None = None
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def _open_connection() -> aiosqlite.Connection:
|
|
14
|
+
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
15
|
+
db = await aiosqlite.connect(str(DB_PATH))
|
|
16
|
+
db.row_factory = aiosqlite.Row
|
|
17
|
+
await db.execute("PRAGMA journal_mode=WAL")
|
|
18
|
+
await db.execute("PRAGMA foreign_keys=ON")
|
|
19
|
+
return db
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@asynccontextmanager
|
|
23
|
+
async def get_db():
|
|
24
|
+
global _conn
|
|
25
|
+
if _conn is None:
|
|
26
|
+
_conn = await _open_connection()
|
|
27
|
+
yield _conn
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async def close_db():
|
|
31
|
+
global _conn
|
|
32
|
+
if _conn is not None:
|
|
33
|
+
await _conn.close()
|
|
34
|
+
_conn = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def init_db():
|
|
38
|
+
global _conn
|
|
39
|
+
# Close existing connection (e.g. tests changing DB_PATH)
|
|
40
|
+
if _conn is not None:
|
|
41
|
+
await _conn.close()
|
|
42
|
+
_conn = None
|
|
43
|
+
|
|
44
|
+
async with get_db() as db:
|
|
45
|
+
await db.executescript("""
|
|
46
|
+
CREATE TABLE IF NOT EXISTS trees (
|
|
47
|
+
id TEXT PRIMARY KEY,
|
|
48
|
+
name TEXT NOT NULL,
|
|
49
|
+
created_at TEXT NOT NULL
|
|
50
|
+
);
|
|
51
|
+
CREATE TABLE IF NOT EXISTS nodes (
|
|
52
|
+
id TEXT PRIMARY KEY,
|
|
53
|
+
tree_id TEXT NOT NULL REFERENCES trees(id),
|
|
54
|
+
parent_id TEXT REFERENCES nodes(id),
|
|
55
|
+
user_message TEXT NOT NULL DEFAULT '',
|
|
56
|
+
assistant_response TEXT NOT NULL DEFAULT '',
|
|
57
|
+
label TEXT NOT NULL DEFAULT '',
|
|
58
|
+
status TEXT NOT NULL DEFAULT 'idle',
|
|
59
|
+
created_at TEXT NOT NULL
|
|
60
|
+
);
|
|
61
|
+
CREATE TABLE IF NOT EXISTS settings (
|
|
62
|
+
key TEXT PRIMARY KEY,
|
|
63
|
+
value TEXT
|
|
64
|
+
);
|
|
65
|
+
CREATE INDEX IF NOT EXISTS idx_nodes_tree ON nodes(tree_id);
|
|
66
|
+
CREATE INDEX IF NOT EXISTS idx_nodes_parent ON nodes(parent_id);
|
|
67
|
+
""")
|
|
68
|
+
|
|
69
|
+
# Migrate: add provider/model columns to trees if missing
|
|
70
|
+
cursor = await db.execute("PRAGMA table_info(trees)")
|
|
71
|
+
columns = {row[1] for row in await cursor.fetchall()}
|
|
72
|
+
if "provider" not in columns:
|
|
73
|
+
await db.execute(
|
|
74
|
+
f"ALTER TABLE trees ADD COLUMN provider TEXT NOT NULL DEFAULT '{DEFAULT_PROVIDER}'"
|
|
75
|
+
)
|
|
76
|
+
if "model" not in columns:
|
|
77
|
+
await db.execute(
|
|
78
|
+
f"ALTER TABLE trees ADD COLUMN model TEXT NOT NULL DEFAULT '{DEFAULT_MODEL}'"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Migrate: add repo_mode, repo_source to trees
|
|
82
|
+
if "repo_mode" not in columns:
|
|
83
|
+
await db.execute("ALTER TABLE trees ADD COLUMN repo_mode TEXT NOT NULL DEFAULT 'none'")
|
|
84
|
+
if "repo_source" not in columns:
|
|
85
|
+
await db.execute("ALTER TABLE trees ADD COLUMN repo_source TEXT")
|
|
86
|
+
|
|
87
|
+
# Migrate: add max_turns to trees
|
|
88
|
+
if "max_turns" not in columns:
|
|
89
|
+
await db.execute("ALTER TABLE trees ADD COLUMN max_turns INTEGER")
|
|
90
|
+
|
|
91
|
+
# Migrate: add skill to trees
|
|
92
|
+
if "skill" not in columns:
|
|
93
|
+
await db.execute("ALTER TABLE trees ADD COLUMN skill TEXT NOT NULL DEFAULT ''")
|
|
94
|
+
|
|
95
|
+
# Migrate: add notes to trees
|
|
96
|
+
if "notes" not in columns:
|
|
97
|
+
await db.execute("ALTER TABLE trees ADD COLUMN notes TEXT NOT NULL DEFAULT '[]'")
|
|
98
|
+
|
|
99
|
+
# Migrate: rename provider "anthropic" → "claude-code"
|
|
100
|
+
await db.execute("UPDATE trees SET provider = 'claude-code' WHERE provider = 'anthropic'")
|
|
101
|
+
|
|
102
|
+
# Migrate: add git_branch, git_commit to nodes
|
|
103
|
+
cursor2 = await db.execute("PRAGMA table_info(nodes)")
|
|
104
|
+
node_columns = {row[1] for row in await cursor2.fetchall()}
|
|
105
|
+
if "git_branch" not in node_columns:
|
|
106
|
+
await db.execute("ALTER TABLE nodes ADD COLUMN git_branch TEXT")
|
|
107
|
+
if "git_commit" not in node_columns:
|
|
108
|
+
await db.execute("ALTER TABLE nodes ADD COLUMN git_commit TEXT")
|
|
109
|
+
if "session_id" not in node_columns:
|
|
110
|
+
await db.execute("ALTER TABLE nodes ADD COLUMN session_id TEXT")
|
|
111
|
+
if "created_by" not in node_columns:
|
|
112
|
+
await db.execute("ALTER TABLE nodes ADD COLUMN created_by TEXT NOT NULL DEFAULT 'human'")
|
|
113
|
+
if "quoted_node_ids" not in node_columns:
|
|
114
|
+
await db.execute("ALTER TABLE nodes ADD COLUMN quoted_node_ids TEXT NOT NULL DEFAULT '[]'")
|
|
115
|
+
|
|
116
|
+
await db.commit()
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Async event bus for decoupled communication between services and WebSocket layer.
|
|
2
|
+
|
|
3
|
+
Adapted from WhatTheBot's core/events.py — same pub/sub pattern, CodeFission-specific events.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
from collections import defaultdict
|
|
10
|
+
from typing import Any, Callable, Coroutine
|
|
11
|
+
|
|
12
|
+
Callback = Callable[..., Coroutine[Any, Any, None]]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class EventBus:
|
|
16
|
+
def __init__(self) -> None:
|
|
17
|
+
self._listeners: dict[str, list[Callback]] = defaultdict(list)
|
|
18
|
+
|
|
19
|
+
def on(self, event: str, callback: Callback) -> None:
|
|
20
|
+
self._listeners[event].append(callback)
|
|
21
|
+
|
|
22
|
+
def off(self, event: str, callback: Callback) -> None:
|
|
23
|
+
self._listeners[event] = [
|
|
24
|
+
cb for cb in self._listeners[event] if cb is not callback
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
async def emit(self, event: str, **kwargs: Any) -> None:
|
|
28
|
+
for cb in list(self._listeners.get(event, [])):
|
|
29
|
+
asyncio.create_task(cb(**kwargs))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Singleton bus
|
|
33
|
+
bus = EventBus()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ── Well-known event names (internal, backend-side) ─────────────────────
|
|
37
|
+
|
|
38
|
+
STREAM_START = "stream_start" # chat streaming begins for a node
|
|
39
|
+
STREAM_DELTA = "stream_delta" # new token(s) in a streaming response
|
|
40
|
+
STREAM_END = "stream_end" # chat streaming finished
|
|
41
|
+
STREAM_ERROR = "stream_error" # chat streaming hit an error
|
|
42
|
+
NODE_CREATED = "node_created" # a new node was created
|
|
43
|
+
NODE_UPDATED = "node_updated" # a node's data changed
|
|
44
|
+
TREE_CREATED = "tree_created" # a new tree was created
|
|
45
|
+
TREE_DELETED = "tree_deleted" # a tree was deleted
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# ── WebSocket message types (wire protocol, client ↔ server) ───────────
|
|
49
|
+
|
|
50
|
+
class WS:
|
|
51
|
+
"""Structured constants for WebSocket JSON message types.
|
|
52
|
+
|
|
53
|
+
Inbound = client → server requests
|
|
54
|
+
Outbound = server → client responses/pushes
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
# Inbound (client → server)
|
|
58
|
+
LIST_TREES = "list_trees"
|
|
59
|
+
CREATE_TREE = "create_tree"
|
|
60
|
+
LOAD_TREE = "load_tree"
|
|
61
|
+
DELETE_TREE = "delete_tree"
|
|
62
|
+
BRANCH = "branch"
|
|
63
|
+
CHAT = "chat"
|
|
64
|
+
CANCEL = "cancel"
|
|
65
|
+
DUPLICATE = "duplicate"
|
|
66
|
+
GET_NODE = "get_node"
|
|
67
|
+
SET_REPO = "set_repo"
|
|
68
|
+
GET_NODE_FILES = "get_node_files"
|
|
69
|
+
GET_NODE_DIFF = "get_node_diff"
|
|
70
|
+
GET_FILE_CONTENT = "get_file_content"
|
|
71
|
+
SELECT_TREE = "select_tree"
|
|
72
|
+
SET_EXPANDED = "set_expanded"
|
|
73
|
+
SET_SUBTREE_COLLAPSED = "set_subtree_collapsed"
|
|
74
|
+
GET_SETTINGS = "get_settings"
|
|
75
|
+
UPDATE_GLOBAL_SETTINGS = "update_global_settings"
|
|
76
|
+
UPDATE_TREE_SETTINGS = "update_tree_settings"
|
|
77
|
+
GET_NODE_PROCESSES = "get_node_processes"
|
|
78
|
+
KILL_PROCESS = "kill_process"
|
|
79
|
+
KILL_ALL_PROCESSES = "kill_all_processes"
|
|
80
|
+
DELETE_NODE = "delete_node"
|
|
81
|
+
|
|
82
|
+
# Outbound
|
|
83
|
+
SETTINGS = "settings"
|
|
84
|
+
|
|
85
|
+
# Outbound (server → client)
|
|
86
|
+
TREES = "trees"
|
|
87
|
+
TREE_CREATED = "tree_created"
|
|
88
|
+
TREE_LOADED = "tree_loaded"
|
|
89
|
+
TREE_DELETED = "tree_deleted"
|
|
90
|
+
TREE_UPDATED = "tree_updated"
|
|
91
|
+
NODE_CREATED = "node_created"
|
|
92
|
+
NODE_DATA = "node_data"
|
|
93
|
+
NODE_FILES = "node_files"
|
|
94
|
+
NODE_DIFF = "node_diff"
|
|
95
|
+
FILE_CONTENT = "file_content"
|
|
96
|
+
STATUS = "status"
|
|
97
|
+
CHUNK = "chunk"
|
|
98
|
+
TOOL_START = "tool_start"
|
|
99
|
+
TOOL_END = "tool_end"
|
|
100
|
+
DONE = "done"
|
|
101
|
+
ERROR = "error"
|
|
102
|
+
NODE_PROCESSES = "node_processes"
|
|
103
|
+
NODES_DELETED = "nodes_deleted"
|