kagan-legacy
AGENTS.md106 starsChanged 9 months agoMITArchived repositoryView on GitHub
Generated: 2026-03-13 Commit: ddf5c5f Branch: feat/remote-clients Kagan — AI-powered Kanban TUI (Python 3.12+/Textual) that orchestrates coding agents on your codebase. Supports 14 agent backends, auto/pair execution modes, MCP protocol, and a bundled web dashboard (React 19).
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- docs/llms.txtllms.txt
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
14 rules. About 0 are common, 1 is distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 60
DB access: Always via _db_sync/_db_async helpers wrapping SQLModel sessions
- Very specific: line 63
Error hierarchy: All errors inherit KaganError (see core/errors.py)
- Distinctive: line 66
Type annotations: All public functions typed.
- Very specific: line 89
NEVER: add direct SQLAlchemy session usage — always use _db_sync/_db_async
- Very specific: line 90
NEVER: import from _-prefixed modules outside their parent package
- Very specific: line 92
DO NOT: use stdlib logging — use loguru
- Very specific: line 93
DO NOT: put test fixtures in test files — use tests/helpers/
- Very specific: line 94
DO NOT: write task.status = X outside a _db_sync/_db_async callback or the files listed above — use transition_task instead
- Very specific: line 95
DO NOT: use /api/chat/sessions/{id}/watch or /messages?after_id= — these were removed in W9a cleanup.
- Very specific: line 96
DO NOT: write task.status or session.status directly in EventLog frame producers — frames are supplementary.
- Very specific: line 160
Do not bypass apiClient; keep HTTP calls centralized in src/lib/api/client.ts.
- Very specific: line 161
Do not add global styles outside src/app.css.
- Very specific: line 162
Use @/ path alias for imports (maps to src/).
- Very specific: line 169
All HTTP calls go through KaganClient — no raw fetch in providers.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PROJECT KNOWLEDGE BASE
Generated: 2026-03-13 Commit: ddf5c5f Branch: feat/remote-clients
OVERVIEW
Kagan — AI-powered Kanban TUI (Python 3.12+/Textual) that orchestrates coding agents on your codebase. Supports 14 agent backends, auto/pair execution modes, MCP protocol, and a bundled web dashboard (React 19).
STRUCTURE
kagan/
├── src/kagan/ # Python package (core logic, TUI, CLI, MCP, server)
│ ├── core/ # Domain: DB, models, agents, tasks, sessions, worktrees
│ ├── tui/ # Textual TUI: screens/, widgets/, styles/
│ ├── cli/ # Click CLI surface (entrypoint: `kagan`/`kg`)
│ ├── mcp/ # MCP server: toolsets/, prompts, resources
│ ├── server/ # HTTP server: REST API, SSE streaming, auth, web UI
│ ├── chat/ # CLI chat REPL: ACP streaming, commands, sessions
│ ├── crypto/ # X25519 key exchange, TLS, tokens, QR
│ ├── wire/ # (compat shim) Re-exports envelope types
│ └── integrations/ # Typed native integrations (GitHub, future: Jira/Linear)
├── packages/
│ ├── vscode/ # VS Code extension: chat participant, tree view, SCM, reviews
│ ├── web/ # React 19 + jotai + Tailwind CSS 4 web dashboard (SPA)
│ └── wire/ # (removed — TS types now generated from response models)
├── tests/ # pytest: core/, tui/, mcp/, server/, unit/, helpers/
├── scripts/ # Build/quality scripts (LOC budget, web build)
├── docs/ # MkDocs documentation site
├── registry/ # Persona repo whitelist
└── references/ # External reference repos (NOT part of build)WHERE TO LOOK
| Task | Location | Notes |
| Add CLI command | src/kagan/cli/ | Click group in main.py, lazy-loaded modules |
| Add MCP tool | src/kagan/mcp/toolsets/ | One file per domain, use get_context() |
| Add TUI screen | src/kagan/tui/screens/ | Register in app.py SCREENS dict |
| Add TUI widget | src/kagan/tui/widgets/ | Follow Textual compose pattern |
| Modify task lifecycle | src/kagan/core/_transitions.py | State machine for task status |
| Add agent backend | src/kagan/core/_agent.py | AGENT_BACKENDS registry dict |
| Add DB migration | alembic -c alembic.ini revision --autogenerate -m "msg" | Via poe db-migration-generate |
| Wire protocol change | src/kagan/server/responses.py | Response models → JSON Schema → TypeScript via scripts/generate_wire_types.py |
| Add SSE event channel | src/kagan/server/_event_routes.py | Register route + hook into register_event_routes(mcp) in server.py |
| Add frame consumer | src/kagan/tui/_event_source.py / packages/web/src/lib/hooks/use-entry-stream.ts / packages/vscode/src/api/event-source.ts | TUI: implement InProcEventSource/HttpEventSource interface; Web: use useEntryStream; VS Code: use KaganEventSource |
| Web UI feature | packages/web/src/ | React 19 + jotai + Tailwind CSS 4 |
| API endpoint | src/kagan/server/_routes.py | Starlette routes via FastMCP |
| Add integration | src/kagan/core/integrations/ | Implement Integration protocol, register in all_enabled() |
| VS Code feature | packages/vscode/src/providers/ | One provider per VS Code API surface |
| VS Code command | packages/vscode/src/commands/ | Register in extension.ts |
| Modify prompt system | src/kagan/core/_prompts.py | Three-layer resolution: dotfile → defaults + behavioral → additional instructions |
CONVENTIONS
- Private modules: Underscore prefix (
_tasks.py,_agent.py) = internal;client.py,models.py,enums.py= public API - DB access: Always via
_db_sync/_db_asynchelpers wrapping SQLModel sessions - Async pattern:
asyncio.to_threadfor DB ops, native async for I/O - Logging:
loguru.loggereverywhere (not stdlib logging) - Error hierarchy: All errors inherit
KaganError(seecore/errors.py) - LOC budget: 2500 lines max per Python file (enforced via
poe check-loc) - Complexity cap: McCabe max-complexity = 20 (ruff C90)
- Type annotations: All public functions typed; pyrefly for typechecking (not mypy)
- MCP annotations: TC001/TC002/TC003 suppressed in
src/kagan/mcp/— MCP evaluates annotations at runtime - Prompt resolution: Three-layer pipeline in
core/_prompts.py— dotfile override → code defaults + behavioral settings → additional instructions - Settings keys: Behavioral controls (
default_execution_mode,review_strictness,planning_depth,auto_confirm_single_tasks) + singleadditional_instructionsfield
Status mutations
task.status and session.status may only be written through
kagan.core.transitions.transition_task and transition_session. Direct
assignments (task.status = ...) bypass review gates and are forbidden in
external-facing code paths (REST routes, MCP tools, CLI commands).
The funnel functions enforce the (from, to) matrix at runtime; if you
encounter a transition the matrix does not cover, add a match arm with the
appropriate guard rather than working around the funnel.
Exceptions: raw DB writes inside _db_sync / _db_async callbacks that
operate at the SQLAlchemy layer (e.g. _orphan_reap.py, _sessions.py
internal helpers) may assign .status directly when they cannot call the
async funnel from within a sync transaction context.
ANTI-PATTERNS (THIS PROJECT)
- NEVER suppress types with
as any/@ts-ignore/# type: ignorewithout documented reason - NEVER add direct SQLAlchemy session usage — always use
_db_sync/_db_async - NEVER import from
_-prefixed modules outside their parent package - NEVER modify migration files after they ship — generate a new migration
- DO NOT use stdlib
logging— useloguru - DO NOT put test fixtures in test files — use
tests/helpers/ - DO NOT write
task.status = Xoutside a_db_sync/_db_asynccallback or the files listed above — usetransition_taskinstead - DO NOT use
/api/chat/sessions/{id}/watchor/messages?after_id=— these were removed in W9a cleanup; subscribe viaGET /api/sessions/{id}/eventswithLast-Event-IDfor resume - DO NOT write
task.statusorsession.statusdirectly in EventLog frame producers — frames are supplementary; status transitions still go throughtransition_task/transition_session - RUF012 / RUF006 / SIM102 / SIM117 intentionally suppressed (see pyproject.toml)
COMMANDS
# Development
uv run poe dev # Run TUI in dev mode (textual dev server)
uv run poe test # Run all tests (pytest, parallel)
uv run poe lint # Ruff lint
uv run poe format # Ruff format
uv run poe typecheck # Pyrefly typecheck
uv run poe deadcode # Vulture dead code detection
uv run poe check # All: lint + typecheck + deadcode + test
uv run poe check-guardrails # LOC budget + complexity check
uv run poe fix # Auto-fix lint + format
# Database
uv run poe db-migration-generate "migration message"
uv run poe db-migrations-check
# Web
uv run poe web-build # Build React app → src/kagan/server/_web_static/
uv run poe docs-dev # MkDocs dev server
# Install
uv run poe install-local # Install as local CLI tool
uv run poe dev-setup # Install + reset DB + stop daemon
# Snapshots
uv run poe snapshot-update # Update TUI snapshot testsDEEP DIVE DOCS
| Module | Architecture Doc | Features Doc |
| core | docs/internal/architecture/core.md | docs/internal/features/core.md |
| tui | docs/internal/architecture/tui.md | docs/internal/features/tui.md |
| server | docs/internal/architecture/server.md | docs/internal/features/server.md |
| web | docs/internal/architecture/web.md | docs/internal/features/web.md |
| vscode | docs/internal/architecture/vscode.md | docs/internal/features/vscode.md |
TypeScript / Web Checks
cd packages/web && pnpm exec vitest run
cd packages/web && pnpm exec playwright test # requires running server (`kagan web`)
cd packages/web && pnpm run buildTypeScript / VS Code Extension Checks
cd packages/vscode && pnpm run check-types
cd packages/vscode && pnpm run test:unit
cd packages/vscode && pnpm run test:integration
cd packages/vscode && pnpm run test:e2eModule Pitfalls
web
- Do not bypass
apiClient; keep HTTP calls centralized insrc/lib/api/client.ts. - Do not add global styles outside
src/app.css; keep overrides inside component<style>blocks. - Use
@/path alias for imports (maps tosrc/). - State management via jotai atoms — no class-based stores.
vscode
- Event type strings come from
EVENT_TYPE/SSE_TYPEconsts inapi/types.ts— never hand-type event strings. - ACP payloads nest tool data under
payload.acp— useacpPayload()helpers, not direct field access. - All HTTP calls go through
KaganClient— no rawfetchin providers. - One provider per VS Code API surface — do not mix concerns.
NOTES
references/contains external repos for study — excluded from build/test/lint.claude/worktrees/are agent worktrees — excluded from analysisCLAUDE.mdis a symlink toAGENTS.md- Pre-commit runs: gitleaks, ruff lint/format, pyrefly, mdformat, uv-lock
- CI pipeline: lint → fast-gate (unit) → test-pr (full suite, matrix: py3.12-3.14, ubuntu/macos/windows)
- Semantic release on main: conventional commits, beta prereleases
- Web UI is bundled as static files into the Python package at build time
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

