feat(assistant): self-configuring assistant mode (#244)

* test(backend): replace better-sqlite3 test mock with node:sqlite

Reimplement the bun:sqlite test mock on top of node:sqlite with an
explicit BEGIN/COMMIT/ROLLBACK transaction wrapper.

* feat(assistant): self-configuring assistant mode

Add a self-editable assistant workspace and the APIs that support it:
- POST /assistant/reload disposes and re-bootstraps the assistant
  instance (directory-scoped, rate-limited) so agent.md edits apply.
- Internal settings API accepts non-secret TTS/STT patches via
  dedicated partial schemas.
- Strip the generated agent persona from opencode.json on repair so
  user-customized agents are preserved across config recovery.
- Cache the last assistant session id to avoid redundant session
  listing on launch.

* style(repo): align worktree and workspace tabs with primary/orange theme
This commit is contained in:
Chris Scott authored and GitHub committed 2026-05-31 11:38:02 -04:00
1 parent eedbbfb94e
commit dbd6866682
22 files changed
+733 -156

No files matched your search

+29
View File
@@ -104,13 +104,17 @@ The following preference keys can be modified:
- `simpleChatMode`, `leaderKey`, `directShortcuts`
- `keyboardShortcuts`, `customCommands`, `notifications`
- `repoOrder`, `repoSortMode`
- `tts` — Non-secret TTS preferences (`enabled`, `provider`, `autoPlay`, `voice`, `model`, `speed`). TTS must already be configured in the UI (the endpoint returns 400 otherwise).
- `stt` — Non-secret STT preferences (`enabled`, `provider`, `model`, `language`). STT must already be configured in the UI (the endpoint returns 400 otherwise).
**Restricted Keys:**
The following keys are **NOT** allowed and will be rejected:
- `gitCredentials` - Git credentials must be managed via the full UI
- `gitIdentity` - Git identity must be managed via the full UI
- `tts.apiKey` - TTS credentials must be managed via the full UI
- `tts.endpoint` - TTS endpoint must be managed via the full UI
- `stt.apiKey` - STT credentials must be managed via the full UI
- `stt.endpoint` - STT endpoint must be managed via the full UI
- `lastKnownGoodConfig` - Internal state, do not modify
**Request Body:**
@@ -124,6 +128,31 @@ Returns the updated settings object.
- `400`: Invalid request body or disallowed key
- `401`: Missing or invalid bearer token
### Assistant
**POST `/api/internal/assistant/reload`**
Reload the assistant workspace by disposing the current OpenCode instance. Use this after editing `.opencode/agents/assistant.md` or `opencode.json` so changes take effect on the next message.
**Rate Limiting:** 5 requests per minute per token. Returns `429 Too Many Requests` with `Retry-After` header when exceeded.
**Example:**
```bash
curl -X POST -H "Authorization: Bearer <token>" \
"http://localhost:5003/api/internal/assistant/reload"
```
**Response:**
```ts
{ "success": true }
```
**Status Codes:**
- `200`: Assistant workspace reloaded
- `401`: Missing or invalid bearer token
- `429`: Rate limit exceeded
- `502`: Failed to reload (upstream OpenCode error)
### Repos
**GET `/api/internal/repos`**
+7 -1
View File
@@ -22,11 +22,17 @@ Four skills are provisioned automatically when assistant mode is initialized:
|-------|----------------|
| `schedule-management` | Create, list, update, delete, and run scheduled jobs |
| `notifications` | Send push notifications to registered user devices |
| `manager-settings` | Read and patch user preferences |
| `manager-settings` | Read and patch user preferences, and reload the assistant workspace |
| `repo-management` | List all managed repositories |
See [Assistant Internal API](assistant-internal-api.md) for the full API reference these skills expose.
## Assistant Persona
The assistant's system prompt, behavior, and durable preferences live solely in `.opencode/agents/assistant.md`. This file is the single source of truth for the assistant agent's personality and self-editing rules. The `opencode.json` configuration no longer duplicates the agent persona — it only stores agent mode and workspace-level settings.
When the assistant self-edits its agent definition (e.g., to refine behavior or add durable preferences), it uses the `manager-settings` skill to call the `POST /assistant/reload` endpoint. This disposes the current OpenCode workspace instance so the changes take effect on the next message. The reload endpoint is rate-limited to 5 requests per minute; the assistant always asks the user before reloading.
## Getting Started
1. Click **Assistant** in the sidebar or mobile tab bar