Spaces:
Runtime error
Runtime error
merge: resolve PR conflicts and add OpenClaw offline E2E harness
Browse files- README.md +6 -4
- package.json +4 -1
- playwright.openclaw.gateway.config.ts +26 -0
- playwright.openclaw.local.config.ts +26 -0
- scripts/e2e-openclaw/bin/clawdbot +20 -0
- scripts/e2e-openclaw/bin/openclaw +20 -0
- scripts/e2e-openclaw/mock-gateway.mjs +61 -0
- scripts/e2e-openclaw/start-e2e-server.mjs +99 -0
- src/app/api/agents/[id]/soul/route.ts +11 -5
- src/app/api/cron/route.ts +3 -3
- src/app/api/gateway-config/route.ts +3 -5
- src/app/api/integrations/route.ts +8 -8
- src/app/api/status/route.ts +4 -1
- src/components/ErrorBoundary.tsx +4 -1
- src/components/chat/chat-panel.tsx +6 -3
- src/components/chat/conversation-list.tsx +4 -1
- src/components/dashboard/sidebar.tsx +4 -1
- src/components/panels/agent-cost-panel.tsx +4 -1
- src/components/panels/agent-detail-tabs.tsx +6 -3
- src/components/panels/agent-spawn-panel.tsx +5 -2
- src/components/panels/agent-squad-panel-phase3.tsx +11 -8
- src/components/panels/agent-squad-panel.tsx +6 -3
- src/components/panels/cron-management-panel.tsx +8 -6
- src/components/panels/gateway-config-panel.tsx +1 -1
- src/components/panels/log-viewer-panel.tsx +24 -21
- src/components/panels/memory-browser-panel.tsx +36 -19
- src/components/panels/session-details-panel.tsx +4 -1
- src/components/panels/standup-panel.tsx +4 -1
- src/components/panels/task-board-panel.tsx +8 -2
- src/components/panels/token-dashboard-panel.tsx +6 -3
- src/lib/agent-sync.ts +14 -7
- src/lib/client-logger.ts +68 -0
- src/lib/command.ts +2 -2
- src/lib/config.ts +21 -5
- src/lib/device-identity.ts +5 -1
- src/lib/sessions.ts +4 -4
- src/lib/use-server-events.ts +5 -2
- src/lib/websocket.ts +20 -17
- tests/README.md +14 -0
- tests/fixtures/openclaw/agents/engineering-bot/sessions/sessions.json +15 -0
- tests/fixtures/openclaw/agents/research-bot/sessions/sessions.json +15 -0
- tests/fixtures/openclaw/cron/jobs.json +59 -0
- tests/fixtures/openclaw/openclaw.json +49 -0
- tests/fixtures/openclaw/workspaces/engineering-bot/TOOLS.md +3 -0
- tests/fixtures/openclaw/workspaces/engineering-bot/identity.md +3 -0
- tests/fixtures/openclaw/workspaces/engineering-bot/soul.md +2 -0
- tests/fixtures/openclaw/workspaces/research-bot/TOOLS.md +2 -0
- tests/fixtures/openclaw/workspaces/research-bot/identity.md +3 -0
- tests/fixtures/openclaw/workspaces/research-bot/soul.md +2 -0
- tests/openclaw-harness.spec.ts +56 -0
README.md
CHANGED
|
@@ -342,7 +342,9 @@ See [`.env.example`](.env.example) for the complete list. Key variables:
|
|
| 342 |
| `AUTH_PASS` | No | Initial admin password |
|
| 343 |
| `AUTH_PASS_B64` | No | Base64-encoded admin password (overrides `AUTH_PASS` if set) |
|
| 344 |
| `API_KEY` | No | API key for headless access |
|
| 345 |
-
| `
|
|
|
|
|
|
|
| 346 |
| `OPENCLAW_GATEWAY_HOST` | No | Gateway host (default: `127.0.0.1`) |
|
| 347 |
| `OPENCLAW_GATEWAY_PORT` | No | Gateway WebSocket port (default: `18789`) |
|
| 348 |
| `OPENCLAW_GATEWAY_TOKEN` | No | Server-side gateway auth token |
|
|
@@ -354,10 +356,10 @@ See [`.env.example`](.env.example) for the complete list. Key variables:
|
|
| 354 |
| `MC_TRUSTED_PROXIES` | No | Comma-separated trusted proxy IPs for XFF parsing |
|
| 355 |
| `MC_ALLOWED_HOSTS` | No | Host allowlist for production |
|
| 356 |
|
| 357 |
-
*Memory browser, log viewer, and gateway config require `
|
| 358 |
|
| 359 |
> **Memory Browser note:** OpenClaw does not store agent memory markdown files under
|
| 360 |
-
> `$
|
| 361 |
> in each agent's workspace (e.g. `~/clawd-agents/{agent}/memory/`). Set
|
| 362 |
> `OPENCLAW_MEMORY_DIR` to your agents root directory to make the Memory Browser show
|
| 363 |
> daily logs, `MEMORY.md`, and other markdown files:
|
|
@@ -399,7 +401,7 @@ pnpm install --frozen-lockfile
|
|
| 399 |
pnpm build
|
| 400 |
|
| 401 |
# Run
|
| 402 |
-
|
| 403 |
```
|
| 404 |
|
| 405 |
Network access is restricted by default in production. Set `MC_ALLOWED_HOSTS` (comma-separated) or `MC_ALLOW_ANY_HOST=1` to control access.
|
|
|
|
| 342 |
| `AUTH_PASS` | No | Initial admin password |
|
| 343 |
| `AUTH_PASS_B64` | No | Base64-encoded admin password (overrides `AUTH_PASS` if set) |
|
| 344 |
| `API_KEY` | No | API key for headless access |
|
| 345 |
+
| `OPENCLAW_CONFIG_PATH` | Yes* | Absolute path to `openclaw.json` (preferred) |
|
| 346 |
+
| `OPENCLAW_STATE_DIR` | Yes* | OpenClaw state root (default: `~/.openclaw`) |
|
| 347 |
+
| `OPENCLAW_HOME` | No | Legacy alias for state dir (fallback if `OPENCLAW_STATE_DIR` unset) |
|
| 348 |
| `OPENCLAW_GATEWAY_HOST` | No | Gateway host (default: `127.0.0.1`) |
|
| 349 |
| `OPENCLAW_GATEWAY_PORT` | No | Gateway WebSocket port (default: `18789`) |
|
| 350 |
| `OPENCLAW_GATEWAY_TOKEN` | No | Server-side gateway auth token |
|
|
|
|
| 356 |
| `MC_TRUSTED_PROXIES` | No | Comma-separated trusted proxy IPs for XFF parsing |
|
| 357 |
| `MC_ALLOWED_HOSTS` | No | Host allowlist for production |
|
| 358 |
|
| 359 |
+
*Memory browser, log viewer, and gateway config require OpenClaw config/state resolution (`OPENCLAW_CONFIG_PATH` and/or `OPENCLAW_STATE_DIR`).
|
| 360 |
|
| 361 |
> **Memory Browser note:** OpenClaw does not store agent memory markdown files under
|
| 362 |
+
> `$OPENCLAW_STATE_DIR/memory/` — that directory does not exist by default. Agent memory lives
|
| 363 |
> in each agent's workspace (e.g. `~/clawd-agents/{agent}/memory/`). Set
|
| 364 |
> `OPENCLAW_MEMORY_DIR` to your agents root directory to make the Memory Browser show
|
| 365 |
> daily logs, `MEMORY.md`, and other markdown files:
|
|
|
|
| 401 |
pnpm build
|
| 402 |
|
| 403 |
# Run
|
| 404 |
+
OPENCLAW_CONFIG_PATH=/path/to/.openclaw/openclaw.json OPENCLAW_STATE_DIR=/path/to/.openclaw pnpm start
|
| 405 |
```
|
| 406 |
|
| 407 |
Network access is restricted by default in production. Set `MC_ALLOWED_HOSTS` (comma-separated) or `MC_ALLOW_ANY_HOST=1` to control access.
|
package.json
CHANGED
|
@@ -12,6 +12,9 @@
|
|
| 12 |
"test:watch": "vitest",
|
| 13 |
"test:ui": "vitest --ui",
|
| 14 |
"test:e2e": "playwright test",
|
|
|
|
|
|
|
|
|
|
| 15 |
"test:all": "pnpm lint && pnpm typecheck && pnpm test && pnpm build && pnpm test:e2e",
|
| 16 |
"quality:gate": "pnpm test:all"
|
| 17 |
},
|
|
@@ -77,4 +80,4 @@
|
|
| 77 |
"better-sqlite3"
|
| 78 |
]
|
| 79 |
}
|
| 80 |
-
}
|
|
|
|
| 12 |
"test:watch": "vitest",
|
| 13 |
"test:ui": "vitest --ui",
|
| 14 |
"test:e2e": "playwright test",
|
| 15 |
+
"test:e2e:openclaw:local": "E2E_GATEWAY_EXPECTED=0 playwright test -c playwright.openclaw.local.config.ts",
|
| 16 |
+
"test:e2e:openclaw:gateway": "E2E_GATEWAY_EXPECTED=1 playwright test -c playwright.openclaw.gateway.config.ts",
|
| 17 |
+
"test:e2e:openclaw": "pnpm test:e2e:openclaw:local && pnpm test:e2e:openclaw:gateway",
|
| 18 |
"test:all": "pnpm lint && pnpm typecheck && pnpm test && pnpm build && pnpm test:e2e",
|
| 19 |
"quality:gate": "pnpm test:all"
|
| 20 |
},
|
|
|
|
| 80 |
"better-sqlite3"
|
| 81 |
]
|
| 82 |
}
|
| 83 |
+
}
|
playwright.openclaw.gateway.config.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig, devices } from '@playwright/test'
|
| 2 |
+
|
| 3 |
+
export default defineConfig({
|
| 4 |
+
testDir: 'tests',
|
| 5 |
+
testMatch: /openclaw-harness\.spec\.ts/,
|
| 6 |
+
timeout: 60_000,
|
| 7 |
+
expect: {
|
| 8 |
+
timeout: 10_000,
|
| 9 |
+
},
|
| 10 |
+
fullyParallel: false,
|
| 11 |
+
workers: 1,
|
| 12 |
+
reporter: [['list']],
|
| 13 |
+
use: {
|
| 14 |
+
baseURL: 'http://127.0.0.1:3005',
|
| 15 |
+
trace: 'retain-on-failure',
|
| 16 |
+
},
|
| 17 |
+
projects: [
|
| 18 |
+
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
|
| 19 |
+
],
|
| 20 |
+
webServer: {
|
| 21 |
+
command: 'node scripts/e2e-openclaw/start-e2e-server.mjs --mode=gateway',
|
| 22 |
+
url: 'http://127.0.0.1:3005',
|
| 23 |
+
reuseExistingServer: false,
|
| 24 |
+
timeout: 120_000,
|
| 25 |
+
},
|
| 26 |
+
})
|
playwright.openclaw.local.config.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig, devices } from '@playwright/test'
|
| 2 |
+
|
| 3 |
+
export default defineConfig({
|
| 4 |
+
testDir: 'tests',
|
| 5 |
+
testMatch: /openclaw-harness\.spec\.ts/,
|
| 6 |
+
timeout: 60_000,
|
| 7 |
+
expect: {
|
| 8 |
+
timeout: 10_000,
|
| 9 |
+
},
|
| 10 |
+
fullyParallel: false,
|
| 11 |
+
workers: 1,
|
| 12 |
+
reporter: [['list']],
|
| 13 |
+
use: {
|
| 14 |
+
baseURL: 'http://127.0.0.1:3005',
|
| 15 |
+
trace: 'retain-on-failure',
|
| 16 |
+
},
|
| 17 |
+
projects: [
|
| 18 |
+
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
|
| 19 |
+
],
|
| 20 |
+
webServer: {
|
| 21 |
+
command: 'node scripts/e2e-openclaw/start-e2e-server.mjs --mode=local',
|
| 22 |
+
url: 'http://127.0.0.1:3005',
|
| 23 |
+
reuseExistingServer: false,
|
| 24 |
+
timeout: 120_000,
|
| 25 |
+
},
|
| 26 |
+
})
|
scripts/e2e-openclaw/bin/clawdbot
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
if [[ "${1:-}" == "--version" ]]; then
|
| 5 |
+
echo "clawdbot 2026.3.2"
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
|
| 9 |
+
if [[ "${1:-}" == "-c" ]]; then
|
| 10 |
+
cmd="${2:-}"
|
| 11 |
+
if [[ "$cmd" == sessions_spawn* ]]; then
|
| 12 |
+
echo "Session created: mock-clawdbot-session"
|
| 13 |
+
exit 0
|
| 14 |
+
fi
|
| 15 |
+
echo "ok"
|
| 16 |
+
exit 0
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
echo "clawdbot mock: unsupported args: $*" >&2
|
| 20 |
+
exit 0
|
scripts/e2e-openclaw/bin/openclaw
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
if [[ "${1:-}" == "--version" ]]; then
|
| 5 |
+
echo "openclaw 2026.3.2"
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
|
| 9 |
+
if [[ "${1:-}" == "-c" ]]; then
|
| 10 |
+
cmd="${2:-}"
|
| 11 |
+
if [[ "$cmd" == sessions_spawn* ]]; then
|
| 12 |
+
echo "Session created: mock-openclaw-session"
|
| 13 |
+
exit 0
|
| 14 |
+
fi
|
| 15 |
+
echo "ok"
|
| 16 |
+
exit 0
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
echo "openclaw mock: unsupported args: $*" >&2
|
| 20 |
+
exit 0
|
scripts/e2e-openclaw/mock-gateway.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
import http from 'node:http'
|
| 3 |
+
import { WebSocketServer } from 'ws'
|
| 4 |
+
|
| 5 |
+
const host = process.env.OPENCLAW_GATEWAY_HOST || '127.0.0.1'
|
| 6 |
+
const port = Number(process.env.OPENCLAW_GATEWAY_PORT || 18789)
|
| 7 |
+
|
| 8 |
+
const server = http.createServer((req, res) => {
|
| 9 |
+
if (!req.url) {
|
| 10 |
+
res.writeHead(404)
|
| 11 |
+
res.end()
|
| 12 |
+
return
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
if (req.url === '/health') {
|
| 16 |
+
res.writeHead(200, { 'content-type': 'application/json' })
|
| 17 |
+
res.end(JSON.stringify({ ok: true, service: 'openclaw-mock-gateway' }))
|
| 18 |
+
return
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
res.writeHead(200, { 'content-type': 'application/json' })
|
| 22 |
+
res.end(JSON.stringify({ ok: true }))
|
| 23 |
+
})
|
| 24 |
+
|
| 25 |
+
const wss = new WebSocketServer({ noServer: true })
|
| 26 |
+
|
| 27 |
+
wss.on('connection', (ws) => {
|
| 28 |
+
ws.send(JSON.stringify({ type: 'status', connected: true, source: 'mock-gateway' }))
|
| 29 |
+
ws.on('message', (raw) => {
|
| 30 |
+
const text = raw.toString()
|
| 31 |
+
if (text.includes('ping')) {
|
| 32 |
+
ws.send(JSON.stringify({ type: 'pong', ts: Date.now() }))
|
| 33 |
+
return
|
| 34 |
+
}
|
| 35 |
+
ws.send(JSON.stringify({ type: 'event', message: 'ack', raw: text }))
|
| 36 |
+
})
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
server.on('upgrade', (req, socket, head) => {
|
| 40 |
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
| 41 |
+
wss.emit('connection', ws, req)
|
| 42 |
+
})
|
| 43 |
+
})
|
| 44 |
+
|
| 45 |
+
server.listen(port, host, () => {
|
| 46 |
+
process.stdout.write(`[openclaw-mock-gateway] listening on ${host}:${port}\n`)
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
function shutdown() {
|
| 50 |
+
wss.clients.forEach((client) => {
|
| 51 |
+
try {
|
| 52 |
+
client.close()
|
| 53 |
+
} catch {
|
| 54 |
+
// noop
|
| 55 |
+
}
|
| 56 |
+
})
|
| 57 |
+
server.close(() => process.exit(0))
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
process.on('SIGINT', shutdown)
|
| 61 |
+
process.on('SIGTERM', shutdown)
|
scripts/e2e-openclaw/start-e2e-server.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
import { spawn } from 'node:child_process'
|
| 3 |
+
import fs from 'node:fs'
|
| 4 |
+
import path from 'node:path'
|
| 5 |
+
import process from 'node:process'
|
| 6 |
+
|
| 7 |
+
const modeArg = process.argv.find((arg) => arg.startsWith('--mode='))
|
| 8 |
+
const mode = modeArg ? modeArg.split('=')[1] : 'local'
|
| 9 |
+
if (mode !== 'local' && mode !== 'gateway') {
|
| 10 |
+
process.stderr.write(`Invalid mode: ${mode}\n`)
|
| 11 |
+
process.exit(1)
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const repoRoot = process.cwd()
|
| 15 |
+
const fixtureSource = path.join(repoRoot, 'tests', 'fixtures', 'openclaw')
|
| 16 |
+
const runtimeRoot = path.join(repoRoot, '.tmp', 'e2e-openclaw', mode)
|
| 17 |
+
const dataDir = path.join(runtimeRoot, 'data')
|
| 18 |
+
const mockBinDir = path.join(repoRoot, 'scripts', 'e2e-openclaw', 'bin')
|
| 19 |
+
|
| 20 |
+
fs.rmSync(runtimeRoot, { recursive: true, force: true })
|
| 21 |
+
fs.mkdirSync(runtimeRoot, { recursive: true })
|
| 22 |
+
fs.mkdirSync(dataDir, { recursive: true })
|
| 23 |
+
fs.cpSync(fixtureSource, runtimeRoot, { recursive: true })
|
| 24 |
+
|
| 25 |
+
const gatewayHost = '127.0.0.1'
|
| 26 |
+
const gatewayPort = '18789'
|
| 27 |
+
|
| 28 |
+
const baseEnv = {
|
| 29 |
+
...process.env,
|
| 30 |
+
API_KEY: process.env.API_KEY || 'test-api-key-e2e-12345',
|
| 31 |
+
AUTH_USER: process.env.AUTH_USER || 'admin',
|
| 32 |
+
AUTH_PASS: process.env.AUTH_PASS || 'admin',
|
| 33 |
+
MC_DISABLE_RATE_LIMIT: '1',
|
| 34 |
+
MISSION_CONTROL_DATA_DIR: dataDir,
|
| 35 |
+
MISSION_CONTROL_DB_PATH: path.join(dataDir, 'mission-control.db'),
|
| 36 |
+
OPENCLAW_STATE_DIR: runtimeRoot,
|
| 37 |
+
OPENCLAW_CONFIG_PATH: path.join(runtimeRoot, 'openclaw.json'),
|
| 38 |
+
OPENCLAW_GATEWAY_HOST: gatewayHost,
|
| 39 |
+
OPENCLAW_GATEWAY_PORT: gatewayPort,
|
| 40 |
+
OPENCLAW_BIN: path.join(mockBinDir, 'openclaw'),
|
| 41 |
+
CLAWDBOT_BIN: path.join(mockBinDir, 'clawdbot'),
|
| 42 |
+
PATH: `${mockBinDir}:${process.env.PATH || ''}`,
|
| 43 |
+
E2E_GATEWAY_EXPECTED: mode === 'gateway' ? '1' : '0',
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const children = []
|
| 47 |
+
|
| 48 |
+
if (mode === 'gateway') {
|
| 49 |
+
const gw = spawn('node', ['scripts/e2e-openclaw/mock-gateway.mjs'], {
|
| 50 |
+
cwd: repoRoot,
|
| 51 |
+
env: baseEnv,
|
| 52 |
+
stdio: 'inherit',
|
| 53 |
+
})
|
| 54 |
+
children.push(gw)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
const standaloneServerPath = path.join(repoRoot, '.next', 'standalone', 'server.js')
|
| 58 |
+
const app = fs.existsSync(standaloneServerPath)
|
| 59 |
+
? spawn('node', [standaloneServerPath], {
|
| 60 |
+
cwd: repoRoot,
|
| 61 |
+
env: {
|
| 62 |
+
...baseEnv,
|
| 63 |
+
HOSTNAME: '127.0.0.1',
|
| 64 |
+
PORT: '3005',
|
| 65 |
+
},
|
| 66 |
+
stdio: 'inherit',
|
| 67 |
+
})
|
| 68 |
+
: spawn('pnpm', ['start'], {
|
| 69 |
+
cwd: repoRoot,
|
| 70 |
+
env: baseEnv,
|
| 71 |
+
stdio: 'inherit',
|
| 72 |
+
})
|
| 73 |
+
children.push(app)
|
| 74 |
+
|
| 75 |
+
function shutdown(signal = 'SIGTERM') {
|
| 76 |
+
for (const child of children) {
|
| 77 |
+
if (!child.killed) {
|
| 78 |
+
try {
|
| 79 |
+
child.kill(signal)
|
| 80 |
+
} catch {
|
| 81 |
+
// noop
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
process.on('SIGINT', () => {
|
| 88 |
+
shutdown('SIGINT')
|
| 89 |
+
process.exit(130)
|
| 90 |
+
})
|
| 91 |
+
process.on('SIGTERM', () => {
|
| 92 |
+
shutdown('SIGTERM')
|
| 93 |
+
process.exit(143)
|
| 94 |
+
})
|
| 95 |
+
|
| 96 |
+
app.on('exit', (code) => {
|
| 97 |
+
shutdown('SIGTERM')
|
| 98 |
+
process.exit(code ?? 0)
|
| 99 |
+
})
|
src/app/api/agents/[id]/soul/route.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server';
|
| 2 |
import { getDatabase, db_helpers } from '@/lib/db';
|
| 3 |
import { readFileSync, existsSync, readdirSync, writeFileSync, mkdirSync } from 'fs';
|
| 4 |
-
import { join, dirname } from 'path';
|
| 5 |
import { config } from '@/lib/config';
|
| 6 |
import { resolveWithin } from '@/lib/paths';
|
| 7 |
import { requireRole } from '@/lib/auth';
|
| 8 |
import { logger } from '@/lib/logger';
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
/**
|
| 11 |
* GET /api/agents/[id]/soul - Get agent's SOUL content
|
| 12 |
*/
|
|
@@ -41,8 +47,8 @@ export async function GET(
|
|
| 41 |
|
| 42 |
try {
|
| 43 |
const agentConfig = agent.config ? JSON.parse(agent.config) : {}
|
| 44 |
-
if (agentConfig.workspace
|
| 45 |
-
const safeWorkspace =
|
| 46 |
const safeSoulPath = resolveWithin(safeWorkspace, 'soul.md')
|
| 47 |
if (existsSync(safeSoulPath)) {
|
| 48 |
soulContent = readFileSync(safeSoulPath, 'utf-8')
|
|
@@ -157,8 +163,8 @@ export async function PUT(
|
|
| 157 |
let savedToWorkspace = false
|
| 158 |
try {
|
| 159 |
const agentConfig = agent.config ? JSON.parse(agent.config) : {}
|
| 160 |
-
if (agentConfig.workspace
|
| 161 |
-
const safeWorkspace =
|
| 162 |
const safeSoulPath = resolveWithin(safeWorkspace, 'soul.md')
|
| 163 |
mkdirSync(dirname(safeSoulPath), { recursive: true })
|
| 164 |
writeFileSync(safeSoulPath, newSoulContent || '', 'utf-8')
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server';
|
| 2 |
import { getDatabase, db_helpers } from '@/lib/db';
|
| 3 |
import { readFileSync, existsSync, readdirSync, writeFileSync, mkdirSync } from 'fs';
|
| 4 |
+
import { join, dirname, isAbsolute, resolve } from 'path';
|
| 5 |
import { config } from '@/lib/config';
|
| 6 |
import { resolveWithin } from '@/lib/paths';
|
| 7 |
import { requireRole } from '@/lib/auth';
|
| 8 |
import { logger } from '@/lib/logger';
|
| 9 |
|
| 10 |
+
function resolveAgentWorkspacePath(workspace: string): string {
|
| 11 |
+
if (isAbsolute(workspace)) return resolve(workspace)
|
| 12 |
+
if (!config.openclawStateDir) throw new Error('OPENCLAW_STATE_DIR not configured')
|
| 13 |
+
return resolveWithin(config.openclawStateDir, workspace)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
/**
|
| 17 |
* GET /api/agents/[id]/soul - Get agent's SOUL content
|
| 18 |
*/
|
|
|
|
| 47 |
|
| 48 |
try {
|
| 49 |
const agentConfig = agent.config ? JSON.parse(agent.config) : {}
|
| 50 |
+
if (agentConfig.workspace) {
|
| 51 |
+
const safeWorkspace = resolveAgentWorkspacePath(agentConfig.workspace)
|
| 52 |
const safeSoulPath = resolveWithin(safeWorkspace, 'soul.md')
|
| 53 |
if (existsSync(safeSoulPath)) {
|
| 54 |
soulContent = readFileSync(safeSoulPath, 'utf-8')
|
|
|
|
| 163 |
let savedToWorkspace = false
|
| 164 |
try {
|
| 165 |
const agentConfig = agent.config ? JSON.parse(agent.config) : {}
|
| 166 |
+
if (agentConfig.workspace) {
|
| 167 |
+
const safeWorkspace = resolveAgentWorkspacePath(agentConfig.workspace)
|
| 168 |
const safeSoulPath = resolveWithin(safeWorkspace, 'soul.md')
|
| 169 |
mkdirSync(dirname(safeSoulPath), { recursive: true })
|
| 170 |
writeFileSync(safeSoulPath, newSoulContent || '', 'utf-8')
|
src/app/api/cron/route.ts
CHANGED
|
@@ -67,9 +67,9 @@ interface OpenClawCronFile {
|
|
| 67 |
}
|
| 68 |
|
| 69 |
function getCronFilePath(): string {
|
| 70 |
-
const
|
| 71 |
-
if (!
|
| 72 |
-
return path.join(
|
| 73 |
}
|
| 74 |
|
| 75 |
async function loadCronFile(): Promise<OpenClawCronFile | null> {
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
function getCronFilePath(): string {
|
| 70 |
+
const openclawStateDir = config.openclawStateDir
|
| 71 |
+
if (!openclawStateDir) return ''
|
| 72 |
+
return path.join(openclawStateDir, 'cron', 'jobs.json')
|
| 73 |
}
|
| 74 |
|
| 75 |
async function loadCronFile(): Promise<OpenClawCronFile | null> {
|
src/app/api/gateway-config/route.ts
CHANGED
|
@@ -2,13 +2,11 @@ import { NextRequest, NextResponse } from 'next/server'
|
|
| 2 |
import { requireRole } from '@/lib/auth'
|
| 3 |
import { logAuditEvent } from '@/lib/db'
|
| 4 |
import { config } from '@/lib/config'
|
| 5 |
-
import { join } from 'path'
|
| 6 |
import { validateBody, gatewayConfigUpdateSchema } from '@/lib/validation'
|
| 7 |
import { mutationLimiter } from '@/lib/rate-limit'
|
| 8 |
|
| 9 |
function getConfigPath(): string | null {
|
| 10 |
-
|
| 11 |
-
return join(config.openclawHome, 'openclaw.json')
|
| 12 |
}
|
| 13 |
|
| 14 |
/**
|
|
@@ -20,7 +18,7 @@ export async function GET(request: NextRequest) {
|
|
| 20 |
|
| 21 |
const configPath = getConfigPath()
|
| 22 |
if (!configPath) {
|
| 23 |
-
return NextResponse.json({ error: '
|
| 24 |
}
|
| 25 |
|
| 26 |
try {
|
|
@@ -60,7 +58,7 @@ export async function PUT(request: NextRequest) {
|
|
| 60 |
|
| 61 |
const configPath = getConfigPath()
|
| 62 |
if (!configPath) {
|
| 63 |
-
return NextResponse.json({ error: '
|
| 64 |
}
|
| 65 |
|
| 66 |
const result = await validateBody(request, gatewayConfigUpdateSchema)
|
|
|
|
| 2 |
import { requireRole } from '@/lib/auth'
|
| 3 |
import { logAuditEvent } from '@/lib/db'
|
| 4 |
import { config } from '@/lib/config'
|
|
|
|
| 5 |
import { validateBody, gatewayConfigUpdateSchema } from '@/lib/validation'
|
| 6 |
import { mutationLimiter } from '@/lib/rate-limit'
|
| 7 |
|
| 8 |
function getConfigPath(): string | null {
|
| 9 |
+
return config.openclawConfigPath || null
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
/**
|
|
|
|
| 18 |
|
| 19 |
const configPath = getConfigPath()
|
| 20 |
if (!configPath) {
|
| 21 |
+
return NextResponse.json({ error: 'OPENCLAW_CONFIG_PATH not configured' }, { status: 404 })
|
| 22 |
}
|
| 23 |
|
| 24 |
try {
|
|
|
|
| 58 |
|
| 59 |
const configPath = getConfigPath()
|
| 60 |
if (!configPath) {
|
| 61 |
+
return NextResponse.json({ error: 'OPENCLAW_CONFIG_PATH not configured' }, { status: 404 })
|
| 62 |
}
|
| 63 |
|
| 64 |
const result = await validateBody(request, gatewayConfigUpdateSchema)
|
src/app/api/integrations/route.ts
CHANGED
|
@@ -108,8 +108,8 @@ function serializeEnv(lines: EnvLine[]): string {
|
|
| 108 |
}
|
| 109 |
|
| 110 |
function getEnvPath(): string | null {
|
| 111 |
-
if (!config.
|
| 112 |
-
return join(config.
|
| 113 |
}
|
| 114 |
|
| 115 |
async function readEnvFile(): Promise<{ lines: EnvLine[]; raw: string } | null> {
|
|
@@ -184,7 +184,7 @@ export async function GET(request: NextRequest) {
|
|
| 184 |
|
| 185 |
const envData = await readEnvFile()
|
| 186 |
if (!envData) {
|
| 187 |
-
return NextResponse.json({ error: '
|
| 188 |
}
|
| 189 |
|
| 190 |
const envMap = new Map<string, string>()
|
|
@@ -261,7 +261,7 @@ export async function PUT(request: NextRequest) {
|
|
| 261 |
|
| 262 |
const envData = await readEnvFile()
|
| 263 |
if (!envData) {
|
| 264 |
-
return NextResponse.json({ error: '
|
| 265 |
}
|
| 266 |
|
| 267 |
const { lines } = envData
|
|
@@ -324,7 +324,7 @@ export async function DELETE(request: NextRequest) {
|
|
| 324 |
|
| 325 |
const envData = await readEnvFile()
|
| 326 |
if (!envData) {
|
| 327 |
-
return NextResponse.json({ error: '
|
| 328 |
}
|
| 329 |
|
| 330 |
const removed: string[] = []
|
|
@@ -408,7 +408,7 @@ async function handleTest(
|
|
| 408 |
|
| 409 |
const envData = await readEnvFile()
|
| 410 |
if (!envData) {
|
| 411 |
-
return NextResponse.json({ error: '
|
| 412 |
}
|
| 413 |
|
| 414 |
const envMap = new Map<string, string>()
|
|
@@ -552,7 +552,7 @@ async function handlePull(
|
|
| 552 |
// Write to .env
|
| 553 |
const envData = await readEnvFile()
|
| 554 |
if (!envData) {
|
| 555 |
-
return NextResponse.json({ error: '
|
| 556 |
}
|
| 557 |
|
| 558 |
const { lines } = envData
|
|
@@ -621,7 +621,7 @@ async function handlePullAll(
|
|
| 621 |
|
| 622 |
const envData = await readEnvFile()
|
| 623 |
if (!envData) {
|
| 624 |
-
return NextResponse.json({ error: '
|
| 625 |
}
|
| 626 |
|
| 627 |
const { lines } = envData
|
|
|
|
| 108 |
}
|
| 109 |
|
| 110 |
function getEnvPath(): string | null {
|
| 111 |
+
if (!config.openclawStateDir) return null
|
| 112 |
+
return join(config.openclawStateDir, '.env')
|
| 113 |
}
|
| 114 |
|
| 115 |
async function readEnvFile(): Promise<{ lines: EnvLine[]; raw: string } | null> {
|
|
|
|
| 184 |
|
| 185 |
const envData = await readEnvFile()
|
| 186 |
if (!envData) {
|
| 187 |
+
return NextResponse.json({ error: 'OPENCLAW_STATE_DIR not configured' }, { status: 404 })
|
| 188 |
}
|
| 189 |
|
| 190 |
const envMap = new Map<string, string>()
|
|
|
|
| 261 |
|
| 262 |
const envData = await readEnvFile()
|
| 263 |
if (!envData) {
|
| 264 |
+
return NextResponse.json({ error: 'OPENCLAW_STATE_DIR not configured' }, { status: 404 })
|
| 265 |
}
|
| 266 |
|
| 267 |
const { lines } = envData
|
|
|
|
| 324 |
|
| 325 |
const envData = await readEnvFile()
|
| 326 |
if (!envData) {
|
| 327 |
+
return NextResponse.json({ error: 'OPENCLAW_STATE_DIR not configured' }, { status: 404 })
|
| 328 |
}
|
| 329 |
|
| 330 |
const removed: string[] = []
|
|
|
|
| 408 |
|
| 409 |
const envData = await readEnvFile()
|
| 410 |
if (!envData) {
|
| 411 |
+
return NextResponse.json({ error: 'OPENCLAW_STATE_DIR not configured' }, { status: 404 })
|
| 412 |
}
|
| 413 |
|
| 414 |
const envMap = new Map<string, string>()
|
|
|
|
| 552 |
// Write to .env
|
| 553 |
const envData = await readEnvFile()
|
| 554 |
if (!envData) {
|
| 555 |
+
return NextResponse.json({ error: 'OPENCLAW_STATE_DIR not configured' }, { status: 404 })
|
| 556 |
}
|
| 557 |
|
| 558 |
const { lines } = envData
|
|
|
|
| 621 |
|
| 622 |
const envData = await readEnvFile()
|
| 623 |
if (!envData) {
|
| 624 |
+
return NextResponse.json({ error: 'OPENCLAW_STATE_DIR not configured' }, { status: 404 })
|
| 625 |
}
|
| 626 |
|
| 627 |
const { lines } = envData
|
src/app/api/status/route.ts
CHANGED
|
@@ -475,7 +475,10 @@ async function performHealthCheck() {
|
|
| 475 |
async function getCapabilities() {
|
| 476 |
const gateway = await isPortOpen(config.gatewayHost, config.gatewayPort)
|
| 477 |
|
| 478 |
-
const openclawHome =
|
|
|
|
|
|
|
|
|
|
| 479 |
|
| 480 |
const claudeProjectsPath = path.join(config.claudeHome, 'projects')
|
| 481 |
const claudeHome = existsSync(claudeProjectsPath)
|
|
|
|
| 475 |
async function getCapabilities() {
|
| 476 |
const gateway = await isPortOpen(config.gatewayHost, config.gatewayPort)
|
| 477 |
|
| 478 |
+
const openclawHome = Boolean(
|
| 479 |
+
(config.openclawStateDir && existsSync(config.openclawStateDir)) ||
|
| 480 |
+
(config.openclawConfigPath && existsSync(config.openclawConfigPath))
|
| 481 |
+
)
|
| 482 |
|
| 483 |
const claudeProjectsPath = path.join(config.claudeHome, 'projects')
|
| 484 |
const claudeHome = existsSync(claudeProjectsPath)
|
src/components/ErrorBoundary.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { Component, type ErrorInfo, type ReactNode } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface Props {
|
| 6 |
children: ReactNode
|
|
@@ -23,7 +26,7 @@ export class ErrorBoundary extends Component<Props, State> {
|
|
| 23 |
}
|
| 24 |
|
| 25 |
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
| 26 |
-
|
| 27 |
}
|
| 28 |
|
| 29 |
render() {
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { Component, type ErrorInfo, type ReactNode } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('ErrorBoundary')
|
| 7 |
|
| 8 |
interface Props {
|
| 9 |
children: ReactNode
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
| 29 |
+
log.error('Panel error:', error, errorInfo)
|
| 30 |
}
|
| 31 |
|
| 32 |
render() {
|
src/components/chat/chat-panel.tsx
CHANGED
|
@@ -3,10 +3,13 @@
|
|
| 3 |
import { useEffect, useCallback, useState, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
| 6 |
import { ConversationList } from './conversation-list'
|
| 7 |
import { MessageList } from './message-list'
|
| 8 |
import { ChatInput } from './chat-input'
|
| 9 |
|
|
|
|
|
|
|
| 10 |
export function ChatPanel() {
|
| 11 |
const {
|
| 12 |
chatPanelOpen,
|
|
@@ -52,7 +55,7 @@ export function ChatPanel() {
|
|
| 52 |
const data = await res.json()
|
| 53 |
if (data.agents) setAgents(data.agents)
|
| 54 |
} catch (err) {
|
| 55 |
-
|
| 56 |
}
|
| 57 |
}
|
| 58 |
if (chatPanelOpen) loadAgents()
|
|
@@ -67,7 +70,7 @@ export function ChatPanel() {
|
|
| 67 |
const data = await res.json()
|
| 68 |
if (data.messages) setChatMessages(data.messages)
|
| 69 |
} catch (err) {
|
| 70 |
-
|
| 71 |
}
|
| 72 |
}, [activeConversation, setChatMessages])
|
| 73 |
|
|
@@ -145,7 +148,7 @@ export function ChatPanel() {
|
|
| 145 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 146 |
}
|
| 147 |
} catch (err) {
|
| 148 |
-
|
| 149 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 150 |
}
|
| 151 |
}
|
|
|
|
| 3 |
import { useEffect, useCallback, useState, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
import { ConversationList } from './conversation-list'
|
| 8 |
import { MessageList } from './message-list'
|
| 9 |
import { ChatInput } from './chat-input'
|
| 10 |
|
| 11 |
+
const log = createClientLogger('ChatPanel')
|
| 12 |
+
|
| 13 |
export function ChatPanel() {
|
| 14 |
const {
|
| 15 |
chatPanelOpen,
|
|
|
|
| 55 |
const data = await res.json()
|
| 56 |
if (data.agents) setAgents(data.agents)
|
| 57 |
} catch (err) {
|
| 58 |
+
log.error('Failed to load agents:', err)
|
| 59 |
}
|
| 60 |
}
|
| 61 |
if (chatPanelOpen) loadAgents()
|
|
|
|
| 70 |
const data = await res.json()
|
| 71 |
if (data.messages) setChatMessages(data.messages)
|
| 72 |
} catch (err) {
|
| 73 |
+
log.error('Failed to load messages:', err)
|
| 74 |
}
|
| 75 |
}, [activeConversation, setChatMessages])
|
| 76 |
|
|
|
|
| 148 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 149 |
}
|
| 150 |
} catch (err) {
|
| 151 |
+
log.error('Failed to send message:', err)
|
| 152 |
updatePendingMessage(tempId, { pendingStatus: 'failed' })
|
| 153 |
}
|
| 154 |
}
|
src/components/chat/conversation-list.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl, Conversation, Agent } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
function timeAgo(timestamp: number): string {
|
| 8 |
const diff = Math.floor(Date.now() / 1000) - timestamp
|
|
@@ -64,7 +67,7 @@ export function ConversationList({ onNewConversation }: ConversationListProps) {
|
|
| 64 |
)
|
| 65 |
}
|
| 66 |
} catch (err) {
|
| 67 |
-
|
| 68 |
}
|
| 69 |
}, [setConversations])
|
| 70 |
|
|
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl, Conversation, Agent } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('ConversationList')
|
| 9 |
|
| 10 |
function timeAgo(timestamp: number): string {
|
| 11 |
const diff = Math.floor(Date.now() / 1000) - timestamp
|
|
|
|
| 67 |
)
|
| 68 |
}
|
| 69 |
} catch (err) {
|
| 70 |
+
log.error('Failed to load conversations:', err)
|
| 71 |
}
|
| 72 |
}, [setConversations])
|
| 73 |
|
src/components/dashboard/sidebar.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useEffect, useState } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useNavigateToPanel } from '@/lib/navigation'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
interface MenuItem {
|
| 8 |
id: string
|
|
@@ -36,7 +39,7 @@ export function Sidebar() {
|
|
| 36 |
fetch('/api/status?action=overview')
|
| 37 |
.then(res => res.json())
|
| 38 |
.then(data => setSystemStats(data))
|
| 39 |
-
.catch(err =>
|
| 40 |
}, [])
|
| 41 |
|
| 42 |
const activeSessions = sessions.filter(s => s.active).length
|
|
|
|
| 3 |
import { useEffect, useState } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useNavigateToPanel } from '@/lib/navigation'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('Sidebar')
|
| 9 |
|
| 10 |
interface MenuItem {
|
| 11 |
id: string
|
|
|
|
| 39 |
fetch('/api/status?action=overview')
|
| 40 |
.then(res => res.json())
|
| 41 |
.then(data => setSystemStats(data))
|
| 42 |
+
.catch(err => log.error('Failed to fetch system status:', err))
|
| 43 |
}, [])
|
| 44 |
|
| 45 |
const activeSessions = sessions.filter(s => s.active).length
|
src/components/panels/agent-cost-panel.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
|
|
|
| 4 |
import {
|
| 5 |
PieChart, Pie, Cell, LineChart, Line, XAxis, YAxis, CartesianGrid,
|
| 6 |
Tooltip, Legend, ResponsiveContainer,
|
| 7 |
} from 'recharts'
|
| 8 |
|
|
|
|
|
|
|
| 9 |
interface AgentCostData {
|
| 10 |
stats: { totalTokens: number; totalCost: number; requestCount: number; avgTokensPerRequest: number; avgCostPerRequest: number }
|
| 11 |
models: Record<string, { totalTokens: number; totalCost: number; requestCount: number }>
|
|
@@ -34,7 +37,7 @@ export function AgentCostPanel() {
|
|
| 34 |
const json = await res.json()
|
| 35 |
setData(json)
|
| 36 |
} catch (err) {
|
| 37 |
-
|
| 38 |
} finally {
|
| 39 |
setIsLoading(false)
|
| 40 |
}
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
import {
|
| 6 |
PieChart, Pie, Cell, LineChart, Line, XAxis, YAxis, CartesianGrid,
|
| 7 |
Tooltip, Legend, ResponsiveContainer,
|
| 8 |
} from 'recharts'
|
| 9 |
|
| 10 |
+
const log = createClientLogger('AgentCostPanel')
|
| 11 |
+
|
| 12 |
interface AgentCostData {
|
| 13 |
stats: { totalTokens: number; totalCost: number; requestCount: number; avgTokensPerRequest: number; avgCostPerRequest: number }
|
| 14 |
models: Record<string, { totalTokens: number; totalCost: number; requestCount: number }>
|
|
|
|
| 37 |
const json = await res.json()
|
| 38 |
setData(json)
|
| 39 |
} catch (err) {
|
| 40 |
+
log.error('Failed to load agent costs:', err)
|
| 41 |
} finally {
|
| 42 |
setIsLoading(false)
|
| 43 |
}
|
src/components/panels/agent-detail-tabs.tsx
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
|
|
|
| 4 |
import Link from 'next/link'
|
| 5 |
|
|
|
|
|
|
|
| 6 |
interface Agent {
|
| 7 |
id: number
|
| 8 |
name: string
|
|
@@ -374,7 +377,7 @@ export function SoulTab({
|
|
| 374 |
setSelectedTemplate(templateName)
|
| 375 |
}
|
| 376 |
} catch (error) {
|
| 377 |
-
|
| 378 |
}
|
| 379 |
}
|
| 380 |
|
|
@@ -626,7 +629,7 @@ export function TasksTab({ agent }: { agent: Agent }) {
|
|
| 626 |
setTasks(data.tasks || [])
|
| 627 |
}
|
| 628 |
} catch (error) {
|
| 629 |
-
|
| 630 |
} finally {
|
| 631 |
setLoading(false)
|
| 632 |
}
|
|
@@ -725,7 +728,7 @@ export function ActivityTab({ agent }: { agent: Agent }) {
|
|
| 725 |
setActivities(data.activities || [])
|
| 726 |
}
|
| 727 |
} catch (error) {
|
| 728 |
-
|
| 729 |
} finally {
|
| 730 |
setLoading(false)
|
| 731 |
}
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
import Link from 'next/link'
|
| 6 |
|
| 7 |
+
const log = createClientLogger('AgentDetailTabs')
|
| 8 |
+
|
| 9 |
interface Agent {
|
| 10 |
id: number
|
| 11 |
name: string
|
|
|
|
| 377 |
setSelectedTemplate(templateName)
|
| 378 |
}
|
| 379 |
} catch (error) {
|
| 380 |
+
log.error('Failed to load template:', error)
|
| 381 |
}
|
| 382 |
}
|
| 383 |
|
|
|
|
| 629 |
setTasks(data.tasks || [])
|
| 630 |
}
|
| 631 |
} catch (error) {
|
| 632 |
+
log.error('Failed to fetch tasks:', error)
|
| 633 |
} finally {
|
| 634 |
setLoading(false)
|
| 635 |
}
|
|
|
|
| 728 |
setActivities(data.activities || [])
|
| 729 |
}
|
| 730 |
} catch (error) {
|
| 731 |
+
log.error('Failed to fetch activities:', error)
|
| 732 |
} finally {
|
| 733 |
setLoading(false)
|
| 734 |
}
|
src/components/panels/agent-spawn-panel.tsx
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface SpawnFormData {
|
| 7 |
task: string
|
|
@@ -33,7 +36,7 @@ export function AgentSpawnPanel() {
|
|
| 33 |
fetch('/api/spawn')
|
| 34 |
.then(res => res.json())
|
| 35 |
.then(data => setSpawnHistory(data.history || []))
|
| 36 |
-
.catch(err =>
|
| 37 |
}, [])
|
| 38 |
|
| 39 |
const handleSpawn = async () => {
|
|
@@ -95,7 +98,7 @@ export function AgentSpawnPanel() {
|
|
| 95 |
})
|
| 96 |
}
|
| 97 |
} catch (error) {
|
| 98 |
-
|
| 99 |
updateSpawnRequest(spawnId, {
|
| 100 |
status: 'failed',
|
| 101 |
error: error instanceof Error ? error.message : 'Network error'
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('AgentSpawnPanel')
|
| 8 |
|
| 9 |
interface SpawnFormData {
|
| 10 |
task: string
|
|
|
|
| 36 |
fetch('/api/spawn')
|
| 37 |
.then(res => res.json())
|
| 38 |
.then(data => setSpawnHistory(data.history || []))
|
| 39 |
+
.catch(err => log.error('Failed to load spawn history:', err))
|
| 40 |
}, [])
|
| 41 |
|
| 42 |
const handleSpawn = async () => {
|
|
|
|
| 98 |
})
|
| 99 |
}
|
| 100 |
} catch (error) {
|
| 101 |
+
log.error('Spawn error:', error)
|
| 102 |
updateSpawnRequest(spawnId, {
|
| 103 |
status: 'failed',
|
| 104 |
error: error instanceof Error ? error.message : 'Network error'
|
src/components/panels/agent-squad-panel-phase3.tsx
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
| 5 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 6 |
import {
|
| 7 |
OverviewTab,
|
|
@@ -13,6 +14,8 @@ import {
|
|
| 13 |
CreateAgentModal
|
| 14 |
} from './agent-detail-tabs'
|
| 15 |
|
|
|
|
|
|
|
| 16 |
interface Agent {
|
| 17 |
id: number
|
| 18 |
name: string
|
|
@@ -148,7 +151,7 @@ export function AgentSquadPanelPhase3() {
|
|
| 148 |
: agent
|
| 149 |
))
|
| 150 |
} catch (error) {
|
| 151 |
-
|
| 152 |
setError('Failed to update agent status')
|
| 153 |
}
|
| 154 |
}
|
|
@@ -171,7 +174,7 @@ export function AgentSquadPanelPhase3() {
|
|
| 171 |
|
| 172 |
await updateAgentStatus(agentName, 'idle', 'Manually woken via session')
|
| 173 |
} catch (error) {
|
| 174 |
-
|
| 175 |
setError('Failed to wake agent')
|
| 176 |
}
|
| 177 |
}
|
|
@@ -503,7 +506,7 @@ function AgentDetailModalPhase3({
|
|
| 503 |
setSoulTemplates(data.templates || [])
|
| 504 |
}
|
| 505 |
} catch (error) {
|
| 506 |
-
|
| 507 |
}
|
| 508 |
}
|
| 509 |
|
|
@@ -522,7 +525,7 @@ function AgentDetailModalPhase3({
|
|
| 522 |
setHeartbeatData(data)
|
| 523 |
}
|
| 524 |
} catch (error) {
|
| 525 |
-
|
| 526 |
} finally {
|
| 527 |
setLoadingHeartbeat(false)
|
| 528 |
}
|
|
@@ -544,7 +547,7 @@ function AgentDetailModalPhase3({
|
|
| 544 |
setEditing(false)
|
| 545 |
onUpdate()
|
| 546 |
} catch (error) {
|
| 547 |
-
|
| 548 |
}
|
| 549 |
}
|
| 550 |
|
|
@@ -564,7 +567,7 @@ function AgentDetailModalPhase3({
|
|
| 564 |
setFormData(prev => ({ ...prev, soul_content: content }))
|
| 565 |
onUpdate()
|
| 566 |
} catch (error) {
|
| 567 |
-
|
| 568 |
}
|
| 569 |
}
|
| 570 |
|
|
@@ -585,7 +588,7 @@ function AgentDetailModalPhase3({
|
|
| 585 |
setFormData(prev => ({ ...prev, working_memory: data.working_memory }))
|
| 586 |
onUpdate()
|
| 587 |
} catch (error) {
|
| 588 |
-
|
| 589 |
}
|
| 590 |
}
|
| 591 |
|
|
@@ -746,7 +749,7 @@ function QuickSpawnModal({
|
|
| 746 |
alert(result.error || 'Failed to spawn agent')
|
| 747 |
}
|
| 748 |
} catch (error) {
|
| 749 |
-
|
| 750 |
alert('Network error occurred')
|
| 751 |
} finally {
|
| 752 |
setIsSpawning(false)
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 7 |
import {
|
| 8 |
OverviewTab,
|
|
|
|
| 14 |
CreateAgentModal
|
| 15 |
} from './agent-detail-tabs'
|
| 16 |
|
| 17 |
+
const log = createClientLogger('AgentSquadPhase3')
|
| 18 |
+
|
| 19 |
interface Agent {
|
| 20 |
id: number
|
| 21 |
name: string
|
|
|
|
| 151 |
: agent
|
| 152 |
))
|
| 153 |
} catch (error) {
|
| 154 |
+
log.error('Failed to update agent status:', error)
|
| 155 |
setError('Failed to update agent status')
|
| 156 |
}
|
| 157 |
}
|
|
|
|
| 174 |
|
| 175 |
await updateAgentStatus(agentName, 'idle', 'Manually woken via session')
|
| 176 |
} catch (error) {
|
| 177 |
+
log.error('Failed to wake agent:', error)
|
| 178 |
setError('Failed to wake agent')
|
| 179 |
}
|
| 180 |
}
|
|
|
|
| 506 |
setSoulTemplates(data.templates || [])
|
| 507 |
}
|
| 508 |
} catch (error) {
|
| 509 |
+
log.error('Failed to load SOUL templates:', error)
|
| 510 |
}
|
| 511 |
}
|
| 512 |
|
|
|
|
| 525 |
setHeartbeatData(data)
|
| 526 |
}
|
| 527 |
} catch (error) {
|
| 528 |
+
log.error('Failed to perform heartbeat:', error)
|
| 529 |
} finally {
|
| 530 |
setLoadingHeartbeat(false)
|
| 531 |
}
|
|
|
|
| 547 |
setEditing(false)
|
| 548 |
onUpdate()
|
| 549 |
} catch (error) {
|
| 550 |
+
log.error('Failed to update agent:', error)
|
| 551 |
}
|
| 552 |
}
|
| 553 |
|
|
|
|
| 567 |
setFormData(prev => ({ ...prev, soul_content: content }))
|
| 568 |
onUpdate()
|
| 569 |
} catch (error) {
|
| 570 |
+
log.error('Failed to update SOUL:', error)
|
| 571 |
}
|
| 572 |
}
|
| 573 |
|
|
|
|
| 588 |
setFormData(prev => ({ ...prev, working_memory: data.working_memory }))
|
| 589 |
onUpdate()
|
| 590 |
} catch (error) {
|
| 591 |
+
log.error('Failed to update memory:', error)
|
| 592 |
}
|
| 593 |
}
|
| 594 |
|
|
|
|
| 749 |
alert(result.error || 'Failed to spawn agent')
|
| 750 |
}
|
| 751 |
} catch (error) {
|
| 752 |
+
log.error('Spawn failed:', error)
|
| 753 |
alert('Network error occurred')
|
| 754 |
} finally {
|
| 755 |
setIsSpawning(false)
|
src/components/panels/agent-squad-panel.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface Agent {
|
| 6 |
id: number
|
|
@@ -103,7 +106,7 @@ export function AgentSquadPanel() {
|
|
| 103 |
: agent
|
| 104 |
))
|
| 105 |
} catch (error) {
|
| 106 |
-
|
| 107 |
setError('Failed to update agent status')
|
| 108 |
}
|
| 109 |
}
|
|
@@ -355,7 +358,7 @@ function AgentDetailModal({
|
|
| 355 |
setEditing(false)
|
| 356 |
onUpdate()
|
| 357 |
} catch (error) {
|
| 358 |
-
|
| 359 |
}
|
| 360 |
}
|
| 361 |
|
|
@@ -540,7 +543,7 @@ function CreateAgentModal({
|
|
| 540 |
onCreated()
|
| 541 |
onClose()
|
| 542 |
} catch (error) {
|
| 543 |
-
|
| 544 |
}
|
| 545 |
}
|
| 546 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('AgentSquadPanel')
|
| 7 |
|
| 8 |
interface Agent {
|
| 9 |
id: number
|
|
|
|
| 106 |
: agent
|
| 107 |
))
|
| 108 |
} catch (error) {
|
| 109 |
+
log.error('Failed to update agent status:', error)
|
| 110 |
setError('Failed to update agent status')
|
| 111 |
}
|
| 112 |
}
|
|
|
|
| 358 |
setEditing(false)
|
| 359 |
onUpdate()
|
| 360 |
} catch (error) {
|
| 361 |
+
log.error('Failed to update agent:', error)
|
| 362 |
}
|
| 363 |
}
|
| 364 |
|
|
|
|
| 543 |
onCreated()
|
| 544 |
onClose()
|
| 545 |
} catch (error) {
|
| 546 |
+
log.error('Error creating agent:', error)
|
| 547 |
}
|
| 548 |
}
|
| 549 |
|
src/components/panels/cron-management-panel.tsx
CHANGED
|
@@ -2,6 +2,8 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback, useMemo } from 'react'
|
| 4 |
import { useMissionControl, CronJob } from '@/store'
|
|
|
|
|
|
|
| 5 |
import { buildDayKey, getCronOccurrences } from '@/lib/cron-occurrences'
|
| 6 |
|
| 7 |
interface NewJobForm {
|
|
@@ -92,7 +94,7 @@ export function CronManagementPanel() {
|
|
| 92 |
const data = await response.json()
|
| 93 |
setCronJobs(data.jobs || [])
|
| 94 |
} catch (error) {
|
| 95 |
-
|
| 96 |
} finally {
|
| 97 |
setIsLoading(false)
|
| 98 |
}
|
|
@@ -126,7 +128,7 @@ export function CronManagementPanel() {
|
|
| 126 |
const data = await response.json()
|
| 127 |
setJobLogs(data.logs || [])
|
| 128 |
} catch (error) {
|
| 129 |
-
|
| 130 |
setJobLogs([])
|
| 131 |
}
|
| 132 |
}
|
|
@@ -150,7 +152,7 @@ export function CronManagementPanel() {
|
|
| 150 |
alert(`Failed to toggle job: ${error.error}`)
|
| 151 |
}
|
| 152 |
} catch (error) {
|
| 153 |
-
|
| 154 |
alert('Network error occurred')
|
| 155 |
}
|
| 156 |
}
|
|
@@ -175,7 +177,7 @@ export function CronManagementPanel() {
|
|
| 175 |
alert(`Job failed:\n${result.error}\n${result.stderr}`)
|
| 176 |
}
|
| 177 |
} catch (error) {
|
| 178 |
-
|
| 179 |
alert('Network error occurred')
|
| 180 |
}
|
| 181 |
}
|
|
@@ -214,7 +216,7 @@ export function CronManagementPanel() {
|
|
| 214 |
alert(`Failed to add job: ${error.error}`)
|
| 215 |
}
|
| 216 |
} catch (error) {
|
| 217 |
-
|
| 218 |
alert('Network error occurred')
|
| 219 |
}
|
| 220 |
}
|
|
@@ -244,7 +246,7 @@ export function CronManagementPanel() {
|
|
| 244 |
alert(`Failed to remove job: ${error.error}`)
|
| 245 |
}
|
| 246 |
} catch (error) {
|
| 247 |
-
|
| 248 |
alert('Network error occurred')
|
| 249 |
}
|
| 250 |
}
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback, useMemo } from 'react'
|
| 4 |
import { useMissionControl, CronJob } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
const log = createClientLogger('CronManagement')
|
| 7 |
import { buildDayKey, getCronOccurrences } from '@/lib/cron-occurrences'
|
| 8 |
|
| 9 |
interface NewJobForm {
|
|
|
|
| 94 |
const data = await response.json()
|
| 95 |
setCronJobs(data.jobs || [])
|
| 96 |
} catch (error) {
|
| 97 |
+
log.error('Failed to load cron jobs:', error)
|
| 98 |
} finally {
|
| 99 |
setIsLoading(false)
|
| 100 |
}
|
|
|
|
| 128 |
const data = await response.json()
|
| 129 |
setJobLogs(data.logs || [])
|
| 130 |
} catch (error) {
|
| 131 |
+
log.error('Failed to load job logs:', error)
|
| 132 |
setJobLogs([])
|
| 133 |
}
|
| 134 |
}
|
|
|
|
| 152 |
alert(`Failed to toggle job: ${error.error}`)
|
| 153 |
}
|
| 154 |
} catch (error) {
|
| 155 |
+
log.error('Failed to toggle job:', error)
|
| 156 |
alert('Network error occurred')
|
| 157 |
}
|
| 158 |
}
|
|
|
|
| 177 |
alert(`Job failed:\n${result.error}\n${result.stderr}`)
|
| 178 |
}
|
| 179 |
} catch (error) {
|
| 180 |
+
log.error('Failed to trigger job:', error)
|
| 181 |
alert('Network error occurred')
|
| 182 |
}
|
| 183 |
}
|
|
|
|
| 216 |
alert(`Failed to add job: ${error.error}`)
|
| 217 |
}
|
| 218 |
} catch (error) {
|
| 219 |
+
log.error('Failed to add job:', error)
|
| 220 |
alert('Network error occurred')
|
| 221 |
}
|
| 222 |
}
|
|
|
|
| 246 |
alert(`Failed to remove job: ${error.error}`)
|
| 247 |
}
|
| 248 |
} catch (error) {
|
| 249 |
+
log.error('Failed to remove job:', error)
|
| 250 |
alert('Network error occurred')
|
| 251 |
}
|
| 252 |
}
|
src/components/panels/gateway-config-panel.tsx
CHANGED
|
@@ -113,7 +113,7 @@ export function GatewayConfigPanel() {
|
|
| 113 |
<div className="p-6">
|
| 114 |
<div className="bg-destructive/10 text-destructive rounded-lg p-4 text-sm">{error}</div>
|
| 115 |
<p className="text-xs text-muted-foreground mt-2">
|
| 116 |
-
Ensure
|
| 117 |
</p>
|
| 118 |
</div>
|
| 119 |
)
|
|
|
|
| 113 |
<div className="p-6">
|
| 114 |
<div className="bg-destructive/10 text-destructive rounded-lg p-4 text-sm">{error}</div>
|
| 115 |
<p className="text-xs text-muted-foreground mt-2">
|
| 116 |
+
Ensure `OPENCLAW_CONFIG_PATH` (or `OPENCLAW_STATE_DIR`) is set and the config file exists.
|
| 117 |
</p>
|
| 118 |
</div>
|
| 119 |
)
|
src/components/panels/log-viewer-panel.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useState, useEffect, useRef, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
interface LogFilters {
|
| 8 |
level?: string
|
|
@@ -36,7 +39,7 @@ export function LogViewerPanel() {
|
|
| 36 |
}, [logFilters])
|
| 37 |
|
| 38 |
const loadLogs = useCallback(async (tail = false) => {
|
| 39 |
-
|
| 40 |
setIsLoading(!tail) // Only show loading for initial load, not for tailing
|
| 41 |
|
| 42 |
try {
|
|
@@ -53,37 +56,37 @@ export function LogViewerPanel() {
|
|
| 53 |
...(tail && currentLogs.length > 0 && { since: currentLogs[0]?.timestamp.toString() })
|
| 54 |
})
|
| 55 |
|
| 56 |
-
|
| 57 |
const response = await fetch(`/api/logs?${params}`)
|
| 58 |
const data = await response.json()
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
if (data.logs && data.logs.length > 0) {
|
| 63 |
if (tail) {
|
| 64 |
// Add new logs for tail mode - prepend to existing logs
|
| 65 |
let newLogsAdded = 0
|
| 66 |
const existingIds = new Set((currentLogs || []).map((l: any) => l?.id).filter(Boolean))
|
| 67 |
-
data.logs.reverse().forEach((
|
| 68 |
-
if (existingIds.has(
|
| 69 |
-
addLog(
|
| 70 |
newLogsAdded++
|
| 71 |
})
|
| 72 |
-
|
| 73 |
} else {
|
| 74 |
// Replace logs for initial load or refresh
|
| 75 |
-
|
| 76 |
clearLogs() // Clear existing logs
|
| 77 |
-
data.logs.reverse().forEach((
|
| 78 |
-
addLog(
|
| 79 |
})
|
| 80 |
-
|
| 81 |
}
|
| 82 |
} else {
|
| 83 |
-
|
| 84 |
}
|
| 85 |
} catch (error) {
|
| 86 |
-
|
| 87 |
} finally {
|
| 88 |
setIsLoading(false)
|
| 89 |
}
|
|
@@ -95,13 +98,13 @@ export function LogViewerPanel() {
|
|
| 95 |
const data = await response.json()
|
| 96 |
setAvailableSources(data.sources || [])
|
| 97 |
} catch (error) {
|
| 98 |
-
|
| 99 |
}
|
| 100 |
}, [])
|
| 101 |
|
| 102 |
// Load initial logs and sources
|
| 103 |
useEffect(() => {
|
| 104 |
-
|
| 105 |
loadLogs()
|
| 106 |
loadSources()
|
| 107 |
}, [loadLogs, loadSources])
|
|
@@ -154,16 +157,16 @@ export function LogViewerPanel() {
|
|
| 154 |
}
|
| 155 |
}
|
| 156 |
|
| 157 |
-
const filteredLogs = logs.filter(
|
| 158 |
-
if (logFilters.level &&
|
| 159 |
-
if (logFilters.source &&
|
| 160 |
-
if (logFilters.search && !
|
| 161 |
-
if (logFilters.session && (!
|
| 162 |
return true
|
| 163 |
})
|
| 164 |
|
| 165 |
// Debug logging
|
| 166 |
-
|
| 167 |
|
| 168 |
return (
|
| 169 |
<div className="flex flex-col h-full p-6 space-y-4">
|
|
|
|
| 3 |
import { useState, useEffect, useRef, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('LogViewer')
|
| 9 |
|
| 10 |
interface LogFilters {
|
| 11 |
level?: string
|
|
|
|
| 39 |
}, [logFilters])
|
| 40 |
|
| 41 |
const loadLogs = useCallback(async (tail = false) => {
|
| 42 |
+
log.debug(`Loading logs (tail=${tail})`)
|
| 43 |
setIsLoading(!tail) // Only show loading for initial load, not for tailing
|
| 44 |
|
| 45 |
try {
|
|
|
|
| 56 |
...(tail && currentLogs.length > 0 && { since: currentLogs[0]?.timestamp.toString() })
|
| 57 |
})
|
| 58 |
|
| 59 |
+
log.debug(`Fetching /api/logs?${params}`)
|
| 60 |
const response = await fetch(`/api/logs?${params}`)
|
| 61 |
const data = await response.json()
|
| 62 |
|
| 63 |
+
log.debug(`Received ${data.logs?.length || 0} logs from API`)
|
| 64 |
|
| 65 |
if (data.logs && data.logs.length > 0) {
|
| 66 |
if (tail) {
|
| 67 |
// Add new logs for tail mode - prepend to existing logs
|
| 68 |
let newLogsAdded = 0
|
| 69 |
const existingIds = new Set((currentLogs || []).map((l: any) => l?.id).filter(Boolean))
|
| 70 |
+
data.logs.reverse().forEach((entry: any) => {
|
| 71 |
+
if (existingIds.has(entry?.id)) return
|
| 72 |
+
addLog(entry)
|
| 73 |
newLogsAdded++
|
| 74 |
})
|
| 75 |
+
log.debug(`Added ${newLogsAdded} new logs (tail mode)`)
|
| 76 |
} else {
|
| 77 |
// Replace logs for initial load or refresh
|
| 78 |
+
log.debug(`Clearing existing logs and loading ${data.logs.length} logs`)
|
| 79 |
clearLogs() // Clear existing logs
|
| 80 |
+
data.logs.reverse().forEach((entry: any) => {
|
| 81 |
+
addLog(entry)
|
| 82 |
})
|
| 83 |
+
log.debug(`Successfully added ${data.logs.length} logs to store`)
|
| 84 |
}
|
| 85 |
} else {
|
| 86 |
+
log.debug('No logs received from API')
|
| 87 |
}
|
| 88 |
} catch (error) {
|
| 89 |
+
log.error('Failed to load logs:', error)
|
| 90 |
} finally {
|
| 91 |
setIsLoading(false)
|
| 92 |
}
|
|
|
|
| 98 |
const data = await response.json()
|
| 99 |
setAvailableSources(data.sources || [])
|
| 100 |
} catch (error) {
|
| 101 |
+
log.error('Failed to load log sources:', error)
|
| 102 |
}
|
| 103 |
}, [])
|
| 104 |
|
| 105 |
// Load initial logs and sources
|
| 106 |
useEffect(() => {
|
| 107 |
+
log.debug('Initial load started')
|
| 108 |
loadLogs()
|
| 109 |
loadSources()
|
| 110 |
}, [loadLogs, loadSources])
|
|
|
|
| 157 |
}
|
| 158 |
}
|
| 159 |
|
| 160 |
+
const filteredLogs = logs.filter(entry => {
|
| 161 |
+
if (logFilters.level && entry.level !== logFilters.level) return false
|
| 162 |
+
if (logFilters.source && entry.source !== logFilters.source) return false
|
| 163 |
+
if (logFilters.search && !entry.message.toLowerCase().includes(logFilters.search.toLowerCase())) return false
|
| 164 |
+
if (logFilters.session && (!entry.session || !entry.session.includes(logFilters.session))) return false
|
| 165 |
return true
|
| 166 |
})
|
| 167 |
|
| 168 |
// Debug logging
|
| 169 |
+
log.debug(`Store has ${logs.length} logs, filtered to ${filteredLogs.length}`)
|
| 170 |
|
| 171 |
return (
|
| 172 |
<div className="flex flex-col h-full p-6 space-y-4">
|
src/components/panels/memory-browser-panel.tsx
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import React, { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface MemoryFile {
|
| 7 |
path: string
|
|
@@ -46,7 +49,7 @@ export function MemoryBrowserPanel() {
|
|
| 46 |
// Auto-expand some common directories
|
| 47 |
setExpandedFolders(new Set(['daily', 'knowledge']))
|
| 48 |
} catch (error) {
|
| 49 |
-
|
| 50 |
} finally {
|
| 51 |
setIsLoading(false)
|
| 52 |
}
|
|
@@ -83,7 +86,7 @@ export function MemoryBrowserPanel() {
|
|
| 83 |
alert(data.error || 'Failed to load file content')
|
| 84 |
}
|
| 85 |
} catch (error) {
|
| 86 |
-
|
| 87 |
alert('Network error occurred')
|
| 88 |
} finally {
|
| 89 |
setIsLoading(false)
|
|
@@ -99,7 +102,7 @@ export function MemoryBrowserPanel() {
|
|
| 99 |
const data = await response.json()
|
| 100 |
setSearchResults(data.results || [])
|
| 101 |
} catch (error) {
|
| 102 |
-
|
| 103 |
setSearchResults([])
|
| 104 |
} finally {
|
| 105 |
setIsSearching(false)
|
|
@@ -165,7 +168,7 @@ export function MemoryBrowserPanel() {
|
|
| 165 |
alert(data.error || 'Failed to save file')
|
| 166 |
}
|
| 167 |
} catch (error) {
|
| 168 |
-
|
| 169 |
alert('Network error occurred')
|
| 170 |
} finally {
|
| 171 |
setIsSaving(false)
|
|
@@ -192,7 +195,7 @@ export function MemoryBrowserPanel() {
|
|
| 192 |
alert(data.error || 'Failed to create file')
|
| 193 |
}
|
| 194 |
} catch (error) {
|
| 195 |
-
|
| 196 |
alert('Network error occurred')
|
| 197 |
}
|
| 198 |
}
|
|
@@ -220,7 +223,7 @@ export function MemoryBrowserPanel() {
|
|
| 220 |
alert(data.error || 'Failed to delete file')
|
| 221 |
}
|
| 222 |
} catch (error) {
|
| 223 |
-
|
| 224 |
alert('Network error occurred')
|
| 225 |
}
|
| 226 |
}
|
|
@@ -271,6 +274,30 @@ export function MemoryBrowserPanel() {
|
|
| 271 |
))
|
| 272 |
}
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
const renderMarkdown = (content: string) => {
|
| 275 |
// Improved markdown rendering with proper line handling
|
| 276 |
const lines = content.split('\n')
|
|
@@ -323,20 +350,10 @@ export function MemoryBrowserPanel() {
|
|
| 323 |
elements.push(<div key={`${i}-space`} className="mb-2"></div>)
|
| 324 |
} else if (trimmedLine.length > 0) {
|
| 325 |
if (inList) inList = false
|
| 326 |
-
// Handle inline formatting — escape HTML entities first to prevent XSS
|
| 327 |
-
let content = trimmedLine
|
| 328 |
-
.replace(/&/g, '&')
|
| 329 |
-
.replace(/</g, '<')
|
| 330 |
-
.replace(/>/g, '>')
|
| 331 |
-
.replace(/"/g, '"')
|
| 332 |
-
.replace(/'/g, ''')
|
| 333 |
-
// Simple bold formatting
|
| 334 |
-
content = content.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 335 |
-
// Simple italic formatting
|
| 336 |
-
content = content.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 337 |
-
|
| 338 |
elements.push(
|
| 339 |
-
<p key={`${i}-p`} className="mb-2"
|
|
|
|
|
|
|
| 340 |
)
|
| 341 |
}
|
| 342 |
}
|
|
|
|
| 2 |
|
| 3 |
import React, { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('MemoryBrowser')
|
| 8 |
|
| 9 |
interface MemoryFile {
|
| 10 |
path: string
|
|
|
|
| 49 |
// Auto-expand some common directories
|
| 50 |
setExpandedFolders(new Set(['daily', 'knowledge']))
|
| 51 |
} catch (error) {
|
| 52 |
+
log.error('Failed to load file tree:', error)
|
| 53 |
} finally {
|
| 54 |
setIsLoading(false)
|
| 55 |
}
|
|
|
|
| 86 |
alert(data.error || 'Failed to load file content')
|
| 87 |
}
|
| 88 |
} catch (error) {
|
| 89 |
+
log.error('Failed to load file content:', error)
|
| 90 |
alert('Network error occurred')
|
| 91 |
} finally {
|
| 92 |
setIsLoading(false)
|
|
|
|
| 102 |
const data = await response.json()
|
| 103 |
setSearchResults(data.results || [])
|
| 104 |
} catch (error) {
|
| 105 |
+
log.error('Search failed:', error)
|
| 106 |
setSearchResults([])
|
| 107 |
} finally {
|
| 108 |
setIsSearching(false)
|
|
|
|
| 168 |
alert(data.error || 'Failed to save file')
|
| 169 |
}
|
| 170 |
} catch (error) {
|
| 171 |
+
log.error('Failed to save file:', error)
|
| 172 |
alert('Network error occurred')
|
| 173 |
} finally {
|
| 174 |
setIsSaving(false)
|
|
|
|
| 195 |
alert(data.error || 'Failed to create file')
|
| 196 |
}
|
| 197 |
} catch (error) {
|
| 198 |
+
log.error('Failed to create file:', error)
|
| 199 |
alert('Network error occurred')
|
| 200 |
}
|
| 201 |
}
|
|
|
|
| 223 |
alert(data.error || 'Failed to delete file')
|
| 224 |
}
|
| 225 |
} catch (error) {
|
| 226 |
+
log.error('Failed to delete file:', error)
|
| 227 |
alert('Network error occurred')
|
| 228 |
}
|
| 229 |
}
|
|
|
|
| 274 |
))
|
| 275 |
}
|
| 276 |
|
| 277 |
+
const renderInlineFormatting = (text: string): React.ReactNode[] => {
|
| 278 |
+
const parts: React.ReactNode[] = []
|
| 279 |
+
const regex = /(\*\*.*?\*\*|\*.*?\*)/g
|
| 280 |
+
let lastIndex = 0
|
| 281 |
+
let match: RegExpExecArray | null
|
| 282 |
+
let key = 0
|
| 283 |
+
while ((match = regex.exec(text)) !== null) {
|
| 284 |
+
if (match.index > lastIndex) {
|
| 285 |
+
parts.push(text.slice(lastIndex, match.index))
|
| 286 |
+
}
|
| 287 |
+
const m = match[0]
|
| 288 |
+
if (m.startsWith('**') && m.endsWith('**')) {
|
| 289 |
+
parts.push(<strong key={key++}>{m.slice(2, -2)}</strong>)
|
| 290 |
+
} else if (m.startsWith('*') && m.endsWith('*')) {
|
| 291 |
+
parts.push(<em key={key++}>{m.slice(1, -1)}</em>)
|
| 292 |
+
}
|
| 293 |
+
lastIndex = regex.lastIndex
|
| 294 |
+
}
|
| 295 |
+
if (lastIndex < text.length) {
|
| 296 |
+
parts.push(text.slice(lastIndex))
|
| 297 |
+
}
|
| 298 |
+
return parts
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
const renderMarkdown = (content: string) => {
|
| 302 |
// Improved markdown rendering with proper line handling
|
| 303 |
const lines = content.split('\n')
|
|
|
|
| 350 |
elements.push(<div key={`${i}-space`} className="mb-2"></div>)
|
| 351 |
} else if (trimmedLine.length > 0) {
|
| 352 |
if (inList) inList = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
elements.push(
|
| 354 |
+
<p key={`${i}-p`} className="mb-2">
|
| 355 |
+
{renderInlineFormatting(trimmedLine)}
|
| 356 |
+
</p>
|
| 357 |
)
|
| 358 |
}
|
| 359 |
}
|
src/components/panels/session-details-panel.tsx
CHANGED
|
@@ -3,6 +3,9 @@
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
export function SessionDetailsPanel() {
|
| 8 |
const {
|
|
@@ -20,7 +23,7 @@ export function SessionDetailsPanel() {
|
|
| 20 |
const data = await response.json()
|
| 21 |
setSessions(data.sessions || data)
|
| 22 |
} catch (error) {
|
| 23 |
-
|
| 24 |
}
|
| 25 |
}, [setSessions])
|
| 26 |
|
|
|
|
| 3 |
import { useState, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 6 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 7 |
+
|
| 8 |
+
const log = createClientLogger('SessionDetails')
|
| 9 |
|
| 10 |
export function SessionDetailsPanel() {
|
| 11 |
const {
|
|
|
|
| 23 |
const data = await response.json()
|
| 24 |
setSessions(data.sessions || data)
|
| 25 |
} catch (error) {
|
| 26 |
+
log.error('Failed to load sessions:', error)
|
| 27 |
}
|
| 28 |
}, [setSessions])
|
| 29 |
|
src/components/panels/standup-panel.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
interface StandupReport {
|
| 6 |
date: string
|
|
@@ -133,7 +136,7 @@ export function StandupPanel() {
|
|
| 133 |
const data = await response.json()
|
| 134 |
setStandupHistory(data.history || [])
|
| 135 |
} catch (err) {
|
| 136 |
-
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 5 |
+
|
| 6 |
+
const log = createClientLogger('StandupPanel')
|
| 7 |
|
| 8 |
interface StandupReport {
|
| 9 |
date: string
|
|
|
|
| 136 |
const data = await response.json()
|
| 137 |
setStandupHistory(data.history || [])
|
| 138 |
} catch (err) {
|
| 139 |
+
log.error('Failed to fetch standup history:', err)
|
| 140 |
}
|
| 141 |
}
|
| 142 |
|
src/components/panels/task-board-panel.tsx
CHANGED
|
@@ -4,10 +4,16 @@ import { useState, useEffect, useCallback, useRef } from 'react'
|
|
| 4 |
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
|
| 5 |
import { useMissionControl } from '@/store'
|
| 6 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
|
|
|
|
|
|
|
|
|
| 7 |
import { useFocusTrap } from '@/lib/use-focus-trap'
|
|
|
|
| 8 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 9 |
import { MarkdownRenderer } from '@/components/markdown-renderer'
|
| 10 |
|
|
|
|
|
|
|
| 11 |
interface Task {
|
| 12 |
id: number
|
| 13 |
title: string
|
|
@@ -1024,7 +1030,7 @@ function CreateTaskModal({
|
|
| 1024 |
onCreated()
|
| 1025 |
onClose()
|
| 1026 |
} catch (error) {
|
| 1027 |
-
|
| 1028 |
}
|
| 1029 |
}
|
| 1030 |
|
|
@@ -1193,7 +1199,7 @@ function EditTaskModal({
|
|
| 1193 |
|
| 1194 |
onUpdated()
|
| 1195 |
} catch (error) {
|
| 1196 |
-
|
| 1197 |
}
|
| 1198 |
}
|
| 1199 |
|
|
|
|
| 4 |
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
|
| 5 |
import { useMissionControl } from '@/store'
|
| 6 |
import { useSmartPoll } from '@/lib/use-smart-poll'
|
| 7 |
+
|
| 8 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 9 |
+
|
| 10 |
import { useFocusTrap } from '@/lib/use-focus-trap'
|
| 11 |
+
|
| 12 |
import { AgentAvatar } from '@/components/ui/agent-avatar'
|
| 13 |
import { MarkdownRenderer } from '@/components/markdown-renderer'
|
| 14 |
|
| 15 |
+
const log = createClientLogger('TaskBoard')
|
| 16 |
+
|
| 17 |
interface Task {
|
| 18 |
id: number
|
| 19 |
title: string
|
|
|
|
| 1030 |
onCreated()
|
| 1031 |
onClose()
|
| 1032 |
} catch (error) {
|
| 1033 |
+
log.error('Error creating task:', error)
|
| 1034 |
}
|
| 1035 |
}
|
| 1036 |
|
|
|
|
| 1199 |
|
| 1200 |
onUpdated()
|
| 1201 |
} catch (error) {
|
| 1202 |
+
log.error('Error updating task:', error)
|
| 1203 |
}
|
| 1204 |
}
|
| 1205 |
|
src/components/panels/token-dashboard-panel.tsx
CHANGED
|
@@ -2,8 +2,11 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
| 5 |
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, PieChart, Pie, Cell } from 'recharts'
|
| 6 |
|
|
|
|
|
|
|
| 7 |
interface UsageStats {
|
| 8 |
summary: {
|
| 9 |
totalTokens: number
|
|
@@ -39,7 +42,7 @@ export function TokenDashboardPanel() {
|
|
| 39 |
const data = await response.json()
|
| 40 |
setUsageStats(data)
|
| 41 |
} catch (error) {
|
| 42 |
-
|
| 43 |
} finally {
|
| 44 |
setIsLoading(false)
|
| 45 |
}
|
|
@@ -51,7 +54,7 @@ export function TokenDashboardPanel() {
|
|
| 51 |
const data = await response.json()
|
| 52 |
setTrendData(data)
|
| 53 |
} catch (error) {
|
| 54 |
-
|
| 55 |
}
|
| 56 |
}, [selectedTimeframe])
|
| 57 |
|
|
@@ -80,7 +83,7 @@ export function TokenDashboardPanel() {
|
|
| 80 |
window.URL.revokeObjectURL(url)
|
| 81 |
document.body.removeChild(a)
|
| 82 |
} catch (error) {
|
| 83 |
-
|
| 84 |
alert('Export failed: ' + error)
|
| 85 |
} finally {
|
| 86 |
setIsExporting(false)
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect, useCallback } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, PieChart, Pie, Cell } from 'recharts'
|
| 7 |
|
| 8 |
+
const log = createClientLogger('TokenDashboard')
|
| 9 |
+
|
| 10 |
interface UsageStats {
|
| 11 |
summary: {
|
| 12 |
totalTokens: number
|
|
|
|
| 42 |
const data = await response.json()
|
| 43 |
setUsageStats(data)
|
| 44 |
} catch (error) {
|
| 45 |
+
log.error('Failed to load usage stats:', error)
|
| 46 |
} finally {
|
| 47 |
setIsLoading(false)
|
| 48 |
}
|
|
|
|
| 54 |
const data = await response.json()
|
| 55 |
setTrendData(data)
|
| 56 |
} catch (error) {
|
| 57 |
+
log.error('Failed to load trend data:', error)
|
| 58 |
}
|
| 59 |
}, [selectedTimeframe])
|
| 60 |
|
|
|
|
| 83 |
window.URL.revokeObjectURL(url)
|
| 84 |
document.body.removeChild(a)
|
| 85 |
} catch (error) {
|
| 86 |
+
log.error('Export failed:', error)
|
| 87 |
alert('Export failed: ' + error)
|
| 88 |
} finally {
|
| 89 |
setIsExporting(false)
|
src/lib/agent-sync.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
import { config } from './config'
|
| 9 |
import { getDatabase, db_helpers, logAuditEvent } from './db'
|
| 10 |
import { eventBus } from './event-bus'
|
| 11 |
-
import { join } from 'path'
|
| 12 |
import { existsSync, readFileSync } from 'fs'
|
| 13 |
import { resolveWithin } from './paths'
|
| 14 |
import { logger } from './logger'
|
|
@@ -127,15 +127,22 @@ function parseToolsFromFile(content: string): { allow?: string[]; raw?: string }
|
|
| 127 |
}
|
| 128 |
|
| 129 |
function getConfigPath(): string | null {
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
/** Safely read a file from an agent's workspace directory */
|
| 135 |
function readWorkspaceFile(workspace: string | undefined, filename: string): string | null {
|
| 136 |
-
if (!workspace
|
| 137 |
try {
|
| 138 |
-
const safeWorkspace =
|
| 139 |
const safePath = resolveWithin(safeWorkspace, filename)
|
| 140 |
if (existsSync(safePath)) {
|
| 141 |
return readFileSync(safePath, 'utf-8')
|
|
@@ -173,7 +180,7 @@ export function enrichAgentConfigFromWorkspace(configData: any): any {
|
|
| 173 |
/** Read and parse openclaw.json agents list */
|
| 174 |
async function readOpenClawAgents(): Promise<OpenClawAgent[]> {
|
| 175 |
const configPath = getConfigPath()
|
| 176 |
-
if (!configPath) throw new Error('
|
| 177 |
|
| 178 |
const { readFile } = require('fs/promises')
|
| 179 |
const raw = await readFile(configPath, 'utf-8')
|
|
@@ -334,7 +341,7 @@ export async function previewSyncDiff(): Promise<SyncDiff> {
|
|
| 334 |
/** Write an agent config back to openclaw.json agents.list */
|
| 335 |
export async function writeAgentToConfig(agentConfig: any): Promise<void> {
|
| 336 |
const configPath = getConfigPath()
|
| 337 |
-
if (!configPath) throw new Error('
|
| 338 |
|
| 339 |
const { readFile, writeFile } = require('fs/promises')
|
| 340 |
const raw = await readFile(configPath, 'utf-8')
|
|
|
|
| 8 |
import { config } from './config'
|
| 9 |
import { getDatabase, db_helpers, logAuditEvent } from './db'
|
| 10 |
import { eventBus } from './event-bus'
|
| 11 |
+
import { join, isAbsolute, resolve } from 'path'
|
| 12 |
import { existsSync, readFileSync } from 'fs'
|
| 13 |
import { resolveWithin } from './paths'
|
| 14 |
import { logger } from './logger'
|
|
|
|
| 127 |
}
|
| 128 |
|
| 129 |
function getConfigPath(): string | null {
|
| 130 |
+
return config.openclawConfigPath || null
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
function resolveAgentWorkspacePath(workspace: string): string {
|
| 134 |
+
if (isAbsolute(workspace)) return resolve(workspace)
|
| 135 |
+
if (!config.openclawStateDir) {
|
| 136 |
+
throw new Error('OPENCLAW_STATE_DIR not configured')
|
| 137 |
+
}
|
| 138 |
+
return resolveWithin(config.openclawStateDir, workspace)
|
| 139 |
}
|
| 140 |
|
| 141 |
/** Safely read a file from an agent's workspace directory */
|
| 142 |
function readWorkspaceFile(workspace: string | undefined, filename: string): string | null {
|
| 143 |
+
if (!workspace) return null
|
| 144 |
try {
|
| 145 |
+
const safeWorkspace = resolveAgentWorkspacePath(workspace)
|
| 146 |
const safePath = resolveWithin(safeWorkspace, filename)
|
| 147 |
if (existsSync(safePath)) {
|
| 148 |
return readFileSync(safePath, 'utf-8')
|
|
|
|
| 180 |
/** Read and parse openclaw.json agents list */
|
| 181 |
async function readOpenClawAgents(): Promise<OpenClawAgent[]> {
|
| 182 |
const configPath = getConfigPath()
|
| 183 |
+
if (!configPath) throw new Error('OPENCLAW_CONFIG_PATH not configured')
|
| 184 |
|
| 185 |
const { readFile } = require('fs/promises')
|
| 186 |
const raw = await readFile(configPath, 'utf-8')
|
|
|
|
| 341 |
/** Write an agent config back to openclaw.json agents.list */
|
| 342 |
export async function writeAgentToConfig(agentConfig: any): Promise<void> {
|
| 343 |
const configPath = getConfigPath()
|
| 344 |
+
if (!configPath) throw new Error('OPENCLAW_CONFIG_PATH not configured')
|
| 345 |
|
| 346 |
const { readFile, writeFile } = require('fs/promises')
|
| 347 |
const raw = await readFile(configPath, 'utf-8')
|
src/lib/client-logger.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Lightweight structured logger for client-side ('use client') components.
|
| 3 |
+
*
|
| 4 |
+
* Mirrors pino's API surface (info/warn/error/debug) so call sites are
|
| 5 |
+
* consistent with the server-side logger in src/lib/logger.ts.
|
| 6 |
+
* In production builds, debug and info messages are suppressed.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error'
|
| 10 |
+
|
| 11 |
+
const LOG_LEVELS: Record<LogLevel, number> = {
|
| 12 |
+
debug: 10,
|
| 13 |
+
info: 20,
|
| 14 |
+
warn: 30,
|
| 15 |
+
error: 40,
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const minLevel: number =
|
| 19 |
+
process.env.NODE_ENV === 'production' ? LOG_LEVELS.warn : LOG_LEVELS.debug
|
| 20 |
+
|
| 21 |
+
function shouldLog(level: LogLevel): boolean {
|
| 22 |
+
return LOG_LEVELS[level] >= minLevel
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
function formatArgs(
|
| 26 |
+
level: LogLevel,
|
| 27 |
+
module: string,
|
| 28 |
+
msgOrObj: unknown,
|
| 29 |
+
...rest: unknown[]
|
| 30 |
+
): unknown[] {
|
| 31 |
+
const prefix = `[${level.toUpperCase()}] ${module}:`
|
| 32 |
+
if (typeof msgOrObj === 'string') {
|
| 33 |
+
return [prefix, msgOrObj, ...rest]
|
| 34 |
+
}
|
| 35 |
+
return [prefix, msgOrObj, ...rest]
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export interface ClientLogger {
|
| 39 |
+
debug(msg: string, ...args: unknown[]): void
|
| 40 |
+
debug(obj: Record<string, unknown>, msg?: string): void
|
| 41 |
+
info(msg: string, ...args: unknown[]): void
|
| 42 |
+
info(obj: Record<string, unknown>, msg?: string): void
|
| 43 |
+
warn(msg: string, ...args: unknown[]): void
|
| 44 |
+
warn(obj: Record<string, unknown>, msg?: string): void
|
| 45 |
+
error(msg: string, ...args: unknown[]): void
|
| 46 |
+
error(obj: Record<string, unknown>, msg?: string): void
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export function createClientLogger(module: string): ClientLogger {
|
| 50 |
+
return {
|
| 51 |
+
debug(msgOrObj: unknown, ...rest: unknown[]) {
|
| 52 |
+
if (!shouldLog('debug')) return
|
| 53 |
+
console.debug(...formatArgs('debug', module, msgOrObj, ...rest))
|
| 54 |
+
},
|
| 55 |
+
info(msgOrObj: unknown, ...rest: unknown[]) {
|
| 56 |
+
if (!shouldLog('info')) return
|
| 57 |
+
console.info(...formatArgs('info', module, msgOrObj, ...rest))
|
| 58 |
+
},
|
| 59 |
+
warn(msgOrObj: unknown, ...rest: unknown[]) {
|
| 60 |
+
if (!shouldLog('warn')) return
|
| 61 |
+
console.warn(...formatArgs('warn', module, msgOrObj, ...rest))
|
| 62 |
+
},
|
| 63 |
+
error(msgOrObj: unknown, ...rest: unknown[]) {
|
| 64 |
+
if (!shouldLog('error')) return
|
| 65 |
+
console.error(...formatArgs('error', module, msgOrObj, ...rest))
|
| 66 |
+
},
|
| 67 |
+
}
|
| 68 |
+
}
|
src/lib/command.ts
CHANGED
|
@@ -74,13 +74,13 @@ export function runCommand(
|
|
| 74 |
export function runOpenClaw(args: string[], options: CommandOptions = {}) {
|
| 75 |
return runCommand(config.openclawBin, args, {
|
| 76 |
...options,
|
| 77 |
-
cwd: options.cwd || config.
|
| 78 |
})
|
| 79 |
}
|
| 80 |
|
| 81 |
export function runClawdbot(args: string[], options: CommandOptions = {}) {
|
| 82 |
return runCommand(config.clawdbotBin, args, {
|
| 83 |
...options,
|
| 84 |
-
cwd: options.cwd || config.
|
| 85 |
})
|
| 86 |
}
|
|
|
|
| 74 |
export function runOpenClaw(args: string[], options: CommandOptions = {}) {
|
| 75 |
return runCommand(config.openclawBin, args, {
|
| 76 |
...options,
|
| 77 |
+
cwd: options.cwd || config.openclawStateDir || process.cwd()
|
| 78 |
})
|
| 79 |
}
|
| 80 |
|
| 81 |
export function runClawdbot(args: string[], options: CommandOptions = {}) {
|
| 82 |
return runCommand(config.clawdbotBin, args, {
|
| 83 |
...options,
|
| 84 |
+
cwd: options.cwd || config.openclawStateDir || process.cwd()
|
| 85 |
})
|
| 86 |
}
|
src/lib/config.ts
CHANGED
|
@@ -3,11 +3,24 @@ import os from 'node:os'
|
|
| 3 |
import path from 'node:path'
|
| 4 |
|
| 5 |
const defaultDataDir = path.join(process.cwd(), '.data')
|
| 6 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
process.env.OPENCLAW_HOME ||
|
| 8 |
process.env.CLAWDBOT_HOME ||
|
| 9 |
process.env.MISSION_CONTROL_OPENCLAW_HOME ||
|
| 10 |
''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
export const config = {
|
| 13 |
claudeHome:
|
|
@@ -20,22 +33,25 @@ export const config = {
|
|
| 20 |
tokensPath:
|
| 21 |
process.env.MISSION_CONTROL_TOKENS_PATH ||
|
| 22 |
path.join(defaultDataDir, 'mission-control-tokens.json'),
|
| 23 |
-
openclawHome
|
|
|
|
|
|
|
|
|
|
| 24 |
openclawBin: process.env.OPENCLAW_BIN || 'openclaw',
|
| 25 |
clawdbotBin: process.env.CLAWDBOT_BIN || 'clawdbot',
|
| 26 |
gatewayHost: process.env.OPENCLAW_GATEWAY_HOST || '127.0.0.1',
|
| 27 |
gatewayPort: Number(process.env.OPENCLAW_GATEWAY_PORT || '18789'),
|
| 28 |
logsDir:
|
| 29 |
process.env.OPENCLAW_LOG_DIR ||
|
| 30 |
-
(
|
| 31 |
tempLogsDir: process.env.CLAWDBOT_TMP_LOG_DIR || '',
|
| 32 |
memoryDir:
|
| 33 |
process.env.OPENCLAW_MEMORY_DIR ||
|
| 34 |
-
(
|
| 35 |
path.join(defaultDataDir, 'memory'),
|
| 36 |
soulTemplatesDir:
|
| 37 |
process.env.OPENCLAW_SOUL_TEMPLATES_DIR ||
|
| 38 |
-
(
|
| 39 |
homeDir: os.homedir(),
|
| 40 |
// Data retention (days). 0 = keep forever.
|
| 41 |
retention: {
|
|
|
|
| 3 |
import path from 'node:path'
|
| 4 |
|
| 5 |
const defaultDataDir = path.join(process.cwd(), '.data')
|
| 6 |
+
const defaultOpenClawStateDir = path.join(os.homedir(), '.openclaw')
|
| 7 |
+
const explicitOpenClawConfigPath =
|
| 8 |
+
process.env.OPENCLAW_CONFIG_PATH ||
|
| 9 |
+
process.env.MISSION_CONTROL_OPENCLAW_CONFIG_PATH ||
|
| 10 |
+
''
|
| 11 |
+
const legacyOpenClawHome =
|
| 12 |
process.env.OPENCLAW_HOME ||
|
| 13 |
process.env.CLAWDBOT_HOME ||
|
| 14 |
process.env.MISSION_CONTROL_OPENCLAW_HOME ||
|
| 15 |
''
|
| 16 |
+
const openclawStateDir =
|
| 17 |
+
process.env.OPENCLAW_STATE_DIR ||
|
| 18 |
+
process.env.CLAWDBOT_STATE_DIR ||
|
| 19 |
+
legacyOpenClawHome ||
|
| 20 |
+
(explicitOpenClawConfigPath ? path.dirname(explicitOpenClawConfigPath) : defaultOpenClawStateDir)
|
| 21 |
+
const openclawConfigPath =
|
| 22 |
+
explicitOpenClawConfigPath ||
|
| 23 |
+
path.join(openclawStateDir, 'openclaw.json')
|
| 24 |
|
| 25 |
export const config = {
|
| 26 |
claudeHome:
|
|
|
|
| 33 |
tokensPath:
|
| 34 |
process.env.MISSION_CONTROL_TOKENS_PATH ||
|
| 35 |
path.join(defaultDataDir, 'mission-control-tokens.json'),
|
| 36 |
+
// Keep openclawHome as a legacy alias for existing code paths.
|
| 37 |
+
openclawHome: openclawStateDir,
|
| 38 |
+
openclawStateDir,
|
| 39 |
+
openclawConfigPath,
|
| 40 |
openclawBin: process.env.OPENCLAW_BIN || 'openclaw',
|
| 41 |
clawdbotBin: process.env.CLAWDBOT_BIN || 'clawdbot',
|
| 42 |
gatewayHost: process.env.OPENCLAW_GATEWAY_HOST || '127.0.0.1',
|
| 43 |
gatewayPort: Number(process.env.OPENCLAW_GATEWAY_PORT || '18789'),
|
| 44 |
logsDir:
|
| 45 |
process.env.OPENCLAW_LOG_DIR ||
|
| 46 |
+
(openclawStateDir ? path.join(openclawStateDir, 'logs') : ''),
|
| 47 |
tempLogsDir: process.env.CLAWDBOT_TMP_LOG_DIR || '',
|
| 48 |
memoryDir:
|
| 49 |
process.env.OPENCLAW_MEMORY_DIR ||
|
| 50 |
+
(openclawStateDir ? path.join(openclawStateDir, 'memory') : '') ||
|
| 51 |
path.join(defaultDataDir, 'memory'),
|
| 52 |
soulTemplatesDir:
|
| 53 |
process.env.OPENCLAW_SOUL_TEMPLATES_DIR ||
|
| 54 |
+
(openclawStateDir ? path.join(openclawStateDir, 'templates', 'souls') : ''),
|
| 55 |
homeDir: os.homedir(),
|
| 56 |
// Data retention (days). 0 = keep forever.
|
| 57 |
retention: {
|
src/lib/device-identity.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
'use client'
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
/**
|
| 4 |
* Ed25519 device identity for OpenClaw gateway protocol v3 challenge-response.
|
| 5 |
*
|
|
@@ -101,7 +105,7 @@ export async function getOrCreateDeviceIdentity(): Promise<DeviceIdentity> {
|
|
| 101 |
}
|
| 102 |
} catch {
|
| 103 |
// Stored key corrupted — regenerate
|
| 104 |
-
|
| 105 |
}
|
| 106 |
}
|
| 107 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 4 |
+
|
| 5 |
+
const log = createClientLogger('DeviceIdentity')
|
| 6 |
+
|
| 7 |
/**
|
| 8 |
* Ed25519 device identity for OpenClaw gateway protocol v3 challenge-response.
|
| 9 |
*
|
|
|
|
| 105 |
}
|
| 106 |
} catch {
|
| 107 |
// Stored key corrupted — regenerate
|
| 108 |
+
log.warn('Device identity keys corrupted, regenerating...')
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
src/lib/sessions.ts
CHANGED
|
@@ -23,16 +23,16 @@ export interface GatewaySession {
|
|
| 23 |
* Read all sessions from OpenClaw agent session stores on disk.
|
| 24 |
*
|
| 25 |
* OpenClaw stores sessions per-agent at:
|
| 26 |
-
* {
|
| 27 |
*
|
| 28 |
* Each file is a JSON object keyed by session key (e.g. "agent:<agent>:main")
|
| 29 |
* with session metadata as values.
|
| 30 |
*/
|
| 31 |
export function getAllGatewaySessions(activeWithinMs = 60 * 60 * 1000): GatewaySession[] {
|
| 32 |
-
const
|
| 33 |
-
if (!
|
| 34 |
|
| 35 |
-
const agentsDir = path.join(
|
| 36 |
if (!fs.existsSync(agentsDir)) return []
|
| 37 |
|
| 38 |
const sessions: GatewaySession[] = []
|
|
|
|
| 23 |
* Read all sessions from OpenClaw agent session stores on disk.
|
| 24 |
*
|
| 25 |
* OpenClaw stores sessions per-agent at:
|
| 26 |
+
* {OPENCLAW_STATE_DIR}/agents/{agentName}/sessions/sessions.json
|
| 27 |
*
|
| 28 |
* Each file is a JSON object keyed by session key (e.g. "agent:<agent>:main")
|
| 29 |
* with session metadata as values.
|
| 30 |
*/
|
| 31 |
export function getAllGatewaySessions(activeWithinMs = 60 * 60 * 1000): GatewaySession[] {
|
| 32 |
+
const openclawStateDir = config.openclawStateDir
|
| 33 |
+
if (!openclawStateDir) return []
|
| 34 |
|
| 35 |
+
const agentsDir = path.join(openclawStateDir, 'agents')
|
| 36 |
if (!fs.existsSync(agentsDir)) return []
|
| 37 |
|
| 38 |
const sessions: GatewaySession[] = []
|
src/lib/use-server-events.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
import { useEffect, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
interface ServerEvent {
|
| 7 |
type: string
|
|
@@ -73,7 +76,7 @@ export function useServerEvents() {
|
|
| 73 |
|
| 74 |
const attempts = sseReconnectAttemptsRef.current
|
| 75 |
if (attempts >= SSE_MAX_RECONNECT_ATTEMPTS) {
|
| 76 |
-
|
| 77 |
return
|
| 78 |
}
|
| 79 |
|
|
@@ -82,7 +85,7 @@ export function useServerEvents() {
|
|
| 82 |
const delay = Math.round(base + Math.random() * base * 0.5)
|
| 83 |
sseReconnectAttemptsRef.current = attempts + 1
|
| 84 |
|
| 85 |
-
|
| 86 |
reconnectTimeoutRef.current = setTimeout(() => {
|
| 87 |
if (mounted) connect()
|
| 88 |
}, delay)
|
|
|
|
| 2 |
|
| 3 |
import { useEffect, useRef } from 'react'
|
| 4 |
import { useMissionControl } from '@/store'
|
| 5 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 6 |
+
|
| 7 |
+
const log = createClientLogger('SSE')
|
| 8 |
|
| 9 |
interface ServerEvent {
|
| 10 |
type: string
|
|
|
|
| 76 |
|
| 77 |
const attempts = sseReconnectAttemptsRef.current
|
| 78 |
if (attempts >= SSE_MAX_RECONNECT_ATTEMPTS) {
|
| 79 |
+
log.error(`Max reconnect attempts (${SSE_MAX_RECONNECT_ATTEMPTS}) reached`)
|
| 80 |
return
|
| 81 |
}
|
| 82 |
|
|
|
|
| 85 |
const delay = Math.round(base + Math.random() * base * 0.5)
|
| 86 |
sseReconnectAttemptsRef.current = attempts + 1
|
| 87 |
|
| 88 |
+
log.warn(`Reconnecting in ${delay}ms (attempt ${attempts + 1}/${SSE_MAX_RECONNECT_ATTEMPTS})`)
|
| 89 |
reconnectTimeoutRef.current = setTimeout(() => {
|
| 90 |
if (mounted) connect()
|
| 91 |
}, delay)
|
src/lib/websocket.ts
CHANGED
|
@@ -10,6 +10,9 @@ import {
|
|
| 10 |
cacheDeviceToken,
|
| 11 |
} from '@/lib/device-identity'
|
| 12 |
import { APP_VERSION } from '@/lib/version'
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
// Gateway protocol version (v3 required by OpenClaw 2026.x)
|
| 15 |
const PROTOCOL_VERSION = 3
|
|
@@ -116,7 +119,7 @@ export function useWebSocket() {
|
|
| 116 |
|
| 117 |
// Check missed pongs
|
| 118 |
if (missedPongsRef.current >= MAX_MISSED_PONGS) {
|
| 119 |
-
|
| 120 |
addLog({
|
| 121 |
id: `heartbeat-${Date.now()}`,
|
| 122 |
timestamp: Date.now(),
|
|
@@ -213,7 +216,7 @@ export function useWebSocket() {
|
|
| 213 |
nonce,
|
| 214 |
}
|
| 215 |
} catch (err) {
|
| 216 |
-
|
| 217 |
}
|
| 218 |
}
|
| 219 |
|
|
@@ -239,7 +242,7 @@ export function useWebSocket() {
|
|
| 239 |
deviceToken: cachedToken || undefined,
|
| 240 |
}
|
| 241 |
}
|
| 242 |
-
|
| 243 |
ws.send(JSON.stringify(connectRequest))
|
| 244 |
}, [])
|
| 245 |
|
|
@@ -249,7 +252,7 @@ export function useWebSocket() {
|
|
| 249 |
|
| 250 |
// Debug logging for development
|
| 251 |
if (process.env.NODE_ENV === 'development') {
|
| 252 |
-
|
| 253 |
}
|
| 254 |
|
| 255 |
switch (message.type) {
|
|
@@ -319,24 +322,24 @@ export function useWebSocket() {
|
|
| 319 |
break
|
| 320 |
|
| 321 |
default:
|
| 322 |
-
|
| 323 |
}
|
| 324 |
}, [setLastMessage, setSessions, addLog, updateSpawnRequest, setCronJobs, addTokenUsage])
|
| 325 |
|
| 326 |
// Handle gateway protocol frames
|
| 327 |
const handleGatewayFrame = useCallback((frame: GatewayFrame, ws: WebSocket) => {
|
| 328 |
-
|
| 329 |
|
| 330 |
// Handle connect challenge
|
| 331 |
if (frame.type === 'event' && frame.event === 'connect.challenge') {
|
| 332 |
-
|
| 333 |
sendConnectHandshake(ws, frame.payload?.nonce)
|
| 334 |
return
|
| 335 |
}
|
| 336 |
|
| 337 |
// Handle connect response (handshake success)
|
| 338 |
if (frame.type === 'res' && frame.ok && !handshakeCompleteRef.current) {
|
| 339 |
-
|
| 340 |
handshakeCompleteRef.current = true
|
| 341 |
reconnectAttemptsRef.current = 0
|
| 342 |
// Cache device token if returned by gateway
|
|
@@ -361,7 +364,7 @@ export function useWebSocket() {
|
|
| 361 |
|
| 362 |
// Handle connect error
|
| 363 |
if (frame.type === 'res' && !frame.ok) {
|
| 364 |
-
|
| 365 |
const rawMessage = frame.error?.message || JSON.stringify(frame.error)
|
| 366 |
const help = getGatewayErrorHelp(rawMessage)
|
| 367 |
const nonRetryable = isNonRetryableGatewayError(rawMessage)
|
|
@@ -510,14 +513,14 @@ export function useWebSocket() {
|
|
| 510 |
wsRef.current = ws
|
| 511 |
|
| 512 |
ws.onopen = () => {
|
| 513 |
-
|
| 514 |
// Don't set isConnected yet - wait for handshake
|
| 515 |
setConnection({
|
| 516 |
url: url.split('?')[0],
|
| 517 |
reconnectAttempts: 0
|
| 518 |
})
|
| 519 |
// Wait for connect.challenge from server
|
| 520 |
-
|
| 521 |
}
|
| 522 |
|
| 523 |
ws.onmessage = (event) => {
|
|
@@ -525,7 +528,7 @@ export function useWebSocket() {
|
|
| 525 |
const frame = JSON.parse(event.data) as GatewayFrame
|
| 526 |
handleGatewayFrame(frame, ws)
|
| 527 |
} catch (error) {
|
| 528 |
-
|
| 529 |
addLog({
|
| 530 |
id: `raw-${Date.now()}`,
|
| 531 |
timestamp: Date.now(),
|
|
@@ -537,7 +540,7 @@ export function useWebSocket() {
|
|
| 537 |
}
|
| 538 |
|
| 539 |
ws.onclose = (event) => {
|
| 540 |
-
|
| 541 |
setConnection({ isConnected: false })
|
| 542 |
handshakeCompleteRef.current = false
|
| 543 |
stopHeartbeat()
|
|
@@ -555,7 +558,7 @@ export function useWebSocket() {
|
|
| 555 |
if (attempts < maxReconnectAttempts) {
|
| 556 |
const base = Math.min(Math.pow(2, attempts) * 1000, 30000)
|
| 557 |
const timeout = Math.round(base + Math.random() * base * 0.5)
|
| 558 |
-
|
| 559 |
|
| 560 |
reconnectAttemptsRef.current = attempts + 1
|
| 561 |
setConnection({ reconnectAttempts: attempts + 1 })
|
|
@@ -563,7 +566,7 @@ export function useWebSocket() {
|
|
| 563 |
connectRef.current(reconnectUrl.current, authTokenRef.current)
|
| 564 |
}, timeout)
|
| 565 |
} else {
|
| 566 |
-
|
| 567 |
addLog({
|
| 568 |
id: `error-${Date.now()}`,
|
| 569 |
timestamp: Date.now(),
|
|
@@ -575,7 +578,7 @@ export function useWebSocket() {
|
|
| 575 |
}
|
| 576 |
|
| 577 |
ws.onerror = (error) => {
|
| 578 |
-
|
| 579 |
addLog({
|
| 580 |
id: `error-${Date.now()}`,
|
| 581 |
timestamp: Date.now(),
|
|
@@ -586,7 +589,7 @@ export function useWebSocket() {
|
|
| 586 |
}
|
| 587 |
|
| 588 |
} catch (error) {
|
| 589 |
-
|
| 590 |
setConnection({ isConnected: false })
|
| 591 |
}
|
| 592 |
}, [setConnection, handleGatewayFrame, addLog, stopHeartbeat])
|
|
|
|
| 10 |
cacheDeviceToken,
|
| 11 |
} from '@/lib/device-identity'
|
| 12 |
import { APP_VERSION } from '@/lib/version'
|
| 13 |
+
import { createClientLogger } from '@/lib/client-logger'
|
| 14 |
+
|
| 15 |
+
const log = createClientLogger('WebSocket')
|
| 16 |
|
| 17 |
// Gateway protocol version (v3 required by OpenClaw 2026.x)
|
| 18 |
const PROTOCOL_VERSION = 3
|
|
|
|
| 119 |
|
| 120 |
// Check missed pongs
|
| 121 |
if (missedPongsRef.current >= MAX_MISSED_PONGS) {
|
| 122 |
+
log.warn(`Missed ${MAX_MISSED_PONGS} pongs, triggering reconnect`)
|
| 123 |
addLog({
|
| 124 |
id: `heartbeat-${Date.now()}`,
|
| 125 |
timestamp: Date.now(),
|
|
|
|
| 216 |
nonce,
|
| 217 |
}
|
| 218 |
} catch (err) {
|
| 219 |
+
log.warn('Device identity unavailable, proceeding without:', err)
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
|
|
|
| 242 |
deviceToken: cachedToken || undefined,
|
| 243 |
}
|
| 244 |
}
|
| 245 |
+
log.info('Sending connect handshake')
|
| 246 |
ws.send(JSON.stringify(connectRequest))
|
| 247 |
}, [])
|
| 248 |
|
|
|
|
| 252 |
|
| 253 |
// Debug logging for development
|
| 254 |
if (process.env.NODE_ENV === 'development') {
|
| 255 |
+
log.debug(`Message received: ${message.type}`)
|
| 256 |
}
|
| 257 |
|
| 258 |
switch (message.type) {
|
|
|
|
| 322 |
break
|
| 323 |
|
| 324 |
default:
|
| 325 |
+
log.warn(`Unknown gateway message type: ${message.type}`)
|
| 326 |
}
|
| 327 |
}, [setLastMessage, setSessions, addLog, updateSpawnRequest, setCronJobs, addTokenUsage])
|
| 328 |
|
| 329 |
// Handle gateway protocol frames
|
| 330 |
const handleGatewayFrame = useCallback((frame: GatewayFrame, ws: WebSocket) => {
|
| 331 |
+
log.debug(`Gateway frame: ${frame.type}`)
|
| 332 |
|
| 333 |
// Handle connect challenge
|
| 334 |
if (frame.type === 'event' && frame.event === 'connect.challenge') {
|
| 335 |
+
log.info('Received connect challenge, sending handshake')
|
| 336 |
sendConnectHandshake(ws, frame.payload?.nonce)
|
| 337 |
return
|
| 338 |
}
|
| 339 |
|
| 340 |
// Handle connect response (handshake success)
|
| 341 |
if (frame.type === 'res' && frame.ok && !handshakeCompleteRef.current) {
|
| 342 |
+
log.info('Handshake complete')
|
| 343 |
handshakeCompleteRef.current = true
|
| 344 |
reconnectAttemptsRef.current = 0
|
| 345 |
// Cache device token if returned by gateway
|
|
|
|
| 364 |
|
| 365 |
// Handle connect error
|
| 366 |
if (frame.type === 'res' && !frame.ok) {
|
| 367 |
+
log.error(`Gateway error: ${frame.error?.message || JSON.stringify(frame.error)}`)
|
| 368 |
const rawMessage = frame.error?.message || JSON.stringify(frame.error)
|
| 369 |
const help = getGatewayErrorHelp(rawMessage)
|
| 370 |
const nonRetryable = isNonRetryableGatewayError(rawMessage)
|
|
|
|
| 513 |
wsRef.current = ws
|
| 514 |
|
| 515 |
ws.onopen = () => {
|
| 516 |
+
log.info(`Connected to ${url.split('?')[0]}`)
|
| 517 |
// Don't set isConnected yet - wait for handshake
|
| 518 |
setConnection({
|
| 519 |
url: url.split('?')[0],
|
| 520 |
reconnectAttempts: 0
|
| 521 |
})
|
| 522 |
// Wait for connect.challenge from server
|
| 523 |
+
log.debug('Waiting for connect challenge')
|
| 524 |
}
|
| 525 |
|
| 526 |
ws.onmessage = (event) => {
|
|
|
|
| 528 |
const frame = JSON.parse(event.data) as GatewayFrame
|
| 529 |
handleGatewayFrame(frame, ws)
|
| 530 |
} catch (error) {
|
| 531 |
+
log.error('Failed to parse WebSocket message:', error)
|
| 532 |
addLog({
|
| 533 |
id: `raw-${Date.now()}`,
|
| 534 |
timestamp: Date.now(),
|
|
|
|
| 540 |
}
|
| 541 |
|
| 542 |
ws.onclose = (event) => {
|
| 543 |
+
log.info(`Disconnected from Gateway: ${event.code} ${event.reason}`)
|
| 544 |
setConnection({ isConnected: false })
|
| 545 |
handshakeCompleteRef.current = false
|
| 546 |
stopHeartbeat()
|
|
|
|
| 558 |
if (attempts < maxReconnectAttempts) {
|
| 559 |
const base = Math.min(Math.pow(2, attempts) * 1000, 30000)
|
| 560 |
const timeout = Math.round(base + Math.random() * base * 0.5)
|
| 561 |
+
log.info(`Reconnecting in ${timeout}ms (attempt ${attempts + 1}/${maxReconnectAttempts})`)
|
| 562 |
|
| 563 |
reconnectAttemptsRef.current = attempts + 1
|
| 564 |
setConnection({ reconnectAttempts: attempts + 1 })
|
|
|
|
| 566 |
connectRef.current(reconnectUrl.current, authTokenRef.current)
|
| 567 |
}, timeout)
|
| 568 |
} else {
|
| 569 |
+
log.error('Max reconnection attempts reached')
|
| 570 |
addLog({
|
| 571 |
id: `error-${Date.now()}`,
|
| 572 |
timestamp: Date.now(),
|
|
|
|
| 578 |
}
|
| 579 |
|
| 580 |
ws.onerror = (error) => {
|
| 581 |
+
log.error('WebSocket error:', error)
|
| 582 |
addLog({
|
| 583 |
id: `error-${Date.now()}`,
|
| 584 |
timestamp: Date.now(),
|
|
|
|
| 589 |
}
|
| 590 |
|
| 591 |
} catch (error) {
|
| 592 |
+
log.error('Failed to connect to WebSocket:', error)
|
| 593 |
setConnection({ isConnected: false })
|
| 594 |
}
|
| 595 |
}, [setConnection, handleGatewayFrame, addLog, stopHeartbeat])
|
tests/README.md
CHANGED
|
@@ -11,6 +11,9 @@ pnpm dev --hostname 127.0.0.1 --port 3005
|
|
| 11 |
# Run all tests
|
| 12 |
pnpm test:e2e
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
# Run a specific spec
|
| 15 |
pnpm exec playwright test tests/tasks-crud.spec.ts
|
| 16 |
```
|
|
@@ -21,6 +24,17 @@ Tests require `.env.local` with:
|
|
| 21 |
- `API_KEY=test-api-key-e2e-12345`
|
| 22 |
- `MC_DISABLE_RATE_LIMIT=1` (bypasses mutation/read rate limits, keeps login rate limit active)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
## Spec Files
|
| 25 |
|
| 26 |
### Security & Auth
|
|
|
|
| 11 |
# Run all tests
|
| 12 |
pnpm test:e2e
|
| 13 |
|
| 14 |
+
# Run offline OpenClaw harness (no OpenClaw install required)
|
| 15 |
+
pnpm test:e2e:openclaw
|
| 16 |
+
|
| 17 |
# Run a specific spec
|
| 18 |
pnpm exec playwright test tests/tasks-crud.spec.ts
|
| 19 |
```
|
|
|
|
| 24 |
- `API_KEY=test-api-key-e2e-12345`
|
| 25 |
- `MC_DISABLE_RATE_LIMIT=1` (bypasses mutation/read rate limits, keeps login rate limit active)
|
| 26 |
|
| 27 |
+
## OpenClaw Offline Harness
|
| 28 |
+
|
| 29 |
+
The harness runs Mission Control against fixture data and mock binaries/gateway:
|
| 30 |
+
- fixtures: `tests/fixtures/openclaw/`
|
| 31 |
+
- mock CLI: `scripts/e2e-openclaw/bin/{openclaw,clawdbot}`
|
| 32 |
+
- mock gateway: `scripts/e2e-openclaw/mock-gateway.mjs`
|
| 33 |
+
|
| 34 |
+
Profiles:
|
| 35 |
+
- `pnpm test:e2e:openclaw:local` - local mode (gateway not running)
|
| 36 |
+
- `pnpm test:e2e:openclaw:gateway` - gateway mode (mock gateway running)
|
| 37 |
+
|
| 38 |
## Spec Files
|
| 39 |
|
| 40 |
### Security & Auth
|
tests/fixtures/openclaw/agents/engineering-bot/sessions/sessions.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"agent:engineering-bot:main": {
|
| 3 |
+
"sessionId": "sess-eng-main",
|
| 4 |
+
"updatedAt": 4102444800000,
|
| 5 |
+
"chatType": "dm",
|
| 6 |
+
"lastChannel": "engineering",
|
| 7 |
+
"model": {
|
| 8 |
+
"primary": "openai/gpt-5"
|
| 9 |
+
},
|
| 10 |
+
"totalTokens": 24500,
|
| 11 |
+
"inputTokens": 16100,
|
| 12 |
+
"outputTokens": 8400,
|
| 13 |
+
"contextTokens": 120000
|
| 14 |
+
}
|
| 15 |
+
}
|
tests/fixtures/openclaw/agents/research-bot/sessions/sessions.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"agent:research-bot:main": {
|
| 3 |
+
"sessionId": "sess-research-main",
|
| 4 |
+
"updatedAt": 4102444700000,
|
| 5 |
+
"chatType": "dm",
|
| 6 |
+
"lastChannel": "research",
|
| 7 |
+
"model": {
|
| 8 |
+
"primary": "anthropic/claude-sonnet-4-5"
|
| 9 |
+
},
|
| 10 |
+
"totalTokens": 12800,
|
| 11 |
+
"inputTokens": 8100,
|
| 12 |
+
"outputTokens": 4700,
|
| 13 |
+
"contextTokens": 64000
|
| 14 |
+
}
|
| 15 |
+
}
|
tests/fixtures/openclaw/cron/jobs.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"jobs": [
|
| 4 |
+
{
|
| 5 |
+
"id": "job-eng-daily",
|
| 6 |
+
"agentId": "engineering-bot",
|
| 7 |
+
"name": "daily engineering standup",
|
| 8 |
+
"enabled": true,
|
| 9 |
+
"createdAtMs": 1762550000000,
|
| 10 |
+
"updatedAtMs": 1762550600000,
|
| 11 |
+
"schedule": {
|
| 12 |
+
"kind": "cron",
|
| 13 |
+
"expr": "0 9 * * 1-5",
|
| 14 |
+
"tz": "UTC"
|
| 15 |
+
},
|
| 16 |
+
"payload": {
|
| 17 |
+
"kind": "message",
|
| 18 |
+
"message": "Post daily engineering summary",
|
| 19 |
+
"model": "openai/gpt-5"
|
| 20 |
+
},
|
| 21 |
+
"delivery": {
|
| 22 |
+
"mode": "dm",
|
| 23 |
+
"channel": "engineering"
|
| 24 |
+
},
|
| 25 |
+
"state": {
|
| 26 |
+
"nextRunAtMs": 1762602000000,
|
| 27 |
+
"lastRunAtMs": 1762515600000,
|
| 28 |
+
"lastStatus": "success"
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"id": "job-research-hourly",
|
| 33 |
+
"agentId": "research-bot",
|
| 34 |
+
"name": "hourly trend scan",
|
| 35 |
+
"enabled": true,
|
| 36 |
+
"createdAtMs": 1762551000000,
|
| 37 |
+
"updatedAtMs": 1762551000000,
|
| 38 |
+
"schedule": {
|
| 39 |
+
"kind": "cron",
|
| 40 |
+
"expr": "0 * * * *",
|
| 41 |
+
"tz": "UTC"
|
| 42 |
+
},
|
| 43 |
+
"payload": {
|
| 44 |
+
"kind": "message",
|
| 45 |
+
"message": "Scan latest market/AI trends",
|
| 46 |
+
"model": "anthropic/claude-sonnet-4-5"
|
| 47 |
+
},
|
| 48 |
+
"delivery": {
|
| 49 |
+
"mode": "dm",
|
| 50 |
+
"channel": "research"
|
| 51 |
+
},
|
| 52 |
+
"state": {
|
| 53 |
+
"nextRunAtMs": 1762594800000,
|
| 54 |
+
"lastRunAtMs": 1762591200000,
|
| 55 |
+
"lastStatus": "success"
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
]
|
| 59 |
+
}
|
tests/fixtures/openclaw/openclaw.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"gateway": {
|
| 4 |
+
"host": "127.0.0.1",
|
| 5 |
+
"port": 18789
|
| 6 |
+
},
|
| 7 |
+
"agents": {
|
| 8 |
+
"defaults": {
|
| 9 |
+
"workspace": "workspaces"
|
| 10 |
+
},
|
| 11 |
+
"list": [
|
| 12 |
+
{
|
| 13 |
+
"id": "engineering-bot",
|
| 14 |
+
"name": "engineering-bot",
|
| 15 |
+
"default": true,
|
| 16 |
+
"workspace": "workspaces/engineering-bot",
|
| 17 |
+
"agentDir": "agents/engineering-bot",
|
| 18 |
+
"identity": {
|
| 19 |
+
"name": "Engineering Bot",
|
| 20 |
+
"theme": "software-engineer",
|
| 21 |
+
"emoji": ":gear:"
|
| 22 |
+
},
|
| 23 |
+
"model": {
|
| 24 |
+
"primary": "openai/gpt-5"
|
| 25 |
+
},
|
| 26 |
+
"tools": {
|
| 27 |
+
"allow": ["sessions_send", "sessions_history", "shell"]
|
| 28 |
+
}
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"id": "research-bot",
|
| 32 |
+
"name": "research-bot",
|
| 33 |
+
"workspace": "workspaces/research-bot",
|
| 34 |
+
"agentDir": "agents/research-bot",
|
| 35 |
+
"identity": {
|
| 36 |
+
"name": "Research Bot",
|
| 37 |
+
"theme": "analyst",
|
| 38 |
+
"emoji": ":book:"
|
| 39 |
+
},
|
| 40 |
+
"model": {
|
| 41 |
+
"primary": "anthropic/claude-sonnet-4-5"
|
| 42 |
+
},
|
| 43 |
+
"tools": {
|
| 44 |
+
"allow": ["web", "sessions_send"]
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
}
|
tests/fixtures/openclaw/workspaces/engineering-bot/TOOLS.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- `shell`
|
| 2 |
+
- `sessions_send`
|
| 3 |
+
- `sessions_history`
|
tests/fixtures/openclaw/workspaces/engineering-bot/identity.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Engineering Bot
|
| 2 |
+
theme: software-engineer
|
| 3 |
+
emoji: ⚙️
|
tests/fixtures/openclaw/workspaces/engineering-bot/soul.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Engineering Bot
|
| 2 |
+
Focus on implementation quality, safe migrations, and test coverage.
|
tests/fixtures/openclaw/workspaces/research-bot/TOOLS.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- `web`
|
| 2 |
+
- `sessions_send`
|
tests/fixtures/openclaw/workspaces/research-bot/identity.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Research Bot
|
| 2 |
+
theme: analyst
|
| 3 |
+
emoji: 📚
|
tests/fixtures/openclaw/workspaces/research-bot/soul.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Research Bot
|
| 2 |
+
Focus on evidence, citations, and concise recommendations.
|
tests/openclaw-harness.spec.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { test, expect } from '@playwright/test'
|
| 2 |
+
import { API_KEY_HEADER } from './helpers'
|
| 3 |
+
|
| 4 |
+
const EXPECT_GATEWAY = process.env.E2E_GATEWAY_EXPECTED === '1'
|
| 5 |
+
|
| 6 |
+
test.describe('OpenClaw Offline Harness', () => {
|
| 7 |
+
test('capabilities expose OpenClaw state dir/config in offline test mode', async ({ request }) => {
|
| 8 |
+
const res = await request.get('/api/status?action=capabilities', {
|
| 9 |
+
headers: API_KEY_HEADER,
|
| 10 |
+
})
|
| 11 |
+
expect(res.status()).toBe(200)
|
| 12 |
+
|
| 13 |
+
const body = await res.json()
|
| 14 |
+
expect(body.openclawHome).toBe(true)
|
| 15 |
+
expect(Boolean(body.claudeHome)).toBeTruthy()
|
| 16 |
+
expect(Boolean(body.gateway)).toBe(EXPECT_GATEWAY)
|
| 17 |
+
})
|
| 18 |
+
|
| 19 |
+
test('sessions API reads fixture sessions without OpenClaw install', async ({ request }) => {
|
| 20 |
+
const res = await request.get('/api/sessions', {
|
| 21 |
+
headers: API_KEY_HEADER,
|
| 22 |
+
})
|
| 23 |
+
expect(res.status()).toBe(200)
|
| 24 |
+
|
| 25 |
+
const body = await res.json()
|
| 26 |
+
expect(Array.isArray(body.sessions)).toBe(true)
|
| 27 |
+
expect(body.sessions.length).toBeGreaterThan(0)
|
| 28 |
+
expect(body.sessions[0]).toHaveProperty('agent')
|
| 29 |
+
expect(body.sessions[0]).toHaveProperty('tokens')
|
| 30 |
+
})
|
| 31 |
+
|
| 32 |
+
test('cron API reads fixture jobs', async ({ request }) => {
|
| 33 |
+
const res = await request.get('/api/cron?action=list', {
|
| 34 |
+
headers: API_KEY_HEADER,
|
| 35 |
+
})
|
| 36 |
+
expect(res.status()).toBe(200)
|
| 37 |
+
|
| 38 |
+
const body = await res.json()
|
| 39 |
+
expect(Array.isArray(body.jobs)).toBe(true)
|
| 40 |
+
expect(body.jobs.length).toBeGreaterThan(0)
|
| 41 |
+
expect(body.jobs[0]).toHaveProperty('name')
|
| 42 |
+
expect(body.jobs[0]).toHaveProperty('schedule')
|
| 43 |
+
})
|
| 44 |
+
|
| 45 |
+
test('gateway config API reads fixture config', async ({ request }) => {
|
| 46 |
+
const res = await request.get('/api/gateway-config', {
|
| 47 |
+
headers: API_KEY_HEADER,
|
| 48 |
+
})
|
| 49 |
+
expect(res.status()).toBe(200)
|
| 50 |
+
|
| 51 |
+
const body = await res.json()
|
| 52 |
+
expect(typeof body.path).toBe('string')
|
| 53 |
+
expect(body.path.endsWith('openclaw.json')).toBe(true)
|
| 54 |
+
expect(body.config).toHaveProperty('agents')
|
| 55 |
+
})
|
| 56 |
+
})
|