Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68ecee84d1 | ||
|
|
d1ebc4489a | ||
|
|
a71efbe7de | ||
|
|
a7b8c0d963 |
No files matched your search
@@ -5,11 +5,9 @@
|
|||||||
### Breaking
|
### Breaking
|
||||||
- Identifiers: rename bundle IDs and internal domains to `com.clawdis.*` (macOS: `com.clawdis.mac`, iOS: `com.clawdis.ios`, Android: `com.clawdis.android`) and update the gateway LaunchAgent label to `com.clawdis.gateway`.
|
- Identifiers: rename bundle IDs and internal domains to `com.clawdis.*` (macOS: `com.clawdis.mac`, iOS: `com.clawdis.ios`, Android: `com.clawdis.android`) and update the gateway LaunchAgent label to `com.clawdis.gateway`.
|
||||||
- Agent tools: drop the `clawdis_` prefix (`browser`, `canvas`, `nodes`, `cron`, `gateway`).
|
- Agent tools: drop the `clawdis_` prefix (`browser`, `canvas`, `nodes`, `cron`, `gateway`).
|
||||||
- Bash tool: remove `stdinMode: "pty"`/node-pty support; use the tmux skill for real TTYs.
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
- Gateway: support `gateway.port` + `CLAWDIS_GATEWAY_PORT` across CLI, TUI, and macOS app.
|
- Gateway: support `gateway.port` + `CLAWDIS_GATEWAY_PORT` across CLI, TUI, and macOS app.
|
||||||
- Gateway: add config hot reload with hybrid restart strategy (`gateway.reload`) and per-section reload handling.
|
|
||||||
- UI: centralize tool display metadata and show action/detail summaries across Web Chat, SwiftUI, Android, and the TUI.
|
- UI: centralize tool display metadata and show action/detail summaries across Web Chat, SwiftUI, Android, and the TUI.
|
||||||
- Control UI: support configurable base paths (`gateway.controlUi.basePath`, default unchanged) for hosting under URL prefixes.
|
- Control UI: support configurable base paths (`gateway.controlUi.basePath`, default unchanged) for hosting under URL prefixes.
|
||||||
- Onboarding: shared wizard engine powering CLI + macOS via gateway wizard RPC.
|
- Onboarding: shared wizard engine powering CLI + macOS via gateway wizard RPC.
|
||||||
@@ -18,9 +16,7 @@
|
|||||||
- Discord: emit system events for reaction add/remove with per-guild reaction notifications (off|own|all|allowlist) (#140) — thanks @thewilloftheshadow.
|
- Discord: emit system events for reaction add/remove with per-guild reaction notifications (off|own|all|allowlist) (#140) — thanks @thewilloftheshadow.
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Browser tools: tolerate trailing semicolons in evaluate expressions (#153) — thanks @azade-c.
|
|
||||||
- Auto-reply: drop final payloads when block streaming to avoid duplicate Discord sends.
|
- Auto-reply: drop final payloads when block streaming to avoid duplicate Discord sends.
|
||||||
- Bash tool: default auto-background delay to 10s.
|
|
||||||
- Telegram: chunk block-stream replies to avoid “message is too long” errors (#124) — thanks @mukhtharcm.
|
- Telegram: chunk block-stream replies to avoid “message is too long” errors (#124) — thanks @mukhtharcm.
|
||||||
- Block streaming: default to text_end and suppress duplicate block sends while in-flight.
|
- Block streaming: default to text_end and suppress duplicate block sends while in-flight.
|
||||||
- Block streaming: avoid duplicate block chunks when providers repeat full content on text_end.
|
- Block streaming: avoid duplicate block chunks when providers repeat full content on text_end.
|
||||||
@@ -51,7 +47,6 @@
|
|||||||
- Skills: document Discord `sendMessage` media attachments and `to` format clarification.
|
- Skills: document Discord `sendMessage` media attachments and `to` format clarification.
|
||||||
- Skills: add tmux skill + interactive coding guidance in coding-agent.
|
- Skills: add tmux skill + interactive coding guidance in coding-agent.
|
||||||
- Gateway: document port configuration + multi-instance isolation.
|
- Gateway: document port configuration + multi-instance isolation.
|
||||||
- Gateway: document config hot reload + reload matrix.
|
|
||||||
- Onboarding/Config: add protocol notes for wizard + schema RPC.
|
- Onboarding/Config: add protocol notes for wizard + schema RPC.
|
||||||
- Queue: clarify steer-backlog behavior with inline commands and update examples for streaming surfaces.
|
- Queue: clarify steer-backlog behavior with inline commands and update examples for streaming surfaces.
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ Clawdis runs shell commands through the `bash` tool and keeps long‑running tas
|
|||||||
|
|
||||||
Key parameters:
|
Key parameters:
|
||||||
- `command` (required)
|
- `command` (required)
|
||||||
- `yieldMs` (default 10000): auto‑background after this delay
|
- `yieldMs` (default 20000): auto‑background after this delay
|
||||||
- `background` (bool): background immediately
|
- `background` (bool): background immediately
|
||||||
- `timeout` (seconds, default 1800): kill the process after this timeout
|
- `timeout` (seconds, default 1800): kill the process after this timeout
|
||||||
- Need a real TTY? Use the tmux skill.
|
- `stdinMode` (`pipe` | `pty`): use a real TTY when `pty` is requested and node-pty loads (otherwise warns + falls back)
|
||||||
- `workdir`, `env`
|
- `workdir`, `env`
|
||||||
|
|
||||||
Behavior:
|
Behavior:
|
||||||
@@ -30,7 +30,7 @@ Environment overrides:
|
|||||||
- `PI_BASH_JOB_TTL_MS`: TTL for finished sessions (ms, bounded to 1m–3h)
|
- `PI_BASH_JOB_TTL_MS`: TTL for finished sessions (ms, bounded to 1m–3h)
|
||||||
|
|
||||||
Config (preferred):
|
Config (preferred):
|
||||||
- `agent.bash.backgroundMs` (default 10000)
|
- `agent.bash.backgroundMs` (default 20000)
|
||||||
- `agent.bash.timeoutSec` (default 1800)
|
- `agent.bash.timeoutSec` (default 1800)
|
||||||
- `agent.bash.cleanupMs` (default 1800000)
|
- `agent.bash.cleanupMs` (default 1800000)
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -12,10 +12,18 @@ Run shell commands in the workspace. Supports foreground + background execution
|
|||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
- `command` (required)
|
- `command` (required)
|
||||||
- `yieldMs` (default 10000): auto-background after delay
|
- `yieldMs` (default 20000): auto-background after delay
|
||||||
- `background` (bool): background immediately
|
- `background` (bool): background immediately
|
||||||
- `timeout` (seconds, default 1800): kill on expiry
|
- `timeout` (seconds, default 1800): kill on expiry
|
||||||
- Need a real TTY? Use the tmux skill.
|
- `stdinMode` (`pipe` | `pty`):
|
||||||
|
- `pipe` (default): classic stdin/stdout/stderr pipes
|
||||||
|
- `pty`: real TTY via node-pty (merged stdout/stderr)
|
||||||
|
|
||||||
|
## TTY mode (`stdinMode: "pty"`)
|
||||||
|
|
||||||
|
- Uses node-pty if available. If node-pty fails to load/start, the tool warns and falls back to `pipe`.
|
||||||
|
- Output streams are merged (no separate stderr).
|
||||||
|
- `process write` sends raw input; `eof: true` sends Ctrl-D (`\x04`).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -29,3 +37,8 @@ Background + poll:
|
|||||||
{"tool":"bash","command":"npm run build","yieldMs":1000}
|
{"tool":"bash","command":"npm run build","yieldMs":1000}
|
||||||
{"tool":"process","action":"poll","sessionId":"<id>"}
|
{"tool":"process","action":"poll","sessionId":"<id>"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
TTY command:
|
||||||
|
```json
|
||||||
|
{"tool":"bash","command":"htop","stdinMode":"pty","background":true}
|
||||||
|
```
|
||||||
+2
-44
@@ -388,7 +388,7 @@ Controls the embedded agent runtime (model/thinking/verbose/timeouts).
|
|||||||
},
|
},
|
||||||
maxConcurrent: 3,
|
maxConcurrent: 3,
|
||||||
bash: {
|
bash: {
|
||||||
backgroundMs: 10000,
|
backgroundMs: 20000,
|
||||||
timeoutSec: 1800,
|
timeoutSec: 1800,
|
||||||
cleanupMs: 1800000
|
cleanupMs: 1800000
|
||||||
},
|
},
|
||||||
@@ -427,7 +427,7 @@ Z.AI models are available as `zai/<model>` (e.g. `zai/glm-4.7`) and require
|
|||||||
- `prompt`: optional override for the heartbeat body (default: `HEARTBEAT`).
|
- `prompt`: optional override for the heartbeat body (default: `HEARTBEAT`).
|
||||||
|
|
||||||
`agent.bash` configures background bash defaults:
|
`agent.bash` configures background bash defaults:
|
||||||
- `backgroundMs`: time before auto-background (ms, default 10000)
|
- `backgroundMs`: time before auto-background (ms, default 20000)
|
||||||
- `timeoutSec`: auto-kill after this runtime (seconds, default 1800)
|
- `timeoutSec`: auto-kill after this runtime (seconds, default 1800)
|
||||||
- `cleanupMs`: how long to keep finished sessions in memory (ms, default 1800000)
|
- `cleanupMs`: how long to keep finished sessions in memory (ms, default 1800000)
|
||||||
|
|
||||||
@@ -696,48 +696,6 @@ Remote client defaults (CLI):
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `gateway.reload` (Config hot reload)
|
|
||||||
|
|
||||||
The Gateway watches `~/.clawdis/clawdis.json` (or `CLAWDIS_CONFIG_PATH`) and applies changes automatically.
|
|
||||||
|
|
||||||
Modes:
|
|
||||||
- `hybrid` (default): hot-apply safe changes; restart the Gateway for critical changes.
|
|
||||||
- `hot`: only apply hot-safe changes; log when a restart is required.
|
|
||||||
- `restart`: restart the Gateway on any config change.
|
|
||||||
- `off`: disable hot reload.
|
|
||||||
|
|
||||||
```json5
|
|
||||||
{
|
|
||||||
gateway: {
|
|
||||||
reload: {
|
|
||||||
mode: "hybrid",
|
|
||||||
debounceMs: 300
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Hot reload matrix (files + impact)
|
|
||||||
|
|
||||||
Files watched:
|
|
||||||
- `~/.clawdis/clawdis.json` (or `CLAWDIS_CONFIG_PATH`)
|
|
||||||
|
|
||||||
Hot-applied (no full gateway restart):
|
|
||||||
- `hooks` (webhook auth/path/mappings) + `hooks.gmail` (Gmail watcher restarted)
|
|
||||||
- `browser` (browser control server restart)
|
|
||||||
- `cron` (cron service restart + concurrency update)
|
|
||||||
- `agent.heartbeat` (heartbeat runner restart)
|
|
||||||
- `web` (WhatsApp web provider restart)
|
|
||||||
- `telegram`, `discord`, `signal`, `imessage` (provider restarts)
|
|
||||||
- `agent`, `models`, `routing`, `messages`, `session`, `whatsapp`, `logging`, `skills`, `ui`, `talk`, `identity`, `wizard` (dynamic reads)
|
|
||||||
|
|
||||||
Requires full Gateway restart:
|
|
||||||
- `gateway` (port/bind/auth/control UI/tailscale)
|
|
||||||
- `bridge`
|
|
||||||
- `discovery`
|
|
||||||
- `canvasHost`
|
|
||||||
- Any unknown/unsupported config path (defaults to restart for safety)
|
|
||||||
|
|
||||||
### Multi-instance isolation
|
### Multi-instance isolation
|
||||||
|
|
||||||
To run multiple gateways on one host, isolate per-instance state + config and use unique ports:
|
To run multiple gateways on one host, isolate per-instance state + config and use unique ports:
|
||||||
|
|||||||
-26
@@ -530,32 +530,6 @@ Use `/model` to switch without restarting:
|
|||||||
|
|
||||||
**Tip:** `/model` is processed at the gateway level — it works even if you're rate-limited (429) on the current model!
|
**Tip:** `/model` is processed at the gateway level — it works even if you're rate-limited (429) on the current model!
|
||||||
|
|
||||||
### Alternative providers (OpenRouter, Z.AI)?
|
|
||||||
|
|
||||||
If you don't want to use Anthropic directly, you can use alternative providers:
|
|
||||||
|
|
||||||
**OpenRouter** (pay-per-token, many models):
|
|
||||||
```json5
|
|
||||||
{
|
|
||||||
agent: {
|
|
||||||
model: "openrouter/anthropic/claude-sonnet-4",
|
|
||||||
env: { OPENROUTER_API_KEY: "sk-or-..." }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Z.AI** (flat-rate plans, GLM models):
|
|
||||||
```json5
|
|
||||||
{
|
|
||||||
agent: {
|
|
||||||
model: "zai/glm-4.7",
|
|
||||||
env: { ZAI_API_KEY: "..." }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Important:** Always use the latest Claude models (4.5 series). Don't use older 3.x models — they're deprecated and less capable. Check [OpenRouter models](https://openrouter.ai/models?q=claude) for exact IDs.
|
|
||||||
|
|
||||||
### Model + thinking mode issues?
|
### Model + thinking mode issues?
|
||||||
|
|
||||||
Some models don't support extended thinking well:
|
Some models don't support extended thinking well:
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ pnpm clawdis gateway --force
|
|||||||
# dev loop (auto-reload on TS changes):
|
# dev loop (auto-reload on TS changes):
|
||||||
pnpm gateway:watch
|
pnpm gateway:watch
|
||||||
```
|
```
|
||||||
- Config hot reload watches `~/.clawdis/clawdis.json` (or `CLAWDIS_CONFIG_PATH`).
|
|
||||||
- Default mode: `gateway.reload.mode="hybrid"` (hot-apply safe changes, restart on critical).
|
|
||||||
- Hot reload uses in-process restart via **SIGUSR1** when needed.
|
|
||||||
- Disable with `gateway.reload.mode="off"`.
|
|
||||||
- Binds WebSocket control plane to `127.0.0.1:<port>` (default 18789).
|
- Binds WebSocket control plane to `127.0.0.1:<port>` (default 18789).
|
||||||
- The same port also serves HTTP (control UI, hooks, A2UI). Single-port multiplex.
|
- The same port also serves HTTP (control UI, hooks, A2UI). Single-port multiplex.
|
||||||
- Starts a Canvas file server by default on `canvasHost.port` (default `18793`), serving `http://<gateway-host>:18793/__clawdis__/canvas/` from `~/clawd/canvas`. Disable with `canvasHost.enabled=false` or `CLAWDIS_SKIP_CANVAS_HOST=1`.
|
- Starts a Canvas file server by default on `canvasHost.port` (default `18793`), serving `http://<gateway-host>:18793/__clawdis__/canvas/` from `~/clawd/canvas`. Disable with `canvasHost.enabled=false` or `CLAWDIS_SKIP_CANVAS_HOST=1`.
|
||||||
|
|||||||
Vendored
-7
@@ -73,13 +73,6 @@ You have access to your human's stuff. That doesn't mean you *share* their stuff
|
|||||||
|
|
||||||
Skills provide your tools. When you need one, check its `SKILL.md`. Keep local notes (camera names, SSH details, voice preferences) in `TOOLS.md`.
|
Skills provide your tools. When you need one, check its `SKILL.md`. Keep local notes (camera names, SSH details, voice preferences) in `TOOLS.md`.
|
||||||
|
|
||||||
**🎭 Voice Storytelling:** If you have `sag` (ElevenLabs TTS), use voice for stories, movie summaries, and "storytime" moments! Way more engaging than walls of text. Surprise people with funny voices.
|
|
||||||
|
|
||||||
**📝 Platform Formatting:**
|
|
||||||
- **Discord/WhatsApp:** No markdown tables! Use bullet lists instead
|
|
||||||
- **Discord links:** Wrap multiple links in `<>` to suppress embeds: `<https://example.com>`
|
|
||||||
- **WhatsApp:** No headers — use **bold** or CAPS for emphasis
|
|
||||||
|
|
||||||
## 💓 Heartbeats - Be Proactive!
|
## 💓 Heartbeats - Be Proactive!
|
||||||
|
|
||||||
When you receive a `HEARTBEAT` message, don't just reply `HEARTBEAT_OK` every time. Use heartbeats productively!
|
When you receive a `HEARTBEAT` message, don't just reply `HEARTBEAT_OK` every time. Use heartbeats productively!
|
||||||
|
|||||||
+2
-2
@@ -18,10 +18,10 @@ Run shell commands in the workspace.
|
|||||||
|
|
||||||
Core parameters:
|
Core parameters:
|
||||||
- `command` (required)
|
- `command` (required)
|
||||||
- `yieldMs` (auto-background after timeout, default 10000)
|
- `yieldMs` (auto-background after timeout, default 20000)
|
||||||
- `background` (immediate background)
|
- `background` (immediate background)
|
||||||
- `timeout` (seconds; kills the process if exceeded, default 1800)
|
- `timeout` (seconds; kills the process if exceeded, default 1800)
|
||||||
- Need a real TTY? Use the tmux skill.
|
- `stdinMode` (`pipe` | `pty`; `pty` uses node-pty for a real TTY with fallback warning)
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
- Returns `status: "running"` with a `sessionId` when backgrounded.
|
- Returns `status: "running"` with a `sessionId` when backgrounded.
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
"grammy": "^1.39.2",
|
"grammy": "^1.39.2",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"long": "5.3.2",
|
"long": "5.3.2",
|
||||||
|
"node-pty": "^1.1.0",
|
||||||
"playwright-core": "1.57.0",
|
"playwright-core": "1.57.0",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"sharp": "^0.34.5",
|
"sharp": "^0.34.5",
|
||||||
|
|||||||
Generated
+10
@@ -94,6 +94,9 @@ importers:
|
|||||||
long:
|
long:
|
||||||
specifier: 5.3.2
|
specifier: 5.3.2
|
||||||
version: 5.3.2
|
version: 5.3.2
|
||||||
|
node-pty:
|
||||||
|
specifier: ^1.1.0
|
||||||
|
version: 1.1.0
|
||||||
playwright-core:
|
playwright-core:
|
||||||
specifier: 1.57.0
|
specifier: 1.57.0
|
||||||
version: 1.57.0
|
version: 1.57.0
|
||||||
@@ -2185,6 +2188,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
|
resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
|
||||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||||
|
|
||||||
|
node-pty@1.1.0:
|
||||||
|
resolution: {integrity: sha512-20JqtutY6JPXTUnL0ij1uad7Qe1baT46lyolh2sSENDd4sTzKZ4nmAFkeAARDKwmlLjPx6XKRlwRUxwjOy+lUg==}
|
||||||
|
|
||||||
node-wav@0.0.2:
|
node-wav@0.0.2:
|
||||||
resolution: {integrity: sha512-M6Rm/bbG6De/gKGxOpeOobx/dnGuP0dz40adqx38boqHhlWssBJZgLCPBNtb9NkrmnKYiV04xELq+R6PFOnoLA==}
|
resolution: {integrity: sha512-M6Rm/bbG6De/gKGxOpeOobx/dnGuP0dz40adqx38boqHhlWssBJZgLCPBNtb9NkrmnKYiV04xELq+R6PFOnoLA==}
|
||||||
engines: {node: '>=4.4.0'}
|
engines: {node: '>=4.4.0'}
|
||||||
@@ -4828,6 +4834,10 @@ snapshots:
|
|||||||
fetch-blob: 3.2.0
|
fetch-blob: 3.2.0
|
||||||
formdata-polyfill: 4.0.10
|
formdata-polyfill: 4.0.10
|
||||||
|
|
||||||
|
node-pty@1.1.0:
|
||||||
|
dependencies:
|
||||||
|
node-addon-api: 7.1.1
|
||||||
|
|
||||||
node-wav@0.0.2:
|
node-wav@0.0.2:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
|||||||
@@ -41,15 +41,9 @@ process action:kill sessionId:XXX
|
|||||||
|
|
||||||
**Model:** `gpt-5.2-codex` is the default (set in ~/.codex/config.toml)
|
**Model:** `gpt-5.2-codex` is the default (set in ~/.codex/config.toml)
|
||||||
|
|
||||||
### Building/Creating (use --full-auto or --yolo)
|
### Building/Creating (use --full-auto)
|
||||||
```bash
|
```bash
|
||||||
# --full-auto: sandboxed but auto-approves in workspace
|
|
||||||
bash workdir:~/project background:true command:"codex exec --full-auto \"Build a snake game with dark theme\""
|
bash workdir:~/project background:true command:"codex exec --full-auto \"Build a snake game with dark theme\""
|
||||||
|
|
||||||
# --yolo: NO sandbox, NO approvals (fastest, most dangerous)
|
|
||||||
bash workdir:~/project background:true command:"codex --yolo \"Build a snake game with dark theme\""
|
|
||||||
|
|
||||||
# Note: --yolo is a shortcut for --dangerously-bypass-approvals-and-sandbox
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Reviewing PRs (vanilla, no flags)
|
### Reviewing PRs (vanilla, no flags)
|
||||||
@@ -150,51 +144,6 @@ Use the tmux skill for interactive coding sessions (always, except very simple o
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Parallel Issue Fixing with git worktrees + tmux
|
|
||||||
|
|
||||||
For fixing multiple issues in parallel, use git worktrees (isolated branches) + tmux sessions:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 1. Clone repo to temp location
|
|
||||||
cd /tmp && git clone git@github.com:user/repo.git repo-worktrees
|
|
||||||
cd repo-worktrees
|
|
||||||
|
|
||||||
# 2. Create worktrees for each issue (isolated branches!)
|
|
||||||
git worktree add -b fix/issue-78 /tmp/issue-78 main
|
|
||||||
git worktree add -b fix/issue-99 /tmp/issue-99 main
|
|
||||||
|
|
||||||
# 3. Set up tmux sessions
|
|
||||||
SOCKET="${TMPDIR:-/tmp}/codex-fixes.sock"
|
|
||||||
tmux -S "$SOCKET" new-session -d -s fix-78
|
|
||||||
tmux -S "$SOCKET" new-session -d -s fix-99
|
|
||||||
|
|
||||||
# 4. Launch Codex in each (after pnpm install!)
|
|
||||||
tmux -S "$SOCKET" send-keys -t fix-78 "cd /tmp/issue-78 && pnpm install && codex --yolo 'Fix issue #78: <description>. Commit and push.'" Enter
|
|
||||||
tmux -S "$SOCKET" send-keys -t fix-99 "cd /tmp/issue-99 && pnpm install && codex --yolo 'Fix issue #99: <description>. Commit and push.'" Enter
|
|
||||||
|
|
||||||
# 5. Monitor progress
|
|
||||||
tmux -S "$SOCKET" capture-pane -p -t fix-78 -S -30
|
|
||||||
tmux -S "$SOCKET" capture-pane -p -t fix-99 -S -30
|
|
||||||
|
|
||||||
# 6. Check if done (prompt returned)
|
|
||||||
tmux -S "$SOCKET" capture-pane -p -t fix-78 -S -3 | grep -q "❯" && echo "Done!"
|
|
||||||
|
|
||||||
# 7. Create PRs after fixes
|
|
||||||
cd /tmp/issue-78 && git push -u origin fix/issue-78
|
|
||||||
gh pr create --repo user/repo --head fix/issue-78 --title "fix: ..." --body "..."
|
|
||||||
|
|
||||||
# 8. Cleanup
|
|
||||||
tmux -S "$SOCKET" kill-server
|
|
||||||
git worktree remove /tmp/issue-78
|
|
||||||
git worktree remove /tmp/issue-99
|
|
||||||
```
|
|
||||||
|
|
||||||
**Why worktrees?** Each Codex works in isolated branch, no conflicts. Can run 5+ parallel fixes!
|
|
||||||
|
|
||||||
**Why tmux over bash background?** Codex is interactive — needs TTY for proper output. tmux provides persistent sessions with full history capture.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ⚠️ Rules
|
## ⚠️ Rules
|
||||||
|
|
||||||
1. **Respect tool choice** — if user asks for Codex, use Codex. NEVER offer to build it yourself!
|
1. **Respect tool choice** — if user asks for Codex, use Codex. NEVER offer to build it yourself!
|
||||||
|
|||||||
@@ -65,41 +65,6 @@ To monitor:
|
|||||||
- tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL.
|
- tmux is supported on macOS/Linux. On Windows, use WSL and install tmux inside WSL.
|
||||||
- This skill is gated to `darwin`/`linux` and requires `tmux` on PATH.
|
- This skill is gated to `darwin`/`linux` and requires `tmux` on PATH.
|
||||||
|
|
||||||
## Orchestrating Coding Agents (Codex, Claude Code)
|
|
||||||
|
|
||||||
tmux excels at running multiple coding agents in parallel:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
SOCKET="${TMPDIR:-/tmp}/codex-army.sock"
|
|
||||||
|
|
||||||
# Create multiple sessions
|
|
||||||
for i in 1 2 3 4 5; do
|
|
||||||
tmux -S "$SOCKET" new-session -d -s "agent-$i"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Launch agents in different workdirs
|
|
||||||
tmux -S "$SOCKET" send-keys -t agent-1 "cd /tmp/project1 && codex --yolo 'Fix bug X'" Enter
|
|
||||||
tmux -S "$SOCKET" send-keys -t agent-2 "cd /tmp/project2 && codex --yolo 'Fix bug Y'" Enter
|
|
||||||
|
|
||||||
# Poll for completion (check if prompt returned)
|
|
||||||
for sess in agent-1 agent-2; do
|
|
||||||
if tmux -S "$SOCKET" capture-pane -p -t "$sess" -S -3 | grep -q "❯"; then
|
|
||||||
echo "$sess: DONE"
|
|
||||||
else
|
|
||||||
echo "$sess: Running..."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Get full output from completed session
|
|
||||||
tmux -S "$SOCKET" capture-pane -p -t agent-1 -S -500
|
|
||||||
```
|
|
||||||
|
|
||||||
**Tips:**
|
|
||||||
- Use separate git worktrees for parallel fixes (no branch conflicts)
|
|
||||||
- `pnpm install` first before running codex in fresh clones
|
|
||||||
- Check for shell prompt (`❯` or `$`) to detect completion
|
|
||||||
- Codex needs `--yolo` or `--full-auto` for non-interactive fixes
|
|
||||||
|
|
||||||
## Cleanup
|
## Cleanup
|
||||||
|
|
||||||
- Kill a session: `tmux -S "$SOCKET" kill-session -t "$SESSION"`.
|
- Kill a session: `tmux -S "$SOCKET" kill-session -t "$SESSION"`.
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ describe("bash process registry", () => {
|
|||||||
id: "sess",
|
id: "sess",
|
||||||
command: "echo test",
|
command: "echo test",
|
||||||
child: { pid: 123 } as ChildProcessWithoutNullStreams,
|
child: { pid: 123 } as ChildProcessWithoutNullStreams,
|
||||||
|
stdinMode: "pipe",
|
||||||
startedAt: Date.now(),
|
startedAt: Date.now(),
|
||||||
cwd: "/tmp",
|
cwd: "/tmp",
|
||||||
maxOutputChars: 10,
|
maxOutputChars: 10,
|
||||||
@@ -48,6 +49,7 @@ describe("bash process registry", () => {
|
|||||||
id: "sess",
|
id: "sess",
|
||||||
command: "echo test",
|
command: "echo test",
|
||||||
child: { pid: 123 } as ChildProcessWithoutNullStreams,
|
child: { pid: 123 } as ChildProcessWithoutNullStreams,
|
||||||
|
stdinMode: "pipe",
|
||||||
startedAt: Date.now(),
|
startedAt: Date.now(),
|
||||||
cwd: "/tmp",
|
cwd: "/tmp",
|
||||||
maxOutputChars: 100,
|
maxOutputChars: 100,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
||||||
|
import type { IPty } from "node-pty";
|
||||||
|
|
||||||
const DEFAULT_JOB_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
const DEFAULT_JOB_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
||||||
const MIN_JOB_TTL_MS = 60 * 1000; // 1 minute
|
const MIN_JOB_TTL_MS = 60 * 1000; // 1 minute
|
||||||
@@ -15,11 +16,15 @@ let jobTtlMs = clampTtl(
|
|||||||
|
|
||||||
export type ProcessStatus = "running" | "completed" | "failed" | "killed";
|
export type ProcessStatus = "running" | "completed" | "failed" | "killed";
|
||||||
|
|
||||||
|
export type ProcessStdinMode = "pipe" | "pty";
|
||||||
|
|
||||||
export interface ProcessSession {
|
export interface ProcessSession {
|
||||||
id: string;
|
id: string;
|
||||||
command: string;
|
command: string;
|
||||||
child?: ChildProcessWithoutNullStreams;
|
child?: ChildProcessWithoutNullStreams;
|
||||||
|
pty?: IPty;
|
||||||
pid?: number;
|
pid?: number;
|
||||||
|
stdinMode: ProcessStdinMode;
|
||||||
startedAt: number;
|
startedAt: number;
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
maxOutputChars: number;
|
maxOutputChars: number;
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
describe("bash tool pty mode", () => {
|
||||||
|
it("falls back to pipe with warning when node-pty fails to load", async () => {
|
||||||
|
vi.resetModules();
|
||||||
|
vi.doMock("node-pty", () => {
|
||||||
|
throw new Error("boom");
|
||||||
|
});
|
||||||
|
|
||||||
|
const { createBashTool } = await import("./bash-tools.js");
|
||||||
|
const tool = createBashTool({ backgroundMs: 10, timeoutSec: 1 });
|
||||||
|
const result = await tool.execute("call", {
|
||||||
|
command: "echo test",
|
||||||
|
stdinMode: "pty",
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = result.content.find((c) => c.type === "text")?.text ?? "";
|
||||||
|
expect(text).toContain("Warning: node-pty failed to load");
|
||||||
|
expect(text).toContain("falling back to pipe mode.");
|
||||||
|
|
||||||
|
vi.doUnmock("node-pty");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses node-pty when available", async () => {
|
||||||
|
vi.resetModules();
|
||||||
|
const spawn = vi.fn(() => {
|
||||||
|
let onData: ((data: string) => void) | undefined;
|
||||||
|
let onExit:
|
||||||
|
| ((event: { exitCode: number | null; signal?: number | null }) => void)
|
||||||
|
| undefined;
|
||||||
|
const pty = {
|
||||||
|
pid: 4321,
|
||||||
|
onData: (cb: (data: string) => void) => {
|
||||||
|
onData = cb;
|
||||||
|
},
|
||||||
|
onExit: (
|
||||||
|
cb: (event: {
|
||||||
|
exitCode: number | null;
|
||||||
|
signal?: number | null;
|
||||||
|
}) => void,
|
||||||
|
) => {
|
||||||
|
onExit = cb;
|
||||||
|
},
|
||||||
|
write: vi.fn(),
|
||||||
|
kill: vi.fn(),
|
||||||
|
};
|
||||||
|
setTimeout(() => {
|
||||||
|
onData?.("hello\n");
|
||||||
|
onExit?.({ exitCode: 0, signal: null });
|
||||||
|
}, 10);
|
||||||
|
return pty;
|
||||||
|
});
|
||||||
|
vi.doMock("node-pty", () => ({ spawn }));
|
||||||
|
|
||||||
|
const { createBashTool } = await import("./bash-tools.js");
|
||||||
|
const tool = createBashTool({ backgroundMs: 10, timeoutSec: 1 });
|
||||||
|
const result = await tool.execute("call", {
|
||||||
|
command: "ignored",
|
||||||
|
stdinMode: "pty",
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = result.content.find((c) => c.type === "text")?.text ?? "";
|
||||||
|
expect(text).toContain("hello");
|
||||||
|
expect(text).not.toContain("Warning:");
|
||||||
|
|
||||||
|
vi.doUnmock("node-pty");
|
||||||
|
});
|
||||||
|
});
|
||||||
+229
-52
@@ -2,8 +2,10 @@ import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
|
|||||||
import { randomUUID } from "node:crypto";
|
import { randomUUID } from "node:crypto";
|
||||||
import { existsSync, statSync } from "node:fs";
|
import { existsSync, statSync } from "node:fs";
|
||||||
import { homedir } from "node:os";
|
import { homedir } from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
|
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { Type } from "@sinclair/typebox";
|
||||||
|
import type { IPty } from "node-pty";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addSession,
|
addSession,
|
||||||
@@ -16,6 +18,7 @@ import {
|
|||||||
listRunningSessions,
|
listRunningSessions,
|
||||||
markBackgrounded,
|
markBackgrounded,
|
||||||
markExited,
|
markExited,
|
||||||
|
type ProcessStdinMode,
|
||||||
setJobTtlMs,
|
setJobTtlMs,
|
||||||
} from "./bash-process-registry.js";
|
} from "./bash-process-registry.js";
|
||||||
import {
|
import {
|
||||||
@@ -31,6 +34,23 @@ const DEFAULT_MAX_OUTPUT = clampNumber(
|
|||||||
1_000,
|
1_000,
|
||||||
150_000,
|
150_000,
|
||||||
);
|
);
|
||||||
|
const DEFAULT_SHELL_PATH = "/bin/sh";
|
||||||
|
const DEFAULT_PATH =
|
||||||
|
"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
|
||||||
|
const DEFAULT_PTY_NAME = "xterm-256color";
|
||||||
|
|
||||||
|
type PtyModule = typeof import("node-pty");
|
||||||
|
type PtyLoadResult = { module: PtyModule | null; error?: unknown };
|
||||||
|
let ptyModulePromise: Promise<PtyLoadResult> | null = null;
|
||||||
|
|
||||||
|
async function loadPtyModule(): Promise<PtyLoadResult> {
|
||||||
|
if (!ptyModulePromise) {
|
||||||
|
ptyModulePromise = import("node-pty")
|
||||||
|
.then((mod) => ({ module: mod }))
|
||||||
|
.catch((error) => ({ module: null, error }));
|
||||||
|
}
|
||||||
|
return ptyModulePromise;
|
||||||
|
}
|
||||||
|
|
||||||
const stringEnum = (
|
const stringEnum = (
|
||||||
values: readonly string[],
|
values: readonly string[],
|
||||||
@@ -61,7 +81,7 @@ const bashSchema = Type.Object({
|
|||||||
env: Type.Optional(Type.Record(Type.String(), Type.String())),
|
env: Type.Optional(Type.Record(Type.String(), Type.String())),
|
||||||
yieldMs: Type.Optional(
|
yieldMs: Type.Optional(
|
||||||
Type.Number({
|
Type.Number({
|
||||||
description: "Milliseconds to wait before backgrounding (default 10000)",
|
description: "Milliseconds to wait before backgrounding (default 20000)",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
background: Type.Optional(
|
background: Type.Optional(
|
||||||
@@ -72,6 +92,11 @@ const bashSchema = Type.Object({
|
|||||||
description: "Timeout in seconds (optional, kills process on expiry)",
|
description: "Timeout in seconds (optional, kills process on expiry)",
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
stdinMode: Type.Optional(
|
||||||
|
stringEnum(["pipe", "pty"] as const, {
|
||||||
|
description: "stdin mode (pipe or pty when node-pty is available)",
|
||||||
|
}),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type BashToolDetails =
|
export type BashToolDetails =
|
||||||
@@ -95,7 +120,7 @@ export function createBashTool(
|
|||||||
): AgentTool<any, BashToolDetails> {
|
): AgentTool<any, BashToolDetails> {
|
||||||
const defaultBackgroundMs = clampNumber(
|
const defaultBackgroundMs = clampNumber(
|
||||||
defaults?.backgroundMs ?? readEnvInt("PI_BASH_YIELD_MS"),
|
defaults?.backgroundMs ?? readEnvInt("PI_BASH_YIELD_MS"),
|
||||||
10_000,
|
20_000,
|
||||||
10,
|
10,
|
||||||
120_000,
|
120_000,
|
||||||
);
|
);
|
||||||
@@ -108,7 +133,7 @@ export function createBashTool(
|
|||||||
name: "bash",
|
name: "bash",
|
||||||
label: "bash",
|
label: "bash",
|
||||||
description:
|
description:
|
||||||
"Execute bash with background continuation. Use yieldMs/background to continue later via process tool. For real TTY mode, use the tmux skill.",
|
"Execute bash with background continuation. Use yieldMs/background to continue later via process tool.",
|
||||||
parameters: bashSchema,
|
parameters: bashSchema,
|
||||||
execute: async (_toolCallId, args, signal, onUpdate) => {
|
execute: async (_toolCallId, args, signal, onUpdate) => {
|
||||||
const params = args as {
|
const params = args as {
|
||||||
@@ -118,6 +143,7 @@ export function createBashTool(
|
|||||||
yieldMs?: number;
|
yieldMs?: number;
|
||||||
background?: boolean;
|
background?: boolean;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
|
stdinMode?: "pipe" | "pty";
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!params.command) {
|
if (!params.command) {
|
||||||
@@ -143,18 +169,84 @@ export function createBashTool(
|
|||||||
|
|
||||||
const { shell, args: shellArgs } = getShellConfig();
|
const { shell, args: shellArgs } = getShellConfig();
|
||||||
const env = params.env ? { ...process.env, ...params.env } : process.env;
|
const env = params.env ? { ...process.env, ...params.env } : process.env;
|
||||||
const child = spawn(shell, [...shellArgs, params.command], {
|
const requestedStdinMode = params.stdinMode === "pty" ? "pty" : "pipe";
|
||||||
cwd: workdir,
|
let stdinMode: ProcessStdinMode = requestedStdinMode;
|
||||||
env,
|
let warning: string | null = null;
|
||||||
detached: true,
|
let child: ChildProcessWithoutNullStreams | undefined;
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
let pty: IPty | undefined;
|
||||||
});
|
|
||||||
|
if (stdinMode === "pty") {
|
||||||
|
const { module: ptyModule, error: ptyError } = await loadPtyModule();
|
||||||
|
if (!ptyModule) {
|
||||||
|
warning =
|
||||||
|
`Warning: node-pty failed to load${formatPtyError(ptyError)}; ` +
|
||||||
|
"falling back to pipe mode.";
|
||||||
|
stdinMode = "pipe";
|
||||||
|
} else {
|
||||||
|
const ptyEnv = ensurePath({
|
||||||
|
...env,
|
||||||
|
TERM: env.TERM ?? DEFAULT_PTY_NAME,
|
||||||
|
} as Record<string, string>);
|
||||||
|
const ptyShell = resolveShellPath(shell, ptyEnv);
|
||||||
|
try {
|
||||||
|
pty = ptyModule.spawn(ptyShell, [...shellArgs, params.command], {
|
||||||
|
cwd: workdir,
|
||||||
|
env: ptyEnv,
|
||||||
|
name: ptyEnv.TERM || DEFAULT_PTY_NAME,
|
||||||
|
cols: 120,
|
||||||
|
rows: 30,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
ptyShell !== DEFAULT_SHELL_PATH &&
|
||||||
|
existsSync(DEFAULT_SHELL_PATH)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
pty = ptyModule.spawn(
|
||||||
|
DEFAULT_SHELL_PATH,
|
||||||
|
[...shellArgs, params.command],
|
||||||
|
{
|
||||||
|
cwd: workdir,
|
||||||
|
env: ptyEnv,
|
||||||
|
name: ptyEnv.TERM || DEFAULT_PTY_NAME,
|
||||||
|
cols: 120,
|
||||||
|
rows: 30,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (fallbackError) {
|
||||||
|
warning =
|
||||||
|
`Warning: node-pty failed to start${formatPtyError(fallbackError)}; ` +
|
||||||
|
"falling back to pipe mode.";
|
||||||
|
stdinMode = "pipe";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warning =
|
||||||
|
`Warning: node-pty failed to start${formatPtyError(error)}; ` +
|
||||||
|
"falling back to pipe mode.";
|
||||||
|
stdinMode = "pipe";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdinMode === "pipe") {
|
||||||
|
child = spawn(shell, [...shellArgs, params.command], {
|
||||||
|
cwd: workdir,
|
||||||
|
env,
|
||||||
|
detached: true,
|
||||||
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warning) warnings.push(warning);
|
||||||
|
|
||||||
const session = {
|
const session = {
|
||||||
id: sessionId,
|
id: sessionId,
|
||||||
command: params.command,
|
command: params.command,
|
||||||
child,
|
child,
|
||||||
pid: child?.pid,
|
pty,
|
||||||
|
pid: child?.pid ?? pty?.pid,
|
||||||
|
stdinMode,
|
||||||
startedAt,
|
startedAt,
|
||||||
cwd: workdir,
|
cwd: workdir,
|
||||||
maxOutputChars: maxOutput,
|
maxOutputChars: maxOutput,
|
||||||
@@ -217,21 +309,33 @@ export function createBashTool(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
child.stdout.on("data", (data) => {
|
if (child) {
|
||||||
const str = sanitizeBinaryOutput(data.toString());
|
child.stdout.on("data", (data) => {
|
||||||
for (const chunk of chunkString(str)) {
|
const str = sanitizeBinaryOutput(data.toString());
|
||||||
appendOutput(session, "stdout", chunk);
|
for (const chunk of chunkString(str)) {
|
||||||
emitUpdate();
|
appendOutput(session, "stdout", chunk);
|
||||||
}
|
emitUpdate();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
child.stderr.on("data", (data) => {
|
child.stderr.on("data", (data) => {
|
||||||
const str = sanitizeBinaryOutput(data.toString());
|
const str = sanitizeBinaryOutput(data.toString());
|
||||||
for (const chunk of chunkString(str)) {
|
for (const chunk of chunkString(str)) {
|
||||||
appendOutput(session, "stderr", chunk);
|
appendOutput(session, "stderr", chunk);
|
||||||
emitUpdate();
|
emitUpdate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pty) {
|
||||||
|
pty.onData((data) => {
|
||||||
|
const str = sanitizeBinaryOutput(data);
|
||||||
|
for (const chunk of chunkString(str)) {
|
||||||
|
appendOutput(session, "stdout", chunk);
|
||||||
|
emitUpdate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise<AgentToolResult<BashToolDetails>>(
|
return new Promise<AgentToolResult<BashToolDetails>>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
@@ -330,16 +434,24 @@ export function createBashTool(
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
child.once("exit", (code, exitSignal) => {
|
if (child) {
|
||||||
handleExit(code, exitSignal);
|
child.once("exit", (code, exitSignal) => {
|
||||||
});
|
handleExit(code, exitSignal);
|
||||||
|
});
|
||||||
|
|
||||||
child.once("error", (err) => {
|
child.once("error", (err) => {
|
||||||
if (yieldTimer) clearTimeout(yieldTimer);
|
if (yieldTimer) clearTimeout(yieldTimer);
|
||||||
if (timeoutTimer) clearTimeout(timeoutTimer);
|
if (timeoutTimer) clearTimeout(timeoutTimer);
|
||||||
markExited(session, null, null, "failed");
|
markExited(session, null, null, "failed");
|
||||||
settle(() => reject(err));
|
settle(() => reject(err));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pty) {
|
||||||
|
pty.onExit(({ exitCode, signal }) => {
|
||||||
|
handleExit(exitCode ?? null, signal ?? null);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -635,25 +747,43 @@ export function createProcessTool(
|
|||||||
details: { status: "failed" },
|
details: { status: "failed" },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!session.child?.stdin || session.child.stdin.destroyed) {
|
if (session.stdinMode === "pty") {
|
||||||
return {
|
if (!session.pty || session.exited) {
|
||||||
content: [
|
return {
|
||||||
{
|
content: [
|
||||||
type: "text",
|
{
|
||||||
text: `Session ${params.sessionId} stdin is not writable.`,
|
type: "text",
|
||||||
},
|
text: `Session ${params.sessionId} stdin is not writable.`,
|
||||||
],
|
},
|
||||||
details: { status: "failed" },
|
],
|
||||||
};
|
details: { status: "failed" },
|
||||||
}
|
};
|
||||||
await new Promise<void>((resolve, reject) => {
|
}
|
||||||
session.child?.stdin.write(params.data ?? "", (err) => {
|
session.pty.write(params.data ?? "");
|
||||||
if (err) reject(err);
|
if (params.eof) {
|
||||||
else resolve();
|
session.pty.write("\x04");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!session.child?.stdin || session.child.stdin.destroyed) {
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: `Session ${params.sessionId} stdin is not writable.`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
details: { status: "failed" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
session.child?.stdin.write(params.data ?? "", (err) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
if (params.eof) {
|
||||||
if (params.eof) {
|
session.child.stdin.end();
|
||||||
session.child.stdin.end();
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
@@ -778,12 +908,21 @@ export const processTool = createProcessTool();
|
|||||||
|
|
||||||
function killSession(session: {
|
function killSession(session: {
|
||||||
pid?: number;
|
pid?: number;
|
||||||
|
stdinMode: ProcessStdinMode;
|
||||||
|
pty?: IPty;
|
||||||
child?: ChildProcessWithoutNullStreams;
|
child?: ChildProcessWithoutNullStreams;
|
||||||
}) {
|
}) {
|
||||||
const pid = session.pid ?? session.child?.pid;
|
const pid = session.pid ?? session.child?.pid ?? session.pty?.pid;
|
||||||
if (pid) {
|
if (pid) {
|
||||||
killProcessTree(pid);
|
killProcessTree(pid);
|
||||||
}
|
}
|
||||||
|
if (session.stdinMode === "pty") {
|
||||||
|
try {
|
||||||
|
session.pty?.kill();
|
||||||
|
} catch {
|
||||||
|
// ignore kill failures
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveWorkdir(workdir: string, warnings: string[]) {
|
function resolveWorkdir(workdir: string, warnings: string[]) {
|
||||||
@@ -810,6 +949,44 @@ function safeCwd() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensurePath(env: Record<string, string>) {
|
||||||
|
if (!env.PATH?.trim()) {
|
||||||
|
env.PATH = DEFAULT_PATH;
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveShellPath(shell: string, env: Record<string, string>) {
|
||||||
|
if (process.platform === "win32") return shell;
|
||||||
|
if (shell.includes("/") && existsSync(shell)) {
|
||||||
|
return shell;
|
||||||
|
}
|
||||||
|
const searchPath = env.PATH ?? "";
|
||||||
|
for (const segment of searchPath.split(path.delimiter)) {
|
||||||
|
if (!segment) continue;
|
||||||
|
const candidate = path.join(segment, shell);
|
||||||
|
if (existsSync(candidate)) return candidate;
|
||||||
|
}
|
||||||
|
if (existsSync(DEFAULT_SHELL_PATH)) {
|
||||||
|
return DEFAULT_SHELL_PATH;
|
||||||
|
}
|
||||||
|
return shell;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPtyError(error: unknown) {
|
||||||
|
if (!error) return "";
|
||||||
|
if (typeof error === "string") return ` (${error})`;
|
||||||
|
if (error instanceof Error) {
|
||||||
|
const firstLine = error.message.split(/\r?\n/)[0]?.trim();
|
||||||
|
return firstLine ? ` (${firstLine})` : "";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return ` (${JSON.stringify(error)})`;
|
||||||
|
} catch {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clampNumber(
|
function clampNumber(
|
||||||
value: number | undefined,
|
value: number | undefined,
|
||||||
defaultValue: number,
|
defaultValue: number,
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
} from "./pi-embedded-subscribe.js";
|
} from "./pi-embedded-subscribe.js";
|
||||||
import { extractAssistantText } from "./pi-embedded-utils.js";
|
import { extractAssistantText } from "./pi-embedded-utils.js";
|
||||||
import { createClawdisCodingTools } from "./pi-tools.js";
|
import { createClawdisCodingTools } from "./pi-tools.js";
|
||||||
|
import { resolveSandboxContext } from "./sandbox.js";
|
||||||
import {
|
import {
|
||||||
applySkillEnvOverrides,
|
applySkillEnvOverrides,
|
||||||
applySkillEnvOverridesFromSnapshot,
|
applySkillEnvOverridesFromSnapshot,
|
||||||
@@ -362,7 +363,13 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
return enqueueCommandInLane(sessionLane, () =>
|
return enqueueCommandInLane(sessionLane, () =>
|
||||||
enqueueGlobal(async () => {
|
enqueueGlobal(async () => {
|
||||||
const started = Date.now();
|
const started = Date.now();
|
||||||
const resolvedWorkspace = resolveUserPath(params.workspaceDir);
|
const sandbox = await resolveSandboxContext({
|
||||||
|
config: params.config,
|
||||||
|
sessionKey: params.sessionKey,
|
||||||
|
workspaceDir: params.workspaceDir,
|
||||||
|
});
|
||||||
|
const workspaceDir = sandbox?.workspaceDir ?? params.workspaceDir;
|
||||||
|
const resolvedWorkspace = resolveUserPath(workspaceDir);
|
||||||
const prevCwd = process.cwd();
|
const prevCwd = process.cwd();
|
||||||
|
|
||||||
const provider =
|
const provider =
|
||||||
@@ -425,6 +432,7 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
const tools = createClawdisCodingTools({
|
const tools = createClawdisCodingTools({
|
||||||
bash: params.config?.agent?.bash,
|
bash: params.config?.agent?.bash,
|
||||||
surface: params.surface,
|
surface: params.surface,
|
||||||
|
sandbox,
|
||||||
});
|
});
|
||||||
const machineName = await getMachineDisplayName();
|
const machineName = await getMachineDisplayName();
|
||||||
const runtimeInfo = {
|
const runtimeInfo = {
|
||||||
@@ -486,7 +494,7 @@ export async function runEmbeddedPiAgent(params: {
|
|||||||
};
|
};
|
||||||
const queueHandle: EmbeddedPiQueueHandle = {
|
const queueHandle: EmbeddedPiQueueHandle = {
|
||||||
queueMessage: async (text: string) => {
|
queueMessage: async (text: string) => {
|
||||||
await session.steer(text);
|
await session.queueMessage(text);
|
||||||
},
|
},
|
||||||
isStreaming: () => session.isStreaming,
|
isStreaming: () => session.isStreaming,
|
||||||
abort: abortRun,
|
abort: abortRun,
|
||||||
|
|||||||
@@ -232,41 +232,4 @@ describe("pw-tools-core", () => {
|
|||||||
expect(dismiss).toHaveBeenCalled();
|
expect(dismiss).toHaveBeenCalled();
|
||||||
expect(accept).not.toHaveBeenCalled();
|
expect(accept).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("evaluates expressions with trailing semicolons", async () => {
|
|
||||||
const evaluate = vi.fn(
|
|
||||||
async (fn: (body: string) => unknown, body: string) => fn(body),
|
|
||||||
);
|
|
||||||
currentPage = { evaluate };
|
|
||||||
|
|
||||||
const mod = await importModule();
|
|
||||||
const result = await mod.evaluateViaPlaywright({
|
|
||||||
cdpUrl: "http://127.0.0.1:18792",
|
|
||||||
fn: "() => 42;",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBe(42);
|
|
||||||
expect(evaluate).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("evaluates element expressions with trailing semicolons", async () => {
|
|
||||||
const evaluate = vi.fn(
|
|
||||||
async (
|
|
||||||
fn: (el: { tagName: string }, body: string) => unknown,
|
|
||||||
body: string,
|
|
||||||
) => fn({ tagName: "DIV" }, body),
|
|
||||||
);
|
|
||||||
currentRefLocator = { evaluate };
|
|
||||||
currentPage = {};
|
|
||||||
|
|
||||||
const mod = await importModule();
|
|
||||||
const result = await mod.evaluateViaPlaywright({
|
|
||||||
cdpUrl: "http://127.0.0.1:18792",
|
|
||||||
fn: "(el) => el.tagName;",
|
|
||||||
ref: "1",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBe("DIV");
|
|
||||||
expect(sessionMocks.refLocator).toHaveBeenCalledWith(currentPage, "1");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
@@ -207,44 +207,53 @@ export async function evaluateViaPlaywright(opts: {
|
|||||||
}): Promise<unknown> {
|
}): Promise<unknown> {
|
||||||
const fnText = String(opts.fn ?? "").trim();
|
const fnText = String(opts.fn ?? "").trim();
|
||||||
if (!fnText) throw new Error("function is required");
|
if (!fnText) throw new Error("function is required");
|
||||||
const fnBody = fnText.replace(/[;\s]+$/g, "");
|
|
||||||
if (!fnBody) throw new Error("function is required");
|
|
||||||
const page = await getPageForTargetId(opts);
|
const page = await getPageForTargetId(opts);
|
||||||
ensurePageState(page);
|
ensurePageState(page);
|
||||||
if (opts.ref) {
|
if (opts.ref) {
|
||||||
const locator = refLocator(page, opts.ref);
|
const locator = refLocator(page, opts.ref);
|
||||||
// Use Function constructor at runtime to avoid esbuild adding __name helper
|
return await locator.evaluate((el, fnBody) => {
|
||||||
// which doesn't exist in the browser context
|
const compileRunner = (body: string) => {
|
||||||
const elementEvaluator = new Function(
|
const inner = `"use strict"; const candidate = ${body}; return typeof candidate === "function" ? candidate(element) : candidate;`;
|
||||||
"el",
|
// This intentionally evaluates user-supplied code in the browser context.
|
||||||
"fnBody",
|
// oxlint-disable-next-line typescript-eslint/no-implied-eval
|
||||||
`
|
return new Function("element", inner) as (element: Element) => unknown;
|
||||||
"use strict";
|
};
|
||||||
|
let compiled: unknown;
|
||||||
try {
|
try {
|
||||||
var candidate = eval("(" + fnBody + ")");
|
compiled = compileRunner(fnBody);
|
||||||
return typeof candidate === "function" ? candidate(el) : candidate;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error("Invalid evaluate function: " + (err && err.message ? err.message : String(err)));
|
const message =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: typeof err === "string"
|
||||||
|
? err
|
||||||
|
: "invalid expression";
|
||||||
|
throw new Error(`Invalid evaluate function: ${message}`);
|
||||||
}
|
}
|
||||||
`,
|
return (compiled as (element: Element) => unknown)(el as Element);
|
||||||
) as (el: Element, fnBody: string) => unknown;
|
}, fnText);
|
||||||
return await locator.evaluate(elementEvaluator, fnBody);
|
|
||||||
}
|
}
|
||||||
// Use Function constructor at runtime to avoid esbuild adding __name helper
|
return await page.evaluate((fnBody) => {
|
||||||
// which doesn't exist in the browser context
|
const compileRunner = (body: string) => {
|
||||||
const browserEvaluator = new Function(
|
const inner = `"use strict"; const candidate = ${body}; return typeof candidate === "function" ? candidate() : candidate;`;
|
||||||
"fnBody",
|
// This intentionally evaluates user-supplied code in the browser context.
|
||||||
`
|
// oxlint-disable-next-line typescript-eslint/no-implied-eval
|
||||||
"use strict";
|
return new Function(inner) as () => unknown;
|
||||||
|
};
|
||||||
|
let compiled: unknown;
|
||||||
try {
|
try {
|
||||||
var candidate = eval("(" + fnBody + ")");
|
compiled = compileRunner(fnBody);
|
||||||
return typeof candidate === "function" ? candidate() : candidate;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error("Invalid evaluate function: " + (err && err.message ? err.message : String(err)));
|
const message =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: typeof err === "string"
|
||||||
|
? err
|
||||||
|
: "invalid expression";
|
||||||
|
throw new Error(`Invalid evaluate function: ${message}`);
|
||||||
}
|
}
|
||||||
`,
|
return (compiled as () => unknown)();
|
||||||
) as (fnBody: string) => unknown;
|
}, fnText);
|
||||||
return await page.evaluate(browserEvaluator, fnBody);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function armFileUploadViaPlaywright(opts: {
|
export async function armFileUploadViaPlaywright(opts: {
|
||||||
|
|||||||
@@ -447,15 +447,6 @@ export type GatewayRemoteConfig = {
|
|||||||
password?: string;
|
password?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GatewayReloadMode = "off" | "restart" | "hot" | "hybrid";
|
|
||||||
|
|
||||||
export type GatewayReloadConfig = {
|
|
||||||
/** Reload strategy for config changes (default: hybrid). */
|
|
||||||
mode?: GatewayReloadMode;
|
|
||||||
/** Debounce window for config reloads (ms). Default: 300. */
|
|
||||||
debounceMs?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type GatewayConfig = {
|
export type GatewayConfig = {
|
||||||
/** Single multiplexed port for Gateway WS + HTTP (default: 18789). */
|
/** Single multiplexed port for Gateway WS + HTTP (default: 18789). */
|
||||||
port?: number;
|
port?: number;
|
||||||
@@ -473,7 +464,6 @@ export type GatewayConfig = {
|
|||||||
auth?: GatewayAuthConfig;
|
auth?: GatewayAuthConfig;
|
||||||
tailscale?: GatewayTailscaleConfig;
|
tailscale?: GatewayTailscaleConfig;
|
||||||
remote?: GatewayRemoteConfig;
|
remote?: GatewayRemoteConfig;
|
||||||
reload?: GatewayReloadConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SkillConfig = {
|
export type SkillConfig = {
|
||||||
@@ -1318,19 +1308,6 @@ export const ClawdisSchema = z.object({
|
|||||||
password: z.string().optional(),
|
password: z.string().optional(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
reload: z
|
|
||||||
.object({
|
|
||||||
mode: z
|
|
||||||
.union([
|
|
||||||
z.literal("off"),
|
|
||||||
z.literal("restart"),
|
|
||||||
z.literal("hot"),
|
|
||||||
z.literal("hybrid"),
|
|
||||||
])
|
|
||||||
.optional(),
|
|
||||||
debounceMs: z.number().int().min(0).optional(),
|
|
||||||
})
|
|
||||||
.optional(),
|
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
skills: z
|
skills: z
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ const FIELD_LABELS: Record<string, string> = {
|
|||||||
"gateway.auth.token": "Gateway Token",
|
"gateway.auth.token": "Gateway Token",
|
||||||
"gateway.auth.password": "Gateway Password",
|
"gateway.auth.password": "Gateway Password",
|
||||||
"gateway.controlUi.basePath": "Control UI Base Path",
|
"gateway.controlUi.basePath": "Control UI Base Path",
|
||||||
"gateway.reload.mode": "Config Reload Mode",
|
|
||||||
"gateway.reload.debounceMs": "Config Reload Debounce (ms)",
|
|
||||||
"agent.workspace": "Workspace",
|
"agent.workspace": "Workspace",
|
||||||
"agent.model": "Default Model",
|
"agent.model": "Default Model",
|
||||||
"ui.seamColor": "Accent Color",
|
"ui.seamColor": "Accent Color",
|
||||||
@@ -102,10 +100,6 @@ const FIELD_HELP: Record<string, string> = {
|
|||||||
"gateway.auth.password": "Required for Tailscale funnel.",
|
"gateway.auth.password": "Required for Tailscale funnel.",
|
||||||
"gateway.controlUi.basePath":
|
"gateway.controlUi.basePath":
|
||||||
"Optional URL prefix where the Control UI is served (e.g. /clawdis).",
|
"Optional URL prefix where the Control UI is served (e.g. /clawdis).",
|
||||||
"gateway.reload.mode":
|
|
||||||
'Hot reload strategy for config changes ("hybrid" recommended).',
|
|
||||||
"gateway.reload.debounceMs":
|
|
||||||
"Debounce window (ms) before applying config changes.",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const FIELD_PLACEHOLDERS: Record<string, string> = {
|
const FIELD_PLACEHOLDERS: Record<string, string> = {
|
||||||
|
|||||||
+3
-159
@@ -10,8 +10,6 @@ import {
|
|||||||
type Guild,
|
type Guild,
|
||||||
type Message,
|
type Message,
|
||||||
type MessageReaction,
|
type MessageReaction,
|
||||||
type MessageSnapshot,
|
|
||||||
MessageType,
|
|
||||||
type PartialMessage,
|
type PartialMessage,
|
||||||
type PartialMessageReaction,
|
type PartialMessageReaction,
|
||||||
Partials,
|
Partials,
|
||||||
@@ -209,26 +207,13 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
const botId = client.user?.id;
|
const botId = client.user?.id;
|
||||||
const wasMentioned =
|
const wasMentioned =
|
||||||
!isDirectMessage && Boolean(botId && message.mentions.has(botId));
|
!isDirectMessage && Boolean(botId && message.mentions.has(botId));
|
||||||
const forwardedSnapshot = resolveForwardedSnapshot(message);
|
const baseText = resolveDiscordMessageText(message);
|
||||||
const forwardedText = forwardedSnapshot
|
|
||||||
? resolveDiscordSnapshotText(forwardedSnapshot.snapshot)
|
|
||||||
: "";
|
|
||||||
const baseText = resolveDiscordMessageText(message, forwardedText);
|
|
||||||
if (shouldLogVerbose()) {
|
if (shouldLogVerbose()) {
|
||||||
logVerbose(
|
logVerbose(
|
||||||
`discord: inbound id=${message.id} guild=${message.guild?.id ?? "dm"} channel=${message.channelId} mention=${wasMentioned ? "yes" : "no"} type=${isDirectMessage ? "dm" : isGroupDm ? "group-dm" : "guild"} content=${baseText ? "yes" : "no"}`,
|
`discord: inbound id=${message.id} guild=${message.guild?.id ?? "dm"} channel=${message.channelId} mention=${wasMentioned ? "yes" : "no"} type=${isDirectMessage ? "dm" : isGroupDm ? "group-dm" : "guild"} content=${baseText ? "yes" : "no"}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
isGuildMessage &&
|
|
||||||
(message.type === MessageType.ChatInputCommand ||
|
|
||||||
message.type === MessageType.ContextMenuCommand)
|
|
||||||
) {
|
|
||||||
logVerbose("discord: drop channel command message");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildInfo = isGuildMessage
|
const guildInfo = isGuildMessage
|
||||||
? resolveDiscordGuildEntry({
|
? resolveDiscordGuildEntry({
|
||||||
guild: message.guild,
|
guild: message.guild,
|
||||||
@@ -354,20 +339,12 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemText = resolveDiscordSystemEvent(message);
|
|
||||||
if (systemText) {
|
|
||||||
enqueueSystemEvent(systemText, {
|
|
||||||
contextKey: `discord:system:${message.channelId}:${message.id}`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const media = await resolveMedia(message, mediaMaxBytes);
|
const media = await resolveMedia(message, mediaMaxBytes);
|
||||||
const text =
|
const text =
|
||||||
message.content?.trim() ??
|
message.content?.trim() ??
|
||||||
media?.placeholder ??
|
media?.placeholder ??
|
||||||
message.embeds[0]?.description ??
|
message.embeds[0]?.description ??
|
||||||
(forwardedSnapshot ? "<forwarded message>" : "");
|
"";
|
||||||
if (!text) {
|
if (!text) {
|
||||||
logVerbose(`discord: drop message ${message.id} (empty content)`);
|
logVerbose(`discord: drop message ${message.id} (empty content)`);
|
||||||
return;
|
return;
|
||||||
@@ -414,42 +391,6 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
|||||||
if (replyContext) {
|
if (replyContext) {
|
||||||
combinedBody = `[Replied message - for context]\n${replyContext}\n\n${combinedBody}`;
|
combinedBody = `[Replied message - for context]\n${replyContext}\n\n${combinedBody}`;
|
||||||
}
|
}
|
||||||
if (forwardedSnapshot) {
|
|
||||||
const forwarderName = message.author.tag ?? message.author.username;
|
|
||||||
const forwarder = forwarderName
|
|
||||||
? `${forwarderName} id:${message.author.id}`
|
|
||||||
: message.author.id;
|
|
||||||
const snapshotText =
|
|
||||||
resolveDiscordSnapshotText(forwardedSnapshot.snapshot) ||
|
|
||||||
"<forwarded message>";
|
|
||||||
const forwardMetaParts = [
|
|
||||||
forwardedSnapshot.messageId
|
|
||||||
? `forwarded message id: ${forwardedSnapshot.messageId}`
|
|
||||||
: null,
|
|
||||||
forwardedSnapshot.channelId
|
|
||||||
? `channel: ${forwardedSnapshot.channelId}`
|
|
||||||
: null,
|
|
||||||
forwardedSnapshot.guildId
|
|
||||||
? `guild: ${forwardedSnapshot.guildId}`
|
|
||||||
: null,
|
|
||||||
typeof forwardedSnapshot.snapshot.type === "number"
|
|
||||||
? `snapshot type: ${forwardedSnapshot.snapshot.type}`
|
|
||||||
: null,
|
|
||||||
].filter((entry): entry is string => Boolean(entry));
|
|
||||||
const forwardedBody = forwardMetaParts.length
|
|
||||||
? `${snapshotText}\n[${forwardMetaParts.join(" ")}]`
|
|
||||||
: snapshotText;
|
|
||||||
const forwardedEnvelope = formatAgentEnvelope({
|
|
||||||
surface: "Discord",
|
|
||||||
from: `Forwarded by ${forwarder}`,
|
|
||||||
timestamp:
|
|
||||||
forwardedSnapshot.snapshot.createdTimestamp ??
|
|
||||||
message.createdTimestamp ??
|
|
||||||
undefined,
|
|
||||||
body: forwardedBody,
|
|
||||||
});
|
|
||||||
combinedBody = `[Forwarded message]\n${forwardedEnvelope}\n\n${combinedBody}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ctxPayload = {
|
const ctxPayload = {
|
||||||
Body: combinedBody,
|
Body: combinedBody,
|
||||||
@@ -889,24 +830,16 @@ function inferPlaceholder(attachment: Attachment): string {
|
|||||||
return "<media:document>";
|
return "<media:document>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveDiscordMessageText(
|
function resolveDiscordMessageText(message: Message): string {
|
||||||
message: Message,
|
|
||||||
fallbackText?: string,
|
|
||||||
): string {
|
|
||||||
const attachment = message.attachments.first();
|
const attachment = message.attachments.first();
|
||||||
return (
|
return (
|
||||||
message.content?.trim() ||
|
message.content?.trim() ||
|
||||||
(attachment ? inferPlaceholder(attachment) : "") ||
|
(attachment ? inferPlaceholder(attachment) : "") ||
|
||||||
message.embeds[0]?.description ||
|
message.embeds[0]?.description ||
|
||||||
fallbackText?.trim() ||
|
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveDiscordSnapshotText(snapshot: MessageSnapshot): string {
|
|
||||||
return snapshot.content?.trim() || snapshot.embeds[0]?.description || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveReplyContext(message: Message): Promise<string | null> {
|
async function resolveReplyContext(message: Message): Promise<string | null> {
|
||||||
if (!message.reference?.messageId) return null;
|
if (!message.reference?.messageId) return null;
|
||||||
try {
|
try {
|
||||||
@@ -945,95 +878,6 @@ function buildGuildLabel(message: Message) {
|
|||||||
return `${message.guild?.name ?? "Guild"} #${channelName} id:${message.channelId}`;
|
return `${message.guild?.name ?? "Guild"} #${channelName} id:${message.channelId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveDiscordSystemEvent(message: Message): string | null {
|
|
||||||
switch (message.type) {
|
|
||||||
case MessageType.ChannelPinnedMessage:
|
|
||||||
return buildDiscordSystemEvent(message, "pinned a message");
|
|
||||||
case MessageType.RecipientAdd:
|
|
||||||
return buildDiscordSystemEvent(message, "added a recipient");
|
|
||||||
case MessageType.RecipientRemove:
|
|
||||||
return buildDiscordSystemEvent(message, "removed a recipient");
|
|
||||||
case MessageType.UserJoin:
|
|
||||||
return buildDiscordSystemEvent(message, "user joined");
|
|
||||||
case MessageType.GuildBoost:
|
|
||||||
return buildDiscordSystemEvent(message, "boosted the server");
|
|
||||||
case MessageType.GuildBoostTier1:
|
|
||||||
return buildDiscordSystemEvent(
|
|
||||||
message,
|
|
||||||
"boosted the server (Tier 1 reached)",
|
|
||||||
);
|
|
||||||
case MessageType.GuildBoostTier2:
|
|
||||||
return buildDiscordSystemEvent(
|
|
||||||
message,
|
|
||||||
"boosted the server (Tier 2 reached)",
|
|
||||||
);
|
|
||||||
case MessageType.GuildBoostTier3:
|
|
||||||
return buildDiscordSystemEvent(
|
|
||||||
message,
|
|
||||||
"boosted the server (Tier 3 reached)",
|
|
||||||
);
|
|
||||||
case MessageType.ThreadCreated:
|
|
||||||
return buildDiscordSystemEvent(message, "created a thread");
|
|
||||||
case MessageType.AutoModerationAction:
|
|
||||||
return buildDiscordSystemEvent(message, "auto moderation action");
|
|
||||||
case MessageType.GuildIncidentAlertModeEnabled:
|
|
||||||
return buildDiscordSystemEvent(message, "raid protection enabled");
|
|
||||||
case MessageType.GuildIncidentAlertModeDisabled:
|
|
||||||
return buildDiscordSystemEvent(message, "raid protection disabled");
|
|
||||||
case MessageType.GuildIncidentReportRaid:
|
|
||||||
return buildDiscordSystemEvent(message, "raid reported");
|
|
||||||
case MessageType.GuildIncidentReportFalseAlarm:
|
|
||||||
return buildDiscordSystemEvent(message, "raid report marked false alarm");
|
|
||||||
case MessageType.StageStart:
|
|
||||||
return buildDiscordSystemEvent(message, "stage started");
|
|
||||||
case MessageType.StageEnd:
|
|
||||||
return buildDiscordSystemEvent(message, "stage ended");
|
|
||||||
case MessageType.StageSpeaker:
|
|
||||||
return buildDiscordSystemEvent(message, "stage speaker updated");
|
|
||||||
case MessageType.StageTopic:
|
|
||||||
return buildDiscordSystemEvent(message, "stage topic updated");
|
|
||||||
case MessageType.PollResult:
|
|
||||||
return buildDiscordSystemEvent(message, "poll results posted");
|
|
||||||
case MessageType.PurchaseNotification:
|
|
||||||
return buildDiscordSystemEvent(message, "purchase notification");
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveForwardedSnapshot(message: Message): {
|
|
||||||
snapshot: MessageSnapshot;
|
|
||||||
messageId?: string;
|
|
||||||
channelId?: string;
|
|
||||||
guildId?: string;
|
|
||||||
} | null {
|
|
||||||
const snapshots = message.messageSnapshots;
|
|
||||||
if (!snapshots || snapshots.size === 0) return null;
|
|
||||||
const snapshot = snapshots.first();
|
|
||||||
if (!snapshot) return null;
|
|
||||||
const reference = message.reference;
|
|
||||||
return {
|
|
||||||
snapshot,
|
|
||||||
messageId: reference?.messageId ?? undefined,
|
|
||||||
channelId: reference?.channelId ?? undefined,
|
|
||||||
guildId: reference?.guildId ?? undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildDiscordSystemEvent(message: Message, action: string) {
|
|
||||||
const channelName =
|
|
||||||
"name" in message.channel ? message.channel.name : message.channelId;
|
|
||||||
const channelType = message.channel.type as ChannelType;
|
|
||||||
const location = message.guild?.name
|
|
||||||
? `${message.guild.name} #${channelName}`
|
|
||||||
: channelType === ChannelType.GroupDM
|
|
||||||
? `Group DM #${channelName}`
|
|
||||||
: "DM";
|
|
||||||
const authorLabel = message.author?.tag ?? message.author?.username;
|
|
||||||
const actor = authorLabel ? `${authorLabel} ` : "";
|
|
||||||
return `Discord system: ${actor}${action} in ${location}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDiscordReactionEmoji(
|
function formatDiscordReactionEmoji(
|
||||||
reaction: MessageReaction | PartialMessageReaction,
|
reaction: MessageReaction | PartialMessageReaction,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import {
|
|
||||||
buildGatewayReloadPlan,
|
|
||||||
diffConfigPaths,
|
|
||||||
resolveGatewayReloadSettings,
|
|
||||||
} from "./config-reload.js";
|
|
||||||
|
|
||||||
describe("diffConfigPaths", () => {
|
|
||||||
it("captures nested config changes", () => {
|
|
||||||
const prev = { hooks: { gmail: { account: "a" } } };
|
|
||||||
const next = { hooks: { gmail: { account: "b" } } };
|
|
||||||
const paths = diffConfigPaths(prev, next);
|
|
||||||
expect(paths).toContain("hooks.gmail.account");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("captures array changes", () => {
|
|
||||||
const prev = { routing: { groupChat: { mentionPatterns: ["a"] } } };
|
|
||||||
const next = { routing: { groupChat: { mentionPatterns: ["b"] } } };
|
|
||||||
const paths = diffConfigPaths(prev, next);
|
|
||||||
expect(paths).toContain("routing.groupChat.mentionPatterns");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("buildGatewayReloadPlan", () => {
|
|
||||||
it("marks gateway changes as restart required", () => {
|
|
||||||
const plan = buildGatewayReloadPlan(["gateway.port"]);
|
|
||||||
expect(plan.restartGateway).toBe(true);
|
|
||||||
expect(plan.restartReasons).toContain("gateway.port");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("restarts the Gmail watcher for hooks.gmail changes", () => {
|
|
||||||
const plan = buildGatewayReloadPlan(["hooks.gmail.account"]);
|
|
||||||
expect(plan.restartGateway).toBe(false);
|
|
||||||
expect(plan.restartGmailWatcher).toBe(true);
|
|
||||||
expect(plan.reloadHooks).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("restarts providers for web/telegram changes", () => {
|
|
||||||
const plan = buildGatewayReloadPlan(["web.enabled", "telegram.botToken"]);
|
|
||||||
expect(plan.restartGateway).toBe(false);
|
|
||||||
expect(plan.restartProviders.has("whatsapp")).toBe(true);
|
|
||||||
expect(plan.restartProviders.has("telegram")).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("treats gateway.remote as no-op", () => {
|
|
||||||
const plan = buildGatewayReloadPlan(["gateway.remote.url"]);
|
|
||||||
expect(plan.restartGateway).toBe(false);
|
|
||||||
expect(plan.noopPaths).toContain("gateway.remote.url");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("defaults unknown paths to restart", () => {
|
|
||||||
const plan = buildGatewayReloadPlan(["unknownField"]);
|
|
||||||
expect(plan.restartGateway).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("resolveGatewayReloadSettings", () => {
|
|
||||||
it("uses defaults when unset", () => {
|
|
||||||
const settings = resolveGatewayReloadSettings({});
|
|
||||||
expect(settings.mode).toBe("hybrid");
|
|
||||||
expect(settings.debounceMs).toBe(300);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,365 +0,0 @@
|
|||||||
import chokidar from "chokidar";
|
|
||||||
|
|
||||||
import type {
|
|
||||||
ClawdisConfig,
|
|
||||||
ConfigFileSnapshot,
|
|
||||||
GatewayReloadMode,
|
|
||||||
} from "../config/config.js";
|
|
||||||
|
|
||||||
export type GatewayReloadSettings = {
|
|
||||||
mode: GatewayReloadMode;
|
|
||||||
debounceMs: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ProviderKind =
|
|
||||||
| "whatsapp"
|
|
||||||
| "telegram"
|
|
||||||
| "discord"
|
|
||||||
| "signal"
|
|
||||||
| "imessage";
|
|
||||||
|
|
||||||
export type GatewayReloadPlan = {
|
|
||||||
changedPaths: string[];
|
|
||||||
restartGateway: boolean;
|
|
||||||
restartReasons: string[];
|
|
||||||
hotReasons: string[];
|
|
||||||
reloadHooks: boolean;
|
|
||||||
restartGmailWatcher: boolean;
|
|
||||||
restartBrowserControl: boolean;
|
|
||||||
restartCron: boolean;
|
|
||||||
restartHeartbeat: boolean;
|
|
||||||
restartProviders: Set<ProviderKind>;
|
|
||||||
noopPaths: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type ReloadRule = {
|
|
||||||
prefix: string;
|
|
||||||
kind: "restart" | "hot" | "none";
|
|
||||||
actions?: ReloadAction[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type ReloadAction =
|
|
||||||
| "reload-hooks"
|
|
||||||
| "restart-gmail-watcher"
|
|
||||||
| "restart-browser-control"
|
|
||||||
| "restart-cron"
|
|
||||||
| "restart-heartbeat"
|
|
||||||
| "restart-provider:whatsapp"
|
|
||||||
| "restart-provider:telegram"
|
|
||||||
| "restart-provider:discord"
|
|
||||||
| "restart-provider:signal"
|
|
||||||
| "restart-provider:imessage";
|
|
||||||
|
|
||||||
const DEFAULT_RELOAD_SETTINGS: GatewayReloadSettings = {
|
|
||||||
mode: "hybrid",
|
|
||||||
debounceMs: 300,
|
|
||||||
};
|
|
||||||
|
|
||||||
const RELOAD_RULES: ReloadRule[] = [
|
|
||||||
{ prefix: "gateway.remote", kind: "none" },
|
|
||||||
{ prefix: "gateway.reload", kind: "none" },
|
|
||||||
{ prefix: "hooks.gmail", kind: "hot", actions: ["restart-gmail-watcher"] },
|
|
||||||
{ prefix: "hooks", kind: "hot", actions: ["reload-hooks"] },
|
|
||||||
{ prefix: "agent.heartbeat", kind: "hot", actions: ["restart-heartbeat"] },
|
|
||||||
{ prefix: "cron", kind: "hot", actions: ["restart-cron"] },
|
|
||||||
{
|
|
||||||
prefix: "browser",
|
|
||||||
kind: "hot",
|
|
||||||
actions: ["restart-browser-control"],
|
|
||||||
},
|
|
||||||
{ prefix: "web", kind: "hot", actions: ["restart-provider:whatsapp"] },
|
|
||||||
{ prefix: "telegram", kind: "hot", actions: ["restart-provider:telegram"] },
|
|
||||||
{ prefix: "discord", kind: "hot", actions: ["restart-provider:discord"] },
|
|
||||||
{ prefix: "signal", kind: "hot", actions: ["restart-provider:signal"] },
|
|
||||||
{ prefix: "imessage", kind: "hot", actions: ["restart-provider:imessage"] },
|
|
||||||
{ prefix: "identity", kind: "none" },
|
|
||||||
{ prefix: "wizard", kind: "none" },
|
|
||||||
{ prefix: "logging", kind: "none" },
|
|
||||||
{ prefix: "models", kind: "none" },
|
|
||||||
{ prefix: "agent", kind: "none" },
|
|
||||||
{ prefix: "routing", kind: "none" },
|
|
||||||
{ prefix: "messages", kind: "none" },
|
|
||||||
{ prefix: "session", kind: "none" },
|
|
||||||
{ prefix: "whatsapp", kind: "none" },
|
|
||||||
{ prefix: "talk", kind: "none" },
|
|
||||||
{ prefix: "skills", kind: "none" },
|
|
||||||
{ prefix: "ui", kind: "none" },
|
|
||||||
{ prefix: "gateway", kind: "restart" },
|
|
||||||
{ prefix: "bridge", kind: "restart" },
|
|
||||||
{ prefix: "discovery", kind: "restart" },
|
|
||||||
{ prefix: "canvasHost", kind: "restart" },
|
|
||||||
];
|
|
||||||
|
|
||||||
function matchRule(path: string): ReloadRule | null {
|
|
||||||
for (const rule of RELOAD_RULES) {
|
|
||||||
if (path === rule.prefix || path.startsWith(`${rule.prefix}.`)) return rule;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
||||||
return Boolean(
|
|
||||||
value &&
|
|
||||||
typeof value === "object" &&
|
|
||||||
!Array.isArray(value) &&
|
|
||||||
Object.prototype.toString.call(value) === "[object Object]",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function diffConfigPaths(
|
|
||||||
prev: unknown,
|
|
||||||
next: unknown,
|
|
||||||
prefix = "",
|
|
||||||
): string[] {
|
|
||||||
if (prev === next) return [];
|
|
||||||
if (isPlainObject(prev) && isPlainObject(next)) {
|
|
||||||
const keys = new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
||||||
const paths: string[] = [];
|
|
||||||
for (const key of keys) {
|
|
||||||
const prevValue = prev[key];
|
|
||||||
const nextValue = next[key];
|
|
||||||
if (prevValue === undefined && nextValue === undefined) continue;
|
|
||||||
const childPrefix = prefix ? `${prefix}.${key}` : key;
|
|
||||||
const childPaths = diffConfigPaths(prevValue, nextValue, childPrefix);
|
|
||||||
if (childPaths.length > 0) {
|
|
||||||
paths.push(...childPaths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return paths;
|
|
||||||
}
|
|
||||||
if (Array.isArray(prev) && Array.isArray(next)) {
|
|
||||||
if (
|
|
||||||
prev.length === next.length &&
|
|
||||||
prev.every((val, idx) => val === next[idx])
|
|
||||||
) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [prefix || "<root>"];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveGatewayReloadSettings(
|
|
||||||
cfg: ClawdisConfig,
|
|
||||||
): GatewayReloadSettings {
|
|
||||||
const rawMode = cfg.gateway?.reload?.mode;
|
|
||||||
const mode =
|
|
||||||
rawMode === "off" ||
|
|
||||||
rawMode === "restart" ||
|
|
||||||
rawMode === "hot" ||
|
|
||||||
rawMode === "hybrid"
|
|
||||||
? rawMode
|
|
||||||
: DEFAULT_RELOAD_SETTINGS.mode;
|
|
||||||
const debounceRaw = cfg.gateway?.reload?.debounceMs;
|
|
||||||
const debounceMs =
|
|
||||||
typeof debounceRaw === "number" && Number.isFinite(debounceRaw)
|
|
||||||
? Math.max(0, Math.floor(debounceRaw))
|
|
||||||
: DEFAULT_RELOAD_SETTINGS.debounceMs;
|
|
||||||
return { mode, debounceMs };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildGatewayReloadPlan(
|
|
||||||
changedPaths: string[],
|
|
||||||
): GatewayReloadPlan {
|
|
||||||
const plan: GatewayReloadPlan = {
|
|
||||||
changedPaths,
|
|
||||||
restartGateway: false,
|
|
||||||
restartReasons: [],
|
|
||||||
hotReasons: [],
|
|
||||||
reloadHooks: false,
|
|
||||||
restartGmailWatcher: false,
|
|
||||||
restartBrowserControl: false,
|
|
||||||
restartCron: false,
|
|
||||||
restartHeartbeat: false,
|
|
||||||
restartProviders: new Set(),
|
|
||||||
noopPaths: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const applyAction = (action: ReloadAction) => {
|
|
||||||
switch (action) {
|
|
||||||
case "reload-hooks":
|
|
||||||
plan.reloadHooks = true;
|
|
||||||
break;
|
|
||||||
case "restart-gmail-watcher":
|
|
||||||
plan.restartGmailWatcher = true;
|
|
||||||
break;
|
|
||||||
case "restart-browser-control":
|
|
||||||
plan.restartBrowserControl = true;
|
|
||||||
break;
|
|
||||||
case "restart-cron":
|
|
||||||
plan.restartCron = true;
|
|
||||||
break;
|
|
||||||
case "restart-heartbeat":
|
|
||||||
plan.restartHeartbeat = true;
|
|
||||||
break;
|
|
||||||
case "restart-provider:whatsapp":
|
|
||||||
plan.restartProviders.add("whatsapp");
|
|
||||||
break;
|
|
||||||
case "restart-provider:telegram":
|
|
||||||
plan.restartProviders.add("telegram");
|
|
||||||
break;
|
|
||||||
case "restart-provider:discord":
|
|
||||||
plan.restartProviders.add("discord");
|
|
||||||
break;
|
|
||||||
case "restart-provider:signal":
|
|
||||||
plan.restartProviders.add("signal");
|
|
||||||
break;
|
|
||||||
case "restart-provider:imessage":
|
|
||||||
plan.restartProviders.add("imessage");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const path of changedPaths) {
|
|
||||||
const rule = matchRule(path);
|
|
||||||
if (!rule) {
|
|
||||||
plan.restartGateway = true;
|
|
||||||
plan.restartReasons.push(path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (rule.kind === "restart") {
|
|
||||||
plan.restartGateway = true;
|
|
||||||
plan.restartReasons.push(path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (rule.kind === "none") {
|
|
||||||
plan.noopPaths.push(path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
plan.hotReasons.push(path);
|
|
||||||
for (const action of rule.actions ?? []) {
|
|
||||||
applyAction(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.restartGmailWatcher) {
|
|
||||||
plan.reloadHooks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return plan;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type GatewayConfigReloader = {
|
|
||||||
stop: () => Promise<void>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function startGatewayConfigReloader(opts: {
|
|
||||||
initialConfig: ClawdisConfig;
|
|
||||||
readSnapshot: () => Promise<ConfigFileSnapshot>;
|
|
||||||
onHotReload: (
|
|
||||||
plan: GatewayReloadPlan,
|
|
||||||
nextConfig: ClawdisConfig,
|
|
||||||
) => Promise<void>;
|
|
||||||
onRestart: (plan: GatewayReloadPlan, nextConfig: ClawdisConfig) => void;
|
|
||||||
log: {
|
|
||||||
info: (msg: string) => void;
|
|
||||||
warn: (msg: string) => void;
|
|
||||||
error: (msg: string) => void;
|
|
||||||
};
|
|
||||||
watchPath: string;
|
|
||||||
}): GatewayConfigReloader {
|
|
||||||
let currentConfig = opts.initialConfig;
|
|
||||||
let settings = resolveGatewayReloadSettings(currentConfig);
|
|
||||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
||||||
let pending = false;
|
|
||||||
let running = false;
|
|
||||||
let stopped = false;
|
|
||||||
let restartQueued = false;
|
|
||||||
|
|
||||||
const schedule = () => {
|
|
||||||
if (stopped) return;
|
|
||||||
if (debounceTimer) clearTimeout(debounceTimer);
|
|
||||||
const wait = settings.debounceMs;
|
|
||||||
debounceTimer = setTimeout(() => {
|
|
||||||
void runReload();
|
|
||||||
}, wait);
|
|
||||||
};
|
|
||||||
|
|
||||||
const runReload = async () => {
|
|
||||||
if (stopped) return;
|
|
||||||
if (running) {
|
|
||||||
pending = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
running = true;
|
|
||||||
if (debounceTimer) {
|
|
||||||
clearTimeout(debounceTimer);
|
|
||||||
debounceTimer = null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const snapshot = await opts.readSnapshot();
|
|
||||||
if (!snapshot.valid) {
|
|
||||||
const issues = snapshot.issues
|
|
||||||
.map((issue) => `${issue.path}: ${issue.message}`)
|
|
||||||
.join(", ");
|
|
||||||
opts.log.warn(`config reload skipped (invalid config): ${issues}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const nextConfig = snapshot.config;
|
|
||||||
const changedPaths = diffConfigPaths(currentConfig, nextConfig);
|
|
||||||
currentConfig = nextConfig;
|
|
||||||
settings = resolveGatewayReloadSettings(nextConfig);
|
|
||||||
if (changedPaths.length === 0) return;
|
|
||||||
|
|
||||||
const plan = buildGatewayReloadPlan(changedPaths);
|
|
||||||
if (settings.mode === "off") {
|
|
||||||
opts.log.info("config reload disabled (gateway.reload.mode=off)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (settings.mode === "restart") {
|
|
||||||
if (!restartQueued) {
|
|
||||||
restartQueued = true;
|
|
||||||
opts.onRestart(plan, nextConfig);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (plan.restartGateway) {
|
|
||||||
if (settings.mode === "hot") {
|
|
||||||
opts.log.warn(
|
|
||||||
`config reload requires gateway restart; hot mode ignoring (${plan.restartReasons.join(
|
|
||||||
", ",
|
|
||||||
)})`,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!restartQueued) {
|
|
||||||
restartQueued = true;
|
|
||||||
opts.onRestart(plan, nextConfig);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await opts.onHotReload(plan, nextConfig);
|
|
||||||
} catch (err) {
|
|
||||||
opts.log.error(`config reload failed: ${String(err)}`);
|
|
||||||
} finally {
|
|
||||||
running = false;
|
|
||||||
if (pending) {
|
|
||||||
pending = false;
|
|
||||||
schedule();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const watcher = chokidar.watch(opts.watchPath, {
|
|
||||||
ignoreInitial: true,
|
|
||||||
awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.on("add", schedule);
|
|
||||||
watcher.on("change", schedule);
|
|
||||||
watcher.on("unlink", schedule);
|
|
||||||
watcher.on("error", (err) => {
|
|
||||||
opts.log.warn(`config watcher error: ${String(err)}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
stop: async () => {
|
|
||||||
stopped = true;
|
|
||||||
if (debounceTimer) clearTimeout(debounceTimer);
|
|
||||||
debounceTimer = null;
|
|
||||||
await watcher.close().catch(() => {});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -58,14 +58,14 @@ export type HooksRequestHandler = (
|
|||||||
|
|
||||||
export function createHooksRequestHandler(
|
export function createHooksRequestHandler(
|
||||||
opts: {
|
opts: {
|
||||||
getHooksConfig: () => HooksConfigResolved | null;
|
hooksConfig: HooksConfigResolved | null;
|
||||||
bindHost: string;
|
bindHost: string;
|
||||||
port: number;
|
port: number;
|
||||||
logHooks: SubsystemLogger;
|
logHooks: SubsystemLogger;
|
||||||
} & HookDispatchers,
|
} & HookDispatchers,
|
||||||
): HooksRequestHandler {
|
): HooksRequestHandler {
|
||||||
const {
|
const {
|
||||||
getHooksConfig,
|
hooksConfig,
|
||||||
bindHost,
|
bindHost,
|
||||||
port,
|
port,
|
||||||
logHooks,
|
logHooks,
|
||||||
@@ -73,7 +73,6 @@ export function createHooksRequestHandler(
|
|||||||
dispatchWakeHook,
|
dispatchWakeHook,
|
||||||
} = opts;
|
} = opts;
|
||||||
return async (req, res) => {
|
return async (req, res) => {
|
||||||
const hooksConfig = getHooksConfig();
|
|
||||||
if (!hooksConfig) return false;
|
if (!hooksConfig) return false;
|
||||||
const url = new URL(req.url ?? "/", `http://${bindHost}:${port}`);
|
const url = new URL(req.url ?? "/", `http://${bindHost}:${port}`);
|
||||||
const basePath = hooksConfig.basePath;
|
const basePath = hooksConfig.basePath;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { describe, expect, test } from "vitest";
|
import { describe, expect, test } from "vitest";
|
||||||
|
import { readConfigFileSnapshot, writeConfigFile } from "../config/config.js";
|
||||||
import {
|
import {
|
||||||
connectOk,
|
connectOk,
|
||||||
installGatewayTestHooks,
|
installGatewayTestHooks,
|
||||||
@@ -63,9 +64,6 @@ describe("gateway server providers", () => {
|
|||||||
test("telegram.logout clears bot token from config", async () => {
|
test("telegram.logout clears bot token from config", async () => {
|
||||||
const prevToken = process.env.TELEGRAM_BOT_TOKEN;
|
const prevToken = process.env.TELEGRAM_BOT_TOKEN;
|
||||||
delete process.env.TELEGRAM_BOT_TOKEN;
|
delete process.env.TELEGRAM_BOT_TOKEN;
|
||||||
const { readConfigFileSnapshot, writeConfigFile } = await import(
|
|
||||||
"../config/config.js"
|
|
||||||
);
|
|
||||||
await writeConfigFile({
|
await writeConfigFile({
|
||||||
telegram: {
|
telegram: {
|
||||||
botToken: "123:abc",
|
botToken: "123:abc",
|
||||||
|
|||||||
+58
-231
@@ -86,11 +86,6 @@ import {
|
|||||||
authorizeGatewayConnect,
|
authorizeGatewayConnect,
|
||||||
type ResolvedGatewayAuth,
|
type ResolvedGatewayAuth,
|
||||||
} from "./auth.js";
|
} from "./auth.js";
|
||||||
import {
|
|
||||||
type GatewayReloadPlan,
|
|
||||||
type ProviderKind,
|
|
||||||
startGatewayConfigReloader,
|
|
||||||
} from "./config-reload.js";
|
|
||||||
import { normalizeControlUiBasePath } from "./control-ui.js";
|
import { normalizeControlUiBasePath } from "./control-ui.js";
|
||||||
import { resolveHooksConfig } from "./hooks.js";
|
import { resolveHooksConfig } from "./hooks.js";
|
||||||
import {
|
import {
|
||||||
@@ -99,11 +94,7 @@ import {
|
|||||||
resolveGatewayBindHost,
|
resolveGatewayBindHost,
|
||||||
} from "./net.js";
|
} from "./net.js";
|
||||||
import { createBridgeHandlers } from "./server-bridge.js";
|
import { createBridgeHandlers } from "./server-bridge.js";
|
||||||
import {
|
import { createBridgeSubscriptionManager } from "./server-bridge-subscriptions.js";
|
||||||
type BridgeListConnectedFn,
|
|
||||||
type BridgeSendEventFn,
|
|
||||||
createBridgeSubscriptionManager,
|
|
||||||
} from "./server-bridge-subscriptions.js";
|
|
||||||
import { startBrowserControlServerIfEnabled } from "./server-browser.js";
|
import { startBrowserControlServerIfEnabled } from "./server-browser.js";
|
||||||
import { createAgentEventHandler, createChatRunState } from "./server-chat.js";
|
import { createAgentEventHandler, createChatRunState } from "./server-chat.js";
|
||||||
import {
|
import {
|
||||||
@@ -142,7 +133,6 @@ const logProviders = log.child("providers");
|
|||||||
const logBrowser = log.child("browser");
|
const logBrowser = log.child("browser");
|
||||||
const logHealth = log.child("health");
|
const logHealth = log.child("health");
|
||||||
const logCron = log.child("cron");
|
const logCron = log.child("cron");
|
||||||
const logReload = log.child("reload");
|
|
||||||
const logHooks = log.child("hooks");
|
const logHooks = log.child("hooks");
|
||||||
const logWsControl = log.child("ws");
|
const logWsControl = log.child("ws");
|
||||||
const logWhatsApp = logProviders.child("whatsapp");
|
const logWhatsApp = logProviders.child("whatsapp");
|
||||||
@@ -418,7 +408,7 @@ export async function startGatewayServer(
|
|||||||
password,
|
password,
|
||||||
allowTailscale,
|
allowTailscale,
|
||||||
};
|
};
|
||||||
let hooksConfig = resolveHooksConfig(cfgAtStart);
|
const hooksConfig = resolveHooksConfig(cfgAtStart);
|
||||||
const canvasHostEnabled =
|
const canvasHostEnabled =
|
||||||
process.env.CLAWDIS_SKIP_CANVAS_HOST !== "1" &&
|
process.env.CLAWDIS_SKIP_CANVAS_HOST !== "1" &&
|
||||||
cfgAtStart.canvasHost?.enabled !== false;
|
cfgAtStart.canvasHost?.enabled !== false;
|
||||||
@@ -564,7 +554,7 @@ export async function startGatewayServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleHooksRequest = createHooksRequestHandler({
|
const handleHooksRequest = createHooksRequestHandler({
|
||||||
getHooksConfig: () => hooksConfig,
|
hooksConfig,
|
||||||
bindHost,
|
bindHost,
|
||||||
port,
|
port,
|
||||||
logHooks,
|
logHooks,
|
||||||
@@ -660,61 +650,57 @@ export async function startGatewayServer(
|
|||||||
setCommandLaneConcurrency("cron", cfgAtStart.cron?.maxConcurrentRuns ?? 1);
|
setCommandLaneConcurrency("cron", cfgAtStart.cron?.maxConcurrentRuns ?? 1);
|
||||||
setCommandLaneConcurrency("main", cfgAtStart.agent?.maxConcurrent ?? 1);
|
setCommandLaneConcurrency("main", cfgAtStart.agent?.maxConcurrent ?? 1);
|
||||||
|
|
||||||
|
const cronStorePath = resolveCronStorePath(cfgAtStart.cron?.store);
|
||||||
const cronLogger = getChildLogger({
|
const cronLogger = getChildLogger({
|
||||||
module: "cron",
|
module: "cron",
|
||||||
|
storePath: cronStorePath,
|
||||||
});
|
});
|
||||||
const deps = createDefaultDeps();
|
const deps = createDefaultDeps();
|
||||||
const buildCronService = (cfg: ReturnType<typeof loadConfig>) => {
|
const cronEnabled =
|
||||||
const storePath = resolveCronStorePath(cfg.cron?.store);
|
process.env.CLAWDIS_SKIP_CRON !== "1" && cfgAtStart.cron?.enabled !== false;
|
||||||
const cronEnabled =
|
const cron = new CronService({
|
||||||
process.env.CLAWDIS_SKIP_CRON !== "1" && cfg.cron?.enabled !== false;
|
storePath: cronStorePath,
|
||||||
const cron = new CronService({
|
cronEnabled,
|
||||||
storePath,
|
enqueueSystemEvent,
|
||||||
cronEnabled,
|
requestHeartbeatNow,
|
||||||
enqueueSystemEvent,
|
runIsolatedAgentJob: async ({ job, message }) => {
|
||||||
requestHeartbeatNow,
|
const cfg = loadConfig();
|
||||||
runIsolatedAgentJob: async ({ job, message }) => {
|
return await runCronIsolatedAgentTurn({
|
||||||
const runtimeConfig = loadConfig();
|
cfg,
|
||||||
return await runCronIsolatedAgentTurn({
|
deps,
|
||||||
cfg: runtimeConfig,
|
job,
|
||||||
deps,
|
message,
|
||||||
job,
|
sessionKey: `cron:${job.id}`,
|
||||||
message,
|
lane: "cron",
|
||||||
sessionKey: `cron:${job.id}`,
|
});
|
||||||
lane: "cron",
|
},
|
||||||
|
log: cronLogger,
|
||||||
|
onEvent: (evt) => {
|
||||||
|
broadcast("cron", evt, { dropIfSlow: true });
|
||||||
|
if (evt.action === "finished") {
|
||||||
|
const logPath = resolveCronRunLogPath({
|
||||||
|
storePath: cronStorePath,
|
||||||
|
jobId: evt.jobId,
|
||||||
});
|
});
|
||||||
},
|
void appendCronRunLog(logPath, {
|
||||||
log: getChildLogger({ module: "cron", storePath }),
|
ts: Date.now(),
|
||||||
onEvent: (evt) => {
|
jobId: evt.jobId,
|
||||||
broadcast("cron", evt, { dropIfSlow: true });
|
action: "finished",
|
||||||
if (evt.action === "finished") {
|
status: evt.status,
|
||||||
const logPath = resolveCronRunLogPath({
|
error: evt.error,
|
||||||
storePath,
|
summary: evt.summary,
|
||||||
jobId: evt.jobId,
|
runAtMs: evt.runAtMs,
|
||||||
});
|
durationMs: evt.durationMs,
|
||||||
void appendCronRunLog(logPath, {
|
nextRunAtMs: evt.nextRunAtMs,
|
||||||
ts: Date.now(),
|
}).catch((err) => {
|
||||||
jobId: evt.jobId,
|
cronLogger.warn(
|
||||||
action: "finished",
|
{ err: String(err), logPath },
|
||||||
status: evt.status,
|
"cron: run log append failed",
|
||||||
error: evt.error,
|
);
|
||||||
summary: evt.summary,
|
});
|
||||||
runAtMs: evt.runAtMs,
|
}
|
||||||
durationMs: evt.durationMs,
|
},
|
||||||
nextRunAtMs: evt.nextRunAtMs,
|
});
|
||||||
}).catch((err) => {
|
|
||||||
cronLogger.warn(
|
|
||||||
{ err: String(err), logPath },
|
|
||||||
"cron: run log append failed",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return { cron, storePath, cronEnabled };
|
|
||||||
};
|
|
||||||
|
|
||||||
let { cron, storePath: cronStorePath } = buildCronService(cfgAtStart);
|
|
||||||
|
|
||||||
const providerManager = createProviderManager({
|
const providerManager = createProviderManager({
|
||||||
loadConfig,
|
loadConfig,
|
||||||
@@ -733,10 +719,6 @@ export async function startGatewayServer(
|
|||||||
getRuntimeSnapshot,
|
getRuntimeSnapshot,
|
||||||
startProviders,
|
startProviders,
|
||||||
startWhatsAppProvider,
|
startWhatsAppProvider,
|
||||||
startTelegramProvider,
|
|
||||||
startDiscordProvider,
|
|
||||||
startSignalProvider,
|
|
||||||
startIMessageProvider,
|
|
||||||
stopWhatsAppProvider,
|
stopWhatsAppProvider,
|
||||||
stopTelegramProvider,
|
stopTelegramProvider,
|
||||||
stopDiscordProvider,
|
stopDiscordProvider,
|
||||||
@@ -866,11 +848,6 @@ export async function startGatewayServer(
|
|||||||
const bridgeSubscribe = bridgeSubscriptions.subscribe;
|
const bridgeSubscribe = bridgeSubscriptions.subscribe;
|
||||||
const bridgeUnsubscribe = bridgeSubscriptions.unsubscribe;
|
const bridgeUnsubscribe = bridgeSubscriptions.unsubscribe;
|
||||||
const bridgeUnsubscribeAll = bridgeSubscriptions.unsubscribeAll;
|
const bridgeUnsubscribeAll = bridgeSubscriptions.unsubscribeAll;
|
||||||
const bridgeSendEvent: BridgeSendEventFn = (opts) => {
|
|
||||||
bridge?.sendEvent(opts);
|
|
||||||
};
|
|
||||||
const bridgeListConnected: BridgeListConnectedFn = () =>
|
|
||||||
bridge?.listConnected() ?? [];
|
|
||||||
const bridgeSendToSession = (
|
const bridgeSendToSession = (
|
||||||
sessionKey: string,
|
sessionKey: string,
|
||||||
event: string,
|
event: string,
|
||||||
@@ -880,16 +857,20 @@ export async function startGatewayServer(
|
|||||||
sessionKey,
|
sessionKey,
|
||||||
event,
|
event,
|
||||||
payload,
|
payload,
|
||||||
bridgeSendEvent,
|
bridge ? (opts) => bridge.sendEvent(opts) : undefined,
|
||||||
);
|
);
|
||||||
const bridgeSendToAllSubscribed = (event: string, payload: unknown) =>
|
const bridgeSendToAllSubscribed = (event: string, payload: unknown) =>
|
||||||
bridgeSubscriptions.sendToAllSubscribed(event, payload, bridgeSendEvent);
|
bridgeSubscriptions.sendToAllSubscribed(
|
||||||
|
event,
|
||||||
|
payload,
|
||||||
|
bridge ? (opts) => bridge.sendEvent(opts) : undefined,
|
||||||
|
);
|
||||||
const bridgeSendToAllConnected = (event: string, payload: unknown) =>
|
const bridgeSendToAllConnected = (event: string, payload: unknown) =>
|
||||||
bridgeSubscriptions.sendToAllConnected(
|
bridgeSubscriptions.sendToAllConnected(
|
||||||
event,
|
event,
|
||||||
payload,
|
payload,
|
||||||
bridgeListConnected,
|
bridge ? () => bridge.listConnected() : undefined,
|
||||||
bridgeSendEvent,
|
bridge ? (opts) => bridge.sendEvent(opts) : undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
const broadcastVoiceWakeChanged = (triggers: string[]) => {
|
const broadcastVoiceWakeChanged = (triggers: string[]) => {
|
||||||
@@ -1141,7 +1122,7 @@ export async function startGatewayServer(
|
|||||||
broadcast("heartbeat", evt, { dropIfSlow: true });
|
broadcast("heartbeat", evt, { dropIfSlow: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
let heartbeatRunner = startHeartbeatRunner({ cfg: cfgAtStart });
|
const heartbeatRunner = startHeartbeatRunner({ cfg: cfgAtStart });
|
||||||
|
|
||||||
void cron
|
void cron
|
||||||
.start()
|
.start()
|
||||||
@@ -1604,159 +1585,6 @@ export async function startGatewayServer(
|
|||||||
logProviders.info("skipping provider start (CLAWDIS_SKIP_PROVIDERS=1)");
|
logProviders.info("skipping provider start (CLAWDIS_SKIP_PROVIDERS=1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
const applyHotReload = async (
|
|
||||||
plan: GatewayReloadPlan,
|
|
||||||
nextConfig: ReturnType<typeof loadConfig>,
|
|
||||||
) => {
|
|
||||||
if (plan.reloadHooks) {
|
|
||||||
try {
|
|
||||||
hooksConfig = resolveHooksConfig(nextConfig);
|
|
||||||
} catch (err) {
|
|
||||||
logHooks.warn(`hooks config reload failed: ${String(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.restartHeartbeat) {
|
|
||||||
heartbeatRunner.stop();
|
|
||||||
heartbeatRunner = startHeartbeatRunner({ cfg: nextConfig });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.restartCron) {
|
|
||||||
cron.stop();
|
|
||||||
const next = buildCronService(nextConfig);
|
|
||||||
cron = next.cron;
|
|
||||||
cronStorePath = next.storePath;
|
|
||||||
void cron
|
|
||||||
.start()
|
|
||||||
.catch((err) => logCron.error(`failed to start: ${String(err)}`));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.restartBrowserControl) {
|
|
||||||
if (browserControl) {
|
|
||||||
await browserControl.stop().catch(() => {});
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
browserControl = await startBrowserControlServerIfEnabled();
|
|
||||||
} catch (err) {
|
|
||||||
logBrowser.error(`server failed to start: ${String(err)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.restartGmailWatcher) {
|
|
||||||
await stopGmailWatcher().catch(() => {});
|
|
||||||
if (process.env.CLAWDIS_SKIP_GMAIL_WATCHER !== "1") {
|
|
||||||
try {
|
|
||||||
const gmailResult = await startGmailWatcher(nextConfig);
|
|
||||||
if (gmailResult.started) {
|
|
||||||
logHooks.info("gmail watcher started");
|
|
||||||
} else if (
|
|
||||||
gmailResult.reason &&
|
|
||||||
gmailResult.reason !== "hooks not enabled" &&
|
|
||||||
gmailResult.reason !== "no gmail account configured"
|
|
||||||
) {
|
|
||||||
logHooks.warn(`gmail watcher not started: ${gmailResult.reason}`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logHooks.error(`gmail watcher failed to start: ${String(err)}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logHooks.info(
|
|
||||||
"skipping gmail watcher restart (CLAWDIS_SKIP_GMAIL_WATCHER=1)",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plan.restartProviders.size > 0) {
|
|
||||||
if (process.env.CLAWDIS_SKIP_PROVIDERS === "1") {
|
|
||||||
logProviders.info(
|
|
||||||
"skipping provider reload (CLAWDIS_SKIP_PROVIDERS=1)",
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const restartProvider = async (
|
|
||||||
name: ProviderKind,
|
|
||||||
stop: () => Promise<void>,
|
|
||||||
start: () => Promise<void>,
|
|
||||||
) => {
|
|
||||||
logProviders.info(`restarting ${name} provider`);
|
|
||||||
await stop();
|
|
||||||
await start();
|
|
||||||
};
|
|
||||||
if (plan.restartProviders.has("whatsapp")) {
|
|
||||||
await restartProvider(
|
|
||||||
"whatsapp",
|
|
||||||
stopWhatsAppProvider,
|
|
||||||
startWhatsAppProvider,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (plan.restartProviders.has("telegram")) {
|
|
||||||
await restartProvider(
|
|
||||||
"telegram",
|
|
||||||
stopTelegramProvider,
|
|
||||||
startTelegramProvider,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (plan.restartProviders.has("discord")) {
|
|
||||||
await restartProvider(
|
|
||||||
"discord",
|
|
||||||
stopDiscordProvider,
|
|
||||||
startDiscordProvider,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (plan.restartProviders.has("signal")) {
|
|
||||||
await restartProvider(
|
|
||||||
"signal",
|
|
||||||
stopSignalProvider,
|
|
||||||
startSignalProvider,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (plan.restartProviders.has("imessage")) {
|
|
||||||
await restartProvider(
|
|
||||||
"imessage",
|
|
||||||
stopIMessageProvider,
|
|
||||||
startIMessageProvider,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setCommandLaneConcurrency("cron", nextConfig.cron?.maxConcurrentRuns ?? 1);
|
|
||||||
setCommandLaneConcurrency("main", nextConfig.agent?.maxConcurrent ?? 1);
|
|
||||||
|
|
||||||
if (plan.hotReasons.length > 0) {
|
|
||||||
logReload.info(
|
|
||||||
`config hot reload applied (${plan.hotReasons.join(", ")})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const requestGatewayRestart = (
|
|
||||||
plan: GatewayReloadPlan,
|
|
||||||
_nextConfig: ReturnType<typeof loadConfig>,
|
|
||||||
) => {
|
|
||||||
const reasons = plan.restartReasons.length
|
|
||||||
? plan.restartReasons.join(", ")
|
|
||||||
: plan.changedPaths.join(", ");
|
|
||||||
logReload.warn(`config change requires gateway restart (${reasons})`);
|
|
||||||
if (process.listenerCount("SIGUSR1") === 0) {
|
|
||||||
logReload.warn("no SIGUSR1 listener found; restart skipped");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
process.emit("SIGUSR1");
|
|
||||||
};
|
|
||||||
|
|
||||||
const configReloader = startGatewayConfigReloader({
|
|
||||||
initialConfig: cfgAtStart,
|
|
||||||
readSnapshot: readConfigFileSnapshot,
|
|
||||||
onHotReload: applyHotReload,
|
|
||||||
onRestart: requestGatewayRestart,
|
|
||||||
log: {
|
|
||||||
info: (msg) => logReload.info(msg),
|
|
||||||
warn: (msg) => logReload.warn(msg),
|
|
||||||
error: (msg) => logReload.error(msg),
|
|
||||||
},
|
|
||||||
watchPath: CONFIG_PATH_CLAWDIS,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
close: async (opts) => {
|
close: async (opts) => {
|
||||||
const reasonRaw =
|
const reasonRaw =
|
||||||
@@ -1836,7 +1664,6 @@ export async function startGatewayServer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
clients.clear();
|
clients.clear();
|
||||||
await configReloader.stop().catch(() => {});
|
|
||||||
if (browserControl) {
|
if (browserControl) {
|
||||||
await browserControl.stop().catch(() => {});
|
await browserControl.stop().catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, expect, vi } from "vitest";
|
import { afterEach, beforeEach, expect, vi } from "vitest";
|
||||||
import { WebSocket } from "ws";
|
import { WebSocket } from "ws";
|
||||||
|
import { agentCommand } from "../commands/agent.js";
|
||||||
import { resetAgentRunContextForTest } from "../infra/agent-events.js";
|
import { resetAgentRunContextForTest } from "../infra/agent-events.js";
|
||||||
import { drainSystemEvents, peekSystemEvents } from "../infra/system-events.js";
|
import { drainSystemEvents, peekSystemEvents } from "../infra/system-events.js";
|
||||||
import { rawDataToString } from "../infra/ws.js";
|
import { rawDataToString } from "../infra/ws.js";
|
||||||
@@ -63,7 +64,6 @@ const hoisted = vi.hoisted(() => ({
|
|||||||
}>,
|
}>,
|
||||||
},
|
},
|
||||||
cronIsolatedRun: vi.fn(async () => ({ status: "ok", summary: "ok" })),
|
cronIsolatedRun: vi.fn(async () => ({ status: "ok", summary: "ok" })),
|
||||||
agentCommand: vi.fn().mockResolvedValue(undefined),
|
|
||||||
testIsNixMode: { value: false },
|
testIsNixMode: { value: false },
|
||||||
sessionStoreSaveDelayMs: { value: 0 },
|
sessionStoreSaveDelayMs: { value: 0 },
|
||||||
}));
|
}));
|
||||||
@@ -75,7 +75,6 @@ export const bridgeSendEvent = hoisted.bridgeSendEvent;
|
|||||||
export const testTailnetIPv4 = hoisted.testTailnetIPv4;
|
export const testTailnetIPv4 = hoisted.testTailnetIPv4;
|
||||||
export const piSdkMock = hoisted.piSdkMock;
|
export const piSdkMock = hoisted.piSdkMock;
|
||||||
export const cronIsolatedRun = hoisted.cronIsolatedRun;
|
export const cronIsolatedRun = hoisted.cronIsolatedRun;
|
||||||
export const agentCommand = hoisted.agentCommand;
|
|
||||||
|
|
||||||
export const testState = {
|
export const testState = {
|
||||||
sessionStorePath: undefined as string | undefined,
|
sessionStorePath: undefined as string | undefined,
|
||||||
@@ -291,7 +290,7 @@ vi.mock("../web/outbound.js", () => ({
|
|||||||
.mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" }),
|
.mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" }),
|
||||||
}));
|
}));
|
||||||
vi.mock("../commands/agent.js", () => ({
|
vi.mock("../commands/agent.js", () => ({
|
||||||
agentCommand,
|
agentCommand: vi.fn().mockResolvedValue(undefined),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
process.env.CLAWDIS_SKIP_PROVIDERS = "1";
|
process.env.CLAWDIS_SKIP_PROVIDERS = "1";
|
||||||
@@ -510,3 +509,5 @@ export async function waitForSystemEvent(timeoutMs = 2000) {
|
|||||||
}
|
}
|
||||||
throw new Error("timeout waiting for system event");
|
throw new Error("timeout waiting for system event");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { agentCommand };
|
||||||
Reference in new issue
Block a user