amicus 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +477 -0
  4. package/bin/amicus.js +382 -0
  5. package/electron/assets/icon.png +0 -0
  6. package/electron/assets/icon.svg +5 -0
  7. package/electron/fold.js +163 -0
  8. package/electron/ipc-setup.js +176 -0
  9. package/electron/load-failsafe.js +85 -0
  10. package/electron/main.js +468 -0
  11. package/electron/preload-setup.js +38 -0
  12. package/electron/preload.js +33 -0
  13. package/electron/setup-ui-alias-script.js +218 -0
  14. package/electron/setup-ui-aliases.js +85 -0
  15. package/electron/setup-ui-keys-script.js +115 -0
  16. package/electron/setup-ui-keys.js +97 -0
  17. package/electron/setup-ui-model.js +138 -0
  18. package/electron/setup-ui-styles.js +327 -0
  19. package/electron/setup-ui.js +465 -0
  20. package/electron/summary.js +118 -0
  21. package/electron/toolbar.js +229 -0
  22. package/electron/window-position.js +35 -0
  23. package/package.json +98 -0
  24. package/scripts/postinstall.js +193 -0
  25. package/scripts/setup-hooks.js +42 -0
  26. package/skill/SKILL.md +976 -0
  27. package/skills/second-opinion/COUNCIL-DESIGN.md +227 -0
  28. package/skills/second-opinion/MODEL-NOTES.md +104 -0
  29. package/skills/second-opinion/SKILL.md +389 -0
  30. package/src/cli-handlers.js +188 -0
  31. package/src/cli.js +400 -0
  32. package/src/conflict.js +144 -0
  33. package/src/context-compression.js +102 -0
  34. package/src/context.js +199 -0
  35. package/src/drift.js +144 -0
  36. package/src/environment.js +157 -0
  37. package/src/headless.js +742 -0
  38. package/src/index.js +106 -0
  39. package/src/jsonl-parser.js +180 -0
  40. package/src/mcp-server.js +625 -0
  41. package/src/mcp-tools.js +407 -0
  42. package/src/opencode-client.js +615 -0
  43. package/src/prompt-builder.js +355 -0
  44. package/src/prompts/cowork-agent-prompt.js +118 -0
  45. package/src/session-manager.js +414 -0
  46. package/src/session.js +180 -0
  47. package/src/sidecar/context-builder.js +297 -0
  48. package/src/sidecar/continue.js +212 -0
  49. package/src/sidecar/crash-handler.js +56 -0
  50. package/src/sidecar/fanout-leg.js +107 -0
  51. package/src/sidecar/fanout-output.js +46 -0
  52. package/src/sidecar/fanout.js +236 -0
  53. package/src/sidecar/interactive.js +217 -0
  54. package/src/sidecar/models.js +135 -0
  55. package/src/sidecar/progress.js +218 -0
  56. package/src/sidecar/read.js +183 -0
  57. package/src/sidecar/resume.js +221 -0
  58. package/src/sidecar/session-utils.js +288 -0
  59. package/src/sidecar/setup-window.js +79 -0
  60. package/src/sidecar/setup.js +280 -0
  61. package/src/sidecar/start.js +251 -0
  62. package/src/utils/agent-mapping.js +138 -0
  63. package/src/utils/alias-audit.js +98 -0
  64. package/src/utils/alias-resolver.js +77 -0
  65. package/src/utils/api-key-store.js +259 -0
  66. package/src/utils/api-key-validation.js +97 -0
  67. package/src/utils/auth-json.js +109 -0
  68. package/src/utils/config.js +291 -0
  69. package/src/utils/curated-models.js +82 -0
  70. package/src/utils/env-compat.js +38 -0
  71. package/src/utils/env-loader.js +54 -0
  72. package/src/utils/idle-watchdog.js +225 -0
  73. package/src/utils/input-validators.js +127 -0
  74. package/src/utils/lifecycle.js +43 -0
  75. package/src/utils/logger.js +84 -0
  76. package/src/utils/mcp-discovery.js +194 -0
  77. package/src/utils/mcp-validators.js +78 -0
  78. package/src/utils/model-catalog.js +103 -0
  79. package/src/utils/model-fetcher.js +179 -0
  80. package/src/utils/model-validator.js +207 -0
  81. package/src/utils/path-setup.js +41 -0
  82. package/src/utils/port-pid.js +39 -0
  83. package/src/utils/prompt-source.js +53 -0
  84. package/src/utils/result-schema.js +261 -0
  85. package/src/utils/server-setup.js +93 -0
  86. package/src/utils/session-abort.js +53 -0
  87. package/src/utils/session-lock.js +95 -0
  88. package/src/utils/shared-server.js +216 -0
  89. package/src/utils/start-helpers.js +76 -0
  90. package/src/utils/thinking-validators.js +92 -0
  91. package/src/utils/update-notifier-loader.js +18 -0
  92. package/src/utils/updater.js +157 -0
  93. package/src/utils/validators.js +300 -0
