brainfile 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.
- brainfile-0.1.0/.github/workflows/publish.yml +43 -0
- brainfile-0.1.0/.gitignore +30 -0
- brainfile-0.1.0/LICENSE +21 -0
- brainfile-0.1.0/PKG-INFO +252 -0
- brainfile-0.1.0/README.md +222 -0
- brainfile-0.1.0/examples/list_tasks.py +263 -0
- brainfile-0.1.0/pyproject.toml +61 -0
- brainfile-0.1.0/src/brainfile/__init__.py +687 -0
- brainfile-0.1.0/src/brainfile/board_validation.py +61 -0
- brainfile-0.1.0/src/brainfile/contract_ops.py +342 -0
- brainfile-0.1.0/src/brainfile/discovery.py +662 -0
- brainfile-0.1.0/src/brainfile/files.py +143 -0
- brainfile-0.1.0/src/brainfile/formatters.py +265 -0
- brainfile-0.1.0/src/brainfile/id_gen.py +152 -0
- brainfile-0.1.0/src/brainfile/inference.py +199 -0
- brainfile-0.1.0/src/brainfile/linter.py +363 -0
- brainfile-0.1.0/src/brainfile/models.py +582 -0
- brainfile-0.1.0/src/brainfile/operations.py +1304 -0
- brainfile-0.1.0/src/brainfile/parser.py +414 -0
- brainfile-0.1.0/src/brainfile/py.typed +0 -0
- brainfile-0.1.0/src/brainfile/query.py +330 -0
- brainfile-0.1.0/src/brainfile/realtime.py +311 -0
- brainfile-0.1.0/src/brainfile/schema_hints.py +172 -0
- brainfile-0.1.0/src/brainfile/serializer.py +173 -0
- brainfile-0.1.0/src/brainfile/task_file.py +197 -0
- brainfile-0.1.0/src/brainfile/task_operations.py +435 -0
- brainfile-0.1.0/src/brainfile/templates.py +250 -0
- brainfile-0.1.0/src/brainfile/validator.py +689 -0
- brainfile-0.1.0/src/brainfile/workspace.py +193 -0
- brainfile-0.1.0/tests/__init__.py +1 -0
- brainfile-0.1.0/tests/conftest.py +149 -0
- brainfile-0.1.0/tests/fixtures/__init__.py +19 -0
- brainfile-0.1.0/tests/fixtures/boards.py +185 -0
- brainfile-0.1.0/tests/test_board_validation.py +70 -0
- brainfile-0.1.0/tests/test_contract_ops.py +101 -0
- brainfile-0.1.0/tests/test_discovery.py +476 -0
- brainfile-0.1.0/tests/test_formatters.py +60 -0
- brainfile-0.1.0/tests/test_id_gen.py +196 -0
- brainfile-0.1.0/tests/test_inference.py +218 -0
- brainfile-0.1.0/tests/test_linter.py +271 -0
- brainfile-0.1.0/tests/test_models.py +211 -0
- brainfile-0.1.0/tests/test_operations.py +344 -0
- brainfile-0.1.0/tests/test_parser.py +215 -0
- brainfile-0.1.0/tests/test_query.py +304 -0
- brainfile-0.1.0/tests/test_realtime.py +469 -0
- brainfile-0.1.0/tests/test_schema_hints.py +147 -0
- brainfile-0.1.0/tests/test_serializer.py +101 -0
- brainfile-0.1.0/tests/test_task_operations.py +147 -0
- brainfile-0.1.0/tests/test_templates.py +280 -0
- brainfile-0.1.0/tests/test_validator.py +393 -0
- brainfile-0.1.0/uv.lock +568 -0
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.12"
|
|
16
|
+
|
|
17
|
+
- name: Install build tools
|
|
18
|
+
run: pip install build
|
|
19
|
+
|
|
20
|
+
- name: Build package
|
|
21
|
+
run: python -m build
|
|
22
|
+
|
|
23
|
+
- name: Upload artifacts
|
|
24
|
+
uses: actions/upload-artifact@v4
|
|
25
|
+
with:
|
|
26
|
+
name: dist
|
|
27
|
+
path: dist/
|
|
28
|
+
|
|
29
|
+
publish:
|
|
30
|
+
needs: build
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
environment: pypi
|
|
33
|
+
permissions:
|
|
34
|
+
id-token: write
|
|
35
|
+
steps:
|
|
36
|
+
- name: Download artifacts
|
|
37
|
+
uses: actions/download-artifact@v4
|
|
38
|
+
with:
|
|
39
|
+
name: dist
|
|
40
|
+
path: dist/
|
|
41
|
+
|
|
42
|
+
- name: Publish to PyPI
|
|
43
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
*.egg
|
|
9
|
+
|
|
10
|
+
# Virtual environments
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
|
|
15
|
+
# Testing
|
|
16
|
+
.coverage
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
htmlcov/
|
|
19
|
+
|
|
20
|
+
# Type checking / linting
|
|
21
|
+
.mypy_cache/
|
|
22
|
+
.ruff_cache/
|
|
23
|
+
|
|
24
|
+
# IDE
|
|
25
|
+
.vscode/
|
|
26
|
+
.idea/
|
|
27
|
+
|
|
28
|
+
# OS
|
|
29
|
+
.DS_Store
|
|
30
|
+
Thumbs.db
|
brainfile-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Brainfile 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.
|
brainfile-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brainfile
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python library for the Brainfile task management protocol
|
|
5
|
+
Project-URL: Homepage, https://brainfile.md
|
|
6
|
+
Project-URL: Repository, https://github.com/brainfile/py
|
|
7
|
+
Project-URL: Issues, https://github.com/brainfile/py/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/brainfile/protocol
|
|
9
|
+
Author: Brainfile Contributors
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai-agents,brainfile,kanban,markdown,mcp,task-management,yaml
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: pydantic>=2.0
|
|
22
|
+
Requires-Dist: ruamel-yaml>=0.18
|
|
23
|
+
Requires-Dist: watchdog>=3.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<img src="https://raw.githubusercontent.com/brainfile/core/main/logo.png" alt="Brainfile Logo" width="128" height="128">
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
# brainfile
|
|
36
|
+
|
|
37
|
+
**The Python engine behind [Brainfile](https://brainfile.md).**
|
|
38
|
+
|
|
39
|
+
This library provides the core logic for managing Brainfile v2 projects: reading/writing task files, managing contracts, validating boards, and querying task state. It is the Python equivalent of [@brainfile/core](https://github.com/brainfile/core) with full API parity.
|
|
40
|
+
|
|
41
|
+
Used by [Cecli](https://github.com/dwash96/cecli) and other tools that need programmatic access to Brainfile workspaces.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install brainfile
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or with [uv](https://github.com/astral-sh/uv):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv add brainfile
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## v2 Architecture
|
|
56
|
+
|
|
57
|
+
Brainfile v2 uses a directory-based structure. Each task is its own markdown file.
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
.brainfile/
|
|
61
|
+
├── brainfile.md # Board config (columns, types, rules)
|
|
62
|
+
├── board/ # Active tasks
|
|
63
|
+
│ ├── task-1.md
|
|
64
|
+
│ └── task-2.md
|
|
65
|
+
└── logs/ # Completed tasks (history)
|
|
66
|
+
└── task-0.md
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from brainfile import ensureV2Dirs, addTaskFile, readTasksDir, completeTaskFile
|
|
73
|
+
|
|
74
|
+
# Initialize workspace
|
|
75
|
+
dirs = ensureV2Dirs(".brainfile/brainfile.md")
|
|
76
|
+
|
|
77
|
+
# Add a task
|
|
78
|
+
result = addTaskFile(
|
|
79
|
+
dirs.boardDir,
|
|
80
|
+
{"title": "Implement auth", "column": "in-progress", "priority": "high"},
|
|
81
|
+
body="## Description\nAdd JWT authentication to the API.\n",
|
|
82
|
+
)
|
|
83
|
+
print(result["task"].id) # "task-1"
|
|
84
|
+
|
|
85
|
+
# List all active tasks
|
|
86
|
+
for doc in readTasksDir(dirs.boardDir):
|
|
87
|
+
t = doc.task
|
|
88
|
+
print(f"{t.id}: {t.title} [{t.column}]")
|
|
89
|
+
|
|
90
|
+
# Complete a task (moves to logs/)
|
|
91
|
+
completeTaskFile(result["filePath"], dirs.logsDir)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Task File Operations
|
|
95
|
+
|
|
96
|
+
Read and write individual task files.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from brainfile import readTaskFile, writeTaskFile, findV2Task, getV2Dirs
|
|
100
|
+
|
|
101
|
+
# Read a single task
|
|
102
|
+
doc = readTaskFile(".brainfile/board/task-1.md")
|
|
103
|
+
print(doc.task.title)
|
|
104
|
+
print(doc.body) # Markdown content below frontmatter
|
|
105
|
+
|
|
106
|
+
# Find a task across board and logs
|
|
107
|
+
dirs = getV2Dirs(".brainfile/brainfile.md")
|
|
108
|
+
result = findV2Task(dirs, "task-1", searchLogs=True)
|
|
109
|
+
if result:
|
|
110
|
+
print(result["doc"].task.title, "in", "logs" if result["isLog"] else "board")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Contracts
|
|
114
|
+
|
|
115
|
+
Tasks can carry formal contracts for AI agent coordination: deliverables, validation commands, constraints, and feedback for rework.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from brainfile import readTaskFile, writeTaskFile, Contract, Deliverable
|
|
119
|
+
|
|
120
|
+
doc = readTaskFile(".brainfile/board/task-1.md")
|
|
121
|
+
task = doc.task
|
|
122
|
+
|
|
123
|
+
# Attach a contract
|
|
124
|
+
task.contract = Contract(
|
|
125
|
+
status="ready",
|
|
126
|
+
deliverables=[
|
|
127
|
+
Deliverable(path="src/auth.py", description="JWT auth module"),
|
|
128
|
+
Deliverable(path="tests/test_auth.py", description="Unit tests"),
|
|
129
|
+
],
|
|
130
|
+
validation={"commands": ["pytest tests/test_auth.py"]},
|
|
131
|
+
constraints=["Use PyJWT library", "Token expiry must be configurable"],
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
writeTaskFile(".brainfile/board/task-1.md", task, doc.body)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Contract Lifecycle
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
ready → in_progress → delivered → done
|
|
141
|
+
│ │
|
|
142
|
+
└─────────→ failed ←────┘
|
|
143
|
+
(add feedback, reset to ready)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from brainfile import setTaskContractStatus
|
|
148
|
+
|
|
149
|
+
# Agent picks up work
|
|
150
|
+
setTaskContractStatus(board, "task-1", "in_progress")
|
|
151
|
+
|
|
152
|
+
# Agent delivers
|
|
153
|
+
setTaskContractStatus(board, "task-1", "delivered")
|
|
154
|
+
|
|
155
|
+
# PM validates
|
|
156
|
+
setTaskContractStatus(board, "task-1", "done")
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Board Operations (V1)
|
|
160
|
+
|
|
161
|
+
Immutable operations on in-memory board objects. Useful for single-file workflows or building custom tools.
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from brainfile import Brainfile, add_task, move_task, patch_task, TaskInput, TaskPatch
|
|
165
|
+
|
|
166
|
+
# Parse a brainfile
|
|
167
|
+
result = Brainfile.parse(markdown_content)
|
|
168
|
+
board = result.board
|
|
169
|
+
|
|
170
|
+
# Add a task
|
|
171
|
+
result = add_task(board, "todo", TaskInput(title="New task", priority="high"))
|
|
172
|
+
board = result.board
|
|
173
|
+
|
|
174
|
+
# Move between columns
|
|
175
|
+
result = move_task(board, "task-1", "todo", "in-progress")
|
|
176
|
+
|
|
177
|
+
# Patch fields
|
|
178
|
+
result = patch_task(board, "task-1", TaskPatch(tags=["urgent"], assignee="codex"))
|
|
179
|
+
|
|
180
|
+
# Serialize back
|
|
181
|
+
output = Brainfile.serialize(board)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Queries
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from brainfile import (
|
|
188
|
+
find_task_by_id,
|
|
189
|
+
get_all_tasks,
|
|
190
|
+
get_tasks_by_tag,
|
|
191
|
+
get_tasks_by_assignee,
|
|
192
|
+
search_tasks,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
task_info = find_task_by_id(board, "task-1")
|
|
196
|
+
urgent = get_tasks_by_tag(board, "urgent")
|
|
197
|
+
results = search_tasks(board, "auth")
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Validation and Linting
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from brainfile import BrainfileValidator, BrainfileLinter, LintOptions
|
|
204
|
+
|
|
205
|
+
# Validate board structure
|
|
206
|
+
result = BrainfileValidator.validate(board)
|
|
207
|
+
for error in result.errors:
|
|
208
|
+
print(f"{error.path}: {error.message}")
|
|
209
|
+
|
|
210
|
+
# Lint with auto-fix
|
|
211
|
+
result = BrainfileLinter.lint(content, LintOptions(auto_fix=True))
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## File Discovery
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from brainfile import discover, find_nearest_brainfile, isV2
|
|
218
|
+
|
|
219
|
+
# Find brainfiles in a project
|
|
220
|
+
result = discover("/path/to/project")
|
|
221
|
+
for f in result.files:
|
|
222
|
+
print(f"{f.name}: {f.item_count} tasks")
|
|
223
|
+
|
|
224
|
+
# Walk up to find nearest brainfile
|
|
225
|
+
path = find_nearest_brainfile()
|
|
226
|
+
|
|
227
|
+
# Check if a workspace is v2
|
|
228
|
+
if isV2(".brainfile/brainfile.md"):
|
|
229
|
+
print("V2 workspace detected")
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Ecosystem
|
|
233
|
+
|
|
234
|
+
| Package | Description |
|
|
235
|
+
|---------|-------------|
|
|
236
|
+
| [brainfile (Python)](https://github.com/brainfile/py) | This library |
|
|
237
|
+
| [@brainfile/core](https://github.com/brainfile/core) | TypeScript core library |
|
|
238
|
+
| [@brainfile/cli](https://github.com/brainfile/cli) | CLI with TUI and MCP server |
|
|
239
|
+
| [Protocol](https://github.com/brainfile/protocol) | Specification and JSON Schema |
|
|
240
|
+
|
|
241
|
+
## Development
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
git clone https://github.com/brainfile/py.git
|
|
245
|
+
cd py
|
|
246
|
+
uv sync --dev
|
|
247
|
+
uv run pytest
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
MIT
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/brainfile/core/main/logo.png" alt="Brainfile Logo" width="128" height="128">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# brainfile
|
|
6
|
+
|
|
7
|
+
**The Python engine behind [Brainfile](https://brainfile.md).**
|
|
8
|
+
|
|
9
|
+
This library provides the core logic for managing Brainfile v2 projects: reading/writing task files, managing contracts, validating boards, and querying task state. It is the Python equivalent of [@brainfile/core](https://github.com/brainfile/core) with full API parity.
|
|
10
|
+
|
|
11
|
+
Used by [Cecli](https://github.com/dwash96/cecli) and other tools that need programmatic access to Brainfile workspaces.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install brainfile
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or with [uv](https://github.com/astral-sh/uv):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv add brainfile
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## v2 Architecture
|
|
26
|
+
|
|
27
|
+
Brainfile v2 uses a directory-based structure. Each task is its own markdown file.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
.brainfile/
|
|
31
|
+
├── brainfile.md # Board config (columns, types, rules)
|
|
32
|
+
├── board/ # Active tasks
|
|
33
|
+
│ ├── task-1.md
|
|
34
|
+
│ └── task-2.md
|
|
35
|
+
└── logs/ # Completed tasks (history)
|
|
36
|
+
└── task-0.md
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from brainfile import ensureV2Dirs, addTaskFile, readTasksDir, completeTaskFile
|
|
43
|
+
|
|
44
|
+
# Initialize workspace
|
|
45
|
+
dirs = ensureV2Dirs(".brainfile/brainfile.md")
|
|
46
|
+
|
|
47
|
+
# Add a task
|
|
48
|
+
result = addTaskFile(
|
|
49
|
+
dirs.boardDir,
|
|
50
|
+
{"title": "Implement auth", "column": "in-progress", "priority": "high"},
|
|
51
|
+
body="## Description\nAdd JWT authentication to the API.\n",
|
|
52
|
+
)
|
|
53
|
+
print(result["task"].id) # "task-1"
|
|
54
|
+
|
|
55
|
+
# List all active tasks
|
|
56
|
+
for doc in readTasksDir(dirs.boardDir):
|
|
57
|
+
t = doc.task
|
|
58
|
+
print(f"{t.id}: {t.title} [{t.column}]")
|
|
59
|
+
|
|
60
|
+
# Complete a task (moves to logs/)
|
|
61
|
+
completeTaskFile(result["filePath"], dirs.logsDir)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Task File Operations
|
|
65
|
+
|
|
66
|
+
Read and write individual task files.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from brainfile import readTaskFile, writeTaskFile, findV2Task, getV2Dirs
|
|
70
|
+
|
|
71
|
+
# Read a single task
|
|
72
|
+
doc = readTaskFile(".brainfile/board/task-1.md")
|
|
73
|
+
print(doc.task.title)
|
|
74
|
+
print(doc.body) # Markdown content below frontmatter
|
|
75
|
+
|
|
76
|
+
# Find a task across board and logs
|
|
77
|
+
dirs = getV2Dirs(".brainfile/brainfile.md")
|
|
78
|
+
result = findV2Task(dirs, "task-1", searchLogs=True)
|
|
79
|
+
if result:
|
|
80
|
+
print(result["doc"].task.title, "in", "logs" if result["isLog"] else "board")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Contracts
|
|
84
|
+
|
|
85
|
+
Tasks can carry formal contracts for AI agent coordination: deliverables, validation commands, constraints, and feedback for rework.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from brainfile import readTaskFile, writeTaskFile, Contract, Deliverable
|
|
89
|
+
|
|
90
|
+
doc = readTaskFile(".brainfile/board/task-1.md")
|
|
91
|
+
task = doc.task
|
|
92
|
+
|
|
93
|
+
# Attach a contract
|
|
94
|
+
task.contract = Contract(
|
|
95
|
+
status="ready",
|
|
96
|
+
deliverables=[
|
|
97
|
+
Deliverable(path="src/auth.py", description="JWT auth module"),
|
|
98
|
+
Deliverable(path="tests/test_auth.py", description="Unit tests"),
|
|
99
|
+
],
|
|
100
|
+
validation={"commands": ["pytest tests/test_auth.py"]},
|
|
101
|
+
constraints=["Use PyJWT library", "Token expiry must be configurable"],
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
writeTaskFile(".brainfile/board/task-1.md", task, doc.body)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Contract Lifecycle
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
ready → in_progress → delivered → done
|
|
111
|
+
│ │
|
|
112
|
+
└─────────→ failed ←────┘
|
|
113
|
+
(add feedback, reset to ready)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from brainfile import setTaskContractStatus
|
|
118
|
+
|
|
119
|
+
# Agent picks up work
|
|
120
|
+
setTaskContractStatus(board, "task-1", "in_progress")
|
|
121
|
+
|
|
122
|
+
# Agent delivers
|
|
123
|
+
setTaskContractStatus(board, "task-1", "delivered")
|
|
124
|
+
|
|
125
|
+
# PM validates
|
|
126
|
+
setTaskContractStatus(board, "task-1", "done")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Board Operations (V1)
|
|
130
|
+
|
|
131
|
+
Immutable operations on in-memory board objects. Useful for single-file workflows or building custom tools.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from brainfile import Brainfile, add_task, move_task, patch_task, TaskInput, TaskPatch
|
|
135
|
+
|
|
136
|
+
# Parse a brainfile
|
|
137
|
+
result = Brainfile.parse(markdown_content)
|
|
138
|
+
board = result.board
|
|
139
|
+
|
|
140
|
+
# Add a task
|
|
141
|
+
result = add_task(board, "todo", TaskInput(title="New task", priority="high"))
|
|
142
|
+
board = result.board
|
|
143
|
+
|
|
144
|
+
# Move between columns
|
|
145
|
+
result = move_task(board, "task-1", "todo", "in-progress")
|
|
146
|
+
|
|
147
|
+
# Patch fields
|
|
148
|
+
result = patch_task(board, "task-1", TaskPatch(tags=["urgent"], assignee="codex"))
|
|
149
|
+
|
|
150
|
+
# Serialize back
|
|
151
|
+
output = Brainfile.serialize(board)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Queries
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from brainfile import (
|
|
158
|
+
find_task_by_id,
|
|
159
|
+
get_all_tasks,
|
|
160
|
+
get_tasks_by_tag,
|
|
161
|
+
get_tasks_by_assignee,
|
|
162
|
+
search_tasks,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
task_info = find_task_by_id(board, "task-1")
|
|
166
|
+
urgent = get_tasks_by_tag(board, "urgent")
|
|
167
|
+
results = search_tasks(board, "auth")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Validation and Linting
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from brainfile import BrainfileValidator, BrainfileLinter, LintOptions
|
|
174
|
+
|
|
175
|
+
# Validate board structure
|
|
176
|
+
result = BrainfileValidator.validate(board)
|
|
177
|
+
for error in result.errors:
|
|
178
|
+
print(f"{error.path}: {error.message}")
|
|
179
|
+
|
|
180
|
+
# Lint with auto-fix
|
|
181
|
+
result = BrainfileLinter.lint(content, LintOptions(auto_fix=True))
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## File Discovery
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from brainfile import discover, find_nearest_brainfile, isV2
|
|
188
|
+
|
|
189
|
+
# Find brainfiles in a project
|
|
190
|
+
result = discover("/path/to/project")
|
|
191
|
+
for f in result.files:
|
|
192
|
+
print(f"{f.name}: {f.item_count} tasks")
|
|
193
|
+
|
|
194
|
+
# Walk up to find nearest brainfile
|
|
195
|
+
path = find_nearest_brainfile()
|
|
196
|
+
|
|
197
|
+
# Check if a workspace is v2
|
|
198
|
+
if isV2(".brainfile/brainfile.md"):
|
|
199
|
+
print("V2 workspace detected")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Ecosystem
|
|
203
|
+
|
|
204
|
+
| Package | Description |
|
|
205
|
+
|---------|-------------|
|
|
206
|
+
| [brainfile (Python)](https://github.com/brainfile/py) | This library |
|
|
207
|
+
| [@brainfile/core](https://github.com/brainfile/core) | TypeScript core library |
|
|
208
|
+
| [@brainfile/cli](https://github.com/brainfile/cli) | CLI with TUI and MCP server |
|
|
209
|
+
| [Protocol](https://github.com/brainfile/protocol) | Specification and JSON Schema |
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
git clone https://github.com/brainfile/py.git
|
|
215
|
+
cd py
|
|
216
|
+
uv sync --dev
|
|
217
|
+
uv run pytest
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
MIT
|