Skip to content

Commit 08b1343

Browse files
authored
feat: continue web sessions in the terminal (#122870)
* feat: continue sessions in terminal Add a credential-free Control UI continuation command and allow openclaw resume to reuse current-profile authentication only for byte-exact configured Gateway targets. * fix(gateway): separate public origin TLS ownership Allow exact public-origin resume targets to reuse local authentication without inheriting the direct local listener certificate fingerprint. * fix(gateway): scope exact targets to gateway mode Prevent remote profiles from reusing dormant local Gateway authentication for explicit loopback or public-origin targets. * fix(cli): encode terminal resume handoffs Replace shell-specific quoting with a strict credential-free base64url handoff, gate configured auth reuse to validated handoffs, and skip unused session discovery. * fix(gateway): isolate handoff auth identity Suppress ambient Gateway auth fallback for validated handoffs while preserving explicit credentials, configured SecretRefs, stored device auth, and exact-target TLS ownership. * fix(cli): harden terminal resume handoffs * fix(cli): parse terminal handoff outcomes * fix(cli): bind handoffs to resolved agent * test(ui): align terminal continuation proof * docs(plan): track terminal continuation * refactor(ui): keep terminal handoff result local
1 parent 52cda53 commit 08b1343

31 files changed

Lines changed: 2084 additions & 116 deletions

‎docs/cli/resume.md‎

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ the Gateway; `resume` selects it and opens the existing [TUI](/cli/tui).
1515
```bash
1616
openclaw resume
1717
openclaw resume <query>
18+
openclaw resume --handoff <payload>
1819
```
1920

2021
With no query, OpenClaw displays up to 50 sessions active in the last seven
@@ -33,23 +34,80 @@ status 1. If no recent session matches, it suggests the picker and
3334

3435
| Flag | Default | Description |
3536
| ---------------------------- | -------------------------------- | ------------------------------------------------------------------- |
37+
| `--handoff <payload>` | (none) | Opaque session key and Gateway URL copied from the Control UI. |
3638
| `--url <url>` | `gateway.remote.url` from config | Gateway WebSocket URL. |
3739
| `--token <token>` | (none) | Gateway token if required. |
3840
| `--password <pass>` | (none) | Gateway password if required. |
3941
| `--tls-fingerprint <sha256>` | `gateway.remote.tlsFingerprint` | Expected TLS certificate fingerprint for a pinned `wss://` Gateway. |
4042

41-
`resume` uses the same Gateway URL, authentication, and TLS resolution as
42-
[`openclaw tui`](/cli/tui). It never starts a Gateway automatically. If the
43-
configured Gateway is unavailable, start or repair it and rerun the command.
43+
`--handoff` cannot be combined with a positional query or `--url` because it
44+
authoritatively supplies both. You can combine it with `--token`, `--password`,
45+
and `--tls-fingerprint`; those explicit authentication values keep their normal
46+
highest priority.
47+
48+
`resume` never starts a Gateway automatically. If the configured Gateway is
49+
unavailable, start or repair it and rerun the command.
4450

4551
`resume` resolves configured Gateway auth SecretRefs for token/password auth
4652
when possible (`env`/`file`/`exec`/`store` providers).
4753

48-
Gateway target precedence is explicit `--url`, then `OPENCLAW_GATEWAY_URL`,
49-
then `gateway.remote.url` when `gateway.mode` is `remote`, then the local
50-
loopback Gateway. For that local Gateway, `OPENCLAW_GATEWAY_PORT` takes
51-
precedence over the active port recorded by a running Gateway, which takes
52-
precedence over the configured or default `gateway.port`.
54+
When present, `--handoff` supplies the target Gateway URL. Otherwise, Gateway
55+
target precedence is explicit `--url`, then `OPENCLAW_GATEWAY_URL`, then
56+
`gateway.remote.url` when `gateway.mode` is `remote`, then the local loopback
57+
Gateway. For that local Gateway, `OPENCLAW_GATEWAY_PORT` takes precedence over
58+
the active port recorded by a running Gateway, which takes precedence over the
59+
configured or default `gateway.port`.
60+
61+
An explicit target normally requires an explicit `--token` or `--password`;
62+
OpenClaw does not borrow credentials or a TLS pin from a different configured
63+
target. `resume` has one narrow exception for a handoff copied from the Control
64+
UI: when its Gateway URL byte-for-byte matches a canonical target of the current
65+
profile, it may reuse that profile's configured interactive auth, SecretRef,
66+
and stored exact-origin device auth. In local mode, the eligible targets are the
67+
current local target with `gateway.controlUi.basePath` and `gateway.publicOrigin`
68+
converted to WebSocket form with that base path. In remote mode, only the exact
69+
`gateway.remote.url` is eligible. TLS pin ownership is narrower: an exact
70+
direct-local target may reuse the
71+
local Gateway certificate fingerprint, and an exact configured remote target
72+
may reuse `gateway.remote.tlsFingerprint`; a public-origin target never inherits
73+
the local listener's pin. Pass `--tls-fingerprint` explicitly when that public
74+
origin needs a pin. A host, port, path, profile, query, or fragment mismatch
75+
fails closed under the normal explicit-target policy. OpenClaw never scans
76+
other profiles for a match. Handoff connections also ignore ambient
77+
`OPENCLAW_GATEWAY_TOKEN` and `OPENCLAW_GATEWAY_PASSWORD` fallback, so shell
78+
credentials for another Gateway cannot cross into the selected target. Explicit
79+
flags and credentials owned by an exact configured target remain eligible.
80+
81+
## Continue from the Control UI
82+
83+
Open the selected session's header menu and choose **Continue in terminal…**.
84+
The dialog shows one copyable `openclaw resume --handoff <payload>` command.
85+
The opaque payload is versioned, bounded, and encoded with an unpadded URL-safe
86+
base64 alphabet, so the command needs no quoting and is safe to paste in common
87+
POSIX shells, PowerShell, and `cmd.exe`. The encoded argument is limited to 4096
88+
characters; inside it, the agent-qualified session key is limited to 512
89+
user-perceived characters and the Gateway URL to 2048 characters. It contains
90+
only the exact qualified session key and selected Gateway WebSocket URL,
91+
including any Control UI base path. It contains no token, password, device
92+
credential, or bootstrap credential, and the browser does not execute it.
93+
94+
The Control UI does not offer this command when the selected Gateway URL uses a
95+
query string. Gateway authentication and stored device scope are origin-based,
96+
not query-aware, so OpenClaw never strips or copies that query into a
97+
credential-free handoff. Use a manually authenticated CLI target with explicit
98+
`--token` or `--password`, or configure a queryless Gateway URL.
99+
100+
Run the command in an already configured OpenClaw terminal. The terminal
101+
authenticates independently. Before opening the TUI, `resume` asks that Gateway
102+
to resolve the qualified key and uses the returned canonical key. A deleted or
103+
stale session stops with guidance to copy a fresh command; it never starts a new
104+
session. The Gateway's session access controls remain authoritative. This flow
105+
continues an existing session; it does not delegate first-use authentication
106+
from the browser.
107+
108+
If OpenClaw reports an invalid `--handoff` payload, return to the session's
109+
Control UI menu and copy a fresh command. Do not edit or reuse a truncated
110+
payload.
53111

54112
## Examples
55113

@@ -65,6 +123,9 @@ openclaw resume bugfix
65123

66124
# Remote Gateway override
67125
openclaw resume bugfix --url wss://gateway.example.com --token <token>
126+
127+
# Opaque command copied from the Control UI
128+
openclaw resume --handoff <payload>
68129
```
69130

70131
## Related

‎docs/concepts/session-attachment.md‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,31 @@ separately when first pairing with a Gateway origin.
9999

100100
### Continue in the terminal
101101

102-
For Gateway-backed continuation, pass the URL or reference to `openclaw tui`:
102+
From the Control UI, open the session header menu and choose **Continue in
103+
terminal…**. The dialog copies a credential-free `openclaw resume` command with
104+
one opaque, versioned handoff argument. The argument encodes only the exact
105+
agent-qualified session key and selected Gateway WebSocket URL. The key is
106+
bounded to 512 user-perceived characters. Its URL-safe alphabet needs no shell
107+
quoting, so the command is safe to paste in common POSIX shells, PowerShell, and
108+
`cmd.exe`. Run it in an OpenClaw CLI profile that is already configured for that
109+
Gateway; the terminal authenticates independently. The Gateway canonicalizes
110+
the key before the TUI attaches, and a missing session produces recovery
111+
guidance instead of creating another session. The session ACL still applies.
112+
113+
Query-routed Gateway URLs cannot produce this credential-free command because
114+
Gateway authentication and stored device scope are not query-aware. The Control
115+
UI does not strip or copy the query. Use a manually authenticated CLI target
116+
with explicit `--token` or `--password`, or configure a queryless Gateway URL.
117+
118+
You can also choose or query a recent session directly:
119+
120+
```bash
121+
openclaw resume
122+
openclaw resume agent:main:deploy-monitor
123+
```
124+
125+
For Gateway-backed continuation from a URL or short reference, pass the target
126+
to `openclaw tui`:
103127

104128
```bash
105129
openclaw tui https://claw.example.com/dashboard/main/deploy-monitor-6db92d48
@@ -136,7 +160,21 @@ launch options.
136160

137161
A URL or gateway shorthand authoritatively selects one normalized Gateway
138162
origin. OpenClaw never reuses configured credentials or a stored device token
139-
from another origin for that target.
163+
from another origin for that target. The credential-free command copied by
164+
**Continue in terminal…** has a narrower rule: `openclaw resume` may reuse the
165+
current CLI profile only when its explicit WebSocket URL byte-for-byte matches
166+
that profile's mode: local and public-origin targets are eligible only in local
167+
mode, while only `gateway.remote.url` is eligible in remote mode. It never
168+
searches other profiles, and any host, port, or path mismatch returns to the
169+
normal explicit-credential requirement. Exact direct-local targets may reuse
170+
the local listener's certificate fingerprint, and exact configured remote
171+
targets may reuse the configured remote pin. A public-origin target does not
172+
inherit the local listener's pin; pass `--tls-fingerprint` explicitly if that
173+
proxy origin needs one. The payload contains no credentials; explicit `--token`,
174+
`--password`, or `--tls-fingerprint` values supplied beside the handoff still
175+
take priority. Handoff resolution suppresses ambient
176+
`OPENCLAW_GATEWAY_TOKEN` and `OPENCLAW_GATEWAY_PASSWORD` fallback while keeping
177+
those explicit values and exact-target configured credentials eligible.
140178

141179
On first contact:
142180

@@ -150,6 +188,13 @@ On first contact:
150188
4. Later connections to the same origin can use the stored device token. An
151189
explicit `--token` or `--password` always wins for the entire connection.
152190

191+
The Control UI continuation command does not perform these first-contact steps
192+
or carry their credentials. Configure or pair the terminal independently before
193+
using it. If the CLI rejects an invalid or truncated handoff, copy a fresh
194+
command from the Control UI instead of editing the opaque argument. If the
195+
session was deleted after the command was copied, return to the Control UI and
196+
copy a command from an available session.
197+
153198
Revoke or remove the device from the same Gateway's **Devices** page when that
154199
client should no longer connect. Tokens do not cross origins. Read-only probes
155200
through an SSH tunnel also suppress stored device auth because the loopback

‎docs/plan/runners.md‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ advances a milestone.
1919
| 1a | Naming: session copy revert | landed | #120667 |
2020
| 1b | Naming: devices consolidation | landed | #120689 |
2121
| 1c | Cleanup: node-pairing → device-pairing merge | landed | #120726 |
22-
| 2 | `openclaw resume` + web Continue in terminal | in progress | #120664 |
22+
| 2 | `openclaw resume` + web Continue in terminal | in progress | #120664, #122870 |
2323
| 3 | `openclaw connect` one-paste onboarding + `/j/` join route | in progress | #120768, #122499 |
2424
| 4 | Picker: grouping, placement, liveness, enrichment | in progress | #120804, #122531, #122635, #122774 |
2525
| F | Real-wire session boundary harness | landed | #121212 |
@@ -386,8 +386,27 @@ Independently mergeable PR series; 3–5 can interleave after 1c.
386386

387387
1. **1c naming cleanup**: finish nodes → devices in route ids, i18n keys,
388388
labels; `node-pairing.ts` facade merge. Before any new placement copy.
389-
2. **Continuation ergonomics** (in progress): `openclaw resume`, web
390-
"Continue in terminal".
389+
2. **Continuation ergonomics** (in progress): `openclaw resume` plus the web
390+
**Continue in terminal…** session action. The browser copies one
391+
credential-free command with one bounded, versioned, URL-safe handoff
392+
argument that encodes the exact qualified session key and selected Gateway
393+
WebSocket URL without shell-specific quoting. The key is agent-qualified and
394+
bounded to 512 user-perceived characters. Query-routed Gateway URLs are
395+
intentionally excluded because authentication and stored device scope are
396+
not query-aware; the UI never strips or copies the query and instead directs
397+
operators to a manually authenticated target or queryless configured URL. It
398+
never executes the CLI or delegates first-use authentication. Before attach,
399+
Resume asks the Gateway to resolve the key, uses only the returned canonical
400+
key, and rejects a missing or ambiguous handoff without starting another
401+
session. Resume may reuse only the current
402+
profile's auth, SecretRefs, and exact-origin device auth when the handoff URL
403+
byte-for-byte matches a target owned by the configured mode: local + Control
404+
UI base path or public origin + base path in local mode, and only the remote
405+
URL in remote mode. TLS pin reuse is limited to direct-local and
406+
configured remote identities; public origins inherit no local-listener pin.
407+
Ambient Gateway auth env fallback is suppressed for handoffs. Mismatches fail
408+
closed, terminal auth remains independent, and session ACLs stay
409+
authoritative.
391410
3. **`openclaw connect`**: verb + `oc-pair://` decoder + TLS pin in payload +
392411
`/j/<shortcode>` join route (reserved prefix, single-use, rate-limited) +
393412
shortcode mint + curl wrapper on the public site. Exit: a fresh machine

‎packages/terminal-core/src/safe-text.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
// Terminal Core tests cover safe text behavior.
22
import { describe, expect, it } from "vitest";
3-
import { sanitizeTerminalText } from "./safe-text.js";
3+
import { hasTerminalControl, sanitizeTerminalText } from "./safe-text.js";
4+
5+
describe("hasTerminalControl", () => {
6+
it.each([
7+
["C0", "safe\u0000text"],
8+
["DEL", "safe\u007ftext"],
9+
["C1", "safe\u0085text"],
10+
])("detects %s controls", (_name, input) => {
11+
expect(hasTerminalControl(input)).toBe(true);
12+
});
13+
14+
it("allows printable shell metacharacters and Unicode", () => {
15+
expect(hasTerminalControl(`'"$&;|<>^()%![]{}\\\`-%PATH%-��`)).toBe(false);
16+
});
17+
});
418

519
describe("sanitizeTerminalText", () => {
620
it("removes C1 control characters", () => {

‎packages/terminal-core/src/safe-text.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
// Terminal Core module implements safe text behavior.
22
import { stripAnsi } from "./ansi.js";
33

4+
/** Return whether text contains C0 or C1 terminal control characters. */
5+
export function hasTerminalControl(input: string): boolean {
6+
for (const char of input) {
7+
const codePoint = char.codePointAt(0);
8+
if (
9+
codePoint !== undefined &&
10+
(codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f))
11+
) {
12+
return true;
13+
}
14+
}
15+
return false;
16+
}
17+
418
/**
519
* Normalize untrusted text for single-line terminal/log rendering.
620
*/
@@ -11,9 +25,7 @@ export function sanitizeTerminalText(input: string): string {
1125
.replace(/\t/g, "\\t");
1226
let sanitized = "";
1327
for (const char of normalized) {
14-
const code = char.charCodeAt(0);
15-
const isControl = (code >= 0x00 && code <= 0x1f) || (code >= 0x7f && code <= 0x9f);
16-
if (!isControl) {
28+
if (!hasTerminalControl(char)) {
1729
sanitized += char;
1830
}
1931
}

0 commit comments

Comments
 (0)