feat: Phase 0+1 — repo sync, pino, lint fixes, core components

Phase 0:
- Synced latest live-status.js from workspace (9928 bytes)
- Fixed 43 lint issues: empty catch blocks, console statements
- Added pino dependency
- Created src/tool-labels.json with all known tool mappings
- make check passes

Phase 1 (Core Components):
- src/config.js: env-var config with validation, throws on missing required vars
- src/logger.js: pino singleton with child loggers, level validation
- src/circuit-breaker.js: CLOSED/OPEN/HALF_OPEN state machine with callbacks
- src/tool-labels.js: exact/prefix/regex tool->label resolver with external override
- src/status-box.js: Mattermost post manager (keepAlive, throttle, retry, circuit breaker)
- src/status-formatter.js: pure SessionState->text formatter (nested, compact)
- src/health.js: HTTP health endpoint + metrics
- src/status-watcher.js: JSONL file watcher (inotify, compaction detection, idle detection)

Tests:
- test/unit/config.test.js: 7 tests
- test/unit/circuit-breaker.test.js: 12 tests
- test/unit/logger.test.js: 5 tests
- test/unit/status-formatter.test.js: 20 tests
- test/unit/tool-labels.test.js: 15 tests

All 59 unit tests pass. make check clean.
This commit is contained in:
sol
2026-03-07 17:26:53 +00:00
parent b3ec2c61db
commit 43cfebee96
21 changed files with 2691 additions and 287 deletions

View File

@@ -9,6 +9,7 @@ Planner sub-agent (proj035-planner) conducted inline discovery before drafting t
**Confirmed format (JSONL, version 3):**
Each line is a JSON object with `type` field:
- `session` — First line only. Contains `id` (UUID), `version: 3`, `cwd`
- `model_change``provider`, `modelId` change events
- `thinking_level_change` — thinking on/off
@@ -16,6 +17,7 @@ Each line is a JSON object with `type` field:
- `message` — Main event type. `role` = `user`, `assistant`, or `toolResult`
Message content types:
- `{type: "text", text: "..."}` — plain text from any role
- `{type: "toolCall", id, name, arguments: {...}}` — tool invocations in assistant messages
- `{type: "thinking", thinking: "..."}` — internal reasoning (thinking mode)
@@ -25,6 +27,7 @@ Assistant messages carry extra fields: `api`, `provider`, `model`, `usage`, `sto
ToolResult messages carry: `toolCallId`, `toolName`, `isError`, `content: [{type, text}]`
**Key signals for watcher:**
- `stopReason: "stop"` + no new lines → agent turn complete → idle
- `stopReason: "toolUse"` → agent waiting for tool results → NOT idle
- `custom.customType: "openclaw.cache-ttl"` → turn boundary marker
@@ -34,6 +37,7 @@ ToolResult messages carry: `toolCallId`, `toolName`, `isError`, `content: [{type
Session keys in sessions.json follow the pattern: `agent:{agentId}:{context}`
Examples:
- `agent:main:main` — direct session
- `agent:main:mattermost:channel:{channelId}` — channel session
- `agent:main:mattermost:channel:{channelId}:thread:{threadId}` — thread session
@@ -42,6 +46,7 @@ Examples:
- `agent:main:cron:{name}` — cron session
Sub-agent entry fields relevant to watcher:
- `sessionId` — maps to `{sessionId}.jsonl` filename
- `spawnedBy` — parent session key (for nesting)
- `spawnDepth` — nesting depth (1 = direct child of main)
@@ -49,6 +54,7 @@ Sub-agent entry fields relevant to watcher:
- `channel` — delivery channel (mattermost, etc.)
Sessions files: `/home/node/.openclaw/agents/{agentId}/sessions/`
- `sessions.json` — registry (updated on every message)
- `{uuid}.jsonl` — transcript files
- `{uuid}-topic-{topicId}.jsonl` — topic-scoped transcripts
@@ -56,6 +62,7 @@ Sessions files: `/home/node/.openclaw/agents/{agentId}/sessions/`
## Discovery 3: OpenClaw Hook Events
Available internal hook events (confirmed from source):
- `command:new`, `command:reset`, `command:stop` — user commands
- `command` — all commands
- `agent:bootstrap` — before workspace files injected