Skip to content

Commit b3faf62

Browse files
committed
update claude.md to reference mofa framework usage guide
1 parent ec2afe9 commit b3faf62

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

.claude/CLAUDE.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Git Conventions
6+
7+
- **Commit file by file**: Always commit changes file by file to create many small, focused commits. This makes the git history easier to review and understand.
8+
- **Commit messages**: Keep commit messages short and lowercase. Use descriptive but concise messages.
9+
- **Never use Co-Authored-By**: Never add `Co-Authored-By` trailers to commit messages.
10+
11+
## Build & Development Commands
12+
13+
```bash
14+
# Build the binary
15+
cargo build --release
16+
17+
# Install CLI from source
18+
cargo install --path cli/
19+
20+
# Run directly
21+
cargo run --release -- <command>
22+
23+
# Run tests
24+
cargo test
25+
26+
# Run tests for a specific crate
27+
cargo test -p mofaclaw-core
28+
29+
# Run a single test
30+
cargo test -p mofaclaw-core <test_name>
31+
32+
# Format code
33+
cargo fmt
34+
35+
# Lint
36+
cargo clippy
37+
38+
# Check without building
39+
cargo check
40+
```
41+
42+
## Toolchain
43+
44+
Rust stable (1.85+) with `rustfmt` and `clippy` components (see `rust-toolchain.toml`).
45+
46+
## Architecture
47+
48+
mofaclaw is a Rust-based personal AI assistant with a workspace/workspace structure split into two crates:
49+
50+
- **`core/`** (`mofaclaw-core`) — The library crate containing all core logic
51+
- **`cli/`** (`mofaclaw`) — The binary crate providing the `mofaclaw` CLI
52+
53+
### Core Subsystems (`core/src/`)
54+
55+
| Module | Purpose |
56+
|--------|---------|
57+
| `agent/` | Agent loop (`loop_.rs`), context builder (`context.rs`), subagent manager (`subagent.rs`) |
58+
| `tools/` | Built-in tools: filesystem, shell, web fetch/search, spawn (subagents), message |
59+
| `provider/` | Thin re-export layer over `mofa_sdk::llm` — no direct LLM code here |
60+
| `channels/` | Channel integrations: Telegram, Discord, DingTalk, Feishu, WhatsApp |
61+
| `bus/` | Async `MessageBus` (MPSC queue) decoupling channels from the agent loop |
62+
| `session/` | Conversation history via `mofa_sdk`'s JSONL-backed `SessionManager` |
63+
| `rbac/` | Role-Based Access Control for tools, skills, and filesystem paths |
64+
| `cron/` | Scheduled task execution via cron expressions |
65+
| `heartbeat/` | Periodic proactive wake-up service |
66+
| `config.rs` | Config loading from `~/.mofaclaw/config.json` |
67+
| `messages.rs` | `InboundMessage` / `OutboundMessage` types for bus communication |
68+
69+
### Key Dependency: `mofa-sdk`
70+
71+
LLM interaction, session storage, skills, and the agent loop core are delegated to the `mofa-sdk` crate (`mofa_sdk`). The `AgentLoop` wraps `mofa_sdk::llm::AgentLoop` and `TaskOrchestrator`. The `provider/mod.rs` re-exports `mofa_sdk::llm` types — no direct HTTP LLM calls exist in this codebase.
72+
73+
**IMPORTANT**: Always use MoFA framework components (`mofa-sdk`) for LLM interactions, agent creation, and tool execution. See [MoFA Framework Usage Guide](.claude/mofa-framework-usage.md) for detailed standards and patterns.
74+
75+
### Data Flow
76+
77+
```
78+
Channel (Telegram/Discord/etc.)
79+
↓ InboundMessage
80+
MessageBus (async MPSC)
81+
82+
AgentLoop
83+
→ ContextBuilder (builds system prompt from workspace files)
84+
→ mofa_sdk LLMAgent (LLM call)
85+
→ ToolRegistry (execute tool calls)
86+
↓ OutboundMessage
87+
MessageBus
88+
89+
Channel (send reply)
90+
```
91+
92+
### Workspace Files (`workspace/`)
93+
94+
The agent's personality and context come from markdown files in the configured workspace directory (default `~/.mofaclaw/workspace/`):
95+
- `SOUL.md` — Agent personality/values
96+
- `USER.md` — User profile
97+
- `HEARTBEAT.md` — Heartbeat/proactive message instructions
98+
- `AGENTS.md` — Subagent definitions
99+
- `TOOLS.md` — Tool configuration
100+
- `memory/MEMORY.md` — Persistent memory
101+
102+
### Skills (`skills/`)
103+
104+
Bundled skills live in `skills/<name>/SKILL.md` with YAML frontmatter. Workspace-local skills in `<workspace>/skills/` override bundled ones with the same name.
105+
106+
### RBAC
107+
108+
The RBAC system (`core/src/rbac/`) controls per-user access to tools and filesystem paths. Configured via `rbac` key in `~/.mofaclaw/config.json`. Channel-level `allow_from` lists provide coarse-grained access control before RBAC applies.
109+
110+
## Config File
111+
112+
`~/.mofaclaw/config.json` — loaded by `load_config()` in `core/src/config.rs`. Data directory: `~/.mofaclaw/data/`. Sessions stored as JSONL in `~/.mofaclaw/data/sessions/`.

0 commit comments

Comments
 (0)