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)
System Tools (require trust level ≥ 2)
Write Tools (require trust level ≥ 3, user approval at level 3)
At trust level 3 (Agent), write tools prompt the user for approval. At trust level 4 (Sovereign), no approval is needed.
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