packages/core/src/agent/.
runAgent
The entry point is runAgent, an async generator that yields typed events:
ChatApp.tsx and the CLI’s chat command both consume this generator.
Tools
The agent has access to 18 tools defined inagent/tools.ts. Tools are divided by capability level:
Quest & Life OS Tools (always available)
| Tool | Description |
|---|---|
create_quest | Create a new quest |
complete_quest | Complete a quest |
start_timer | Start a timer on a quest |
stop_timer | Stop the running timer |
abandon_quest | Abandon a quest |
list_quests | List quests with filtering |
get_status | Get character stats and overview |
analyze_patterns | Analyze completion patterns and suggest improvements |
suggest_quest | Suggest new quests based on goals |
System Tools (require trust level ≥ 2)
| Tool | Permission Required |
|---|---|
read_file | Trust ≥ 2 |
glob | Trust ≥ 2 |
grep | Trust ≥ 2 |
fetch_url | Trust ≥ 2 |
web_search | Trust ≥ 2 |
Write Tools (require trust level ≥ 3, user approval at level 3)
| Tool | Permission Required |
|---|---|
write_file | Trust ≥ 3 |
edit_file | Trust ≥ 3 |
bash | Trust ≥ 3 |
Session Persistence
agent/sessions.ts handles conversation persistence:
- Messages are stored in the
messagestable - Each conversation has a record in
conversations appendMessageadds each new message atomicallyloadSessionreconstructs the message history for a conversationcompactSessionsummarizes older messages when the context window fills
Context Compaction
agent/compaction.ts implements context window management:
- When token usage exceeds a threshold, compaction is triggered
- The oldest messages (excluding the system prompt) are summarized
- The summary replaces the compacted messages
- Conversation continues with the summary in context
/compact in the TUI.
Extended Thinking
For Anthropic models, extended thinking (chain-of-thought) is supported:reasoning events and displayed separately in the TUI.
Adding a New Tool
- Define the tool in
agent/tools.tsusing Vercel AI SDK’stool()helper - Add a permission check if it requires elevated trust
- Add the tool to the
toolsobject passed togenerateText/streamText - Add rendering logic in the TUI’s
ChatApp.tsxfor tool call display