Skip to content

Commit 0474704

Browse files
authored
feat(control-ui): create and manage goals without slash commands (#131370)
* feat(control-ui): create and manage goals without slash commands * fix(control-ui): keep goal composer contracts acyclic * refactor(control-ui): tighten goal composer guidance * fix(goals): admit fresh and completed local sessions Create the first session with its Goal, input, run claim, and receipt in the existing transaction. Scope reply dispatch hooks consistently at admission and execution, and retain built-in runtime eligibility after completed turns. Preserve creator and lifecycle checks and cover the failures observed through the real Control UI flow. * fix(ui): preserve button names during fade-in * docs: defer Goal release notes to release generation
1 parent 240b485 commit 0474704

131 files changed

Lines changed: 5562 additions & 615 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ enum class GatewayMethod(
584584
SessionsSend("sessions.send"),
585585
SessionsAbort("sessions.abort"),
586586
SessionsPatch("sessions.patch"),
587+
SessionsGoalUpdate("sessions.goal.update"),
588+
SessionsGoalClear("sessions.goal.clear"),
587589
SessionsPluginPatch("sessions.pluginPatch"),
588590
SessionsCleanup("sessions.cleanup"),
589591
SessionsReset("sessions.reset"),

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8409,6 +8409,82 @@ public struct SessionDiscussionOpenResult: Codable, Sendable {
84098409
}
84108410
}
84118411

8412+
public struct SessionsGoalClearParams: Codable, Sendable {
8413+
public let sessionkey: String
8414+
public let agentid: String?
8415+
public let sessionid: String?
8416+
public let goalid: String
8417+
public let operationid: String
8418+
public let issuedatms: Int
8419+
8420+
public init(
8421+
sessionkey: String,
8422+
agentid: String? = nil,
8423+
sessionid: String? = nil,
8424+
goalid: String,
8425+
operationid: String,
8426+
issuedatms: Int)
8427+
{
8428+
self.sessionkey = sessionkey
8429+
self.agentid = agentid
8430+
self.sessionid = sessionid
8431+
self.goalid = goalid
8432+
self.operationid = operationid
8433+
self.issuedatms = issuedatms
8434+
}
8435+
8436+
private enum CodingKeys: String, CodingKey {
8437+
case sessionkey = "sessionKey"
8438+
case agentid = "agentId"
8439+
case sessionid = "sessionId"
8440+
case goalid = "goalId"
8441+
case operationid = "operationId"
8442+
case issuedatms = "issuedAtMs"
8443+
}
8444+
}
8445+
8446+
public struct SessionsGoalMutationResult: Codable, Sendable {
8447+
public let operationid: String
8448+
public let action: AnyCodable
8449+
public let sessionid: String
8450+
public let goalid: String
8451+
public let goal: [String: AnyCodable]?
8452+
public let runid: String?
8453+
public let replayed: Bool?
8454+
public let status: AnyCodable
8455+
8456+
public init(
8457+
operationid: String,
8458+
action: AnyCodable,
8459+
sessionid: String,
8460+
goalid: String,
8461+
goal: [String: AnyCodable]? = nil,
8462+
runid: String? = nil,
8463+
replayed: Bool? = nil,
8464+
status: AnyCodable)
8465+
{
8466+
self.operationid = operationid
8467+
self.action = action
8468+
self.sessionid = sessionid
8469+
self.goalid = goalid
8470+
self.goal = goal
8471+
self.runid = runid
8472+
self.replayed = replayed
8473+
self.status = status
8474+
}
8475+
8476+
private enum CodingKeys: String, CodingKey {
8477+
case operationid = "operationId"
8478+
case action
8479+
case sessionid = "sessionId"
8480+
case goalid = "goalId"
8481+
case goal
8482+
case runid = "runId"
8483+
case replayed
8484+
case status
8485+
}
8486+
}
8487+
84128488
public struct SessionsCompactionListParams: Codable, Sendable {
84138489
public let key: String
84148490
public let agentid: String?
@@ -20705,6 +20781,7 @@ public struct ChatSendParams: Codable, Sendable {
2070520781
public let agentid: String?
2070620782
public let sessionid: String?
2070720783
public let message: String
20784+
public let intent: [String: AnyCodable]?
2070820785
public let thinking: String?
2070920786
public let fastmodevalue: AnyCodable?
2071020787
public var fastmode: Bool? { fastmodevalue?.value as? Bool }
@@ -20731,6 +20808,7 @@ public struct ChatSendParams: Codable, Sendable {
2073120808
agentid: String? = nil,
2073220809
sessionid: String? = nil,
2073320810
message: String,
20811+
intent: [String: AnyCodable]? = nil,
2073420812
thinking: String? = nil,
2073520813
fastmodevalue: AnyCodable? = nil,
2073620814
fastautoonseconds: Int? = nil,
@@ -20755,6 +20833,7 @@ public struct ChatSendParams: Codable, Sendable {
2075520833
self.agentid = agentid
2075620834
self.sessionid = sessionid
2075720835
self.message = message
20836+
self.intent = intent
2075820837
self.thinking = thinking
2075920838
self.fastmodevalue = fastmodevalue
2076020839
self.fastautoonseconds = fastautoonseconds
@@ -20781,6 +20860,7 @@ public struct ChatSendParams: Codable, Sendable {
2078120860
agentid: String? = nil,
2078220861
sessionid: String? = nil,
2078320862
message: String,
20863+
intent: [String: AnyCodable]? = nil,
2078420864
thinking: String? = nil,
2078520865
fastmode: Bool?,
2078620866
queuemode: String? = nil,
@@ -20805,6 +20885,7 @@ public struct ChatSendParams: Codable, Sendable {
2080520885
agentid: agentid,
2080620886
sessionid: sessionid,
2080720887
message: message,
20888+
intent: intent,
2080820889
thinking: thinking,
2080920890
fastmodevalue: fastmode.map { AnyCodable($0) },
2081020891
fastautoonseconds: nil,
@@ -20831,6 +20912,7 @@ public struct ChatSendParams: Codable, Sendable {
2083120912
case agentid = "agentId"
2083220913
case sessionid = "sessionId"
2083320914
case message
20915+
case intent
2083420916
case thinking
2083520917
case fastmodevalue = "fastMode"
2083620918
case fastautoonseconds = "fastAutoOnSeconds"

‎docs/plugins/hooks.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ modifications explicitly instead of relying on in-place mutation.
194194
| `registrationId` | Stable identity for one registration inside a plugin. Skill evaluators use it as `evaluatorId`; otherwise the plugin id is used. |
195195
| `timeoutMs` | Per-handler asynchronous await budget. Expiry applies the hook's failure policy below; it does not cancel the handler or its side effects. Omit to use the runner's default, if any. |
196196
| `eligibleTriggers` | For `before_agent_reply` only, limits host dispatch to one or more of `cron`, `heartbeat`, or `user`. |
197+
| `eligibleDispatchKinds` | For `reply_dispatch` only, limits host dispatch to `agent`, `acp`, or both. Omit to handle all dispatch kinds. |
197198
| `requiresToolAuthority` | For `before_prompt_build` only, runs the handler after the host finalizes the current turn's tool surface and supplies ephemeral `ctx.toolAuthority`. Use this for context retrieval that must follow tool policy. |
198199

199200
Trigger eligibility is enforced by the host before it invokes the handler. A
@@ -1019,6 +1020,16 @@ message context and a host dispatcher, and a handled result reports
10191020
`queuedFinal` and delivery `counts`. Use `before_agent_reply` for a simple
10201021
synthetic reply, and the sending hooks below to transform outgoing payloads.
10211022

1023+
Use `eligibleDispatchKinds: ["acp"]` for an ACP-only dispatcher. The host
1024+
classifies the resolved target, including conversation bindings, and passes
1025+
`ctx.dispatchKind` as `acp` or `agent`. Stored ACP metadata and ACP session keys
1026+
both select `acp`; a missing ACP binding does not fall back to agent dispatch.
1027+
The host applies the same eligibility check before invocation and when deciding
1028+
whether a hook prevents durable chat admission. An ACP-only hook therefore
1029+
does not block ordinary agent sessions. Omitted, empty, malformed, or partly
1030+
unknown eligibility lists remain unrestricted. Missing or unknown dispatch
1031+
context also keeps the hook eligible.
1032+
10221033
Use message hooks for channel-level routing and delivery policy:
10231034

10241035
- `message_received`: observe inbound content, sender, `threadId`,

‎docs/reference/database-schemas.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ safely.
5252

5353
Installing OpenClaw manually through npm bypasses the updater guard. Database open checks still refuse an incompatible build.
5454

55+
Structured [Goal controls](/tools/goal#gateway-requests-and-retries) use a lazy
56+
per-agent `session_goal_operations` table without changing the schema version.
57+
Goal start/resume commits the Goal transition, input turn, run lifecycle, and
58+
operation receipt in one transaction. Management operations commit the Goal
59+
transition and receipt together. Older readers ignore the added table.
60+
Receipts survive Goal clear and session reset/deletion until their 24-hour
61+
validity expires; later Goal writes prune expired rows. They retain the
62+
original result and a keyed request fingerprint, not a second raw request.
63+
There is no backfill or configuration switch. Downgrading preserves the table
64+
but disables the new structured controls; upgrading can read retained receipts.
65+
5566
## Review checkpoint for material changes
5667

5768
Before implementing a material SQLite or persistent-store change, open or link a maintainer discussion and record acceptance of the design. A schema-version bump is always material, but a change can be material even when the numeric version stays the same.

‎docs/tools/goal.md‎

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ read_when:
55
- You want OpenClaw to keep one objective visible across a long session
66
- You need to pause, resume, block, complete, or clear a session goal
77
- You want to understand the get_goal, create_goal, and update_goal tools
8-
- You want to see how goals appear in the TUI
8+
- You want to use the Goal composer in the Control UI or see goals in the TUI
99
title: "Goal"
1010
---
1111

@@ -164,22 +164,71 @@ so an operator stop remains in effect until the goal is resumed.
164164

165165
## Control UI
166166

167+
Select **Goal** from the command picker, type the objective, and send. The
168+
composer shows a Goal label so you can see what Send will do. The objective is
169+
literal text: words such as `clear` and text such as `/stop` do not become
170+
commands in Goal mode. Cancel leaves the objective as a normal chat draft.
171+
172+
Starting a Goal saves the Goal, its user turn, and the run admission together
173+
before acknowledging Send. A failed admission leaves the draft intact and
174+
does not create a Goal. Start and Resume require an idle local session with
175+
recoverable history; they are not queued or steered into another run. The UI
176+
reports unsupported or busy sessions rather than creating an inactive Goal.
177+
167178
The web Control UI shows the goal as a compact pill above the chat composer:
168179
a status icon, the status label (for example `Pursuing goal`), the truncated
169180
objective, and a live elapsed timer.
170181

171182
The pill carries inline controls:
172183

173-
- **Pencil** prefills the composer with `/goal edit <objective>` so the
174-
objective can be reworded and submitted.
175-
- **Pause / resume** toggles between `/goal pause` and `/goal resume` based
176-
on the current status.
177-
- **Trash** sends `/goal clear`.
184+
- **Pencil** opens an Edit Goal composer with the current objective. Saving
185+
changes only the objective; cancelling restores the previous chat draft.
186+
- **Pause / resume** updates the current Goal. Resume also starts a continuation
187+
through normal chat admission. Its internal input stays in model history
188+
without appearing as a human chat message; the assistant reply remains visible.
189+
- **Trash** clears the current Goal.
178190
- **Chevron** expands the pill to show the full objective, the latest status
179191
note, token usage, and elapsed time.
180192

181-
The action buttons are hidden while the composer cannot send (for example
182-
when the gateway connection is down); the expand chevron keeps working.
193+
Edit, Pause, and Clear do not send slash commands or add chat turns. Controls
194+
target the displayed Goal ID, so a stale button cannot change a replacement
195+
Goal. If a request is interrupted, retry it unchanged; a successful replay
196+
refreshes the current state instead of restoring an old Goal snapshot.
197+
198+
The action buttons are unavailable without a connection; the expand chevron
199+
keeps working. Concurrent Goal actions are rejected while an operation is
200+
pending. These controls require
201+
a Gateway advertising the structured Goal capability. Text `/goal` commands
202+
remain available for CLI and other command-capable surfaces.
203+
204+
### Gateway requests and retries
205+
206+
Goal start uses `chat.send` with the ordinary `message` as the objective and
207+
`intent: { kind: "session-goal-start", version: 1, issuedAtMs }`. It keeps the
208+
normal `idempotencyKey`, attachment, and reply fields. Per-request runtime or
209+
delivery-route overrides are rejected; Goal work uses the session settings and
210+
local delivery so recovery keeps the same contract. Objectives
211+
must contain non-whitespace text and are limited to 16,000 characters.
212+
213+
`sessions.goal.update` accepts `edit` with `objective`, or `pause`, `resume`,
214+
`block`, and `complete` with an optional `note` of at most 2,000 characters.
215+
`sessions.goal.clear` removes the Goal. Both methods require `sessionKey`,
216+
`goalId`, `operationId`, and `issuedAtMs`; `agentId` and `sessionId` can pin the
217+
target. They require normal session participation and `operator.write` scope.
218+
219+
Keep the original operation ID, timestamp, target, and payload for retries.
220+
Receipts remain valid for 24 hours from `issuedAtMs`; timestamps more than
221+
five minutes ahead of the Gateway clock are rejected. Reusing an ID with a
222+
different request is rejected. Expired requests cannot recreate a cleared
223+
Goal. The per-session limit is 4,096 unexpired receipts; hitting it rejects
224+
new operations until receipts expire rather than evicting valid retry state.
225+
226+
Results include `operationId`, `action`, `sessionId`, `goalId`, and `status`
227+
(`started`, `updated`, or `cleared`), plus the resulting `goal` when present
228+
and `runId` for start/resume. A replay adds `replayed: true`: this is the
229+
original operation result, not the current Goal state. Refresh the session
230+
after replay. Receipts prevent duplicate Goal mutations and input turns;
231+
they do not promise exactly-once external tool or provider effects.
183232

184233
## TUI
185234

‎extensions/acpx/index.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe("acpx plugin", () => {
6868
expect(api.registerService).toHaveBeenCalledWith(service);
6969
expect(api.on).toHaveBeenCalledWith("reply_dispatch", expect.any(Function), {
7070
timeoutMs: 120_000,
71+
eligibleDispatchKinds: ["acp"],
7172
});
7273
});
7374

@@ -86,6 +87,7 @@ describe("acpx plugin", () => {
8687

8788
expect(api.on).toHaveBeenCalledWith("reply_dispatch", expect.any(Function), {
8889
timeoutMs: 180_000,
90+
eligibleDispatchKinds: ["acp"],
8991
});
9092
});
9193

‎extensions/acpx/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const plugin = {
6060
api.on(
6161
"reply_dispatch",
6262
(event, ctx) => tryDispatchAcpReplyHookWithTimeout(event, ctx, replyDispatchTimeoutMs),
63-
{ timeoutMs: replyDispatchTimeoutMs },
63+
{ timeoutMs: replyDispatchTimeoutMs, eligibleDispatchKinds: ["acp"] },
6464
);
6565
},
6666
};

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export {
2929
export * from "./schema/session-classification.js";
3030
export * from "./schema/sessions-suggestions.js";
3131
export * from "./schema/sessions-delete.js";
32+
export * from "./schema/sessions-goal.js";
3233
export {
3334
SESSION_CREATE_IDEMPOTENCY_RETENTION_MS,
3435
SESSION_CREATE_RETRY_WINDOW_MS,

‎packages/gateway-protocol/src/public-schema.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Explicit schema exports keep public protocol changes reviewable.
2+
export * from "./schema/sessions-goal.js";
23
export {
34
isCloudWorkerPlacementState,
45
ConnectParamsSchema,

‎packages/gateway-protocol/src/schema/logs-chat.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,20 @@ const RunToolBindingsSchema = Type.Record(
139139
const QUEUE_MODES = ["steer", "followup", "collect", "interrupt"] as const;
140140
export type QueueMode = (typeof QUEUE_MODES)[number];
141141

142+
export const ChatSendIntentSchema = closedObject({
143+
kind: Type.Literal("session-goal-start"),
144+
version: Type.Literal(1),
145+
issuedAtMs: Type.Integer({ minimum: 0 }),
146+
});
147+
export type ChatSendIntent = Static<typeof ChatSendIntentSchema>;
148+
142149
/** User-to-agent send request; idempotency key lets clients safely retry transport failures. */
143150
export const ChatSendParamsSchema = closedObject({
144151
sessionKey: ChatSendSessionKeyString,
145152
agentId: Type.Optional(NonEmptyString),
146153
sessionId: Type.Optional(NonEmptyString),
147154
message: Type.String(),
155+
intent: Type.Optional(ChatSendIntentSchema),
148156
thinking: Type.Optional(Type.String()),
149157
fastMode: Type.Optional(Type.Union([Type.Boolean(), Type.Literal("auto")])),
150158
// One-turn override for auto fast-mode cutoff seconds.

0 commit comments

Comments
 (0)