moi-computer 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/api/workspace-keys.ts +1 -2
- package/client/app/AppRouter.tsx +10 -3
- package/client/app/routes/HomeRoute.tsx +1 -1
- package/client/app/shell/SidebarLayout.tsx +2 -14
- package/client/components/shared/Composer.tsx +20 -7
- package/client/components/shared/PanelHeader.tsx +8 -1
- package/client/components/ui/button.tsx +3 -3
- package/client/components/ui/dialog.tsx +1 -1
- package/client/components/ui/dropdown-menu.tsx +2 -2
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/resizable.tsx +40 -0
- package/client/features/chat/ChatEmptyState.tsx +9 -11
- package/client/features/chat/ChatPanel.tsx +76 -48
- package/client/features/chat/ChatPopup.tsx +16 -2
- package/client/features/chat/ChatPromptBubbles.tsx +6 -8
- package/client/features/chat/ChatSelector.tsx +24 -7
- package/client/features/chat/MarkdownContent.tsx +1 -1
- package/client/features/chat/ModelPicker.tsx +5 -4
- package/client/features/chat/TurnView.tsx +108 -13
- package/client/features/chat/api.ts +1 -18
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/{ChatComposer.tsx → composer/ChatComposer.tsx} +6 -5
- package/client/features/chat/composer/banners/ChatErrorBanner.tsx +28 -0
- package/client/features/chat/composer/banners/ComposerBanner.tsx +30 -0
- package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +91 -0
- package/client/features/{workspace → chat/composer/banners}/WorkspaceSkillUpdateBanner.tsx +9 -7
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +74 -0
- package/client/features/{workspace → chat/composer}/useWorkspaceSkillUpdates.ts +1 -1
- package/client/features/chat/group-turns.ts +46 -28
- package/client/features/chat/interleave-notices.ts +84 -0
- package/client/features/chat/model-order.ts +9 -3
- package/client/features/chat/tool-group/TimelineRow.tsx +23 -11
- package/client/features/chat/tool-group/ToolCallGroup.tsx +38 -3
- package/client/features/chat/tool-group/format.ts +51 -10
- package/client/features/chat/useAppletChatMessage.ts +11 -16
- package/client/features/chat/useChat.ts +3 -7
- package/client/features/dev/ChatStatesPage.tsx +466 -0
- package/client/features/dev/DevIndexPage.tsx +52 -0
- package/client/features/dev/DevRoutes.tsx +6 -3
- package/client/features/dev/HarnessDebugPage.tsx +3 -3
- package/client/features/dev/chat-states-fixtures.ts +744 -0
- package/client/features/scratchpad/Scratchpad.tsx +4 -0
- package/client/features/scratchpad/scratch-session.ts +71 -0
- package/client/features/views/ViewBuilderTab.tsx +5 -4
- package/client/features/views/useViewBuilderActions.ts +2 -2
- package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -2
- package/client/features/workspace/WorkspaceScreen.tsx +128 -146
- package/client/features/workspace/WorkspaceSplitLayout.tsx +111 -0
- package/client/features/workspace/api.ts +33 -8
- package/client/features/workspace/useFitsSplitLayout.ts +31 -5
- package/client/index.css +1 -1
- package/client/lib/flags.ts +4 -3
- package/client/runtime/useWorkspaceEvents.ts +18 -1
- package/client/store/ui.ts +5 -1
- package/dist/{chunk-0pcdwjkp.js → chunk-2vaafjp4.js} +1 -1
- package/dist/{chunk-9y2zbzqz.js → chunk-35fq49qa.js} +1 -1
- package/dist/{chunk-h9h8f176.js → chunk-3b3rkjet.js} +1 -1
- package/dist/chunk-gt7n06ef.js +1 -0
- package/dist/{chunk-r5ce5cdg.js → chunk-kkj86722.js} +75 -75
- package/dist/chunk-ty1sqbmn.js +80 -0
- package/dist/chunk-xeyxk7ep.js +10 -0
- package/dist/chunk-yz6wd5vc.css +1 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +37 -7
- package/lib/themes.ts +2 -2
- package/lib/types.ts +38 -8
- package/lib/workspace-layout.ts +2 -2
- package/package.json +6 -4
- package/server/agent.ts +199 -0
- package/server/api.ts +36 -17
- package/server/bundler/build-applet.ts +35 -44
- package/server/cli-env.ts +2 -2
- package/server/cli.ts +39 -53
- package/server/constants.ts +8 -0
- package/server/control-client.ts +124 -0
- package/server/control.ts +2 -2
- package/server/env-apply.ts +4 -0
- package/server/harness/README.md +32 -12
- package/server/harness/claude-code/auth.ts +54 -0
- package/server/harness/claude-code/index.ts +6 -1
- package/server/harness/codex/adapter.ts +9 -1
- package/server/harness/codex/auth.ts +50 -0
- package/server/harness/codex/index.ts +6 -1
- package/server/harness/codex/session.ts +33 -14
- package/server/harness/openclaw/NOTES.md +619 -186
- package/server/harness/openclaw/adapter.ts +121 -54
- package/server/harness/openclaw/compat.ts +95 -0
- package/server/harness/openclaw/cron-view.ts +78 -0
- package/server/harness/openclaw/discovery.ts +145 -52
- package/server/harness/openclaw/gateway.ts +224 -36
- package/server/harness/openclaw/index.ts +56 -21
- package/server/harness/openclaw/session.ts +1002 -67
- package/server/harness/openclaw/strip.ts +71 -23
- package/server/harness/openclaw/thinking.ts +150 -0
- package/server/harness/types.ts +10 -5
- package/server/layout.ts +5 -2
- package/server/service.ts +2 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +6 -6
- package/workspace/.claude/skills/moi-workspace/{DESIGN.md → references/DESIGN.md} +19 -9
- package/client/features/dev/PixelPainter.tsx +0 -94
- package/client/features/dev/PlaygroundPage.tsx +0 -69
- package/dist/chunk-0k7brsms.js +0 -9
- package/dist/chunk-dfs36zgc.js +0 -1
- package/dist/chunk-dtwxpxbg.js +0 -51
- package/dist/chunk-ga7t9qsk.js +0 -2
- package/dist/chunk-tey2nq7c.js +0 -31
- package/dist/chunk-z73xpsa0.js +0 -50
- package/dist/chunk-zzgredta.css +0 -1
- /package/workspace/.claude/skills/moi-workspace/{SCRATCHPAD.md → references/SCRATCHPAD.md} +0 -0
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
# OpenClaw — integration notes
|
|
2
2
|
|
|
3
|
-
Everything we learned wiring
|
|
4
|
-
|
|
5
|
-
the things that bit us, and how to use it from Bun.
|
|
6
|
-
|
|
7
|
-
Pinned
|
|
8
|
-
|
|
3
|
+
Everything we learned wiring moi to OpenClaw's local gateway. Covers on-disk
|
|
4
|
+
layout, the WebSocket protocol, auth, the RPC surface, the live event stream,
|
|
5
|
+
per-version drift, the things that bit us, and how to use it from Bun.
|
|
6
|
+
|
|
7
|
+
Pinned dep: **`openclaw@2026.7.1`**. Compatibility: moi speaks gateway **wire
|
|
8
|
+
protocol 4**, the protocol of both the 2026.7.x and 2026.6.x lines — verified
|
|
9
|
+
identical for everything moi uses against live 2026.7.1 and 2026.6.33
|
|
10
|
+
gateways. Protocol-3 gateways (≤ 2026.5.x) reject the handshake with
|
|
11
|
+
`protocol mismatch` (verified live against 2026.4.22, WS close 1002); those
|
|
12
|
+
are detect-and-surface only (`compat.ts` → `classifyGatewayError`), never
|
|
13
|
+
silently degraded into empty lists.
|
|
14
|
+
|
|
15
|
+
Claims here are only as good as their last capture. §6 was rewritten against
|
|
16
|
+
live 2026.7.1 traffic (`ollama-cloud/glm-5.2:cloud`, `openai/gpt-5.5`,
|
|
17
|
+
`claude-cli/claude-sonnet-5`), transcribed into `wire-replay.test.ts`. Much of
|
|
18
|
+
what this file used to say about "backend-specific" frame behavior was one
|
|
19
|
+
capture on one config generalized too far — record a run before trusting it.
|
|
9
20
|
|
|
10
21
|
## 1. What OpenClaw is
|
|
11
22
|
|
|
@@ -15,8 +26,8 @@ two components that matter:
|
|
|
15
26
|
|
|
16
27
|
- **The gateway** — a local service exposing a WebSocket JSON-RPC API at
|
|
17
28
|
`ws://127.0.0.1:18789`. Every feature (sessions, agents, channels, config,
|
|
18
|
-
approvals, memory, logs, skills) is reachable through it. It's the
|
|
19
|
-
control plane.
|
|
29
|
+
approvals, memory, logs, skills, cron) is reachable through it. It's the
|
|
30
|
+
single control plane.
|
|
20
31
|
- **The `openclaw` CLI** — a thin wrapper over the gateway's RPC methods. Most
|
|
21
32
|
subcommands (`openclaw sessions`, `openclaw agents list`, `openclaw logs`)
|
|
22
33
|
just open a WS connection, call one method, and format the result.
|
|
@@ -26,7 +37,10 @@ Control UI SPA and a tiny `/health` endpoint. Everything else is WebSocket.
|
|
|
26
37
|
|
|
27
38
|
## 2. On-disk layout
|
|
28
39
|
|
|
29
|
-
State root: `~/.openclaw
|
|
40
|
+
State root: `~/.openclaw/` by default. moi resolves the config the way the
|
|
41
|
+
CLI does: `OPENCLAW_CONFIG_PATH` wins, then `OPENCLAW_STATE_DIR/openclaw.json`
|
|
42
|
+
(profile runs), then `~/.openclaw/openclaw.json` (`gateway.ts →
|
|
43
|
+
openClawConfigPath`).
|
|
30
44
|
|
|
31
45
|
| What | Path |
|
|
32
46
|
| ----------------------------------------------------------------- | ---------------------------------------------------------- |
|
|
@@ -43,28 +57,17 @@ State root: `~/.openclaw/`.
|
|
|
43
57
|
| Paired devices (control-UI, CLI, health) | `~/.openclaw/devices/paired.json` |
|
|
44
58
|
| Pending pairing requests | `~/.openclaw/devices/pending.json` |
|
|
45
59
|
|
|
46
|
-
Each agent has its **own workspace dir** (override with `openclaw agents add
|
|
47
|
-
and its own agent-state dir. The default `~/.openclaw/workspace/`
|
|
48
|
-
fallback when an agent doesn't specify one — don't assume it's
|
|
49
|
-
enumerating per-agent data
|
|
50
|
-
per agent from `agents.list
|
|
51
|
-
|
|
52
|
-
### Session `.jsonl` schema
|
|
53
|
-
|
|
54
|
-
Each line is one event. Types seen in the wild (from a fresh agent run):
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
session { version, id, cwd, timestamp }
|
|
58
|
-
model_change { provider, modelId }
|
|
59
|
-
thinking_level_change{ thinkingLevel }
|
|
60
|
-
custom { customType, data } ← OpenClaw's synthetic-event channel
|
|
61
|
-
message { role: 'user'|'assistant', content: [...] }
|
|
62
|
-
toolResult message-shaped with tool output
|
|
63
|
-
```
|
|
60
|
+
Each agent has its **own workspace dir** (override with `openclaw agents add
|
|
61
|
+
--workspace`) and its own agent-state dir. The default `~/.openclaw/workspace/`
|
|
62
|
+
is only the fallback when an agent doesn't specify one — don't assume it's
|
|
63
|
+
global. If you're enumerating per-agent data, **always resolve the workspace
|
|
64
|
+
per agent from `agents.list`**.
|
|
64
65
|
|
|
65
|
-
The
|
|
66
|
-
`session
|
|
67
|
-
`
|
|
66
|
+
The session `.jsonl` record vocabulary is identical across 2026.4.x → 2026.7.x
|
|
67
|
+
(diffed in dist): `session`/`session_info`, `message` (roles
|
|
68
|
+
`user`/`assistant`/`toolResult`), `compaction`, `custom`, `custom_message`,
|
|
69
|
+
`model_change`, `thinking_level_change`, `branch_summary`, `label`. Content
|
|
70
|
+
blocks: `text`, `thinking` (+`thinkingSignature`), `toolCall`.
|
|
68
71
|
|
|
69
72
|
## 3. Auth & device pairing — the part that breaks you
|
|
70
73
|
|
|
@@ -80,11 +83,12 @@ Three auth concepts stack on the gateway:
|
|
|
80
83
|
approved scope set (`operator.read`, `operator.write`, `operator.admin`,
|
|
81
84
|
`operator.approvals`, `operator.pairing`, `operator.talk.secrets`).
|
|
82
85
|
|
|
83
|
-
A
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
A loopback `gateway-client` in `backend` mode holding a valid gateway token
|
|
87
|
+
skips pairing entirely — this is moi's path, and on a fresh install it gets
|
|
88
|
+
full operator scopes immediately (verified in the cloud sandbox,
|
|
89
|
+
`docs/openclaw-sandbox.md`). The pairing dance below bites shared/remote
|
|
90
|
+
setups where devices start with **`operator.read` only**. When the CLI
|
|
91
|
+
connects with insufficient scopes the gateway emits:
|
|
88
92
|
|
|
89
93
|
```
|
|
90
94
|
GatewayClientRequestError: scope upgrade pending approval (requestId: <uuid>)
|
|
@@ -103,208 +107,637 @@ requestId`.
|
|
|
103
107
|
Resolution paths, in order of practicality:
|
|
104
108
|
|
|
105
109
|
1. **Approve from the Control UI** (`http://127.0.0.1:18789/`). The browser is
|
|
106
|
-
usually already paired
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
its device token.
|
|
111
|
-
3. **Revoke the current read-only CLI pairing** so it re-pairs from scratch;
|
|
112
|
-
the fresh pairing shows up as a new request the browser can approve.
|
|
110
|
+
usually already paired with full operator scopes. One click in the Devices
|
|
111
|
+
panel approves the latest pending request.
|
|
112
|
+
2. **Approve from another already-paired device** holding admin scopes.
|
|
113
|
+
3. **Revoke the current read-only CLI pairing** so it re-pairs from scratch.
|
|
113
114
|
|
|
114
|
-
Once approved, the role token in `device-auth.json`
|
|
115
|
-
config changes needed.
|
|
115
|
+
Once approved, the role token in `device-auth.json` is upgraded in place.
|
|
116
116
|
|
|
117
117
|
### Fallback behavior of the CLI
|
|
118
118
|
|
|
119
119
|
Most `openclaw` subcommands that need RPC have a local-file fallback: if the
|
|
120
|
-
gateway refuses the connection, they read `~/.openclaw/…` directly
|
|
121
|
-
sessions`, `openclaw status`, `openclaw agents list`, `openclaw logs`
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
gateway refuses the connection, they read `~/.openclaw/…` directly (`openclaw
|
|
121
|
+
sessions`, `openclaw status`, `openclaw agents list`, `openclaw logs`). Watch
|
|
122
|
+
for the "Direct scope access failed; using local fallback" banner when
|
|
123
|
+
debugging — those commands may never have hit the gateway.
|
|
124
|
+
|
|
125
|
+
## 4. Handshake and hello-ok
|
|
126
|
+
|
|
127
|
+
The server pushes `connect.challenge {nonce, ts}` on socket open; the client's
|
|
128
|
+
first frame must be a `connect` request. On success the response payload is
|
|
129
|
+
(observed live on both lines):
|
|
130
|
+
|
|
131
|
+
```jsonc
|
|
132
|
+
{
|
|
133
|
+
"type": "hello-ok",
|
|
134
|
+
"protocol": 4,
|
|
135
|
+
"server": { "version": "2026.7.1", "connId": "<uuid>" },
|
|
136
|
+
"features": {
|
|
137
|
+
"methods": ["..."], // 218 on 2026.7.1, 193 on 2026.6.33
|
|
138
|
+
"events": ["..."], // 30 / 27
|
|
139
|
+
"capabilities": ["chat-send-routing-contract"] // 2026.7.x only
|
|
140
|
+
},
|
|
141
|
+
"snapshot": {
|
|
142
|
+
"presence": [],
|
|
143
|
+
"health": {},
|
|
144
|
+
"uptimeMs": 0,
|
|
145
|
+
"sessionDefaults": {},
|
|
146
|
+
"authMode": "token"
|
|
147
|
+
},
|
|
148
|
+
"auth": { "role": "operator", "scopes": ["..."] },
|
|
149
|
+
"policy": { "maxPayload": 26214400, "maxBufferedBytes": 52428800, "tickIntervalMs": 30000 }
|
|
150
|
+
}
|
|
151
|
+
```
|
|
126
152
|
|
|
127
|
-
|
|
153
|
+
**`features.methods` UNDER-REPORTS.** Methods registered with
|
|
154
|
+
`advertise:false` (`sessions.get`, `sessions.resolve`, `sessions.usage*`) are
|
|
155
|
+
omitted yet fully callable — both live gateways omit `sessions.get` from
|
|
156
|
+
`features.methods` and still answer it (verified live against 2026.7.1 /
|
|
157
|
+
2026.6.33). Absence proves nothing, so nothing in moi gates on the list; it is
|
|
158
|
+
carried for `/status` and for diagnosing a version mismatch.
|
|
159
|
+
|
|
160
|
+
Rule for params in the other direction: gateways validate with
|
|
161
|
+
`additionalProperties: false` and hard-reject unknown fields, so never send a
|
|
162
|
+
param that only newer schemas know without gating on the announced version
|
|
163
|
+
(e.g. `sessions.list {archived}` and `sessions.create {fork, worktree}` are
|
|
164
|
+
2026.7.x-only).
|
|
165
|
+
|
|
166
|
+
## 5. RPC surface
|
|
167
|
+
|
|
168
|
+
Methods moi uses, all present and shape-identical on both supported lines:
|
|
169
|
+
`agents.list` · `agents.files.get` · `models.list` · `sessions.list` ·
|
|
170
|
+
`sessions.get` · `sessions.resolve` · `sessions.create` · `sessions.send` ·
|
|
171
|
+
`sessions.steer` · `sessions.abort` · `sessions.patch` ·
|
|
172
|
+
`sessions.subscribe`/`unsubscribe` · `sessions.messages.subscribe`/
|
|
173
|
+
`unsubscribe`. Also there: `sessions.preview`, `sessions.compact`,
|
|
174
|
+
`chat.history`, `cron.list`, `cron.runs`, and many more.
|
|
128
175
|
|
|
129
|
-
|
|
130
|
-
them live):
|
|
176
|
+
### Gotchas in params
|
|
131
177
|
|
|
132
|
-
|
|
133
|
-
`
|
|
134
|
-
`
|
|
135
|
-
`
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
`
|
|
178
|
+
- **`sessions.list`** accepts `limit`, `offset`, `activeMinutes`,
|
|
179
|
+
`includeGlobal`, `includeUnknown`, `configuredAgentsOnly`,
|
|
180
|
+
`includeDerivedTitles`, `includeLastMessage`, `label`, `spawnedBy`,
|
|
181
|
+
`agentId`, `search` (+`archived` on 2026.7.x) — **not** `allAgents` (the CLI
|
|
182
|
+
flag is client-side aggregation). Pass `includeGlobal: true` to aggregate.
|
|
183
|
+
- **`sessions.get`** takes `{ key | sessionKey, limit?, agentId? }` (no strict
|
|
184
|
+
schema) → `{ messages }`; unknown keys return `{ messages: [] }`, not an
|
|
185
|
+
error. `sessions.preview({ keys, limit, maxChars })` returns `{ role, text }`
|
|
186
|
+
items but caps around 11 — use `sessions.get` for transcripts.
|
|
187
|
+
- **`agents.list`** accepts **no** extra params. The row is richer than it
|
|
188
|
+
used to be — `{ id, workspace, workspaceGit, agentRuntime, thinkingLevels,
|
|
189
|
+
thinkingOptions, thinkingDefault, model }` (verified live) — but identity
|
|
190
|
+
(`identityName`, emoji, bindings) is still CLI-enriched; fetch
|
|
191
|
+
`agents.files.get({ agentId, name: 'IDENTITY.md' })` yourself.
|
|
192
|
+
- **`agents.files.get`** uses `{ agentId, name }` — not `{ id, path }`.
|
|
193
|
+
- Scope errors return `INVALID_REQUEST` or `scope upgrade pending approval`
|
|
194
|
+
depending on the method's required scope.
|
|
139
195
|
|
|
140
|
-
|
|
141
|
-
`agents.files.{list,get,set}`.
|
|
196
|
+
### sessions.patch
|
|
142
197
|
|
|
143
|
-
|
|
198
|
+
Params (`additionalProperties: false`): `key` (+`agentId`) plus any of
|
|
199
|
+
`label`, `category`, `archived`, `pinned`, `unread`, `thinkingLevel`,
|
|
200
|
+
`fastMode`, `verboseLevel`, `traceLevel`, `reasoningLevel`, `responseUsage`,
|
|
201
|
+
`elevatedLevel`, `execHost`/`execSecurity`/`execAsk`/`execNode`, `model`,
|
|
202
|
+
`spawnedBy`, `spawnedWorkspaceDir`, `spawnedCwd`, `spawnDepth`,
|
|
203
|
+
`subagentRole`, `subagentControlScope`, `inheritedToolAllow`/`Deny`,
|
|
204
|
+
`sendPolicy`, `groupActivation`. Write scope covers the organizational fields
|
|
205
|
+
(`label`, `category`, `pinned`, `archived`, `unread`); the rest needs admin.
|
|
144
206
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
outside
|
|
207
|
+
`{ model, thinkingLevel }` is how moi applies the picker before each send
|
|
208
|
+
(both lines, verified live). The config's `agents.defaults.models` map is a
|
|
209
|
+
**model allowlist**: patching to a model outside it is rejected with
|
|
210
|
+
`INVALID_REQUEST` `model not allowed: <provider>/<model>` (verified live
|
|
211
|
+
against 2026.6.33).
|
|
148
212
|
|
|
149
|
-
|
|
213
|
+
#### Never patch the model straight into a send
|
|
150
214
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
215
|
+
`sessions.patch { model }` is **not** a session-local write: OpenClaw persists
|
|
216
|
+
the pick into the agent's effective `model.primary`, and that config write
|
|
217
|
+
bumps the prepared-model-runtime generation. A run admitted inside that window
|
|
218
|
+
is superseded and dies **during admission** — `sessions.send` still answers
|
|
219
|
+
`status: 'started'` with a runId, and the only thing that follows is
|
|
220
|
+
`sessions.changed { reason: 'chat.dispatch-error' }` (no runId to match on).
|
|
221
|
+
|
|
222
|
+
Captured on the wire against 2026.7.2-beta.7, first message of a new chat:
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
14:49:47.901 SEND sessions.patch { model, thinkingLevel, reasoningLevel }
|
|
226
|
+
14:49:47.930 RESP patch ok
|
|
227
|
+
14:49:47.930 SEND sessions.send ← same millisecond
|
|
228
|
+
14:49:47.946 RESP send status=started runId=88a7701d
|
|
229
|
+
14:49:49.959 EVT sessions.changed reason=chat.dispatch-error ← run dead, 2.0s later
|
|
230
|
+
14:49:58.641 SEND sessions.send (user resent) → ran fine
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The resend works because the model is already applied, so there is no second
|
|
234
|
+
config write. That is the whole shape of the bug: **first message of a new
|
|
235
|
+
chat fails, second always works.**
|
|
236
|
+
|
|
237
|
+
So moi carries the model **in `sessions.create`** instead (`session.ts →
|
|
238
|
+
sendOpenClawMessageImpl`) and marks it applied on the record so
|
|
239
|
+
`applySessionSettings` skips the model patch. Note the asymmetry that decides
|
|
240
|
+
what may ride along on create:
|
|
241
|
+
|
|
242
|
+
`sessions.create` takes `model` on both lines. It does **not** take
|
|
243
|
+
`thinkingLevel` on either — re-checked live on 2026.7.1, which answers
|
|
244
|
+
`invalid sessions.create params: at root: unexpected property 'thinkingLevel'`
|
|
245
|
+
(an earlier revision of this file recorded it as 2026.7-only, which was wrong).
|
|
246
|
+
Create validates with `additionalProperties: false`, so passing it would
|
|
247
|
+
hard-reject every new chat. Effort stays a patch — it is session-scoped, writes
|
|
248
|
+
no config, and so cannot supersede a run.
|
|
249
|
+
|
|
250
|
+
**Scope of the race.** Re-tested on the pinned 2026.7.1: `sessions.patch
|
|
251
|
+
{ model }` immediately followed by `sessions.send` completed normally, no
|
|
252
|
+
`chat.dispatch-error`. So this is a 2026.7.2-beta.x regression, not a property
|
|
253
|
+
of every line. moi keeps carrying the model in `sessions.create` anyway — it
|
|
254
|
+
costs nothing, the model belongs to the session from the start, and it is one
|
|
255
|
+
round-trip fewer on a new chat — but the workaround is for the NEXT line, not
|
|
256
|
+
this one.
|
|
257
|
+
|
|
258
|
+
**Thinking levels are per model, not gateway-global** (an earlier version of
|
|
259
|
+
this doc claimed otherwise and moi shipped one static list because of it).
|
|
260
|
+
The gateway resolves the menu from per-provider policies in the dist
|
|
261
|
+
(`provider-claude-thinking`, `moonshot-thinking`, …) and validates
|
|
262
|
+
`thinkingLevel` against the session's _resolved_ model, rejecting by name:
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
thinkingLevel "adaptive" is not supported for openai/gpt-5.6-sol
|
|
266
|
+
(use off|minimal|low|medium|high|xhigh|max|ultra)
|
|
267
|
+
thinkingLevel "minimal" is not supported for ollama/deepseek-v4-flash:cloud
|
|
268
|
+
(use off|low|medium|high|max)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Menus captured live from `sessions.list` rows on 2026.7.1-2:
|
|
272
|
+
|
|
273
|
+
| model | thinkingOptions | default |
|
|
274
|
+
| ------------------------------ | -------------------------------------------------- | ------- |
|
|
275
|
+
| openai/gpt-5.6-sol | off minimal low medium high xhigh max **ultra** | low |
|
|
276
|
+
| openai/gpt-5.6-terra | off minimal low medium high xhigh max **ultra** | medium |
|
|
277
|
+
| openai/gpt-5.6-luna | off minimal low medium high xhigh max | medium |
|
|
278
|
+
| anthropic/claude-opus-4-8 | off minimal low medium **adaptive** high xhigh max | off |
|
|
279
|
+
| ollama/kimi-k3:cloud | off low medium high max | off |
|
|
280
|
+
| ollama/deepseek-v4-flash:cloud | off low medium high max | off |
|
|
281
|
+
| openai/kimi-k3:cloud | off minimal low medium high | off |
|
|
282
|
+
|
|
283
|
+
So `adaptive` is Claude-only, `ultra` is OpenAI-only (and absent from luna),
|
|
284
|
+
the ollama models drop `minimal`/`xhigh`, and the same model id under two
|
|
285
|
+
providers gets two different menus. `thinkingDefault` varies too.
|
|
286
|
+
|
|
287
|
+
`models.list` carries only `reasoning: boolean` — no levels — **and even that
|
|
288
|
+
flag is not dependable**: on 2026.7.2-beta.7 the OpenAI rows come back with
|
|
289
|
+
`reasoning: undefined` while their session rows still advertise the full
|
|
290
|
+
`off…ultra` menu (verified live). Gating the effort picker on the flag alone
|
|
291
|
+
therefore makes it vanish for every GPT model on that line, so
|
|
292
|
+
`getOpenClawModels` also accepts a learned menu with more than one level as
|
|
293
|
+
proof the model reasons. There is no per-model thinking RPC either (`models.get`/`models.capabilities` don't exist;
|
|
294
|
+
`models.list` hard-rejects an `agentId` param). Every **session row** does
|
|
295
|
+
carry the resolved menu, so `thinking.ts` harvests rows (discovery
|
|
296
|
+
`sessions.list` + the row embedded in every live frame) into a per-model map
|
|
297
|
+
that feeds the picker, and relearns a model's menu from a rejection message
|
|
298
|
+
when one slips through. Models with no row yet fall back to the
|
|
299
|
+
cross-provider intersection `off low medium high`.
|
|
300
|
+
|
|
301
|
+
### reasoningLevel — the gate on reasoning output
|
|
302
|
+
|
|
303
|
+
`sessions.patch { reasoningLevel: 'off' | 'on' | 'stream' }`, **default
|
|
304
|
+
`off`**. In the dist, `reasoningMode = reasoningLevel ?? 'off'` and then
|
|
305
|
+
`includeReasoning: reasoningMode === 'on'`, `streamReasoning: reasoningMode
|
|
306
|
+
=== 'stream'`, both further gated on `canShowReasoning = thinkingLevel !==
|
|
307
|
+
'off'`. moi patches `reasoningLevel: 'stream'` whenever the picked effort is
|
|
308
|
+
not `off`, so a provider that can surface reasoning does.
|
|
309
|
+
|
|
310
|
+
Necessary but not sufficient — see §6 for which backends actually carry the
|
|
311
|
+
text. Note the side effect on a session that also serves a channel (a
|
|
312
|
+
Telegram-routed `agent:<a>:main`): reasoning mode is a session property, so
|
|
313
|
+
raising it changes what that channel streams too.
|
|
314
|
+
|
|
315
|
+
Config edits hot-reload where possible: the gateway watches `openclaw.json`
|
|
316
|
+
and logs `config hot reload applied (…)` vs `requires gateway restart (…)`
|
|
317
|
+
per key; CLI config writes print `Gateway restart required` when a key
|
|
318
|
+
doesn't hot-apply. Don't assume every config write needs a restart anymore —
|
|
319
|
+
but model-auth changes still resolve at startup.
|
|
168
320
|
|
|
169
321
|
### Detecting running sessions
|
|
170
322
|
|
|
171
323
|
`sessions.list` rows include `status` + `startedAt` / `endedAt` / `runtimeMs`
|
|
172
324
|
once a session has had at least one gateway run. `status === 'running'` is
|
|
173
325
|
the live discriminator; `abortedLastRun: true` means the last run was killed.
|
|
174
|
-
Rows for never-run sessions
|
|
175
|
-
assume they're present.
|
|
326
|
+
Rows for never-run sessions omit these fields entirely.
|
|
176
327
|
|
|
177
|
-
###
|
|
328
|
+
### Stopping a run
|
|
178
329
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
`
|
|
183
|
-
|
|
330
|
+
`sessions.abort({ key, runId? })`. Pass the specific `runId` to kill a
|
|
331
|
+
particular run; omit it to kill whatever's active. Returns `{ ok: true,
|
|
332
|
+
abortedRunId, status: 'aborted' | 'no-active-run' }`. `sessions.steer` is
|
|
333
|
+
`sessions.send` that interrupts the active run first (response carries
|
|
334
|
+
`interruptedActiveRun`).
|
|
335
|
+
|
|
336
|
+
## 6. Live events
|
|
337
|
+
|
|
338
|
+
One WebSocket connection: `sessions.subscribe({})` for the agent-wide
|
|
339
|
+
firehose, `sessions.messages.subscribe({ key })` per session. Events arrive
|
|
340
|
+
as `{ type: 'event', event, payload, seq? }` frames. moi refcounts the
|
|
341
|
+
per-session subscriptions (`gateway.ts`): the first live record subscribes a
|
|
342
|
+
key, later records reuse it, and the last one to tear down (idle eviction or
|
|
343
|
+
shutdown) `sessions.messages.unsubscribe({ key })`s it — best-effort, since a
|
|
344
|
+
dropped socket already unsubscribes server-side. On reconnect it re-subscribes
|
|
345
|
+
every key that still has a live holder. **Every session-scoped
|
|
346
|
+
event embeds a fresh session row** (`payload.session` and/or flattened
|
|
347
|
+
fields): `model`/`modelProvider`, `thinkingLevel` (+`thinkingLevels`),
|
|
348
|
+
`inputTokens`/`outputTokens`/`totalTokens`, `estimatedCostUsd`, `status`,
|
|
349
|
+
`origin`, `contextTokens`, `contextBudgetStatus.shouldCompact` — a free
|
|
350
|
+
state sync on every frame.
|
|
351
|
+
|
|
352
|
+
Families we consume (skeletons from live captures; wire shapes identical on
|
|
353
|
+
2026.7.1 and 2026.6.33 unless noted):
|
|
354
|
+
|
|
355
|
+
**`chat`** — token streaming. `message` is the cumulative partial (full
|
|
356
|
+
content blocks), `deltaText` just the increment:
|
|
357
|
+
|
|
358
|
+
```jsonc
|
|
359
|
+
{
|
|
360
|
+
"runId": "…",
|
|
361
|
+
"sessionKey": "agent:main:main",
|
|
362
|
+
"seq": 6,
|
|
363
|
+
"state": "delta", // delta | final | error | aborted
|
|
364
|
+
"deltaText": " moon is …",
|
|
365
|
+
"message": {
|
|
366
|
+
"role": "assistant",
|
|
367
|
+
"content": [{ "type": "text", "text": "The moon is …" }],
|
|
368
|
+
"timestamp": 0
|
|
369
|
+
},
|
|
370
|
+
"stopReason": "stop", // final/aborted ("rpc" on a steer interrupt)
|
|
371
|
+
"errorMessage": "…"
|
|
372
|
+
} // error only
|
|
373
|
+
```
|
|
184
374
|
|
|
185
|
-
|
|
375
|
+
**`session.message`** — durable transcript rows, pushed as they commit. The
|
|
376
|
+
`message` carries `__openclaw` meta (see §7), including **`seq` — the row's
|
|
377
|
+
position in the transcript**, mirrored as a top-level `messageSeq`. That number
|
|
378
|
+
is the only ordering authority: the gateway serializes its broadcasts behind a
|
|
379
|
+
promise queue (`server-session-events.ts` → `createTranscriptUpdateBroadcastHandler`,
|
|
380
|
+
"Preserve transcript update order even when counting messages requires an async
|
|
381
|
+
read"), but a frame can still be lost to a dropped socket and arrive later via
|
|
382
|
+
the reconcile. moi carries `seq` onto `Turn.seq`, and `lib/format.ts`
|
|
383
|
+
`applyEvent` places a new turn by it, so a late row lands where it belongs
|
|
384
|
+
rather than after the reply it preceded.
|
|
385
|
+
|
|
386
|
+
Rows without `__openclaw.id` are transient pre-envelope echoes — skip them; the
|
|
387
|
+
durable row follows.
|
|
388
|
+
|
|
389
|
+
Two things about this stream are easy to get wrong, and both were (verified
|
|
390
|
+
live on 2026.7.1 against `ollama-cloud/glm-5.2:cloud` and `openai/gpt-5.5`,
|
|
391
|
+
frame orders transcribed into `wire-replay.test.ts`):
|
|
392
|
+
|
|
393
|
+
- **`toolResult` rows do NOT stream.** In every capture the transcript ends up
|
|
394
|
+
with `user(1) · assistant(2) · toolResult(3) · assistant(4)` and the frames
|
|
395
|
+
delivered are seq 1, 2 and 4 — never 3. A tool's output reaches us live only
|
|
396
|
+
on the tool stream below; the run-end `sessions.get` reconcile is the
|
|
397
|
+
backstop, not a nicety.
|
|
398
|
+
- **A row can grow after it streams.** When a model fans out several calls at
|
|
399
|
+
once, the assistant row is pushed as text and its `toolCall` blocks are
|
|
400
|
+
attached afterwards, with no second frame. The live view therefore has a row
|
|
401
|
+
the transcript disagrees with, which is why the reconcile refreshes rows whose
|
|
402
|
+
content changed instead of only adopting ids it has never seen.
|
|
403
|
+
|
|
404
|
+
**`session.tool` and `agent`/`tool` are the same payload, split by audience —
|
|
405
|
+
not by backend.** This is the single most important fact about this stream, and
|
|
406
|
+
believing otherwise is what produced every duplicate-card bug this harness has
|
|
407
|
+
shipped. From `server-chat.ts`: the gateway sends `agent`/`tool` to the
|
|
408
|
+
connections registered as run-scoped tool recipients — the connection that
|
|
409
|
+
issued `sessions.send` — and mirrors the identical payload as `session.tool` to
|
|
410
|
+
every _other_ session subscriber, `excludeConnIds(sessionEventSubscribers,
|
|
411
|
+
runToolRecipients)`. The two audiences are disjoint by construction.
|
|
412
|
+
|
|
413
|
+
Demonstrated directly: two connections, same gateway, same run, one sends and
|
|
414
|
+
one only subscribes.
|
|
186
415
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
416
|
+
```
|
|
417
|
+
sender : agent/tool:start, agent/tool:update, agent/tool:result
|
|
418
|
+
observer: session.tool:start, session.tool:update, session.tool:result
|
|
419
|
+
```
|
|
190
420
|
|
|
191
|
-
|
|
421
|
+
So moi sees `agent`/`tool` for runs it starts and `session.tool` for everything
|
|
422
|
+
else — a channel message, a cron firing, another client, or a run already in
|
|
423
|
+
flight when it attached. `session.ts` routes both into one `handleToolFrame`.
|
|
424
|
+
Frame shape (`data.phase` `start`/`update`/`result`, full output inline):
|
|
425
|
+
|
|
426
|
+
```jsonc
|
|
427
|
+
{
|
|
428
|
+
"runId": "…",
|
|
429
|
+
"stream": "tool",
|
|
430
|
+
"sessionKey": "agent:main:main",
|
|
431
|
+
"data": {
|
|
432
|
+
"phase": "result", // start: name/toolCallId/args · update: +partialResult
|
|
433
|
+
"name": "exec",
|
|
434
|
+
"toolCallId": "call_y42lj8xv",
|
|
435
|
+
"isError": false,
|
|
436
|
+
"result": {
|
|
437
|
+
"content": [{ "type": "text", "text": "hello" }],
|
|
438
|
+
"details": { "status": "completed", "exitCode": 0, "durationMs": 228, "cwd": "/…" }
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
"session": {
|
|
442
|
+
/* fresh row */
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
```
|
|
192
446
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
`
|
|
447
|
+
**`agent`** — the raw run stream `{ runId, stream, seq, ts, data }`;
|
|
448
|
+
`stream` values: `assistant` (`{ text, delta }`, cumulative + increment;
|
|
449
|
+
`thinking` likewise), `item` (tool/item lifecycle `{ itemId, phase:
|
|
450
|
+
start|update|end, kind, status, name, toolCallId }`), `command_output`
|
|
451
|
+
(`{ output, phase: delta|end, exitCode?, durationMs?, cwd? }`), `lifecycle`
|
|
452
|
+
(phases `start` → `finishing` `{ stopReason, aborted }` → `end`, or `error`
|
|
453
|
+
`{ error }`, plus `fallback_step` when a model chain retries).
|
|
196
454
|
|
|
197
|
-
|
|
198
|
-
|
|
455
|
+
### Who owns a tool card
|
|
456
|
+
|
|
457
|
+
The durable owner row and the tool `start` frame race, and which wins decides
|
|
458
|
+
what renders. Measured on both providers, single call:
|
|
459
|
+
|
|
460
|
+
```
|
|
461
|
+
11891 session.message assistant seq=2 blocks=toolCall ← owner commits first
|
|
462
|
+
11895 agent/tool phase=start call_y42lj8xv ← 4ms later
|
|
463
|
+
11936 agent/tool phase=result call_y42lj8xv
|
|
464
|
+
13638 session.message assistant seq=4 blocks=text
|
|
199
465
|
```
|
|
200
466
|
|
|
201
|
-
|
|
202
|
-
`withOperatorApprovalsGatewayClient`, the `EventFrame` protocol type.
|
|
467
|
+
and the same run with three calls fanned out of one row:
|
|
203
468
|
|
|
204
|
-
|
|
469
|
+
```
|
|
470
|
+
30822 session.message assistant seq=2 blocks=text ← no toolCall blocks
|
|
471
|
+
30827 agent/tool phase=start call_d88i21w1 ← the only evidence
|
|
472
|
+
30831 agent/tool phase=start call_0f2nwkab these calls exist
|
|
473
|
+
30835 agent/tool phase=start call_p7i1myi5
|
|
474
|
+
34796 session.message assistant seq=6 blocks=text
|
|
475
|
+
```
|
|
205
476
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
477
|
+
So the rule is a question about the run, not about the backend: **does a
|
|
478
|
+
durable row own this call yet?** If yes, that row renders the card and the
|
|
479
|
+
frames only fill in its state. If no, the frame gets a card of its own
|
|
480
|
+
(`livetool:<toolCallId>`), placed just past the last durable row ingested, and
|
|
481
|
+
it keeps that call for the rest of the session — durable rows that later grow
|
|
482
|
+
the same block suppress it (adapter `omitToolCallIds`).
|
|
483
|
+
|
|
484
|
+
Ownership is decided once, at creation: `applyEvent` upserts by id and can never
|
|
485
|
+
retract, so a card that changes identity mid-run is a duplicate on screen
|
|
486
|
+
forever. Getting this wrong is what made every single-tool run render twice.
|
|
487
|
+
|
|
488
|
+
Tool ids were stable across `start`/`update`/`result`/durable in every capture,
|
|
489
|
+
on both providers.
|
|
490
|
+
|
|
491
|
+
**Run failures are reported on three frames.** A dying run says why on `chat`
|
|
492
|
+
`state:'error'` (`errorMessage`), on `agent`/`lifecycle` `phase:'error'`
|
|
493
|
+
(`data.error`), and as a bare `sessions.changed phase:'error'` with no text at
|
|
494
|
+
all — with three wordings (the raw reason, then a wrapped "⚠️ Agent failed
|
|
495
|
+
before reply: … Logs: openclaw logs --follow"). `reportRunError` takes the
|
|
496
|
+
first with text. The error rides on `chat`, which moi otherwise ignores when
|
|
497
|
+
token streaming is off, so failures are surfaced regardless of that toggle.
|
|
498
|
+
|
|
499
|
+
**Thinking blocks: who actually emits them.** The wire shape exists and moi
|
|
500
|
+
renders it — durable rows carry `{ type: 'thinking', thinking,
|
|
501
|
+
thinkingSignature }` and `adapter.ts` maps it to a `reasoning` part. What varies
|
|
502
|
+
is whether a model produces one at all, and this varies by MODEL and by the
|
|
503
|
+
config it runs under, not by a fixed backend taxonomy. Measured on 2026.7.1
|
|
504
|
+
with the default config:
|
|
505
|
+
|
|
506
|
+
| model | reasoning on the wire | text? |
|
|
507
|
+
| ---------------------------- | ---------------------------------------------------------- | ----- |
|
|
508
|
+
| `openai/gpt-5.5` | `agent`/`thinking` deltas, then a durable `thinking` block | YES |
|
|
509
|
+
| `ollama-cloud/glm-5.2:cloud` | nothing — the model writes its reasoning as plain text | n/a |
|
|
510
|
+
|
|
511
|
+
An earlier revision of this file claimed OpenAI models route through a codex
|
|
512
|
+
app-server that never carries reasoning text. That is not what the default
|
|
513
|
+
config does on 2026.7.1: `openai/gpt-5.5` streams the words on `agent`/`thinking`
|
|
514
|
+
and commits them durably, and no `codex_app_server.*` frame appears anywhere in
|
|
515
|
+
the capture. (`models status` reporting "openai via codex" is about which auth
|
|
516
|
+
store the credential comes from, not which runtime serves the turn.) Treat
|
|
517
|
+
"which runtime is behind this model" as a config question, not something to
|
|
518
|
+
infer from frames — and never gate rendering on the answer.
|
|
519
|
+
|
|
520
|
+
`reasoningLevel` (§5) stays set whenever the picked effort is not `off`: it is
|
|
521
|
+
the gateway's documented gate (`reasoningMode = reasoningLevel ?? 'off'`,
|
|
522
|
+
further gated on `canShowReasoning = thinkingLevel !== 'off'`), and a model that
|
|
523
|
+
can surface reasoning needs it.
|
|
524
|
+
|
|
525
|
+
Some runtimes report reasoning only as an `agent`/`item` frame of
|
|
526
|
+
`kind:'analysis'` — presence and timing, no text. `session.ts →
|
|
527
|
+
handleReasoningItemFrame` turns that into a textless `{ type: 'reasoning',
|
|
528
|
+
text: '', redacted: true, durationMs }` part, so such a run shows "Thinking" →
|
|
529
|
+
"Thought for 1.1s" instead of a silent gap. Like the live tool cards it is not
|
|
530
|
+
durable — nothing in the transcript backs it, so a cold reload drops the row.
|
|
531
|
+
|
|
532
|
+
**`task`** — subagent runs (2026.7.x; the event family is new there):
|
|
533
|
+
|
|
534
|
+
```jsonc
|
|
535
|
+
{
|
|
536
|
+
"action": "upserted",
|
|
537
|
+
"task": {
|
|
538
|
+
"kind": "subagent",
|
|
539
|
+
"status": "running", // → completed
|
|
540
|
+
"title": "…",
|
|
541
|
+
"sessionKey": "agent:main:main",
|
|
542
|
+
"childSessionKey": "agent:main:subagent:<uuid>",
|
|
543
|
+
"runId": "…"
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
```
|
|
213
547
|
|
|
214
|
-
|
|
548
|
+
**`session.operation`** — compaction:
|
|
549
|
+
`{ operationId, operation: 'compact', phase: 'start' | 'end', sessionKey,
|
|
550
|
+
completed?, ts }`.
|
|
551
|
+
|
|
552
|
+
**`presence` / `health`** — connected-device roster and a rich gateway
|
|
553
|
+
health blob (`eventLoop`, `plugins`, `channels`, `sessions`); useful for
|
|
554
|
+
liveness, ignored otherwise. `tick` is the heartbeat.
|
|
555
|
+
|
|
556
|
+
### Tool vocabulary is per runtime
|
|
557
|
+
|
|
558
|
+
One agent's tools change name and argument shape depending on which runtime
|
|
559
|
+
serves the model, and all of them arrive as `provider: 'openclaw'`. Captured on
|
|
560
|
+
2026.7.1:
|
|
561
|
+
|
|
562
|
+
| runtime | shell | edit | read |
|
|
563
|
+
| -------------------------- | ----------------------------- | --------------------------------------------- | -------------------------- |
|
|
564
|
+
| built-in loop | `exec` / `bash` `{ command }` | `edit` `{ path }` | `read` `{ path }` |
|
|
565
|
+
| codex (`extensions/codex`) | `bash` `{ command, cwd }` | `apply_patch` `{ changes: [{ path, kind }] }` | none — reads run as `bash` |
|
|
566
|
+
| `claude-cli` | `Bash` `{ command }` | `Edit` `{ file_path }` | `Read` `{ file_path }` |
|
|
567
|
+
|
|
568
|
+
So there is no Read card on a codex-backed run: the model reads by shelling out
|
|
569
|
+
(`bash -lc "sed -n '1,120p' notes.txt"`), and that is what the transcript
|
|
570
|
+
records. Nothing is being dropped.
|
|
571
|
+
|
|
572
|
+
The client's tool-card labels and briefs live in
|
|
573
|
+
`client/features/chat/tool-group/format.ts`; the OpenClaw path falls back to the
|
|
574
|
+
Claude Code vocabulary for the `claude-cli` case.
|
|
575
|
+
|
|
576
|
+
**`agent`/`item` frames are not a second source of tool cards.** They carry
|
|
577
|
+
`itemId`, `kind`, `title`, `status`, `summary`, `meta` — and **no `toolCallId`
|
|
578
|
+
and no `args`** (`AgentItemEventData` in `src/infra/agent-activity-events.ts`,
|
|
579
|
+
confirmed on the wire: every `command`/`patch` item frame arrives with
|
|
580
|
+
`toolCallId` absent). Every one of them is paired with a `tool` frame that has
|
|
581
|
+
both, a few milliseconds apart. moi renders from the `tool` frames and reads
|
|
582
|
+
item frames only for the textless `analysis` reasoning span.
|
|
583
|
+
|
|
584
|
+
### `sessions.changed`
|
|
585
|
+
|
|
586
|
+
Two flavors share the event name (both lines, verified live):
|
|
587
|
+
|
|
588
|
+
- **Run lifecycle**: `{ phase: 'start' | 'end' | 'error', runId, …row }` —
|
|
589
|
+
drives the busy flag.
|
|
590
|
+
- **Mutations**: `{ reason, …row }`. Observed live: `send`, `steer`,
|
|
591
|
+
`create`, `patch`, `compact`, `subagent-status`; the dist also emits
|
|
592
|
+
`new`, `delete`, `abort`, `cleanup` and friends — treat the set as open.
|
|
593
|
+
**`chat.title` is 2026.7.x-only** — zero emit sites in the 2026.6.33 dist,
|
|
594
|
+
so title refreshes on 6.x ride the other reasons.
|
|
595
|
+
|
|
596
|
+
## 7. Durable-row drift between the lines
|
|
597
|
+
|
|
598
|
+
Where 2026.7.x and 2026.6.x rows actually differ for us (all verified live
|
|
599
|
+
via `sessions.get` + `session.message` frames on both gateways):
|
|
600
|
+
|
|
601
|
+
| Field | 2026.7.x | 2026.6.x |
|
|
602
|
+
| ------------------------------------------ | ------------------------------------------------------- | ------------------------------------------------------------ |
|
|
603
|
+
| `<runId>:user` send idempotency key | `__openclaw.idempotencyKey` (+ mirrored on the message) | message-level `idempotencyKey` only |
|
|
604
|
+
| `__openclaw.senderIsOwner` | on user rows (`false` = channel inbound) | absent |
|
|
605
|
+
| `__openclaw.id` | 8-hex short hash | short hash on agent rows, uuid seen on gateway-injected rows |
|
|
606
|
+
| assistant `responseId` (`msg_…`) + `model` | both | both |
|
|
607
|
+
|
|
608
|
+
Treat `__openclaw.id` as an opaque string. `compat.ts →
|
|
609
|
+
messageIdempotencyKey` reads nested-then-flat so the user-echo rendezvous
|
|
610
|
+
matches on either line; text matching stays as the fallback.
|
|
611
|
+
|
|
612
|
+
## 8. Cron sessions
|
|
613
|
+
|
|
614
|
+
Anatomy (verified live against 2026.7.1): the job's session key is
|
|
615
|
+
`agent:<a>:cron:<jobId>` with label/displayName `Cron: <name>`; every firing
|
|
616
|
+
runs under a per-run key `agent:<a>:cron:<jobId>:run:<uuid>` with its own
|
|
617
|
+
`sessionId` (visible in `cron.runs` entries). The post-run session reset
|
|
618
|
+
**orphans the per-run transcript file** — `sessions.get` AND `chat.history`
|
|
619
|
+
return 0 messages for both the job key and the run key (verified live). The
|
|
620
|
+
readable record is `cron.runs`: entries carry `{ ts, jobId, action, status:
|
|
621
|
+
'ok' | 'error', summary, runId, durationMs, model, usage, sessionKey,
|
|
622
|
+
error? }`. Don't build cron transcript views on the session APIs.
|
|
623
|
+
|
|
624
|
+
## 9. Channel routing
|
|
625
|
+
|
|
626
|
+
With default routing an inbound channel DM (IRC, Telegram, …) lands in the
|
|
627
|
+
agent's **main** session `agent:<a>:main` — no new session. Verified live
|
|
628
|
+
against 2026.7.1 with a loopback IRC channel:
|
|
629
|
+
|
|
630
|
+
- The session row's `channel`/`lastChannel` flip to the provider and `origin`
|
|
631
|
+
absorbs the peer identity: `{ label: 'mole!mole@127.0.0.1', from:
|
|
632
|
+
'irc:mole!mole@127.0.0.1', to: 'irc:mole' }`; `deliveryContext` records the
|
|
633
|
+
reply route.
|
|
634
|
+
- `displayName` becomes the peer identity string — which **hijacks title
|
|
635
|
+
precedence** (label > displayName > derivedTitle > preview), so the chat
|
|
636
|
+
list suddenly shows `mole!mole@127.0.0.1` instead of the derived title.
|
|
637
|
+
- Per-message provenance is minimal: the inbound user row carries only
|
|
638
|
+
`__openclaw.senderIsOwner: false` (2026.7.x; 6.x rows have no marker), plus
|
|
639
|
+
the strippable inbound-metadata envelope in the text (see `strip.ts`).
|
|
640
|
+
|
|
641
|
+
## 10. Using the `openclaw` npm package
|
|
642
|
+
|
|
643
|
+
**Don't roll your own WS client.** The `openclaw` package publishes a
|
|
644
|
+
supported subpath export:
|
|
215
645
|
|
|
216
646
|
```ts
|
|
217
647
|
import { GatewayClient } from 'openclaw/plugin-sdk/gateway-runtime'
|
|
648
|
+
```
|
|
218
649
|
|
|
650
|
+
`GatewayClient` handles device-identity loading & signing, token auth, the
|
|
651
|
+
challenge-response handshake, reconnect backoff, heartbeat watch, and per-RPC
|
|
652
|
+
timeouts. `opts` is private — connect callbacks go to the constructor
|
|
653
|
+
(that's true on every version we support, not just 2026.7.x):
|
|
654
|
+
|
|
655
|
+
```ts
|
|
219
656
|
const client = new GatewayClient({
|
|
220
657
|
url: `ws://127.0.0.1:${port}`,
|
|
221
658
|
token, // from openclaw.json gateway.auth.token
|
|
222
659
|
role: 'operator',
|
|
223
660
|
scopes: ['operator.admin', 'operator.read', 'operator.write'],
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
661
|
+
// REQUIRED for live tool cards: the gateway registers a connection as a
|
|
662
|
+
// tool-event recipient only when it advertises this cap. Omit it and
|
|
663
|
+
// `session.tool` frames never arrive (the SDK defaults `caps` to `[]`).
|
|
664
|
+
caps: ['tool-events'],
|
|
665
|
+
// moi speaks wire protocol 4 (compat.ts). The SDK already defaults both to 4,
|
|
666
|
+
// so pinning them is self-documenting, not a behavior change.
|
|
667
|
+
minProtocol: 4,
|
|
668
|
+
maxProtocol: 4,
|
|
669
|
+
requestTimeoutMs: 2000,
|
|
670
|
+
onHelloOk: hello => {
|
|
671
|
+
/* parseHelloOk(hello) → GatewayInfo */
|
|
672
|
+
},
|
|
673
|
+
onConnectError: err => {
|
|
674
|
+
/* classifyGatewayError(err) */
|
|
675
|
+
},
|
|
676
|
+
onEvent: evt => {
|
|
677
|
+
/* { event, payload } frames */
|
|
678
|
+
}
|
|
231
679
|
})
|
|
232
|
-
|
|
680
|
+
client.start()
|
|
233
681
|
const result = await client.request('sessions.list', { includeGlobal: true })
|
|
234
682
|
client.stop()
|
|
235
683
|
```
|
|
236
684
|
|
|
685
|
+
moi builds these shared options once in `gateway.ts → gatewayClientBaseOptions`
|
|
686
|
+
and spreads them into both the persistent streaming client and the one-shot
|
|
687
|
+
discovery client, so both advertise `caps: ['tool-events']`.
|
|
688
|
+
|
|
237
689
|
Important: **always wrap `connect` in your own timeout**. `GatewayClient`
|
|
238
690
|
doesn't enforce one on the initial handshake (only on individual RPCs), so a
|
|
239
|
-
silent gateway will hang forever. We
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
- `
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
`server/openclaw.ts` — discovery helper with a 2 s timeout wrapper around both
|
|
283
|
-
connect and every RPC. Returns `OpenClawAgent[]` = `{ path, agentId, name?,
|
|
284
|
-
isDefault, lastRunAt? }`. Any failure (missing config, gateway down, timeout,
|
|
285
|
-
malformed response) → empty array, silently.
|
|
286
|
-
|
|
287
|
-
Pipeline:
|
|
288
|
-
|
|
289
|
-
1. Read `~/.openclaw/openclaw.json` for port + token (sync filesystem)
|
|
290
|
-
2. Lazy-import `GatewayClient` (keeps startup cost off the critical path if
|
|
291
|
-
the feature's unused)
|
|
292
|
-
3. Open one WS connection; wait for `onHelloOk` or 2 s timeout
|
|
293
|
-
4. **Round-trip 1** (parallel): `agents.list` + `sessions.list({ includeGlobal })`
|
|
294
|
-
5. **Round-trip 2** (parallel per agent): `agents.files.get(IDENTITY.md)`
|
|
295
|
-
6. Parse `- **Name:** ...` from the identity markdown; group
|
|
296
|
-
`sessions.list` rows by the `agent:<id>:…` key prefix for `lastRunAt`
|
|
297
|
-
7. Map to the `OpenClawAgent` shape; `stop()` the client
|
|
298
|
-
|
|
299
|
-
That's it — 2 round-trips to get everything we show on `/`.
|
|
300
|
-
|
|
301
|
-
## 8. Commands worth knowing
|
|
691
|
+
silent gateway will hang forever. We race a 2–5 s timer.
|
|
692
|
+
|
|
693
|
+
The package is **big** (~300+ transitive deps — channel plugins, provider
|
|
694
|
+
SDKs, the full CLI). For our case (the server already has lots of deps) the
|
|
695
|
+
subpath import wins over rolling a minimal client.
|
|
696
|
+
|
|
697
|
+
## 11. What our code does
|
|
698
|
+
|
|
699
|
+
`server/harness/openclaw/` — the harness. Module map:
|
|
700
|
+
|
|
701
|
+
- `gateway.ts` — one process-global `GatewayClient` (reconnect, subscription
|
|
702
|
+
replay, wire tap), config-path resolution, one-shot client for discovery,
|
|
703
|
+
and the last connect outcome for `/status` (`getOpenClawGatewayStatus`).
|
|
704
|
+
- `compat.ts` — protocol-4 tolerance layer: `parseHelloOk`,
|
|
705
|
+
`classifyGatewayError`, `messageIdempotencyKey`. Read its header before
|
|
706
|
+
sending any new param to the gateway.
|
|
707
|
+
- `thinking.ts` — per-model thinking menus learned from session rows, plus the
|
|
708
|
+
relearn-from-rejection path. The effort picker reads it (§5).
|
|
709
|
+
- `discovery.ts` — agents → workspace candidates, models catalog, transcript
|
|
710
|
+
seeds (2 round-trips: `agents.list` + `sessions.list`, then per-agent
|
|
711
|
+
`agents.files.get(IDENTITY.md)`).
|
|
712
|
+
- `session.ts` — live session records: `sessions.get` seed, `session.message`
|
|
713
|
+
ingest, `chat` → StreamPreview, tool frames → tool cards, `sessions.patch`
|
|
714
|
+
before sends, echo rendezvous, run-end reconcile, run-error reporting.
|
|
715
|
+
- `adapter.ts` — gateway rows/messages → moi turns; `strip.ts` — mirror of
|
|
716
|
+
upstream `strip-inbound-meta` (re-diff on every bump, see its header).
|
|
717
|
+
- `wire-replay.test.ts` — the frame orders a live gateway produces, replayed
|
|
718
|
+
through the real session code. **Record a run before changing how frames are
|
|
719
|
+
interpreted** (`docs/openclaw-sandbox.md` shows how), then transcribe what it
|
|
720
|
+
shows into a scenario there. Every ordering and duplication bug this harness
|
|
721
|
+
has shipped came from reasoning about frame order in the abstract; a
|
|
722
|
+
recording is the only thing that argues back.
|
|
723
|
+
|
|
724
|
+
Two rules the modules above depend on, both learned the hard way:
|
|
725
|
+
|
|
726
|
+
1. **Never branch on "which backend is this".** The frame families that look
|
|
727
|
+
backend-specific are audience-specific (§6), and which runtime serves a
|
|
728
|
+
model is a config choice. Ask about the state you actually have — does a
|
|
729
|
+
durable row own this call? — not about who is on the other end.
|
|
730
|
+
2. **A broadcast turn can be upserted but never retracted.** Any id a turn is
|
|
731
|
+
published under is permanent. Decide identity once, at creation.
|
|
732
|
+
|
|
733
|
+
## 12. Commands worth knowing
|
|
302
734
|
|
|
303
735
|
```
|
|
304
736
|
openclaw status # overview (gateway, agents, sessions, security)
|
|
305
737
|
openclaw agents list [--json] # agents + workspaces + bindings (CLI-enriched)
|
|
306
738
|
openclaw sessions --all-agents --json # aggregate sessions across agents (uses RPC)
|
|
307
739
|
openclaw logs --follow --json # tail gateway logs (WS if scoped, else /tmp file)
|
|
740
|
+
openclaw cron list --all # cron jobs incl. disabled; `cron runs` for history
|
|
308
741
|
openclaw devices list # pending + paired devices
|
|
309
742
|
openclaw devices approve <requestId> # needs admin scope (chicken-and-egg, see §3)
|
|
310
743
|
openclaw doctor # lint config, flag risky dm policies
|
|
@@ -312,5 +745,5 @@ openclaw dashboard # open Control UI with token in URL
|
|
|
312
745
|
```
|
|
313
746
|
|
|
314
747
|
`openclaw --dev` runs a completely isolated instance under `~/.openclaw-dev/`
|
|
315
|
-
on port `19001
|
|
316
|
-
|
|
748
|
+
on port `19001`. Same for `--profile <name>` (`~/.openclaw-<name>/`) — the
|
|
749
|
+
multi-version test rig in `docs/openclaw-sandbox.md` is built on profiles.
|