|
1 | | -# @singularity-ai/spectra-code |
| 1 | +# Spectra Code |
2 | 2 |
|
3 | | -> TUI coding agent with CLI commands, tools, and LLM integration. |
4 | | -> |
5 | | -> ✅ Feature gap analysis completed and gap document removed. |
| 3 | +> AI coding agent in your terminal. Built on the Spectra agent framework. |
| 4 | +
|
| 5 | +Spectra Code is a terminal-native AI coding agent with a full-screen TUI, CLI commands, MCP integration, and ACP support for editor integration. It runs locally, respects your config, and keeps your API keys in a secure auth store. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **TUI** — Full-screen terminal UI with session management, model switching, and real-time streaming |
| 10 | +- **CLI** — Command-line interface for scripting and automation |
| 11 | +- **Custom Tools** — Define your own tools as `.ts` files in `.spectra/tools/`; loaded automatically alongside built-in tools |
| 12 | +- **MCP + ACP** — MCP client (stdio + HTTP) for external tool servers; ACP server (JSON-RPC 2.0) for editor integration with Zed, Neovim, JetBrains |
| 13 | +- **Multiple agents** — Build, Plan, Debug, and Explore modes with tailored tool sets |
| 14 | +- **Sessions** — Persistent session storage with fork, archive, revert, and checkpointing |
| 15 | +- **Custom providers** — Register any LLM provider via the TUI or config |
| 16 | +- **Auth store** — Secure API key management with file permissions |
| 17 | + |
| 18 | +## Install |
| 19 | + |
| 20 | +```bash |
| 21 | +bun add @mohanscodex/spectra-code |
| 22 | +``` |
| 23 | + |
| 24 | +Or run directly: |
| 25 | + |
| 26 | +```bash |
| 27 | +npx @mohanscodex/spectra-code |
| 28 | +``` |
6 | 29 |
|
7 | 30 | ## Usage |
8 | 31 |
|
| 32 | +### TUI (default) |
| 33 | + |
| 34 | +```bash |
| 35 | +spectra |
| 36 | +``` |
| 37 | + |
| 38 | +Launches the full-screen terminal UI. Navigate with keyboard shortcuts, switch models, browse sessions, and chat with agents. |
| 39 | + |
| 40 | +### CLI Commands |
| 41 | + |
| 42 | +```bash |
| 43 | +spectra session list # List all sessions |
| 44 | +spectra session delete --id <id> # Delete a session |
| 45 | +spectra agent list # List available agent modes |
| 46 | +spectra doctor # Run system health check |
| 47 | +spectra db path # Show data directory path |
| 48 | +``` |
| 49 | + |
| 50 | +#### MCP Server Management |
| 51 | + |
| 52 | +```bash |
| 53 | +spectra mcp list # List configured MCP servers |
| 54 | +spectra mcp add my-server --command "npx ..." # Add a local MCP server |
| 55 | +spectra mcp add my-api --url "https://..." # Add a remote MCP server |
| 56 | +spectra mcp connect my-server # Connect to a server |
| 57 | +spectra mcp disconnect my-server # Disconnect |
| 58 | +spectra mcp tools --server my-server # List available tools |
| 59 | +spectra mcp remove my-server # Remove from config |
| 60 | +``` |
| 61 | + |
| 62 | +### ACP |
| 63 | + |
| 64 | +Use Spectra Code as the AI agent inside your editor: |
| 65 | + |
9 | 66 | ```bash |
10 | | -# dev |
11 | | -bun dev |
| 67 | +spectra acp |
| 68 | +``` |
| 69 | + |
| 70 | +Compatible with [any editor that supports ACP](https://agentclientprotocol.com) — Zed, Neovim (avante.nvim, CodeCompanion), JetBrains, and more. |
| 71 | + |
| 72 | +#### Zed Configuration |
| 73 | + |
| 74 | +Add to `~/.config/zed/settings.json`: |
| 75 | + |
| 76 | +```json |
| 77 | +{ |
| 78 | + "agent_servers": { |
| 79 | + "Spectra Code": { |
| 80 | + "command": "spectra", |
| 81 | + "args": ["acp"] |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
12 | 86 |
|
13 | | -# build |
14 | | -bun run build |
| 87 | +#### Neovim (avante.nvim) |
15 | 88 |
|
16 | | -# run |
17 | | -bun start |
| 89 | +```lua |
| 90 | +{ |
| 91 | + acp_providers = { |
| 92 | + ["spectra"] = { |
| 93 | + command = "spectra", |
| 94 | + args = { "acp" } |
| 95 | + } |
| 96 | + } |
| 97 | +} |
18 | 98 | ``` |
19 | 99 |
|
20 | | -## Exports |
| 100 | +## Custom Tools |
21 | 101 |
|
22 | | -| Export | Description | |
23 | | -|--------|-------------| |
24 | | -| `launchTui` | Launch the terminal UI | |
25 | | -| `loadConfig` / `loadContext` | Configuration & context loading | |
26 | | -| `SessionStore` | Session persistence | |
27 | | -| `builtinTools` / `createAllTools` | Tool system | |
28 | | -| `shellTool`, `readTool`, `writeTool`, `editTool`, `grepTool`, `globTool`, `webFetchTool` | Built-in agent tools | |
29 | | -| `getPlatformInfo`, `getSystemPrompt` | Platform utils | |
30 | | -| `getGlobalConfigDir`, `getGlobalDataDir`, `getGlobalCacheDir` | Path resolution | |
| 102 | +Define your own tools the agent can call. Place `.ts` files in `.spectra/tools/` (project) or `~/.config/spectra/tools/` (global). Each file becomes a tool named after the filename. |
31 | 103 |
|
32 | | -## CLI |
| 104 | +```typescript |
| 105 | +// .spectra/tools/weather.ts |
| 106 | +import { z } from "zod"; |
33 | 107 |
|
| 108 | +export default { |
| 109 | + description: "Get current weather for a location", |
| 110 | + args: { |
| 111 | + location: z.string().describe("City name"), |
| 112 | + }, |
| 113 | + async execute(args: { location: string }) { |
| 114 | + const res = await fetch( |
| 115 | + `https://api.weather.com/current?city=${encodeURIComponent(args.location)}` |
| 116 | + ); |
| 117 | + const data = await res.json(); |
| 118 | + return `Weather in ${args.location}: ${data.temp}°C, ${data.condition}`; |
| 119 | + }, |
| 120 | +}; |
34 | 121 | ``` |
35 | | -spectra [command] [options] |
| 122 | + |
| 123 | +Multiple tools per file using named exports: |
| 124 | + |
| 125 | +```typescript |
| 126 | +// .spectra/tools/math.ts |
| 127 | +import { z } from "zod"; |
| 128 | + |
| 129 | +export const add = { |
| 130 | + description: "Add two numbers", |
| 131 | + args: { a: z.number(), b: z.number() }, |
| 132 | + async execute(args: { a: number; b: number }) { |
| 133 | + return String(args.a + args.b); |
| 134 | + }, |
| 135 | +}; |
| 136 | + |
| 137 | +export const multiply = { |
| 138 | + description: "Multiply two numbers", |
| 139 | + args: { a: z.number(), b: z.number() }, |
| 140 | + async execute(args: { a: number; b: number }) { |
| 141 | + return String(args.a * args.b); |
| 142 | + }, |
| 143 | +}; |
| 144 | +``` |
| 145 | + |
| 146 | +This creates two tools: `math_add` and `math_multiply`. Tools are loaded automatically by the ACP server and merged into the agent's toolset alongside built-in and MCP tools. |
| 147 | + |
| 148 | +## Configuration |
| 149 | + |
| 150 | +Spectra Code reads config from `spectra.json`, `opencode.json`, or `config.json` in the project or global config directory (`~/.config/spectra/` on Linux, `%LOCALAPPDATA%/spectra/Config/` on Windows). |
| 151 | + |
| 152 | +```json |
| 153 | +{ |
| 154 | + "model": "anthropic/claude-sonnet-4-20250514", |
| 155 | + "agent": "build", |
| 156 | + "theme": "dark", |
| 157 | + "mcp": [ |
| 158 | + { |
| 159 | + "name": "filesystem", |
| 160 | + "command": "npx", |
| 161 | + "args": ["-y", "@modelcontextprotocol/server-filesystem", "."], |
| 162 | + "enabled": true |
| 163 | + } |
| 164 | + ] |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +Environment variables: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `SPECTRA_MODEL`, `SPECTRA_PROVIDER`. |
| 169 | + |
| 170 | +## Architecture |
| 171 | + |
| 172 | +``` |
| 173 | +cli.ts CLI entry point (yargs) |
| 174 | +├── tui/ Full-screen terminal UI (React + @opentui) |
| 175 | +├── commands/ CLI command handlers |
| 176 | +├── services/ Config, session store, auth, snapshots |
| 177 | +├── tools/ Built-in agent tools (read, write, edit, shell, grep, glob, web_fetch, task) |
| 178 | +├── agents/ Agent definitions (build, plan, debug, explore) |
| 179 | +└── integrations/ |
| 180 | + ├── mcp/ MCP client (stdio + HTTP) |
| 181 | + ├── acp/ ACP server (JSON-RPC 2.0) |
| 182 | + └── custom-tools/ Custom tool loader |
| 183 | +``` |
| 184 | + |
| 185 | +## API |
| 186 | + |
| 187 | +```typescript |
| 188 | +import { launchTui, loadConfig, SessionStore } from "@mohanscodex/spectra-code"; |
| 189 | +import { shellTool, readTool, writeTool } from "@mohanscodex/spectra-code"; |
| 190 | + |
| 191 | +const store = new SessionStore(); |
| 192 | +const sessions = store.list(); |
36 | 193 | ``` |
37 | 194 |
|
38 | 195 | ## License |
39 | 196 |
|
40 | | -MIT |
| 197 | +MIT |
0 commit comments