package/skill/SKILL.md ADDED
@@ -0,0 +1,976 @@
1
+ ---
2
+ name: sidecar
3
+ description: >
4
+ Spawn conversations with other LLMs (Gemini, GPT, ChatGPT, Codex, o3, DeepSeek, Qwen,
5
+ Grok, Mistral, etc.) and fold results back into your context. TRIGGER when: user asks to
6
+ talk to, chat with, use, call, or spawn another LLM or model; user mentions Gemini, GPT,
7
+ ChatGPT, Codex, o3, DeepSeek, Claude (as a sidecar target), Qwen, Grok, Mistral, or any
8
+ non-current model by name; user asks to get a second opinion from another model; user
9
+ wants parallel exploration with a different model; user says "sidecar", "fork", or "fold".
10
+ CRITICAL RULES: (1) ALWAYS launch amicus CLI commands with Bash tool's
11
+ run_in_background: true. Never run amicus start/resume/continue in the foreground.
12
+ (2) The fold summary returns on stdout when the user clicks Fold in the GUI or the
13
+ headless agent finishes. Use TaskOutput to read it when the background task completes.
14
+ (3) For long or multi-line briefings, write them to a temp file and pass
15
+ --prompt-file <path> (mutually exclusive with --prompt; avoids shell-quoting hazards
16
+ and argument-size caps). (4) NEVER use o3 or o3-pro unless the user explicitly asks for it by
17
+ name. These models are extremely expensive ($10-60+ per request). If the user asks for
18
+ o3, warn them about the cost before proceeding. Default to gemini for most tasks.
19
+ (5) When the user asks to query MULTIPLE LLMs simultaneously (e.g., "ask Gemini AND
20
+ ChatGPT", "compare Gemini vs GPT"), ALWAYS use --no-ui (headless) for all of them
21
+ unless the user explicitly requests interactive. Opening multiple Electron windows at
22
+ once is disruptive. Launch them all in parallel with run_in_background: true.
23
+ (6) When the SAME prompt should go to N models, use `amicus fanout --models a,b,c
24
+ --prompt-file <path> --json` (one headless wave, one JSON result) instead of N
25
+ separate start calls. Different prompts per model → separate parallel
26
+ `amicus start --no-ui` calls.
27
+ ---
28
+
29
+ # Amicus: Multi-Model Sidecar Tool
30
+
31
+ Spawn parallel conversations with different LLMs (Gemini, GPT, ChatGPT, Codex, o3, etc.) and fold results back into your context.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install -g amicus
37
+ ```
38
+
39
+ Verify installation:
40
+ ```bash
41
+ amicus --version
42
+ ```
43
+
44
+ ### Requirements
45
+ - Node.js 18+
46
+ - API credentials (see Setup below)
47
+ - Electron (installed automatically as optional dependency)
48
+
49
+ ### MCP Server (Auto-Registered)
50
+
51
+ On install, an MCP server is auto-registered for Claude Cowork and Claude Desktop. If you're in an MCP-enabled environment, you can use `amicus_start`, `amicus_status`, `amicus_read`, and other MCP tools directly instead of CLI commands. Call `amicus_guide` for detailed usage instructions.
52
+
53
+ ---
54
+
55
+ ## Setup: Configuring API Access
56
+
57
+ Amicus uses the OpenCode SDK to communicate with LLM providers. You need to configure API credentials for your chosen provider(s).
58
+
59
+ **Recommended:** run `amicus setup` — a guided wizard that stores keys in `~/.config/amicus/.env`, picks your default model from the live catalog, and seeds aliases. The options below are manual alternatives.
60
+
61
+ ### Option A: OpenRouter (Recommended for Multi-Model Access)
62
+
63
+ OpenRouter provides unified access to many models (Gemini, GPT-4, Claude, o3, etc.) with a single API key. If you'd rather not hand-edit JSON, run `amicus setup` instead — it stores the key for you.
64
+
65
+ **Step 1: Get an OpenRouter API key**
66
+ - Sign up at https://openrouter.ai
67
+ - Go to Keys → Create Key
68
+ - Copy your key (starts with `sk-or-v1-...`)
69
+
70
+ **Step 2: Configure credentials**
71
+
72
+ Create the auth file:
73
+ ```bash
74
+ mkdir -p ~/.local/share/opencode
75
+ cat > ~/.local/share/opencode/auth.json << 'EOF'
76
+ {
77
+ "openrouter": {
78
+ "apiKey": "sk-or-v1-YOUR_KEY_HERE"
79
+ }
80
+ }
81
+ EOF
82
+ ```
83
+
84
+ **Step 3: Verify setup**
85
+ ```bash
86
+ amicus start --model gemini --prompt "Say hello" --no-ui
87
+ ```
88
+
89
+ **Model names with OpenRouter:**
90
+ When using OpenRouter, prefix the model with `openrouter/`:
91
+ ```bash
92
+ amicus start --model gemini --prompt "..."
93
+ amicus start --model gpt --prompt "..."
94
+ amicus start --model claude --prompt "..."
95
+ ```
96
+
97
+ ### Option B: Direct API Keys (Provider-Specific)
98
+
99
+ Use this if you have API keys directly from Google, OpenAI, or Anthropic.
100
+
101
+ **For Google Gemini:**
102
+ ```bash
103
+ export GOOGLE_GENERATIVE_AI_API_KEY=your-google-api-key
104
+ ```
105
+
106
+ **For OpenAI:**
107
+ ```bash
108
+ export OPENAI_API_KEY=your-openai-api-key
109
+ ```
110
+
111
+ **For Anthropic:**
112
+ ```bash
113
+ export ANTHROPIC_API_KEY=your-anthropic-api-key
114
+ ```
115
+
116
+ Add these to your shell profile (`~/.bashrc`, `~/.zshrc`) for persistence.
117
+
118
+ **zsh users:** `~/.zshrc` is only sourced by interactive shells. If you use amicus from Claude Code, CI, or scripts, either:
119
+ - Run `amicus setup` to store keys in amicus's config (recommended)
120
+ - Move your exports to `~/.zshenv` (sourced by all zsh shell types)
121
+
122
+ **Model names with direct API keys:**
123
+ When using direct API keys, use the provider/model format WITHOUT the `openrouter/` prefix:
124
+ ```bash
125
+ amicus start --model google/<model-name> --prompt "..."
126
+ amicus start --model openai/<model-name> --prompt "..."
127
+ amicus start --model anthropic/<model-name> --prompt "..."
128
+ ```
129
+
130
+ ### Model Naming Summary
131
+
132
+ | Provider Access | Model Name Format | Example |
133
+ |-----------------|-------------------|---------|
134
+ | OpenRouter | `openrouter/provider/model` | `openrouter/google/<model-name>` |
135
+ | Direct Google API | `google/model` | `google/<model-name>` |
136
+ | Direct OpenAI API | `openai/model` | `openai/<model-name>` |
137
+ | Direct Anthropic API | `anthropic/model` | `anthropic/<model-name>` |
138
+
139
+ **Important:** The model name format tells the SDK which authentication to use:
140
+ - `openrouter/...` → Uses OpenRouter API key from auth.json
141
+ - `google/...` → Uses `GOOGLE_GENERATIVE_AI_API_KEY` environment variable
142
+ - `openai/...` → Uses `OPENAI_API_KEY` environment variable
143
+ - `anthropic/...` → Uses `ANTHROPIC_API_KEY` environment variable
144
+
145
+ ---
146
+
147
+ ## When to Use Sidecars
148
+
149
+ **DO spawn a sidecar when:**
150
+ - Task benefits from a different model's strengths (Gemini's large context, o3's reasoning)
151
+ - Deep exploration that would pollute your main context
152
+ - User explicitly requests a different model
153
+ - Parallel investigation while you continue other work
154
+ - Research/comparison tasks that generate verbose output
155
+
156
+ **DON'T spawn a sidecar when:**
157
+ - Simple task you can handle directly
158
+ - User wants to stay in the current conversation
159
+ - Task requires your specific context that's hard to transfer
160
+
161
+ ### Agent Selection Guidelines
162
+
163
+ **Chat mode (default)** — no `--agent` flag needed. Reads are auto-approved, writes and bash commands require user permission in the Electron UI:
164
+ ```bash
165
+ # Default — good for questions, analysis, and guided work
166
+ amicus start --model gemini --prompt "Analyze the auth flow and suggest improvements"
167
+ ```
168
+
169
+ **Plan mode** — fully read-only, no file modifications possible:
170
+ ```bash
171
+ # Strict read-only for deep analysis
172
+ amicus start --model gemini --prompt "Review the codebase architecture" --agent Plan
173
+ ```
174
+
175
+ **Build mode** — full tool access, all operations auto-approved:
176
+ ```bash
177
+ # Only when offloading development tasks
178
+ amicus start --model gemini --prompt "Implement the login feature" --agent Build
179
+ ```
180
+
181
+ **When to use each mode:**
182
+
183
+ | Mode | Use When |
184
+ |------|----------|
185
+ | **Chat** (default) | Questions, analysis, guided exploration — you control what gets written |
186
+ | **Plan** | Comprehensive read-only analysis where no changes should happen |
187
+ | **Build** | Offloading implementation tasks where full autonomy is desired |
188
+
189
+ ---
190
+
191
+ ## Commands
192
+
193
+ ### Start a Sidecar
194
+
195
+ ```bash
196
+ amicus start \
197
+ --model <provider/model> \
198
+ --prompt "<task description>" \
199
+ --session-id <your-session-id>
200
+ ```
201
+
202
+ **Required:**
203
+ - `--model`: The model to use (see Models below)
204
+ - `--prompt`: Detailed task description you generate
205
+
206
+ **Recommended:**
207
+ - `--session`: Your Claude Code session ID for accurate context passing
208
+
209
+ **Optional:**
210
+ - `--no-ui`: Run autonomously without GUI (for bulk tasks)
211
+ - `--no-context`: Skip parent conversation history. Use when the briefing is self-contained and includes all necessary file paths, code snippets, and criteria. Default: context is included.
212
+ - `--timeout <min>`: Headless timeout (default: 15)
213
+ - `--context-turns <N>`: Max conversation turns to include (default: 50)
214
+ - `--context-since <duration>`: Time filter for context (e.g., `2h`, `30m`, `1d`). Overrides `--context-turns`.
215
+ - `--context-max-tokens <N>`: Max context size (default: 80000)
216
+ - `--thinking <level>`: Model thinking/reasoning effort level:
217
+ - `none` - No extended thinking
218
+ - `minimal` - Minimal thinking (may be adjusted if unsupported by model)
219
+ - `low` - Low thinking effort
220
+ - `medium` - Medium thinking effort (default)
221
+ - `high` - High thinking effort
222
+ - `xhigh` - Extra high thinking effort
223
+ Note: If the model doesn't support the specified level, it will be automatically adjusted.
224
+ - `--summary-length <length>`: Summary verbosity:
225
+ - `brief` - Concise summary
226
+ - `normal` - Standard summary (default)
227
+ - `verbose` - Detailed summary
228
+ - `--mcp <spec>`: Add MCP server for enhanced tool access. Formats:
229
+ - `name=url` - Remote MCP server (e.g., `--mcp "db=postgresql://localhost:5432/mydb"`)
230
+ - `name=command` - Local MCP server (spawns process)
231
+ - `--mcp-config <path>`: Path to opencode.json file with MCP server configuration. Alternative to `--mcp` for complex setups.
232
+ - `--client <type>`: Client entry point (`code-local`, `code-web`, `cowork`). Affects system prompt personality. Default: `code-local`.
233
+ - `--prompt-file <path>`: Read the prompt/briefing from a UTF-8 file (mutually exclusive with
234
+ `--prompt`). Use for long or multi-line briefings.
235
+ - `--json`: With `--no-ui`, emit the run result as one stable JSON document on stdout
236
+ (`schemaVersion: 1`; the `summary` field is the model's output).
237
+ - `--no-validate-model`: Skip the model-catalog pre-flight check (validation is on by default).
238
+ - `--agent <agent>`: Agent mode (controls tool permissions). If omitted, defaults to **Chat**.
239
+
240
+ **Primary Agents (for `amicus start`):**
241
+ - `Chat` **(default)**: Reads auto-approved, writes/bash require user permission
242
+ - `Plan`: Read-only mode - no file modifications possible
243
+ - `Build`: Full tool access - all operations auto-approved
244
+
245
+ **Custom Agents:**
246
+ Custom agents defined in `~/.config/opencode/agents/` or `.opencode/agents/` are passed through directly.
247
+
248
+ ### Input Validation
249
+
250
+ The CLI validates all inputs **before** launching the sidecar. Invalid inputs fail immediately with clear error messages - no Electron window will open.
251
+
252
+ **Required inputs (will error if invalid):**
253
+
254
+ | Input | Validation | Error Message |
255
+ |-------|------------|---------------|
256
+ | `--model` | Must be present, format: `provider/model` | `Error: --model is required` or `Error: --model must be in format provider/model` |
257
+ | `--prompt` | Must be present and non-empty | `Error: --prompt is required` or `Error: --prompt cannot be empty or whitespace-only` |
258
+ | `--cwd` | If provided, directory must exist | `Error: --cwd path does not exist: <path>` |
259
+ | `--session-id` | If explicit ID provided (not 'current'), must exist | `Error: --session-id '<id>' not found. Use 'amicus list' to see available sessions or omit --session-id for most recent.` |
260
+ | `--agent` | If provided, must be non-empty | `Error: --agent cannot be empty` |
261
+ | `--timeout` | Must be positive number | `Error: --timeout must be a positive number` |
262
+ | `--context-turns` | Must be positive number | `Error: --context-turns must be a positive number` |
263
+ | `--context-since` | Must match format: `30m`, `2h`, `1d` | `Error: --context-since must be in format: 30m, 2h, or 1d` |
264
+ | API Key | Must be set for model's provider | `Error: <KEY_NAME> environment variable is required for <Provider> models` |
265
+
266
+ **API Key Requirements by Provider:**
267
+
268
+ | Model Prefix | Required Env Var | Example |
269
+ |--------------|------------------|---------|
270
+ | `openrouter/...` | `OPENROUTER_API_KEY` | `export OPENROUTER_API_KEY=sk-or-...` |
271
+ | `google/...` | `GOOGLE_GENERATIVE_AI_API_KEY` | `export GOOGLE_GENERATIVE_AI_API_KEY=...` |
272
+ | `openai/...` | `OPENAI_API_KEY` | `export OPENAI_API_KEY=sk-...` |
273
+ | `anthropic/...` | `ANTHROPIC_API_KEY` | `export ANTHROPIC_API_KEY=sk-ant-...` |
274
+ | `deepseek/...` | `DEEPSEEK_API_KEY` | `export DEEPSEEK_API_KEY=...` |
275
+
276
+ **Handling validation errors:**
277
+
278
+ If you receive a validation error, fix the input and retry:
279
+
280
+ ```bash
281
+ # Error: --session-id 'abc123' not found
282
+ # Fix: Use 'current' or omit --session
283
+ amicus start --model gemini --prompt "Task" --session-id current
284
+
285
+ # Error: --agent cannot be empty
286
+ # Fix: Use a valid OpenCode agent
287
+ amicus start --model gemini --prompt "Task" --agent Build
288
+
289
+ # Error: --prompt cannot be empty
290
+ # Fix: Provide a non-empty briefing
291
+ amicus start --model gemini --prompt "Detailed task description"
292
+
293
+ # Error: OPENROUTER_API_KEY environment variable is required
294
+ # Fix: Set the API key for your provider
295
+ export OPENROUTER_API_KEY=sk-or-your-key
296
+ amicus start --model gemini --prompt "Task"
297
+ ```
298
+
299
+ ### Fan Out One Prompt to N Models
300
+
301
+ ```bash
302
+ amicus fanout --models gemini,gpt,deepseek --prompt-file ./briefing.md --json
303
+ ```
304
+
305
+ Runs the same prompt on every listed model in parallel (one shared engine server, headless),
306
+ then prints ONE JSON wave document: `status` (`complete`|`partial`|`error`), `counts`, and
307
+ `legs[]` where each leg's `summary` is that model's answer. Exit codes: 0 complete, 2 partial,
308
+ 1 error/aborted. Aliases and full `provider/model` IDs both work; duplicates are allowed
309
+ (distinct legs). `--wave-id <id>` pins leg IDs to `<id>-1..N`. Shared per-leg knobs: `--agent`,
310
+ `--thinking`, `--timeout`, `--summary-length`, `--no-context`, `--context-*`, `--mcp*`,
311
+ `--no-validate-model`, `--cwd`.
312
+
313
+ ### Inspect the Model Catalog
314
+
315
+ ```bash
316
+ amicus models # list the live catalog (context + pricing columns)
317
+ amicus models --search grok # substring search over id + name
318
+ amicus models --refresh # force-refresh from OpenRouter (TTL cache otherwise)
319
+ amicus models --check # audit configured aliases against the catalog
320
+ ```
321
+
322
+ The catalog is cached at `~/.config/amicus/model-catalog.json` and refreshes automatically;
323
+ `start`/`fanout` validate models against it before launching (skip with `--no-validate-model`).
324
+
325
+ ### List Past Sidecars
326
+
327
+ ```bash
328
+ amicus list
329
+ amicus list --status complete
330
+ amicus list --all # All projects
331
+ amicus list --json # Output as JSON
332
+ ```
333
+
334
+ **Optional:**
335
+ - `--status <filter>`: Filter by status (`running`, `complete`)
336
+ - `--all`: Show sessions from all projects
337
+ - `--json`: Output as JSON format (for programmatic use)
338
+ - `--cwd <path>`: Project directory (default: current directory)
339
+
340
+ ### Resume a Sidecar
341
+
342
+ ```bash
343
+ amicus resume <task_id>
344
+ ```
345
+
346
+ Reopens a previous session with full conversation history. Amicus continues in the **same** OpenCode session — all previous messages and tool state are preserved.
347
+
348
+ **Use resume when:** You want to pick up exactly where you left off (e.g., re-examine findings, ask follow-up questions in the same conversation).
349
+
350
+ **Optional:**
351
+ - `--no-ui`: Continue session in autonomous mode
352
+ - `--timeout <minutes>`: Timeout for headless mode (default: 15)
353
+ - `--cwd <path>`: Project directory (default: current directory)
354
+
355
+ ### Continue from a Sidecar
356
+
357
+ ```bash
358
+ amicus continue <task_id> --prompt "<new task>"
359
+ ```
360
+
361
+ Starts a **new** sidecar session that inherits the old session's conversation as context. The previous session's messages become read-only background context for the new task.
362
+
363
+ **Use continue when:** You want to build on previous findings with a new task or different model (e.g., "Now implement the fix from the previous analysis").
364
+
365
+ **Required:**
366
+ - `--prompt`: New task description for the continuation
367
+
368
+ **Optional:**
369
+ - `--model <model>`: Override model (defaults to original session's model)
370
+ - `--context-turns <N>`: Max turns from previous session to include (default: 50)
371
+ - `--context-max-tokens <N>`: Max tokens for context (default: 80000)
372
+ - `--no-ui`: Run in autonomous mode
373
+ - `--timeout <minutes>`: Timeout for headless mode (default: 15)
374
+ - `--cwd <path>`: Project directory (default: current directory)
375
+
376
+ ### Read Sidecar Output
377
+
378
+ ```bash
379
+ amicus read <task_id> # Show summary
380
+ amicus read <task_id> --conversation # Show full conversation
381
+ amicus read <task_id> --metadata # Show session metadata
382
+ ```
383
+
384
+ **Optional:**
385
+ - `--summary`: Show summary (default if no option specified)
386
+ - `--conversation`: Show full conversation history
387
+ - `--metadata`: Show session metadata (model, agent, timestamps, etc.)
388
+ - `--cwd <path>`: Project directory (default: current directory)
389
+
390
+ ### Abort a Running Session
391
+
392
+ ```bash
393
+ amicus abort <task_id> # stop one session
394
+ amicus abort --all # stop every running session in this project
395
+ ```
396
+
397
+ ---
398
+
399
+ ## Models Available
400
+
401
+ ### Model Selection
402
+
403
+ Use short aliases (run `amicus guide` to see all available aliases and their current model IDs):
404
+ - `--model gemini` -- Google Gemini (fast, large context)
405
+ - `--model opus` -- Claude Opus (deep analysis)
406
+ - `--model gpt` -- OpenAI GPT
407
+ - `--model deepseek` -- DeepSeek
408
+ - Omit `--model` entirely to use your configured default
409
+
410
+ Full model strings also work: `--model openrouter/provider/model-id`
411
+
412
+ ### Verifying Model Names
413
+
414
+ Model names change frequently. Verify against the live catalog:
415
+
416
+ ```bash
417
+ amicus models --search gemini
418
+ ```
419
+
420
+ Aliases are seeded by `amicus setup` and audited by `amicus models --check`, which suggests
421
+ replacements for stale aliases. See also [Inspect the Model Catalog](#inspect-the-model-catalog) for `--refresh` and the cache location.
422
+
423
+ ---
424
+
425
+ ## Session ID (Important)
426
+
427
+ For reliable context passing, provide your session ID:
428
+
429
+ ```bash
430
+ amicus start --session-id "a1b2c3d4-..." --model ... --prompt ...
431
+ ```
432
+
433
+ **How to find your session ID:**
434
+
435
+ Your conversations are stored in:
436
+ ```
437
+ ~/.claude/projects/[encoded-project-path]/[session-id].jsonl
438
+ ```
439
+
440
+ The encoded path replaces `/`, `\`, and `_` with `-`. For example:
441
+ - Project: `/Users/john/myproject`
442
+ - Encoded: `-Users-john-myproject`
443
+ - Full path: `~/.claude/projects/-Users-john-myproject/`
444
+
445
+ List session files to find yours:
446
+ ```bash
447
+ ls -lt ~/.claude/projects/-Users-john-myproject/*.jsonl | head -5
448
+ ```
449
+
450
+ The most recently modified file is likely your current session. Extract the UUID from the filename.
451
+
452
+ **Session ID behavior:**
453
+ - **Omit `--session`** or use `--session-id current`: Uses the most recently modified session file (less reliable if multiple sessions are active)
454
+ - **Explicit session ID** (`--session-id abc123-def456`): Must exist or the command fails immediately with: `Error: --session-id 'abc123-def456' not found`
455
+
456
+ **If you get a session not found error:**
457
+ 1. List available sessions: `amicus list`
458
+ 2. Use one of the listed session IDs, OR
459
+ 3. Omit `--session` to use the most recent session
460
+
461
+ ---
462
+
463
+ ## Generating the Briefing
464
+
465
+ You create the briefing—it should be a comprehensive handoff document:
466
+
467
+ ```markdown
468
+ ## Task Briefing
469
+
470
+ **Objective:** [One-line goal]
471
+
472
+ **Background:** [What led to this task, relevant context]
473
+
474
+ **What's been tried:** [Previous attempts, if any]
475
+
476
+ **Files of interest:**
477
+ - path/to/relevant/file.ts
478
+ - path/to/another/file.ts
479
+
480
+ **Success criteria:** [How to know when done]
481
+
482
+ **Constraints:** [Time limits, scope limits, things to avoid]
483
+ ```
484
+
485
+ **Example:**
486
+
487
+ ```bash
488
+ amicus start \
489
+ --model gemini-pro \
490
+ --session-id "abc123-def456" \
491
+ --prompt "## Task Briefing
492
+
493
+ **Objective:** Debug the intermittent 401 errors on mobile
494
+
495
+ **Background:** Users report sporadic auth failures. Server logs show
496
+ token refresh race conditions. I suspect TokenManager.ts.
497
+
498
+ **Files of interest:**
499
+ - src/auth/TokenManager.ts (main suspect)
500
+ - src/api/client.ts (where tokens are used)
501
+ - logs/auth-errors-2025-01-25.txt
502
+
503
+ **Success criteria:** Identify root cause and propose fix
504
+
505
+ **Constraints:** Focus on auth flow only, don't refactor unrelated code"
506
+ ```
507
+
508
+ ---
509
+
510
+ ## Context Control
511
+
512
+ By default, amicus includes your parent conversation history (up to 80k tokens). Skip this with `--no-context` when the task is self-contained.
513
+
514
+ ### When You MUST Include Context
515
+ - Task references something from the current conversation ("that bug", "the approach you suggested")
516
+ - Fact checking, second opinions, or code review of recent work
517
+ - "Does this look right?" or validation requests
518
+ - Continuing a debugging thread
519
+
520
+ ### When You Can Skip Context
521
+ - Greenfield tasks with explicit file paths and instructions
522
+ - General knowledge or research questions
523
+ - Tasks fully described in the briefing (files, criteria, constraints all specified)
524
+ - Independent analysis unrelated to current conversation
525
+
526
+ ### Self-Contained Briefing Example
527
+
528
+ ```bash
529
+ amicus start \
530
+ --model gemini \
531
+ --no-context \
532
+ --prompt "## Task Briefing
533
+
534
+ **Objective:** Add retry logic with exponential backoff to the HTTP client
535
+
536
+ **Files to read:**
537
+ - src/api/client.ts (current implementation)
538
+ - src/utils/retry.ts (existing retry utility, if any)
539
+
540
+ **Success criteria:**
541
+ - Retries up to 3 times on 5xx errors
542
+ - Exponential backoff: 1s, 2s, 4s
543
+ - No retry on 4xx errors
544
+ - Add unit tests
545
+
546
+ **Constraints:** Don't modify the public API surface"
547
+ ```
548
+
549
+ ---
550
+
551
+ ## Agent Modes
552
+
553
+ Amicus uses OpenCode's agent framework with three primary modes:
554
+
555
+ ### Primary Agents (for Main Sessions)
556
+
557
+ | Agent | Reads | Writes/Edits | Bash | Default |
558
+ |-------|-------|-------------|------|---------|
559
+ | **Chat** | auto | asks permission | asks permission | Yes |
560
+ | **Plan** | auto | denied | denied | No |
561
+ | **Build** | auto | auto | auto | No |
562
+
563
+ #### Chat Agent (Default)
564
+
565
+ Conversational mode — reads are auto-approved, writes and bash commands prompt for user permission in the UI. This is the default when no `--agent` flag is provided.
566
+
567
+ ```bash
568
+ # These are equivalent — Chat is the default
569
+ amicus start --model gemini --prompt "Analyze the auth flow"
570
+ amicus start --model gemini --prompt "Analyze the auth flow" --agent Chat
571
+ ```
572
+
573
+ **Use Chat agent when:**
574
+ - Asking questions or requesting analysis
575
+ - You want to review and approve any file changes
576
+ - Interactive exploration where the model might suggest edits
577
+ - Any task where you want human-in-the-loop control over writes
578
+
579
+ #### Plan Agent
580
+
581
+ Strict read-only mode — file modifications are completely blocked:
582
+
583
+ ```bash
584
+ amicus start --model gemini --prompt "Review the codebase architecture" --agent Plan
585
+ ```
586
+
587
+ **Use Plan agent when:**
588
+ - Comprehensive analysis where no changes should happen
589
+ - Code review and security audits
590
+ - Architecture exploration
591
+
592
+ #### Build Agent
593
+
594
+ Full autonomous access — all operations auto-approved:
595
+
596
+ ```bash
597
+ amicus start --model gemini --prompt "Implement the login feature" --agent Build
598
+ ```
599
+
600
+ **Use Build agent when:**
601
+ - Offloading development tasks to the sidecar
602
+ - User explicitly requests implementation ("implement", "fix", "write", "create")
603
+ - Headless batch operations (test generation, linting, etc.)
604
+
605
+ ---
606
+
607
+ ## Interactive vs Headless
608
+
609
+ ### Interactive (Default)
610
+
611
+ - Opens a GUI window
612
+ - User can converse with the sidecar
613
+ - **Model Picker:** Click the model name in the input area to switch models mid-conversation
614
+ - Click **FOLD** when done to generate summary
615
+ - Summary returns to your context via stdout
616
+
617
+ **Use for:** Debugging, exploration, architectural discussions
618
+
619
+ **Mid-Conversation Model Switching:**
620
+ In interactive mode, you can change models without restarting:
621
+ 1. Click the model dropdown (shows current model name)
622
+ 2. Select a different model from the categorized list
623
+ 3. A system message confirms the switch
624
+ 4. Subsequent messages use the new model
625
+
626
+ This is useful when you want to:
627
+ - Start fast with Flash, then switch to Pro for complex analysis
628
+ - Try a different model's perspective on a problem
629
+ - Use reasoning models (o3-mini) for specific parts of the task
630
+
631
+ ### Headless (--no-ui)
632
+
633
+ - Runs autonomously, no GUI
634
+ - Agent works until done or timeout
635
+ - Summary returns automatically
636
+ - **Default agent is `build`** — `chat` agent requires interactive UI and will stall in headless mode
637
+ - **Always use headless when spawning multiple sidecars at once** (see Multi-LLM rule below)
638
+
639
+ **Multi-LLM Rule:** When the SAME prompt goes to N models, use `amicus fanout` (see [Fan Out One Prompt to N Models](#fan-out-one-prompt-to-n-models)) — one headless wave, one JSON result. When prompts differ per model, use separate parallel `amicus start --no-ui` calls with `run_in_background: true`. Only switch to interactive if the user explicitly asks.
640
+
641
+ **Agent Headless Compatibility:**
642
+
643
+ | Agent | Headless Safe | Notes |
644
+ |-------|--------------|-------|
645
+ | `build` | Yes | Default for `--no-ui` — full autonomous access |
646
+ | `plan` | Yes | Read-only analysis |
647
+ | `explore` | Yes | Read-only codebase exploration |
648
+ | `general` | Yes | Full-access subagent |
649
+ | `chat` | **No** | Blocked — requires interactive mode for write permissions |
650
+
651
+ (`explore` and `general` are OpenCode-native agent types accepted by `--agent`; custom agents from `~/.config/opencode/agents/` are passed through as-is.)
652
+
653
+ ```bash
654
+ # Error: chat + headless
655
+ amicus start --model gemini --prompt "..." --agent chat --no-ui
656
+ # → Error: --agent chat requires interactive mode (remove --no-ui or use --agent build)
657
+ ```
658
+
659
+ **Use for:** Bulk tasks, test generation, documentation, linting
660
+
661
+ ```bash
662
+ amicus start \
663
+ --model gemini \
664
+ --prompt "Generate unit tests for src/utils/. Use Jest." \
665
+ --no-ui \
666
+ --timeout 20
667
+ ```
668
+
669
+ ---
670
+
671
+ ## Background Execution (REQUIRED)
672
+
673
+ **ALWAYS run amicus commands in the background.** Use the Bash tool's `run_in_background: true` parameter for every `amicus start`, `amicus resume`, and `amicus continue` invocation. This ensures:
674
+
675
+ - No timeout ceiling — tasks can run for the full 15+ minutes
676
+ - You can continue working while the sidecar runs
677
+ - You'll be automatically notified when it completes
678
+
679
+ **Example invocation pattern:**
680
+ ```
681
+ Bash tool:
682
+ command: "amicus start --model gemini --prompt '...' --no-ui"
683
+ run_in_background: true
684
+ ```
685
+
686
+ After launching, tell the user:
687
+ > "Amicus is running in the background. I'll share the results when it completes."
688
+
689
+ **When the background task completes**, you will be automatically notified. Use the `TaskOutput` tool with the task ID to read the sidecar's summary output, then present it to the user. Do NOT poll or sleep — the notification arrives automatically.
690
+
691
+ **Interactive mode note:** When running without `--no-ui`, the Electron GUI opens in a separate window. Backgrounding frees the terminal but does not prevent the user from interacting with the GUI window.
692
+
693
+ **Important:** Warn users about potential file conflicts:
694
+ > "I recommend committing your current changes before the sidecar completes, in case there are file conflicts."
695
+
696
+ ---
697
+
698
+ ## Understanding Sidecar Output
699
+
700
+ The summary includes:
701
+
702
+ ```markdown
703
+ ## Sidecar Results: [Title]
704
+
705
+ 📍 **Context Age:** [How stale the context might be]
706
+
707
+ ⚠️ **FILE CONFLICT WARNING** [If files were modified externally]
708
+
709
+ **Task:** [What was requested]
710
+ **Findings:** [Key discoveries]
711
+ **Attempted Approaches:** [What was tried but didn't work]
712
+ **Recommendations:** [Suggested actions]
713
+ **Code Changes:** [Specific code with paths]
714
+ **Files Modified:** [List of files]
715
+ **Assumptions Made:** [Things to verify]
716
+ **Open Questions:** [Remaining uncertainties]
717
+ ```
718
+
719
+ **Act on the summary:**
720
+ - Implement recommended fixes
721
+ - Verify assumptions listed
722
+ - Don't repeat failed approaches
723
+ - Review files with conflict warnings carefully
724
+
725
+ ### Handling Config Update Notices
726
+
727
+ When amicus emits `[AMICUS_CONFIG_UPDATE]` on stderr (or the legacy `[SIDECAR_CONFIG_UPDATE]` from older installs — accept either), the user's model aliases have changed (via `amicus setup`). The message contains a hash comment and a markdown alias table.
728
+
729
+ **Action required:**
730
+ 1. Find the "Model Aliases" section in the project's CLAUDE.md
731
+ 2. Replace that section's content with the block provided in the message
732
+ 3. If no "Model Aliases" section exists, add one after the title line
733
+ 4. Do **not** remove the `<!-- amicus-config-hash: ... -->` comment (legacy files may use `<!-- sidecar-config-hash: ... -->` — do not remove whichever is present) — it tracks config changes and prevents duplicate notifications
734
+
735
+ The update is purely informational (alias mappings) and safe to apply without user confirmation.
736
+
737
+ ---
738
+
739
+ ## Checking for Existing Sidecars
740
+
741
+ Before spawning a new sidecar, check if relevant work exists:
742
+
743
+ ```bash
744
+ amicus list
745
+ ```
746
+
747
+ If a relevant sidecar exists:
748
+ - Read its findings: `amicus read <id>`
749
+ - Reopen it: `amicus resume <id>`
750
+ - Build on it: `amicus continue <id> --prompt "..."`
751
+
752
+ **Ask the user** if you're unsure whether to resume or start fresh.
753
+
754
+ ---
755
+
756
+ ## Examples
757
+
758
+ ### Example 1: Interactive Debugging (Chat Mode - Default)
759
+
760
+ ```bash
761
+ # Default Chat mode — can read freely, asks before writing
762
+ amicus start \
763
+ --model gpt \
764
+ --session-id "$(ls -t ~/.claude/projects/-Users-john-myproject/*.jsonl | head -1 | xargs basename .jsonl)" \
765
+ --prompt "## Debug Memory Leak
766
+
767
+ **Objective:** Find the source of memory growth in the worker process
768
+
769
+ **Background:** Memory usage grows 50MB/hour. Heap snapshots show retained
770
+ closures but I can't identify the source.
771
+
772
+ **Files of interest:**
773
+ - src/workers/processor.ts
774
+ - src/cache/lru.ts
775
+
776
+ **Success criteria:** Identify the leak and propose fix"
777
+ ```
778
+
779
+ ### Example 2: Headless Test Generation (Build Mode - Explicit Request)
780
+
781
+ ```bash
782
+ # Build mode is appropriate here because user explicitly requested file creation
783
+ amicus start \
784
+ --model gemini \
785
+ --agent Build \
786
+ --prompt "Generate comprehensive Jest tests for all exported functions
787
+ in src/utils/. Include edge cases. Write to tests/utils/." \
788
+ --no-ui \
789
+ --timeout 15
790
+ ```
791
+
792
+ ### Example 3: Code Review (Plan Mode - Read-Only)
793
+
794
+ ```bash
795
+ # Plan mode for strict read-only review
796
+ amicus start \
797
+ --model gemini \
798
+ --agent Plan \
799
+ --prompt "Review the authentication flow for security issues.
800
+ Focus on: token handling, session management, CSRF protection.
801
+ Analyze and report findings."
802
+ ```
803
+
804
+ ### Example 4: Continue Previous Work
805
+
806
+ ```bash
807
+ # First, check what exists
808
+ amicus list
809
+
810
+ # Read what was found
811
+ amicus read abc123
812
+
813
+ # Continue with a follow-up task
814
+ amicus continue abc123 \
815
+ --model gpt \
816
+ --prompt "Implement the fix recommended in the previous session.
817
+ The mutex approach looks correct. Add tests."
818
+ ```
819
+
820
+ ---
821
+
822
+ ## Troubleshooting
823
+
824
+ ### "Missing Authentication header" in Claude Code or CI
825
+
826
+ API keys in `~/.zshrc` are not available in non-interactive shells. Resolution order: `process.env` > `~/.config/amicus/.env` (legacy `~/.config/sidecar/.env` still read) > `~/.local/share/opencode/auth.json` (first wins). Fix:
827
+ 1. Run `amicus setup` (stores keys in `~/.config/amicus/.env`)
828
+ 2. Or move exports to `~/.zshenv`
829
+ 3. Or add credentials to `~/.local/share/opencode/auth.json`
830
+
831
+ ### "No Claude Code conversation history found"
832
+
833
+ Your project path encoding may not match. Check:
834
+ ```bash
835
+ ls ~/.claude/projects/
836
+ ```
837
+
838
+ Find the correct encoded path for your project. Remember that `/`, `\`, and `_` are all converted to `-`.
839
+
840
+ ### "Multiple active sessions detected"
841
+
842
+ You have multiple Claude Code windows. Pass `--session` explicitly:
843
+ ```bash
844
+ ls -lt ~/.claude/projects/[your-path]/*.jsonl | head -3
845
+ # Pick the correct session UUID
846
+ ```
847
+
848
+ ### Sidecar doesn't start / API errors
849
+
850
+ **Check API credentials are configured:**
851
+
852
+ For OpenRouter:
853
+ ```bash
854
+ cat ~/.local/share/opencode/auth.json
855
+ # Should contain: {"openrouter": {"apiKey": "sk-or-v1-..."}}
856
+ ```
857
+
858
+ For direct API keys:
859
+ ```bash
860
+ echo $GOOGLE_GENERATIVE_AI_API_KEY # For Google models
861
+ echo $OPENAI_API_KEY # For OpenAI models
862
+ echo $ANTHROPIC_API_KEY # For Anthropic models
863
+ ```
864
+
865
+ ### "401 Unauthorized" or authentication errors
866
+
867
+ 1. Verify you're using the correct model name format:
868
+ - OpenRouter models: `openrouter/provider/model`
869
+ - Direct API models: `provider/model`
870
+
871
+ 2. Check your API key is valid and has credits
872
+
873
+ 3. For OpenRouter, ensure auth.json exists:
874
+ ```bash
875
+ cat ~/.local/share/opencode/auth.json
876
+ ```
877
+
878
+ ### Headless mode times out with no output
879
+
880
+ 1. Increase timeout: `--timeout 30`
881
+ 2. Enable debug logging: `LOG_LEVEL=debug amicus start ...`
882
+
883
+ ### Summary is corrupted
884
+
885
+ Debug output may be leaking to stdout. Check for console.log statements if you've modified the sidecar code. All logging should go to stderr via the structured logger.
886
+
887
+ ### Validation Errors
888
+
889
+ **"Error: --prompt cannot be empty or whitespace-only"**
890
+
891
+ The briefing must contain actual content:
892
+ ```bash
893
+ # Wrong
894
+ amicus start --model gemini --prompt ""
895
+ amicus start --model gemini --prompt " "
896
+
897
+ # Right
898
+ amicus start --model gemini --prompt "Debug the auth issue in TokenManager.ts"
899
+ ```
900
+
901
+ **"Error: --session-id '<id>' not found"**
902
+
903
+ The explicit session ID doesn't exist. Either:
904
+ 1. Use `amicus list` to find valid session IDs
905
+ 2. Omit `--session` to use the most recent session
906
+ 3. Use `--session-id current` for automatic resolution
907
+
908
+ ```bash
909
+ # Find valid sessions
910
+ amicus list
911
+
912
+ # Use most recent session
913
+ amicus start --model gemini --prompt "Task"
914
+ ```
915
+
916
+ **"Error: --cwd path does not exist"**
917
+
918
+ The specified project directory doesn't exist:
919
+ ```bash
920
+ # Wrong
921
+ amicus start --model ... --prompt "..." --cwd /nonexistent/path
922
+
923
+ # Right - use current directory
924
+ amicus start --model ... --prompt "..." --cwd .
925
+
926
+ # Right - use full path
927
+ amicus start --model ... --prompt "..." --cwd /Users/john/myproject
928
+ ```
929
+
930
+ **"Error: --agent cannot be empty"**
931
+
932
+ The agent name cannot be empty. Use an OpenCode native agent or a custom agent:
933
+ ```bash
934
+ # Wrong - empty agent
935
+ amicus start --model ... --prompt "..." --agent ""
936
+
937
+ # Right - use OpenCode native agent
938
+ amicus start --model ... --prompt "..." --agent Explore
939
+
940
+ # Right - use custom agent (defined in ~/.config/opencode/agents/)
941
+ amicus start --model ... --prompt "..." --agent MyCustomAgent
942
+ ```
943
+
944
+ **"Error: <KEY_NAME> environment variable is required for <Provider> models"**
945
+
946
+ The API key for the model's provider is not set:
947
+ ```bash
948
+ # For OpenRouter models (openrouter/...)
949
+ export OPENROUTER_API_KEY=sk-or-your-key
950
+
951
+ # For Google models (google/...)
952
+ export GOOGLE_GENERATIVE_AI_API_KEY=your-google-key
953
+
954
+ # For OpenAI models (openai/...)
955
+ export OPENAI_API_KEY=sk-your-openai-key
956
+
957
+ # For Anthropic models (anthropic/...)
958
+ export ANTHROPIC_API_KEY=sk-ant-your-key
959
+
960
+ # For DeepSeek models (deepseek/...)
961
+ export DEEPSEEK_API_KEY=your-deepseek-key
962
+
963
+ # Then retry
964
+ amicus start --model gemini --prompt "Task"
965
+ ```
966
+
967
+ ---
968
+
969
+ ## Quick Start Checklist
970
+
971
+ 1. [ ] Install amicus: `npm install -g amicus`
972
+ 2. [ ] Configure API access (choose one):
973
+ - [ ] Run `amicus setup` (recommended — wizard stores keys and seeds aliases)
974
+ - [ ] OpenRouter manual: Create `~/.local/share/opencode/auth.json` with your key
975
+ - [ ] Direct API: Set environment variable (`GOOGLE_GENERATIVE_AI_API_KEY`, etc.)
976
+ 3. [ ] Test amicus: `amicus start --model <your-model> --prompt "Hello" --no-ui`