Files
Jiang Bohan 9fe7340211 feat(agent): OpenClaw backend P1 — hardened parsing, lifecycle events, usage variants
Three robustness improvements to the OpenClaw agent backend:

1. Hardened JSON parsing — tryParseOpenclawResult now requires lines to
   start with '{', eliminating the fragile brace-scanning fallback that
   could false-match JSON fragments inside log lines.

2. Lifecycle event handling — new "lifecycle" event type with phase
   tracking (error/failed/cancelled). Structured error objects are now
   parsed (error.name, error.data.message, error.message) matching the
   PaperClip adapter pattern.

3. Usage field name variants — parseOpenclawUsage supports multiple
   naming conventions (input/inputTokens/input_tokens, cacheRead/
   cachedInputTokens/cache_read_input_tokens, etc.) so usage is
   correctly extracted regardless of which OpenClaw version or protocol
   the agent uses. Usage accumulates incrementally across step_finish
   events.

Adds 13 new tests (31 total for the openclaw backend).

Refs MUL-726
2026-04-14 01:47:48 +08:00
..