Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(skills): point use-avibe at the /api Web API routes (#3055)

Call White404df377f4ec
diff --git a/skills/use-avibe/SKILL.md b/skills/use-avibe/SKILL.md
index 2ec9b4984..bc4b10666 100644
--- a/skills/use-avibe/SKILL.md
+++ b/skills/use-avibe/SKILL.md
@@ -2,7 +2,7 @@
name: use-avibe
slug: use-avibe
description: Safely inspect and modify local Avibe configuration, routing, runtime settings, watches, scheduled tasks, Avibe Cloud remote access, and operational state. Also use it to report an Avibe bug, send product feedback, or file a feature request from the current conversation.
-version: 0.9.0
+version: 0.9.1
---
# Use Avibe
@@ -39,8 +39,8 @@ Follow this skill as an operations playbook for agents, not as end-user marketin
6. Change one channel, topic, or DM user with `PATCH /api/settings/scope`, which writes only the named fields; `POST /api/settings` replaces the platform's whole channel map.
7. Change a bound DM user's fields with `PATCH /api/settings/scope` (`"scope": "user"`); `POST /api/users` writes each included user as a whole row.
8. Make every persistent-state change through the Web UI API or the `vibe` CLI. Avibe's internal storage is opaque — do not read, query, or hand-edit it.
-9. `POST /config` persists the new payload but does not restart running platform adapters by itself. When the change is platform credentials, `proxy_url`, or other transport-level settings, plan an explicit restart afterwards; prefer the delayed CLI form (`vibe restart --delay-seconds 60`) when triggering it from inside an active conversation. The only credential save that restarts on its own is the WeChat QR-login completion through `POST /wechat/qr_login/poll`.
-10. Do not restart the service by default. Use `POST /doctor`, `GET /status`, and read-back checks first.
+9. `POST /api/config` persists the new payload but does not restart running platform adapters by itself. When the change is platform credentials, `proxy_url`, or other transport-level settings, plan an explicit restart afterwards; prefer the delayed CLI form (`vibe restart --delay-seconds 60`) when triggering it from inside an active conversation. The only credential save that restarts on its own is the WeChat QR-login completion through `POST /api/wechat/qr_login/poll`.
+10. Do not restart the service by default. Use `POST /api/doctor`, `GET /status`, and read-back checks first.
11. Only start, stop, restart, or reload Avibe when the user explicitly asks or when a change cannot take effect otherwise; explain why before doing it.
12. If an agent must restart Avibe from an active conversation, use `vibe restart --delay-seconds 60` so the current session can receive the reply before the restart lands.
13. Tell the user whether the change is global or scope-specific.
@@ -55,16 +55,16 @@ Use this order when changing Avibe configuration:
- When Avibe Cloud remote access is active, the public origin (e.g. `https://<slug>.avibe.bot`) also speaks the same API and requires OIDC session cookies — prefer the local origin from the host running Avibe.
- Check liveness with `GET /health` or `GET /status`.
2. Decide whether the request belongs in:
- - `POST /config` for global defaults, platform credentials, runtime config, agent defaults, UI config, remote-access provider settings, update policy, or global display toggles
+ - `POST /api/config` for global defaults, platform credentials, runtime config, agent defaults, UI config, remote-access provider settings, update policy, or global display toggles
- `PATCH /api/settings/scope` for one channel's, topic's, or DM user's routing, working directory, visibility, enablement, and mention policy
- `/api/users` and `/api/bind-codes` for DM user binding and user-scope settings
- - `/remote-access/*` for Avibe Cloud pairing and tunnel control
+ - `/api/remote-access/*` for Avibe Cloud pairing and tunnel control
- host backend config instead of Avibe when the request is OpenCode, Claude Code, or Codex native behavior
3. Fetch the current state from the matching GET endpoint.
4. Merge the requested change in memory.
5. Send the mutating request through the Web UI API with CSRF protection.
6. Read back the changed resource and verify the effective payload.
-7. Run `POST /doctor` only when the change affects runtime health, platform credentials, or backend availability.
+7. Run `POST /api/doctor` only when the change affects runtime health, platform credentials, or backend availability.
8. Report the changed scope or global keys and whether a restart was avoided or still required.
## Task References
diff --git a/skills/use-avibe/references/api-client.md b/skills/use-avibe/references/api-client.md
index 896cf2391..5dad7a17b 100644
--- a/skills/use-avibe/references/api-client.md
+++ b/skills/use-avibe/references/api-client.md
@@ -45,8 +45,8 @@ export VIBE_UI_BASE="http://127.0.0.1:5123"
python3 skills/use-avibe/scripts/vibe_api.py GET /health
python3 skills/use-avibe/scripts/vibe_api.py GET '/api/settings?platform=slack'
-python3 skills/use-avibe/scripts/vibe_api.py POST /doctor '{}'
-python3 skills/use-avibe/scripts/vibe_api.py POST /config '{"show_duration":true}'
+python3 skills/use-avibe/scripts/vibe_api.py POST /api/doctor '{}'
+python3 skills/use-avibe/scripts/vibe_api.py POST /api/config '{"show_duration":true}'
python3 skills/use-avibe/scripts/vibe_api.py DELETE '/api/users/U123?platform=slack'
```
diff --git a/skills/use-avibe/references/backends.md b/skills/use-avibe/references/backends.md
index 23b0fcfaa..63697e124 100644
--- a/skills/use-avibe/references/backends.md
+++ b/skills/use-avibe/references/backends.md
@@ -2,20 +2,20 @@
### Backend and local helper endpoints
-- `GET /cli/detect?binary=<name-or-path>`
+- `GET /api/cli/detect?binary=<name-or-path>`
- detects a CLI binary path
-- `POST /agent/<name>/install`
+- `POST /api/agent/<name>/install`
- `name` must be `opencode`, `claude`, or `codex`
-- `POST /opencode/options`
+- `POST /api/opencode/options`
- payload: `{"cwd": "/path/to/repo"}`
- returns OpenCode model, agent, and reasoning option data for that cwd
-- `POST /opencode/setup-permission`
+- `POST /api/opencode/setup-permission`
- intentionally writes OpenCode native config to set `permission` to `allow`
-- `GET /claude/agents?cwd=/path/to/repo`
-- `GET /codex/agents?cwd=/path/to/repo`
-- `GET /claude/models`
-- `GET /codex/models`
-- `POST /browse`
+- `GET /api/claude/agents?cwd=/path/to/repo`
+- `GET /api/codex/agents?cwd=/path/to/repo`
+- `GET /api/claude/models`
+- `GET /api/codex/models`
+- `POST /api/browse`
- payload: `{"path": "~", "show_hidden": false}`
## Agent Backend Capability Matrix
@@ -81,7 +81,7 @@ Relevant docs:
- plugins: `https://opencode.ai/docs/plugins/`
- MCP servers: `https://opencode.ai/docs/mcp-servers/`
-Inside Avibe, a scope can select an OpenCode-backed Vibe Agent and then set subagent, model, and reasoning effort overrides. Use `POST /opencode/setup-permission` only for the specific permission helper.
+Inside Avibe, a scope can select an OpenCode-backed Vibe Agent and then set subagent, model, and reasoning effort overrides. Use `POST /api/opencode/setup-permission` only for the specific permission helper.
### Claude Code
diff --git a/skills/use-avibe/references/global-config.md b/skills/use-avibe/references/global-config.md
index fd663967b..06fb5d04a 100644
--- a/skills/use-avibe/references/global-config.md
+++ b/skills/use-avibe/references/global-config.md
@@ -2,9 +2,9 @@
### Global config
-- `GET /config`
+- `GET /api/config`
- returns the current V2 config payload
-- `POST /config`
+- `POST /api/config`
- accepts a partial object, deep-merges it with current config, validates it through `V2Config.from_payload`, then persists it
- use for platform credentials, enabled platforms, primary platform, runtime defaults, agent defaults, UI config, remote-access provider settings, update policy, and global toggles
- the handler only persists and (for `remote_access`) reconciles the cloudflared tunnel; running platform adapters keep using their previous credentials and transport until a restart. Plan a `vibe restart --delay-seconds 60` after any credential, `proxy_url`, or transport-level change.
@@ -140,7 +140,7 @@ Important config payload shape:
}
```
-Discord server access belongs to `/settings`, not `/config`. Store enabled
+Discord server access belongs to `/api/settings`, not `/api/config`. Store enabled
servers under `guilds`, next to channel settings:
```json
@@ -162,13 +162,13 @@ Per-platform fields worth knowing about:
- every platform inherits `proxy_url` from the shared `BaseIMConfig`. Set it when the host machine cannot reach the upstream API directly. Accepts standard HTTP/HTTPS proxy URLs and any `socks*://` URL (`socks4`, `socks4a`, `socks5`, `socks5h`). SOCKS variants route through `aiohttp_socks`.
- `slack.disable_link_unfurl` suppresses link previews when posting messages.
- `discord.thread_auto_archive_minutes` must be one of `60`, `1440`, `4320`, or `10080`.
-- `discord.guild_allowlist` / `guild_denylist` are legacy input lists; current runtime server access lives in `/settings` under `guilds`.
+- `discord.guild_allowlist` / `guild_denylist` are legacy input lists; current runtime server access lives in `/api/settings` under `guilds`.
- `telegram.forum_auto_topic` enables automatic topic creation in forum chats; `use_webhook` plus `webhook_url` / `webhook_secret_token` switches Telegram delivery to the webhook transport.
- `telegram.allowed_chat_ids` / `allowed_user_ids` restrict which chats and users Telegram will respond to.
- `wechat.cdn_base_url` controls the CDN host used for fetching WeChat media; the default `novac2c.cdn.weixin.qq.com` is the official c2c CDN.
- `update.auto_update`, `check_interval_minutes`, and `idle_minutes` control unattended upgrades; `notify_admins` posts the upgrade announcement to bound admins.
- `agents.<backend>.auto_update` (default `true`) installs a newer backend CLI release on the same check once `idle_minutes` have passed without a message and no turn is using that backend; messages that arrive during the install run afterwards. Each release is tried once unattended, and `check_interval_minutes = 0` stops it as well.
-- `ui.setup_host`, `setup_port`, and `open_browser` configure the local Web UI server; changing host or port requires `POST /ui/reload`.
+- `ui.setup_host`, `setup_port`, and `open_browser` configure the local Web UI server; changing host or port requires `POST /api/ui/reload`.
Secret-bearing config fields that you should not print:
@@ -191,40 +191,40 @@ Secret-bearing config fields that you should not print:
### Platform discovery and validation
-- `GET /slack/manifest`
+- `GET /api/slack/manifest`
- returns Slack app manifest JSON for setup
-- `POST /slack/auth_test`
+- `POST /api/slack/auth_test`
- payload: `{"bot_token": "xoxb-..."}`
-- `POST /slack/channels`
+- `POST /api/slack/channels`
- payload: `{"bot_token": "xoxb-...", "browse_all": false}`
-- `POST /discord/auth_test`
+- `POST /api/discord/auth_test`
- payload: `{"bot_token": "..."}`
-- `POST /discord/guilds`
+- `POST /api/discord/guilds`
- payload: `{"bot_token": "..."}`
-- `POST /discord/channels`
+- `POST /api/discord/channels`
- payload: `{"bot_token": "...", "guild_id": "..."}`
-- `POST /telegram/auth_test`
+- `POST /api/telegram/auth_test`
- payload: `{"bot_token": "123:abc"}`
-- `POST /telegram/chats`
+- `POST /api/telegram/chats`
- payload: `{"include_private": false}`
-- `POST /lark/auth_test`
+- `POST /api/lark/auth_test`
- payload: `{"app_id": "...", "app_secret": "...", "domain": "feishu"}`
-- `POST /lark/chats`
+- `POST /api/lark/chats`
- payload: `{"app_id": "...", "app_secret": "...", "domain": "feishu"}`
-- `POST /lark/temp_ws/start`
+- `POST /api/lark/temp_ws/start`
- payload: `{"app_id": "...", "app_secret": "...", "domain": "feishu"}`
-- `POST /lark/temp_ws/stop`
+- `POST /api/lark/temp_ws/stop`
- payload: `{}`
-- `POST /wechat/qr_login/start`
+- `POST /api/wechat/qr_login/start`
- payload: `{"base_url": "https://ilinkai.weixin.qq.com"}` or `{}`
-- `POST /wechat/qr_login/poll`
+- `POST /api/wechat/qr_login/poll`
- payload: `{"session_key": "..."}`
WeChat QR login is special: when login is confirmed and a token is returned, the API auto-binds the WeChat user and schedules an internal service restart so the new token can take effect. Do not add an extra restart unless the user asks.
### Change the global default working directory
-Use `POST /config`:
+Use `POST /api/config`:
```json
{
@@ -238,7 +238,7 @@ Do not overwrite scope-level `custom_cwd` entries.
### Switch primary platform
-Use `POST /config` and keep `platforms.enabled` complete:
+Use `POST /api/config` and keep `platforms.enabled` complete:
```json
{
@@ -256,7 +256,7 @@ Make sure the target platform config section exists and validates. Do not delete
When the host cannot reach a platform API directly, set `proxy_url` on that platform's config block.
-Use `POST /config` with only the proxy field for the affected platform:
+Use `POST /api/config` with only the proxy field for the affected platform:
```json
{
@@ -270,5 +270,5 @@ Notes:
- `proxy_url` accepts `http://`, `https://`, and any `socks*://` scheme (`socks4`, `socks4a`, `socks5`, `socks5h`). The SOCKS variants route through `aiohttp_socks` (bundled).
- Set the field to `null` (or omit it on a fresh save) to disable the proxy.
-- `POST /config` only persists the new value; running platform adapters keep their old transport until the service restarts. After saving, run `vibe restart --delay-seconds 60` (or `POST /control {"action":"restart"}` with the user's confirmation) so the proxy applies to live connections.
+- `POST /api/config` only persists the new value; running platform adapters keep their old transport until the service restarts. After saving, run `vibe restart --delay-seconds 60` (or `POST /api/control {"action":"restart"}` with the user's confirmation) so the proxy applies to live connections.
- Do not paste credentialed proxy URLs (`user:pass@host`) into logs or chat replies; mask the credentials portion when reporting back.
diff --git a/skills/use-avibe/references/operations.md b/skills/use-avibe/references/operations.md
index 54f368897..2c08598f9 100644
--- a/skills/use-avibe/references/operations.md
+++ b/skills/use-avibe/references/operations.md
@@ -4,8 +4,8 @@
Avibe stores runtime data under `~/.avibe/` by default, or under `AVIBE_HOME` when that env var is set. Existing default `~/.vibe_remote/` homes may be migrated to `~/.avibe/` with `~/.vibe_remote` kept as a back-symlink. The only paths an agent normally needs:
-- `~/.avibe/config/config.json` — global config; mutate through `POST /config`, not by editing the file
-- `~/.avibe/logs/vibe_remote.log` — main application log; read via `POST /logs`
+- `~/.avibe/config/config.json` — global config; mutate through `POST /api/config`, not by editing the file
+- `~/.avibe/logs/vibe_remote.log` — main application log; read via `POST /api/logs`
- `~/.avibe/screenshots/` — default output directory for `vibe screenshot`
- `~/.avibe/state/user_preferences.md` — shared long-term preference file (safe to read and update)
@@ -19,31 +19,31 @@ Agent harness state is managed through `vibe agent run`, `vibe task`, `vibe watc
- returns `{"status":"ok"}` when the Web UI server is reachable
- `GET /status`
- returns runtime status, running state, PID metadata, and last action
-- `GET /doctor`
+- `GET /api/doctor`
- reads the latest persisted doctor result
-- `POST /doctor`
+- `POST /api/doctor`
- runs doctor immediately and returns the result
-- `POST /logs`
+- `POST /api/logs`
- payload: `{"lines": 500, "source": "service"}`
- `source` can be `service` or another source listed in the response; use `all` for aggregated logs
-- `GET /version`
+- `GET /api/version`
- returns current version and update metadata
- `GET /api/csrf-token`
- issues the `vibe_csrf_token` cookie and returns the matching token value for `X-Vibe-CSRF-Token`
-- `GET /platforms`
- - returns the static catalog of supported IM platforms only (id, config_key, title/description i18n keys, credential field names, capabilities). It does not include enablement or credential-presence state — fetch `/config` to see which platforms are enabled and whether credentials are configured.
+- `GET /api/platforms`
+ - returns the static catalog of supported IM platforms only (id, config_key, title/description i18n keys, credential field names, capabilities). It does not include enablement or credential-presence state — fetch `/api/config` to see which platforms are enabled and whether credentials are configured.
### Control endpoints
-- `POST /control`
+- `POST /api/control`
- payload: `{"action": "start"}`, `{"action": "stop"}`, or `{"action": "restart"}`
-- `POST /ui/reload`
+- `POST /api/ui/reload`
- payload: `{"host": "127.0.0.1", "port": 5123}`
-- `POST /upgrade`
+- `POST /api/upgrade`
- payload: `{}`
- triggers an in-place upgrade to the latest released version using the same code path as `vibe upgrade`
-Avoid these for routine configuration. `POST /control` starts, stops, or restarts the service. `POST /ui/reload` restarts only the Web UI server to apply host or port changes. `POST /upgrade` reinstalls Avibe and then restarts the service. Use them only with explicit user intent or a concrete need.
+Avoid these for routine configuration. `POST /api/control` starts, stops, or restarts the service. `POST /api/ui/reload` restarts only the Web UI server to apply host or port changes. `POST /api/upgrade` reinstalls Avibe and then restarts the service. Use them only with explicit user intent or a concrete need.
When the restart is initiated by an agent from an active conversation, use the CLI delayed form `vibe restart --delay-seconds 60` so the transport does not cut off the current reply.
@@ -63,7 +63,7 @@ Service lifecycle:
Updates:
- `vibe check-update` — query the release feed and print whether an upgrade is available
-- `vibe upgrade` — reinstall Avibe to the latest release. The CLI does not restart the service for you; it prints "Please restart vibe..." and exits. Run `vibe restart` (or `vibe restart --delay-seconds 60` from inside an active conversation) yourself after the upgrade reports success. The Web UI's `POST /upgrade` endpoint is the path that performs an automatic restart.
+- `vibe upgrade` — reinstall Avibe to the latest release. The CLI does not restart the service for you; it prints "Please restart vibe..." and exits. Run `vibe restart` (or `vibe restart --delay-seconds 60` from inside an active conversation) yourself after the upgrade reports success. The Web UI's `POST /api/upgrade` endpoint is the path that performs an automatic restart.
Remote access:
@@ -98,23 +98,23 @@ For any subcommand, prefer `<command> --help` before composing a new invocation.
Start with evidence:
1. `GET /status`
-2. `POST /doctor`
-3. `POST /logs` with a small line count and focused source
-4. read back `/config`, `/settings`, or `/api/users` for the affected scope
+2. `POST /api/doctor`
+3. `POST /api/logs` with a small line count and focused source
+4. read back `/api/config`, `/api/settings`, or `/api/users` for the affected scope
Common cases:
- config does not apply: verify the API read-back first; only restart if the changed field is startup-only
-- backend missing: confirm backend is enabled, CLI path is executable, and `/cli/detect` finds it
-- channel does not respond: verify `/settings?platform=<platform>` contains the channel and `enabled` is true
+- backend missing: confirm backend is enabled, CLI path is executable, and `/api/cli/detect` finds it
+- channel does not respond: verify `/api/settings?platform=<platform>` contains the channel and `enabled` is true
- wrong repository/cwd: inspect `custom_cwd` and `runtime.default_cwd`
- DM access denied: inspect `/api/users?platform=<platform>` and bind-code state
- platform cannot reach API: inspect `proxy_url` on that platform's config block; check logs for proxy/TLS errors; for SOCKS proxies confirm `aiohttp_socks` is installed
-- remote URL is unreachable: `GET /remote-access/status` should show `running: true` and `binary_found: true`; if not, run `POST /doctor` and check the configured `cloudflared_path`
+- remote URL is unreachable: `GET /api/remote-access/status` should show `running: true` and `binary_found: true`; if not, run `POST /api/doctor` and check the configured `cloudflared_path`
- remote session expired: instruct the user to re-sign in at the public URL (24h TTL with sliding renewal); use `POST /auth/logout` to clear a stale session on the current device
-- upgrade did not apply: inspect the response from `POST /upgrade` (auto-restart on success) or `vibe upgrade` (does not auto-restart — run `vibe restart` manually), then verify with `vibe status` that the new PID is running
-- startup failure: use `GET /status`, `POST /doctor`, then inspect logs
+- upgrade did not apply: inspect the response from `POST /api/upgrade` (auto-restart on success) or `vibe upgrade` (does not auto-restart — run `vibe restart` manually), then verify with `vibe status` that the new PID is running
+- startup failure: use `GET /status`, `POST /api/doctor`, then inspect logs
-Do not use `vibe restart`, `POST /control {"action":"restart"}`, or `POST /ui/reload` as a first response to config problems.
+Do not use `vibe restart`, `POST /api/control {"action":"restart"}`, or `POST /api/ui/reload` as a first response to config problems.
If a restart is still required and you are replying through an active Avibe conversation, use `vibe restart --delay-seconds 60` so the current reply can be delivered before the restart lands.
diff --git a/skills/use-avibe/references/remote-access.md b/skills/use-avibe/references/remote-access.md
index 9084ba18a..1aecff75f 100644
--- a/skills/use-avibe/references/remote-access.md
+++ b/skills/use-avibe/references/remote-access.md
@@ -2,7 +2,7 @@
### Remote access (Avibe Cloud)
-These endpoints drive the managed `avibe.bot` tunnel that exposes the local Web UI to other devices. They are paired with the `remote_access.vibe_cloud` block under `/config`.
+These endpoints drive the managed `avibe.bot` tunnel that exposes the local Web UI to other devices. They are paired with the `remote_access.vibe_cloud` block under `/api/config`.
- `GET /api/remote-access/status`
- returns `enabled`, `paired`, `public_url`, `running` (tunnel up), `pid`, `pid_state`, plus `binary_found` / `binary_path` / `binary_version` for the resolved `cloudflared` executable. Use `running: true` to assert the tunnel is up.
@@ -42,8 +42,8 @@ Treat `tunnel_token`, `instance_secret`, `session_secret`, and `client_id` from
Goal: connect the local Web UI to `avibe.bot` so it is reachable from another device.
1. The user signs in at `https://avibe.bot`, creates a remote-access bot, and copies the one-time pairing key (format `vrp_...`).
-2. Call `POST /remote-access/vibe-cloud/pair` with `{"pairing_key": "vrp_..."}` from the local Web UI origin.
-3. Verify with `GET /remote-access/status` — `enabled: true`, `paired: true`, `public_url` populated, `running: true`.
+2. Call `POST /api/remote-access/vibe-cloud/pair` with `{"pairing_key": "vrp_..."}` from the local Web UI origin.
+3. Verify with `GET /api/remote-access/status` — `enabled: true`, `paired: true`, `public_url` populated, `running: true`.
4. Have the user open `public_url` and sign in with the same avibe.bot account.
Alternatively, drive the same flow from the CLI:
diff --git a/skills/use-avibe/references/scopes-and-routing.md b/skills/use-avibe/references/scopes-and-routing.md
index 279cab942..5a89990ee 100644
--- a/skills/use-avibe/references/scopes-and-routing.md
+++ b/skills/use-avibe/references/scopes-and-routing.md
@@ -122,14 +122,14 @@ Agent resolution priority is:
3. global default Vibe Agent from the Agent catalog
4. registered backend compatibility fallback, only when no enabled default Agent is available
-If the user names a specific channel or DM and wants a specific Agent, use the scope API, not global `/config`. New routing is Agent-based.
+If the user names a specific channel or DM and wants a specific Agent, use the scope API, not global `/api/config`. New routing is Agent-based.
### Working directory
Working directory resolution is:
1. `custom_cwd` on the target channel or user scope
-2. `runtime.default_cwd` from `/config`
+2. `runtime.default_cwd` from `/api/config`
### Message visibility
@@ -141,7 +141,7 @@ If a user asks for "vault messages", "internal messages", or "tool execution mes
`require_mention` works like this:
-- `null`: inherit platform default from `/config`
+- `null`: inherit platform default from `/api/config`
- `true`: require mention in that channel
- `false`: do not require mention in that channel
diff --git a/skills/use-avibe/scripts/vibe_api.py b/skills/use-avibe/scripts/vibe_api.py
index b7b6dc248..c3ea53e43 100755
--- a/skills/use-avibe/scripts/vibe_api.py
+++ b/skills/use-avibe/scripts/vibe_api.py
@@ -48,9 +48,9 @@ class VibeApiClient:
method = method.upper()
url = urllib.parse.urljoin(self.base_url + "/", path.lstrip("/"))
data = None if payload is None else json.dumps(payload).encode("utf-8")
- headers = {"Accept": "application/json"}
+ # Protected reads need the same-origin evidence mutations do.
+ headers = {"Accept": "application/json", "Origin": self.base_url}
if method in MUTATING_METHODS:
- headers["Origin"] = self.base_url
headers["Content-Type"] = "application/json"
headers["X-Vibe-CSRF-Token"] = self.get_csrf_token()
@@ -90,7 +90,7 @@ def main(argv: list[str] | None = None) -> int:
description="Call the local Avibe Web UI API with CSRF handling.",
)
parser.add_argument("method", help="HTTP method, for example GET, POST, DELETE")
- parser.add_argument("path", help="API path, for example /settings?platform=slack")
+ parser.add_argument("path", help="API path, for example /api/settings?platform=slack")
parser.add_argument(
"payload",
nargs="?",
diff --git a/tests/test_use_avibe_api_paths.py b/tests/test_use_avibe_api_paths.py
new file mode 100644
index 000000000..f1986b2e8
--- /dev/null
+++ b/tests/test_use_avibe_api_paths.py
@@ -0,0 +1,101 @@
+"""The use-avibe Skill's Web API calls reach the routes the Web UI serves.
+
+Its pages named bare paths (`POST /config`, `GET /settings`) long after the API
+moved under `/api/`; an Agent following them got the SPA's HTML back.
+"""
+
+from __future__ import annotations
+
+import importlib.util
+import re
+import threading
+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
+from pathlib import Path
+
+import pytest
+
+from vibe import ui_server
+
+SKILL = Path(__file__).resolve().parents[1] / "skills" / "use-avibe"
+# `GET /api/x`, `vibe_api.py POST /api/x '{}'`, `GET '/api/x?platform=...'`
+CALL = re.compile(r"\b(GET|POST|PUT|PATCH|DELETE) '?(/[^\s'`?\"]*)")
+
+
+def _documented_calls() -> list[tuple[str, str, str]]:
+ calls = set()
+ for page in sorted(SKILL.rglob("*.md")):
+ for method, path in CALL.findall(page.read_text(encoding="utf-8")):
+ calls.add((page.relative_to(SKILL).as_posix(), method, path))
+ return sorted(calls)
+
+
+def _served_routes() -> list[tuple[frozenset[str], re.Pattern[str]]]:
+ served = []
+ for route in ui_server.app.routes:
+ path = getattr(route, "path", None)
+ # The SPA fallback (`/{path:path}`) answers any path with the app's HTML:
+ # exactly what a stale documented path gets back, so it serves no call.
+ if not path or ":path}" in path:
+ continue
+ pattern = re.sub(r"\\\{[^}]+\\\}", "[^/]+", re.escape(path))
+ served.append((frozenset(getattr(route, "methods", None) or ()), re.compile(f"{pattern}$")))
+ return served
+
+
+def _is_served(method: str, path: str) -> bool:
+ concrete = re.sub(r"<[^>]+>", "x", path)
+ return any(method in methods and pattern.match(concrete) for methods, pattern in _served_routes())
+
+
+def test_the_skill_documents_web_api_calls() -> None:
+ assert len(_documented_calls()) > 40
+
+
+def test_a_path_only_the_spa_answers_is_not_served() -> None:
+ assert _is_served("GET", "/api/config") and _is_served("GET", "/status")
+ for method, path in (("GET", "/config"), ("GET", "/settings"), ("GET", "/version"), ("POST", "/config")):
+ assert not _is_served(method, path), f"{method} {path}"
+
+
[email protected](("page", "method", "path"), _documented_calls())
+def test_every_documented_call_names_a_served_route(page: str, method: str, path: str) -> None:
+ assert _is_served(method, path), f"{page}: {method} {path} is not a Web UI route"
+
+
+def _load_helper():
+ spec = importlib.util.spec_from_file_location("vibe_api_helper", SKILL / "scripts" / "vibe_api.py")
+ module = importlib.util.module_from_spec(spec)
+ assert spec.loader is not None
+ spec.loader.exec_module(module)
+ return module
+
+
+def test_the_helper_sends_same_origin_evidence_on_reads(tmp_path: Path) -> None:
+ seen: list[dict[str, str]] = []
+
+ class Handler(BaseHTTPRequestHandler):
+ def do_GET(self): # noqa: N802 - http.server API
+ seen.append(dict(self.headers))
+ body = b'{"ok": true}'
+ self.send_response(200)
+ self.send_header("Content-Type", "application/json")
+ self.send_header("Content-Length", str(len(body)))
+ self.end_headers()
+ self.wfile.write(body)
+
+ def log_message(self, *_args):
+ pass
+
+ server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ base = f"http://127.0.0.1:{server.server_address[1]}"
+ try:
+ client = _load_helper().VibeApiClient(base, cookie_jar_path=tmp_path / "cookies")
+ assert client.call("GET", "/api/cli/detect?binary=codex") == {"ok": True}
+ finally:
+ server.shutdown()
+ server.server_close()
+
+ # A protected read (`/api/cli/detect`) is refused without it.
+ assert seen[0].get("Origin") == base