Skip to content

Commit d2193d4

Browse files
jahoomaclaude
andcommitted
Refactor knowledge.md into AGENTS.md + docs/ directory
Move detailed documentation from knowledge.md into dedicated files under docs/, keeping AGENTS.md as a lightweight table of contents. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 83b334c commit d2193d4

File tree

8 files changed

+155
-141
lines changed

8 files changed

+155
-141
lines changed

AGENTS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Codebuff
2+
3+
Codebuff is a tool for editing codebases via natural-language instructions to Buffy (an expert AI programming assistant).
4+
5+
## Goals
6+
7+
- Make expert engineers faster (power-user focus).
8+
- Reduce time/effort for common programming tasks.
9+
- Improve via iteration/feedback (learn/adapt from usage).
10+
11+
## Key Technologies
12+
13+
- TypeScript monorepo (Bun workspaces)
14+
- Bun runtime + package manager
15+
- Next.js (web app + API routes)
16+
- Multiple LLM providers (Anthropic/OpenAI/Gemini/etc.)
17+
18+
## Repo Map
19+
20+
- `cli/` — TUI client (OpenTUI + React) and local UX
21+
- `sdk/` — JS/TS SDK used by the CLI and external users
22+
- `web/` — Next.js app + API routes (the "web API")
23+
- `packages/agent-runtime/` — agent runtime + tool handling (server-side)
24+
- `common/` — shared types, tools, schemas, utilities
25+
- `agents/` — main agents shipped with codebuff
26+
- `.agents/` — local agent templates (prompt + programmatic agents)
27+
28+
## Docs
29+
30+
- [`docs/architecture.md`](docs/architecture.md) — Package dependency graph, per-package details, key architectural patterns
31+
- [`docs/request-flow.md`](docs/request-flow.md) — Full request lifecycle from CLI through server and back
32+
- [`docs/error-schema.md`](docs/error-schema.md) — Server error response formats and client-side handling
33+
- [`docs/error-handling.md`](docs/error-handling.md) — ErrorOr pattern for return values
34+
- [`docs/development.md`](docs/development.md) — Dev setup, worktrees, logs, package management, DB migrations
35+
- [`docs/testing.md`](docs/testing.md) — Testing conventions, DI over mocking, tmux CLI testing
36+
- [`docs/environment-variables.md`](docs/environment-variables.md) — Env var rules, DI helpers, loading order
37+
- [`docs/agents-and-tools.md`](docs/agents-and-tools.md) — Agent system, shell shims, tool definitions, referral system
38+
- [`docs/git-guidelines.md`](docs/git-guidelines.md) — Git safety rules

docs/agents-and-tools.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Agents and Tools
2+
3+
## Agents
4+
5+
- Prompt/programmatic agents live in `.agents/` (programmatic agents use `handleSteps` generators).
6+
- Generator functions execute in a sandbox; agent templates define tool access and subagents.
7+
8+
### Shell Shims
9+
10+
Direct commands without `codebuff` prefix:
11+
12+
```bash
13+
codebuff shims install codebuff/base-lite@1.0.0
14+
eval "$(codebuff shims env)"
15+
base-lite "fix this bug"
16+
```
17+
18+
## Tools
19+
20+
- Tool definitions live in `common/src/tools` and are executed via the SDK helpers + agent-runtime.
21+
22+
## Referral System
23+
24+
Referral codes are applied via the CLI (web onboarding only instructs the user); see `web/src/app/api/referrals/helpers.ts`.

docs/development.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Development
2+
3+
## Getting Started
4+
5+
Start the web server first:
6+
7+
```bash
8+
bun up
9+
```
10+
11+
Then start the CLI separately:
12+
13+
```bash
14+
bun start-cli
15+
```
16+
17+
Other service commands:
18+
19+
```bash
20+
bun ps # check running services
21+
bun down # stop services
22+
```
23+
24+
## Worktrees
25+
26+
To run multiple stacks on different ports, create `.env.development.local`:
27+
28+
```bash
29+
PORT=3001
30+
NEXT_PUBLIC_WEB_PORT=3001
31+
NEXT_PUBLIC_CODEBUFF_APP_URL=http://localhost:3001
32+
```
33+
34+
## Logs
35+
36+
Logs are in `debug/console/` (`db.log`, `studio.log`, `sdk.log`, `web.log`).
37+
38+
## Package Management
39+
40+
- Use `bun install`, `bun run ...` (avoid `npm`).
41+
42+
## Database Migrations
43+
44+
Edit schema using Drizzle's TS DSL (don't hand-write migration SQL), then run the internal DB scripts to generate/apply migrations.

docs/environment-variables.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Environment Variables
2+
3+
## Quick Rules
4+
5+
- Public client env: `NEXT_PUBLIC_*` only, validated in `common/src/env-schema.ts` (used via `@codebuff/common/env`).
6+
- Server secrets: validated in `packages/internal/src/env-schema.ts` (used via `@codebuff/internal/env`).
7+
- Runtime/OS env: pass typed snapshots instead of reading `process.env` throughout the codebase.
8+
9+
## Env DI Helpers
10+
11+
- Base contracts: `common/src/types/contracts/env.ts` (`BaseEnv`, `BaseCiEnv`, `ClientEnv`, `CiEnv`)
12+
- Helpers: `common/src/env-process.ts`, `common/src/env-ci.ts`
13+
- Test helpers: `common/src/testing-env-process.ts`, `common/src/testing-env-ci.ts`
14+
- CLI: `cli/src/utils/env.ts` (`getCliEnv`)
15+
- CLI test helpers: `cli/src/testing/env.ts` (`createTestCliEnv`)
16+
- SDK: `sdk/src/env.ts` (`getSdkEnv`)
17+
- SDK test helpers: `sdk/src/testing/env.ts` (`createTestSdkEnv`)
18+
19+
## Loading Order
20+
21+
Bun loads (highest precedence last):
22+
23+
- `.env.local` (Infisical-synced secrets, gitignored)
24+
- `.env.development.local` (worktree overrides like ports, gitignored)
25+
26+
## Releases
27+
28+
Release scripts read `CODEBUFF_GITHUB_TOKEN`.

docs/error-handling.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Error Handling
2+
3+
Prefer `ErrorOr<T>` return values (`success(...)`/`failure(...)` in `common/src/util/error.ts`) over throwing.
4+
5+
See [Error Schema](./error-schema.md) for the full server error response format and client-side handling.

docs/git-guidelines.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Git Safety Rules
2+
3+
- Never force-push `main` unless explicitly requested.
4+
- To exclude files from a commit: stage only what you want (`git add <paths>`). Never use `git restore`/`git checkout HEAD -- <file>` to "uncommit" changes.
5+
- Run interactive git commands in tmux (anything that opens an editor or prompts).

docs/testing.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Testing
2+
3+
- Prefer dependency injection over module mocking; define contracts in `common/src/types/contracts/`.
4+
- Use `spyOn()` only for globals / legacy seams.
5+
- Avoid `mock.module()` for functions; use `@codebuff/common/testing/mock-modules.ts` helpers for constants only.
6+
7+
CLI hook testing note: React 19 + Bun + RTL `renderHook()` is unreliable; prefer integration tests via components for hook behavior.
8+
9+
## CLI tmux Testing
10+
11+
For testing CLI behavior via tmux, use the helper scripts in `scripts/tmux/`. These handle bracketed paste mode and session logging automatically. Session data is saved to `debug/tmux-sessions/` in YAML format and can be viewed with `bun scripts/tmux/tmux-viewer/index.tsx`. See `scripts/tmux/README.md` for details.

knowledge.md

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)