Nicholai dc0cd40b13
feat(agent): add Claude Code bridge integration (#60)
Add local daemon that routes inference through user's own Anthropic
API key with filesystem and terminal access. Includes WebSocket
transport, MCP tool adapter, and API key auth.

Key components:
- compass-bridge package: local daemon with tool registry
- WebSocket transport for agent communication
- MCP API key management with HMAC auth and scoped permissions
- Usage tracking (tool calls, duration, success/failure)
- Settings UI for Claude Code configuration
- Migration 0019: mcp_api_keys and mcp_usage tables
- Test suite for auth and transport layers

Co-authored-by: Nicholai <nicholaivogelfilms@gmail.com>
2026-02-09 00:29:00 -07:00

92 lines
2.5 KiB
TypeScript

// system prompt builder for the bridge daemon
import { hostname, platform, userInfo } from "os"
import type { RegisterResult } from "./auth"
export function buildSystemPrompt(
context: RegisterResult,
): string {
const user = context.user
const now = new Date()
const date = now.toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
})
const sections: string[] = []
// anthropic's claude max oauth endpoint requires
// this prefix in the system prompt
sections.push(
"You are Claude Code, Anthropic's official CLI " +
"for Claude.\n\n" +
"You are Dr. Slab Diggems, the AI assistant for " +
"Compass -- a construction project management " +
"platform. You are running via the compass-bridge " +
"daemon on the user's local machine, giving you " +
"access to both Compass data and local files.",
)
sections.push(
`## User Context\n` +
`- Name: ${user.name}\n` +
`- Role: ${user.role}\n` +
`- Date: ${date}\n` +
`- Machine: ${userInfo().username}@${hostname()}\n` +
`- Platform: ${platform()}`,
)
if (context.memories) {
sections.push(
`## What You Remember About This User\n` +
context.memories,
)
}
// tool descriptions
const compassTools = context.tools
.map(
(t) =>
`- ${t.name} [${t.scope}]: ${t.description}`,
)
.join("\n")
const localTools = [
"- readFile: Read a file on the user's machine",
"- writeFile: Write content to a file",
"- listDirectory: List directory contents",
"- searchFiles: Search for files by glob pattern",
"- runCommand: Execute a shell command",
].join("\n")
sections.push(
`## Available Tools\n\n` +
`### Compass Tools (remote)\n${compassTools}\n\n` +
`### Local Tools\n${localTools}`,
)
if (context.dashboards.length > 0) {
const list = context.dashboards
.map((d) => `- ${d.name}: ${d.description}`)
.join("\n")
sections.push(`## Saved Dashboards\n${list}`)
}
sections.push(
"## Guidelines\n" +
"- You have access to the user's local file " +
"system and terminal. Use this to help with " +
"development tasks, file management, and builds.\n" +
"- For Compass data (projects, customers, " +
"invoices, etc.), use the Compass tools.\n" +
"- Be direct and helpful. If you need to run " +
"a command or read a file, just do it.\n" +
"- When running commands, show the output to " +
"the user.",
)
return sections.join("\n\n")
}